Merge lp:~cimi/overlay-scrollbar/use-enums into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 288
Merged at revision: 285
Proposed branch: lp:~cimi/overlay-scrollbar/use-enums
Merge into: lp:overlay-scrollbar
Prerequisite: lp:~cimi/overlay-scrollbar/fine-scroll
Diff against target: 303 lines (+48/-48)
3 files modified
os/os-private.h (+9/-0)
os/os-scrollbar.c (+22/-29)
os/os-thumb.c (+17/-19)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/use-enums
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+67205@code.launchpad.net

This proposal supersedes a proposal from 2011-07-07.

Description of the change

If you have ideas on namings or other sets of enums to create, just ping me in IRC and not marking as "NEED FIXING" :)
Or they could be handled in separated branches

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

I think that this patch is fine. I'm curious if the states can't be turned into a pure enum without the need to handle it like a bitmask. This is still putting it in the position of being in multiple states simultaneously, which is complex to read and debug.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'os/os-private.h'
2--- os/os-private.h 2011-07-07 15:14:15 +0000
3+++ os/os-private.h 2011-07-07 15:14:15 +0000
4@@ -36,6 +36,15 @@
5
6 G_BEGIN_DECLS
7
8+typedef enum
9+{
10+ OS_EVENT_NONE = 0,
11+ OS_EVENT_BUTTON_PRESS = 1,
12+ OS_EVENT_ENTER_NOTIFY = 2,
13+ OS_EVENT_MOTION_NOTIFY = 4,
14+ OS_EVENT_VALUE_CHANGED = 8
15+} OsEvent;
16+
17 /* os-log.c */
18
19 /* Severity levels. */
20
21=== modified file 'os/os-scrollbar.c'
22--- os/os-scrollbar.c 2011-07-07 15:14:15 +0000
23+++ os/os-scrollbar.c 2011-07-07 15:14:15 +0000
24@@ -91,10 +91,7 @@
25 OsAnimation *animation;
26 OsPager *pager;
27 OsSide side;
28- gboolean button_press_event;
29- gboolean enter_notify_event;
30- gboolean motion_notify_event;
31- gboolean value_changed_event;
32+ OsEvent event;
33 gboolean active_window;
34 gboolean can_deactivate_pager;
35 gboolean can_hide;
36@@ -918,7 +915,8 @@
37 calc_layout_pager (scrollbar, gtk_adjustment_get_value (adjustment));
38 calc_layout_slider (scrollbar, gtk_adjustment_get_value (adjustment));
39
40- if (!priv->motion_notify_event && !priv->enter_notify_event)
41+ if (!(priv->event & OS_EVENT_ENTER_NOTIFY) &&
42+ !(priv->event & OS_EVENT_MOTION_NOTIFY))
43 gtk_widget_hide (priv->thumb);
44
45 move_pager (scrollbar);
46@@ -1022,13 +1020,14 @@
47 calc_layout_pager (scrollbar, gtk_adjustment_get_value (adjustment));
48 calc_layout_slider (scrollbar, gtk_adjustment_get_value (adjustment));
49
50- if (!priv->motion_notify_event && !priv->enter_notify_event)
51+ if (!(priv->event & OS_EVENT_ENTER_NOTIFY) &&
52+ !(priv->event & OS_EVENT_MOTION_NOTIFY))
53 gtk_widget_hide (priv->thumb);
54
55 if (gtk_widget_get_mapped (priv->thumb))
56 {
57 /* if we're dragging the thumb, it can't be detached. */
58- if (priv->motion_notify_event)
59+ if (priv->event & OS_EVENT_MOTION_NOTIFY)
60 {
61 os_pager_set_detached (priv->pager, FALSE);
62 os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE);
63@@ -1251,11 +1250,11 @@
64 priv->present_time = g_get_monotonic_time ();
65 present_gdk_window_with_timestamp (GTK_WIDGET (scrollbar), event->time);
66
67+ priv->event |= OS_EVENT_BUTTON_PRESS;
68+ priv->event &= ~(OS_EVENT_MOTION_NOTIFY);
69+
70 priv->detached_scroll = FALSE;
71
72- priv->button_press_event = TRUE;
73- priv->motion_notify_event = FALSE;
74-
75 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
76 {
77 priv->slide_initial_slider_position = MIN (priv->slider.y, priv->overlay.y);
78@@ -1348,7 +1347,7 @@
79
80 gtk_window_set_transient_for (GTK_WINDOW (widget), NULL);
81
82- if (!priv->motion_notify_event && !priv->detached_scroll)
83+ if (!(priv->event & OS_EVENT_MOTION_NOTIFY) && !priv->detached_scroll)
84 {
85 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
86 {
87@@ -1365,11 +1364,10 @@
88 page_down (scrollbar);
89 }
90
91- priv->value_changed_event = TRUE;
92+ priv->event |= OS_EVENT_VALUE_CHANGED;
93 }
94
95- priv->button_press_event = FALSE;
96- priv->motion_notify_event = FALSE;
97+ priv->event &= ~(OS_EVENT_BUTTON_PRESS | OS_EVENT_MOTION_NOTIFY);
98 }
99 }
100
101@@ -1387,7 +1385,8 @@
102 scrollbar = OS_SCROLLBAR (user_data);
103 priv = scrollbar->priv;
104
105- priv->enter_notify_event = TRUE;
106+ priv->event |= OS_EVENT_ENTER_NOTIFY;
107+
108 priv->can_deactivate_pager = FALSE;
109 priv->can_hide = FALSE;
110
111@@ -1410,7 +1409,7 @@
112
113 /* add the timeouts only if you are
114 * not interacting with the thumb. */
115- if (!priv->button_press_event)
116+ if (!(priv->event & OS_EVENT_BUTTON_PRESS))
117 {
118 /* never deactivate the pager in an active window. */
119 if (!priv->active_window)
120@@ -1593,14 +1592,14 @@
121 scrollbar = OS_SCROLLBAR (user_data);
122 priv = scrollbar->priv;
123
124- if (priv->button_press_event)
125+ if (priv->event & OS_EVENT_BUTTON_PRESS)
126 {
127 gint x, y;
128
129 /* thumb and pager are detached.
130 * Detached scroll: keep the thumb detached during the scroll,
131 * update the visual connection when reaching an edge. */
132- if (priv->value_changed_event)
133+ if (priv->event & OS_EVENT_VALUE_CHANGED)
134 {
135 /* return if the mouse movement is small. */
136 if (abs (priv->pointer_x - event->x) <= TOLERANCE_PIXELS &&
137@@ -1715,7 +1714,7 @@
138 /* thumb and pager are connected.
139 * Normal scroll: keep the thumb in sync with the pager,
140 * do not update the visual connection. */
141- priv->motion_notify_event = TRUE;
142+ priv->event |= OS_EVENT_MOTION_NOTIFY;
143
144 capture_movement (scrollbar, event->x_root, event->y_root);
145
146@@ -1811,7 +1810,7 @@
147 scrollbar = OS_SCROLLBAR (user_data);
148 priv = scrollbar->priv;
149
150- priv->value_changed_event = TRUE;
151+ priv->event |= OS_EVENT_VALUE_CHANGED;
152
153 delta = get_wheel_delta (scrollbar, event->direction);
154
155@@ -1834,13 +1833,10 @@
156 scrollbar = OS_SCROLLBAR (user_data);
157 priv = scrollbar->priv;
158
159+ priv->event = OS_EVENT_NONE;
160+
161 priv->detached_scroll = FALSE;
162
163- priv->button_press_event = FALSE;
164- priv->motion_notify_event = FALSE;
165- priv->enter_notify_event = FALSE;
166- priv->value_changed_event = FALSE;
167-
168 os_pager_set_detached (priv->pager, FALSE);
169 }
170
171@@ -2571,10 +2567,7 @@
172 os_root_list = g_list_append (os_root_list, scrollbar);
173 }
174
175- priv->button_press_event = FALSE;
176- priv->enter_notify_event = FALSE;
177- priv->motion_notify_event = FALSE;
178- priv->value_changed_event = FALSE;
179+ priv->event = OS_EVENT_NONE;
180
181 priv->active_window = FALSE;
182 priv->can_deactivate_pager = TRUE;
183
184=== modified file 'os/os-thumb.c'
185--- os/os-thumb.c 2011-06-30 10:52:41 +0000
186+++ os/os-thumb.c 2011-07-07 15:14:15 +0000
187@@ -56,8 +56,7 @@
188 GtkOrientation orientation;
189 GtkWidget *grabbed_widget;
190 OsAnimation *animation;
191- gboolean button_press_event;
192- gboolean motion_notify_event;
193+ OsEvent event;
194 gboolean can_rgba;
195 gboolean detached;
196 gboolean use_tolerance;
197@@ -190,8 +189,7 @@
198 OsThumbPrivate);
199 priv = thumb->priv;
200
201- priv->button_press_event = FALSE;
202- priv->motion_notify_event = FALSE;
203+ priv->event = OS_EVENT_NONE;
204
205 priv->can_rgba = FALSE;
206 priv->detached = FALSE;
207@@ -245,8 +243,8 @@
208 priv->pointer_x = event->x;
209 priv->pointer_y = event->y;
210
211- priv->button_press_event = TRUE;
212- priv->motion_notify_event = FALSE;
213+ priv->event |= OS_EVENT_BUTTON_PRESS;
214+ priv->event &= ~(OS_EVENT_MOTION_NOTIFY);
215
216 priv->use_tolerance = TRUE;
217
218@@ -276,8 +274,7 @@
219 {
220 gtk_grab_remove (widget);
221
222- priv->button_press_event = FALSE;
223- priv->motion_notify_event = FALSE;
224+ priv->event &= ~(OS_EVENT_BUTTON_PRESS | OS_EVENT_MOTION_NOTIFY);
225
226 gtk_widget_queue_draw (widget);
227 }
228@@ -687,7 +684,8 @@
229 else
230 pat = cairo_pattern_create_linear (0, 0, width, 0);
231
232- if (priv->button_press_event && !priv->motion_notify_event)
233+ if ((priv->event & OS_EVENT_BUTTON_PRESS) &&
234+ !(priv->event & OS_EVENT_MOTION_NOTIFY))
235 {
236 if ((priv->orientation == GTK_ORIENTATION_VERTICAL && (priv->pointer_y < height / 2)) ||
237 (priv->orientation == GTK_ORIENTATION_HORIZONTAL && (priv->pointer_x < width / 2)))
238@@ -715,7 +713,7 @@
239 cairo_set_source (cr, pat);
240 cairo_pattern_destroy (pat);
241
242- if (priv->motion_notify_event)
243+ if (priv->event & OS_EVENT_MOTION_NOTIFY)
244 {
245 cairo_fill_preserve (cr);
246 set_source_gdk_rgba (cr, &bg_arrow_down, 0.3);
247@@ -837,8 +835,8 @@
248 /* If we exit the thumb when a button is pressed,
249 * there's no need to stop the animation, it should
250 * already be stopped.
251- * Stop it only if priv->button_press_event is FALSE. */
252- if (!priv->button_press_event)
253+ * Stop it only if OS_EVENT_BUTTON_PRESS is not set. */
254+ if (!(priv->event & OS_EVENT_BUTTON_PRESS))
255 {
256 if (priv->source_id != 0)
257 {
258@@ -901,9 +899,9 @@
259
260 /* If you're not dragging, and you're outside
261 * the tolerance pixels, enable the fade-out.
262- * priv->motion_notify_event is TRUE only on dragging,
263+ * OS_EVENT_MOTION_NOTIFY is set only on dragging,
264 * see code few lines below. */
265- if (!priv->motion_notify_event)
266+ if (!(priv->event & OS_EVENT_MOTION_NOTIFY))
267 {
268 if (!priv->use_tolerance ||
269 (abs (priv->pointer_x - event->x) > TOLERANCE_PIXELS ||
270@@ -916,12 +914,12 @@
271 }
272 }
273
274- if (priv->button_press_event)
275+ if (priv->event & OS_EVENT_BUTTON_PRESS)
276 {
277- if (!priv->motion_notify_event)
278+ if (!(priv->event & OS_EVENT_MOTION_NOTIFY))
279 gtk_widget_queue_draw (widget);
280
281- priv->motion_notify_event = TRUE;
282+ priv->event |= OS_EVENT_MOTION_NOTIFY;
283 }
284
285 return FALSE;
286@@ -988,8 +986,7 @@
287 thumb = OS_THUMB (widget);
288 priv = thumb->priv;
289
290- priv->button_press_event = FALSE;
291- priv->motion_notify_event = FALSE;
292+ priv->event = OS_EVENT_NONE;
293
294 priv->use_tolerance = FALSE;
295
296@@ -1155,6 +1152,7 @@
297 if (priv->detached != detached)
298 {
299 priv->detached = detached;
300+
301 gtk_widget_queue_draw (GTK_WIDGET (thumb));
302 }
303 }

Subscribers

People subscribed via source and target branches