Merge lp:~ricotz/plank/hidpi into lp:plank

Proposed by Rico Tzschichholz
Status: Merged
Merged at revision: 1008
Proposed branch: lp:~ricotz/plank/hidpi
Merge into: lp:plank
Diff against target: 259 lines (+88/-23)
6 files modified
configure.ac (+10/-0)
lib/DockRenderer.vala (+25/-5)
lib/Factories/AbstractMain.vala (+3/-0)
lib/HideManager.vala (+13/-0)
lib/PositionManager.vala (+33/-18)
vapi/compat.vapi (+4/-0)
To merge this branch: bzr merge lp:~ricotz/plank/hidpi
Reviewer Review Type Date Requested Status
Cassidy James Blaede (community) Approve
Docky Core Pending
Review via email: mp+210035@code.launchpad.net

Description of the change

Simple hack to figure out what needs to be done to support HiDPI

The main problem are Pixbuf based drawings with need to be upscaled by the scale-factor and downscaled for the dock-rendering again. The Gdk-API is providing scaled coords automatically. On the other hand Wnck is working with the real unscaled dimensions.

Run with "GDK_SCALE=2 src/plank"

To post a comment you must log in.
Revision history for this message
Cassidy James Blaede (cassidyjames) wrote :

This looks to be doing the right thing when run with GDK_SCALE=2.

review: Approve
lp:~ricotz/plank/hidpi updated
1008. By Rico Tzschichholz

Add support for GTK's HiDPI

The main problem are Pixbuf based drawings which need to be upscaled
by the scale-factor and downscaled for the dock-rendering again.

The Gdk-API is providing scaled coords automatically while Wnck is
working with and returning the real unscaled dimensions. So we are
adjusting those accordingly.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2014-01-29 10:37:49 +0000
3+++ configure.ac 2014-03-20 10:19:57 +0000
4@@ -141,6 +141,15 @@
5 # Optional Dependencies
6 # -----------------------------------------------------------
7
8+# Check for HiDPI support of Gtk+
9+GTK_MIN_VERSION=3.10.0
10+GTK_PKGS="gtk+-3.0 >= $GTK_MIN_VERSION"
11+PKG_CHECK_MODULES(GTK, $GTK_PKGS, [enable_hidpi=yes], [enable_hidpi=no])
12+if test "x$enable_hidpi" = "xyes" ; then
13+ VALAFLAGS="$VALAFLAGS --define HAVE_GTK_3_10"
14+fi
15+AM_CONDITIONAL([HAVE_hidpi], [test "x$enable_hidpi" = "xyes"])
16+
17 # Check for newer BAMF
18 BAMF_MIN_VERSION=0.4.0
19 BAMF_PKGS="libbamf3 >= $BAMF_MIN_VERSION"
20@@ -310,6 +319,7 @@
21
22 Use gee-0.8.................: ${enable_gee_0_8}
23 Dbusmenu support............: ${enable_dbusmenu}
24+ HiDPI support...............: ${enable_hidpi}
25
26 Apport support..............: ${enable_apport}
27
28
29=== modified file 'lib/DockRenderer.vala'
30--- lib/DockRenderer.vala 2014-02-27 12:27:55 +0000
31+++ lib/DockRenderer.vala 2014-03-20 10:19:57 +0000
32@@ -62,6 +62,7 @@
33
34 bool screen_is_composited = false;
35 uint reset_position_manager_timer = 0;
36+ int window_scale_factor = 1;
37
38 /**
39 * Create a new dock renderer for a dock.
40@@ -242,6 +243,13 @@
41 */
42 public void draw_dock (Context cr)
43 {
44+#if HAVE_GTK_3_10
45+#if VALA_0_22
46+ window_scale_factor = controller.window.get_window ().get_scale_factor ();
47+#else
48+ window_scale_factor = gdk_window_get_scale_factor (controller.window.get_window ());
49+#endif
50+#endif
51 // take the previous frame values into account to decide if we
52 // can bail a full draw to not miss a finishing animation-frame
53 var no_full_draw_needed = (hide_progress == 1.0 && opacity == 1.0);
54@@ -380,7 +388,7 @@
55 #if BENCHMARK
56 var start = new DateTime.now_local ();
57 #endif
58- var icon_surface = item.get_surface_copy (icon_size, icon_size, main_buffer);
59+ var icon_surface = item.get_surface_copy (icon_size * window_scale_factor, icon_size * window_scale_factor, main_buffer);
60 unowned Context icon_cr = icon_surface.Context;
61
62 DockSurface? icon_shadow_surface = null;
63@@ -532,14 +540,26 @@
64
65 // draw the icon shadow
66 if (icon_shadow_surface != null) {
67+ if (window_scale_factor > 1) {
68+ shadow_cr.save ();
69+ shadow_cr.scale (1.0 / window_scale_factor, 1.0 / window_scale_factor);
70+ }
71 shadow_cr.set_operator (Cairo.Operator.OVER);
72- shadow_cr.set_source_surface (icon_shadow_surface.Internal, draw_value.draw_region.x - shadow_size, draw_value.draw_region.y - shadow_size);
73+ shadow_cr.set_source_surface (icon_shadow_surface.Internal, (draw_value.draw_region.x - shadow_size) * window_scale_factor, (draw_value.draw_region.y - shadow_size) * window_scale_factor);
74 shadow_cr.paint ();
75+ if (window_scale_factor > 1)
76+ shadow_cr.restore ();
77 }
78
79 // draw the icon
80- main_cr.set_source_surface (icon_surface.Internal, draw_value.draw_region.x, draw_value.draw_region.y);
81+ if (window_scale_factor > 1) {
82+ main_cr.save ();
83+ main_cr.scale (1.0 / window_scale_factor, 1.0 / window_scale_factor);
84+ }
85+ main_cr.set_source_surface (icon_surface.Internal, draw_value.draw_region.x * window_scale_factor, draw_value.draw_region.y * window_scale_factor);
86 main_cr.paint ();
87+ if (window_scale_factor > 1)
88+ main_cr.restore ();
89
90 // draw indicators
91 if (item.Indicator != IndicatorState.NONE)
92@@ -559,7 +579,7 @@
93 Logger.verbose ("DockItem.draw_item_overlay (width = %i, height = %i)", width, height);
94 var surface = new DockSurface.with_dock_surface (width, height, icon_surface);
95
96- var icon_size = position_manager.IconSize;
97+ var icon_size = position_manager.IconSize * window_scale_factor;
98 var urgent_color = get_styled_color ();
99 urgent_color.add_hue (theme.UrgentHueShift);
100
101@@ -576,7 +596,7 @@
102
103 DockSurface draw_item_shadow (DockItem item, DockSurface icon_surface, DockSurface? current_surface)
104 {
105- var shadow_size = controller.position_manager.IconShadowSize;
106+ var shadow_size = controller.position_manager.IconShadowSize * window_scale_factor;
107
108 // Inflate size to fit shadow
109 var width = icon_surface.Width + 2 * shadow_size;
110
111=== modified file 'lib/Factories/AbstractMain.vala'
112--- lib/Factories/AbstractMain.vala 2013-11-15 15:14:36 +0000
113+++ lib/Factories/AbstractMain.vala 2014-03-20 10:19:57 +0000
114@@ -175,6 +175,9 @@
115 message ("Kernel version: %s", Posix.utsname ().release);
116 message ("GLib version: %u.%u.%u", GLib.Version.major, GLib.Version.minor, GLib.Version.micro);
117 message ("GTK+ version: %u.%u.%u", Gtk.get_major_version (), Gtk.get_minor_version () , Gtk.get_micro_version ());
118+#if HAVE_GTK_3_10
119+ message ("+ HiDPI support enabled");
120+#endif
121 message ("Wnck version: %d.%d.%d", Wnck.Version.MAJOR_VERSION, Wnck.Version.MINOR_VERSION, Wnck.Version.MICRO_VERSION);
122 message ("Cairo version: %s", Cairo.version_string ());
123 message ("Pango version: %s", Pango.version_string ());
124
125=== modified file 'lib/HideManager.vala'
126--- lib/HideManager.vala 2014-02-18 07:45:27 +0000
127+++ lib/HideManager.vala 2014-03-20 10:19:57 +0000
128@@ -317,6 +317,19 @@
129 void update_window_intersect ()
130 {
131 var dock_rect = controller.position_manager.get_static_dock_region ();
132+#if HAVE_GTK_3_10
133+#if VALA_0_22
134+ var window_scale_factor = controller.window.get_window ().get_scale_factor ();
135+#else
136+ var window_scale_factor = gdk_window_get_scale_factor (controller.window.get_window ());
137+#endif
138+ if (window_scale_factor > 1) {
139+ dock_rect.x *= window_scale_factor;
140+ dock_rect.y *= window_scale_factor;
141+ dock_rect.width *= window_scale_factor;
142+ dock_rect.height *= window_scale_factor;
143+ }
144+#endif
145
146 var intersect = false;
147 var dialog_intersect = false;
148
149=== modified file 'lib/PositionManager.vala'
150--- lib/PositionManager.vala 2014-02-13 10:40:46 +0000
151+++ lib/PositionManager.vala 2014-03-20 10:19:57 +0000
152@@ -106,6 +106,7 @@
153 Gdk.Rectangle monitor_geo;
154
155 bool screen_is_composited;
156+ int window_scale_factor = 1;
157
158 /**
159 * Creates a new position manager.
160@@ -436,24 +437,31 @@
161 {
162 var cursor_region = static_dock_region;
163 var progress = 1.0 - controller.renderer.hide_progress;
164+#if HAVE_GTK_3_10
165+#if VALA_0_22
166+ window_scale_factor = controller.window.get_window ().get_scale_factor ();
167+#else
168+ window_scale_factor = gdk_window_get_scale_factor (controller.window.get_window ());
169+#endif
170+#endif
171
172 switch (controller.prefs.Position) {
173 default:
174 case PositionType.BOTTOM:
175- cursor_region.height = int.max (1, (int) (progress * cursor_region.height));
176- cursor_region.y = DockHeight - cursor_region.height;
177+ cursor_region.height = int.max (1 * window_scale_factor, (int) (progress * cursor_region.height));
178+ cursor_region.y = DockHeight - cursor_region.height + (window_scale_factor - 1);
179 break;
180 case PositionType.TOP:
181- cursor_region.height = int.max (1, (int) (progress * cursor_region.height));
182+ cursor_region.height = int.max (1 * window_scale_factor, (int) (progress * cursor_region.height));
183 cursor_region.y = 0;
184 break;
185 case PositionType.LEFT:
186- cursor_region.width = int.max (1, (int) (progress * cursor_region.width));
187+ cursor_region.width = int.max (1 * window_scale_factor, (int) (progress * cursor_region.width));
188 cursor_region.x = 0;
189 break;
190 case PositionType.RIGHT:
191- cursor_region.width = int.max (1, (int) (progress * cursor_region.width));
192- cursor_region.x = DockWidth - cursor_region.width;
193+ cursor_region.width = int.max (1 * window_scale_factor, (int) (progress * cursor_region.width));
194+ cursor_region.x = DockWidth - cursor_region.width + (window_scale_factor - 1);
195 break;
196 }
197
198@@ -1065,27 +1073,34 @@
199 */
200 public void get_struts (ref ulong[] struts)
201 {
202+#if HAVE_GTK_3_10
203+#if VALA_0_22
204+ window_scale_factor = controller.window.get_window ().get_scale_factor ();
205+#else
206+ window_scale_factor = gdk_window_get_scale_factor (controller.window.get_window ());
207+#endif
208+#endif
209 switch (controller.prefs.Position) {
210 default:
211 case PositionType.BOTTOM:
212- struts [Struts.BOTTOM] = VisibleDockHeight + controller.window.get_screen ().get_height () - monitor_geo.y - monitor_geo.height;
213- struts [Struts.BOTTOM_START] = monitor_geo.x;
214- struts [Struts.BOTTOM_END] = monitor_geo.x + monitor_geo.width - 1;
215+ struts [Struts.BOTTOM] = (VisibleDockHeight + controller.window.get_screen ().get_height () - monitor_geo.y - monitor_geo.height) * window_scale_factor;
216+ struts [Struts.BOTTOM_START] = monitor_geo.x * window_scale_factor;
217+ struts [Struts.BOTTOM_END] = (monitor_geo.x + monitor_geo.width) * window_scale_factor - 1;
218 break;
219 case PositionType.TOP:
220- struts [Struts.TOP] = monitor_geo.y + VisibleDockHeight;
221- struts [Struts.TOP_START] = monitor_geo.x;
222- struts [Struts.TOP_END] = monitor_geo.x + monitor_geo.width - 1;
223+ struts [Struts.TOP] = (monitor_geo.y + VisibleDockHeight) * window_scale_factor;
224+ struts [Struts.TOP_START] = monitor_geo.x * window_scale_factor;
225+ struts [Struts.TOP_END] = (monitor_geo.x + monitor_geo.width) * window_scale_factor - 1;
226 break;
227 case PositionType.LEFT:
228- struts [Struts.LEFT] = monitor_geo.x + VisibleDockWidth;
229- struts [Struts.LEFT_START] = monitor_geo.y;
230- struts [Struts.LEFT_END] = monitor_geo.y + monitor_geo.height - 1;
231+ struts [Struts.LEFT] = (monitor_geo.x + VisibleDockWidth) * window_scale_factor;
232+ struts [Struts.LEFT_START] = monitor_geo.y * window_scale_factor;
233+ struts [Struts.LEFT_END] = (monitor_geo.y + monitor_geo.height) * window_scale_factor - 1;
234 break;
235 case PositionType.RIGHT:
236- struts [Struts.RIGHT] = VisibleDockWidth + controller.window.get_screen ().get_width () - monitor_geo.x - monitor_geo.width;
237- struts [Struts.RIGHT_START] = monitor_geo.y;
238- struts [Struts.RIGHT_END] = monitor_geo.y + monitor_geo.height - 1;
239+ struts [Struts.RIGHT] = (VisibleDockWidth + controller.window.get_screen ().get_width () - monitor_geo.x - monitor_geo.width) * window_scale_factor;
240+ struts [Struts.RIGHT_START] = monitor_geo.y * window_scale_factor;
241+ struts [Struts.RIGHT_END] = (monitor_geo.y + monitor_geo.height) * window_scale_factor - 1;
242 break;
243 }
244 }
245
246=== modified file 'vapi/compat.vapi'
247--- vapi/compat.vapi 2014-02-14 07:00:32 +0000
248+++ vapi/compat.vapi 2014-03-20 10:19:57 +0000
249@@ -21,6 +21,10 @@
250 [CCode (cheader_filename = "gdk-pixbuf/gdk-pixbuf.h", cname = "gdk_pixbuf_new_from_resource")]
251 public Gdk.Pixbuf gdk_pixbuf_new_from_resource (string resource_path) throws GLib.Error;
252 #endif
253+#if !VALA_0_22 && HAVE_GTK_3_10
254+ [CCode (cheader_filename = "gdk/gdk.h", cname = "gdk_window_get_scale_factor")]
255+ public int gdk_window_get_scale_factor (Gdk.Window window);
256+#endif
257 #if !VALA_0_24
258 [CCode (cheader_filename = "gtk/gtk.h", cname = "gtk_widget_shape_combine_region")]
259 public void gtk_widget_shape_combine_region (Gtk.Widget widget, Cairo.Region? region);

Subscribers

People subscribed via source and target branches

to status/vote changes: