summaryrefslogtreecommitdiff
path: root/0001-Hacks-on-gtk-window-decorator-to-give-deviceid-this.patch
blob: 213eb856f1044b30ec74ef2396987ba3d0d3834d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
From bda80922c29d283d04a5969b0c0785855143f7f4 Mon Sep 17 00:00:00 2001
From: root <root@JOEL-GENTOO2.(none)>
Date: Fri, 29 Feb 2008 11:36:34 +0900
Subject: [PATCH] Hacks on gtk-window-decorator to give deviceid (this breaks the spec)

---
 gtk/window-decorator/gtk-window-decorator.c |  197 ++++++++++++++++++++++-----
 1 files changed, 161 insertions(+), 36 deletions(-)

diff --git a/gtk/window-decorator/gtk-window-decorator.c b/gtk/window-decorator/gtk-window-decorator.c
index 41ce6ae..556b228 100644
--- a/gtk/window-decorator/gtk-window-decorator.c
+++ b/gtk/window-decorator/gtk-window-decorator.c
@@ -29,6 +29,8 @@
 #include <X11/Xatom.h>
 #include <X11/cursorfont.h>
 #include <X11/extensions/Xrender.h>
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XInput.h>
 #include <X11/Xregion.h>
 
 #ifndef GDK_DISABLE_DEPRECATED
@@ -230,6 +232,7 @@ int double_click_action = DOUBLE_CLICK_ACTION_DEFAULT;
 int middle_click_action = MIDDLE_CLICK_ACTION_DEFAULT;
 int right_click_action  = RIGHT_CLICK_ACTION_DEFAULT;
 int wheel_action        = WHEEL_ACTION_DEFAULT;
+static int DeviceButtonPressed;
 
 static gboolean minimal = FALSE;
 
@@ -237,6 +240,50 @@ static double decoration_alpha = 0.5;
 
 #define SWITCHER_SPACE 40
 
+typedef struct _ResizePointer ResizePointer;
+struct _ResizePointer
+{
+    XDevice *device;
+    XID deviceid;
+    
+    ResizePointer *next;
+};
+
+static ResizePointer *pointerHead = NULL;
+
+static ResizePointer
+*addDevice (void)
+{
+ int i=0;
+    ResizePointer *p;
+
+    if(pointerHead == NULL)
+    {
+	pointerHead = malloc (sizeof(ResizePointer));
+	    if(pointerHead == NULL) return NULL;
+	p = pointerHead;
+    }
+    else
+    {
+    	for(p=pointerHead; p->next; p=p->next) i++;
+	p->next = malloc (sizeof(ResizePointer));
+	    if(p->next == NULL) return NULL;
+	p = p->next;
+    }
+    return p;
+}
+
+static ResizePointer
+*resizeFindDeviceFromDeviceid(XID deviceid)
+{
+    ResizePointer *dev;
+    for(dev=pointerHead; dev; dev=dev->next)
+    {
+	if(dev->deviceid == deviceid) break;
+    }
+    return dev;
+}
+
 static decor_extents_t _shadow_extents      = { 0, 0, 0, 0 };
 static decor_extents_t _win_extents         = { 6, 6, 4, 6 };
 static decor_extents_t _max_win_extents     = { 6, 6, 4, 6 };
@@ -3489,11 +3536,66 @@ add_frame_window (WnckWindow *win,
 
     xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
 
-    attr.event_mask = ButtonPressMask | EnterWindowMask | LeaveWindowMask;
+    attr.event_mask =  EnterWindowMask | LeaveWindowMask;
     attr.override_redirect = TRUE;
 
     gdk_error_trap_push ();
 
+
+    /* *** MPX *** *
+    int num;
+    int num_pointers;
+    
+    XDeviceInfo* devs = XListInputDevices(xdisplay, &num);
+    XDevice **pointers = (XDevice**)calloc(sizeof(XDevice*), num);
+    XEventClass *evclasses = (XEventClass*)calloc(sizeof(XEventClass), num);
+    num_pointers = 0;
+
+    while(num-- > 0)
+    {
+        if (devs[num].use == IsXPointer) //only care about master pointers
+        {
+            XDevice* dev = XOpenDevice(xdisplay, devs[num].id);
+            DeviceButtonPress(dev, DeviceButtonPressed, evclasses[num_pointers]); 
+            pointers[num_pointers++] = dev;
+        }
+    }
+
+    pointers = realloc(pointers, sizeof(XDevice**) * num_pointers);
+    evclasses = realloc(evclasses, sizeof(XEventClass) * num_pointers);
+    
+    
+    /*************/
+    pointerHead = NULL;
+    
+    XDeviceInfo* devs;
+    int num;
+    int tempNum = 0;
+        
+    devs = XListInputDevices(xdisplay, &num);
+    ResizePointer *dev;
+    
+    XEventClass *evclasses = (XEventClass*)calloc(sizeof(XEventClass), num);    
+    
+    while(num-- > 0)
+    {
+        if (devs[num].use == IsXPointer)
+        {
+	    dev = addDevice();
+		if(dev == NULL) fprintf (stderr, "FAILED\n");
+	    dev->device =  XOpenDevice(xdisplay, devs[num].id);
+	    dev->deviceid = devs[num].id;
+	    dev->next = NULL;
+            DeviceButtonPress(dev->device, DeviceButtonPressed, evclasses[++tempNum]); 	  
+        fprintf(stderr, "Add a device: %d \n", devs[num].id);              
+        }
+    }    
+    fprintf(stderr, "%d", tempNum);
+        evclasses = realloc(evclasses, sizeof(XEventClass) * tempNum);
+        
+    XFreeDeviceList(devs);    
+    /* ***** */
+    
     for (i = 0; i < 3; i++)
     {
 	for (j = 0; j < 3; j++)
@@ -3504,6 +3606,8 @@ add_frame_window (WnckWindow *win,
 			       0, 0, 1, 1, 0,
 			       CopyFromParent, CopyFromParent, CopyFromParent,
 			       CWOverrideRedirect | CWEventMask, &attr);
+			       
+	    XSelectExtensionEvent(xdisplay, d->event_windows[i][j], evclasses, tempNum); /* MPX */			       
 
 	    if (cursor[i][j].cursor)
 		XDefineCursor (xdisplay, d->event_windows[i][j],
@@ -3512,6 +3616,7 @@ add_frame_window (WnckWindow *win,
     }
 
     attr.event_mask |= ButtonReleaseMask;
+    attr.event_mask |= ButtonPressMask;
 
     for (i = 0; i < BUTTON_NUM; i++)
     {
@@ -4021,49 +4126,59 @@ move_resize_window (WnckWindow *win,
 		    int	       direction,
 		    XEvent     *xevent)
 {
-    Display    *xdisplay;
-    GdkDisplay *gdkdisplay;
-    GdkScreen  *screen;
-    Window     xroot;
-    XEvent     ev;
+    if(xevent->type == DeviceButtonPressed) //XXX should use the return type from ButtonPressMacro
+    {
+	Display    *xdisplay;
+	GdkDisplay *gdkdisplay;
+	GdkScreen  *screen;
+	Window     xroot;
+	XEvent     ev;
 
-    gdkdisplay = gdk_display_get_default ();
-    xdisplay   = GDK_DISPLAY_XDISPLAY (gdkdisplay);
-    screen     = gdk_display_get_default_screen (gdkdisplay);
-    xroot      = RootWindowOfScreen (gdk_x11_screen_get_xscreen (screen));
+	gdkdisplay = gdk_display_get_default ();
+	xdisplay   = GDK_DISPLAY_XDISPLAY (gdkdisplay);
+	screen     = gdk_display_get_default_screen (gdkdisplay);
+	xroot      = RootWindowOfScreen (gdk_x11_screen_get_xscreen (screen));
 
-    if (action_menu_mapped)
-    {
-	gtk_object_destroy (GTK_OBJECT (action_menu));
-	action_menu_mapped = FALSE;
-	action_menu = NULL;
-	return;
-    }
+	if (action_menu_mapped)
+	{
+	    gtk_object_destroy (GTK_OBJECT (action_menu));
+	    action_menu_mapped = FALSE;
+	    action_menu = NULL;
+	    return;
+	}
 
-    ev.xclient.type    = ClientMessage;
-    ev.xclient.display = xdisplay;
+	ev.xclient.type    = ClientMessage;
+	ev.xclient.display = xdisplay;
 
-    ev.xclient.serial	  = 0;
-    ev.xclient.send_event = TRUE;
+	ev.xclient.serial	  = 0;
+	ev.xclient.send_event = TRUE;
 
-    ev.xclient.window	    = wnck_window_get_xid (win);
-    ev.xclient.message_type = wm_move_resize_atom;
-    ev.xclient.format	    = 32;
+	ev.xclient.window	    = wnck_window_get_xid (win);
+	ev.xclient.message_type = wm_move_resize_atom;
+	ev.xclient.format	    = 32;
 
-    ev.xclient.data.l[0] = xevent->xbutton.x_root;
-    ev.xclient.data.l[1] = xevent->xbutton.y_root;
-    ev.xclient.data.l[2] = direction;
-    ev.xclient.data.l[3] = xevent->xbutton.button;
-    ev.xclient.data.l[4] = 1;
+	XDeviceButtonEvent *bev = xevent;
+	ev.xclient.data.l[0] = bev->x_root; 
+	ev.xclient.data.l[1] = bev->y_root;
+	ev.xclient.data.l[2] = direction;
+	ev.xclient.data.l[3] = bev->button;	
+	ev.xclient.data.l[4] = bev->deviceid; //breaks spec, I don't care
+    
+    fprintf (stderr, "yup: %d \n", bev->deviceid);
+    
+//    XUngrabPointer (xdisplay, xevent->xbutton.time); //XXX
+    XUngrabKeyboard (xdisplay, xevent->xbutton.time); //XXX
 
-    XUngrabPointer (xdisplay, xevent->xbutton.time);
-    XUngrabKeyboard (xdisplay, xevent->xbutton.time);
+    ResizePointer *dev = resizeFindDeviceFromDeviceid( bev->deviceid);
+
+    XUngrabDevice (xdisplay, dev->device , CurrentTime);
 
     XSendEvent (xdisplay, xroot, FALSE,
 		SubstructureRedirectMask | SubstructureNotifyMask,
 		&ev);
 
     XSync (xdisplay, FALSE);
+    }
 }
 
 static void
@@ -4794,14 +4909,17 @@ frame_common_event (WnckWindow *win,
 		    int        direction,
 		    XEvent     *xevent)
 {
-    if (xevent->type != ButtonPress)
+    if(xevent->type == DeviceButtonPressed) //XXX
+    {
+	move_resize_window(win,direction,xevent);
+	restack_window (win, Above);
+    }
+    
+    if (xevent->type != DeviceButtonPressed )
 	return;
 
     switch (xevent->xbutton.button) {
-    case 1:
-	move_resize_window (win, direction, xevent);
-	restack_window (win, Above);
-	break;
+    case 1: break;
     case 2:
 	handle_title_button_event (win, middle_click_action,
 				   &xevent->xbutton);
@@ -5222,6 +5340,11 @@ event_filter_func (GdkXEvent *gdkxevent,
 	break;
     }
 
+    if(xevent->type == DeviceButtonPressed)
+	{xid = (gulong)
+	    g_hash_table_lookup (frame_table,
+				 GINT_TO_POINTER (xevent->xbutton.window));}
+
     if (xid)
     {
 	WnckWindow *win;
@@ -6832,6 +6955,8 @@ main (int argc, char *argv[])
     gdkdisplay = gdk_display_get_default ();
     xdisplay   = gdk_x11_display_get_xdisplay (gdkdisplay);
     gdkscreen  = gdk_display_get_default_screen (gdkdisplay);
+    
+    
 
     frame_window_atom	= XInternAtom (xdisplay, "_NET_FRAME_WINDOW", FALSE);
     win_decor_atom	= XInternAtom (xdisplay, DECOR_WINDOW_ATOM_NAME, FALSE);
-- 
1.5.4.2