Merge lp:~cimi/overlay-scrollbar/0.2-refactoring into lp:overlay-scrollbar
- 0.2-refactoring
- Merge into trunk
Proposed by
Andrea Cimitan
Status: | Merged |
---|---|
Approved by: | Ted Gould |
Approved revision: | 239 |
Merged at revision: | 238 |
Proposed branch: | lp:~cimi/overlay-scrollbar/0.2-refactoring |
Merge into: | lp:overlay-scrollbar |
Diff against target: |
2609 lines (+955/-960) 4 files modified
os/os-animation.c (+33/-37) os/os-pager.c (+184/-192) os/os-scrollbar.c (+626/-618) os/os-thumb.c (+112/-113) |
To merge this branch: | bzr merge lp:~cimi/overlay-scrollbar/0.2-refactoring |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ted Gould (community) | Approve | ||
Review via email: mp+61454@code.launchpad.net |
Commit message
Description of the change
Functions moved, comments, etc etc...
........(compiles) :D
To post a comment you must log in.
- 239. By Andrea Cimitan
-
Renamed xevent into xev to save space
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'os/os-animation.c' | |||
2 | --- os/os-animation.c 2011-04-04 16:17:15 +0000 | |||
3 | +++ os/os-animation.c 2011-05-18 18:39:29 +0000 | |||
4 | @@ -37,45 +37,9 @@ | |||
5 | 37 | guint32 source_id; | 37 | guint32 source_id; |
6 | 38 | }; | 38 | }; |
7 | 39 | 39 | ||
8 | 40 | static gboolean os_animation_update_cb (gpointer user_data); | ||
9 | 41 | static void os_animation_dispose (GObject* object); | 40 | static void os_animation_dispose (GObject* object); |
10 | 42 | static void os_animation_finalize (GObject* object); | 41 | static void os_animation_finalize (GObject* object); |
11 | 43 | 42 | ||
12 | 44 | /* Private functions. */ | ||
13 | 45 | |||
14 | 46 | static gboolean | ||
15 | 47 | os_animation_update_cb (gpointer user_data) | ||
16 | 48 | { | ||
17 | 49 | OsAnimation *animation = OS_ANIMATION (user_data); | ||
18 | 50 | OsAnimationPrivate *priv = animation->priv; | ||
19 | 51 | const gint64 current_time = g_get_monotonic_time (); | ||
20 | 52 | const gint64 end_time = priv->start_time + priv->duration; | ||
21 | 53 | |||
22 | 54 | if (current_time < end_time) | ||
23 | 55 | { | ||
24 | 56 | /* On-going animation. */ | ||
25 | 57 | const gfloat diff_time = current_time - priv->start_time; | ||
26 | 58 | const gfloat weight = diff_time / priv->duration; | ||
27 | 59 | |||
28 | 60 | priv->update_func (weight, priv->user_data); | ||
29 | 61 | |||
30 | 62 | return TRUE; | ||
31 | 63 | } | ||
32 | 64 | else | ||
33 | 65 | { | ||
34 | 66 | /* Animation ended. */ | ||
35 | 67 | priv->update_func (1.0f, priv->user_data); | ||
36 | 68 | priv->source_id = 0; | ||
37 | 69 | |||
38 | 70 | if (priv->end_func != NULL) | ||
39 | 71 | priv->end_func (priv->user_data); | ||
40 | 72 | |||
41 | 73 | return FALSE; | ||
42 | 74 | } | ||
43 | 75 | } | ||
44 | 76 | |||
45 | 77 | /* Type definition. */ | ||
46 | 78 | |||
47 | 79 | G_DEFINE_TYPE (OsAnimation, os_animation, G_TYPE_OBJECT); | 43 | G_DEFINE_TYPE (OsAnimation, os_animation, G_TYPE_OBJECT); |
48 | 80 | 44 | ||
49 | 81 | static void | 45 | static void |
50 | @@ -189,6 +153,38 @@ | |||
51 | 189 | priv->duration = (gint64) duration * G_GINT64_CONSTANT (1000); | 153 | priv->duration = (gint64) duration * G_GINT64_CONSTANT (1000); |
52 | 190 | } | 154 | } |
53 | 191 | 155 | ||
54 | 156 | /* callback called by the animation */ | ||
55 | 157 | static gboolean | ||
56 | 158 | update_cb (gpointer user_data) | ||
57 | 159 | { | ||
58 | 160 | OsAnimation *animation = OS_ANIMATION (user_data); | ||
59 | 161 | OsAnimationPrivate *priv = animation->priv; | ||
60 | 162 | const gint64 current_time = g_get_monotonic_time (); | ||
61 | 163 | const gint64 end_time = priv->start_time + priv->duration; | ||
62 | 164 | |||
63 | 165 | if (current_time < end_time) | ||
64 | 166 | { | ||
65 | 167 | /* On-going animation. */ | ||
66 | 168 | const gfloat diff_time = current_time - priv->start_time; | ||
67 | 169 | const gfloat weight = diff_time / priv->duration; | ||
68 | 170 | |||
69 | 171 | priv->update_func (weight, priv->user_data); | ||
70 | 172 | |||
71 | 173 | return TRUE; | ||
72 | 174 | } | ||
73 | 175 | else | ||
74 | 176 | { | ||
75 | 177 | /* Animation ended. */ | ||
76 | 178 | priv->update_func (1.0f, priv->user_data); | ||
77 | 179 | priv->source_id = 0; | ||
78 | 180 | |||
79 | 181 | if (priv->end_func != NULL) | ||
80 | 182 | priv->end_func (priv->user_data); | ||
81 | 183 | |||
82 | 184 | return FALSE; | ||
83 | 185 | } | ||
84 | 186 | } | ||
85 | 187 | |||
86 | 192 | /** | 188 | /** |
87 | 193 | * os_animation_start: | 189 | * os_animation_start: |
88 | 194 | * @animation: a #OsAnimation | 190 | * @animation: a #OsAnimation |
89 | @@ -207,7 +203,7 @@ | |||
90 | 207 | if (priv->source_id == 0) | 203 | if (priv->source_id == 0) |
91 | 208 | { | 204 | { |
92 | 209 | priv->start_time = g_get_monotonic_time (); | 205 | priv->start_time = g_get_monotonic_time (); |
94 | 210 | priv->source_id = g_timeout_add (priv->rate, os_animation_update_cb, animation); | 206 | priv->source_id = g_timeout_add (priv->rate, update_cb, animation); |
95 | 211 | } | 207 | } |
96 | 212 | } | 208 | } |
97 | 213 | 209 | ||
98 | 214 | 210 | ||
99 | === modified file 'os/os-pager.c' | |||
100 | --- os/os-pager.c 2011-05-12 23:39:33 +0000 | |||
101 | +++ os/os-pager.c 2011-05-18 18:39:29 +0000 | |||
102 | @@ -49,135 +49,40 @@ | |||
103 | 49 | gboolean detached; | 49 | gboolean detached; |
104 | 50 | gboolean visible; | 50 | gboolean visible; |
105 | 51 | gfloat weight; | 51 | gfloat weight; |
106 | 52 | gint width; | ||
107 | 53 | gint height; | ||
108 | 54 | gulong handler_id; | 52 | gulong handler_id; |
109 | 55 | }; | 53 | }; |
110 | 56 | 54 | ||
111 | 57 | static gboolean rectangle_changed (GdkRectangle rectangle1, GdkRectangle rectangle2); | ||
112 | 58 | static void os_pager_dispose (GObject *object); | 55 | static void os_pager_dispose (GObject *object); |
113 | 59 | static void os_pager_finalize (GObject *object); | 56 | static void os_pager_finalize (GObject *object); |
114 | 60 | static void os_pager_change_state_cb (gfloat weight, gpointer user_data); | ||
115 | 61 | static void os_pager_create (OsPager *pager); | ||
116 | 62 | static void os_pager_draw (OsPager *pager); | ||
117 | 63 | static void os_pager_draw_connection (OsPager *pager); | ||
118 | 64 | static void os_pager_mask (OsPager *pager); | ||
119 | 65 | static void os_pager_notify_gtk_theme_name_cb (GObject *object, GParamSpec* pspec, gpointer user_data); | ||
120 | 66 | 57 | ||
121 | 67 | /* Private functions */ | 58 | /* Private functions */ |
122 | 68 | 59 | ||
235 | 69 | static gboolean | 60 | /* draw on the connection_window */ |
236 | 70 | rectangle_changed (GdkRectangle rectangle1, | 61 | static void |
237 | 71 | GdkRectangle rectangle2) | 62 | draw_connection (OsPager *pager) |
238 | 72 | { | 63 | { |
239 | 73 | if (rectangle1.x != rectangle2.x) return TRUE; | 64 | GdkColor color; |
240 | 74 | if (rectangle1.y != rectangle2.y) return TRUE; | 65 | OsPagerPrivate *priv; |
241 | 75 | if (rectangle1.width != rectangle2.width) return TRUE; | 66 | |
242 | 76 | if (rectangle1.height != rectangle2.height) return TRUE; | 67 | priv = pager->priv; |
243 | 77 | 68 | ||
244 | 78 | return FALSE; | 69 | /* 0.6 is taken from os_thumb_expose. */ |
245 | 79 | } | 70 | color.red = 65535 * 0.6; |
246 | 80 | 71 | color.green = 65535 * 0.6; | |
247 | 81 | /* Create a pager. */ | 72 | color.blue = 65535 * 0.6; |
248 | 82 | static void | 73 | |
249 | 83 | os_pager_create (OsPager *pager) | 74 | gdk_colormap_alloc_color (gdk_drawable_get_colormap (priv->connection_window), &color, FALSE, TRUE); |
250 | 84 | { | 75 | |
251 | 85 | GdkWindowAttr attributes; | 76 | gdk_window_set_background (priv->connection_window, &color); |
252 | 86 | OsPagerPrivate *priv; | 77 | |
253 | 87 | 78 | gdk_window_clear (priv->connection_window); | |
254 | 88 | priv = pager->priv; | 79 | |
255 | 89 | 80 | gdk_window_invalidate_rect (gtk_widget_get_window (priv->parent), &priv->allocation, TRUE); | |
256 | 90 | /* Instead reparenting, | 81 | } |
257 | 91 | * which doesn't seem to work well, | 82 | |
258 | 92 | * destroy the two windows. */ | 83 | /* draw on the pager_window */ |
259 | 93 | if (priv->connection_window != NULL) | 84 | static void |
260 | 94 | { | 85 | draw_pager (OsPager *pager) |
149 | 95 | /* From the Gdk documentation: | ||
150 | 96 | * "Note that a window will not be destroyed | ||
151 | 97 | * automatically when its reference count | ||
152 | 98 | * reaches zero. You must call | ||
153 | 99 | * gdk_window_destroy () | ||
154 | 100 | * yourself before that happens". */ | ||
155 | 101 | gdk_window_destroy (priv->connection_window); | ||
156 | 102 | |||
157 | 103 | g_object_unref (priv->connection_window); | ||
158 | 104 | priv->connection_window = NULL; | ||
159 | 105 | } | ||
160 | 106 | |||
161 | 107 | if (priv->pager_window != NULL) | ||
162 | 108 | { | ||
163 | 109 | /* From the Gdk documentation: | ||
164 | 110 | * "Note that a window will not be destroyed | ||
165 | 111 | * automatically when its reference count | ||
166 | 112 | * reaches zero. You must call | ||
167 | 113 | * gdk_window_destroy () | ||
168 | 114 | * yourself before that happens". */ | ||
169 | 115 | gdk_window_destroy (priv->pager_window); | ||
170 | 116 | |||
171 | 117 | g_object_unref (priv->pager_window); | ||
172 | 118 | priv->pager_window = NULL; | ||
173 | 119 | } | ||
174 | 120 | |||
175 | 121 | attributes.width = priv->allocation.width; | ||
176 | 122 | attributes.height = priv->allocation.height; | ||
177 | 123 | attributes.wclass = GDK_INPUT_OUTPUT; | ||
178 | 124 | attributes.window_type = GDK_WINDOW_CHILD; | ||
179 | 125 | attributes.visual = gtk_widget_get_visual (priv->parent); | ||
180 | 126 | attributes.colormap = gtk_widget_get_colormap (priv->parent); | ||
181 | 127 | |||
182 | 128 | /* connection_window */ | ||
183 | 129 | priv->connection_window = gdk_window_new (gtk_widget_get_window (priv->parent), | ||
184 | 130 | &attributes, | ||
185 | 131 | GDK_WA_VISUAL | GDK_WA_COLORMAP); | ||
186 | 132 | |||
187 | 133 | g_object_ref_sink (priv->connection_window); | ||
188 | 134 | |||
189 | 135 | gdk_window_set_transient_for (priv->connection_window, | ||
190 | 136 | gtk_widget_get_window (priv->parent)); | ||
191 | 137 | |||
192 | 138 | gdk_window_input_shape_combine_region (priv->connection_window, | ||
193 | 139 | gdk_region_new (), | ||
194 | 140 | 0, 0); | ||
195 | 141 | |||
196 | 142 | /* pager_window */ | ||
197 | 143 | priv->pager_window = gdk_window_new (gtk_widget_get_window (priv->parent), | ||
198 | 144 | &attributes, | ||
199 | 145 | GDK_WA_VISUAL | GDK_WA_COLORMAP); | ||
200 | 146 | |||
201 | 147 | g_object_ref_sink (priv->pager_window); | ||
202 | 148 | |||
203 | 149 | /* stay above the connection_window */ | ||
204 | 150 | gdk_window_set_transient_for (priv->pager_window, | ||
205 | 151 | priv->connection_window); | ||
206 | 152 | |||
207 | 153 | gdk_window_input_shape_combine_region (priv->pager_window, | ||
208 | 154 | gdk_region_new (), | ||
209 | 155 | 0, 0); | ||
210 | 156 | } | ||
211 | 157 | |||
212 | 158 | static void | ||
213 | 159 | os_pager_change_state_cb (gfloat weight, | ||
214 | 160 | gpointer user_data) | ||
215 | 161 | { | ||
216 | 162 | OsPager *pager; | ||
217 | 163 | OsPagerPrivate *priv; | ||
218 | 164 | |||
219 | 165 | pager = OS_PAGER (user_data); | ||
220 | 166 | |||
221 | 167 | priv = pager->priv; | ||
222 | 168 | |||
223 | 169 | priv->weight = weight; | ||
224 | 170 | |||
225 | 171 | if (priv->parent == NULL) | ||
226 | 172 | return; | ||
227 | 173 | |||
228 | 174 | os_pager_draw_connection (pager); | ||
229 | 175 | os_pager_draw (pager); | ||
230 | 176 | } | ||
231 | 177 | |||
232 | 178 | /* Draw on the pager_window. */ | ||
233 | 179 | static void | ||
234 | 180 | os_pager_draw (OsPager *pager) | ||
261 | 181 | { | 86 | { |
262 | 182 | GdkColor c1, c2, color; | 87 | GdkColor c1, c2, color; |
263 | 183 | GtkStyle *style; | 88 | GtkStyle *style; |
264 | @@ -214,63 +119,32 @@ | |||
265 | 214 | gdk_window_invalidate_rect (gtk_widget_get_window (priv->parent), &priv->allocation, TRUE); | 119 | gdk_window_invalidate_rect (gtk_widget_get_window (priv->parent), &priv->allocation, TRUE); |
266 | 215 | } | 120 | } |
267 | 216 | 121 | ||
325 | 217 | /* Draw on the connection_window. */ | 122 | /* callback called by the change-state animation */ |
326 | 218 | static void | 123 | static void |
327 | 219 | os_pager_draw_connection (OsPager *pager) | 124 | change_state_cb (gfloat weight, |
328 | 220 | { | 125 | gpointer user_data) |
329 | 221 | GdkColor color; | 126 | { |
330 | 222 | OsPagerPrivate *priv; | 127 | OsPager *pager; |
331 | 223 | 128 | OsPagerPrivate *priv; | |
332 | 224 | priv = pager->priv; | 129 | |
333 | 225 | 130 | pager = OS_PAGER (user_data); | |
334 | 226 | /* 0.6 is taken from os_thumb_expose. */ | 131 | |
335 | 227 | color.red = 65535 * 0.6; | 132 | priv = pager->priv; |
336 | 228 | color.green = 65535 * 0.6; | 133 | |
337 | 229 | color.blue = 65535 * 0.6; | 134 | priv->weight = weight; |
338 | 230 | 135 | ||
339 | 231 | gdk_colormap_alloc_color (gdk_drawable_get_colormap (priv->connection_window), &color, FALSE, TRUE); | 136 | if (priv->parent == NULL) |
340 | 232 | 137 | return; | |
341 | 233 | gdk_window_set_background (priv->connection_window, &color); | 138 | |
342 | 234 | 139 | draw_connection (pager); | |
343 | 235 | gdk_window_clear (priv->connection_window); | 140 | draw_pager (pager); |
344 | 236 | 141 | } | |
345 | 237 | gdk_window_invalidate_rect (gtk_widget_get_window (priv->parent), &priv->allocation, TRUE); | 142 | |
346 | 238 | } | 143 | /* callback called when the Gtk+ theme changes */ |
347 | 239 | 144 | static void | |
348 | 240 | /* Mask the pager_window. */ | 145 | notify_gtk_theme_name_cb (GObject* gobject, |
349 | 241 | static void | 146 | GParamSpec* pspec, |
350 | 242 | os_pager_mask (OsPager *pager) | 147 | gpointer user_data) |
294 | 243 | { | ||
295 | 244 | OsPagerPrivate *priv; | ||
296 | 245 | |||
297 | 246 | priv = pager->priv; | ||
298 | 247 | |||
299 | 248 | gdk_window_shape_combine_region (priv->pager_window, | ||
300 | 249 | gdk_region_rectangle (&priv->mask), | ||
301 | 250 | 0, 0); | ||
302 | 251 | |||
303 | 252 | gdk_window_clear (priv->pager_window); | ||
304 | 253 | } | ||
305 | 254 | |||
306 | 255 | /* Mask the connection_window. */ | ||
307 | 256 | static void | ||
308 | 257 | os_pager_mask_connection (OsPager *pager) | ||
309 | 258 | { | ||
310 | 259 | OsPagerPrivate *priv; | ||
311 | 260 | |||
312 | 261 | priv = pager->priv; | ||
313 | 262 | |||
314 | 263 | gdk_window_shape_combine_region (priv->connection_window, | ||
315 | 264 | gdk_region_rectangle (&priv->connection_mask), | ||
316 | 265 | 0, 0); | ||
317 | 266 | |||
318 | 267 | gdk_window_clear (priv->connection_window); | ||
319 | 268 | } | ||
320 | 269 | |||
321 | 270 | static void | ||
322 | 271 | os_pager_notify_gtk_theme_name_cb (GObject* gobject, | ||
323 | 272 | GParamSpec* pspec, | ||
324 | 273 | gpointer user_data) | ||
351 | 274 | { | 148 | { |
352 | 275 | OsPager *pager; | 149 | OsPager *pager; |
353 | 276 | OsPagerPrivate *priv; | 150 | OsPagerPrivate *priv; |
354 | @@ -283,11 +157,22 @@ | |||
355 | 283 | priv->connection_window == NULL) | 157 | priv->connection_window == NULL) |
356 | 284 | return; | 158 | return; |
357 | 285 | 159 | ||
363 | 286 | os_pager_draw_connection (pager); | 160 | draw_connection (pager); |
364 | 287 | os_pager_draw (pager); | 161 | draw_pager (pager); |
365 | 288 | } | 162 | } |
366 | 289 | 163 | ||
367 | 290 | /* Type definition. */ | 164 | /* check if two GdkRectangle are different */ |
368 | 165 | static gboolean | ||
369 | 166 | rectangle_changed (GdkRectangle rectangle1, | ||
370 | 167 | GdkRectangle rectangle2) | ||
371 | 168 | { | ||
372 | 169 | if (rectangle1.x != rectangle2.x) return TRUE; | ||
373 | 170 | if (rectangle1.y != rectangle2.y) return TRUE; | ||
374 | 171 | if (rectangle1.width != rectangle2.width) return TRUE; | ||
375 | 172 | if (rectangle1.height != rectangle2.height) return TRUE; | ||
376 | 173 | |||
377 | 174 | return FALSE; | ||
378 | 175 | } | ||
379 | 291 | 176 | ||
380 | 292 | G_DEFINE_TYPE (OsPager, os_pager, G_TYPE_OBJECT); | 177 | G_DEFINE_TYPE (OsPager, os_pager, G_TYPE_OBJECT); |
381 | 293 | 178 | ||
382 | @@ -335,10 +220,10 @@ | |||
383 | 335 | priv->weight = 1.0f; | 220 | priv->weight = 1.0f; |
384 | 336 | 221 | ||
385 | 337 | priv->animation = os_animation_new (RATE_FADE, DURATION_FADE_OUT, | 222 | priv->animation = os_animation_new (RATE_FADE, DURATION_FADE_OUT, |
387 | 338 | os_pager_change_state_cb, NULL, pager); | 223 | change_state_cb, NULL, pager); |
388 | 339 | 224 | ||
389 | 340 | priv->handler_id = g_signal_connect (gtk_settings_get_default (), "notify::gtk-theme-name", | 225 | priv->handler_id = g_signal_connect (gtk_settings_get_default (), "notify::gtk-theme-name", |
391 | 341 | G_CALLBACK (os_pager_notify_gtk_theme_name_cb), pager); | 226 | G_CALLBACK (notify_gtk_theme_name_cb), pager); |
392 | 342 | } | 227 | } |
393 | 343 | 228 | ||
394 | 344 | static void | 229 | static void |
395 | @@ -413,6 +298,21 @@ | |||
396 | 413 | return g_object_new (OS_TYPE_PAGER, NULL); | 298 | return g_object_new (OS_TYPE_PAGER, NULL); |
397 | 414 | } | 299 | } |
398 | 415 | 300 | ||
399 | 301 | /* move a mask on the connection_window, fake movement */ | ||
400 | 302 | static void | ||
401 | 303 | mask_connection (OsPager *pager) | ||
402 | 304 | { | ||
403 | 305 | OsPagerPrivate *priv; | ||
404 | 306 | |||
405 | 307 | priv = pager->priv; | ||
406 | 308 | |||
407 | 309 | gdk_window_shape_combine_region (priv->connection_window, | ||
408 | 310 | gdk_region_rectangle (&priv->connection_mask), | ||
409 | 311 | 0, 0); | ||
410 | 312 | |||
411 | 313 | gdk_window_clear (priv->connection_window); | ||
412 | 314 | } | ||
413 | 315 | |||
414 | 416 | /** | 316 | /** |
415 | 417 | * os_pager_connect: | 317 | * os_pager_connect: |
416 | 418 | * @pager: a #OsPager | 318 | * @pager: a #OsPager |
417 | @@ -438,7 +338,7 @@ | |||
418 | 438 | if (priv->parent == NULL) | 338 | if (priv->parent == NULL) |
419 | 439 | return; | 339 | return; |
420 | 440 | 340 | ||
422 | 441 | os_pager_mask_connection (pager); | 341 | mask_connection (pager); |
423 | 442 | } | 342 | } |
424 | 443 | 343 | ||
425 | 444 | /** | 344 | /** |
426 | @@ -468,6 +368,21 @@ | |||
427 | 468 | gdk_window_hide (priv->pager_window); | 368 | gdk_window_hide (priv->pager_window); |
428 | 469 | } | 369 | } |
429 | 470 | 370 | ||
430 | 371 | /* move a mask on the pager_window, fake movement */ | ||
431 | 372 | static void | ||
432 | 373 | mask_pager (OsPager *pager) | ||
433 | 374 | { | ||
434 | 375 | OsPagerPrivate *priv; | ||
435 | 376 | |||
436 | 377 | priv = pager->priv; | ||
437 | 378 | |||
438 | 379 | gdk_window_shape_combine_region (priv->pager_window, | ||
439 | 380 | gdk_region_rectangle (&priv->mask), | ||
440 | 381 | 0, 0); | ||
441 | 382 | |||
442 | 383 | gdk_window_clear (priv->pager_window); | ||
443 | 384 | } | ||
444 | 385 | |||
445 | 471 | /** | 386 | /** |
446 | 472 | * os_pager_move_resize: | 387 | * os_pager_move_resize: |
447 | 473 | * @pager: a #OsPager | 388 | * @pager: a #OsPager |
448 | @@ -493,7 +408,7 @@ | |||
449 | 493 | if (priv->parent == NULL) | 408 | if (priv->parent == NULL) |
450 | 494 | return; | 409 | return; |
451 | 495 | 410 | ||
453 | 496 | os_pager_mask (pager); | 411 | mask_pager (pager); |
454 | 497 | } | 412 | } |
455 | 498 | 413 | ||
456 | 499 | /** | 414 | /** |
457 | @@ -534,7 +449,7 @@ | |||
458 | 534 | { | 449 | { |
459 | 535 | priv->weight = 1.0f; | 450 | priv->weight = 1.0f; |
460 | 536 | 451 | ||
462 | 537 | os_pager_draw (pager); | 452 | draw_pager (pager); |
463 | 538 | } | 453 | } |
464 | 539 | } | 454 | } |
465 | 540 | } | 455 | } |
466 | @@ -574,6 +489,83 @@ | |||
467 | 574 | } | 489 | } |
468 | 575 | } | 490 | } |
469 | 576 | 491 | ||
470 | 492 | /* create connection_window and pager_window */ | ||
471 | 493 | static void | ||
472 | 494 | create_windows (OsPager *pager) | ||
473 | 495 | { | ||
474 | 496 | GdkWindowAttr attributes; | ||
475 | 497 | OsPagerPrivate *priv; | ||
476 | 498 | |||
477 | 499 | priv = pager->priv; | ||
478 | 500 | |||
479 | 501 | /* Instead reparenting, | ||
480 | 502 | * which doesn't seem to work well, | ||
481 | 503 | * destroy the two windows. */ | ||
482 | 504 | if (priv->connection_window != NULL) | ||
483 | 505 | { | ||
484 | 506 | /* From the Gdk documentation: | ||
485 | 507 | * "Note that a window will not be destroyed | ||
486 | 508 | * automatically when its reference count | ||
487 | 509 | * reaches zero. You must call | ||
488 | 510 | * gdk_window_destroy () | ||
489 | 511 | * yourself before that happens". */ | ||
490 | 512 | gdk_window_destroy (priv->connection_window); | ||
491 | 513 | |||
492 | 514 | g_object_unref (priv->connection_window); | ||
493 | 515 | priv->connection_window = NULL; | ||
494 | 516 | } | ||
495 | 517 | |||
496 | 518 | if (priv->pager_window != NULL) | ||
497 | 519 | { | ||
498 | 520 | /* From the Gdk documentation: | ||
499 | 521 | * "Note that a window will not be destroyed | ||
500 | 522 | * automatically when its reference count | ||
501 | 523 | * reaches zero. You must call | ||
502 | 524 | * gdk_window_destroy () | ||
503 | 525 | * yourself before that happens". */ | ||
504 | 526 | gdk_window_destroy (priv->pager_window); | ||
505 | 527 | |||
506 | 528 | g_object_unref (priv->pager_window); | ||
507 | 529 | priv->pager_window = NULL; | ||
508 | 530 | } | ||
509 | 531 | |||
510 | 532 | attributes.width = priv->allocation.width; | ||
511 | 533 | attributes.height = priv->allocation.height; | ||
512 | 534 | attributes.wclass = GDK_INPUT_OUTPUT; | ||
513 | 535 | attributes.window_type = GDK_WINDOW_CHILD; | ||
514 | 536 | attributes.visual = gtk_widget_get_visual (priv->parent); | ||
515 | 537 | attributes.colormap = gtk_widget_get_colormap (priv->parent); | ||
516 | 538 | |||
517 | 539 | /* connection_window */ | ||
518 | 540 | priv->connection_window = gdk_window_new (gtk_widget_get_window (priv->parent), | ||
519 | 541 | &attributes, | ||
520 | 542 | GDK_WA_VISUAL | GDK_WA_COLORMAP); | ||
521 | 543 | |||
522 | 544 | g_object_ref_sink (priv->connection_window); | ||
523 | 545 | |||
524 | 546 | gdk_window_set_transient_for (priv->connection_window, | ||
525 | 547 | gtk_widget_get_window (priv->parent)); | ||
526 | 548 | |||
527 | 549 | gdk_window_input_shape_combine_region (priv->connection_window, | ||
528 | 550 | gdk_region_new (), | ||
529 | 551 | 0, 0); | ||
530 | 552 | |||
531 | 553 | /* pager_window */ | ||
532 | 554 | priv->pager_window = gdk_window_new (gtk_widget_get_window (priv->parent), | ||
533 | 555 | &attributes, | ||
534 | 556 | GDK_WA_VISUAL | GDK_WA_COLORMAP); | ||
535 | 557 | |||
536 | 558 | g_object_ref_sink (priv->pager_window); | ||
537 | 559 | |||
538 | 560 | /* stay above the connection_window */ | ||
539 | 561 | gdk_window_set_transient_for (priv->pager_window, | ||
540 | 562 | priv->connection_window); | ||
541 | 563 | |||
542 | 564 | gdk_window_input_shape_combine_region (priv->pager_window, | ||
543 | 565 | gdk_region_new (), | ||
544 | 566 | 0, 0); | ||
545 | 567 | } | ||
546 | 568 | |||
547 | 577 | /** | 569 | /** |
548 | 578 | * os_pager_set_parent: | 570 | * os_pager_set_parent: |
549 | 579 | * @pager: a #OsPager | 571 | * @pager: a #OsPager |
550 | @@ -608,10 +600,10 @@ | |||
551 | 608 | 600 | ||
552 | 609 | priv->weight = 1.0f; | 601 | priv->weight = 1.0f; |
553 | 610 | 602 | ||
558 | 611 | os_pager_create (pager); | 603 | create_windows (pager); |
559 | 612 | os_pager_draw_connection (pager); | 604 | draw_connection (pager); |
560 | 613 | os_pager_draw (pager); | 605 | draw_pager (pager); |
561 | 614 | os_pager_mask (pager); | 606 | mask_pager (pager); |
562 | 615 | 607 | ||
563 | 616 | gdk_window_move_resize (priv->connection_window, | 608 | gdk_window_move_resize (priv->connection_window, |
564 | 617 | priv->allocation.x, | 609 | priv->allocation.x, |
565 | 618 | 610 | ||
566 | === modified file 'os/os-scrollbar.c' | |||
567 | --- os/os-scrollbar.c 2011-05-17 20:54:31 +0000 | |||
568 | +++ os/os-scrollbar.c 2011-05-18 18:39:29 +0000 | |||
569 | @@ -65,12 +65,12 @@ | |||
570 | 65 | gboolean active_window; | 65 | gboolean active_window; |
571 | 66 | gboolean can_deactivate_pager; | 66 | gboolean can_deactivate_pager; |
572 | 67 | gboolean can_hide; | 67 | gboolean can_hide; |
573 | 68 | gboolean toplevel_button_press; | ||
574 | 69 | gboolean filter; | 68 | gboolean filter; |
575 | 70 | gboolean fullsize; | 69 | gboolean fullsize; |
576 | 71 | gboolean internal; | 70 | gboolean internal; |
577 | 72 | gboolean lock_position; | 71 | gboolean lock_position; |
578 | 73 | gboolean proximity; | 72 | gboolean proximity; |
579 | 73 | gboolean toplevel_button_press; | ||
580 | 74 | gint win_x; | 74 | gint win_x; |
581 | 75 | gint win_y; | 75 | gint win_y; |
582 | 76 | gint slide_initial_slider_position; | 76 | gint slide_initial_slider_position; |
583 | @@ -86,7 +86,20 @@ | |||
584 | 86 | static Atom net_active_window_atom = None; | 86 | static Atom net_active_window_atom = None; |
585 | 87 | static GList *os_root_list = NULL; | 87 | static GList *os_root_list = NULL; |
586 | 88 | 88 | ||
587 | 89 | static void swap_adjustment (OsScrollbar *scrollbar, GtkAdjustment *adjustment); | ||
588 | 90 | static void swap_thumb (OsScrollbar *scrollbar, GtkWidget *thumb); | ||
589 | 91 | static void adjustment_changed_cb (GtkAdjustment *adjustment, gpointer user_data); | ||
590 | 92 | static void adjustment_value_changed_cb (GtkAdjustment *adjustment, gpointer user_data); | ||
591 | 93 | static gboolean thumb_button_press_event_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data); | ||
592 | 94 | static gboolean thumb_button_release_event_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data); | ||
593 | 95 | static gboolean thumb_enter_notify_event_cb (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data); | ||
594 | 96 | static gboolean thumb_leave_notify_event_cb (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data); | ||
595 | 97 | static void thumb_map_cb (GtkWidget *widget, gpointer user_data); | ||
596 | 98 | static gboolean thumb_motion_notify_event_cb (GtkWidget *widget, GdkEventMotion *event, gpointer user_data); | ||
597 | 99 | static gboolean thumb_scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, gpointer user_data); | ||
598 | 100 | static void thumb_unmap_cb (GtkWidget *widget, gpointer user_data); | ||
599 | 89 | static gboolean os_scrollbar_expose_event (GtkWidget *widget, GdkEventExpose *event); | 101 | static gboolean os_scrollbar_expose_event (GtkWidget *widget, GdkEventExpose *event); |
600 | 102 | |||
601 | 90 | static void os_scrollbar_grab_notify (GtkWidget *widget, gboolean was_grabbed); | 103 | static void os_scrollbar_grab_notify (GtkWidget *widget, gboolean was_grabbed); |
602 | 91 | static void os_scrollbar_hide (GtkWidget *widget); | 104 | static void os_scrollbar_hide (GtkWidget *widget); |
603 | 92 | static void os_scrollbar_map (GtkWidget *widget); | 105 | static void os_scrollbar_map (GtkWidget *widget); |
604 | @@ -98,98 +111,13 @@ | |||
605 | 98 | static void os_scrollbar_unrealize (GtkWidget *widget); | 111 | static void os_scrollbar_unrealize (GtkWidget *widget); |
606 | 99 | static void os_scrollbar_dispose (GObject *object); | 112 | static void os_scrollbar_dispose (GObject *object); |
607 | 100 | static void os_scrollbar_finalize (GObject *object); | 113 | static void os_scrollbar_finalize (GObject *object); |
608 | 101 | static void os_scrollbar_calc_layout_pager (OsScrollbar *scrollbar, gdouble adjustment_value); | ||
609 | 102 | static void os_scrollbar_calc_layout_slider (OsScrollbar *scrollbar, gdouble adjustment_value); | ||
610 | 103 | static gdouble os_scrollbar_coord_to_value (OsScrollbar *scrollbar, gint coord); | ||
611 | 104 | static void os_scrollbar_deactivate_pager (OsScrollbar *scrollbar); | ||
612 | 105 | static gboolean os_scrollbar_deactivate_pager_cb (gpointer user_data); | ||
613 | 106 | static gdouble os_scrollbar_get_wheel_delta (OsScrollbar *scrollbar, GdkScrollDirection direction); | ||
614 | 107 | static void os_scrollbar_hide_thumb (OsScrollbar *scrollbar); | ||
615 | 108 | static gboolean os_scrollbar_hide_thumb_cb (gpointer user_data); | ||
616 | 109 | static gboolean os_scrollbar_unlock_thumb_cb (gpointer user_data); | ||
617 | 110 | static void os_scrollbar_move (OsScrollbar *scrollbar, gint mouse_x, gint mouse_y); | ||
618 | 111 | static void os_scrollbar_move_thumb (OsScrollbar *scrollbar, gint x, gint y); | ||
619 | 112 | static void os_scrollbar_notify_adjustment_cb (GObject *object, gpointer user_data); | ||
620 | 113 | static void os_scrollbar_notify_orientation_cb (GObject *object, gpointer user_data); | ||
621 | 114 | static gint os_scrollbar_sanitize_x (OsScrollbar *scrollbar, gint x, gint y); | ||
622 | 115 | static gint os_scrollbar_sanitize_y (OsScrollbar *scrollbar, gint x, gint y); | ||
623 | 116 | static void os_scrollbar_store_window_position (OsScrollbar *scrollbar); | ||
624 | 117 | static void os_scrollbar_swap_adjustment (OsScrollbar *scrollbar, GtkAdjustment *adjustment); | ||
625 | 118 | static void os_scrollbar_swap_thumb (OsScrollbar *scrollbar, GtkWidget *thumb); | ||
626 | 119 | static gboolean thumb_button_press_event_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data); | ||
627 | 120 | static gboolean thumb_button_release_event_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data); | ||
628 | 121 | static gboolean thumb_enter_notify_event_cb (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data); | ||
629 | 122 | static gboolean thumb_leave_notify_event_cb (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data); | ||
630 | 123 | static void thumb_map_cb (GtkWidget *widget, gpointer user_data); | ||
631 | 124 | static gboolean thumb_motion_notify_event_cb (GtkWidget *widget, GdkEventMotion *event, gpointer user_data); | ||
632 | 125 | static gboolean thumb_scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, gpointer user_data); | ||
633 | 126 | static void thumb_unmap_cb (GtkWidget *widget, gpointer user_data); | ||
634 | 127 | static void pager_move (OsScrollbar *scrollbar); | ||
635 | 128 | static void pager_set_state_from_pointer (OsScrollbar *scrollbar, gint x, gint y); | ||
636 | 129 | static void adjustment_changed_cb (GtkAdjustment *adjustment, gpointer user_data); | ||
637 | 130 | static void adjustment_value_changed_cb (GtkAdjustment *adjustment, gpointer user_data); | ||
638 | 131 | static GdkFilterReturn root_filter_func (GdkXEvent *gdkxevent, GdkEvent *event, gpointer user_data); | ||
639 | 132 | static void root_gfunc (gpointer data, gpointer user_data); | ||
640 | 133 | static gboolean toplevel_configure_event_cb (GtkWidget *widget, GdkEventConfigure *event, gpointer user_data); | ||
641 | 134 | static GdkFilterReturn toplevel_filter_func (GdkXEvent *gdkxevent, GdkEvent *event, gpointer user_data); | ||
642 | 135 | 114 | ||
643 | 136 | /* Private functions. */ | 115 | /* Private functions. */ |
644 | 137 | 116 | ||
700 | 138 | /* Present a X11 window. */ | 117 | /* calculate pager layout info */ |
701 | 139 | static void | 118 | static void |
702 | 140 | os_present_window_with_timestamp (Screen *screen, | 119 | calc_layout_pager (OsScrollbar *scrollbar, |
703 | 141 | gint xid, | 120 | gdouble adjustment_value) |
649 | 142 | guint32 timestamp) | ||
650 | 143 | { | ||
651 | 144 | Display *display; | ||
652 | 145 | Window root; | ||
653 | 146 | XEvent xev; | ||
654 | 147 | |||
655 | 148 | if (timestamp == 0) | ||
656 | 149 | g_warning ("Received a timestamp of 0; window activation may not " | ||
657 | 150 | "function properly.\n"); | ||
658 | 151 | |||
659 | 152 | display = DisplayOfScreen (screen); | ||
660 | 153 | root = RootWindowOfScreen (screen); | ||
661 | 154 | |||
662 | 155 | xev.xclient.type = ClientMessage; | ||
663 | 156 | xev.xclient.serial = 0; | ||
664 | 157 | xev.xclient.send_event = True; | ||
665 | 158 | xev.xclient.display = display; | ||
666 | 159 | xev.xclient.window = xid; | ||
667 | 160 | xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW"); | ||
668 | 161 | xev.xclient.format = 32; | ||
669 | 162 | xev.xclient.data.l[0] = 1; | ||
670 | 163 | xev.xclient.data.l[1] = timestamp; | ||
671 | 164 | xev.xclient.data.l[2] = 0; | ||
672 | 165 | xev.xclient.data.l[3] = 0; | ||
673 | 166 | xev.xclient.data.l[4] = 0; | ||
674 | 167 | |||
675 | 168 | gdk_error_trap_push (); | ||
676 | 169 | |||
677 | 170 | XSendEvent (display, root, False, | ||
678 | 171 | SubstructureRedirectMask | SubstructureNotifyMask, | ||
679 | 172 | &xev); | ||
680 | 173 | |||
681 | 174 | gdk_flush (); | ||
682 | 175 | |||
683 | 176 | gdk_error_trap_pop (); | ||
684 | 177 | } | ||
685 | 178 | |||
686 | 179 | /* Present a GDK window. */ | ||
687 | 180 | static void | ||
688 | 181 | os_present_gdk_window_with_timestamp (GtkWidget *widget, | ||
689 | 182 | guint32 timestamp) | ||
690 | 183 | { | ||
691 | 184 | os_present_window_with_timestamp (GDK_SCREEN_XSCREEN (gtk_widget_get_screen (widget)), | ||
692 | 185 | GDK_WINDOW_XID (gtk_widget_get_window (widget)), | ||
693 | 186 | timestamp); | ||
694 | 187 | } | ||
695 | 188 | |||
696 | 189 | /* Calculate layout and store info. */ | ||
697 | 190 | static void | ||
698 | 191 | os_scrollbar_calc_layout_pager (OsScrollbar *scrollbar, | ||
699 | 192 | gdouble adjustment_value) | ||
704 | 193 | { | 121 | { |
705 | 194 | OsScrollbarPrivate *priv; | 122 | OsScrollbarPrivate *priv; |
706 | 195 | 123 | ||
707 | @@ -261,10 +189,10 @@ | |||
708 | 261 | } | 189 | } |
709 | 262 | } | 190 | } |
710 | 263 | 191 | ||
712 | 264 | /* Calculate OsScrollbar layout and store info. */ | 192 | /* calculate slider (thumb) layout info */ |
713 | 265 | static void | 193 | static void |
716 | 266 | os_scrollbar_calc_layout_slider (OsScrollbar *scrollbar, | 194 | calc_layout_slider (OsScrollbar *scrollbar, |
717 | 267 | gdouble adjustment_value) | 195 | gdouble adjustment_value) |
718 | 268 | { | 196 | { |
719 | 269 | OsScrollbarPrivate *priv; | 197 | OsScrollbarPrivate *priv; |
720 | 270 | 198 | ||
721 | @@ -316,51 +244,9 @@ | |||
722 | 316 | } | 244 | } |
723 | 317 | } | 245 | } |
724 | 318 | 246 | ||
768 | 319 | /* Traduce pixels into proper values. */ | 247 | /* deactivate the pager if it's the case */ |
726 | 320 | static gdouble | ||
727 | 321 | os_scrollbar_coord_to_value (OsScrollbar *scrollbar, | ||
728 | 322 | gint coord) | ||
729 | 323 | { | ||
730 | 324 | OsScrollbarPrivate *priv; | ||
731 | 325 | gdouble frac; | ||
732 | 326 | gdouble value; | ||
733 | 327 | gint trough_length; | ||
734 | 328 | gint trough_start; | ||
735 | 329 | gint slider_length; | ||
736 | 330 | |||
737 | 331 | priv = scrollbar->priv; | ||
738 | 332 | |||
739 | 333 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | ||
740 | 334 | { | ||
741 | 335 | trough_length = priv->trough.height; | ||
742 | 336 | trough_start = priv->trough.y; | ||
743 | 337 | slider_length = MAX (priv->slider.height, priv->overlay.height); | ||
744 | 338 | } | ||
745 | 339 | else | ||
746 | 340 | { | ||
747 | 341 | trough_length = priv->trough.width; | ||
748 | 342 | trough_start = priv->trough.y; | ||
749 | 343 | slider_length = MAX (priv->slider.width, priv->overlay.width); | ||
750 | 344 | } | ||
751 | 345 | |||
752 | 346 | if (trough_length == slider_length) | ||
753 | 347 | frac = 1.0; | ||
754 | 348 | else | ||
755 | 349 | frac = (MAX (0, coord - trough_start) / | ||
756 | 350 | (gdouble) (trough_length - slider_length)); | ||
757 | 351 | |||
758 | 352 | value = priv->adjustment->lower + frac * (priv->adjustment->upper - | ||
759 | 353 | priv->adjustment->lower - | ||
760 | 354 | priv->adjustment->page_size); | ||
761 | 355 | |||
762 | 356 | value = CLAMP (value, priv->adjustment->lower, priv->adjustment->upper - priv->adjustment->page_size); | ||
763 | 357 | |||
764 | 358 | return value; | ||
765 | 359 | } | ||
766 | 360 | |||
767 | 361 | /* Deactivate pager if it's ok to make it inactive. */ | ||
769 | 362 | static void | 248 | static void |
771 | 363 | os_scrollbar_deactivate_pager (OsScrollbar *scrollbar) | 249 | deactivate_pager (OsScrollbar *scrollbar) |
772 | 364 | { | 250 | { |
773 | 365 | OsScrollbarPrivate *priv; | 251 | OsScrollbarPrivate *priv; |
774 | 366 | 252 | ||
775 | @@ -370,8 +256,9 @@ | |||
776 | 370 | os_pager_set_active (OS_PAGER (priv->pager), FALSE); | 256 | os_pager_set_active (OS_PAGER (priv->pager), FALSE); |
777 | 371 | } | 257 | } |
778 | 372 | 258 | ||
779 | 259 | /* timeout before deactivating the pager */ | ||
780 | 373 | static gboolean | 260 | static gboolean |
782 | 374 | os_scrollbar_deactivate_pager_cb (gpointer user_data) | 261 | deactivate_pager_cb (gpointer user_data) |
783 | 375 | { | 262 | { |
784 | 376 | OsScrollbar *scrollbar; | 263 | OsScrollbar *scrollbar; |
785 | 377 | OsScrollbarPrivate *priv; | 264 | OsScrollbarPrivate *priv; |
786 | @@ -381,33 +268,15 @@ | |||
787 | 381 | 268 | ||
788 | 382 | OS_DCHECK (!priv->active_window); | 269 | OS_DCHECK (!priv->active_window); |
789 | 383 | 270 | ||
791 | 384 | os_scrollbar_deactivate_pager (scrollbar); | 271 | deactivate_pager (scrollbar); |
792 | 385 | priv->source_deactivate_pager_id = 0; | 272 | priv->source_deactivate_pager_id = 0; |
793 | 386 | 273 | ||
794 | 387 | return FALSE; | 274 | return FALSE; |
795 | 388 | } | 275 | } |
796 | 389 | 276 | ||
816 | 390 | static gdouble | 277 | /* hide the thumb if it's the case */ |
798 | 391 | os_scrollbar_get_wheel_delta (OsScrollbar *scrollbar, | ||
799 | 392 | GdkScrollDirection direction) | ||
800 | 393 | { | ||
801 | 394 | OsScrollbarPrivate *priv; | ||
802 | 395 | gdouble delta; | ||
803 | 396 | |||
804 | 397 | priv = scrollbar->priv; | ||
805 | 398 | |||
806 | 399 | delta = pow (priv->adjustment->page_size, 2.0 / 3.0); | ||
807 | 400 | |||
808 | 401 | if (direction == GDK_SCROLL_UP || | ||
809 | 402 | direction == GDK_SCROLL_LEFT) | ||
810 | 403 | delta = - delta; | ||
811 | 404 | |||
812 | 405 | return delta; | ||
813 | 406 | } | ||
814 | 407 | |||
815 | 408 | /* Hide if it's ok to hide. */ | ||
817 | 409 | static void | 278 | static void |
819 | 410 | os_scrollbar_hide_thumb (OsScrollbar *scrollbar) | 279 | hide_thumb (OsScrollbar *scrollbar) |
820 | 411 | { | 280 | { |
821 | 412 | OsScrollbarPrivate *priv; | 281 | OsScrollbarPrivate *priv; |
822 | 413 | 282 | ||
823 | @@ -420,8 +289,9 @@ | |||
824 | 420 | } | 289 | } |
825 | 421 | } | 290 | } |
826 | 422 | 291 | ||
827 | 292 | /* timeout before hiding the thumb */ | ||
828 | 423 | static gboolean | 293 | static gboolean |
830 | 424 | os_scrollbar_hide_thumb_cb (gpointer user_data) | 294 | hide_thumb_cb (gpointer user_data) |
831 | 425 | { | 295 | { |
832 | 426 | OsScrollbar *scrollbar; | 296 | OsScrollbar *scrollbar; |
833 | 427 | OsScrollbarPrivate *priv; | 297 | OsScrollbarPrivate *priv; |
834 | @@ -429,97 +299,44 @@ | |||
835 | 429 | scrollbar = OS_SCROLLBAR (user_data); | 299 | scrollbar = OS_SCROLLBAR (user_data); |
836 | 430 | priv = scrollbar->priv; | 300 | priv = scrollbar->priv; |
837 | 431 | 301 | ||
839 | 432 | os_scrollbar_hide_thumb (scrollbar); | 302 | hide_thumb (scrollbar); |
840 | 433 | priv->source_hide_thumb_id = 0; | 303 | priv->source_hide_thumb_id = 0; |
841 | 434 | 304 | ||
842 | 435 | return FALSE; | 305 | return FALSE; |
843 | 436 | } | 306 | } |
844 | 437 | 307 | ||
862 | 438 | static gboolean | 308 | /* move the pager */ |
846 | 439 | os_scrollbar_unlock_thumb_cb (gpointer user_data) | ||
847 | 440 | { | ||
848 | 441 | OsScrollbar *scrollbar; | ||
849 | 442 | OsScrollbarPrivate *priv; | ||
850 | 443 | |||
851 | 444 | scrollbar = OS_SCROLLBAR (user_data); | ||
852 | 445 | priv = scrollbar->priv; | ||
853 | 446 | |||
854 | 447 | if (priv->can_hide) | ||
855 | 448 | priv->lock_position = FALSE; | ||
856 | 449 | |||
857 | 450 | priv->source_unlock_thumb_id = 0; | ||
858 | 451 | |||
859 | 452 | return FALSE; | ||
860 | 453 | } | ||
861 | 454 | |||
863 | 455 | static void | 309 | static void |
867 | 456 | os_scrollbar_move (OsScrollbar *scrollbar, | 310 | move_pager (OsScrollbar *scrollbar) |
865 | 457 | gint mouse_x, | ||
866 | 458 | gint mouse_y) | ||
868 | 459 | { | 311 | { |
869 | 312 | GdkRectangle mask; | ||
870 | 460 | OsScrollbarPrivate *priv; | 313 | OsScrollbarPrivate *priv; |
871 | 461 | gint delta; | ||
872 | 462 | gint c; | ||
873 | 463 | gdouble new_value; | ||
874 | 464 | 314 | ||
875 | 465 | priv = scrollbar->priv; | 315 | priv = scrollbar->priv; |
876 | 466 | 316 | ||
877 | 467 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | 317 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
879 | 468 | delta = mouse_y - priv->slide_initial_coordinate; | 318 | { |
880 | 319 | mask.x = 0; | ||
881 | 320 | mask.y = priv->overlay.y; | ||
882 | 321 | mask.width = DEFAULT_PAGER_WIDTH; | ||
883 | 322 | mask.height = priv->overlay.height; | ||
884 | 323 | } | ||
885 | 469 | else | 324 | else |
935 | 470 | delta = mouse_x - priv->slide_initial_coordinate; | 325 | { |
936 | 471 | 326 | mask.x = priv->overlay.x; | |
937 | 472 | c = priv->slide_initial_slider_position + delta; | 327 | mask.y = 0; |
938 | 473 | 328 | mask.width = priv->overlay.width; | |
939 | 474 | new_value = os_scrollbar_coord_to_value (scrollbar, c); | 329 | mask.height = DEFAULT_PAGER_WIDTH; |
940 | 475 | 330 | } | |
941 | 476 | gtk_adjustment_set_value (priv->adjustment, new_value); | 331 | |
942 | 477 | } | 332 | os_pager_move_resize (OS_PAGER (priv->pager), mask); |
943 | 478 | 333 | } | |
944 | 479 | static void | 334 | |
945 | 480 | os_scrollbar_move_thumb (OsScrollbar *scrollbar, | 335 | /* sanitize x coordinate of thumb window */ |
897 | 481 | gint x, | ||
898 | 482 | gint y) | ||
899 | 483 | { | ||
900 | 484 | OsScrollbarPrivate *priv; | ||
901 | 485 | |||
902 | 486 | priv = scrollbar->priv; | ||
903 | 487 | |||
904 | 488 | gtk_window_move (GTK_WINDOW (priv->thumb), | ||
905 | 489 | os_scrollbar_sanitize_x (scrollbar, x, y), | ||
906 | 490 | os_scrollbar_sanitize_y (scrollbar, x, y)); | ||
907 | 491 | } | ||
908 | 492 | |||
909 | 493 | static void | ||
910 | 494 | os_scrollbar_notify_adjustment_cb (GObject *object, | ||
911 | 495 | gpointer user_data) | ||
912 | 496 | { | ||
913 | 497 | OsScrollbar *scrollbar; | ||
914 | 498 | |||
915 | 499 | scrollbar = OS_SCROLLBAR (object); | ||
916 | 500 | |||
917 | 501 | os_scrollbar_swap_adjustment (scrollbar, gtk_range_get_adjustment (GTK_RANGE (object))); | ||
918 | 502 | } | ||
919 | 503 | |||
920 | 504 | static void | ||
921 | 505 | os_scrollbar_notify_orientation_cb (GObject *object, | ||
922 | 506 | gpointer user_data) | ||
923 | 507 | { | ||
924 | 508 | OsScrollbar *scrollbar; | ||
925 | 509 | OsScrollbarPrivate *priv; | ||
926 | 510 | |||
927 | 511 | scrollbar = OS_SCROLLBAR (object); | ||
928 | 512 | priv = scrollbar->priv; | ||
929 | 513 | |||
930 | 514 | priv->orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (object)); | ||
931 | 515 | |||
932 | 516 | os_scrollbar_swap_thumb (scrollbar, os_thumb_new (priv->orientation)); | ||
933 | 517 | } | ||
934 | 518 | |||
946 | 519 | static gint | 336 | static gint |
950 | 520 | os_scrollbar_sanitize_x (OsScrollbar *scrollbar, | 337 | sanitize_x (OsScrollbar *scrollbar, |
951 | 521 | gint x, | 338 | gint x, |
952 | 522 | gint y) | 339 | gint y) |
953 | 523 | { | 340 | { |
954 | 524 | GdkRectangle rect; | 341 | GdkRectangle rect; |
955 | 525 | OsScrollbarPrivate *priv; | 342 | OsScrollbarPrivate *priv; |
956 | @@ -550,10 +367,11 @@ | |||
957 | 550 | return x; | 367 | return x; |
958 | 551 | } | 368 | } |
959 | 552 | 369 | ||
960 | 370 | /* sanitize y coordinate of thumb window */ | ||
961 | 553 | static gint | 371 | static gint |
965 | 554 | os_scrollbar_sanitize_y (OsScrollbar *scrollbar, | 372 | sanitize_y (OsScrollbar *scrollbar, |
966 | 555 | gint x, | 373 | gint x, |
967 | 556 | gint y) | 374 | gint y) |
968 | 557 | { | 375 | { |
969 | 558 | GdkRectangle rect; | 376 | GdkRectangle rect; |
970 | 559 | OsScrollbarPrivate *priv; | 377 | OsScrollbarPrivate *priv; |
971 | @@ -584,33 +402,53 @@ | |||
972 | 584 | return y; | 402 | return y; |
973 | 585 | } | 403 | } |
974 | 586 | 404 | ||
1002 | 587 | /* Store scrollbar window position. */ | 405 | /* move the thumb window */ |
1003 | 588 | static void | 406 | static void |
1004 | 589 | os_scrollbar_store_window_position (OsScrollbar *scrollbar) | 407 | move_thumb (OsScrollbar *scrollbar, |
1005 | 590 | { | 408 | gint x, |
1006 | 591 | OsScrollbarPrivate *priv; | 409 | gint y) |
1007 | 592 | gint win_x, win_y; | 410 | { |
1008 | 593 | 411 | OsScrollbarPrivate *priv; | |
1009 | 594 | priv = scrollbar->priv; | 412 | |
1010 | 595 | 413 | priv = scrollbar->priv; | |
1011 | 596 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &win_x, &win_y); | 414 | |
1012 | 597 | 415 | gtk_window_move (GTK_WINDOW (priv->thumb), | |
1013 | 598 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | 416 | sanitize_x (scrollbar, x, y), |
1014 | 599 | { | 417 | sanitize_y (scrollbar, x, y)); |
1015 | 600 | priv->win_x = win_x + priv->thumb_all.x; | 418 | } |
1016 | 601 | priv->win_y = win_y + priv->thumb_all.y; | 419 | |
1017 | 602 | } | 420 | /* callback called when the adjustment changes */ |
1018 | 603 | else | 421 | static void |
1019 | 604 | { | 422 | notify_adjustment_cb (GObject *object, |
1020 | 605 | priv->win_x = win_x + priv->thumb_all.x; | 423 | gpointer user_data) |
1021 | 606 | priv->win_y = win_y + priv->thumb_all.y; | 424 | { |
1022 | 607 | } | 425 | OsScrollbar *scrollbar; |
1023 | 608 | } | 426 | |
1024 | 609 | 427 | scrollbar = OS_SCROLLBAR (object); | |
1025 | 610 | /* Swap the adjustment pointer. */ | 428 | |
1026 | 611 | static void | 429 | swap_adjustment (scrollbar, gtk_range_get_adjustment (GTK_RANGE (object))); |
1027 | 612 | os_scrollbar_swap_adjustment (OsScrollbar *scrollbar, | 430 | } |
1028 | 613 | GtkAdjustment *adjustment) | 431 | |
1029 | 432 | /* callback called when the orientation changes */ | ||
1030 | 433 | static void | ||
1031 | 434 | notify_orientation_cb (GObject *object, | ||
1032 | 435 | gpointer user_data) | ||
1033 | 436 | { | ||
1034 | 437 | OsScrollbar *scrollbar; | ||
1035 | 438 | OsScrollbarPrivate *priv; | ||
1036 | 439 | |||
1037 | 440 | scrollbar = OS_SCROLLBAR (object); | ||
1038 | 441 | priv = scrollbar->priv; | ||
1039 | 442 | |||
1040 | 443 | priv->orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (object)); | ||
1041 | 444 | |||
1042 | 445 | swap_thumb (scrollbar, os_thumb_new (priv->orientation)); | ||
1043 | 446 | } | ||
1044 | 447 | |||
1045 | 448 | /* swap adjustment pointer */ | ||
1046 | 449 | static void | ||
1047 | 450 | swap_adjustment (OsScrollbar *scrollbar, | ||
1048 | 451 | GtkAdjustment *adjustment) | ||
1049 | 614 | { | 452 | { |
1050 | 615 | OsScrollbarPrivate *priv; | 453 | OsScrollbarPrivate *priv; |
1051 | 616 | 454 | ||
1052 | @@ -639,10 +477,10 @@ | |||
1053 | 639 | } | 477 | } |
1054 | 640 | } | 478 | } |
1055 | 641 | 479 | ||
1057 | 642 | /* Swap the thumb pointer. */ | 480 | /* swap thumb pointer */ |
1058 | 643 | static void | 481 | static void |
1061 | 644 | os_scrollbar_swap_thumb (OsScrollbar *scrollbar, | 482 | swap_thumb (OsScrollbar *scrollbar, |
1062 | 645 | GtkWidget *thumb) | 483 | GtkWidget *thumb) |
1063 | 646 | { | 484 | { |
1064 | 647 | OsScrollbarPrivate *priv; | 485 | OsScrollbarPrivate *priv; |
1065 | 648 | 486 | ||
1066 | @@ -697,6 +535,353 @@ | |||
1067 | 697 | } | 535 | } |
1068 | 698 | } | 536 | } |
1069 | 699 | 537 | ||
1070 | 538 | /* timeout before unlocking the thumb */ | ||
1071 | 539 | static gboolean | ||
1072 | 540 | unlock_thumb_cb (gpointer user_data) | ||
1073 | 541 | { | ||
1074 | 542 | OsScrollbar *scrollbar; | ||
1075 | 543 | OsScrollbarPrivate *priv; | ||
1076 | 544 | |||
1077 | 545 | scrollbar = OS_SCROLLBAR (user_data); | ||
1078 | 546 | priv = scrollbar->priv; | ||
1079 | 547 | |||
1080 | 548 | if (priv->can_hide) | ||
1081 | 549 | priv->lock_position = FALSE; | ||
1082 | 550 | |||
1083 | 551 | priv->source_unlock_thumb_id = 0; | ||
1084 | 552 | |||
1085 | 553 | return FALSE; | ||
1086 | 554 | } | ||
1087 | 555 | |||
1088 | 556 | /* adjustment functions */ | ||
1089 | 557 | |||
1090 | 558 | static void | ||
1091 | 559 | adjustment_changed_cb (GtkAdjustment *adjustment, | ||
1092 | 560 | gpointer user_data) | ||
1093 | 561 | { | ||
1094 | 562 | OsScrollbar *scrollbar; | ||
1095 | 563 | OsScrollbarPrivate *priv; | ||
1096 | 564 | |||
1097 | 565 | scrollbar = OS_SCROLLBAR (user_data); | ||
1098 | 566 | priv = scrollbar->priv; | ||
1099 | 567 | |||
1100 | 568 | /* FIXME(Cimi) we should control each time os_pager_show()/hide() | ||
1101 | 569 | * is called here and in map()/unmap(). | ||
1102 | 570 | * We are arbitrary calling that and I'm frightened we should show or keep | ||
1103 | 571 | * hidden a pager that is meant to be hidden/shown. | ||
1104 | 572 | * I don't want to see pagers reappearing because | ||
1105 | 573 | * of a change in the adjustment of an invisible pager or viceversa. */ | ||
1106 | 574 | if ((adjustment->upper - adjustment->lower) > adjustment->page_size) | ||
1107 | 575 | { | ||
1108 | 576 | priv->fullsize = FALSE; | ||
1109 | 577 | if (priv->proximity != FALSE) | ||
1110 | 578 | os_pager_show (OS_PAGER (priv->pager)); | ||
1111 | 579 | } | ||
1112 | 580 | else | ||
1113 | 581 | { | ||
1114 | 582 | priv->fullsize = TRUE; | ||
1115 | 583 | if (priv->proximity != FALSE) | ||
1116 | 584 | { | ||
1117 | 585 | os_pager_hide (OS_PAGER (priv->pager)); | ||
1118 | 586 | |||
1119 | 587 | gtk_widget_hide (priv->thumb); | ||
1120 | 588 | } | ||
1121 | 589 | } | ||
1122 | 590 | |||
1123 | 591 | calc_layout_pager (scrollbar, adjustment->value); | ||
1124 | 592 | calc_layout_slider (scrollbar, adjustment->value); | ||
1125 | 593 | |||
1126 | 594 | if (!priv->motion_notify_event && !priv->enter_notify_event) | ||
1127 | 595 | gtk_widget_hide (GTK_WIDGET (priv->thumb)); | ||
1128 | 596 | |||
1129 | 597 | move_pager (scrollbar); | ||
1130 | 598 | } | ||
1131 | 599 | |||
1132 | 600 | static void | ||
1133 | 601 | adjustment_value_changed_cb (GtkAdjustment *adjustment, | ||
1134 | 602 | gpointer user_data) | ||
1135 | 603 | { | ||
1136 | 604 | OsScrollbar *scrollbar; | ||
1137 | 605 | OsScrollbarPrivate *priv; | ||
1138 | 606 | |||
1139 | 607 | scrollbar = OS_SCROLLBAR (user_data); | ||
1140 | 608 | priv = scrollbar->priv; | ||
1141 | 609 | |||
1142 | 610 | calc_layout_pager (scrollbar, adjustment->value); | ||
1143 | 611 | calc_layout_slider (scrollbar, adjustment->value); | ||
1144 | 612 | |||
1145 | 613 | if (!priv->motion_notify_event && !priv->enter_notify_event) | ||
1146 | 614 | gtk_widget_hide (GTK_WIDGET (priv->thumb)); | ||
1147 | 615 | |||
1148 | 616 | if (gtk_widget_get_mapped (GTK_WIDGET (priv->thumb))) | ||
1149 | 617 | { | ||
1150 | 618 | /* if we're dragging the thumb, it can't be detached. */ | ||
1151 | 619 | if (priv->motion_notify_event) | ||
1152 | 620 | { | ||
1153 | 621 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); | ||
1154 | 622 | os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE); | ||
1155 | 623 | } | ||
1156 | 624 | else | ||
1157 | 625 | { | ||
1158 | 626 | gint x_pos, y_pos; | ||
1159 | 627 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (priv->thumb)), &x_pos, &y_pos); | ||
1160 | 628 | |||
1161 | 629 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | ||
1162 | 630 | { | ||
1163 | 631 | if (priv->win_y + priv->overlay.y > y_pos + priv->slider.height) | ||
1164 | 632 | { | ||
1165 | 633 | GdkRectangle mask; | ||
1166 | 634 | |||
1167 | 635 | mask.x = 0; | ||
1168 | 636 | mask.y = y_pos + priv->slider.height / 2 - priv->win_y; | ||
1169 | 637 | mask.width = DEFAULT_PAGER_WIDTH; | ||
1170 | 638 | mask.height = priv->overlay.y - mask.y; | ||
1171 | 639 | |||
1172 | 640 | os_pager_connect (OS_PAGER (priv->pager), mask); | ||
1173 | 641 | os_pager_set_detached (OS_PAGER (priv->pager), TRUE); | ||
1174 | 642 | |||
1175 | 643 | os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE); | ||
1176 | 644 | } | ||
1177 | 645 | else if (priv->win_y + priv->overlay.y + priv->overlay.height < y_pos) | ||
1178 | 646 | { | ||
1179 | 647 | GdkRectangle mask; | ||
1180 | 648 | |||
1181 | 649 | mask.x = 0; | ||
1182 | 650 | mask.y = priv->overlay.y + priv->overlay.height; | ||
1183 | 651 | mask.width = DEFAULT_PAGER_WIDTH; | ||
1184 | 652 | mask.height = y_pos + priv->slider.height / 2 - priv->win_y - mask.y; | ||
1185 | 653 | |||
1186 | 654 | os_pager_connect (OS_PAGER (priv->pager), mask); | ||
1187 | 655 | os_pager_set_detached (OS_PAGER (priv->pager), TRUE); | ||
1188 | 656 | |||
1189 | 657 | os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE); | ||
1190 | 658 | } | ||
1191 | 659 | else | ||
1192 | 660 | { | ||
1193 | 661 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); | ||
1194 | 662 | os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE); | ||
1195 | 663 | } | ||
1196 | 664 | } | ||
1197 | 665 | else | ||
1198 | 666 | { | ||
1199 | 667 | if (priv->win_x + priv->overlay.x > x_pos + priv->slider.width) | ||
1200 | 668 | { | ||
1201 | 669 | GdkRectangle mask; | ||
1202 | 670 | |||
1203 | 671 | mask.x = x_pos + priv->slider.width / 2 - priv->win_x; | ||
1204 | 672 | mask.y = 0; | ||
1205 | 673 | mask.width = priv->overlay.x - mask.x; | ||
1206 | 674 | mask.height = DEFAULT_PAGER_WIDTH; | ||
1207 | 675 | |||
1208 | 676 | os_pager_connect (OS_PAGER (priv->pager), mask); | ||
1209 | 677 | os_pager_set_detached (OS_PAGER (priv->pager), TRUE); | ||
1210 | 678 | |||
1211 | 679 | os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE); | ||
1212 | 680 | } | ||
1213 | 681 | else if (priv->win_x + priv->overlay.x + priv->overlay.width < x_pos) | ||
1214 | 682 | { | ||
1215 | 683 | GdkRectangle mask; | ||
1216 | 684 | |||
1217 | 685 | mask.x = priv->overlay.y + priv->overlay.height; | ||
1218 | 686 | mask.y = 0; | ||
1219 | 687 | mask.width = x_pos + priv->slider.width / 2 - priv->win_x - mask.x; | ||
1220 | 688 | mask.height = DEFAULT_PAGER_WIDTH; | ||
1221 | 689 | |||
1222 | 690 | os_pager_connect (OS_PAGER (priv->pager), mask); | ||
1223 | 691 | os_pager_set_detached (OS_PAGER (priv->pager), TRUE); | ||
1224 | 692 | } | ||
1225 | 693 | else | ||
1226 | 694 | { | ||
1227 | 695 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); | ||
1228 | 696 | os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE); | ||
1229 | 697 | } | ||
1230 | 698 | } | ||
1231 | 699 | } | ||
1232 | 700 | } | ||
1233 | 701 | |||
1234 | 702 | move_pager (scrollbar); | ||
1235 | 703 | } | ||
1236 | 704 | |||
1237 | 705 | /* pager functions */ | ||
1238 | 706 | |||
1239 | 707 | /* set the state of the pager checking mouse position */ | ||
1240 | 708 | static void | ||
1241 | 709 | pager_set_state_from_pointer (OsScrollbar *scrollbar, | ||
1242 | 710 | gint x, | ||
1243 | 711 | gint y) | ||
1244 | 712 | { | ||
1245 | 713 | GtkAllocation allocation; | ||
1246 | 714 | OsScrollbarPrivate *priv; | ||
1247 | 715 | |||
1248 | 716 | priv = scrollbar->priv; | ||
1249 | 717 | |||
1250 | 718 | OS_DCHECK (!priv->active_window); | ||
1251 | 719 | |||
1252 | 720 | gtk_widget_get_allocation (gtk_widget_get_parent (GTK_WIDGET (scrollbar)), &allocation); | ||
1253 | 721 | |||
1254 | 722 | if ((x > allocation.x && x < allocation.x + allocation.width) && | ||
1255 | 723 | (y > allocation.y && y < allocation.y + allocation.height)) | ||
1256 | 724 | { | ||
1257 | 725 | priv->can_deactivate_pager = FALSE; | ||
1258 | 726 | os_pager_set_active (OS_PAGER (priv->pager), TRUE); | ||
1259 | 727 | } | ||
1260 | 728 | else | ||
1261 | 729 | { | ||
1262 | 730 | priv->can_deactivate_pager = TRUE; | ||
1263 | 731 | os_pager_set_active (OS_PAGER (priv->pager), FALSE); | ||
1264 | 732 | } | ||
1265 | 733 | } | ||
1266 | 734 | |||
1267 | 735 | /* root window functions */ | ||
1268 | 736 | |||
1269 | 737 | /* react on active window changes */ | ||
1270 | 738 | static void | ||
1271 | 739 | root_gfunc (gpointer data, | ||
1272 | 740 | gpointer user_data) | ||
1273 | 741 | { | ||
1274 | 742 | OsScrollbar *scrollbar; | ||
1275 | 743 | OsScrollbarPrivate *priv; | ||
1276 | 744 | |||
1277 | 745 | scrollbar = OS_SCROLLBAR (data); | ||
1278 | 746 | priv = scrollbar->priv; | ||
1279 | 747 | |||
1280 | 748 | OS_DCHECK (scrollbar != NULL); | ||
1281 | 749 | |||
1282 | 750 | if (gtk_widget_get_mapped (GTK_WIDGET (scrollbar))) | ||
1283 | 751 | { | ||
1284 | 752 | if (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar))) == | ||
1285 | 753 | gdk_screen_get_active_window (gtk_widget_get_screen (GTK_WIDGET (scrollbar)))) | ||
1286 | 754 | { | ||
1287 | 755 | /* stops potential running timeout. */ | ||
1288 | 756 | if (priv->source_deactivate_pager_id != 0) | ||
1289 | 757 | { | ||
1290 | 758 | g_source_remove (priv->source_deactivate_pager_id); | ||
1291 | 759 | priv->source_deactivate_pager_id = 0; | ||
1292 | 760 | } | ||
1293 | 761 | |||
1294 | 762 | priv->active_window = TRUE; | ||
1295 | 763 | |||
1296 | 764 | priv->can_deactivate_pager = FALSE; | ||
1297 | 765 | os_pager_set_active (OS_PAGER (priv->pager), TRUE); | ||
1298 | 766 | } | ||
1299 | 767 | else if (priv->active_window) | ||
1300 | 768 | { | ||
1301 | 769 | GdkWindow *parent; | ||
1302 | 770 | GdkWindow *window; | ||
1303 | 771 | const gint64 current_time = g_get_monotonic_time (); | ||
1304 | 772 | const gint64 end_time = priv->present_time + TIMEOUT_PRESENT_WINDOW * 1000; | ||
1305 | 773 | |||
1306 | 774 | priv->active_window = FALSE; | ||
1307 | 775 | |||
1308 | 776 | /* loop through parent windows until it reaches | ||
1309 | 777 | * either an unknown GdkWindow (NULL), | ||
1310 | 778 | * or the toplevel window. */ | ||
1311 | 779 | window = gtk_widget_get_window (GTK_WIDGET (scrollbar)); | ||
1312 | 780 | parent = gdk_window_at_pointer (NULL, NULL); | ||
1313 | 781 | while (parent != NULL) | ||
1314 | 782 | { | ||
1315 | 783 | if (window == parent) | ||
1316 | 784 | break; | ||
1317 | 785 | |||
1318 | 786 | parent = gdk_window_get_parent (parent); | ||
1319 | 787 | } | ||
1320 | 788 | |||
1321 | 789 | if (parent != NULL) | ||
1322 | 790 | { | ||
1323 | 791 | gint x, y; | ||
1324 | 792 | |||
1325 | 793 | gdk_window_get_pointer (window, &x, &y, NULL); | ||
1326 | 794 | |||
1327 | 795 | /* when the window is unfocused, | ||
1328 | 796 | * check the position of the pointer | ||
1329 | 797 | * and set the state accordingly. */ | ||
1330 | 798 | pager_set_state_from_pointer (scrollbar, x, y); | ||
1331 | 799 | } | ||
1332 | 800 | else | ||
1333 | 801 | { | ||
1334 | 802 | /* if the pointer is outside of the window, set it inactive. */ | ||
1335 | 803 | priv->can_deactivate_pager = TRUE; | ||
1336 | 804 | os_pager_set_active (OS_PAGER (priv->pager), FALSE); | ||
1337 | 805 | } | ||
1338 | 806 | |||
1339 | 807 | if ((current_time > end_time) && priv->thumb != NULL) | ||
1340 | 808 | gtk_widget_hide (priv->thumb); | ||
1341 | 809 | } | ||
1342 | 810 | } | ||
1343 | 811 | } | ||
1344 | 812 | |||
1345 | 813 | /* filter function applied to the root window */ | ||
1346 | 814 | static GdkFilterReturn | ||
1347 | 815 | root_filter_func (GdkXEvent *gdkxevent, | ||
1348 | 816 | GdkEvent *event, | ||
1349 | 817 | gpointer user_data) | ||
1350 | 818 | { | ||
1351 | 819 | XEvent* xev; | ||
1352 | 820 | |||
1353 | 821 | xev = gdkxevent; | ||
1354 | 822 | |||
1355 | 823 | if (xev->xany.type == PropertyNotify && | ||
1356 | 824 | xev->xproperty.atom == net_active_window_atom) | ||
1357 | 825 | { | ||
1358 | 826 | g_list_foreach (os_root_list, root_gfunc, NULL); | ||
1359 | 827 | } | ||
1360 | 828 | |||
1361 | 829 | return GDK_FILTER_CONTINUE; | ||
1362 | 830 | } | ||
1363 | 831 | |||
1364 | 832 | /* thumb functions */ | ||
1365 | 833 | |||
1366 | 834 | /* present a X11 window */ | ||
1367 | 835 | static void | ||
1368 | 836 | present_window_with_timestamp (Screen *screen, | ||
1369 | 837 | gint xid, | ||
1370 | 838 | guint32 timestamp) | ||
1371 | 839 | { | ||
1372 | 840 | Display *display; | ||
1373 | 841 | Window root; | ||
1374 | 842 | XEvent xev; | ||
1375 | 843 | |||
1376 | 844 | if (timestamp == 0) | ||
1377 | 845 | g_warning ("Received a timestamp of 0; window activation may not " | ||
1378 | 846 | "function properly.\n"); | ||
1379 | 847 | |||
1380 | 848 | display = DisplayOfScreen (screen); | ||
1381 | 849 | root = RootWindowOfScreen (screen); | ||
1382 | 850 | |||
1383 | 851 | xev.xclient.type = ClientMessage; | ||
1384 | 852 | xev.xclient.serial = 0; | ||
1385 | 853 | xev.xclient.send_event = True; | ||
1386 | 854 | xev.xclient.display = display; | ||
1387 | 855 | xev.xclient.window = xid; | ||
1388 | 856 | xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW"); | ||
1389 | 857 | xev.xclient.format = 32; | ||
1390 | 858 | xev.xclient.data.l[0] = 1; | ||
1391 | 859 | xev.xclient.data.l[1] = timestamp; | ||
1392 | 860 | xev.xclient.data.l[2] = 0; | ||
1393 | 861 | xev.xclient.data.l[3] = 0; | ||
1394 | 862 | xev.xclient.data.l[4] = 0; | ||
1395 | 863 | |||
1396 | 864 | gdk_error_trap_push (); | ||
1397 | 865 | |||
1398 | 866 | XSendEvent (display, root, False, | ||
1399 | 867 | SubstructureRedirectMask | SubstructureNotifyMask, | ||
1400 | 868 | &xev); | ||
1401 | 869 | |||
1402 | 870 | gdk_flush (); | ||
1403 | 871 | |||
1404 | 872 | gdk_error_trap_pop (); | ||
1405 | 873 | } | ||
1406 | 874 | |||
1407 | 875 | /* present a Gdk window */ | ||
1408 | 876 | static void | ||
1409 | 877 | present_gdk_window_with_timestamp (GtkWidget *widget, | ||
1410 | 878 | guint32 timestamp) | ||
1411 | 879 | { | ||
1412 | 880 | present_window_with_timestamp (GDK_SCREEN_XSCREEN (gtk_widget_get_screen (widget)), | ||
1413 | 881 | GDK_WINDOW_XID (gtk_widget_get_window (widget)), | ||
1414 | 882 | timestamp); | ||
1415 | 883 | } | ||
1416 | 884 | |||
1417 | 700 | static gboolean | 885 | static gboolean |
1418 | 701 | thumb_button_press_event_cb (GtkWidget *widget, | 886 | thumb_button_press_event_cb (GtkWidget *widget, |
1419 | 702 | GdkEventButton *event, | 887 | GdkEventButton *event, |
1420 | @@ -716,7 +901,7 @@ | |||
1421 | 716 | GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar)))); | 901 | GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar)))); |
1422 | 717 | 902 | ||
1423 | 718 | priv->present_time = g_get_monotonic_time (); | 903 | priv->present_time = g_get_monotonic_time (); |
1425 | 719 | os_present_gdk_window_with_timestamp (GTK_WIDGET (scrollbar), event->time); | 904 | present_gdk_window_with_timestamp (GTK_WIDGET (scrollbar), event->time); |
1426 | 720 | 905 | ||
1427 | 721 | priv->button_press_event = TRUE; | 906 | priv->button_press_event = TRUE; |
1428 | 722 | priv->motion_notify_event = FALSE; | 907 | priv->motion_notify_event = FALSE; |
1429 | @@ -830,7 +1015,7 @@ | |||
1430 | 830 | g_source_remove (priv->source_deactivate_pager_id); | 1015 | g_source_remove (priv->source_deactivate_pager_id); |
1431 | 831 | 1016 | ||
1432 | 832 | priv->source_deactivate_pager_id = g_timeout_add (TIMEOUT_THUMB_HIDE, | 1017 | priv->source_deactivate_pager_id = g_timeout_add (TIMEOUT_THUMB_HIDE, |
1434 | 833 | os_scrollbar_deactivate_pager_cb, | 1018 | deactivate_pager_cb, |
1435 | 834 | scrollbar); | 1019 | scrollbar); |
1436 | 835 | } | 1020 | } |
1437 | 836 | 1021 | ||
1438 | @@ -840,7 +1025,7 @@ | |||
1439 | 840 | g_source_remove (priv->source_hide_thumb_id); | 1025 | g_source_remove (priv->source_hide_thumb_id); |
1440 | 841 | 1026 | ||
1441 | 842 | priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_THUMB_HIDE, | 1027 | priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_THUMB_HIDE, |
1443 | 843 | os_scrollbar_hide_thumb_cb, | 1028 | hide_thumb_cb, |
1444 | 844 | scrollbar); | 1029 | scrollbar); |
1445 | 845 | } | 1030 | } |
1446 | 846 | 1031 | ||
1447 | @@ -916,6 +1101,73 @@ | |||
1448 | 916 | } | 1101 | } |
1449 | 917 | } | 1102 | } |
1450 | 918 | 1103 | ||
1451 | 1104 | /* traduce coordinates into GtkRange values */ | ||
1452 | 1105 | static gdouble | ||
1453 | 1106 | coord_to_value (OsScrollbar *scrollbar, | ||
1454 | 1107 | gint coord) | ||
1455 | 1108 | { | ||
1456 | 1109 | OsScrollbarPrivate *priv; | ||
1457 | 1110 | gdouble frac; | ||
1458 | 1111 | gdouble value; | ||
1459 | 1112 | gint trough_length; | ||
1460 | 1113 | gint trough_start; | ||
1461 | 1114 | gint slider_length; | ||
1462 | 1115 | |||
1463 | 1116 | priv = scrollbar->priv; | ||
1464 | 1117 | |||
1465 | 1118 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | ||
1466 | 1119 | { | ||
1467 | 1120 | trough_length = priv->trough.height; | ||
1468 | 1121 | trough_start = priv->trough.y; | ||
1469 | 1122 | slider_length = MAX (priv->slider.height, priv->overlay.height); | ||
1470 | 1123 | } | ||
1471 | 1124 | else | ||
1472 | 1125 | { | ||
1473 | 1126 | trough_length = priv->trough.width; | ||
1474 | 1127 | trough_start = priv->trough.y; | ||
1475 | 1128 | slider_length = MAX (priv->slider.width, priv->overlay.width); | ||
1476 | 1129 | } | ||
1477 | 1130 | |||
1478 | 1131 | if (trough_length == slider_length) | ||
1479 | 1132 | frac = 1.0; | ||
1480 | 1133 | else | ||
1481 | 1134 | frac = (MAX (0, coord - trough_start) / | ||
1482 | 1135 | (gdouble) (trough_length - slider_length)); | ||
1483 | 1136 | |||
1484 | 1137 | value = priv->adjustment->lower + frac * (priv->adjustment->upper - | ||
1485 | 1138 | priv->adjustment->lower - | ||
1486 | 1139 | priv->adjustment->page_size); | ||
1487 | 1140 | |||
1488 | 1141 | value = CLAMP (value, priv->adjustment->lower, priv->adjustment->upper - priv->adjustment->page_size); | ||
1489 | 1142 | |||
1490 | 1143 | return value; | ||
1491 | 1144 | } | ||
1492 | 1145 | |||
1493 | 1146 | /* from pointer movement, set GtkRange value */ | ||
1494 | 1147 | static void | ||
1495 | 1148 | capture_movement (OsScrollbar *scrollbar, | ||
1496 | 1149 | gint mouse_x, | ||
1497 | 1150 | gint mouse_y) | ||
1498 | 1151 | { | ||
1499 | 1152 | OsScrollbarPrivate *priv; | ||
1500 | 1153 | gint delta; | ||
1501 | 1154 | gint c; | ||
1502 | 1155 | gdouble new_value; | ||
1503 | 1156 | |||
1504 | 1157 | priv = scrollbar->priv; | ||
1505 | 1158 | |||
1506 | 1159 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | ||
1507 | 1160 | delta = mouse_y - priv->slide_initial_coordinate; | ||
1508 | 1161 | else | ||
1509 | 1162 | delta = mouse_x - priv->slide_initial_coordinate; | ||
1510 | 1163 | |||
1511 | 1164 | c = priv->slide_initial_slider_position + delta; | ||
1512 | 1165 | |||
1513 | 1166 | new_value = coord_to_value (scrollbar, c); | ||
1514 | 1167 | |||
1515 | 1168 | gtk_adjustment_set_value (priv->adjustment, new_value); | ||
1516 | 1169 | } | ||
1517 | 1170 | |||
1518 | 919 | static gboolean | 1171 | static gboolean |
1519 | 920 | thumb_motion_notify_event_cb (GtkWidget *widget, | 1172 | thumb_motion_notify_event_cb (GtkWidget *widget, |
1520 | 921 | GdkEventMotion *event, | 1173 | GdkEventMotion *event, |
1521 | @@ -945,13 +1197,14 @@ | |||
1522 | 945 | priv->slide_initial_coordinate = event->x_root; | 1197 | priv->slide_initial_coordinate = event->x_root; |
1523 | 946 | } | 1198 | } |
1524 | 947 | 1199 | ||
1526 | 948 | os_scrollbar_move (scrollbar, event->x_root, event->y_root); | 1200 | /* FIXME(Cimi) seems useless. */ |
1527 | 1201 | capture_movement (scrollbar, event->x_root, event->y_root); | ||
1528 | 949 | priv->value_changed_event = FALSE; | 1202 | priv->value_changed_event = FALSE; |
1529 | 950 | } | 1203 | } |
1530 | 951 | 1204 | ||
1531 | 952 | priv->motion_notify_event = TRUE; | 1205 | priv->motion_notify_event = TRUE; |
1532 | 953 | 1206 | ||
1534 | 954 | os_scrollbar_move (scrollbar, event->x_root, event->y_root); | 1207 | capture_movement (scrollbar, event->x_root, event->y_root); |
1535 | 955 | 1208 | ||
1536 | 956 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | 1209 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
1537 | 957 | { | 1210 | { |
1538 | @@ -1006,12 +1259,31 @@ | |||
1539 | 1006 | } | 1259 | } |
1540 | 1007 | } | 1260 | } |
1541 | 1008 | 1261 | ||
1543 | 1009 | os_scrollbar_move_thumb (scrollbar, x, y); | 1262 | move_thumb (scrollbar, x, y); |
1544 | 1010 | } | 1263 | } |
1545 | 1011 | 1264 | ||
1546 | 1012 | return FALSE; | 1265 | return FALSE; |
1547 | 1013 | } | 1266 | } |
1548 | 1014 | 1267 | ||
1549 | 1268 | /* mouse wheel delta */ | ||
1550 | 1269 | static gdouble | ||
1551 | 1270 | get_wheel_delta (OsScrollbar *scrollbar, | ||
1552 | 1271 | GdkScrollDirection direction) | ||
1553 | 1272 | { | ||
1554 | 1273 | OsScrollbarPrivate *priv; | ||
1555 | 1274 | gdouble delta; | ||
1556 | 1275 | |||
1557 | 1276 | priv = scrollbar->priv; | ||
1558 | 1277 | |||
1559 | 1278 | delta = pow (priv->adjustment->page_size, 2.0 / 3.0); | ||
1560 | 1279 | |||
1561 | 1280 | if (direction == GDK_SCROLL_UP || | ||
1562 | 1281 | direction == GDK_SCROLL_LEFT) | ||
1563 | 1282 | delta = - delta; | ||
1564 | 1283 | |||
1565 | 1284 | return delta; | ||
1566 | 1285 | } | ||
1567 | 1286 | |||
1568 | 1015 | static gboolean | 1287 | static gboolean |
1569 | 1016 | thumb_scroll_event_cb (GtkWidget *widget, | 1288 | thumb_scroll_event_cb (GtkWidget *widget, |
1570 | 1017 | GdkEventScroll *event, | 1289 | GdkEventScroll *event, |
1571 | @@ -1026,7 +1298,7 @@ | |||
1572 | 1026 | 1298 | ||
1573 | 1027 | priv->value_changed_event = TRUE; | 1299 | priv->value_changed_event = TRUE; |
1574 | 1028 | 1300 | ||
1576 | 1029 | delta = os_scrollbar_get_wheel_delta (scrollbar, event->direction); | 1301 | delta = get_wheel_delta (scrollbar, event->direction); |
1577 | 1030 | 1302 | ||
1578 | 1031 | gtk_adjustment_set_value (priv->adjustment, | 1303 | gtk_adjustment_set_value (priv->adjustment, |
1579 | 1032 | CLAMP (priv->adjustment->value + delta, | 1304 | CLAMP (priv->adjustment->value + delta, |
1580 | @@ -1054,297 +1326,30 @@ | |||
1581 | 1054 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); | 1326 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); |
1582 | 1055 | } | 1327 | } |
1583 | 1056 | 1328 | ||
1585 | 1057 | /* Move the pager to the right position. */ | 1329 | /* toplevel functions */ |
1586 | 1330 | |||
1587 | 1331 | /* store the position of the toplevel window */ | ||
1588 | 1058 | static void | 1332 | static void |
1590 | 1059 | pager_move (OsScrollbar *scrollbar) | 1333 | store_toplevel_position (OsScrollbar *scrollbar) |
1591 | 1060 | { | 1334 | { |
1592 | 1061 | GdkRectangle mask; | ||
1593 | 1062 | OsScrollbarPrivate *priv; | 1335 | OsScrollbarPrivate *priv; |
1594 | 1336 | gint win_x, win_y; | ||
1595 | 1063 | 1337 | ||
1596 | 1064 | priv = scrollbar->priv; | 1338 | priv = scrollbar->priv; |
1597 | 1065 | 1339 | ||
1598 | 1340 | /* In reality, I'm storing widget's window, not the toplevel. | ||
1599 | 1341 | * Is that the same with gdk_window_get_origin? */ | ||
1600 | 1342 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &win_x, &win_y); | ||
1601 | 1343 | |||
1602 | 1066 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | 1344 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
1603 | 1067 | { | 1345 | { |
1884 | 1068 | mask.x = 0; | 1346 | priv->win_x = win_x + priv->thumb_all.x; |
1885 | 1069 | mask.y = priv->overlay.y; | 1347 | priv->win_y = win_y + priv->thumb_all.y; |
1886 | 1070 | mask.width = DEFAULT_PAGER_WIDTH; | 1348 | } |
1887 | 1071 | mask.height = priv->overlay.height; | 1349 | else |
1888 | 1072 | } | 1350 | { |
1889 | 1073 | else | 1351 | priv->win_x = win_x + priv->thumb_all.x; |
1890 | 1074 | { | 1352 | priv->win_y = win_y + priv->thumb_all.y; |
1611 | 1075 | mask.x = priv->overlay.x; | ||
1612 | 1076 | mask.y = 0; | ||
1613 | 1077 | mask.width = priv->overlay.width; | ||
1614 | 1078 | mask.height = DEFAULT_PAGER_WIDTH; | ||
1615 | 1079 | } | ||
1616 | 1080 | |||
1617 | 1081 | os_pager_move_resize (OS_PAGER (priv->pager), mask); | ||
1618 | 1082 | } | ||
1619 | 1083 | |||
1620 | 1084 | static void | ||
1621 | 1085 | pager_set_state_from_pointer (OsScrollbar *scrollbar, | ||
1622 | 1086 | gint x, | ||
1623 | 1087 | gint y) | ||
1624 | 1088 | { | ||
1625 | 1089 | GtkAllocation allocation; | ||
1626 | 1090 | OsScrollbarPrivate *priv; | ||
1627 | 1091 | |||
1628 | 1092 | priv = scrollbar->priv; | ||
1629 | 1093 | |||
1630 | 1094 | OS_DCHECK (!priv->active_window); | ||
1631 | 1095 | |||
1632 | 1096 | gtk_widget_get_allocation (gtk_widget_get_parent (GTK_WIDGET (scrollbar)), &allocation); | ||
1633 | 1097 | |||
1634 | 1098 | if ((x > allocation.x && x < allocation.x + allocation.width) && | ||
1635 | 1099 | (y > allocation.y && y < allocation.y + allocation.height)) | ||
1636 | 1100 | { | ||
1637 | 1101 | priv->can_deactivate_pager = FALSE; | ||
1638 | 1102 | os_pager_set_active (OS_PAGER (priv->pager), TRUE); | ||
1639 | 1103 | } | ||
1640 | 1104 | else | ||
1641 | 1105 | { | ||
1642 | 1106 | priv->can_deactivate_pager = TRUE; | ||
1643 | 1107 | os_pager_set_active (OS_PAGER (priv->pager), FALSE); | ||
1644 | 1108 | } | ||
1645 | 1109 | } | ||
1646 | 1110 | |||
1647 | 1111 | static void | ||
1648 | 1112 | adjustment_changed_cb (GtkAdjustment *adjustment, | ||
1649 | 1113 | gpointer user_data) | ||
1650 | 1114 | { | ||
1651 | 1115 | OsScrollbar *scrollbar; | ||
1652 | 1116 | OsScrollbarPrivate *priv; | ||
1653 | 1117 | |||
1654 | 1118 | scrollbar = OS_SCROLLBAR (user_data); | ||
1655 | 1119 | priv = scrollbar->priv; | ||
1656 | 1120 | |||
1657 | 1121 | /* FIXME(Cimi) we should control each time os_pager_show()/hide() | ||
1658 | 1122 | * is called here and in map()/unmap(). | ||
1659 | 1123 | * We are arbitrary calling that and I'm frightened we should show or keep | ||
1660 | 1124 | * hidden a pager that is meant to be hidden/shown. | ||
1661 | 1125 | * I don't want to see pagers reappearing because | ||
1662 | 1126 | * of a change in the adjustment of an invisible pager or viceversa. */ | ||
1663 | 1127 | if ((adjustment->upper - adjustment->lower) > adjustment->page_size) | ||
1664 | 1128 | { | ||
1665 | 1129 | priv->fullsize = FALSE; | ||
1666 | 1130 | if (priv->proximity != FALSE) | ||
1667 | 1131 | os_pager_show (OS_PAGER (priv->pager)); | ||
1668 | 1132 | } | ||
1669 | 1133 | else | ||
1670 | 1134 | { | ||
1671 | 1135 | priv->fullsize = TRUE; | ||
1672 | 1136 | if (priv->proximity != FALSE) | ||
1673 | 1137 | { | ||
1674 | 1138 | os_pager_hide (OS_PAGER (priv->pager)); | ||
1675 | 1139 | |||
1676 | 1140 | gtk_widget_hide (priv->thumb); | ||
1677 | 1141 | } | ||
1678 | 1142 | } | ||
1679 | 1143 | |||
1680 | 1144 | os_scrollbar_calc_layout_pager (scrollbar, adjustment->value); | ||
1681 | 1145 | os_scrollbar_calc_layout_slider (scrollbar, adjustment->value); | ||
1682 | 1146 | |||
1683 | 1147 | if (!priv->motion_notify_event && !priv->enter_notify_event) | ||
1684 | 1148 | gtk_widget_hide (GTK_WIDGET (priv->thumb)); | ||
1685 | 1149 | |||
1686 | 1150 | pager_move (scrollbar); | ||
1687 | 1151 | } | ||
1688 | 1152 | |||
1689 | 1153 | static void | ||
1690 | 1154 | adjustment_value_changed_cb (GtkAdjustment *adjustment, | ||
1691 | 1155 | gpointer user_data) | ||
1692 | 1156 | { | ||
1693 | 1157 | OsScrollbar *scrollbar; | ||
1694 | 1158 | OsScrollbarPrivate *priv; | ||
1695 | 1159 | |||
1696 | 1160 | scrollbar = OS_SCROLLBAR (user_data); | ||
1697 | 1161 | priv = scrollbar->priv; | ||
1698 | 1162 | |||
1699 | 1163 | os_scrollbar_calc_layout_pager (scrollbar, adjustment->value); | ||
1700 | 1164 | os_scrollbar_calc_layout_slider (scrollbar, adjustment->value); | ||
1701 | 1165 | |||
1702 | 1166 | if (!priv->motion_notify_event && !priv->enter_notify_event) | ||
1703 | 1167 | gtk_widget_hide (GTK_WIDGET (priv->thumb)); | ||
1704 | 1168 | |||
1705 | 1169 | if (gtk_widget_get_mapped (GTK_WIDGET (priv->thumb))) | ||
1706 | 1170 | { | ||
1707 | 1171 | /* if we're dragging the thumb, it can't be detached. */ | ||
1708 | 1172 | if (priv->motion_notify_event) | ||
1709 | 1173 | { | ||
1710 | 1174 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); | ||
1711 | 1175 | os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE); | ||
1712 | 1176 | } | ||
1713 | 1177 | else | ||
1714 | 1178 | { | ||
1715 | 1179 | gint x_pos, y_pos; | ||
1716 | 1180 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (priv->thumb)), &x_pos, &y_pos); | ||
1717 | 1181 | |||
1718 | 1182 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | ||
1719 | 1183 | { | ||
1720 | 1184 | if (priv->win_y + priv->overlay.y > y_pos + priv->slider.height) | ||
1721 | 1185 | { | ||
1722 | 1186 | GdkRectangle mask; | ||
1723 | 1187 | |||
1724 | 1188 | mask.x = 0; | ||
1725 | 1189 | mask.y = y_pos + priv->slider.height / 2 - priv->win_y; | ||
1726 | 1190 | mask.width = DEFAULT_PAGER_WIDTH; | ||
1727 | 1191 | mask.height = priv->overlay.y - mask.y; | ||
1728 | 1192 | |||
1729 | 1193 | os_pager_connect (OS_PAGER (priv->pager), mask); | ||
1730 | 1194 | os_pager_set_detached (OS_PAGER (priv->pager), TRUE); | ||
1731 | 1195 | |||
1732 | 1196 | os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE); | ||
1733 | 1197 | } | ||
1734 | 1198 | else if (priv->win_y + priv->overlay.y + priv->overlay.height < y_pos) | ||
1735 | 1199 | { | ||
1736 | 1200 | GdkRectangle mask; | ||
1737 | 1201 | |||
1738 | 1202 | mask.x = 0; | ||
1739 | 1203 | mask.y = priv->overlay.y + priv->overlay.height; | ||
1740 | 1204 | mask.width = DEFAULT_PAGER_WIDTH; | ||
1741 | 1205 | mask.height = y_pos + priv->slider.height / 2 - priv->win_y - mask.y; | ||
1742 | 1206 | |||
1743 | 1207 | os_pager_connect (OS_PAGER (priv->pager), mask); | ||
1744 | 1208 | os_pager_set_detached (OS_PAGER (priv->pager), TRUE); | ||
1745 | 1209 | |||
1746 | 1210 | os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE); | ||
1747 | 1211 | } | ||
1748 | 1212 | else | ||
1749 | 1213 | { | ||
1750 | 1214 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); | ||
1751 | 1215 | os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE); | ||
1752 | 1216 | } | ||
1753 | 1217 | } | ||
1754 | 1218 | else | ||
1755 | 1219 | { | ||
1756 | 1220 | if (priv->win_x + priv->overlay.x > x_pos + priv->slider.width) | ||
1757 | 1221 | { | ||
1758 | 1222 | GdkRectangle mask; | ||
1759 | 1223 | |||
1760 | 1224 | mask.x = x_pos + priv->slider.width / 2 - priv->win_x; | ||
1761 | 1225 | mask.y = 0; | ||
1762 | 1226 | mask.width = priv->overlay.x - mask.x; | ||
1763 | 1227 | mask.height = DEFAULT_PAGER_WIDTH; | ||
1764 | 1228 | |||
1765 | 1229 | os_pager_connect (OS_PAGER (priv->pager), mask); | ||
1766 | 1230 | os_pager_set_detached (OS_PAGER (priv->pager), TRUE); | ||
1767 | 1231 | |||
1768 | 1232 | os_thumb_set_detached (OS_THUMB (priv->thumb), TRUE); | ||
1769 | 1233 | } | ||
1770 | 1234 | else if (priv->win_x + priv->overlay.x + priv->overlay.width < x_pos) | ||
1771 | 1235 | { | ||
1772 | 1236 | GdkRectangle mask; | ||
1773 | 1237 | |||
1774 | 1238 | mask.x = priv->overlay.y + priv->overlay.height; | ||
1775 | 1239 | mask.y = 0; | ||
1776 | 1240 | mask.width = x_pos + priv->slider.width / 2 - priv->win_x - mask.x; | ||
1777 | 1241 | mask.height = DEFAULT_PAGER_WIDTH; | ||
1778 | 1242 | |||
1779 | 1243 | os_pager_connect (OS_PAGER (priv->pager), mask); | ||
1780 | 1244 | os_pager_set_detached (OS_PAGER (priv->pager), TRUE); | ||
1781 | 1245 | } | ||
1782 | 1246 | else | ||
1783 | 1247 | { | ||
1784 | 1248 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); | ||
1785 | 1249 | os_thumb_set_detached (OS_THUMB (priv->thumb), FALSE); | ||
1786 | 1250 | } | ||
1787 | 1251 | } | ||
1788 | 1252 | } | ||
1789 | 1253 | } | ||
1790 | 1254 | |||
1791 | 1255 | pager_move (scrollbar); | ||
1792 | 1256 | } | ||
1793 | 1257 | |||
1794 | 1258 | static GdkFilterReturn | ||
1795 | 1259 | root_filter_func (GdkXEvent *gdkxevent, | ||
1796 | 1260 | GdkEvent *event, | ||
1797 | 1261 | gpointer user_data) | ||
1798 | 1262 | { | ||
1799 | 1263 | XEvent* xevent; | ||
1800 | 1264 | |||
1801 | 1265 | xevent = gdkxevent; | ||
1802 | 1266 | |||
1803 | 1267 | if (xevent->xany.type == PropertyNotify && | ||
1804 | 1268 | xevent->xproperty.atom == net_active_window_atom) | ||
1805 | 1269 | { | ||
1806 | 1270 | g_list_foreach (os_root_list, root_gfunc, NULL); | ||
1807 | 1271 | } | ||
1808 | 1272 | |||
1809 | 1273 | return GDK_FILTER_CONTINUE; | ||
1810 | 1274 | } | ||
1811 | 1275 | |||
1812 | 1276 | static void | ||
1813 | 1277 | root_gfunc (gpointer data, | ||
1814 | 1278 | gpointer user_data) | ||
1815 | 1279 | { | ||
1816 | 1280 | OsScrollbar *scrollbar; | ||
1817 | 1281 | OsScrollbarPrivate *priv; | ||
1818 | 1282 | |||
1819 | 1283 | scrollbar = OS_SCROLLBAR (data); | ||
1820 | 1284 | priv = scrollbar->priv; | ||
1821 | 1285 | |||
1822 | 1286 | OS_DCHECK (scrollbar != NULL); | ||
1823 | 1287 | |||
1824 | 1288 | if (gtk_widget_get_mapped (GTK_WIDGET (scrollbar))) | ||
1825 | 1289 | { | ||
1826 | 1290 | if (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar))) == | ||
1827 | 1291 | gdk_screen_get_active_window (gtk_widget_get_screen (GTK_WIDGET (scrollbar)))) | ||
1828 | 1292 | { | ||
1829 | 1293 | /* stops potential running timeout. */ | ||
1830 | 1294 | if (priv->source_deactivate_pager_id != 0) | ||
1831 | 1295 | { | ||
1832 | 1296 | g_source_remove (priv->source_deactivate_pager_id); | ||
1833 | 1297 | priv->source_deactivate_pager_id = 0; | ||
1834 | 1298 | } | ||
1835 | 1299 | |||
1836 | 1300 | priv->active_window = TRUE; | ||
1837 | 1301 | |||
1838 | 1302 | priv->can_deactivate_pager = FALSE; | ||
1839 | 1303 | os_pager_set_active (OS_PAGER (priv->pager), TRUE); | ||
1840 | 1304 | } | ||
1841 | 1305 | else if (priv->active_window) | ||
1842 | 1306 | { | ||
1843 | 1307 | GdkWindow *parent; | ||
1844 | 1308 | GdkWindow *window; | ||
1845 | 1309 | const gint64 current_time = g_get_monotonic_time (); | ||
1846 | 1310 | const gint64 end_time = priv->present_time + TIMEOUT_PRESENT_WINDOW * 1000; | ||
1847 | 1311 | |||
1848 | 1312 | priv->active_window = FALSE; | ||
1849 | 1313 | |||
1850 | 1314 | /* loop through parent windows until it reaches | ||
1851 | 1315 | * either an unknown GdkWindow (NULL), | ||
1852 | 1316 | * or the toplevel window. */ | ||
1853 | 1317 | window = gtk_widget_get_window (GTK_WIDGET (scrollbar)); | ||
1854 | 1318 | parent = gdk_window_at_pointer (NULL, NULL); | ||
1855 | 1319 | while (parent != NULL) | ||
1856 | 1320 | { | ||
1857 | 1321 | if (window == parent) | ||
1858 | 1322 | break; | ||
1859 | 1323 | |||
1860 | 1324 | parent = gdk_window_get_parent (parent); | ||
1861 | 1325 | } | ||
1862 | 1326 | |||
1863 | 1327 | if (parent != NULL) | ||
1864 | 1328 | { | ||
1865 | 1329 | gint x, y; | ||
1866 | 1330 | |||
1867 | 1331 | gdk_window_get_pointer (window, &x, &y, NULL); | ||
1868 | 1332 | |||
1869 | 1333 | /* when the window is unfocused, | ||
1870 | 1334 | * check the position of the pointer | ||
1871 | 1335 | * and set the state accordingly. */ | ||
1872 | 1336 | pager_set_state_from_pointer (scrollbar, x, y); | ||
1873 | 1337 | } | ||
1874 | 1338 | else | ||
1875 | 1339 | { | ||
1876 | 1340 | /* if the pointer is outside of the window, set it inactive. */ | ||
1877 | 1341 | priv->can_deactivate_pager = TRUE; | ||
1878 | 1342 | os_pager_set_active (OS_PAGER (priv->pager), FALSE); | ||
1879 | 1343 | } | ||
1880 | 1344 | |||
1881 | 1345 | if ((current_time > end_time) && priv->thumb != NULL) | ||
1882 | 1346 | gtk_widget_hide (priv->thumb); | ||
1883 | 1347 | } | ||
1891 | 1348 | } | 1353 | } |
1892 | 1349 | } | 1354 | } |
1893 | 1350 | 1355 | ||
1894 | @@ -1405,15 +1410,15 @@ | |||
1895 | 1405 | 1410 | ||
1896 | 1406 | priv->lock_position = FALSE; | 1411 | priv->lock_position = FALSE; |
1897 | 1407 | 1412 | ||
1900 | 1408 | os_scrollbar_calc_layout_pager (scrollbar, priv->adjustment->value); | 1413 | calc_layout_pager (scrollbar, priv->adjustment->value); |
1901 | 1409 | os_scrollbar_calc_layout_slider (scrollbar, priv->adjustment->value); | 1414 | calc_layout_slider (scrollbar, priv->adjustment->value); |
1902 | 1410 | 1415 | ||
1904 | 1411 | os_scrollbar_store_window_position (scrollbar); | 1416 | store_toplevel_position (scrollbar); |
1905 | 1412 | 1417 | ||
1906 | 1413 | return FALSE; | 1418 | return FALSE; |
1907 | 1414 | } | 1419 | } |
1908 | 1415 | 1420 | ||
1910 | 1416 | /* Add a filter to the toplevel GdkWindow, to activate proximity effect. */ | 1421 | /* filter function applied to the toplevel window */ |
1911 | 1417 | static GdkFilterReturn | 1422 | static GdkFilterReturn |
1912 | 1418 | toplevel_filter_func (GdkXEvent *gdkxevent, | 1423 | toplevel_filter_func (GdkXEvent *gdkxevent, |
1913 | 1419 | GdkEvent *event, | 1424 | GdkEvent *event, |
1914 | @@ -1421,37 +1426,37 @@ | |||
1915 | 1421 | { | 1426 | { |
1916 | 1422 | OsScrollbar *scrollbar; | 1427 | OsScrollbar *scrollbar; |
1917 | 1423 | OsScrollbarPrivate *priv; | 1428 | OsScrollbarPrivate *priv; |
1919 | 1424 | XEvent *xevent; | 1429 | XEvent *xev; |
1920 | 1425 | 1430 | ||
1921 | 1426 | g_return_val_if_fail (OS_SCROLLBAR (user_data), GDK_FILTER_CONTINUE); | 1431 | g_return_val_if_fail (OS_SCROLLBAR (user_data), GDK_FILTER_CONTINUE); |
1922 | 1427 | 1432 | ||
1923 | 1428 | scrollbar = OS_SCROLLBAR (user_data); | 1433 | scrollbar = OS_SCROLLBAR (user_data); |
1924 | 1429 | 1434 | ||
1925 | 1430 | priv = scrollbar->priv; | 1435 | priv = scrollbar->priv; |
1927 | 1431 | xevent = gdkxevent; | 1436 | xev = gdkxevent; |
1928 | 1432 | 1437 | ||
1929 | 1433 | g_return_val_if_fail (priv->pager != NULL, GDK_FILTER_CONTINUE); | 1438 | g_return_val_if_fail (priv->pager != NULL, GDK_FILTER_CONTINUE); |
1930 | 1434 | g_return_val_if_fail (priv->thumb != NULL, GDK_FILTER_CONTINUE); | 1439 | g_return_val_if_fail (priv->thumb != NULL, GDK_FILTER_CONTINUE); |
1931 | 1435 | 1440 | ||
1932 | 1436 | if (!priv->fullsize) | 1441 | if (!priv->fullsize) |
1933 | 1437 | { | 1442 | { |
1935 | 1438 | if (xevent->type == ButtonPress) | 1443 | if (xev->type == ButtonPress) |
1936 | 1439 | { | 1444 | { |
1937 | 1440 | priv->toplevel_button_press = TRUE; | 1445 | priv->toplevel_button_press = TRUE; |
1938 | 1441 | gtk_widget_hide (priv->thumb); | 1446 | gtk_widget_hide (priv->thumb); |
1939 | 1442 | } | 1447 | } |
1940 | 1443 | 1448 | ||
1942 | 1444 | if (priv->toplevel_button_press && xevent->type == ButtonRelease) | 1449 | if (priv->toplevel_button_press && xev->type == ButtonRelease) |
1943 | 1445 | { | 1450 | { |
1944 | 1446 | priv->toplevel_button_press = FALSE; | 1451 | priv->toplevel_button_press = FALSE; |
1945 | 1447 | 1452 | ||
1946 | 1448 | /* proximity area */ | 1453 | /* proximity area */ |
1947 | 1449 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | 1454 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
1948 | 1450 | { | 1455 | { |
1953 | 1451 | if ((priv->thumb_all.x - xevent->xbutton.x <= PROXIMITY_WIDTH && | 1456 | if ((priv->thumb_all.x - xev->xbutton.x <= PROXIMITY_WIDTH && |
1954 | 1452 | priv->thumb_all.x - xevent->xbutton.x >= 0) && | 1457 | priv->thumb_all.x - xev->xbutton.x >= 0) && |
1955 | 1453 | (xevent->xbutton.y >= priv->thumb_all.y + priv->overlay.y && | 1458 | (xev->xbutton.y >= priv->thumb_all.y + priv->overlay.y && |
1956 | 1454 | xevent->xbutton.y <= priv->thumb_all.y + priv->overlay.y + priv->overlay.height)) | 1459 | xev->xbutton.y <= priv->thumb_all.y + priv->overlay.y + priv->overlay.height)) |
1957 | 1455 | { | 1460 | { |
1958 | 1456 | priv->can_hide = FALSE; | 1461 | priv->can_hide = FALSE; |
1959 | 1457 | 1462 | ||
1960 | @@ -1465,15 +1470,15 @@ | |||
1961 | 1465 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos); | 1470 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos); |
1962 | 1466 | 1471 | ||
1963 | 1467 | x = priv->thumb_all.x; | 1472 | x = priv->thumb_all.x; |
1965 | 1468 | y = CLAMP (xevent->xbutton.y - priv->slider.height / 2, | 1473 | y = CLAMP (xev->xbutton.y - priv->slider.height / 2, |
1966 | 1469 | priv->thumb_all.y + priv->overlay.y, | 1474 | priv->thumb_all.y + priv->overlay.y, |
1967 | 1470 | priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height); | 1475 | priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height); |
1968 | 1471 | 1476 | ||
1970 | 1472 | os_scrollbar_move_thumb (scrollbar, x_pos + x, y_pos + y); | 1477 | move_thumb (scrollbar, x_pos + x, y_pos + y); |
1971 | 1473 | } | 1478 | } |
1972 | 1474 | else | 1479 | else |
1973 | 1475 | { | 1480 | { |
1975 | 1476 | os_scrollbar_move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y); | 1481 | move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y); |
1976 | 1477 | } | 1482 | } |
1977 | 1478 | 1483 | ||
1978 | 1479 | gtk_widget_show (GTK_WIDGET (priv->thumb)); | 1484 | gtk_widget_show (GTK_WIDGET (priv->thumb)); |
1979 | @@ -1481,10 +1486,10 @@ | |||
1980 | 1481 | } | 1486 | } |
1981 | 1482 | else | 1487 | else |
1982 | 1483 | { | 1488 | { |
1987 | 1484 | if ((priv->thumb_all.y - xevent->xbutton.y <= PROXIMITY_WIDTH && | 1489 | if ((priv->thumb_all.y - xev->xbutton.y <= PROXIMITY_WIDTH && |
1988 | 1485 | priv->thumb_all.y - xevent->xbutton.y >= 0) && | 1490 | priv->thumb_all.y - xev->xbutton.y >= 0) && |
1989 | 1486 | (xevent->xbutton.x >= priv->thumb_all.x + priv->overlay.x && | 1491 | (xev->xbutton.x >= priv->thumb_all.x + priv->overlay.x && |
1990 | 1487 | xevent->xbutton.x <= priv->thumb_all.x + priv->overlay.x + priv->overlay.width)) | 1492 | xev->xbutton.x <= priv->thumb_all.x + priv->overlay.x + priv->overlay.width)) |
1991 | 1488 | { | 1493 | { |
1992 | 1489 | priv->can_hide = FALSE; | 1494 | priv->can_hide = FALSE; |
1993 | 1490 | 1495 | ||
1994 | @@ -1497,16 +1502,16 @@ | |||
1995 | 1497 | 1502 | ||
1996 | 1498 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos); | 1503 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos); |
1997 | 1499 | 1504 | ||
1999 | 1500 | x = CLAMP (xevent->xbutton.x - priv->slider.width / 2, | 1505 | x = CLAMP (xev->xbutton.x - priv->slider.width / 2, |
2000 | 1501 | priv->thumb_all.x + priv->overlay.x, | 1506 | priv->thumb_all.x + priv->overlay.x, |
2001 | 1502 | priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width); | 1507 | priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width); |
2002 | 1503 | y = priv->thumb_all.y; | 1508 | y = priv->thumb_all.y; |
2003 | 1504 | 1509 | ||
2005 | 1505 | os_scrollbar_move_thumb (scrollbar, x_pos + x, y_pos + y); | 1510 | move_thumb (scrollbar, x_pos + x, y_pos + y); |
2006 | 1506 | } | 1511 | } |
2007 | 1507 | else | 1512 | else |
2008 | 1508 | { | 1513 | { |
2010 | 1509 | os_scrollbar_move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y); | 1514 | move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y); |
2011 | 1510 | } | 1515 | } |
2012 | 1511 | 1516 | ||
2013 | 1512 | gtk_widget_show (GTK_WIDGET (priv->thumb)); | 1517 | gtk_widget_show (GTK_WIDGET (priv->thumb)); |
2014 | @@ -1520,10 +1525,10 @@ | |||
2015 | 1520 | * this call checks the pointer after the scroll-event, | 1525 | * this call checks the pointer after the scroll-event, |
2016 | 1521 | * since it enters the window, | 1526 | * since it enters the window, |
2017 | 1522 | * then sets the state accordingly. */ | 1527 | * then sets the state accordingly. */ |
2020 | 1523 | if (!priv->active_window && xevent->type == EnterNotify) | 1528 | if (!priv->active_window && xev->type == EnterNotify) |
2021 | 1524 | pager_set_state_from_pointer (scrollbar, xevent->xcrossing.x, xevent->xcrossing.y); | 1529 | pager_set_state_from_pointer (scrollbar, xev->xcrossing.x, xev->xcrossing.y); |
2022 | 1525 | 1530 | ||
2024 | 1526 | if (xevent->type == LeaveNotify) | 1531 | if (xev->type == LeaveNotify) |
2025 | 1527 | { | 1532 | { |
2026 | 1528 | /* never deactivate the pager in an active window. */ | 1533 | /* never deactivate the pager in an active window. */ |
2027 | 1529 | if (!priv->active_window) | 1534 | if (!priv->active_window) |
2028 | @@ -1534,7 +1539,7 @@ | |||
2029 | 1534 | g_source_remove (priv->source_deactivate_pager_id); | 1539 | g_source_remove (priv->source_deactivate_pager_id); |
2030 | 1535 | 1540 | ||
2031 | 1536 | priv->source_deactivate_pager_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE, | 1541 | priv->source_deactivate_pager_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE, |
2033 | 1537 | os_scrollbar_deactivate_pager_cb, | 1542 | deactivate_pager_cb, |
2034 | 1538 | scrollbar); | 1543 | scrollbar); |
2035 | 1539 | } | 1544 | } |
2036 | 1540 | 1545 | ||
2037 | @@ -1545,32 +1550,32 @@ | |||
2038 | 1545 | g_source_remove (priv->source_hide_thumb_id); | 1550 | g_source_remove (priv->source_hide_thumb_id); |
2039 | 1546 | 1551 | ||
2040 | 1547 | priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE, | 1552 | priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE, |
2042 | 1548 | os_scrollbar_hide_thumb_cb, | 1553 | hide_thumb_cb, |
2043 | 1549 | scrollbar); | 1554 | scrollbar); |
2044 | 1550 | 1555 | ||
2045 | 1551 | if (priv->source_unlock_thumb_id != 0) | 1556 | if (priv->source_unlock_thumb_id != 0) |
2046 | 1552 | g_source_remove (priv->source_unlock_thumb_id); | 1557 | g_source_remove (priv->source_unlock_thumb_id); |
2047 | 1553 | 1558 | ||
2048 | 1554 | priv->source_unlock_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE, | 1559 | priv->source_unlock_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE, |
2050 | 1555 | os_scrollbar_unlock_thumb_cb, | 1560 | unlock_thumb_cb, |
2051 | 1556 | scrollbar); | 1561 | scrollbar); |
2052 | 1557 | } | 1562 | } |
2053 | 1558 | 1563 | ||
2054 | 1559 | /* get the motion_notify_event trough XEvent */ | 1564 | /* get the motion_notify_event trough XEvent */ |
2056 | 1560 | if (!priv->toplevel_button_press && xevent->type == MotionNotify) | 1565 | if (!priv->toplevel_button_press && xev->type == MotionNotify) |
2057 | 1561 | { | 1566 | { |
2058 | 1562 | /* react to motion_notify_event | 1567 | /* react to motion_notify_event |
2059 | 1563 | * and set the state accordingly. */ | 1568 | * and set the state accordingly. */ |
2060 | 1564 | if (!priv->active_window) | 1569 | if (!priv->active_window) |
2062 | 1565 | pager_set_state_from_pointer (scrollbar, xevent->xmotion.x, xevent->xmotion.y); | 1570 | pager_set_state_from_pointer (scrollbar, xev->xmotion.x, xev->xmotion.y); |
2063 | 1566 | 1571 | ||
2064 | 1567 | /* proximity area */ | 1572 | /* proximity area */ |
2065 | 1568 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | 1573 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
2066 | 1569 | { | 1574 | { |
2071 | 1570 | if ((priv->thumb_all.x - xevent->xmotion.x <= PROXIMITY_WIDTH && | 1575 | if ((priv->thumb_all.x - xev->xmotion.x <= PROXIMITY_WIDTH && |
2072 | 1571 | priv->thumb_all.x - xevent->xmotion.x >= 0) && | 1576 | priv->thumb_all.x - xev->xmotion.x >= 0) && |
2073 | 1572 | (xevent->xmotion.y >= priv->thumb_all.y + priv->overlay.y && | 1577 | (xev->xmotion.y >= priv->thumb_all.y + priv->overlay.y && |
2074 | 1573 | xevent->xmotion.y <= priv->thumb_all.y + priv->overlay.y + priv->overlay.height)) | 1578 | xev->xmotion.y <= priv->thumb_all.y + priv->overlay.y + priv->overlay.height)) |
2075 | 1574 | { | 1579 | { |
2076 | 1575 | priv->can_hide = FALSE; | 1580 | priv->can_hide = FALSE; |
2077 | 1576 | 1581 | ||
2078 | @@ -1584,15 +1589,15 @@ | |||
2079 | 1584 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos); | 1589 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos); |
2080 | 1585 | 1590 | ||
2081 | 1586 | x = priv->thumb_all.x; | 1591 | x = priv->thumb_all.x; |
2083 | 1587 | y = CLAMP (xevent->xmotion.y - priv->slider.height / 2, | 1592 | y = CLAMP (xev->xmotion.y - priv->slider.height / 2, |
2084 | 1588 | priv->thumb_all.y + priv->overlay.y, | 1593 | priv->thumb_all.y + priv->overlay.y, |
2085 | 1589 | priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height); | 1594 | priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height); |
2086 | 1590 | 1595 | ||
2088 | 1591 | os_scrollbar_move_thumb (scrollbar, x_pos + x, y_pos + y); | 1596 | move_thumb (scrollbar, x_pos + x, y_pos + y); |
2089 | 1592 | } | 1597 | } |
2090 | 1593 | else | 1598 | else |
2091 | 1594 | { | 1599 | { |
2093 | 1595 | os_scrollbar_move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y); | 1600 | move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y); |
2094 | 1596 | } | 1601 | } |
2095 | 1597 | 1602 | ||
2096 | 1598 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); | 1603 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); |
2097 | @@ -1603,15 +1608,15 @@ | |||
2098 | 1603 | { | 1608 | { |
2099 | 1604 | priv->can_hide = TRUE; | 1609 | priv->can_hide = TRUE; |
2100 | 1605 | priv->lock_position = FALSE; | 1610 | priv->lock_position = FALSE; |
2102 | 1606 | os_scrollbar_hide_thumb (scrollbar); | 1611 | hide_thumb (scrollbar); |
2103 | 1607 | } | 1612 | } |
2104 | 1608 | } | 1613 | } |
2105 | 1609 | else | 1614 | else |
2106 | 1610 | { | 1615 | { |
2111 | 1611 | if ((priv->thumb_all.y - xevent->xmotion.y <= PROXIMITY_WIDTH && | 1616 | if ((priv->thumb_all.y - xev->xmotion.y <= PROXIMITY_WIDTH && |
2112 | 1612 | priv->thumb_all.y - xevent->xmotion.y >= 0) && | 1617 | priv->thumb_all.y - xev->xmotion.y >= 0) && |
2113 | 1613 | (xevent->xmotion.x >= priv->thumb_all.x + priv->overlay.x && | 1618 | (xev->xmotion.x >= priv->thumb_all.x + priv->overlay.x && |
2114 | 1614 | xevent->xmotion.x <= priv->thumb_all.x + priv->overlay.x + priv->overlay.width)) | 1619 | xev->xmotion.x <= priv->thumb_all.x + priv->overlay.x + priv->overlay.width)) |
2115 | 1615 | { | 1620 | { |
2116 | 1616 | priv->can_hide = FALSE; | 1621 | priv->can_hide = FALSE; |
2117 | 1617 | 1622 | ||
2118 | @@ -1624,16 +1629,16 @@ | |||
2119 | 1624 | 1629 | ||
2120 | 1625 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos); | 1630 | gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos); |
2121 | 1626 | 1631 | ||
2123 | 1627 | x = CLAMP (xevent->xmotion.x - priv->slider.width / 2, | 1632 | x = CLAMP (xev->xmotion.x - priv->slider.width / 2, |
2124 | 1628 | priv->thumb_all.x + priv->overlay.x, | 1633 | priv->thumb_all.x + priv->overlay.x, |
2125 | 1629 | priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width); | 1634 | priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width); |
2126 | 1630 | y = priv->thumb_all.y; | 1635 | y = priv->thumb_all.y; |
2127 | 1631 | 1636 | ||
2129 | 1632 | os_scrollbar_move_thumb (scrollbar, x_pos + x, y_pos + y); | 1637 | move_thumb (scrollbar, x_pos + x, y_pos + y); |
2130 | 1633 | } | 1638 | } |
2131 | 1634 | else | 1639 | else |
2132 | 1635 | { | 1640 | { |
2134 | 1636 | os_scrollbar_move_thumb (scrollbar, priv->win_x + priv->slider.x, priv->win_y); | 1641 | move_thumb (scrollbar, priv->win_x + priv->slider.x, priv->win_y); |
2135 | 1637 | } | 1642 | } |
2136 | 1638 | 1643 | ||
2137 | 1639 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); | 1644 | os_pager_set_detached (OS_PAGER (priv->pager), FALSE); |
2138 | @@ -1644,7 +1649,7 @@ | |||
2139 | 1644 | { | 1649 | { |
2140 | 1645 | priv->can_hide = TRUE; | 1650 | priv->can_hide = TRUE; |
2141 | 1646 | priv->lock_position = FALSE; | 1651 | priv->lock_position = FALSE; |
2143 | 1647 | os_scrollbar_hide_thumb (scrollbar); | 1652 | hide_thumb (scrollbar); |
2144 | 1648 | } | 1653 | } |
2145 | 1649 | } | 1654 | } |
2146 | 1650 | } | 1655 | } |
2147 | @@ -1653,8 +1658,6 @@ | |||
2148 | 1653 | return GDK_FILTER_CONTINUE; | 1658 | return GDK_FILTER_CONTINUE; |
2149 | 1654 | } | 1659 | } |
2150 | 1655 | 1660 | ||
2151 | 1656 | /* Type definition. */ | ||
2152 | 1657 | |||
2153 | 1658 | G_DEFINE_TYPE (OsScrollbar, os_scrollbar, GTK_TYPE_SCROLLBAR); | 1661 | G_DEFINE_TYPE (OsScrollbar, os_scrollbar, GTK_TYPE_SCROLLBAR); |
2154 | 1659 | 1662 | ||
2155 | 1660 | static void | 1663 | static void |
2156 | @@ -1717,6 +1720,11 @@ | |||
2157 | 1717 | os_root_list = g_list_append (os_root_list, scrollbar); | 1720 | os_root_list = g_list_append (os_root_list, scrollbar); |
2158 | 1718 | } | 1721 | } |
2159 | 1719 | 1722 | ||
2160 | 1723 | priv->button_press_event = FALSE; | ||
2161 | 1724 | priv->enter_notify_event = FALSE; | ||
2162 | 1725 | priv->motion_notify_event = FALSE; | ||
2163 | 1726 | priv->value_changed_event = FALSE; | ||
2164 | 1727 | |||
2165 | 1720 | priv->active_window = FALSE; | 1728 | priv->active_window = FALSE; |
2166 | 1721 | priv->can_deactivate_pager = TRUE; | 1729 | priv->can_deactivate_pager = TRUE; |
2167 | 1722 | priv->can_hide = TRUE; | 1730 | priv->can_hide = TRUE; |
2168 | @@ -1733,10 +1741,10 @@ | |||
2169 | 1733 | priv->pager = os_pager_new (); | 1741 | priv->pager = os_pager_new (); |
2170 | 1734 | 1742 | ||
2171 | 1735 | g_signal_connect (G_OBJECT (scrollbar), "notify::adjustment", | 1743 | g_signal_connect (G_OBJECT (scrollbar), "notify::adjustment", |
2173 | 1736 | G_CALLBACK (os_scrollbar_notify_adjustment_cb), NULL); | 1744 | G_CALLBACK (notify_adjustment_cb), NULL); |
2174 | 1737 | 1745 | ||
2175 | 1738 | g_signal_connect (G_OBJECT (scrollbar), "notify::orientation", | 1746 | g_signal_connect (G_OBJECT (scrollbar), "notify::orientation", |
2177 | 1739 | G_CALLBACK (os_scrollbar_notify_orientation_cb), NULL); | 1747 | G_CALLBACK (notify_orientation_cb), NULL); |
2178 | 1740 | } | 1748 | } |
2179 | 1741 | 1749 | ||
2180 | 1742 | static void | 1750 | static void |
2181 | @@ -1778,8 +1786,8 @@ | |||
2182 | 1778 | priv->pager = NULL; | 1786 | priv->pager = NULL; |
2183 | 1779 | } | 1787 | } |
2184 | 1780 | 1788 | ||
2187 | 1781 | os_scrollbar_swap_adjustment (scrollbar, NULL); | 1789 | swap_adjustment (scrollbar, NULL); |
2188 | 1782 | os_scrollbar_swap_thumb (scrollbar, NULL); | 1790 | swap_thumb (scrollbar, NULL); |
2189 | 1783 | 1791 | ||
2190 | 1784 | G_OBJECT_CLASS (os_scrollbar_parent_class)->dispose (object); | 1792 | G_OBJECT_CLASS (os_scrollbar_parent_class)->dispose (object); |
2191 | 1785 | } | 1793 | } |
2192 | @@ -1892,11 +1900,11 @@ | |||
2193 | 1892 | g_signal_connect (G_OBJECT (gtk_widget_get_toplevel (widget)), "configure-event", | 1900 | g_signal_connect (G_OBJECT (gtk_widget_get_toplevel (widget)), "configure-event", |
2194 | 1893 | G_CALLBACK (toplevel_configure_event_cb), scrollbar); | 1901 | G_CALLBACK (toplevel_configure_event_cb), scrollbar); |
2195 | 1894 | 1902 | ||
2197 | 1895 | os_scrollbar_calc_layout_pager (scrollbar, priv->adjustment->value); | 1903 | calc_layout_pager (scrollbar, priv->adjustment->value); |
2198 | 1896 | 1904 | ||
2199 | 1897 | os_pager_set_parent (OS_PAGER (priv->pager), widget); | 1905 | os_pager_set_parent (OS_PAGER (priv->pager), widget); |
2200 | 1898 | 1906 | ||
2202 | 1899 | os_scrollbar_store_window_position (scrollbar); | 1907 | store_toplevel_position (scrollbar); |
2203 | 1900 | } | 1908 | } |
2204 | 1901 | 1909 | ||
2205 | 1902 | static void | 1910 | static void |
2206 | @@ -1955,16 +1963,16 @@ | |||
2207 | 1955 | 1963 | ||
2208 | 1956 | if (priv->adjustment != NULL) | 1964 | if (priv->adjustment != NULL) |
2209 | 1957 | { | 1965 | { |
2212 | 1958 | os_scrollbar_calc_layout_pager (scrollbar, priv->adjustment->value); | 1966 | calc_layout_pager (scrollbar, priv->adjustment->value); |
2213 | 1959 | os_scrollbar_calc_layout_slider (scrollbar, priv->adjustment->value); | 1967 | calc_layout_slider (scrollbar, priv->adjustment->value); |
2214 | 1960 | } | 1968 | } |
2215 | 1961 | 1969 | ||
2216 | 1962 | os_pager_size_allocate (OS_PAGER (priv->pager), rect); | 1970 | os_pager_size_allocate (OS_PAGER (priv->pager), rect); |
2217 | 1963 | 1971 | ||
2219 | 1964 | pager_move (scrollbar); | 1972 | move_pager (scrollbar); |
2220 | 1965 | 1973 | ||
2221 | 1966 | if (gtk_widget_get_realized (widget)) | 1974 | if (gtk_widget_get_realized (widget)) |
2223 | 1967 | os_scrollbar_store_window_position (scrollbar); | 1975 | store_toplevel_position (scrollbar); |
2224 | 1968 | 1976 | ||
2225 | 1969 | widget->allocation = *allocation; | 1977 | widget->allocation = *allocation; |
2226 | 1970 | } | 1978 | } |
2227 | 1971 | 1979 | ||
2228 | === modified file 'os/os-thumb.c' | |||
2229 | --- os/os-thumb.c 2011-05-17 22:10:53 +0000 | |||
2230 | +++ os/os-thumb.c 2011-05-18 18:39:29 +0000 | |||
2231 | @@ -50,8 +50,8 @@ | |||
2232 | 50 | gboolean button_press_event; | 50 | gboolean button_press_event; |
2233 | 51 | gboolean motion_notify_event; | 51 | gboolean motion_notify_event; |
2234 | 52 | gboolean can_rgba; | 52 | gboolean can_rgba; |
2235 | 53 | gboolean detached; | ||
2236 | 53 | gboolean use_tolerance; | 54 | gboolean use_tolerance; |
2237 | 54 | gboolean detached; | ||
2238 | 55 | gint pointer_x; | 55 | gint pointer_x; |
2239 | 56 | gint pointer_y; | 56 | gint pointer_y; |
2240 | 57 | guint32 source_id; | 57 | guint32 source_id; |
2241 | @@ -63,8 +63,6 @@ | |||
2242 | 63 | LAST_ARG | 63 | LAST_ARG |
2243 | 64 | }; | 64 | }; |
2244 | 65 | 65 | ||
2245 | 66 | static void os_thumb_fade_out_cb (gfloat weight, gpointer user_data); | ||
2246 | 67 | static gboolean os_thumb_timeout_fade_out_cb (gpointer user_data); | ||
2247 | 68 | static gboolean os_thumb_button_press_event (GtkWidget *widget, GdkEventButton *event); | 66 | static gboolean os_thumb_button_press_event (GtkWidget *widget, GdkEventButton *event); |
2248 | 69 | static gboolean os_thumb_button_release_event (GtkWidget *widget, GdkEventButton *event); | 67 | static gboolean os_thumb_button_release_event (GtkWidget *widget, GdkEventButton *event); |
2249 | 70 | static void os_thumb_composited_changed (GtkWidget *widget); | 68 | static void os_thumb_composited_changed (GtkWidget *widget); |
2250 | @@ -81,61 +79,12 @@ | |||
2251 | 81 | static void os_thumb_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); | 79 | static void os_thumb_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); |
2252 | 82 | static void os_thumb_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); | 80 | static void os_thumb_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); |
2253 | 83 | 81 | ||
2309 | 84 | /* Private functions. */ | 82 | /* Private functions */ |
2310 | 85 | 83 | ||
2311 | 86 | /* Draw an arror. */ | 84 | /* callback called by the fade-out animation */ |
2312 | 87 | static void | 85 | static void |
2313 | 88 | os_cairo_draw_arrow (cairo_t *cr, | 86 | fade_out_cb (gfloat weight, |
2314 | 89 | gdouble x, | 87 | gpointer user_data) |
2260 | 90 | gdouble y, | ||
2261 | 91 | gdouble width, | ||
2262 | 92 | gdouble height) | ||
2263 | 93 | { | ||
2264 | 94 | cairo_save (cr); | ||
2265 | 95 | |||
2266 | 96 | cairo_translate (cr, x, y); | ||
2267 | 97 | cairo_move_to (cr, -width / 2, -height / 2); | ||
2268 | 98 | cairo_line_to (cr, 0, height / 2); | ||
2269 | 99 | cairo_line_to (cr, width / 2, -height / 2); | ||
2270 | 100 | cairo_close_path (cr); | ||
2271 | 101 | |||
2272 | 102 | cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 0.75); | ||
2273 | 103 | cairo_fill_preserve (cr); | ||
2274 | 104 | |||
2275 | 105 | cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 1.0); | ||
2276 | 106 | cairo_stroke (cr); | ||
2277 | 107 | |||
2278 | 108 | cairo_restore (cr); | ||
2279 | 109 | } | ||
2280 | 110 | |||
2281 | 111 | /* Draw a rounded rectangle. */ | ||
2282 | 112 | static void | ||
2283 | 113 | os_cairo_draw_rounded_rect (cairo_t *cr, | ||
2284 | 114 | gdouble x, | ||
2285 | 115 | gdouble y, | ||
2286 | 116 | gdouble width, | ||
2287 | 117 | gdouble height, | ||
2288 | 118 | gdouble radius) | ||
2289 | 119 | { | ||
2290 | 120 | if (radius < 1) | ||
2291 | 121 | { | ||
2292 | 122 | cairo_rectangle (cr, x, y, width, height); | ||
2293 | 123 | return; | ||
2294 | 124 | } | ||
2295 | 125 | |||
2296 | 126 | radius = MIN (radius, MIN (width / 2.0, height / 2.0)); | ||
2297 | 127 | |||
2298 | 128 | cairo_move_to (cr, x + radius, y); | ||
2299 | 129 | |||
2300 | 130 | cairo_arc (cr, x + width - radius, y + radius, radius, G_PI * 1.5, G_PI * 2); | ||
2301 | 131 | cairo_arc (cr, x + width - radius, y + height - radius, radius, 0, G_PI * 0.5); | ||
2302 | 132 | cairo_arc (cr, x + radius, y + height - radius, radius, G_PI * 0.5, G_PI); | ||
2303 | 133 | cairo_arc (cr, x + radius, y + radius, radius, G_PI, G_PI * 1.5); | ||
2304 | 134 | } | ||
2305 | 135 | |||
2306 | 136 | static void | ||
2307 | 137 | os_thumb_fade_out_cb (gfloat weight, | ||
2308 | 138 | gpointer user_data) | ||
2315 | 139 | { | 88 | { |
2316 | 140 | OsThumb *thumb; | 89 | OsThumb *thumb; |
2317 | 141 | 90 | ||
2318 | @@ -147,8 +96,9 @@ | |||
2319 | 147 | gtk_widget_hide (GTK_WIDGET (thumb)); | 96 | gtk_widget_hide (GTK_WIDGET (thumb)); |
2320 | 148 | } | 97 | } |
2321 | 149 | 98 | ||
2322 | 99 | /* timeout before starting the fade-out animation */ | ||
2323 | 150 | static gboolean | 100 | static gboolean |
2325 | 151 | os_thumb_timeout_fade_out_cb (gpointer user_data) | 101 | timeout_fade_out_cb (gpointer user_data) |
2326 | 152 | { | 102 | { |
2327 | 153 | OsThumb *thumb; | 103 | OsThumb *thumb; |
2328 | 154 | OsThumbPrivate *priv; | 104 | OsThumbPrivate *priv; |
2329 | @@ -163,8 +113,6 @@ | |||
2330 | 163 | return FALSE; | 113 | return FALSE; |
2331 | 164 | } | 114 | } |
2332 | 165 | 115 | ||
2333 | 166 | /* Type definition. */ | ||
2334 | 167 | |||
2335 | 168 | G_DEFINE_TYPE (OsThumb, os_thumb, GTK_TYPE_WINDOW); | 116 | G_DEFINE_TYPE (OsThumb, os_thumb, GTK_TYPE_WINDOW); |
2336 | 169 | 117 | ||
2337 | 170 | static void | 118 | static void |
2338 | @@ -214,16 +162,19 @@ | |||
2339 | 214 | OsThumbPrivate); | 162 | OsThumbPrivate); |
2340 | 215 | priv = thumb->priv; | 163 | priv = thumb->priv; |
2341 | 216 | 164 | ||
2342 | 165 | priv->button_press_event = FALSE; | ||
2343 | 166 | priv->motion_notify_event = FALSE; | ||
2344 | 167 | |||
2345 | 217 | priv->can_rgba = FALSE; | 168 | priv->can_rgba = FALSE; |
2346 | 218 | priv->detached = FALSE; | 169 | priv->detached = FALSE; |
2347 | 170 | priv->use_tolerance = FALSE; | ||
2348 | 219 | 171 | ||
2349 | 220 | priv->source_id = 0; | 172 | priv->source_id = 0; |
2350 | 221 | priv->animation = os_animation_new (RATE_FADE_OUT, DURATION_FADE_OUT, | 173 | priv->animation = os_animation_new (RATE_FADE_OUT, DURATION_FADE_OUT, |
2352 | 222 | os_thumb_fade_out_cb, NULL, thumb); | 174 | fade_out_cb, NULL, thumb); |
2353 | 223 | 175 | ||
2354 | 224 | gtk_window_set_skip_pager_hint (GTK_WINDOW (thumb), TRUE); | 176 | gtk_window_set_skip_pager_hint (GTK_WINDOW (thumb), TRUE); |
2355 | 225 | gtk_window_set_skip_taskbar_hint (GTK_WINDOW (thumb), TRUE); | 177 | gtk_window_set_skip_taskbar_hint (GTK_WINDOW (thumb), TRUE); |
2356 | 226 | /* gtk_window_set_has_resize_grip (GTK_WINDOW (thumb), FALSE); */ | ||
2357 | 227 | gtk_window_set_decorated (GTK_WINDOW (thumb), FALSE); | 178 | gtk_window_set_decorated (GTK_WINDOW (thumb), FALSE); |
2358 | 228 | gtk_window_set_focus_on_map (GTK_WINDOW (thumb), FALSE); | 179 | gtk_window_set_focus_on_map (GTK_WINDOW (thumb), FALSE); |
2359 | 229 | gtk_window_set_accept_focus (GTK_WINDOW (thumb), FALSE); | 180 | gtk_window_set_accept_focus (GTK_WINDOW (thumb), FALSE); |
2360 | @@ -237,43 +188,6 @@ | |||
2361 | 237 | os_thumb_composited_changed (GTK_WIDGET (thumb)); | 188 | os_thumb_composited_changed (GTK_WIDGET (thumb)); |
2362 | 238 | } | 189 | } |
2363 | 239 | 190 | ||
2364 | 240 | static void | ||
2365 | 241 | os_thumb_dispose (GObject *object) | ||
2366 | 242 | { | ||
2367 | 243 | OsThumb *thumb; | ||
2368 | 244 | OsThumbPrivate *priv; | ||
2369 | 245 | |||
2370 | 246 | thumb = OS_THUMB (object); | ||
2371 | 247 | priv = thumb->priv; | ||
2372 | 248 | |||
2373 | 249 | if (priv->source_id != 0) | ||
2374 | 250 | { | ||
2375 | 251 | g_source_remove (priv->source_id); | ||
2376 | 252 | priv->source_id = 0; | ||
2377 | 253 | } | ||
2378 | 254 | |||
2379 | 255 | if (priv->animation != NULL) | ||
2380 | 256 | { | ||
2381 | 257 | g_object_unref (priv->animation); | ||
2382 | 258 | priv->animation = NULL; | ||
2383 | 259 | } | ||
2384 | 260 | |||
2385 | 261 | if (priv->grabbed_widget != NULL) | ||
2386 | 262 | { | ||
2387 | 263 | g_object_unref (priv->grabbed_widget); | ||
2388 | 264 | priv->grabbed_widget = NULL; | ||
2389 | 265 | } | ||
2390 | 266 | |||
2391 | 267 | G_OBJECT_CLASS (os_thumb_parent_class)->dispose (object); | ||
2392 | 268 | } | ||
2393 | 269 | |||
2394 | 270 | static void | ||
2395 | 271 | os_thumb_finalize (GObject *object) | ||
2396 | 272 | { | ||
2397 | 273 | G_OBJECT_CLASS (os_thumb_parent_class)->finalize (object); | ||
2398 | 274 | } | ||
2399 | 275 | |||
2400 | 276 | |||
2401 | 277 | static gboolean | 191 | static gboolean |
2402 | 278 | os_thumb_button_press_event (GtkWidget *widget, | 192 | os_thumb_button_press_event (GtkWidget *widget, |
2403 | 279 | GdkEventButton *event) | 193 | GdkEventButton *event) |
2404 | @@ -371,6 +285,56 @@ | |||
2405 | 371 | gtk_widget_queue_draw (widget); | 285 | gtk_widget_queue_draw (widget); |
2406 | 372 | } | 286 | } |
2407 | 373 | 287 | ||
2408 | 288 | /* draw an arrow using cairo */ | ||
2409 | 289 | static void | ||
2410 | 290 | draw_arrow (cairo_t *cr, | ||
2411 | 291 | gdouble x, | ||
2412 | 292 | gdouble y, | ||
2413 | 293 | gdouble width, | ||
2414 | 294 | gdouble height) | ||
2415 | 295 | { | ||
2416 | 296 | cairo_save (cr); | ||
2417 | 297 | |||
2418 | 298 | cairo_translate (cr, x, y); | ||
2419 | 299 | cairo_move_to (cr, -width / 2, -height / 2); | ||
2420 | 300 | cairo_line_to (cr, 0, height / 2); | ||
2421 | 301 | cairo_line_to (cr, width / 2, -height / 2); | ||
2422 | 302 | cairo_close_path (cr); | ||
2423 | 303 | |||
2424 | 304 | cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 0.75); | ||
2425 | 305 | cairo_fill_preserve (cr); | ||
2426 | 306 | |||
2427 | 307 | cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 1.0); | ||
2428 | 308 | cairo_stroke (cr); | ||
2429 | 309 | |||
2430 | 310 | cairo_restore (cr); | ||
2431 | 311 | } | ||
2432 | 312 | |||
2433 | 313 | /* draw a rounded rectangle using cairo */ | ||
2434 | 314 | static void | ||
2435 | 315 | draw_round_rect (cairo_t *cr, | ||
2436 | 316 | gdouble x, | ||
2437 | 317 | gdouble y, | ||
2438 | 318 | gdouble width, | ||
2439 | 319 | gdouble height, | ||
2440 | 320 | gdouble radius) | ||
2441 | 321 | { | ||
2442 | 322 | radius = MIN (radius, MIN (width / 2.0, height / 2.0)); | ||
2443 | 323 | |||
2444 | 324 | if (radius < 1) | ||
2445 | 325 | { | ||
2446 | 326 | cairo_rectangle (cr, x, y, width, height); | ||
2447 | 327 | return; | ||
2448 | 328 | } | ||
2449 | 329 | |||
2450 | 330 | cairo_move_to (cr, x + radius, y); | ||
2451 | 331 | |||
2452 | 332 | cairo_arc (cr, x + width - radius, y + radius, radius, G_PI * 1.5, G_PI * 2); | ||
2453 | 333 | cairo_arc (cr, x + width - radius, y + height - radius, radius, 0, G_PI * 0.5); | ||
2454 | 334 | cairo_arc (cr, x + radius, y + height - radius, radius, G_PI * 0.5, G_PI); | ||
2455 | 335 | cairo_arc (cr, x + radius, y + radius, radius, G_PI, G_PI * 1.5); | ||
2456 | 336 | } | ||
2457 | 337 | |||
2458 | 374 | static gboolean | 338 | static gboolean |
2459 | 375 | os_thumb_expose (GtkWidget *widget, | 339 | os_thumb_expose (GtkWidget *widget, |
2460 | 376 | GdkEventExpose *event) | 340 | GdkEventExpose *event) |
2461 | @@ -413,7 +377,7 @@ | |||
2462 | 413 | cairo_set_line_width (cr, 1); | 377 | cairo_set_line_width (cr, 1); |
2463 | 414 | cairo_set_operator (cr, CAIRO_OPERATOR_OVER); | 378 | cairo_set_operator (cr, CAIRO_OPERATOR_OVER); |
2464 | 415 | 379 | ||
2466 | 416 | os_cairo_draw_rounded_rect (cr, x, y, width, height, radius); | 380 | draw_round_rect (cr, x, y, width, height, radius); |
2467 | 417 | 381 | ||
2468 | 418 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | 382 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
2469 | 419 | pat = cairo_pattern_create_linear (x, y, width + x, y); | 383 | pat = cairo_pattern_create_linear (x, y, width + x, y); |
2470 | @@ -426,7 +390,7 @@ | |||
2471 | 426 | cairo_pattern_destroy (pat); | 390 | cairo_pattern_destroy (pat); |
2472 | 427 | cairo_fill (cr); | 391 | cairo_fill (cr); |
2473 | 428 | 392 | ||
2475 | 429 | os_cairo_draw_rounded_rect (cr, x, y, width, height, radius); | 393 | draw_round_rect (cr, x, y, width, height, radius); |
2476 | 430 | 394 | ||
2477 | 431 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) | 395 | if (priv->orientation == GTK_ORIENTATION_VERTICAL) |
2478 | 432 | pat = cairo_pattern_create_linear (x, y, x, height + y); | 396 | pat = cairo_pattern_create_linear (x, y, x, height + y); |
2479 | @@ -461,7 +425,6 @@ | |||
2480 | 461 | cairo_set_source (cr, pat); | 425 | cairo_set_source (cr, pat); |
2481 | 462 | cairo_pattern_destroy (pat); | 426 | cairo_pattern_destroy (pat); |
2482 | 463 | 427 | ||
2483 | 464 | |||
2484 | 465 | if (priv->motion_notify_event) | 428 | if (priv->motion_notify_event) |
2485 | 466 | { | 429 | { |
2486 | 467 | cairo_fill_preserve (cr); | 430 | cairo_fill_preserve (cr); |
2487 | @@ -472,7 +435,7 @@ | |||
2488 | 472 | cairo_fill (cr); | 435 | cairo_fill (cr); |
2489 | 473 | 436 | ||
2490 | 474 | cairo_set_line_width (cr, 2.0); | 437 | cairo_set_line_width (cr, 2.0); |
2492 | 475 | os_cairo_draw_rounded_rect (cr, x + 0.5, y + 0.5, width - 1, height - 1, radius - 1); | 438 | draw_round_rect (cr, x + 0.5, y + 0.5, width - 1, height - 1, radius - 1); |
2493 | 476 | if (!priv->detached) | 439 | if (!priv->detached) |
2494 | 477 | cairo_set_source_rgba (cr, style->bg[GTK_STATE_SELECTED].red/65535.0, | 440 | cairo_set_source_rgba (cr, style->bg[GTK_STATE_SELECTED].red/65535.0, |
2495 | 478 | style->bg[GTK_STATE_SELECTED].green/65535.0, | 441 | style->bg[GTK_STATE_SELECTED].green/65535.0, |
2496 | @@ -482,15 +445,15 @@ | |||
2497 | 482 | cairo_stroke (cr); | 445 | cairo_stroke (cr); |
2498 | 483 | 446 | ||
2499 | 484 | cairo_set_line_width (cr, 1.0); | 447 | cairo_set_line_width (cr, 1.0); |
2501 | 485 | os_cairo_draw_rounded_rect (cr, x + 1, y + 1, width - 2, height - 2, radius - 1); | 448 | draw_round_rect (cr, x + 1, y + 1, width - 2, height - 2, radius - 1); |
2502 | 486 | cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 0.1); | 449 | cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 0.1); |
2503 | 487 | cairo_stroke (cr); | 450 | cairo_stroke (cr); |
2504 | 488 | 451 | ||
2506 | 489 | os_cairo_draw_rounded_rect (cr, x + 2, y + 2, width - 4, height - 4, radius - 3); | 452 | draw_round_rect (cr, x + 2, y + 2, width - 4, height - 4, radius - 3); |
2507 | 490 | cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.5); | 453 | cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, 0.5); |
2508 | 491 | cairo_stroke (cr); | 454 | cairo_stroke (cr); |
2509 | 492 | 455 | ||
2511 | 493 | os_cairo_draw_rounded_rect (cr, x + 3, y + 3, width - 6, height - 6, radius - 4); | 456 | draw_round_rect (cr, x + 3, y + 3, width - 6, height - 6, radius - 4); |
2512 | 494 | cairo_set_source_rgba (cr, 1, 1, 1, 0.2); | 457 | cairo_set_source_rgba (cr, 1, 1, 1, 0.2); |
2513 | 495 | cairo_stroke (cr); | 458 | cairo_stroke (cr); |
2514 | 496 | 459 | ||
2515 | @@ -525,14 +488,14 @@ | |||
2516 | 525 | cairo_save (cr); | 488 | cairo_save (cr); |
2517 | 526 | cairo_translate (cr, 8.5, 8.5); | 489 | cairo_translate (cr, 8.5, 8.5); |
2518 | 527 | cairo_rotate (cr, G_PI); | 490 | cairo_rotate (cr, G_PI); |
2520 | 528 | os_cairo_draw_arrow (cr, 0.5, 0, 4, 3); | 491 | draw_arrow (cr, 0.5, 0, 4, 3); |
2521 | 529 | cairo_restore (cr); | 492 | cairo_restore (cr); |
2522 | 530 | 493 | ||
2523 | 531 | /* direction DOWN. */ | 494 | /* direction DOWN. */ |
2524 | 532 | cairo_save (cr); | 495 | cairo_save (cr); |
2525 | 533 | cairo_translate (cr, 8.5, height - 8.5); | 496 | cairo_translate (cr, 8.5, height - 8.5); |
2526 | 534 | cairo_rotate (cr, 0); | 497 | cairo_rotate (cr, 0); |
2528 | 535 | os_cairo_draw_arrow (cr, -0.5, 0, 4, 3); | 498 | draw_arrow (cr, -0.5, 0, 4, 3); |
2529 | 536 | cairo_restore (cr); | 499 | cairo_restore (cr); |
2530 | 537 | } | 500 | } |
2531 | 538 | else | 501 | else |
2532 | @@ -541,14 +504,14 @@ | |||
2533 | 541 | cairo_save (cr); | 504 | cairo_save (cr); |
2534 | 542 | cairo_translate (cr, 8.5, 8.5); | 505 | cairo_translate (cr, 8.5, 8.5); |
2535 | 543 | cairo_rotate (cr, G_PI * 0.5); | 506 | cairo_rotate (cr, G_PI * 0.5); |
2537 | 544 | os_cairo_draw_arrow (cr, -0.5, 0, 4, 3); | 507 | draw_arrow (cr, -0.5, 0, 4, 3); |
2538 | 545 | cairo_restore (cr); | 508 | cairo_restore (cr); |
2539 | 546 | 509 | ||
2540 | 547 | /* direction RIGHT. */ | 510 | /* direction RIGHT. */ |
2541 | 548 | cairo_save (cr); | 511 | cairo_save (cr); |
2542 | 549 | cairo_translate (cr, width - 8.5, 8.5); | 512 | cairo_translate (cr, width - 8.5, 8.5); |
2543 | 550 | cairo_rotate (cr, G_PI * 1.5); | 513 | cairo_rotate (cr, G_PI * 1.5); |
2545 | 551 | os_cairo_draw_arrow (cr, 0.5, 0, 4, 3); | 514 | draw_arrow (cr, 0.5, 0, 4, 3); |
2546 | 552 | cairo_restore (cr); | 515 | cairo_restore (cr); |
2547 | 553 | } | 516 | } |
2548 | 554 | 517 | ||
2549 | @@ -649,7 +612,7 @@ | |||
2550 | 649 | { | 612 | { |
2551 | 650 | priv->use_tolerance = FALSE; | 613 | priv->use_tolerance = FALSE; |
2552 | 651 | priv->source_id = g_timeout_add (TIMEOUT_FADE_OUT, | 614 | priv->source_id = g_timeout_add (TIMEOUT_FADE_OUT, |
2554 | 652 | os_thumb_timeout_fade_out_cb, | 615 | timeout_fade_out_cb, |
2555 | 653 | thumb); | 616 | thumb); |
2556 | 654 | } | 617 | } |
2557 | 655 | } | 618 | } |
2558 | @@ -700,7 +663,7 @@ | |||
2559 | 700 | gtk_window_set_opacity (GTK_WINDOW (widget), 1.0f); | 663 | gtk_window_set_opacity (GTK_WINDOW (widget), 1.0f); |
2560 | 701 | 664 | ||
2561 | 702 | priv->source_id = g_timeout_add (TIMEOUT_FADE_OUT, | 665 | priv->source_id = g_timeout_add (TIMEOUT_FADE_OUT, |
2563 | 703 | os_thumb_timeout_fade_out_cb, | 666 | timeout_fade_out_cb, |
2564 | 704 | thumb); | 667 | thumb); |
2565 | 705 | 668 | ||
2566 | 706 | return FALSE; | 669 | return FALSE; |
2567 | @@ -742,6 +705,42 @@ | |||
2568 | 742 | } | 705 | } |
2569 | 743 | 706 | ||
2570 | 744 | static void | 707 | static void |
2571 | 708 | os_thumb_dispose (GObject *object) | ||
2572 | 709 | { | ||
2573 | 710 | OsThumb *thumb; | ||
2574 | 711 | OsThumbPrivate *priv; | ||
2575 | 712 | |||
2576 | 713 | thumb = OS_THUMB (object); | ||
2577 | 714 | priv = thumb->priv; | ||
2578 | 715 | |||
2579 | 716 | if (priv->source_id != 0) | ||
2580 | 717 | { | ||
2581 | 718 | g_source_remove (priv->source_id); | ||
2582 | 719 | priv->source_id = 0; | ||
2583 | 720 | } | ||
2584 | 721 | |||
2585 | 722 | if (priv->animation != NULL) | ||
2586 | 723 | { | ||
2587 | 724 | g_object_unref (priv->animation); | ||
2588 | 725 | priv->animation = NULL; | ||
2589 | 726 | } | ||
2590 | 727 | |||
2591 | 728 | if (priv->grabbed_widget != NULL) | ||
2592 | 729 | { | ||
2593 | 730 | g_object_unref (priv->grabbed_widget); | ||
2594 | 731 | priv->grabbed_widget = NULL; | ||
2595 | 732 | } | ||
2596 | 733 | |||
2597 | 734 | G_OBJECT_CLASS (os_thumb_parent_class)->dispose (object); | ||
2598 | 735 | } | ||
2599 | 736 | |||
2600 | 737 | static void | ||
2601 | 738 | os_thumb_finalize (GObject *object) | ||
2602 | 739 | { | ||
2603 | 740 | G_OBJECT_CLASS (os_thumb_parent_class)->finalize (object); | ||
2604 | 741 | } | ||
2605 | 742 | |||
2606 | 743 | static void | ||
2607 | 745 | os_thumb_get_property (GObject *object, | 744 | os_thumb_get_property (GObject *object, |
2608 | 746 | guint prop_id, | 745 | guint prop_id, |
2609 | 747 | GValue *value, | 746 | GValue *value, |
Wow, major reshuffle. Kinda hard to trace everything in the diff, but I couldn't find anything unexpected.