Esempio n. 1
0
/**
 * meta_workspace_get_neighbor:
 * @workspace: a #MetaWorkspace
 * @direction: a #MetaMotionDirection, direction in which to look for the neighbor
 *
 * Gets the neighbor of the #MetaWorkspace in the given direction
 *
 * Return value: (transfer none): the neighbor #MetaWorkspace
 */
MetaWorkspace*
meta_workspace_get_neighbor (MetaWorkspace      *workspace,
                             MetaMotionDirection direction)
{
  MetaWorkspaceLayout layout;  
  int i, current_space, num_workspaces;
  gboolean ltr;

  current_space = meta_workspace_index (workspace);
  num_workspaces = meta_screen_get_n_workspaces (workspace->screen);
  meta_screen_calc_workspace_layout (workspace->screen, num_workspaces,
                                     current_space, &layout);

  meta_verbose ("Getting neighbor of %d in direction %s\n",
                current_space, meta_motion_direction_to_string (direction));
  
  ltr = meta_ui_get_direction() == META_UI_DIRECTION_LTR;

  switch (direction) 
    {
    case META_MOTION_LEFT:
      layout.current_col -= ltr ? 1 : -1;
      break;
    case META_MOTION_RIGHT:
      layout.current_col += ltr ? 1 : -1;
      break;
    case META_MOTION_UP:
      layout.current_row -= 1;
      break;
    case META_MOTION_DOWN:
      layout.current_row += 1;
      break;
    default:;
    }

  if (layout.current_col < 0)
    layout.current_col = 0;
  if (layout.current_col >= layout.cols)
    layout.current_col = layout.cols - 1;
  if (layout.current_row < 0)
    layout.current_row = 0;
  if (layout.current_row >= layout.rows)
    layout.current_row = layout.rows - 1;

  i = layout.grid[layout.current_row * layout.cols + layout.current_col];

  if (i < 0)
    i = current_space;

  if (i >= num_workspaces)
    meta_bug ("calc_workspace_layout left an invalid (too-high) workspace number %d in the grid\n",
              i);
    
  meta_verbose ("Neighbor workspace is %d at row %d col %d\n",
                i, layout.current_row, layout.current_col);

  meta_screen_free_workspace_layout (&layout);
  
  return meta_screen_get_workspace_by_index (workspace->screen, i);
}
Esempio n. 2
0
void
meta_core_change_workspace (Display *xdisplay,
                            Window   frame_xwindow,
                            int      new_workspace)
{
  MetaWindow *window = get_window (xdisplay, frame_xwindow);

  meta_window_change_workspace (window,
                                meta_screen_get_workspace_by_index (window->screen,
                                                                    new_workspace));
}
Esempio n. 3
0
const char*
meta_core_get_workspace_name_with_index (Display *xdisplay,
                                         Window   xroot,
                                         int      index)
{
  MetaDisplay *display;
  MetaScreen *screen;
  MetaWorkspace *workspace;

  display = meta_display_for_x_display (xdisplay);
  screen = meta_display_screen_for_root (display, xroot);
  g_assert (screen != NULL);
  workspace = meta_screen_get_workspace_by_index (screen, index);
  return workspace ? meta_workspace_get_name (workspace) : NULL;
}
MetaWorkspace*
meta_workspace_get_neighbor (MetaWorkspace      *workspace,
                             MetaMotionDirection direction)
{
  MetaWorkspaceLayout layout;
  int i, current_space, num_workspaces;
  gboolean ltr;
  MetaWrapStyle wrap;

  current_space = meta_workspace_index (workspace);
  num_workspaces = meta_screen_get_n_workspaces (workspace->screen);
  meta_screen_calc_workspace_layout (workspace->screen, num_workspaces,
                                     current_space, &layout);
  wrap = meta_prefs_get_wrap_style();

  meta_verbose ("Getting neighbor of %d in direction %s\n",
                current_space, meta_motion_direction_to_string (direction));

  ltr = meta_ui_get_direction() == META_UI_DIRECTION_LTR;

  switch (direction)
    {
    case META_MOTION_LEFT:
      layout.current_col -= ltr ? 1 : -1;
      break;
    case META_MOTION_RIGHT:
      layout.current_col += ltr ? 1 : -1;
      break;
    case META_MOTION_UP:
      layout.current_row -= 1;
      break;
    case META_MOTION_DOWN:
      layout.current_row += 1;
      break;
    }

  /* LEFT */
  if (layout.current_col < 0)
    switch (wrap)
      {
      case META_WRAP_NONE:
        layout.current_col = 0;
        break;
      case META_WRAP_TOROIDAL:
        layout.current_row = layout.current_row > 0 ? layout.current_row - 1 : layout.rows - 1;
        /* fall through */
      case META_WRAP_CLASSIC:
        layout.current_col = layout.cols - 1;
      }
  /* RIGHT */
  if (layout.current_col >= layout.cols)
    switch (wrap)
      {
      case META_WRAP_NONE:
        layout.current_col = layout.cols - 1;
        break;
      case META_WRAP_TOROIDAL:
        layout.current_row = layout.current_row < layout.rows - 1 ? layout.current_row + 1 : 0;
        /* fall through */
      case META_WRAP_CLASSIC:
        layout.current_col = 0;
      }
  /* UP */
  if (layout.current_row < 0)
    switch (wrap)
      {
      case META_WRAP_NONE:
        layout.current_row = 0;
        break;
      case META_WRAP_TOROIDAL:
        layout.current_col = layout.current_col > 0 ? layout.current_col - 1 : layout.cols - 1;
        /* fall through */
      case META_WRAP_CLASSIC:
        layout.current_row = layout.rows - 1;
      }
  /* DOWN */
  if (layout.current_row >= layout.rows)
    switch (wrap)
      {
      case META_WRAP_NONE:
        layout.current_row = layout.rows - 1;
        break;
      case META_WRAP_TOROIDAL:
        layout.current_col = layout.current_col < layout.cols - 1 ? layout.current_col + 1 : 0;
        /* fall through */
      case META_WRAP_CLASSIC:
        layout.current_row = 0;
      }

  /* If we have an uneven arrangement of workspaces, (layout.cols - n, layout.rows - 1) may be an invalid workspace
     e.g. we have 7 workspaces on a 3x3 pane */
  if (wrap != META_WRAP_NONE && (layout.current_row * layout.cols + layout.current_col >= num_workspaces))
    switch (direction)
      {
      case META_MOTION_LEFT:
        layout.current_col = num_workspaces - (layout.current_row * layout.cols + 1);
        break;
      case META_MOTION_RIGHT:
       layout.current_col = 0;
       if (wrap == META_WRAP_TOROIDAL)
         layout.current_row = 0;
       break;
      case META_MOTION_UP:
        layout.current_row -= 1;
        break;
      case META_MOTION_DOWN:
        layout.current_row = 0;
        if (wrap == META_WRAP_TOROIDAL)
	  layout.current_col = layout.current_col < layout.cols - 1 ? layout.current_col + 1 : 0;
        break;
      }

  i = layout.grid[layout.current_row * layout.cols + layout.current_col];

  if (i < 0)
    i = current_space;

  if (i >= num_workspaces)
    meta_bug ("calc_workspace_layout left an invalid (too-high) workspace number %d in the grid\n",
              i);

  meta_verbose ("Neighbor workspace is %d at row %d col %d\n",
                i, layout.current_row, layout.current_col);

  meta_screen_free_workspace_layout (&layout);

  return meta_screen_get_workspace_by_index (workspace->screen, i);
}