Merge lp:~cimi/overlay-scrollbar/g-source-remove-for-timeout into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Merged at revision: 195
Proposed branch: lp:~cimi/overlay-scrollbar/g-source-remove-for-timeout
Merge into: lp:overlay-scrollbar
Diff against target: 278 lines (+122/-22)
1 file modified
os/os-scrollbar.c (+122/-22)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/g-source-remove-for-timeout
Reviewer Review Type Date Requested Status
Loïc Molinari (community) Approve
Kalle Valo (community) Approve
Review via email: mp+56370@code.launchpad.net

Description of the change

As the bugreport... seems cleaner and safer

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

Looks good to me.

review: Approve
195. By Andrea Cimitan

Don't set source_ids to 0 if I'm later assigning them the value returned from g_timeout_add

Revision history for this message
Kalle Valo (kvalo) wrote :

Update makes sense.

review: Approve
Revision history for this message
Loïc Molinari (loic.molinari) :
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-04-04 21:29:28 +0000
3+++ os/os-scrollbar.c 2011-04-05 15:24:51 +0000
4@@ -55,17 +55,22 @@
5 gboolean enter_notify_event;
6 gboolean motion_notify_event;
7 gboolean value_changed_event;
8+ gboolean can_deactivate_pager;
9+ gboolean can_hide;
10+ gboolean filter;
11 gboolean fullsize;
12+ gboolean internal;
13+ gboolean lock_position;
14 gboolean proximity;
15- gboolean filter;
16- gboolean can_deactivate_pager;
17- gboolean can_hide;
18 gint win_x;
19 gint win_y;
20 gint slide_initial_slider_position;
21 gint slide_initial_coordinate;
22 gint pointer_x;
23 gint pointer_y;
24+ guint32 source_deactivate_pager_id;
25+ guint32 source_hide_thumb_id;
26+ guint32 source_unlock_thumb_id;
27 };
28
29 static gboolean os_scrollbar_expose_event (GtkWidget *widget, GdkEventExpose *event);
30@@ -86,6 +91,7 @@
31 static gboolean os_scrollbar_deactivate_pager_cb (gpointer user_data);
32 static void os_scrollbar_hide_thumb (OsScrollbar *scrollbar);
33 static gboolean os_scrollbar_hide_thumb_cb (gpointer user_data);
34+static gboolean os_scrollbar_unlock_thumb_cb (gpointer user_data);
35 static void os_scrollbar_move (OsScrollbar *scrollbar, gint mouse_x, gint mouse_y);
36 static void os_scrollbar_move_thumb (OsScrollbar *scrollbar, gint x, gint y);
37 static void os_scrollbar_notify_adjustment_cb (GObject *object, gpointer user_data);
38@@ -350,10 +356,14 @@
39 static gboolean
40 os_scrollbar_deactivate_pager_cb (gpointer user_data)
41 {
42- OsScrollbar *scrollbar = OS_SCROLLBAR (user_data);
43+ OsScrollbar *scrollbar;
44+ OsScrollbarPrivate *priv;
45+
46+ scrollbar = OS_SCROLLBAR (user_data);
47+ priv = scrollbar->priv;
48
49 os_scrollbar_deactivate_pager (scrollbar);
50- g_object_unref (scrollbar);
51+ priv->source_deactivate_pager_id = 0;
52
53 return FALSE;
54 }
55@@ -376,10 +386,31 @@
56 static gboolean
57 os_scrollbar_hide_thumb_cb (gpointer user_data)
58 {
59- OsScrollbar *scrollbar = OS_SCROLLBAR (user_data);
60+ OsScrollbar *scrollbar;
61+ OsScrollbarPrivate *priv;
62+
63+ scrollbar = OS_SCROLLBAR (user_data);
64+ priv = scrollbar->priv;
65
66 os_scrollbar_hide_thumb (scrollbar);
67- g_object_unref (scrollbar);
68+ priv->source_hide_thumb_id = 0;
69+
70+ return FALSE;
71+}
72+
73+static gboolean
74+os_scrollbar_unlock_thumb_cb (gpointer user_data)
75+{
76+ OsScrollbar *scrollbar;
77+ OsScrollbarPrivate *priv;
78+
79+ scrollbar = OS_SCROLLBAR (user_data);
80+ priv = scrollbar->priv;
81+
82+ if (priv->can_hide)
83+ priv->lock_position = FALSE;
84+
85+ priv->source_unlock_thumb_id = 0;
86
87 return FALSE;
88 }
89@@ -473,7 +504,13 @@
90 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
91 (n_monitor != gdk_screen_get_monitor_at_point (screen, x - 1 + priv->slider.width, y) ||
92 (x - 1 + priv->slider.width) >= screen_width))
93- return x - DEFAULT_PAGER_WIDTH - priv->slider.width;
94+ {
95+ priv->internal = TRUE;
96+ return x - DEFAULT_PAGER_WIDTH - priv->slider.width;
97+ }
98+
99+ if (priv->orientation == GTK_ORIENTATION_VERTICAL)
100+ priv->internal = FALSE;
101
102 return x;
103 }
104@@ -501,7 +538,13 @@
105 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
106 (n_monitor != gdk_screen_get_monitor_at_point (screen, x, y - 1 + priv->slider.height) ||
107 (y - 1 + priv->slider.height) >= screen_height))
108- return y - DEFAULT_PAGER_WIDTH - priv->slider.height;
109+ {
110+ priv->internal = TRUE;
111+ return y - DEFAULT_PAGER_WIDTH - priv->slider.height;
112+ }
113+
114+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
115+ priv->internal = FALSE;
116
117 return y;
118 }
119@@ -715,6 +758,9 @@
120 priv->can_deactivate_pager = FALSE;
121 priv->can_hide = FALSE;
122
123+ if (priv->internal)
124+ priv->lock_position = TRUE;
125+
126 return FALSE;
127 }
128
129@@ -735,10 +781,19 @@
130 priv->can_hide = TRUE;
131 }
132
133- g_timeout_add (TIMEOUT_THUMB_HIDE, os_scrollbar_deactivate_pager_cb,
134- g_object_ref (scrollbar));
135- g_timeout_add (TIMEOUT_THUMB_HIDE, os_scrollbar_hide_thumb_cb,
136- g_object_ref (scrollbar));
137+ if (priv->source_deactivate_pager_id != 0)
138+ g_source_remove (priv->source_deactivate_pager_id);
139+
140+ priv->source_deactivate_pager_id = g_timeout_add (TIMEOUT_THUMB_HIDE,
141+ os_scrollbar_deactivate_pager_cb,
142+ scrollbar);
143+
144+ if (priv->source_hide_thumb_id != 0)
145+ g_source_remove (priv->source_hide_thumb_id);
146+
147+ priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_THUMB_HIDE,
148+ os_scrollbar_hide_thumb_cb,
149+ scrollbar);
150
151 return FALSE;
152 }
153@@ -1057,6 +1112,8 @@
154 if (!priv->enter_notify_event)
155 gtk_widget_hide (GTK_WIDGET (priv->thumb));
156
157+ priv->lock_position = FALSE;
158+
159 os_scrollbar_calc_layout_pager (scrollbar, priv->adjustment->value);
160 os_scrollbar_calc_layout_slider (scrollbar, priv->adjustment->value);
161
162@@ -1102,6 +1159,9 @@
163 {
164 priv->can_hide = FALSE;
165
166+ if (priv->lock_position)
167+ return GDK_FILTER_CONTINUE;
168+
169 if (priv->overlay.height > priv->slider.height)
170 {
171 gint x, y, x_pos, y_pos;
172@@ -1125,6 +1185,7 @@
173 else
174 {
175 priv->can_hide = TRUE;
176+ priv->lock_position = FALSE;
177 os_scrollbar_hide_thumb (scrollbar);
178 }
179 }
180@@ -1137,6 +1198,9 @@
181 {
182 priv->can_hide = FALSE;
183
184+ if (priv->lock_position)
185+ return GDK_FILTER_CONTINUE;
186+
187 if (priv->overlay.width > priv->slider.width)
188 {
189 gint x, y, x_pos, y_pos;
190@@ -1160,15 +1224,12 @@
191 else
192 {
193 priv->can_hide = TRUE;
194+ priv->lock_position = FALSE;
195 os_scrollbar_hide_thumb (scrollbar);
196 }
197 }
198 }
199 }
200- else
201- {
202- return GDK_FILTER_CONTINUE;
203- }
204
205 return GDK_FILTER_CONTINUE;
206 }
207@@ -1188,10 +1249,26 @@
208 priv->can_deactivate_pager = TRUE;
209 priv->can_hide = TRUE;
210
211- g_timeout_add (TIMEOUT_TOPLEVEL_HIDE, os_scrollbar_deactivate_pager_cb,
212- g_object_ref (scrollbar));
213- g_timeout_add (TIMEOUT_TOPLEVEL_HIDE, os_scrollbar_hide_thumb_cb,
214- g_object_ref (scrollbar));
215+ if (priv->source_deactivate_pager_id != 0)
216+ g_source_remove (priv->source_deactivate_pager_id);
217+
218+ priv->source_deactivate_pager_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
219+ os_scrollbar_deactivate_pager_cb,
220+ scrollbar);
221+
222+ if (priv->source_hide_thumb_id != 0)
223+ g_source_remove (priv->source_hide_thumb_id);
224+
225+ priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
226+ os_scrollbar_hide_thumb_cb,
227+ scrollbar);
228+
229+ if (priv->source_unlock_thumb_id != 0)
230+ g_source_remove (priv->source_unlock_thumb_id);
231+
232+ priv->source_unlock_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
233+ os_scrollbar_unlock_thumb_cb,
234+ scrollbar);
235
236 return FALSE;
237 }
238@@ -1237,9 +1314,14 @@
239
240 priv->can_deactivate_pager = TRUE;
241 priv->can_hide = TRUE;
242+ priv->filter = FALSE;
243 priv->fullsize = FALSE;
244+ priv->internal = FALSE;
245+ priv->lock_position = FALSE;
246 priv->proximity = FALSE;
247- priv->filter = FALSE;
248+ priv->source_deactivate_pager_id = 0;
249+ priv->source_hide_thumb_id = 0;
250+ priv->source_unlock_thumb_id = 0;
251
252 priv->pager = os_pager_new ();
253
254@@ -1259,6 +1341,24 @@
255 scrollbar = OS_SCROLLBAR (object);
256 priv = scrollbar->priv;
257
258+ if (priv->source_deactivate_pager_id != 0)
259+ {
260+ g_source_remove (priv->source_deactivate_pager_id);
261+ priv->source_deactivate_pager_id = 0;
262+ }
263+
264+ if (priv->source_hide_thumb_id != 0)
265+ {
266+ g_source_remove (priv->source_hide_thumb_id);
267+ priv->source_hide_thumb_id = 0;
268+ }
269+
270+ if (priv->source_unlock_thumb_id != 0)
271+ {
272+ g_source_remove (priv->source_unlock_thumb_id);
273+ priv->source_unlock_thumb_id = 0;
274+ }
275+
276 if (priv->pager != NULL)
277 {
278 g_object_unref (priv->pager);

Subscribers

People subscribed via source and target branches