summaryrefslogtreecommitdiff
path: root/applets/wncklet
diff options
context:
space:
mode:
authorMoritz Bruder <[email protected]>2017-03-23 21:20:19 +0100
committerlukefromdc <[email protected]>2017-03-30 14:21:23 -0400
commit9b8f9e8147e27e19eb08a262a140b937051545b9 (patch)
tree3bf73b7efb037ea2b86bb43fdf5d7928548290af /applets/wncklet
parent2c1957f884a5e11f8cd6536b9b4cca3f0ee86b6b (diff)
downloadmate-panel-9b8f9e8147e27e19eb08a262a140b937051545b9.tar.bz2
mate-panel-9b8f9e8147e27e19eb08a262a140b937051545b9.tar.xz
Reenable workspace switcher wrapping
These changes have been accidentally removed. The previously used handler has been added to the code again, which connects to the scroll event of the WnckPager widget.
Diffstat (limited to 'applets/wncklet')
-rw-r--r--applets/wncklet/workspace-switcher.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/applets/wncklet/workspace-switcher.c b/applets/wncklet/workspace-switcher.c
index e88839dd..a757d80b 100644
--- a/applets/wncklet/workspace-switcher.c
+++ b/applets/wncklet/workspace-switcher.c
@@ -210,6 +210,113 @@ static void applet_change_background(MatePanelApplet* applet, MatePanelAppletBac
type == PANEL_NO_BACKGROUND ? GTK_SHADOW_NONE : GTK_SHADOW_IN);
}
+/* Replacement for the default scroll handler that also cares about the wrapping property.
+ * Alternative: Add behaviour to libwnck (to the WnckPager widget).
+ */
+static gboolean applet_scroll(MatePanelApplet* applet, GdkEventScroll* event, PagerData* pager)
+{
+ GdkScrollDirection absolute_direction;
+ int index;
+ int n_workspaces;
+ int n_columns;
+ int in_last_row;
+
+ if (event->type != GDK_SCROLL)
+ return FALSE;
+
+ index = wnck_workspace_get_number(wnck_screen_get_active_workspace(pager->screen));
+ n_workspaces = wnck_screen_get_workspace_count(pager->screen);
+ n_columns = n_workspaces / pager->n_rows;
+
+ if (n_workspaces % pager->n_rows != 0)
+ n_columns++;
+
+ in_last_row = n_workspaces % n_columns;
+
+ absolute_direction = event->direction;
+
+ if (gtk_widget_get_direction(GTK_WIDGET(applet)) == GTK_TEXT_DIR_RTL)
+ {
+ switch (event->direction)
+ {
+ case GDK_SCROLL_DOWN:
+ case GDK_SCROLL_UP:
+ break;
+ case GDK_SCROLL_RIGHT:
+ absolute_direction = GDK_SCROLL_LEFT;
+ break;
+ case GDK_SCROLL_LEFT:
+ absolute_direction = GDK_SCROLL_RIGHT;
+ break;
+ }
+ }
+
+ switch (absolute_direction)
+ {
+ case GDK_SCROLL_DOWN:
+ if (index + n_columns < n_workspaces)
+ {
+ index += n_columns;
+ }
+ else if (pager->wrap_workspaces && index == n_workspaces - 1)
+ {
+ index = 0;
+ }
+ else if ((index < n_workspaces - 1 && index + in_last_row != n_workspaces - 1) || (index == n_workspaces - 1 && in_last_row != 0))
+ {
+ index = (index % n_columns) + 1;
+ }
+ break;
+
+ case GDK_SCROLL_RIGHT:
+ if (index < n_workspaces - 1)
+ {
+ index++;
+ }
+ else if (pager->wrap_workspaces)
+ {
+ index = 0;
+ }
+ break;
+
+ case GDK_SCROLL_UP:
+ if (index - n_columns >= 0)
+ {
+ index -= n_columns;
+ }
+ else if (index > 0)
+ {
+ index = ((pager->n_rows - 1) * n_columns) + (index % n_columns) - 1;
+ }
+ else if (pager->wrap_workspaces)
+ {
+ index = n_workspaces - 1;
+ }
+
+ if (index >= n_workspaces)
+ index -= n_columns;
+ break;
+
+ case GDK_SCROLL_LEFT:
+ if (index > 0)
+ {
+ index--;
+ }
+ else if (pager->wrap_workspaces)
+ {
+ index = n_workspaces - 1;
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ wnck_workspace_activate(wnck_screen_get_workspace(pager->screen, index), event->time);
+
+ return TRUE;
+}
+
static void destroy_pager(GtkWidget* widget, PagerData* pager)
{
g_object_unref (pager->settings);
@@ -422,6 +529,9 @@ gboolean workspace_switcher_applet_fill(MatePanelApplet* applet)
g_signal_connect(G_OBJECT(pager->pager), "destroy", G_CALLBACK(destroy_pager), pager);
+ /* overwrite default WnckPager widget scroll-event */
+ g_signal_connect(G_OBJECT(pager->pager), "scroll-event", G_CALLBACK(applet_scroll), pager);
+
gtk_container_add(GTK_CONTAINER(pager->applet), pager->pager);
gtk_widget_show(pager->pager);