commit 082f3dc0e53d4db1b6a990f0a23a18d358bc1b45 Author: Harald Judt Date: Mon Mar 11 20:05:35 2013 +0100 Pager: Add viewport switching support (for compiz and alike). diff --git a/plugins/pager/pager.c b/plugins/pager/pager.c index 6f0a378..0f9b6c3 100644 --- a/plugins/pager/pager.c +++ b/plugins/pager/pager.c @@ -251,26 +251,77 @@ pager_plugin_scroll_event (GtkWidget *widget, if (plugin->scrolling == FALSE) return TRUE; - active_ws = wnck_screen_get_active_workspace (plugin->wnck_screen); - active_n = wnck_workspace_get_number (active_ws); - - if (event->direction == GDK_SCROLL_UP - || event->direction == GDK_SCROLL_LEFT) - active_n--; + if (n_workspaces == 0) + { + /* do we have only one workspace or are we in viewport mode (compiz) */ + active_ws = wnck_screen_get_active_workspace (plugin->wnck_screen); + if (wnck_workspace_is_virtual (active_ws)) + { + /* viewport mode */ + int viewport_x; + int viewport_y; + int screen_width, screen_height; + int workspace_width, workspace_height; + int scroll_direction; + + /* total workspacesize, e.g. 5120x1024 (5120=4x1280) */ + workspace_width = wnck_workspace_get_width (active_ws); + workspace_height = wnck_workspace_get_height (active_ws); + /* current screensize, e.g. 1280x1024 */ + screen_width = wnck_screen_get_width (plugin->wnck_screen); + screen_height = wnck_screen_get_height (plugin->wnck_screen); + /* current viewportcoordinates, e.g. 0,0 or 1280,0 */ + viewport_x = wnck_workspace_get_viewport_x (active_ws); + viewport_y = wnck_workspace_get_viewport_y (active_ws); + + switch (event->direction) + { + case GDK_SCROLL_UP: + case GDK_SCROLL_LEFT: + scroll_direction = +1; + break; + case GDK_SCROLL_DOWN: + case GDK_SCROLL_RIGHT: + scroll_direction = -1; + break; + default: + break; + } + /* viewportscroll is only in x-direction */ + viewport_x = viewport_x + (scroll_direction * screen_width); + + /* wrap if needed */ + if (viewport_x > workspace_width) + viewport_x = 0; + if (viewport_x < 0) + viewport_x = workspace_width - screen_width; + + wnck_screen_move_viewport (plugin->wnck_screen, + viewport_x, viewport_y); + } + } else - active_n++; - - /* wrap around */ - n_workspaces = wnck_screen_get_workspace_count (plugin->wnck_screen) - 1; - if (active_n < 0) - active_n = n_workspaces; - else if (active_n > n_workspaces) - active_n = 0; - - new_ws = wnck_screen_get_workspace (plugin->wnck_screen, active_n); - if (new_ws != NULL && active_ws != new_ws) - wnck_workspace_activate (new_ws, event->time); - + { + /* real workspaces */ + active_ws = wnck_screen_get_active_workspace (plugin->wnck_screen); + active_n = wnck_workspace_get_number (active_ws); + + if (event->direction == GDK_SCROLL_UP + || event->direction == GDK_SCROLL_LEFT) + active_n = active_n + 1; + else + active_n = active_n - 1; + + /* wrap around */ + if (active_n < 0) + active_n = n_workspaces; + else if (active_n > n_workspaces) + active_n = 0; + + new_ws = wnck_screen_get_workspace (plugin->wnck_screen, active_n); + if (new_ws != NULL && active_ws != new_ws) + wnck_workspace_activate (new_ws, event->time); + } return TRUE; }