Merge lp:~cimi/overlay-scrollbar/fix-822806 into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 297
Merged at revision: 297
Proposed branch: lp:~cimi/overlay-scrollbar/fix-822806
Merge into: lp:overlay-scrollbar
Diff against target: 539 lines (+280/-221)
1 file modified
os/os-scrollbar.c (+280/-221)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/fix-822806
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+70796@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'os/os-scrollbar.c'
2--- os/os-scrollbar.c 2011-07-14 14:35:59 +0000
3+++ os/os-scrollbar.c 2011-08-08 21:52:33 +0000
4@@ -1953,7 +1953,7 @@
5 OsScrollbarPrivate *priv;
6
7 priv = scrollbar->priv;
8-
9+
10 switch (priv->side)
11 {
12 case OS_SIDE_RIGHT:
13@@ -1989,6 +1989,15 @@
14
15 /* filter function applied to the toplevel window */
16 #ifdef USE_GTK3
17+typedef enum
18+{
19+ OS_XEVENT_NONE,
20+ OS_XEVENT_BUTTON_PRESS,
21+ OS_XEVENT_BUTTON_RELEASE,
22+ OS_XEVENT_LEAVE,
23+ OS_XEVENT_MOTION
24+} OsXEvent;
25+
26 static GdkFilterReturn
27 window_filter_func (GdkXEvent *gdkxevent,
28 GdkEvent *event,
29@@ -2010,93 +2019,144 @@
30
31 if (!priv->fullsize)
32 {
33+ OsXEvent os_xevent;
34+ gdouble event_x, event_y;
35+
36+ os_xevent = OS_XEVENT_NONE;
37+
38 if (xev->type == GenericEvent)
39 {
40+ /* Deal with XInput 2 events */
41 XIDeviceEvent *xiev;
42
43 xiev = xev->xcookie.data;
44
45 if (xiev->evtype == XI_ButtonPress)
46- {
47- priv->toplevel_button_press = TRUE;
48- gtk_widget_hide (priv->thumb);
49- }
50-
51- if (priv->toplevel_button_press && xiev->evtype == XI_ButtonRelease)
52- {
53- priv->toplevel_button_press = FALSE;
54-
55- /* proximity area */
56- if (priv->orientation == GTK_ORIENTATION_VERTICAL)
57- {
58- if (check_proximity (scrollbar, xiev->event_x, xiev->event_y))
59- {
60- priv->can_hide = FALSE;
61-
62- if (priv->lock_position)
63- return GDK_FILTER_CONTINUE;
64-
65- if (priv->overlay.height > priv->slider.height)
66- {
67- gint x, y, x_pos, y_pos;
68-
69- gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos);
70-
71- x = priv->thumb_all.x;
72- y = CLAMP (xiev->event_y - priv->slider.height / 2,
73- priv->thumb_all.y + priv->overlay.y,
74- priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height);
75-
76- move_thumb (scrollbar, x_pos + x, y_pos + y);
77- }
78- else
79- {
80- move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y);
81- }
82-
83- gtk_widget_show (priv->thumb);
84- }
85- }
86- else
87- {
88- if (check_proximity (scrollbar, xiev->event_x, xiev->event_y))
89- {
90- priv->can_hide = FALSE;
91-
92- if (priv->lock_position)
93- return GDK_FILTER_CONTINUE;
94-
95- if (priv->overlay.width > priv->slider.width)
96- {
97- gint x, y, x_pos, y_pos;
98-
99- gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos);
100-
101- x = CLAMP (xiev->event_x - priv->slider.width / 2,
102- priv->thumb_all.x + priv->overlay.x,
103- priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width);
104- y = priv->thumb_all.y;
105-
106- move_thumb (scrollbar, x_pos + x, y_pos + y);
107- }
108- else
109- {
110- move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y);
111- }
112-
113- gtk_widget_show (priv->thumb);
114- }
115- }
116- }
117-
118- /* after a scroll-event, without motion,
119- * pager becomes inactive because the timeout in
120- * leave-notify-event starts,
121- * this call checks the pointer after the scroll-event,
122- * since it enters the window,
123- * then sets the state accordingly. */
124-
125- /* FIXME(Cimi) code commented out until I find what and where is wrong. */
126+ os_xevent = OS_XEVENT_BUTTON_PRESS;
127+
128+ if (xiev->evtype == XI_ButtonRelease)
129+ {
130+ os_xevent = OS_XEVENT_BUTTON_RELEASE;
131+ event_x = xiev->event_x;
132+ event_y = xiev->event_y;
133+ }
134+
135+ if (xiev->evtype == XI_Leave)
136+ os_xevent = OS_XEVENT_LEAVE;
137+
138+ if (xiev->evtype == XI_Motion)
139+ {
140+ os_xevent = OS_XEVENT_MOTION;
141+ event_x = xiev->event_x;
142+ event_y = xiev->event_y;
143+ }
144+ }
145+ else
146+ {
147+ /* Deal with X core events, when apps (like rhythmbox),
148+ * are using gdk_disable_miltidevice () */
149+ if (xev->type == ButtonPress)
150+ os_xevent = OS_XEVENT_BUTTON_PRESS;
151+
152+ if (xev->type == ButtonRelease)
153+ {
154+ os_xevent = OS_XEVENT_BUTTON_RELEASE;
155+ event_x = xev->xbutton.x;
156+ event_y = xev->xbutton.y;
157+ }
158+
159+ if (xev->type == LeaveNotify)
160+ os_xevent = OS_XEVENT_LEAVE;
161+
162+ if (xev->type == MotionNotify)
163+ {
164+ os_xevent = OS_XEVENT_MOTION;
165+ event_x = xev->xmotion.x;
166+ event_y = xev->xmotion.y;
167+ }
168+ }
169+
170+ if (os_xevent == OS_XEVENT_BUTTON_PRESS)
171+ {
172+ priv->toplevel_button_press = TRUE;
173+ gtk_widget_hide (priv->thumb);
174+ }
175+
176+ if (priv->toplevel_button_press && os_xevent == OS_XEVENT_BUTTON_RELEASE)
177+ {
178+ priv->toplevel_button_press = FALSE;
179+
180+ /* proximity area */
181+ if (priv->orientation == GTK_ORIENTATION_VERTICAL)
182+ {
183+ if (check_proximity (scrollbar, event_x, event_y))
184+ {
185+ priv->can_hide = FALSE;
186+
187+ if (priv->lock_position)
188+ return GDK_FILTER_CONTINUE;
189+
190+ if (priv->overlay.height > priv->slider.height)
191+ {
192+ gint x, y, x_pos, y_pos;
193+
194+ gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos);
195+
196+ x = priv->thumb_all.x;
197+ y = CLAMP (event_y - priv->slider.height / 2,
198+ priv->thumb_all.y + priv->overlay.y,
199+ priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height);
200+
201+ move_thumb (scrollbar, x_pos + x, y_pos + y);
202+ }
203+ else
204+ {
205+ move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y);
206+ }
207+
208+ gtk_widget_show (priv->thumb);
209+ }
210+ }
211+ else
212+ {
213+ if (check_proximity (scrollbar, event_x, event_y))
214+ {
215+ priv->can_hide = FALSE;
216+
217+ if (priv->lock_position)
218+ return GDK_FILTER_CONTINUE;
219+
220+ if (priv->overlay.width > priv->slider.width)
221+ {
222+ gint x, y, x_pos, y_pos;
223+
224+ gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos);
225+
226+ x = CLAMP (event_x - priv->slider.width / 2,
227+ priv->thumb_all.x + priv->overlay.x,
228+ priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width);
229+ y = priv->thumb_all.y;
230+
231+ move_thumb (scrollbar, x_pos + x, y_pos + y);
232+ }
233+ else
234+ {
235+ move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y);
236+ }
237+
238+ gtk_widget_show (priv->thumb);
239+ }
240+ }
241+ }
242+
243+ /* after a scroll-event, without motion,
244+ * pager becomes inactive because the timeout in
245+ * leave-notify-event starts,
246+ * this call checks the pointer after the scroll-event,
247+ * since it enters the window,
248+ * then sets the state accordingly. */
249+
250+ /* FIXME(Cimi) code commented out until I find what and where is wrong. */
251 // if (!priv->active_window && xiev->evtype == XI_Enter)
252 // {
253 // XIEnterEvent *xiee = xev->xcookie.data;
254@@ -2106,147 +2166,146 @@
255 // pager_set_state_from_pointer (scrollbar, xiee->event_x, xiee->event_y);
256 // }
257
258- if (xiev->evtype == XI_Leave)
259- {
260- /* never deactivate the pager in an active window. */
261- if (!priv->active_window)
262- {
263- priv->can_deactivate_pager = TRUE;
264-
265- if (priv->source_deactivate_pager_id != 0)
266- g_source_remove (priv->source_deactivate_pager_id);
267-
268- priv->source_deactivate_pager_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
269- deactivate_pager_cb,
270- scrollbar);
271- }
272-
273- priv->toplevel_button_press = FALSE;
274- priv->can_hide = TRUE;
275-
276- if (priv->source_hide_thumb_id != 0)
277- g_source_remove (priv->source_hide_thumb_id);
278-
279- priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
280- hide_thumb_cb,
281+ if (os_xevent == OS_XEVENT_LEAVE)
282+ {
283+ /* never deactivate the pager in an active window. */
284+ if (!priv->active_window)
285+ {
286+ priv->can_deactivate_pager = TRUE;
287+
288+ if (priv->source_deactivate_pager_id != 0)
289+ g_source_remove (priv->source_deactivate_pager_id);
290+
291+ priv->source_deactivate_pager_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
292+ deactivate_pager_cb,
293+ scrollbar);
294+ }
295+
296+ priv->toplevel_button_press = FALSE;
297+ priv->can_hide = TRUE;
298+
299+ if (priv->source_hide_thumb_id != 0)
300+ g_source_remove (priv->source_hide_thumb_id);
301+
302+ priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
303+ hide_thumb_cb,
304+ scrollbar);
305+
306+ if (priv->source_unlock_thumb_id != 0)
307+ g_source_remove (priv->source_unlock_thumb_id);
308+
309+ priv->source_unlock_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
310+ unlock_thumb_cb,
311 scrollbar);
312-
313- if (priv->source_unlock_thumb_id != 0)
314- g_source_remove (priv->source_unlock_thumb_id);
315-
316- priv->source_unlock_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
317- unlock_thumb_cb,
318- scrollbar);
319- }
320-
321- /* get the motion_notify_event trough XEvent */
322- if (!priv->toplevel_button_press && xiev->evtype == XI_Motion)
323- {
324- /* react to motion_notify_event
325- * and set the state accordingly. */
326- if (!is_insensitive (scrollbar) && !priv->active_window)
327- pager_set_state_from_pointer (scrollbar, xiev->event_x, xiev->event_y);
328-
329- /* proximity area */
330- if (priv->orientation == GTK_ORIENTATION_VERTICAL)
331- {
332- if (check_proximity (scrollbar, xiev->event_x, xiev->event_y))
333- {
334- priv->can_hide = FALSE;
335-
336- if (priv->source_hide_thumb_id != 0)
337- {
338- g_source_remove (priv->source_hide_thumb_id);
339- priv->source_hide_thumb_id = 0;
340- }
341-
342- if (priv->lock_position)
343- return GDK_FILTER_CONTINUE;
344-
345- if (priv->overlay.height > priv->slider.height)
346- {
347- gint x, y, x_pos, y_pos;
348-
349- gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos);
350-
351- x = priv->thumb_all.x;
352- y = CLAMP (xiev->event_y - priv->slider.height / 2,
353- priv->thumb_all.y + priv->overlay.y,
354- priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height);
355-
356- move_thumb (scrollbar, x_pos + x, y_pos + y);
357- }
358- else
359- {
360- move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y);
361- }
362-
363- os_pager_set_detached (priv->pager, FALSE);
364- os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
365- gtk_widget_show (priv->thumb);
366- }
367- else
368- {
369- priv->can_hide = TRUE;
370- priv->lock_position = FALSE;
371-
372- if (gtk_widget_get_mapped (priv->thumb) &&
373- priv->source_hide_thumb_id == 0)
374- priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_PROXIMITY_HIDE,
375- hide_thumb_cb,
376- scrollbar);
377- }
378- }
379- else
380- {
381- if (check_proximity (scrollbar, xiev->event_x, xiev->event_y))
382- {
383- priv->can_hide = FALSE;
384-
385- if (priv->source_hide_thumb_id != 0)
386- {
387- g_source_remove (priv->source_hide_thumb_id);
388- priv->source_hide_thumb_id = 0;
389- }
390-
391- if (priv->lock_position)
392- return GDK_FILTER_CONTINUE;
393-
394- if (priv->overlay.width > priv->slider.width)
395- {
396- gint x, y, x_pos, y_pos;
397-
398- gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos);
399-
400- x = CLAMP (xiev->event_x - priv->slider.width / 2,
401- priv->thumb_all.x + priv->overlay.x,
402- priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width);
403- y = priv->thumb_all.y;
404-
405- move_thumb (scrollbar, x_pos + x, y_pos + y);
406- }
407- else
408- {
409- move_thumb (scrollbar, priv->win_x + priv->slider.x, priv->win_y);
410- }
411-
412- os_pager_set_detached (priv->pager, FALSE);
413- os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
414- gtk_widget_show (priv->thumb);
415- }
416- else
417- {
418- priv->can_hide = TRUE;
419- priv->lock_position = FALSE;
420-
421- if (gtk_widget_get_mapped (priv->thumb) &&
422- priv->source_hide_thumb_id == 0)
423- priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_PROXIMITY_HIDE,
424- hide_thumb_cb,
425- scrollbar);
426- }
427- }
428- }
429+ }
430+
431+ /* get the motion_notify_event trough XEvent */
432+ if (!priv->toplevel_button_press && os_xevent == OS_XEVENT_MOTION)
433+ {
434+ /* react to motion_notify_event
435+ * and set the state accordingly. */
436+ if (!is_insensitive (scrollbar) && !priv->active_window)
437+ pager_set_state_from_pointer (scrollbar, event_x, event_y);
438+
439+ /* proximity area */
440+ if (priv->orientation == GTK_ORIENTATION_VERTICAL)
441+ {
442+ if (check_proximity (scrollbar, event_x, event_y))
443+ {
444+ priv->can_hide = FALSE;
445+
446+ if (priv->source_hide_thumb_id != 0)
447+ {
448+ g_source_remove (priv->source_hide_thumb_id);
449+ priv->source_hide_thumb_id = 0;
450+ }
451+
452+ if (priv->lock_position)
453+ return GDK_FILTER_CONTINUE;
454+
455+ if (priv->overlay.height > priv->slider.height)
456+ {
457+ gint x, y, x_pos, y_pos;
458+
459+ gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos);
460+
461+ x = priv->thumb_all.x;
462+ y = CLAMP (event_y - priv->slider.height / 2,
463+ priv->thumb_all.y + priv->overlay.y,
464+ priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height);
465+
466+ move_thumb (scrollbar, x_pos + x, y_pos + y);
467+ }
468+ else
469+ {
470+ move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y);
471+ }
472+
473+ os_pager_set_detached (priv->pager, FALSE);
474+ os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
475+ gtk_widget_show (priv->thumb);
476+ }
477+ else
478+ {
479+ priv->can_hide = TRUE;
480+ priv->lock_position = FALSE;
481+
482+ if (gtk_widget_get_mapped (priv->thumb) &&
483+ priv->source_hide_thumb_id == 0)
484+ priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_PROXIMITY_HIDE,
485+ hide_thumb_cb,
486+ scrollbar);
487+ }
488+ }
489+ else
490+ {
491+ if (check_proximity (scrollbar, event_x, event_y))
492+ {
493+ priv->can_hide = FALSE;
494+
495+ if (priv->source_hide_thumb_id != 0)
496+ {
497+ g_source_remove (priv->source_hide_thumb_id);
498+ priv->source_hide_thumb_id = 0;
499+ }
500+
501+ if (priv->lock_position)
502+ return GDK_FILTER_CONTINUE;
503+
504+ if (priv->overlay.width > priv->slider.width)
505+ {
506+ gint x, y, x_pos, y_pos;
507+
508+ gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos);
509+
510+ x = CLAMP (event_x - priv->slider.width / 2,
511+ priv->thumb_all.x + priv->overlay.x,
512+ priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width);
513+ y = priv->thumb_all.y;
514+
515+ move_thumb (scrollbar, x_pos + x, y_pos + y);
516+ }
517+ else
518+ {
519+ move_thumb (scrollbar, priv->win_x + priv->slider.x, priv->win_y);
520+ }
521+
522+ os_pager_set_detached (priv->pager, FALSE);
523+ os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
524+ gtk_widget_show (priv->thumb);
525+ }
526+ else
527+ {
528+ priv->can_hide = TRUE;
529+ priv->lock_position = FALSE;
530+
531+ if (gtk_widget_get_mapped (priv->thumb) &&
532+ priv->source_hide_thumb_id == 0)
533+ priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_PROXIMITY_HIDE,
534+ hide_thumb_cb,
535+ scrollbar);
536+ }
537+ }
538 }
539 }
540

Subscribers

People subscribed via source and target branches