Merge lp:~cimi/overlay-scrollbar/unity-net-workarea-region into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 258
Merged at revision: 249
Proposed branch: lp:~cimi/overlay-scrollbar/unity-net-workarea-region
Merge into: lp:overlay-scrollbar
Diff against target: 235 lines (+140/-12)
1 file modified
os/os-scrollbar.c (+140/-12)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/unity-net-workarea-region
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+64331@code.launchpad.net
To post a comment you must log in.
251. By Andrea Cimitan

Cast the two GdkRectangle

252. By Andrea Cimitan

Gets the root window of the proper screen and display

253. By Andrea Cimitan

Added a FIXME

254. By Andrea Cimitan

Now uses the right window on the right screen

255. By Andrea Cimitan

Added a FIXME for the root window on screen-changed

256. By Andrea Cimitan

Added comment to the static function

257. By Andrea Cimitan

Typo

258. By Andrea Cimitan

Removed the FIXME as the screen does not change for a widget in X11

Revision history for this message
Ted Gould (ted) wrote :

You're right in the comment! You should put the clear in the if statement so that it doesn't change unless you're sure you're making it better. If for some reason it failed, it's better to leave it in the default state rather than clearing it.

review: Approve
Revision history for this message
Andrea Cimitan (cimi) wrote :

but in sanitize_x/y, if the region is empty, usage of region is skipped... so again, won't change much if the xgetwindowproperty fail.

basically we have two solutions if xgetwindowproperty fails:
1) the scrollbars won't take into account the struts (like now, because the region is cleared everytime).
2) the scrollbars will use the region calculated before (if the region will be cleared only inside the if statement).

Revision history for this message
Ted Gould (ted) wrote :

Would it make things simpler if we just make the default square be the
screensize and then we don't have to detect if it's empty?

Revision history for this message
Andrea Cimitan (cimi) wrote :

it's exactly the same ted. the code to clear the region is used just because union is used, so if you don't clear the previous region then you'll obtain a bigger region

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'os/os-scrollbar.c'
--- os/os-scrollbar.c 2011-06-09 17:12:44 +0000
+++ os/os-scrollbar.c 2011-06-12 23:49:28 +0000
@@ -27,6 +27,8 @@
27#include "os-scrollbar.h"27#include "os-scrollbar.h"
28#include "os-private.h"28#include "os-private.h"
29#include <gdk/gdkx.h>29#include <gdk/gdkx.h>
30#include <X11/Xatom.h>
31#include <X11/Xutil.h>
30#include <X11/extensions/XInput2.h>32#include <X11/extensions/XInput2.h>
31#include "math.h"33#include "math.h"
3234
@@ -86,7 +88,9 @@
86};88};
8789
88static Atom net_active_window_atom = None;90static Atom net_active_window_atom = None;
91static Atom unity_net_workarea_region_atom = None;
89static GList *os_root_list = NULL;92static GList *os_root_list = NULL;
93static cairo_region_t *os_workarea = NULL;
9094
91static void swap_adjustment (OsScrollbar *scrollbar, GtkAdjustment *adjustment);95static void swap_adjustment (OsScrollbar *scrollbar, GtkAdjustment *adjustment);
92static void swap_thumb (OsScrollbar *scrollbar, GtkWidget *thumb);96static void swap_thumb (OsScrollbar *scrollbar, GtkWidget *thumb);
@@ -270,6 +274,56 @@
270 }274 }
271}275}
272276
277/* calculate the workarea using _UNITY_NET_WORKAREA_REGION */
278static void
279calc_workarea (Display *display,
280 Window root)
281{
282 Atom type;
283 cairo_rectangle_int_t test;
284 gint result, fmt;
285 gulong nitems, nleft;
286 guchar *property_data;
287 gulong *long_data;
288 guint i;
289
290 result = XGetWindowProperty (display, root,
291 unity_net_workarea_region_atom,
292 0L, 4096L, FALSE, XA_CARDINAL,
293 &type, &fmt, &nitems, &nleft, &property_data);
294
295 /* clear the os_workarea region,
296 * before the union with the new rectangles.
297 * Maybe it'd be better to place this call
298 * inside the if statement below. */
299 cairo_region_subtract (os_workarea, os_workarea);
300
301 if (result == Success && property_data)
302 {
303 long_data = (gulong*) property_data;
304
305 if (fmt == 32 && type == XA_CARDINAL && nitems % 4 == 0)
306 {
307 int count;
308 unsigned int i;
309
310 count = nitems / 4;
311
312 for (i = 0; i < count; i++)
313 {
314 cairo_rectangle_int_t rect;
315
316 rect.x = long_data[i * 4 + 0];
317 rect.y = long_data[i * 4 + 1];
318 rect.width = long_data[i * 4 + 2];
319 rect.height = long_data[i * 4 + 3];
320
321 cairo_region_union_rectangle (os_workarea, &rect);
322 }
323 }
324 }
325}
326
273/* deactivate the pager if it's the case */327/* deactivate the pager if it's the case */
274static void328static void
275deactivate_pager (OsScrollbar *scrollbar)329deactivate_pager (OsScrollbar *scrollbar)
@@ -364,7 +418,7 @@
364 gint x,418 gint x,
365 gint y)419 gint y)
366{420{
367 GdkRectangle rect;421 cairo_rectangle_int_t rect;
368 OsScrollbarPrivate *priv;422 OsScrollbarPrivate *priv;
369 gint screen_width, n_monitor;423 gint screen_width, n_monitor;
370 GdkScreen *screen;424 GdkScreen *screen;
@@ -375,9 +429,37 @@
375 * to calculate monitor boundaries. */429 * to calculate monitor boundaries. */
376 screen = gtk_widget_get_screen (GTK_WIDGET (scrollbar)); 430 screen = gtk_widget_get_screen (GTK_WIDGET (scrollbar));
377 n_monitor = gdk_screen_get_monitor_at_point (screen, x - 1, y);431 n_monitor = gdk_screen_get_monitor_at_point (screen, x - 1, y);
378 gdk_screen_get_monitor_geometry (screen, n_monitor, &rect);432 gdk_screen_get_monitor_geometry (screen, n_monitor, (GdkRectangle*) &rect);
379433
380 screen_width = rect.x + rect.width;434 if (cairo_region_is_empty (os_workarea))
435 screen_width = rect.x + rect.width;
436 else
437 {
438 cairo_region_t *monitor_workarea;
439 cairo_rectangle_int_t tmp_rect;
440 gint i, x, width;
441
442 x = rect.x;
443 width = rect.width;
444
445 monitor_workarea = cairo_region_create_rectangle (&rect);
446
447 cairo_region_intersect (monitor_workarea, os_workarea);
448
449 for (i = 0; i < cairo_region_num_rectangles (monitor_workarea); i++)
450 {
451 cairo_region_get_rectangle (monitor_workarea, i, &tmp_rect);
452
453 if (tmp_rect.x > x)
454 x = tmp_rect.x;
455 if (tmp_rect.x + tmp_rect.width < width)
456 width = tmp_rect.x + tmp_rect.width;
457 }
458
459 screen_width = x + width;
460
461 cairo_region_destroy (monitor_workarea);
462 }
381463
382 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&464 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
383 (n_monitor != gdk_screen_get_monitor_at_point (screen, x - 1 + priv->slider.width, y) ||465 (n_monitor != gdk_screen_get_monitor_at_point (screen, x - 1 + priv->slider.width, y) ||
@@ -399,7 +481,7 @@
399 gint x,481 gint x,
400 gint y)482 gint y)
401{483{
402 GdkRectangle rect;484 cairo_rectangle_int_t rect;
403 OsScrollbarPrivate *priv;485 OsScrollbarPrivate *priv;
404 gint screen_height, n_monitor;486 gint screen_height, n_monitor;
405 GdkScreen *screen;487 GdkScreen *screen;
@@ -410,9 +492,37 @@
410 * to calculate monitor boundaries. */492 * to calculate monitor boundaries. */
411 screen = gtk_widget_get_screen (GTK_WIDGET (scrollbar)); 493 screen = gtk_widget_get_screen (GTK_WIDGET (scrollbar));
412 n_monitor = gdk_screen_get_monitor_at_point (screen, x, y - 1);494 n_monitor = gdk_screen_get_monitor_at_point (screen, x, y - 1);
413 gdk_screen_get_monitor_geometry (screen, n_monitor, &rect);495 gdk_screen_get_monitor_geometry (screen, n_monitor, (GdkRectangle*) &rect);
414 496
415 screen_height = rect.y + rect.height;497 if (cairo_region_is_empty (os_workarea))
498 screen_height = rect.y + rect.height;
499 else
500 {
501 cairo_region_t *monitor_workarea;
502 cairo_rectangle_int_t tmp_rect;
503 gint i, y, height;
504
505 y = rect.y;
506 height = rect.height;
507
508 monitor_workarea = cairo_region_create_rectangle (&rect);
509
510 cairo_region_intersect (monitor_workarea, os_workarea);
511
512 for (i = 0; i < cairo_region_num_rectangles (monitor_workarea); i++)
513 {
514 cairo_region_get_rectangle (monitor_workarea, i, &tmp_rect);
515
516 if (tmp_rect.y > y)
517 y = tmp_rect.y;
518 if (tmp_rect.y + tmp_rect.height < height)
519 height = tmp_rect.y + tmp_rect.height;
520 }
521
522 screen_height = y + height;
523
524 cairo_region_destroy (monitor_workarea);
525 }
416526
417 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&527 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
418 (n_monitor != gdk_screen_get_monitor_at_point (screen, x, y - 1 + priv->slider.height) ||528 (n_monitor != gdk_screen_get_monitor_at_point (screen, x, y - 1 + priv->slider.height) ||
@@ -847,10 +957,16 @@
847957
848 xev = gdkxevent;958 xev = gdkxevent;
849959
850 if (xev->xany.type == PropertyNotify &&960 if (xev->type == PropertyNotify)
851 xev->xproperty.atom == net_active_window_atom)
852 {961 {
853 g_list_foreach (os_root_list, root_gfunc, NULL);962 if (xev->xproperty.atom == net_active_window_atom)
963 {
964 g_list_foreach (os_root_list, root_gfunc, NULL);
965 }
966 else if (xev->xproperty.atom == unity_net_workarea_region_atom)
967 {
968 calc_workarea (xev->xany.display, xev->xany.window);
969 }
854 }970 }
855971
856 return GDK_FILTER_CONTINUE;972 return GDK_FILTER_CONTINUE;
@@ -1997,16 +2113,22 @@
19972113
1998 if (os_root_list == NULL)2114 if (os_root_list == NULL)
1999 {2115 {
2116 GdkScreen *screen;
2000 GdkWindow *root;2117 GdkWindow *root;
20012118
2002 /* used in the root_filter_func to match the right property. */2119 /* used in the root_filter_func to match the right property. */
2003 net_active_window_atom = gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW");2120 net_active_window_atom = gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW");
2121 unity_net_workarea_region_atom = gdk_x11_get_xatom_by_name ("_UNITY_NET_WORKAREA_REGION");
20042122
2005 /* append the object to the static linked list. */2123 /* append the object to the static linked list. */
2006 os_root_list = g_list_append (os_root_list, scrollbar);2124 os_root_list = g_list_append (os_root_list, scrollbar);
20072125
2126 /* create the region. */
2127 os_workarea = cairo_region_create ();
2128
2008 /* apply the root_filter_func. */2129 /* apply the root_filter_func. */
2009 root = gdk_get_default_root_window ();2130 screen = gtk_widget_get_screen (GTK_WIDGET (scrollbar));
2131 root = gdk_screen_get_root_window (screen);
2010 gdk_window_set_events (root, gdk_window_get_events (root) |2132 gdk_window_set_events (root, gdk_window_get_events (root) |
2011 GDK_PROPERTY_CHANGE_MASK);2133 GDK_PROPERTY_CHANGE_MASK);
2012 gdk_window_add_filter (root, root_filter_func, NULL);2134 gdk_window_add_filter (root, root_filter_func, NULL);
@@ -2091,6 +2213,12 @@
2091 priv->window_group = NULL;2213 priv->window_group = NULL;
2092 }2214 }
20932215
2216 if (os_workarea != NULL)
2217 {
2218 cairo_region_destroy (os_workarea);
2219 os_workarea = NULL;
2220 }
2221
2094 swap_adjustment (scrollbar, NULL);2222 swap_adjustment (scrollbar, NULL);
2095 swap_thumb (scrollbar, NULL);2223 swap_thumb (scrollbar, NULL);
20962224

Subscribers

People subscribed via source and target branches