3434 */
3535
3636#include < gtk/gtk.h>
37+
38+ #ifndef _WIN32
3739#include < gdk/gdkx.h>
40+ #else
41+ #include < X11/Xlib.h>
42+ #include < cassert>
43+ #include < libaudcore/runtime.h>
44+ #endif
3845
3946#include " grab.h"
4047#include " plugin.h"
@@ -46,6 +53,87 @@ static unsigned int scrolllock_mask = 0;
4653static unsigned int capslock_mask = 0 ;
4754
4855
56+ static int x11_error_handler (Display *dpy, XErrorEvent *error)
57+ {
58+ return 0 ;
59+ }
60+
61+ static GdkFilterReturn
62+ gdk_filter (GdkXEvent *xevent,
63+ GdkEvent *event,
64+ void * data)
65+ {
66+ #ifdef _WIN32
67+ AUDDBG (" lHotkeyFlow:win CommonGrab: Filter trigger." );
68+ assert (false );
69+ #endif
70+ HotkeyConfiguration *hotkey;
71+ hotkey = &(get_config ()->first );
72+ switch (((XEvent*)xevent)->type )
73+ {
74+ case KeyPress:
75+ {
76+ XKeyEvent *keyevent = (XKeyEvent*)xevent;
77+ while (hotkey)
78+ {
79+ if ((hotkey->key == keyevent->keycode ) &&
80+ (hotkey->mask == (keyevent->state & ~(scrolllock_mask | numlock_mask | capslock_mask))) &&
81+ (hotkey->type == TYPE_KEY))
82+ {
83+ if (handle_keyevent (hotkey->event ))
84+ return GDK_FILTER_REMOVE;
85+ break ;
86+ }
87+
88+ hotkey = hotkey->next ;
89+ }
90+ break ;
91+ }
92+ case ButtonPress:
93+ {
94+ XButtonEvent *buttonevent = (XButtonEvent*)xevent;
95+ while (hotkey)
96+ {
97+ if ((hotkey->key == buttonevent->button ) &&
98+ (hotkey->mask == (buttonevent->state & ~(scrolllock_mask | numlock_mask | capslock_mask))) &&
99+ (hotkey->type == TYPE_MOUSE))
100+ {
101+ if (handle_keyevent (hotkey->event ))
102+ return GDK_FILTER_REMOVE;
103+ break ;
104+ }
105+
106+ hotkey = hotkey->next ;
107+ }
108+
109+ break ;
110+ }
111+ }
112+
113+ return GDK_FILTER_CONTINUE;
114+ }
115+
116+ gboolean setup_filter ()
117+ {
118+ #ifdef _WIN32
119+ AUDDBG (" lHotkeyFlow:win CommonGrab: filter up" );
120+ #endif
121+ gdk_window_add_filter (gdk_screen_get_root_window
122+ (gdk_screen_get_default ()), gdk_filter, nullptr );
123+
124+ return true ;
125+ }
126+
127+ void release_filter ()
128+ {
129+ #ifdef _WIN32
130+ AUDDBG (" lHotkeyFlow:win CommonGrab: down filter" );
131+ #endif
132+ gdk_window_remove_filter (gdk_screen_get_root_window
133+ (gdk_screen_get_default ()), gdk_filter, nullptr );
134+ }
135+
136+ #ifndef _WIN32
49137/* Taken from xbindkeys */
50138static void get_offending_modifiers (Display * dpy)
51139{
@@ -54,8 +142,8 @@ static void get_offending_modifiers (Display * dpy)
54142 KeyCode nlock, slock;
55143
56144 static int mask_table[8 ] = {
57- ShiftMask , LockMask, ControlMask, Mod1Mask ,
58- Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
145+ HK_SHIFT_MASK , LockMask, HK_CONTROL_MASK, HK_MOD1_ALT_MASK ,
146+ HK_MOD2_MASK, HK_MOD3_MASK, HK_MOD4_MASK, HK_MOD5_MASK
59147 };
60148
61149 nlock = XKeysymToKeycode (dpy, XK_Num_Lock);
@@ -84,12 +172,6 @@ static void get_offending_modifiers (Display * dpy)
84172 XFreeModifiermap (modmap);
85173}
86174
87-
88- static int x11_error_handler (Display *dpy, XErrorEvent *error)
89- {
90- return 0 ;
91- }
92-
93175/* grab required keys */
94176static void grab_key (const HotkeyConfiguration *hotkey, Display *xdisplay, Window x_root_window)
95177{
@@ -320,69 +402,4 @@ void ungrab_keys ( )
320402
321403 grabbed = 0 ;
322404}
323-
324-
325- static GdkFilterReturn
326- gdk_filter (GdkXEvent *xevent,
327- GdkEvent *event,
328- void * data)
329- {
330- HotkeyConfiguration *hotkey;
331- hotkey = &(get_config ()->first );
332- switch (((XEvent*)xevent)->type )
333- {
334- case KeyPress:
335- {
336- XKeyEvent *keyevent = (XKeyEvent*)xevent;
337- while (hotkey)
338- {
339- if ((hotkey->key == keyevent->keycode ) &&
340- (hotkey->mask == (keyevent->state & ~(scrolllock_mask | numlock_mask | capslock_mask))) &&
341- (hotkey->type == TYPE_KEY))
342- {
343- if (handle_keyevent (hotkey->event ))
344- return GDK_FILTER_REMOVE;
345- break ;
346- }
347-
348- hotkey = hotkey->next ;
349- }
350- break ;
351- }
352- case ButtonPress:
353- {
354- XButtonEvent *buttonevent = (XButtonEvent*)xevent;
355- while (hotkey)
356- {
357- if ((hotkey->key == buttonevent->button ) &&
358- (hotkey->mask == (buttonevent->state & ~(scrolllock_mask | numlock_mask | capslock_mask))) &&
359- (hotkey->type == TYPE_MOUSE))
360- {
361- if (handle_keyevent (hotkey->event ))
362- return GDK_FILTER_REMOVE;
363- break ;
364- }
365-
366- hotkey = hotkey->next ;
367- }
368-
369- break ;
370- }
371- }
372-
373- return GDK_FILTER_CONTINUE;
374- }
375-
376- gboolean setup_filter ()
377- {
378- gdk_window_add_filter (gdk_screen_get_root_window
379- (gdk_screen_get_default ()), gdk_filter, nullptr );
380-
381- return true ;
382- }
383-
384- void release_filter ()
385- {
386- gdk_window_remove_filter (gdk_screen_get_root_window
387- (gdk_screen_get_default ()), gdk_filter, nullptr );
388- }
405+ #endif
0 commit comments