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
=== modified file 'configure.ac'
--- configure.ac 2014-01-29 10:37:49 +0000
+++ configure.ac 2014-03-20 10:19:57 +0000
@@ -141,6 +141,15 @@
141# Optional Dependencies141# Optional Dependencies
142# -----------------------------------------------------------142# -----------------------------------------------------------
143143
144# Check for HiDPI support of Gtk+
145GTK_MIN_VERSION=3.10.0
146GTK_PKGS="gtk+-3.0 >= $GTK_MIN_VERSION"
147PKG_CHECK_MODULES(GTK, $GTK_PKGS, [enable_hidpi=yes], [enable_hidpi=no])
148if test "x$enable_hidpi" = "xyes" ; then
149 VALAFLAGS="$VALAFLAGS --define HAVE_GTK_3_10"
150fi
151AM_CONDITIONAL([HAVE_hidpi], [test "x$enable_hidpi" = "xyes"])
152
144# Check for newer BAMF153# Check for newer BAMF
145BAMF_MIN_VERSION=0.4.0154BAMF_MIN_VERSION=0.4.0
146BAMF_PKGS="libbamf3 >= $BAMF_MIN_VERSION"155BAMF_PKGS="libbamf3 >= $BAMF_MIN_VERSION"
@@ -310,6 +319,7 @@
310319
311 Use gee-0.8.................: ${enable_gee_0_8}320 Use gee-0.8.................: ${enable_gee_0_8}
312 Dbusmenu support............: ${enable_dbusmenu}321 Dbusmenu support............: ${enable_dbusmenu}
322 HiDPI support...............: ${enable_hidpi}
313323
314 Apport support..............: ${enable_apport}324 Apport support..............: ${enable_apport}
315325
316326
=== modified file 'lib/DockRenderer.vala'
--- lib/DockRenderer.vala 2014-02-27 12:27:55 +0000
+++ lib/DockRenderer.vala 2014-03-20 10:19:57 +0000
@@ -62,6 +62,7 @@
62 62
63 bool screen_is_composited = false;63 bool screen_is_composited = false;
64 uint reset_position_manager_timer = 0;64 uint reset_position_manager_timer = 0;
65 int window_scale_factor = 1;
65 66
66 /**67 /**
67 * Create a new dock renderer for a dock.68 * Create a new dock renderer for a dock.
@@ -242,6 +243,13 @@
242 */243 */
243 public void draw_dock (Context cr)244 public void draw_dock (Context cr)
244 {245 {
246#if HAVE_GTK_3_10
247#if VALA_0_22
248 window_scale_factor = controller.window.get_window ().get_scale_factor ();
249#else
250 window_scale_factor = gdk_window_get_scale_factor (controller.window.get_window ());
251#endif
252#endif
245 // take the previous frame values into account to decide if we253 // take the previous frame values into account to decide if we
246 // can bail a full draw to not miss a finishing animation-frame254 // can bail a full draw to not miss a finishing animation-frame
247 var no_full_draw_needed = (hide_progress == 1.0 && opacity == 1.0);255 var no_full_draw_needed = (hide_progress == 1.0 && opacity == 1.0);
@@ -380,7 +388,7 @@
380#if BENCHMARK388#if BENCHMARK
381 var start = new DateTime.now_local ();389 var start = new DateTime.now_local ();
382#endif390#endif
383 var icon_surface = item.get_surface_copy (icon_size, icon_size, main_buffer);391 var icon_surface = item.get_surface_copy (icon_size * window_scale_factor, icon_size * window_scale_factor, main_buffer);
384 unowned Context icon_cr = icon_surface.Context;392 unowned Context icon_cr = icon_surface.Context;
385 393
386 DockSurface? icon_shadow_surface = null;394 DockSurface? icon_shadow_surface = null;
@@ -532,14 +540,26 @@
532 540
533 // draw the icon shadow541 // draw the icon shadow
534 if (icon_shadow_surface != null) {542 if (icon_shadow_surface != null) {
543 if (window_scale_factor > 1) {
544 shadow_cr.save ();
545 shadow_cr.scale (1.0 / window_scale_factor, 1.0 / window_scale_factor);
546 }
535 shadow_cr.set_operator (Cairo.Operator.OVER);547 shadow_cr.set_operator (Cairo.Operator.OVER);
536 shadow_cr.set_source_surface (icon_shadow_surface.Internal, draw_value.draw_region.x - shadow_size, draw_value.draw_region.y - shadow_size);548 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);
537 shadow_cr.paint ();549 shadow_cr.paint ();
550 if (window_scale_factor > 1)
551 shadow_cr.restore ();
538 }552 }
539553
540 // draw the icon554 // draw the icon
541 main_cr.set_source_surface (icon_surface.Internal, draw_value.draw_region.x, draw_value.draw_region.y);555 if (window_scale_factor > 1) {
556 main_cr.save ();
557 main_cr.scale (1.0 / window_scale_factor, 1.0 / window_scale_factor);
558 }
559 main_cr.set_source_surface (icon_surface.Internal, draw_value.draw_region.x * window_scale_factor, draw_value.draw_region.y * window_scale_factor);
542 main_cr.paint ();560 main_cr.paint ();
561 if (window_scale_factor > 1)
562 main_cr.restore ();
543 563
544 // draw indicators564 // draw indicators
545 if (item.Indicator != IndicatorState.NONE)565 if (item.Indicator != IndicatorState.NONE)
@@ -559,7 +579,7 @@
559 Logger.verbose ("DockItem.draw_item_overlay (width = %i, height = %i)", width, height);579 Logger.verbose ("DockItem.draw_item_overlay (width = %i, height = %i)", width, height);
560 var surface = new DockSurface.with_dock_surface (width, height, icon_surface);580 var surface = new DockSurface.with_dock_surface (width, height, icon_surface);
561 581
562 var icon_size = position_manager.IconSize;582 var icon_size = position_manager.IconSize * window_scale_factor;
563 var urgent_color = get_styled_color ();583 var urgent_color = get_styled_color ();
564 urgent_color.add_hue (theme.UrgentHueShift);584 urgent_color.add_hue (theme.UrgentHueShift);
565 585
@@ -576,7 +596,7 @@
576 596
577 DockSurface draw_item_shadow (DockItem item, DockSurface icon_surface, DockSurface? current_surface)597 DockSurface draw_item_shadow (DockItem item, DockSurface icon_surface, DockSurface? current_surface)
578 {598 {
579 var shadow_size = controller.position_manager.IconShadowSize;599 var shadow_size = controller.position_manager.IconShadowSize * window_scale_factor;
580 600
581 // Inflate size to fit shadow601 // Inflate size to fit shadow
582 var width = icon_surface.Width + 2 * shadow_size;602 var width = icon_surface.Width + 2 * shadow_size;
583603
=== modified file 'lib/Factories/AbstractMain.vala'
--- lib/Factories/AbstractMain.vala 2013-11-15 15:14:36 +0000
+++ lib/Factories/AbstractMain.vala 2014-03-20 10:19:57 +0000
@@ -175,6 +175,9 @@
175 message ("Kernel version: %s", Posix.utsname ().release);175 message ("Kernel version: %s", Posix.utsname ().release);
176 message ("GLib version: %u.%u.%u", GLib.Version.major, GLib.Version.minor, GLib.Version.micro);176 message ("GLib version: %u.%u.%u", GLib.Version.major, GLib.Version.minor, GLib.Version.micro);
177 message ("GTK+ version: %u.%u.%u", Gtk.get_major_version (), Gtk.get_minor_version () , Gtk.get_micro_version ());177 message ("GTK+ version: %u.%u.%u", Gtk.get_major_version (), Gtk.get_minor_version () , Gtk.get_micro_version ());
178#if HAVE_GTK_3_10
179 message ("+ HiDPI support enabled");
180#endif
178 message ("Wnck version: %d.%d.%d", Wnck.Version.MAJOR_VERSION, Wnck.Version.MINOR_VERSION, Wnck.Version.MICRO_VERSION);181 message ("Wnck version: %d.%d.%d", Wnck.Version.MAJOR_VERSION, Wnck.Version.MINOR_VERSION, Wnck.Version.MICRO_VERSION);
179 message ("Cairo version: %s", Cairo.version_string ());182 message ("Cairo version: %s", Cairo.version_string ());
180 message ("Pango version: %s", Pango.version_string ());183 message ("Pango version: %s", Pango.version_string ());
181184
=== modified file 'lib/HideManager.vala'
--- lib/HideManager.vala 2014-02-18 07:45:27 +0000
+++ lib/HideManager.vala 2014-03-20 10:19:57 +0000
@@ -317,6 +317,19 @@
317 void update_window_intersect ()317 void update_window_intersect ()
318 {318 {
319 var dock_rect = controller.position_manager.get_static_dock_region ();319 var dock_rect = controller.position_manager.get_static_dock_region ();
320#if HAVE_GTK_3_10
321#if VALA_0_22
322 var window_scale_factor = controller.window.get_window ().get_scale_factor ();
323#else
324 var window_scale_factor = gdk_window_get_scale_factor (controller.window.get_window ());
325#endif
326 if (window_scale_factor > 1) {
327 dock_rect.x *= window_scale_factor;
328 dock_rect.y *= window_scale_factor;
329 dock_rect.width *= window_scale_factor;
330 dock_rect.height *= window_scale_factor;
331 }
332#endif
320 333
321 var intersect = false;334 var intersect = false;
322 var dialog_intersect = false;335 var dialog_intersect = false;
323336
=== modified file 'lib/PositionManager.vala'
--- lib/PositionManager.vala 2014-02-13 10:40:46 +0000
+++ lib/PositionManager.vala 2014-03-20 10:19:57 +0000
@@ -106,6 +106,7 @@
106 Gdk.Rectangle monitor_geo;106 Gdk.Rectangle monitor_geo;
107 107
108 bool screen_is_composited;108 bool screen_is_composited;
109 int window_scale_factor = 1;
109 110
110 /**111 /**
111 * Creates a new position manager.112 * Creates a new position manager.
@@ -436,24 +437,31 @@
436 {437 {
437 var cursor_region = static_dock_region;438 var cursor_region = static_dock_region;
438 var progress = 1.0 - controller.renderer.hide_progress;439 var progress = 1.0 - controller.renderer.hide_progress;
440#if HAVE_GTK_3_10
441#if VALA_0_22
442 window_scale_factor = controller.window.get_window ().get_scale_factor ();
443#else
444 window_scale_factor = gdk_window_get_scale_factor (controller.window.get_window ());
445#endif
446#endif
439 447
440 switch (controller.prefs.Position) {448 switch (controller.prefs.Position) {
441 default:449 default:
442 case PositionType.BOTTOM:450 case PositionType.BOTTOM:
443 cursor_region.height = int.max (1, (int) (progress * cursor_region.height));451 cursor_region.height = int.max (1 * window_scale_factor, (int) (progress * cursor_region.height));
444 cursor_region.y = DockHeight - cursor_region.height;452 cursor_region.y = DockHeight - cursor_region.height + (window_scale_factor - 1);
445 break;453 break;
446 case PositionType.TOP:454 case PositionType.TOP:
447 cursor_region.height = int.max (1, (int) (progress * cursor_region.height));455 cursor_region.height = int.max (1 * window_scale_factor, (int) (progress * cursor_region.height));
448 cursor_region.y = 0;456 cursor_region.y = 0;
449 break;457 break;
450 case PositionType.LEFT:458 case PositionType.LEFT:
451 cursor_region.width = int.max (1, (int) (progress * cursor_region.width));459 cursor_region.width = int.max (1 * window_scale_factor, (int) (progress * cursor_region.width));
452 cursor_region.x = 0;460 cursor_region.x = 0;
453 break;461 break;
454 case PositionType.RIGHT:462 case PositionType.RIGHT:
455 cursor_region.width = int.max (1, (int) (progress * cursor_region.width));463 cursor_region.width = int.max (1 * window_scale_factor, (int) (progress * cursor_region.width));
456 cursor_region.x = DockWidth - cursor_region.width;464 cursor_region.x = DockWidth - cursor_region.width + (window_scale_factor - 1);
457 break;465 break;
458 }466 }
459 467
@@ -1065,27 +1073,34 @@
1065 */1073 */
1066 public void get_struts (ref ulong[] struts)1074 public void get_struts (ref ulong[] struts)
1067 {1075 {
1076#if HAVE_GTK_3_10
1077#if VALA_0_22
1078 window_scale_factor = controller.window.get_window ().get_scale_factor ();
1079#else
1080 window_scale_factor = gdk_window_get_scale_factor (controller.window.get_window ());
1081#endif
1082#endif
1068 switch (controller.prefs.Position) {1083 switch (controller.prefs.Position) {
1069 default:1084 default:
1070 case PositionType.BOTTOM:1085 case PositionType.BOTTOM:
1071 struts [Struts.BOTTOM] = VisibleDockHeight + controller.window.get_screen ().get_height () - monitor_geo.y - monitor_geo.height;1086 struts [Struts.BOTTOM] = (VisibleDockHeight + controller.window.get_screen ().get_height () - monitor_geo.y - monitor_geo.height) * window_scale_factor;
1072 struts [Struts.BOTTOM_START] = monitor_geo.x;1087 struts [Struts.BOTTOM_START] = monitor_geo.x * window_scale_factor;
1073 struts [Struts.BOTTOM_END] = monitor_geo.x + monitor_geo.width - 1;1088 struts [Struts.BOTTOM_END] = (monitor_geo.x + monitor_geo.width) * window_scale_factor - 1;
1074 break;1089 break;
1075 case PositionType.TOP:1090 case PositionType.TOP:
1076 struts [Struts.TOP] = monitor_geo.y + VisibleDockHeight;1091 struts [Struts.TOP] = (monitor_geo.y + VisibleDockHeight) * window_scale_factor;
1077 struts [Struts.TOP_START] = monitor_geo.x;1092 struts [Struts.TOP_START] = monitor_geo.x * window_scale_factor;
1078 struts [Struts.TOP_END] = monitor_geo.x + monitor_geo.width - 1;1093 struts [Struts.TOP_END] = (monitor_geo.x + monitor_geo.width) * window_scale_factor - 1;
1079 break;1094 break;
1080 case PositionType.LEFT:1095 case PositionType.LEFT:
1081 struts [Struts.LEFT] = monitor_geo.x + VisibleDockWidth;1096 struts [Struts.LEFT] = (monitor_geo.x + VisibleDockWidth) * window_scale_factor;
1082 struts [Struts.LEFT_START] = monitor_geo.y;1097 struts [Struts.LEFT_START] = monitor_geo.y * window_scale_factor;
1083 struts [Struts.LEFT_END] = monitor_geo.y + monitor_geo.height - 1;1098 struts [Struts.LEFT_END] = (monitor_geo.y + monitor_geo.height) * window_scale_factor - 1;
1084 break;1099 break;
1085 case PositionType.RIGHT:1100 case PositionType.RIGHT:
1086 struts [Struts.RIGHT] = VisibleDockWidth + controller.window.get_screen ().get_width () - monitor_geo.x - monitor_geo.width;1101 struts [Struts.RIGHT] = (VisibleDockWidth + controller.window.get_screen ().get_width () - monitor_geo.x - monitor_geo.width) * window_scale_factor;
1087 struts [Struts.RIGHT_START] = monitor_geo.y;1102 struts [Struts.RIGHT_START] = monitor_geo.y * window_scale_factor;
1088 struts [Struts.RIGHT_END] = monitor_geo.y + monitor_geo.height - 1;1103 struts [Struts.RIGHT_END] = (monitor_geo.y + monitor_geo.height) * window_scale_factor - 1;
1089 break;1104 break;
1090 }1105 }
1091 }1106 }
10921107
=== modified file 'vapi/compat.vapi'
--- vapi/compat.vapi 2014-02-14 07:00:32 +0000
+++ vapi/compat.vapi 2014-03-20 10:19:57 +0000
@@ -21,6 +21,10 @@
21 [CCode (cheader_filename = "gdk-pixbuf/gdk-pixbuf.h", cname = "gdk_pixbuf_new_from_resource")]21 [CCode (cheader_filename = "gdk-pixbuf/gdk-pixbuf.h", cname = "gdk_pixbuf_new_from_resource")]
22 public Gdk.Pixbuf gdk_pixbuf_new_from_resource (string resource_path) throws GLib.Error;22 public Gdk.Pixbuf gdk_pixbuf_new_from_resource (string resource_path) throws GLib.Error;
23#endif23#endif
24#if !VALA_0_22 && HAVE_GTK_3_10
25 [CCode (cheader_filename = "gdk/gdk.h", cname = "gdk_window_get_scale_factor")]
26 public int gdk_window_get_scale_factor (Gdk.Window window);
27#endif
24#if !VALA_0_2428#if !VALA_0_24
25 [CCode (cheader_filename = "gtk/gtk.h", cname = "gtk_widget_shape_combine_region")]29 [CCode (cheader_filename = "gtk/gtk.h", cname = "gtk_widget_shape_combine_region")]
26 public void gtk_widget_shape_combine_region (Gtk.Widget widget, Cairo.Region? region);30 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: