summaryrefslogtreecommitdiff
path: root/src/core/workspace.c
diff options
context:
space:
mode:
authorBenjamin Valentin <[email protected]>2012-01-09 17:47:29 +0100
committerBenjamin Valentin <benpicco@rechenknecht2k7.(none)>2012-03-16 00:29:11 +0100
commitdacdbd19b2d6037235aa4ed1bd28f89286236046 (patch)
treea63d9ea17ddd2f772bc64819cc348c644d5746b8 /src/core/workspace.c
parent3f122b87a866edb62d0402058f83974cf8a8fd54 (diff)
downloadmarco-dacdbd19b2d6037235aa4ed1bd28f89286236046.tar.bz2
marco-dacdbd19b2d6037235aa4ed1bd28f89286236046.tar.xz
implement option for classic and toroidal workspace switching, based on https://bugzilla.gnome.org/show_bug.cgi?id=89315
Diffstat (limited to 'src/core/workspace.c')
-rw-r--r--src/core/workspace.c87
1 files changed, 78 insertions, 9 deletions
diff --git a/src/core/workspace.c b/src/core/workspace.c
index 2b28fe0b..9694c1f9 100644
--- a/src/core/workspace.c
+++ b/src/core/workspace.c
@@ -809,21 +809,23 @@ MetaWorkspace*
meta_workspace_get_neighbor (MetaWorkspace *workspace,
MetaMotionDirection direction)
{
- MetaWorkspaceLayout layout;
+ 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)
+ switch (direction)
{
case META_MOTION_LEFT:
layout.current_col -= ltr ? 1 : -1;
@@ -839,14 +841,81 @@ meta_workspace_get_neighbor (MetaWorkspace *workspace,
break;
}
+ /* LEFT */
if (layout.current_col < 0)
- 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)
- layout.current_col = layout.cols - 1;
+ 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)
- 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)
- layout.current_row = layout.rows - 1;
+ 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];
@@ -856,12 +925,12 @@ meta_workspace_get_neighbor (MetaWorkspace *workspace,
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);
}