[Xfce4-commits] [apps/xfce4-screenshooter] 01/01: Fix crash and properly handle cursors on HiDPI

noreply at xfce.org noreply at xfce.org
Wed Dec 26 12:18:40 CET 2018


This is an automated email from the git hooks/post-receive script.

a   n   d   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-screenshooter.

commit 7dc181eda81cbb3e3b5731f73e44030fefdba2ff
Author: Viktor Odintsev <ninetls at xfce.org>
Date:   Wed Dec 26 04:33:15 2018 +0300

    Fix crash and properly handle cursors on HiDPI
---
 lib/screenshooter-capture.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/lib/screenshooter-capture.c b/lib/screenshooter-capture.c
index 1c4a628..a8fcf23 100644
--- a/lib/screenshooter-capture.c
+++ b/lib/screenshooter-capture.c
@@ -265,6 +265,10 @@ fallback:
 #endif
   TRACE ("Get the mouse cursor and its image through fallback mode");
 
+  /* cursors are not scaled */
+  if (gdk_window_get_scale_factor (root) != 1)
+    return NULL;
+
   cursor = gdk_cursor_new_for_display (display, GDK_LEFT_PTR);
   cursor_pixbuf = gdk_cursor_get_image (cursor);
 
@@ -298,6 +302,7 @@ static GdkPixbuf
   GdkPixbuf *screenshot;
   GdkWindow *root;
 
+  gint scale;
   GdkRectangle rectangle;
 
   /* Get the root window */
@@ -312,6 +317,8 @@ static GdkPixbuf
     		                                           find_wm_window (xwindow));
     }
 
+  scale = gdk_window_get_scale_factor (window);
+
   rectangle.width = gdk_window_get_width (window);
   rectangle.height = gdk_window_get_height (window);
   gdk_window_get_origin (window, &rectangle.x, &rectangle.y);
@@ -372,7 +379,7 @@ static GdkPixbuf
           gboolean has_alpha = gdk_pixbuf_get_has_alpha (screenshot);
 
           tmp =
-            gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+            gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width * scale, height * scale);
           gdk_pixbuf_fill (tmp, 0);
 
           for (i = 0; i < rectangle_count; i++)
@@ -412,11 +419,11 @@ static GdkPixbuf
                   rec_y = 0;
                 }
 
-              if (x_orig + rec_x + rec_width > gdk_screen_width ())
-                rec_width = gdk_screen_width () - x_orig - rec_x;
+              if (x_orig + rec_x + rec_width > gdk_screen_width () * scale)
+                rec_width = gdk_screen_width () * scale - x_orig - rec_x;
 
-              if (y_orig + rec_y + rec_height > gdk_screen_height ())
-                rec_height = gdk_screen_height () - y_orig - rec_y;
+              if (y_orig + rec_y + rec_height > gdk_screen_height () * scale)
+                rec_height = gdk_screen_height () * scale - y_orig - rec_y;
 
               for (y = rec_y; y < rec_y + rec_height; y++)
                 {
@@ -463,10 +470,10 @@ static GdkPixbuf
             GdkRectangle rectangle_window, rectangle_cursor;
 
             /* rectangle_window stores the window coordinates */
-            rectangle_window.x = x_orig;
-            rectangle_window.y = y_orig;
-            rectangle_window.width = width;
-            rectangle_window.height = height;
+            rectangle_window.x = x_orig * scale;
+            rectangle_window.y = y_orig * scale;
+            rectangle_window.width = width * scale;
+            rectangle_window.height = height * scale;
 
             /* rectangle_cursor stores the cursor coordinates */
             rectangle_cursor.x = cursorx;
@@ -484,12 +491,12 @@ static GdkPixbuf
                 TRACE ("Compose the two pixbufs");
 
                 gdk_pixbuf_composite (cursor_pixbuf, screenshot,
-                                      cursorx - x_orig -xhot,
-                                      cursory - y_orig -yhot,
+                                      cursorx - rectangle_window.x - xhot,
+                                      cursory - rectangle_window.y - yhot,
                                       rectangle_cursor.width,
                                       rectangle_cursor.height,
-                                      cursorx - x_orig - xhot,
-                                      cursory - y_orig -yhot,
+                                      cursorx - rectangle_window.x - xhot,
+                                      cursory - rectangle_window.y - yhot,
                                       1.0, 1.0,
                                       GDK_INTERP_BILINEAR,
                                       255);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list