Merge lp:~cimi/overlay-scrollbar/new-locked-mode into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 319
Merged at revision: 317
Proposed branch: lp:~cimi/overlay-scrollbar/new-locked-mode
Merge into: lp:overlay-scrollbar
Diff against target: 280 lines (+40/-160)
1 file modified
os/os-scrollbar.c (+40/-160)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/new-locked-mode
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+83960@code.launchpad.net

Description of the change

New logic for locked mode. Lock mode is when the thumb is internal (touching the screen or a strut), now it is unlocked when you exit the thumb horizontally or in particular proximity areas

To post a comment you must log in.
319. By Andrea Cimitan

Cosmetic change

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-10-20 23:06:36 +0000
3+++ os/os-scrollbar.c 2011-11-30 16:34:25 +0000
4@@ -1624,6 +1624,15 @@
5 scrollbar = OS_SCROLLBAR (user_data);
6 priv = scrollbar->priv;
7
8+ /* When exiting the thumb horizontally (or vertically),
9+ * in LOCKED state, remove the lock. */
10+ if ((priv->state & OS_STATE_LOCKED) &&
11+ ((priv->side == OS_SIDE_RIGHT && event->x < 0) ||
12+ (priv->side == OS_SIDE_BOTTOM && event->y < 0) ||
13+ (priv->side == OS_SIDE_LEFT && event->x - priv->thumb_all.width >= 0) ||
14+ (priv->side == OS_SIDE_TOP && event->y - priv->thumb_all.height >= 0)))
15+ priv->state &= ~(OS_STATE_LOCKED);
16+
17 /* Add the timeouts only if you are
18 * not interacting with the thumb. */
19 if (!(priv->event & OS_EVENT_BUTTON_PRESS))
20@@ -2160,6 +2169,26 @@
21
22 gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos);
23
24+ if (priv->state & OS_STATE_LOCKED)
25+ {
26+ gint x_pos_t, y_pos_t;
27+
28+ gdk_window_get_origin (gtk_widget_get_window (priv->thumb), &x_pos_t, &y_pos_t);
29+
30+ /* If the pointer is moving in the area of the proximity
31+ * at the left of the thumb (so, not vertically intercepting the thumb),
32+ * unlock it. Viceversa for the horizontal orientation.
33+ * The flag OS_STATE_LOCKED is set only for a mapped thumb,
34+ * so we can freely ask for its position and do our calculations. */
35+ if ((priv->side == OS_SIDE_RIGHT && x_pos + event_x <= x_pos_t) ||
36+ (priv->side == OS_SIDE_BOTTOM && y_pos + event_y <= y_pos_t) ||
37+ (priv->side == OS_SIDE_LEFT && x_pos + event_x >= x_pos_t + priv->thumb_all.width) ||
38+ (priv->side == OS_SIDE_TOP && y_pos + event_y >= y_pos_t + priv->thumb_all.height))
39+ priv->state &= ~(OS_STATE_LOCKED);
40+ else
41+ return;
42+ }
43+
44 /* Calculate priv->thumb_win.x and priv->thumb_win.y
45 * (thumb window allocation in root coordinates).
46 * I guess it's faster to store these values,
47@@ -2382,7 +2411,6 @@
48 }
49
50 /* Filter function applied to the toplevel window. */
51-#ifdef USE_GTK3
52 typedef enum
53 {
54 OS_XEVENT_NONE,
55@@ -2421,6 +2449,7 @@
56 event_x = 0;
57 event_y = 0;
58
59+#ifdef USE_GTK3
60 if (xev->type == GenericEvent)
61 {
62 /* Deal with XInput 2 events. */
63@@ -2450,6 +2479,7 @@
64 }
65 else
66 {
67+#endif
68 /* Deal with X core events, when apps (like rhythmbox),
69 * are using gdk_disable_miltidevice (). */
70 if (xev->type == ButtonPress)
71@@ -2471,7 +2501,9 @@
72 event_x = xev->xmotion.x;
73 event_y = xev->xmotion.y;
74 }
75+#ifdef USE_GTK3
76 }
77+#endif
78
79 if (os_xevent == OS_XEVENT_BUTTON_PRESS)
80 {
81@@ -2495,14 +2527,12 @@
82 {
83 priv->hidable_thumb = FALSE;
84
85+ adjust_thumb_position (scrollbar, event_x, event_y);
86+
87 if (priv->state & OS_STATE_LOCKED)
88 return GDK_FILTER_CONTINUE;
89
90- adjust_thumb_position (scrollbar, event_x, event_y);
91-
92- gtk_widget_show (priv->thumb);
93-
94- update_tail (scrollbar);
95+ show_thumb (scrollbar);
96 }
97 }
98
99@@ -2569,11 +2599,11 @@
100 priv->source_hide_thumb_id = 0;
101 }
102
103+ adjust_thumb_position (scrollbar, event_x, event_y);
104+
105 if (priv->state & OS_STATE_LOCKED)
106 return GDK_FILTER_CONTINUE;
107
108- adjust_thumb_position (scrollbar, event_x, event_y);
109-
110 show_thumb (scrollbar);
111 }
112 else
113@@ -2602,158 +2632,6 @@
114
115 return GDK_FILTER_CONTINUE;
116 }
117-#else
118-static GdkFilterReturn
119-window_filter_func (GdkXEvent *gdkxevent,
120- GdkEvent *event,
121- gpointer user_data)
122-{
123- OsScrollbar *scrollbar;
124- OsScrollbarPrivate *priv;
125- XEvent *xev;
126-
127- g_return_val_if_fail (OS_IS_SCROLLBAR (user_data), GDK_FILTER_CONTINUE);
128-
129- scrollbar = OS_SCROLLBAR (user_data);
130- priv = scrollbar->priv;
131-
132- xev = gdkxevent;
133-
134- g_return_val_if_fail (OS_IS_BAR (priv->bar), GDK_FILTER_CONTINUE);
135- g_return_val_if_fail (OS_IS_THUMB (priv->thumb), GDK_FILTER_CONTINUE);
136-
137- if (!(priv->state & OS_STATE_FULLSIZE))
138- {
139- if (xev->type == ButtonPress)
140- {
141- priv->window_button_press = TRUE;
142-
143- if (priv->source_show_thumb_id != 0)
144- {
145- g_source_remove (priv->source_show_thumb_id);
146- priv->source_show_thumb_id = 0;
147- }
148-
149- gtk_widget_hide (priv->thumb);
150- }
151-
152- if (priv->window_button_press && xev->type == ButtonRelease)
153- {
154- priv->window_button_press = FALSE;
155-
156- /* Proximity area. */
157- if (check_proximity (scrollbar, xev->xbutton.x, xev->xbutton.y))
158- {
159- priv->hidable_thumb = FALSE;
160-
161- if (priv->state & OS_STATE_LOCKED)
162- return GDK_FILTER_CONTINUE;
163-
164- adjust_thumb_position (scrollbar, xev->xbutton.x, xev->xbutton.y);
165-
166- gtk_widget_show (priv->thumb);
167-
168- update_tail (scrollbar);
169- }
170- }
171-
172- if (xev->type == LeaveNotify)
173- {
174- priv->window_button_press = FALSE;
175-
176- /* Never deactivate the bar in an active window. */
177- if (!priv->active_window)
178- {
179- priv->deactivable_bar = TRUE;
180-
181- if (priv->source_deactivate_bar_id != 0)
182- g_source_remove (priv->source_deactivate_bar_id);
183-
184- priv->source_deactivate_bar_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
185- deactivate_bar_cb,
186- scrollbar);
187- }
188-
189- if (gtk_widget_get_mapped (priv->thumb) &&
190- !(priv->event & OS_EVENT_BUTTON_PRESS))
191- {
192- priv->hidable_thumb = TRUE;
193-
194- if (priv->source_hide_thumb_id != 0)
195- g_source_remove (priv->source_hide_thumb_id);
196-
197- priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
198- hide_thumb_cb,
199- scrollbar);
200- }
201-
202- if (priv->source_show_thumb_id != 0)
203- {
204- g_source_remove (priv->source_show_thumb_id);
205- priv->source_show_thumb_id = 0;
206- }
207-
208- if (priv->source_unlock_thumb_id != 0)
209- g_source_remove (priv->source_unlock_thumb_id);
210-
211- priv->source_unlock_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
212- unlock_thumb_cb,
213- scrollbar);
214- }
215-
216- /* Get the motion_notify_event trough XEvent. */
217- if (!priv->window_button_press && xev->type == MotionNotify)
218- {
219- /* React to motion_notify_event
220- * and set the state accordingly. */
221- if (!is_insensitive (scrollbar) && !priv->active_window)
222- bar_set_state_from_pointer (scrollbar, xev->xmotion.x, xev->xmotion.y);
223-
224- /* Proximity area. */
225- if (check_proximity (scrollbar, xev->xmotion.x, xev->xmotion.y))
226- {
227- priv->hidable_thumb = FALSE;
228-
229- if (priv->source_hide_thumb_id != 0)
230- {
231- g_source_remove (priv->source_hide_thumb_id);
232- priv->source_hide_thumb_id = 0;
233- }
234-
235- if (priv->state & OS_STATE_LOCKED)
236- return GDK_FILTER_CONTINUE;
237-
238- adjust_thumb_position (scrollbar, xev->xmotion.x, xev->xmotion.y);
239-
240- show_thumb (scrollbar);
241- }
242- else
243- {
244- priv->state &= ~(OS_STATE_LOCKED);
245-
246- if (priv->source_show_thumb_id != 0)
247- {
248- g_source_remove (priv->source_show_thumb_id);
249- priv->source_show_thumb_id = 0;
250- }
251-
252- if (gtk_widget_get_mapped (priv->thumb) &&
253- !(priv->event & OS_EVENT_BUTTON_PRESS))
254- {
255- priv->hidable_thumb = TRUE;
256-
257- if (priv->source_hide_thumb_id == 0)
258- priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_PROXIMITY_HIDE,
259- hide_thumb_cb,
260- scrollbar);
261- }
262- }
263- }
264- }
265-
266- return GDK_FILTER_CONTINUE;
267-}
268-#endif
269
270 /* Add the window filter function. */
271 static void
272@@ -3130,6 +3008,8 @@
273
274 gdk_window_set_events (gtk_widget_get_window (widget),
275 gdk_window_get_events (gtk_widget_get_window (widget)) |
276+ GDK_BUTTON_PRESS_MASK |
277+ GDK_BUTTON_RELEASE_MASK |
278 GDK_POINTER_MOTION_MASK);
279
280 if (priv->filter.proximity)

Subscribers

People subscribed via source and target branches