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
1=== modified file 'os/os-private.h'
2--- os/os-private.h 2011-12-19 15:50:31 +0000
3+++ os/os-private.h 2012-01-19 16:40:29 +0000
4@@ -38,6 +38,9 @@
5 #define THUMB_WIDTH 21
6 #define THUMB_HEIGHT 68
7
8+/* Number of tolerance pixels on drag, while intercepting a motion-notify-event. */
9+#define TOLERANCE_DRAG 9
10+
11 /* Number of tolerance pixels on pageup/down, while intercepting a motion-notify-event. */
12 #define TOLERANCE_MOTION 2
13
14
15=== modified file 'os/os-scrollbar.c'
16--- os/os-scrollbar.c 2012-01-17 09:54:26 +0000
17+++ os/os-scrollbar.c 2012-01-19 16:40:29 +0000
18@@ -124,6 +124,7 @@
19 OsSide side;
20 OsWindowFilter filter;
21 gboolean active_window;
22+ gboolean allow_resize;
23 gboolean deactivable_bar;
24 gboolean hidable_thumb;
25 gboolean window_button_press; /* FIXME(Cimi) to replace with X11 input events. */
26@@ -1984,18 +1985,94 @@
27 if (priv->event & OS_EVENT_BUTTON_PRESS)
28 {
29 gint x, y;
30+ gint f_x, f_y;
31+
32+ f_x = abs (priv->pointer.x - event->x);
33+ f_y = abs (priv->pointer.y - event->y);
34
35 /* Use tolerance at the first calls to this motion notify event. */
36 if (!(priv->event & OS_EVENT_MOTION_NOTIFY) &&
37- abs (priv->pointer.x - event->x) <= TOLERANCE_MOTION &&
38- abs (priv->pointer.y - event->y) <= TOLERANCE_MOTION)
39+ f_x <= TOLERANCE_MOTION &&
40+ f_y <= TOLERANCE_MOTION)
41 return FALSE;
42
43+ /* The scrollbar allows resize, and a scrolling is not started yet.
44+ * Decide if the user will start a window resize or a normal scroll. */
45+ if (priv->allow_resize &&
46+ !(priv->event & OS_EVENT_MOTION_NOTIFY))
47+ {
48+ /* Trying to draw the area of interest,
49+ * in the case of a vertical scrollbar.
50+ * Everything is reflected for horizontal scrollbars.
51+ *
52+ * + +
53+ * + SCROLLING +
54+ * + +
55+ * + + + +
56+ * R + + + + + + + R
57+ * E + + E
58+ * S + no action + S
59+ * I + taken + I
60+ * Z + + Z
61+ * E + + + + + + + E
62+ * + + + +
63+ * + +
64+ * + SCROLLING +
65+ * + +
66+ *
67+ * The diagonal lines are inclined differently, using 0.5 * f_y.
68+ **/
69+ if (((priv->side == OS_SIDE_RIGHT || priv->side == OS_SIDE_LEFT) && f_x > 0.5 * f_y) ||
70+ ((priv->side == OS_SIDE_BOTTOM || priv->side == OS_SIDE_TOP) && f_y > 0.5 * f_x))
71+ {
72+ /* We're either in the 'RESIZE' or in the 'no action taken' area. */
73+ if (((priv->side == OS_SIDE_RIGHT || priv->side == OS_SIDE_LEFT) && f_x > TOLERANCE_DRAG) ||
74+ ((priv->side == OS_SIDE_BOTTOM || priv->side == OS_SIDE_TOP) && f_y > TOLERANCE_DRAG))
75+ {
76+ /* We're in the 'RESIZE' area.
77+ * Set the right resize type and hide the thumb. */
78+ GdkWindowEdge window_edge;
79+
80+ switch (priv->side)
81+ {
82+ default:
83+ case OS_SIDE_RIGHT:
84+ window_edge = GDK_WINDOW_EDGE_EAST;
85+ break;
86+ case OS_SIDE_BOTTOM:
87+ window_edge = GDK_WINDOW_EDGE_SOUTH;
88+ break;
89+ case OS_SIDE_LEFT:
90+ window_edge = GDK_WINDOW_EDGE_WEST;
91+ break;
92+ case OS_SIDE_TOP:
93+ window_edge = GDK_WINDOW_EDGE_NORTH;
94+ break;
95+ }
96+
97+ gdk_window_begin_resize_drag (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar))),
98+ window_edge,
99+ 1,
100+ event->x_root,
101+ event->y_root,
102+ event->time);
103+ gtk_widget_hide (widget);
104+ }
105+ /* We're in the 'no action taken' area.
106+ * Skip this event. */
107+ return FALSE;
108+ }
109+
110+ /* We're in the 'SCROLLING' area.
111+ * Continue processing the event. */
112+ }
113+
114 if (!(priv->event & OS_EVENT_MOTION_NOTIFY))
115 {
116 /* Check if we can consider the thumb movement connected with the overlay. */
117 check_connection (scrollbar);
118
119+ /* It is a scrolling event, set the flag. */
120 priv->event |= OS_EVENT_MOTION_NOTIFY;
121 }
122
123@@ -3318,6 +3395,59 @@
124 }
125 }
126
127+/* Retrieve if the thumb can resize its toplevel window. */
128+static void
129+retrieve_resizability (OsScrollbar *scrollbar)
130+{
131+ GdkWindow *scrollbar_window;
132+ GdkWindow *toplevel_window;
133+ OsScrollbarPrivate *priv;
134+ gint x, y;
135+ gint x_pos, y_pos;
136+
137+ priv = scrollbar->priv;
138+
139+ /* By default, they don't allow resize. */
140+ priv->allow_resize = FALSE;
141+
142+ scrollbar_window = gtk_widget_get_window (GTK_WIDGET (scrollbar));
143+
144+ if (!scrollbar_window)
145+ return;
146+
147+ toplevel_window = gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar)));
148+
149+ gdk_window_get_origin (toplevel_window, &x, &y);
150+
151+ gdk_window_get_root_coords (scrollbar_window,
152+ priv->thumb_all.x, priv->thumb_all.y,
153+ &x_pos, &y_pos);
154+
155+ /* Check if the thumb is next to a window edge,
156+ * if that's the case, set the allow_resize gboolean. */
157+ switch (priv->side)
158+ {
159+ case OS_SIDE_RIGHT:
160+ if (x + gdk_window_get_width (toplevel_window) - x_pos <= THUMB_WIDTH)
161+ priv->allow_resize = TRUE;
162+ break;
163+ case OS_SIDE_BOTTOM:
164+ if (y + gdk_window_get_height (toplevel_window) - y_pos <= THUMB_WIDTH)
165+ priv->allow_resize = TRUE;
166+ break;
167+ case OS_SIDE_LEFT:
168+ if (x_pos - x <= THUMB_WIDTH)
169+ priv->allow_resize = TRUE;
170+ break;
171+ case OS_SIDE_TOP:
172+ if (y_pos - y <= THUMB_WIDTH)
173+ priv->allow_resize = TRUE;
174+ break;
175+ default:
176+ break;
177+ }
178+}
179+
180 static void
181 os_scrollbar_size_allocate (GtkWidget *widget,
182 GdkRectangle *allocation)
183@@ -3396,6 +3526,9 @@
184
185 move_bar (scrollbar);
186
187+ /* Set resizability. */
188+ retrieve_resizability (scrollbar);
189+
190 gtk_widget_set_allocation (widget, allocation);
191 }
192
193
194=== modified file 'os/os-thumb.c'
195--- os/os-thumb.c 2011-12-20 14:29:14 +0000
196+++ os/os-thumb.c 2012-01-19 16:40:29 +0000
197@@ -1110,6 +1110,8 @@
198
199 priv->tolerance = FALSE;
200
201+ gtk_grab_remove (widget);
202+
203 if (priv->grabbed_widget != NULL && gtk_widget_get_mapped (priv->grabbed_widget))
204 gtk_grab_add (priv->grabbed_widget);
205

Subscribers

People subscribed via source and target branches