Menu

#552 [lxpanel] pager: support scroll wheel

-
closed-accepted
lxpanel (21)
5
2018-01-07
2018-01-04
number Zero
No

Allows to switch workspaces by scrolling over pager (#525 does the same for deskno).
(sorry but “Add attachments” button does not work, so have to paste the patch here in plaintext)

diff --git a/plugins/pager.c b/plugins/pager.c
index 6da24bc..a1845e5 100644
--- a/plugins/pager.c
+++ b/plugins/pager.c
@@ -32,6 +32,7 @@
#endif
#include <libwnck libwnck.h="">

+#include "misc.h"
#include "plugin.h"

typedef struct
@@ -65,6 +66,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 +113,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);

Discussion

  • number Zero

    number Zero - 2018-01-04

    Er, it messed up the patch. Attempt #2

    diff --git a/plugins/pager.c b/plugins/pager.c
    index 6da24bc..a1845e5 100644
    --- a/plugins/pager.c
    +++ b/plugins/pager.c
    @@ -32,6 +32,7 @@
     #endif
     #include <libwnck/libwnck.h>
    
    +#include "misc.h"
     #include "plugin.h"
    
     typedef struct
    @@ -65,6 +66,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 +113,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);
    
     
  • Lonely Stranger

    Lonely Stranger - 2018-01-07
    • labels: --> lxpanel
    • status: open --> closed-accepted
    • assigned_to: Lonely Stranger
     
  • Lonely Stranger

    Lonely Stranger - 2018-01-07

    Thank you very much. Looks good, pushed your change into GIT on your behalf.

     

    Last edit: Lonely Stranger 2018-01-07

Log in to post a comment.