[#552] pager: support scroll wheel
authornumber Zero <numzero@users.sf.net>
Thu, 4 Jan 2018 15:20:03 +0000 (15:20 +0000)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Sun, 7 Jan 2018 20:07:18 +0000 (22:07 +0200)
Allows to switch workspaces by scrolling over pager.

AUTHORS
ChangeLog
plugins/pager.c

diff --git a/AUTHORS b/AUTHORS
index 4ba22a3..87b6655 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -20,6 +20,7 @@ LXPanel - Lightweight X11 desktop panel
     Charles Lehner <cel10@users.sf.net>
     Stanislav Kozina, Ersin <xersin@users.sf.net>
     Mamoru TASAKA <mtasaka@fedoraproject.org>
+    number Zero <numzero@users.sf.net>
 
 [History]
 LXPanel is a derivative work from fbpanel [1] written by Anatoly Asviyan,
index 010eb55..e588912 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
 * Fixed delayed application of font cnahges on dclock and weather plugins.
+* Allowed switching workplaces by scrolling over the pager.
 
 0.9.3
 -------------------------------------------------------------------------
index 6da24bc..fb560c2 100644 (file)
@@ -3,6 +3,7 @@
  * Copyright (C) 2009 Dongxu Li <song6song@sourceforge.net>
  *               2012 Julien Lavergne <gilir@ubuntu.com>
  *               2014 Andriy Grytsenko <andrej@rep.kiev.ua>
+ *               2018 number Zero <numzero@users.sf.net>
  *
  * This file is part of lxpanel.
  *
@@ -32,6 +33,7 @@
 #endif
 #include <libwnck/libwnck.h>
 
+#include "misc.h"
 #include "plugin.h"
 
 typedef struct
@@ -65,6 +67,30 @@ static void on_size_allocate(GtkWidget *p, GdkRectangle *allocation, LXPanel *pa
     on_realize(p, panel);
 }
 
+static gboolean on_scroll_event(GtkWidget * p, GdkEventScroll * ev, LXPanel *panel)
+{
+    int desknum = get_net_current_desktop();
+    int desks = get_net_number_of_desktops();
+    Screen *xscreen = GDK_SCREEN_XSCREEN(gtk_widget_get_screen(p));
+
+    switch (ev->direction) {
+        case GDK_SCROLL_DOWN:
+            desknum++;
+            break;
+        case GDK_SCROLL_UP:
+            desknum--;
+            break;
+        default:
+            return FALSE;
+    }
+
+    if (desknum < 0 || desknum >= desks)
+        return TRUE;
+
+    Xclimsgx(xscreen, RootWindowOfScreen(xscreen), a_NET_CURRENT_DESKTOP, desknum, 0, 0, 0, 0);
+    return TRUE;
+}
+
 static GtkWidget *pager_constructor(LXPanel *panel, config_setting_t *settings)
 {
     GtkWidget *p, *w;
@@ -88,6 +114,7 @@ static GtkWidget *pager_constructor(LXPanel *panel, config_setting_t *settings)
     /* we cannot configure pager until it added into widgets hierarchy */
     g_signal_connect(p, "realize", G_CALLBACK(on_realize), panel);
     g_signal_connect(p, "size-allocate", G_CALLBACK(on_size_allocate), panel);
+    g_signal_connect(p, "scroll-event", G_CALLBACK(on_scroll_event), panel);
     wnck_pager_set_display_mode(d->pager, WNCK_PAGER_DISPLAY_CONTENT);
 
     gtk_widget_show(w);