Merge lp:~cimi/overlay-scrollbar/resize-using-thumbs into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 335
Merged at revision: 333
Proposed branch: lp:~cimi/overlay-scrollbar/resize-using-thumbs
Merge into: lp:overlay-scrollbar
Diff against target: 204 lines (+140/-2)
3 files modified
os/os-private.h (+3/-0)
os/os-scrollbar.c (+135/-2)
os/os-thumb.c (+2/-0)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/resize-using-thumbs
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+89092@code.launchpad.net

Description of the change

Allow resizing the toplevel window using scrollbars close to a window edge

To post a comment you must log in.
334. By Andrea Cimitan

Typos

335. By Andrea Cimitan

Comments

Revision history for this message
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'os/os-private.h'
--- os/os-private.h 2011-12-19 15:50:31 +0000
+++ os/os-private.h 2012-01-19 16:40:29 +0000
@@ -38,6 +38,9 @@
38#define THUMB_WIDTH 2138#define THUMB_WIDTH 21
39#define THUMB_HEIGHT 6839#define THUMB_HEIGHT 68
4040
41/* Number of tolerance pixels on drag, while intercepting a motion-notify-event. */
42#define TOLERANCE_DRAG 9
43
41/* Number of tolerance pixels on pageup/down, while intercepting a motion-notify-event. */44/* Number of tolerance pixels on pageup/down, while intercepting a motion-notify-event. */
42#define TOLERANCE_MOTION 245#define TOLERANCE_MOTION 2
4346
4447
=== modified file 'os/os-scrollbar.c'
--- os/os-scrollbar.c 2012-01-17 09:54:26 +0000
+++ os/os-scrollbar.c 2012-01-19 16:40:29 +0000
@@ -124,6 +124,7 @@
124 OsSide side;124 OsSide side;
125 OsWindowFilter filter;125 OsWindowFilter filter;
126 gboolean active_window;126 gboolean active_window;
127 gboolean allow_resize;
127 gboolean deactivable_bar;128 gboolean deactivable_bar;
128 gboolean hidable_thumb;129 gboolean hidable_thumb;
129 gboolean window_button_press; /* FIXME(Cimi) to replace with X11 input events. */130 gboolean window_button_press; /* FIXME(Cimi) to replace with X11 input events. */
@@ -1984,18 +1985,94 @@
1984 if (priv->event & OS_EVENT_BUTTON_PRESS)1985 if (priv->event & OS_EVENT_BUTTON_PRESS)
1985 {1986 {
1986 gint x, y;1987 gint x, y;
1988 gint f_x, f_y;
1989
1990 f_x = abs (priv->pointer.x - event->x);
1991 f_y = abs (priv->pointer.y - event->y);
19871992
1988 /* Use tolerance at the first calls to this motion notify event. */1993 /* Use tolerance at the first calls to this motion notify event. */
1989 if (!(priv->event & OS_EVENT_MOTION_NOTIFY) &&1994 if (!(priv->event & OS_EVENT_MOTION_NOTIFY) &&
1990 abs (priv->pointer.x - event->x) <= TOLERANCE_MOTION &&1995 f_x <= TOLERANCE_MOTION &&
1991 abs (priv->pointer.y - event->y) <= TOLERANCE_MOTION)1996 f_y <= TOLERANCE_MOTION)
1992 return FALSE;1997 return FALSE;
19931998
1999 /* The scrollbar allows resize, and a scrolling is not started yet.
2000 * Decide if the user will start a window resize or a normal scroll. */
2001 if (priv->allow_resize &&
2002 !(priv->event & OS_EVENT_MOTION_NOTIFY))
2003 {
2004 /* Trying to draw the area of interest,
2005 * in the case of a vertical scrollbar.
2006 * Everything is reflected for horizontal scrollbars.
2007 *
2008 * + +
2009 * + SCROLLING +
2010 * + +
2011 * + + + +
2012 * R + + + + + + + R
2013 * E + + E
2014 * S + no action + S
2015 * I + taken + I
2016 * Z + + Z
2017 * E + + + + + + + E
2018 * + + + +
2019 * + +
2020 * + SCROLLING +
2021 * + +
2022 *
2023 * The diagonal lines are inclined differently, using 0.5 * f_y.
2024 **/
2025 if (((priv->side == OS_SIDE_RIGHT || priv->side == OS_SIDE_LEFT) && f_x > 0.5 * f_y) ||
2026 ((priv->side == OS_SIDE_BOTTOM || priv->side == OS_SIDE_TOP) && f_y > 0.5 * f_x))
2027 {
2028 /* We're either in the 'RESIZE' or in the 'no action taken' area. */
2029 if (((priv->side == OS_SIDE_RIGHT || priv->side == OS_SIDE_LEFT) && f_x > TOLERANCE_DRAG) ||
2030 ((priv->side == OS_SIDE_BOTTOM || priv->side == OS_SIDE_TOP) && f_y > TOLERANCE_DRAG))
2031 {
2032 /* We're in the 'RESIZE' area.
2033 * Set the right resize type and hide the thumb. */
2034 GdkWindowEdge window_edge;
2035
2036 switch (priv->side)
2037 {
2038 default:
2039 case OS_SIDE_RIGHT:
2040 window_edge = GDK_WINDOW_EDGE_EAST;
2041 break;
2042 case OS_SIDE_BOTTOM:
2043 window_edge = GDK_WINDOW_EDGE_SOUTH;
2044 break;
2045 case OS_SIDE_LEFT:
2046 window_edge = GDK_WINDOW_EDGE_WEST;
2047 break;
2048 case OS_SIDE_TOP:
2049 window_edge = GDK_WINDOW_EDGE_NORTH;
2050 break;
2051 }
2052
2053 gdk_window_begin_resize_drag (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar))),
2054 window_edge,
2055 1,
2056 event->x_root,
2057 event->y_root,
2058 event->time);
2059 gtk_widget_hide (widget);
2060 }
2061 /* We're in the 'no action taken' area.
2062 * Skip this event. */
2063 return FALSE;
2064 }
2065
2066 /* We're in the 'SCROLLING' area.
2067 * Continue processing the event. */
2068 }
2069
1994 if (!(priv->event & OS_EVENT_MOTION_NOTIFY))2070 if (!(priv->event & OS_EVENT_MOTION_NOTIFY))
1995 {2071 {
1996 /* Check if we can consider the thumb movement connected with the overlay. */2072 /* Check if we can consider the thumb movement connected with the overlay. */
1997 check_connection (scrollbar);2073 check_connection (scrollbar);
19982074
2075 /* It is a scrolling event, set the flag. */
1999 priv->event |= OS_EVENT_MOTION_NOTIFY;2076 priv->event |= OS_EVENT_MOTION_NOTIFY;
2000 }2077 }
20012078
@@ -3318,6 +3395,59 @@
3318 }3395 }
3319}3396}
33203397
3398/* Retrieve if the thumb can resize its toplevel window. */
3399static void
3400retrieve_resizability (OsScrollbar *scrollbar)
3401{
3402 GdkWindow *scrollbar_window;
3403 GdkWindow *toplevel_window;
3404 OsScrollbarPrivate *priv;
3405 gint x, y;
3406 gint x_pos, y_pos;
3407
3408 priv = scrollbar->priv;
3409
3410 /* By default, they don't allow resize. */
3411 priv->allow_resize = FALSE;
3412
3413 scrollbar_window = gtk_widget_get_window (GTK_WIDGET (scrollbar));
3414
3415 if (!scrollbar_window)
3416 return;
3417
3418 toplevel_window = gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar)));
3419
3420 gdk_window_get_origin (toplevel_window, &x, &y);
3421
3422 gdk_window_get_root_coords (scrollbar_window,
3423 priv->thumb_all.x, priv->thumb_all.y,
3424 &x_pos, &y_pos);
3425
3426 /* Check if the thumb is next to a window edge,
3427 * if that's the case, set the allow_resize gboolean. */
3428 switch (priv->side)
3429 {
3430 case OS_SIDE_RIGHT:
3431 if (x + gdk_window_get_width (toplevel_window) - x_pos <= THUMB_WIDTH)
3432 priv->allow_resize = TRUE;
3433 break;
3434 case OS_SIDE_BOTTOM:
3435 if (y + gdk_window_get_height (toplevel_window) - y_pos <= THUMB_WIDTH)
3436 priv->allow_resize = TRUE;
3437 break;
3438 case OS_SIDE_LEFT:
3439 if (x_pos - x <= THUMB_WIDTH)
3440 priv->allow_resize = TRUE;
3441 break;
3442 case OS_SIDE_TOP:
3443 if (y_pos - y <= THUMB_WIDTH)
3444 priv->allow_resize = TRUE;
3445 break;
3446 default:
3447 break;
3448 }
3449}
3450
3321static void3451static void
3322os_scrollbar_size_allocate (GtkWidget *widget,3452os_scrollbar_size_allocate (GtkWidget *widget,
3323 GdkRectangle *allocation)3453 GdkRectangle *allocation)
@@ -3396,6 +3526,9 @@
33963526
3397 move_bar (scrollbar);3527 move_bar (scrollbar);
33983528
3529 /* Set resizability. */
3530 retrieve_resizability (scrollbar);
3531
3399 gtk_widget_set_allocation (widget, allocation);3532 gtk_widget_set_allocation (widget, allocation);
3400}3533}
34013534
34023535
=== modified file 'os/os-thumb.c'
--- os/os-thumb.c 2011-12-20 14:29:14 +0000
+++ os/os-thumb.c 2012-01-19 16:40:29 +0000
@@ -1110,6 +1110,8 @@
11101110
1111 priv->tolerance = FALSE;1111 priv->tolerance = FALSE;
11121112
1113 gtk_grab_remove (widget);
1114
1113 if (priv->grabbed_widget != NULL && gtk_widget_get_mapped (priv->grabbed_widget))1115 if (priv->grabbed_widget != NULL && gtk_widget_get_mapped (priv->grabbed_widget))
1114 gtk_grab_add (priv->grabbed_widget);1116 gtk_grab_add (priv->grabbed_widget);
11151117

Subscribers

People subscribed via source and target branches