Merge lp:~ayatana-scrollbar-team/overlay-scrollbar/use-backdrop-state-flag-instead-root-filter into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 346
Merged at revision: 346
Proposed branch: lp:~ayatana-scrollbar-team/overlay-scrollbar/use-backdrop-state-flag-instead-root-filter
Merge into: lp:overlay-scrollbar
Diff against target: 386 lines (+117/-87)
1 file modified
os/os-scrollbar.c (+117/-87)
To merge this branch: bzr merge lp:~ayatana-scrollbar-team/overlay-scrollbar/use-backdrop-state-flag-instead-root-filter
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+104789@code.launchpad.net

Description of the change

Try removing code not needed with latest gtk3

To post a comment you must log in.
Revision history for this message
Andrea Cimitan (cimi) wrote :

I know the #ifdef are ugly, but gtk+2 doesn't have backdrop state flag...

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 2012-04-27 13:49:56 +0000
3+++ os/os-scrollbar.c 2012-05-04 18:27:26 +0000
4@@ -125,7 +125,9 @@
5 OsWindowFilter filter;
6 gboolean active_window;
7 gboolean allow_resize;
8+#ifdef USE_GTK3
9 gboolean deactivable_bar;
10+#endif
11 gboolean hidable_thumb;
12 gboolean window_button_press; /* FIXME(Cimi) to replace with X11 input events. */
13 gdouble value;
14@@ -573,6 +575,7 @@
15 return value;
16 }
17
18+#ifdef USE_GTK3
19 /* Deactivate the bar if it's the case. */
20 static void
21 deactivate_bar (GtkScrollbar *scrollbar)
22@@ -602,6 +605,7 @@
23
24 return FALSE;
25 }
26+#endif
27
28 /* Get the private struct. */
29 static OsScrollbarPrivate*
30@@ -647,7 +651,9 @@
31
32 /* Initialize struct variables. */
33 qdata->side = OS_SIDE_RIGHT;
34+#ifdef USE_GTK3
35 qdata->deactivable_bar = TRUE;
36+#endif
37 qdata->hidable_thumb = TRUE;
38 qdata->fine_scroll_multiplier = 1.0;
39 qdata->bar = os_bar_new ();
40@@ -1480,6 +1486,7 @@
41 move_bar (scrollbar);
42 }
43
44+#ifdef USE_GTK3
45 /* Bar functions. */
46
47 /* Set the state of the bar checking mouse position. */
48@@ -1509,89 +1516,10 @@
49 os_bar_set_active (priv->bar, FALSE, TRUE);
50 }
51 }
52+#endif
53
54 /* Root window functions. */
55
56-/* React on active window changes. */
57-static void
58-root_gfunc (gpointer data,
59- gpointer user_data)
60-{
61- GtkScrollbar *scrollbar;
62- OsScrollbarPrivate *priv;
63-
64- scrollbar = GTK_SCROLLBAR (data);
65- priv = get_private (GTK_WIDGET (scrollbar));
66-
67- OS_DCHECK (scrollbar != NULL);
68-
69- /* Return if the scrollbar is insensitive. */
70- if (is_insensitive (scrollbar))
71- return;
72-
73- if (gtk_widget_get_mapped (GTK_WIDGET (scrollbar)))
74- {
75- if (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar))) ==
76- gdk_screen_get_active_window (gtk_widget_get_screen (GTK_WIDGET (scrollbar))))
77- {
78- /* Stops potential running timeout. */
79- if (priv->source_deactivate_bar_id != 0)
80- {
81- g_source_remove (priv->source_deactivate_bar_id);
82- priv->source_deactivate_bar_id = 0;
83- }
84-
85- priv->active_window = TRUE;
86-
87- priv->deactivable_bar = FALSE;
88- os_bar_set_active (priv->bar, TRUE, TRUE);
89- }
90- else if (priv->active_window)
91- {
92- GdkWindow *parent;
93- GdkWindow *window;
94- const gint64 current_time = g_get_monotonic_time ();
95- const gint64 end_time = priv->present_time + TIMEOUT_PRESENT_WINDOW * 1000;
96-
97- priv->active_window = FALSE;
98-
99- /* Loop through parent windows until it reaches
100- * either an unknown GdkWindow (NULL),
101- * or the toplevel window. */
102- window = gtk_widget_get_window (GTK_WIDGET (scrollbar));
103- parent = window_at_pointer (window, NULL, NULL);
104- while (parent != NULL)
105- {
106- if (window == parent)
107- break;
108-
109- parent = gdk_window_get_parent (parent);
110- }
111-
112- if (parent != NULL)
113- {
114- gint x, y;
115-
116- window_get_pointer (window, &x, &y, NULL);
117-
118- /* When the window is unfocused,
119- * check the position of the pointer
120- * and set the state accordingly. */
121- bar_set_state_from_pointer (scrollbar, x, y);
122- }
123- else
124- {
125- /* If the pointer is outside of the window, set it inactive. */
126- priv->deactivable_bar = TRUE;
127- os_bar_set_active (priv->bar, FALSE, TRUE);
128- }
129-
130- if ((current_time > end_time) && priv->thumb != NULL)
131- gtk_widget_hide (priv->thumb);
132- }
133- }
134-}
135-
136 /* Filter function applied to the root window. */
137 static GdkFilterReturn
138 root_filter_func (GdkXEvent *gdkxevent,
139@@ -1604,11 +1532,7 @@
140
141 if (xev->type == PropertyNotify)
142 {
143- if (xev->xproperty.atom == net_active_window_atom)
144- {
145- g_slist_foreach (os_root_list, root_gfunc, NULL);
146- }
147- else if (xev->xproperty.atom == unity_net_workarea_region_atom)
148+ if (xev->xproperty.atom == unity_net_workarea_region_atom)
149 {
150 calc_workarea (xev->xany.display, xev->xany.window);
151 }
152@@ -1914,7 +1838,9 @@
153
154 priv->event |= OS_EVENT_ENTER_NOTIFY;
155
156+#ifdef USE_GTK3
157 priv->deactivable_bar = FALSE;
158+#endif
159 priv->hidable_thumb = FALSE;
160
161 if (priv->state & OS_STATE_INTERNAL)
162@@ -1986,6 +1912,7 @@
163 * not interacting with the thumb. */
164 if (!(priv->event & OS_EVENT_BUTTON_PRESS))
165 {
166+#ifdef USE_GTK3
167 /* Never deactivate the bar in an active window. */
168 if (!priv->active_window)
169 {
170@@ -1998,6 +1925,7 @@
171 deactivate_bar_cb,
172 scrollbar);
173 }
174+#endif
175
176 priv->event &= ~(OS_EVENT_ENTER_NOTIFY);
177
178@@ -2029,9 +1957,11 @@
179 scrollbar = GTK_SCROLLBAR (user_data);
180 priv = get_private (GTK_WIDGET (scrollbar));
181
182+#ifdef USE_GTK3
183 /* Immediately set the bar to be active. */
184 priv->deactivable_bar = FALSE;
185 os_bar_set_active (priv->bar, TRUE, FALSE);
186+#endif
187
188 xid = GDK_WINDOW_XID (gtk_widget_get_window (widget));
189 xid_parent = GDK_WINDOW_XID (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar))));
190@@ -2566,6 +2496,7 @@
191 const gint64 current_time = g_get_monotonic_time ();
192 const gint64 end_time = priv->present_time + TIMEOUT_PRESENT_WINDOW * 1000;
193
194+#ifdef USE_GTK3
195 /* If the widget is mapped, is not insentitive
196 * and the configure-event happens after
197 * the PropertyNotify _NET_ACTIVE_WINDOW event,
198@@ -2609,6 +2540,7 @@
199 os_bar_set_active (priv->bar, TRUE, TRUE);
200 }
201 }
202+#endif
203
204 if (current_time > end_time)
205 gtk_widget_hide (priv->thumb);
206@@ -3027,6 +2959,7 @@
207 {
208 priv->window_button_press = FALSE;
209
210+#ifdef USE_GTK3
211 /* Never deactivate the bar in an active window. */
212 if (!priv->active_window)
213 {
214@@ -3039,6 +2972,7 @@
215 deactivate_bar_cb,
216 scrollbar);
217 }
218+#endif
219
220 if (gtk_widget_get_mapped (priv->thumb) &&
221 !(priv->event & OS_EVENT_BUTTON_PRESS))
222@@ -3070,10 +3004,12 @@
223 /* Get the motion_notify_event trough XEvent. */
224 if (!priv->window_button_press && os_xevent == OS_XEVENT_MOTION)
225 {
226+#ifdef USE_GTK3
227 /* React to motion_notify_event
228 * and set the state accordingly. */
229 if (!is_insensitive (scrollbar) && !priv->active_window)
230 bar_set_state_from_pointer (scrollbar, event_x, event_y);
231+#endif
232
233 /* Proximity area. */
234 if (check_proximity (scrollbar, event_x, event_y))
235@@ -3335,6 +3271,15 @@
236 (* pre_hijacked_scrollbar_hide) (widget);
237 }
238
239+#ifdef USE_GTK3
240+/* Return TRUE if the widget is in backdrop window. */
241+static gboolean
242+is_backdrop_window (GtkWidget *widget)
243+{
244+ return (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_BACKDROP) != 0;
245+}
246+#endif
247+
248 static void
249 hijacked_scrollbar_map (GtkWidget *widget)
250 {
251@@ -3348,9 +3293,9 @@
252
253 (* widget_class_map) (widget);
254
255+#ifdef USE_GTK3
256 /* On map, check for the active window. */
257- if (gtk_widget_get_window (gtk_widget_get_toplevel (widget)) ==
258- gdk_screen_get_active_window (gtk_widget_get_screen (widget)))
259+ if (!is_backdrop_window (GTK_WIDGET (scrollbar)))
260 {
261 /* Stops potential running timeout. */
262 if (priv->source_deactivate_bar_id != 0)
263@@ -3386,6 +3331,7 @@
264 os_bar_set_active (priv->bar, TRUE, FALSE);
265 }
266 }
267+#endif
268
269 if (!(priv->state & OS_STATE_FULLSIZE))
270 os_bar_show (priv->bar);
271@@ -3653,7 +3599,9 @@
272 priv->filter.proximity = FALSE;
273 remove_window_filter (scrollbar);
274
275+#ifdef USE_GTK3
276 os_bar_set_active (priv->bar, FALSE, FALSE);
277+#endif
278
279 gtk_widget_hide (priv->thumb);
280 }
281@@ -3675,6 +3623,7 @@
282 add_window_filter (scrollbar);
283 }
284
285+#ifdef USE_GTK3
286 if (priv->active_window)
287 os_bar_set_active (priv->bar, TRUE, FALSE);
288 else if (gtk_widget_get_realized (GTK_WIDGET (scrollbar)))
289@@ -3688,9 +3637,86 @@
290 * and set the state accordingly. */
291 bar_set_state_from_pointer (scrollbar, x, y);
292 }
293+#endif
294 }
295
296 #ifdef USE_GTK3
297+/* React on active window changes. */
298+static void
299+backdrop_state_flag_changed (GtkScrollbar *scrollbar)
300+{
301+ OsScrollbarPrivate *priv;
302+
303+ priv = get_private (GTK_WIDGET (scrollbar));
304+
305+ OS_DCHECK (scrollbar != NULL);
306+
307+ /* Return if the scrollbar is insensitive. */
308+ if (is_insensitive (scrollbar))
309+ return;
310+
311+ if (gtk_widget_get_mapped (GTK_WIDGET (scrollbar)))
312+ {
313+ if (!is_backdrop_window (GTK_WIDGET (scrollbar)))
314+ {
315+ /* Stops potential running timeout. */
316+ if (priv->source_deactivate_bar_id != 0)
317+ {
318+ g_source_remove (priv->source_deactivate_bar_id);
319+ priv->source_deactivate_bar_id = 0;
320+ }
321+
322+ priv->active_window = TRUE;
323+
324+ priv->deactivable_bar = FALSE;
325+ os_bar_set_active (priv->bar, TRUE, TRUE);
326+ }
327+ else if (priv->active_window)
328+ {
329+ GdkWindow *parent;
330+ GdkWindow *window;
331+ const gint64 current_time = g_get_monotonic_time ();
332+ const gint64 end_time = priv->present_time + TIMEOUT_PRESENT_WINDOW * 1000;
333+
334+ priv->active_window = FALSE;
335+
336+ /* Loop through parent windows until it reaches
337+ * either an unknown GdkWindow (NULL),
338+ * or the toplevel window. */
339+ window = gtk_widget_get_window (GTK_WIDGET (scrollbar));
340+ parent = window_at_pointer (window, NULL, NULL);
341+ while (parent != NULL)
342+ {
343+ if (window == parent)
344+ break;
345+
346+ parent = gdk_window_get_parent (parent);
347+ }
348+
349+ if (parent != NULL)
350+ {
351+ gint x, y;
352+
353+ window_get_pointer (window, &x, &y, NULL);
354+
355+ /* When the window is unfocused,
356+ * check the position of the pointer
357+ * and set the state accordingly. */
358+ bar_set_state_from_pointer (scrollbar, x, y);
359+ }
360+ else
361+ {
362+ /* If the pointer is outside of the window, set it inactive. */
363+ priv->deactivable_bar = TRUE;
364+ os_bar_set_active (priv->bar, FALSE, TRUE);
365+ }
366+
367+ if ((current_time > end_time) && priv->thumb != NULL)
368+ gtk_widget_hide (priv->thumb);
369+ }
370+ }
371+}
372+
373 static void
374 hijacked_scrollbar_state_flags_changed (GtkWidget *widget,
375 GtkStateFlags flags)
376@@ -3699,6 +3725,10 @@
377
378 scrollbar = GTK_SCROLLBAR (widget);
379
380+ if ((flags & GTK_STATE_FLAG_BACKDROP) !=
381+ (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_BACKDROP))
382+ backdrop_state_flag_changed (scrollbar);
383+
384 /* Only set the new state if the right bit changed. */
385 if ((flags & GTK_STATE_FLAG_INSENSITIVE) !=
386 (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_INSENSITIVE))

Subscribers

People subscribed via source and target branches