Merge lp:~cimi/overlay-scrollbar/internal-thumb into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Merged at revision: 137
Proposed branch: lp:~cimi/overlay-scrollbar/internal-thumb
Merge into: lp:overlay-scrollbar
Diff against target: 209 lines (+79/-15)
1 file modified
os/os-scrollbar.c (+79/-15)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/internal-thumb
Reviewer Review Type Date Requested Status
Loïc Molinari (community) Approve
Review via email: mp+52101@code.launchpad.net

Description of the change

The thumb should be inside the screen, for example for maximized windows with a scrollbar on its edge, so this patch looks at the screen dimensions and moves the thumb internally (before the pager) when needed.

To post a comment you must log in.
Revision history for this message
Loïc Molinari (loic.molinari) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'os/os-scrollbar.c'
2--- os/os-scrollbar.c 2011-03-03 16:23:53 +0000
3+++ os/os-scrollbar.c 2011-03-03 17:23:44 +0000
4@@ -28,6 +28,9 @@
5 #include "os-private.h"
6 #include <gdk/gdkx.h>
7
8+/* Default size of the pager in pixels. */
9+#define DEFAULT_PAGER_WIDTH 3
10+
11 /* Default size of the scrollbar in pixels. */
12 #define DEFAULT_SCROLLBAR_WIDTH 15
13 #define DEFAULT_SCROLLBAR_HEIGHT 80
14@@ -86,8 +89,11 @@
15 static void os_scrollbar_hide_thumb (OsScrollbar *scrollbar);
16 static gboolean os_scrollbar_hide_thumb_cb (gpointer user_data);
17 static void os_scrollbar_move (OsScrollbar *scrollbar, gint mouse_x, gint mouse_y);
18+static void os_scrollbar_move_thumb (OsScrollbar *scrollbar, gint x, gint y);
19 static void os_scrollbar_notify_adjustment_cb (GObject *object, gpointer user_data);
20 static void os_scrollbar_notify_orientation_cb (GObject *object, gpointer user_data);
21+static gint os_scrollbar_sanitize_x (OsScrollbar *scrollbar, gint x);
22+static gint os_scrollbar_sanitize_y (OsScrollbar *scrollbar, gint y);
23 static void os_scrollbar_store_window_position (OsScrollbar *scrollbar);
24 static void os_scrollbar_swap_adjustment (OsScrollbar *scrollbar, GtkAdjustment *adjustment);
25 static void os_scrollbar_swap_parent (OsScrollbar *scrollbar, GtkWidget *parent);
26@@ -398,6 +404,20 @@
27 }
28
29 static void
30+os_scrollbar_move_thumb (OsScrollbar *scrollbar,
31+ gint x,
32+ gint y)
33+{
34+ OsScrollbarPrivate *priv;
35+
36+ priv = OS_SCROLLBAR_GET_PRIVATE (scrollbar);
37+
38+ gtk_window_move (GTK_WINDOW (priv->thumb),
39+ os_scrollbar_sanitize_x (scrollbar, x),
40+ os_scrollbar_sanitize_y (scrollbar, y));
41+}
42+
43+static void
44 os_scrollbar_notify_adjustment_cb (GObject *object,
45 gpointer user_data)
46 {
47@@ -421,6 +441,50 @@
48 os_scrollbar_swap_thumb (OS_SCROLLBAR (object), os_thumb_new (priv->orientation));
49 }
50
51+static gint
52+os_scrollbar_sanitize_x (OsScrollbar *scrollbar,
53+ gint x)
54+{
55+ OsScrollbarPrivate *priv;
56+ gint screen_width;
57+
58+ priv = OS_SCROLLBAR_GET_PRIVATE (scrollbar);
59+
60+ /* FIXME we could store screen_width in priv
61+ * and change it at screen-changed signal */
62+ screen_width = gdk_screen_get_width (gtk_widget_get_screen (GTK_WIDGET (scrollbar)));
63+
64+ /* FIXME we could apply a static offest we
65+ * set in size-allocate and configure-event */
66+ if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
67+ (x + priv->slider.width > screen_width))
68+ return x - DEFAULT_PAGER_WIDTH - priv->slider.width;
69+
70+ return x;
71+}
72+
73+static gint
74+os_scrollbar_sanitize_y (OsScrollbar *scrollbar,
75+ gint y)
76+{
77+ OsScrollbarPrivate *priv;
78+ gint screen_height;
79+
80+ priv = OS_SCROLLBAR_GET_PRIVATE (scrollbar);
81+
82+ /* FIXME we could store screen_height in priv
83+ * and change it at screen-changed signal */
84+ screen_height = gdk_screen_get_height (gtk_widget_get_screen (GTK_WIDGET (scrollbar)));
85+
86+ /* FIXME we could apply a static offest we
87+ * set in size-allocate and configure-event */
88+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
89+ (y + priv->slider.height > screen_height))
90+ return y - DEFAULT_PAGER_WIDTH - priv->slider.height;
91+
92+ return y;
93+}
94+
95 /* Store scrollbar window position. */
96 static void
97 os_scrollbar_store_window_position (OsScrollbar *scrollbar)
98@@ -567,7 +631,7 @@
99
100 os_scrollbar_calc_layout_pager (scrollbar, priv->adjustment->value);
101
102- gtk_window_move (GTK_WINDOW (priv->thumb), x_pos + priv->thumb_all.x, y_pos + priv->thumb_all.y);
103+ os_scrollbar_move_thumb (scrollbar, x_pos + priv->thumb_all.x, y_pos + priv->thumb_all.y);
104
105 if (priv->pager != NULL)
106 {
107@@ -802,7 +866,7 @@
108 }
109 }
110
111- gtk_window_move (GTK_WINDOW (widget), x, y);
112+ os_scrollbar_move_thumb (scrollbar, x, y);
113 }
114
115 return TRUE;
116@@ -821,7 +885,7 @@
117 {
118 mask.x = 0;
119 mask.y = priv->overlay.y;
120- mask.width = 3;
121+ mask.width = DEFAULT_PAGER_WIDTH;
122 mask.height = priv->overlay.height;
123
124 if (priv->proximity == TRUE
125@@ -842,7 +906,7 @@
126 mask.x = priv->overlay.x;
127 mask.y = 0;
128 mask.width = priv->overlay.width;
129- mask.height = 3;
130+ mask.height = DEFAULT_PAGER_WIDTH;
131
132 if (priv->proximity == TRUE
133 && priv->overlay.width >= priv->overlay_all.width - 2)
134@@ -874,7 +938,7 @@
135 {
136 rect.x = priv->overlay_all.x;
137 rect.y = priv->overlay_all.y + 1;
138- rect.width = 3;
139+ rect.width = DEFAULT_PAGER_WIDTH;
140 rect.height = priv->overlay_all.height - 2;
141 }
142 else
143@@ -882,7 +946,7 @@
144 rect.x = priv->overlay_all.x + 1;
145 rect.y = priv->overlay_all.y;
146 rect.width = priv->overlay_all.width - 2;
147- rect.height = 3;
148+ rect.height = DEFAULT_PAGER_WIDTH;
149 }
150
151 os_pager_size_allocate (OS_PAGER (priv->pager), rect);
152@@ -949,14 +1013,14 @@
153 {
154 priv->slider.width = DEFAULT_SCROLLBAR_WIDTH;
155 priv->slider.height = DEFAULT_SCROLLBAR_HEIGHT;
156- priv->overlay_all.x = allocation->x + allocation->width - 3;
157+ priv->overlay_all.x = allocation->x + allocation->width - DEFAULT_PAGER_WIDTH;
158 priv->thumb_all.x = allocation->x + allocation->width;
159 }
160 else
161 {
162 priv->slider.width = DEFAULT_SCROLLBAR_HEIGHT;
163 priv->slider.height = DEFAULT_SCROLLBAR_WIDTH;
164- priv->overlay_all.y = allocation->y + allocation->height - 3;
165+ priv->overlay_all.y = allocation->y + allocation->height - DEFAULT_PAGER_WIDTH;
166 priv->thumb_all.y = allocation->y + allocation->height;
167 }
168
169@@ -984,9 +1048,9 @@
170
171 os_scrollbar_calc_layout_pager (scrollbar, priv->adjustment->value);
172 os_scrollbar_calc_layout_slider (scrollbar, priv->adjustment->value);
173- gtk_window_move (GTK_WINDOW (priv->thumb),
174- event->x + priv->thumb_all.x + priv->slider.x,
175- event->y + priv->thumb_all.y + priv->slider.y);
176+ os_scrollbar_move_thumb (scrollbar,
177+ event->x + priv->thumb_all.x + priv->slider.x,
178+ event->y + priv->thumb_all.y + priv->slider.y);
179
180 os_scrollbar_store_window_position (scrollbar);
181
182@@ -1047,11 +1111,11 @@
183 priv->thumb_all.y + priv->overlay.y,
184 priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height);
185
186- gtk_window_move (GTK_WINDOW (priv->thumb), x_pos + x, y_pos + y);
187+ os_scrollbar_move_thumb (scrollbar, x_pos + x, y_pos + y);
188 }
189 else
190 {
191- gtk_window_move (GTK_WINDOW (priv->thumb), priv->win_x, priv->win_y + priv->slider.y);
192+ os_scrollbar_move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y);
193 }
194
195 gtk_widget_show (GTK_WIDGET (priv->thumb));
196@@ -1083,11 +1147,11 @@
197 priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width);
198 y = priv->thumb_all.y;
199
200- gtk_window_move (GTK_WINDOW (priv->thumb), x_pos + x, y_pos + y);
201+ os_scrollbar_move_thumb (scrollbar, x_pos + x, y_pos + y);
202 }
203 else
204 {
205- gtk_window_move (GTK_WINDOW (priv->thumb), priv->win_x, priv->win_y + priv->slider.y);
206+ os_scrollbar_move_thumb (scrollbar, priv->win_x, priv->win_y + priv->slider.y);
207 }
208
209 gtk_widget_show (GTK_WIDGET (priv->thumb));

Subscribers

People subscribed via source and target branches