[Xfce4-commits] [apps/xfce4-screenshooter] 03/04: Move get_active_window functions to utils

noreply at xfce.org noreply at xfce.org
Sun Mar 17 18:08:35 CET 2019


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 2dccba6808abb015bbe3709bdc40178f44c25445
Author: Andre Miranda <andreldm at xfce.org>
Date:   Sun Mar 17 14:01:57 2019 -0300

    Move get_active_window functions to utils
---
 lib/screenshooter-capture.c | 123 +------------------------------------------
 lib/screenshooter-utils.c   | 125 ++++++++++++++++++++++++++++++++++++++++++++
 lib/screenshooter-utils.h   |  41 ++++++++-------
 3 files changed, 148 insertions(+), 141 deletions(-)

diff --git a/lib/screenshooter-capture.c b/lib/screenshooter-capture.c
index 7035e87..c747770 100644
--- a/lib/screenshooter-capture.c
+++ b/lib/screenshooter-capture.c
@@ -20,11 +20,6 @@
 #include "screenshooter-capture.h"
 #include "screenshooter-utils.h"
 
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#include <gdk/gdk.h>
-#include <gdk/gdkx.h>
-
 #define BACKGROUND_TRANSPARENCY 0.4
 
 enum {
@@ -67,11 +62,6 @@ typedef struct
 
 /* Prototypes */
 
-
-static Window           get_active_window_from_xlib         (void);
-static GdkWindow       *get_active_window                   (GdkScreen      *screen,
-                                                             gboolean       *needs_unref,
-                                                             gboolean       *border);
 static void             free_pixmap_data                    (guchar *pixels,
                                                              gpointer data);
 static GdkPixbuf       *get_cursor_pixbuf                   (GdkDisplay *display,
@@ -111,117 +101,6 @@ static GdkPixbuf       *get_rectangle_screenshot_composited (gint delay);
 
 /* Internals */
 
-static Window
-get_active_window_from_xlib (void)
-{
-  GdkDisplay *display;
-  Display *dsp;
-  Atom active_win, type;
-  int status, format;
-  unsigned long n_items, bytes_after;
-  unsigned char *prop;
-  Window window;
-
-  display = gdk_display_get_default ();
-  dsp = gdk_x11_display_get_xdisplay (display);
-
-  active_win = XInternAtom (dsp, "_NET_ACTIVE_WINDOW", True);
-  if (active_win == None)
-    return None;
-
-  gdk_x11_display_error_trap_push (display);
-
-  status = XGetWindowProperty (dsp, DefaultRootWindow (dsp),
-                               active_win, 0, G_MAXLONG, False,
-                               XA_WINDOW, &type, &format, &n_items,
-                               &bytes_after, &prop);
-  if (status != Success || type != XA_WINDOW)
-    {
-      if (prop)
-        XFree (prop);
-
-      gdk_x11_display_error_trap_pop_ignored (display);
-      return None;
-    }
-
-  if (gdk_x11_display_error_trap_pop (display) != Success)
-    {
-      if (prop)
-        XFree (prop);
-
-      return None;
-    }
-
-  window = *(Window *) prop;
-  XFree (prop);
-  return window;
-}
-
-
-
-static GdkWindow
-*get_active_window (GdkScreen *screen,
-                    gboolean  *needs_unref,
-                    gboolean  *border)
-{
-  GdkWindow *window, *window2;
-  Window xwindow;
-  GdkDisplay *display;
-
-  TRACE ("Get the active window");
-
-  display = gdk_display_get_default ();
-  xwindow = get_active_window_from_xlib ();
-  if (xwindow != None)
-    window = gdk_x11_window_foreign_new_for_display (display, xwindow);
-  else
-    window = NULL;
-
-  /* If there is no active window, we fallback to the whole screen. */
-  if (G_UNLIKELY (window == NULL))
-    {
-      TRACE ("No active window, fallback to the root window");
-
-      window = gdk_get_default_root_window ();
-      *needs_unref = FALSE;
-      *border = FALSE;
-    }
-  else if (G_UNLIKELY (gdk_window_is_destroyed (window)))
-    {
-      TRACE ("The active window is destroyed, fallback to the root window.");
-
-      g_object_unref (window);
-      window = gdk_get_default_root_window ();
-      *needs_unref = FALSE;
-      *border = FALSE;
-    }
-  else if (gdk_window_get_type_hint (window) == GDK_WINDOW_TYPE_HINT_DESKTOP)
-    {
-      /* If the active window is the desktop, grab the whole screen */
-      TRACE ("The active window is the desktop, fallback to the root window");
-
-      g_object_unref (window);
-
-      window = gdk_get_default_root_window ();
-      *needs_unref = FALSE;
-      *border = FALSE;
-    }
-  else
-    {
-      /* Else we find the toplevel window to grab the decorations. */
-      TRACE ("Active window is a normal window, grab the toplevel window");
-
-      window2 = gdk_window_get_toplevel (window);
-
-      g_object_unref (window);
-
-      window = window2;
-      *border = TRUE;
-    }
-
-  return window;
-}
-
 
 
 static Window
@@ -1505,7 +1384,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
     {
       TRACE ("We grab the active window");
 
-      window = get_active_window (screen, &needs_unref, &border);
+      window = screenshooter_get_active_window (screen, &needs_unref, &border);
     }
 
   if (region == FULLSCREEN || region == ACTIVE_WINDOW)
diff --git a/lib/screenshooter-utils.c b/lib/screenshooter-utils.c
index 3708641..0790342 100644
--- a/lib/screenshooter-utils.c
+++ b/lib/screenshooter-utils.c
@@ -17,10 +17,70 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+
 #include "screenshooter-utils.h"
 #include <libxfce4ui/libxfce4ui.h>
 
 
+
+/* Internals */
+
+
+
+/* Replacement for gdk_screen_get_active_window */
+static Window
+get_active_window_from_xlib (void)
+{
+  GdkDisplay *display;
+  Display *dsp;
+  Atom active_win, type;
+  int status, format;
+  unsigned long n_items, bytes_after;
+  unsigned char *prop;
+  Window window;
+
+  display = gdk_display_get_default ();
+  dsp = gdk_x11_display_get_xdisplay (display);
+
+  active_win = XInternAtom (dsp, "_NET_ACTIVE_WINDOW", True);
+  if (active_win == None)
+    return None;
+
+  gdk_x11_display_error_trap_push (display);
+
+  status = XGetWindowProperty (dsp, DefaultRootWindow (dsp),
+                               active_win, 0, G_MAXLONG, False,
+                               XA_WINDOW, &type, &format, &n_items,
+                               &bytes_after, &prop);
+
+  if (status != Success || type != XA_WINDOW)
+    {
+      if (prop)
+        XFree (prop);
+
+      gdk_x11_display_error_trap_pop_ignored (display);
+      return None;
+    }
+
+  if (gdk_x11_display_error_trap_pop (display) != Success)
+    {
+      if (prop)
+        XFree (prop);
+
+      return None;
+    }
+
+  window = *(Window *) prop;
+  XFree (prop);
+  return window;
+}
+
+
+
 /* Public */
 
 
@@ -361,3 +421,68 @@ screenshooter_get_screen_geometry (GdkRectangle *geometry)
   geometry->width = w - x;
   geometry->height = h - y;
 }
+
+
+
+GdkWindow*
+screenshooter_get_active_window (GdkScreen *screen,
+                                 gboolean  *needs_unref,
+                                 gboolean  *border)
+{
+  GdkWindow *window, *window2;
+  Window xwindow;
+  GdkDisplay *display;
+
+  TRACE ("Get the active window");
+
+  display = gdk_display_get_default ();
+  xwindow = get_active_window_from_xlib ();
+  if (xwindow != None)
+    window = gdk_x11_window_foreign_new_for_display (display, xwindow);
+  else
+    window = NULL;
+
+  /* If there is no active window, we fallback to the whole screen. */
+  if (G_UNLIKELY (window == NULL))
+    {
+      TRACE ("No active window, fallback to the root window");
+
+      window = gdk_get_default_root_window ();
+      *needs_unref = FALSE;
+      *border = FALSE;
+    }
+  else if (G_UNLIKELY (gdk_window_is_destroyed (window)))
+    {
+      TRACE ("The active window is destroyed, fallback to the root window.");
+
+      g_object_unref (window);
+      window = gdk_get_default_root_window ();
+      *needs_unref = FALSE;
+      *border = FALSE;
+    }
+  else if (gdk_window_get_type_hint (window) == GDK_WINDOW_TYPE_HINT_DESKTOP)
+    {
+      /* If the active window is the desktop, grab the whole screen */
+      TRACE ("The active window is the desktop, fallback to the root window");
+
+      g_object_unref (window);
+
+      window = gdk_get_default_root_window ();
+      *needs_unref = FALSE;
+      *border = FALSE;
+    }
+  else
+    {
+      /* Else we find the toplevel window to grab the decorations. */
+      TRACE ("Active window is a normal window, grab the toplevel window");
+
+      window2 = gdk_window_get_toplevel (window);
+
+      g_object_unref (window);
+
+      window = window2;
+      *border = TRUE;
+    }
+
+  return window;
+}
diff --git a/lib/screenshooter-utils.h b/lib/screenshooter-utils.h
index 85205c3..451ea78 100644
--- a/lib/screenshooter-utils.h
+++ b/lib/screenshooter-utils.h
@@ -36,24 +36,27 @@
 
 
 
-void      screenshooter_copy_to_clipboard     (GdkPixbuf      *screenshot);
-void      screenshooter_read_rc_file          (const gchar    *file,
-                                               ScreenshotData *sd);
-void      screenshooter_write_rc_file         (const gchar    *file,
-                                               ScreenshotData *sd);
-void      screenshooter_open_screenshot       (const gchar    *screenshot_path,
-                                               const gchar    *application,
-                                                     GAppInfo *app_info);
-gchar    *screenshooter_get_home_uri          (void);
-gchar    *screenshooter_get_xdg_image_dir_uri (void);
-gboolean  screenshooter_is_remote_uri         (const gchar    *uri);
-void      screenshooter_error                 (const gchar    *format,
-                                               ...);
-gchar    *screenshooter_get_datetime          (const gchar    *format);
-void      screenshooter_open_help             (GtkWindow      *parent);
-gboolean  screenshooter_f1_key                (GtkWidget      *widget,
-                                               GdkEventKey    *event,
-                                               gpointer        user_data);
-void      screenshooter_get_screen_geometry   (GdkRectangle   *geometry);
+void       screenshooter_copy_to_clipboard     (GdkPixbuf      *screenshot);
+void       screenshooter_read_rc_file          (const gchar    *file,
+                                                ScreenshotData *sd);
+void       screenshooter_write_rc_file         (const gchar    *file,
+                                                ScreenshotData *sd);
+void       screenshooter_open_screenshot       (const gchar    *screenshot_path,
+                                                const gchar    *application,
+                                                      GAppInfo *app_info);
+gchar     *screenshooter_get_home_uri          (void);
+gchar     *screenshooter_get_xdg_image_dir_uri (void);
+gboolean   screenshooter_is_remote_uri         (const gchar    *uri);
+void       screenshooter_error                 (const gchar    *format,
+                                                ...);
+gchar     *screenshooter_get_datetime          (const gchar    *format);
+void       screenshooter_open_help             (GtkWindow      *parent);
+gboolean   screenshooter_f1_key                (GtkWidget      *widget,
+                                                GdkEventKey    *event,
+                                                gpointer        user_data);
+void       screenshooter_get_screen_geometry   (GdkRectangle   *geometry);
+GdkWindow *screenshooter_get_active_window     (GdkScreen      *screen,
+                                                gboolean       *needs_unref,
+                                                gboolean       *border);
 
 #endif

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


More information about the Xfce4-commits mailing list