[gnome-screenshot/wip/exalm/x11] Make X11 dependency optional



commit 7981a6a942e12df62c590df085d3d6a10336af4f
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Mar 30 23:01:00 2020 +0500

    Make X11 dependency optional
    
    Introduce an 'x11' feature build option, and disable the fallback backend
    if it's used.
    
    Remove an unnecessary include in ScreenshotApplication.

 meson.build                  | 13 +++++++++----
 meson_options.txt            |  6 ++++++
 src/screenshot-application.c |  1 -
 src/screenshot-utils.c       | 22 ++++++++++++++++++++--
 src/screenshot-utils.h       |  1 -
 5 files changed, 35 insertions(+), 8 deletions(-)
---
diff --git a/meson.build b/meson.build
index 016f8dd..30bab93 100644
--- a/meson.build
+++ b/meson.build
@@ -33,8 +33,8 @@ glib_req_version = '>= 2.35.1'
 gtk_req_version = '>= 3.12.0'
 
 mathlib_dep = cc.find_library('m', required: false)
-x11_dep = dependency('x11')
-xext_dep = dependency('xext')
+x11_dep = dependency('x11', required: get_option ('x11'))
+xext_dep = dependency('xext', required: get_option ('x11'))
 glib_dep = dependency('glib-2.0', version: glib_req_version)
 gtk_dep = dependency('gtk+-3.0', version: gtk_req_version)
 canberra_dep = dependency('libcanberra-gtk3')
@@ -43,8 +43,13 @@ config_h = configuration_data()
 config_h.set_quoted('VERSION', meson.project_version())
 config_h.set_quoted('GETTEXT_PACKAGE', meson.project_name())
 
-if cc.has_header('X11/extensions/shape.h')
-  config_h.set('HAVE_X11_EXTENSIONS_SHAPE_H', 1)
+has_x11 = x11_dep.found() and xext_dep.found()
+if has_x11
+  config_h.set('HAVE_X11', 1)
+
+  if cc.has_header('X11/extensions/shape.h')
+    config_h.set('HAVE_X11_EXTENSIONS_SHAPE_H', 1)
+  endif
 endif
 
 configure_file(output: 'config.h', configuration: config_h)
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..7228d35
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,6 @@
+option (
+  'x11',
+  type: 'feature',
+  description: 'Enable fallback X11 backend',
+  value: 'auto'
+)
diff --git a/src/screenshot-application.c b/src/screenshot-application.c
index 1c6fe18..9836492 100644
--- a/src/screenshot-application.c
+++ b/src/screenshot-application.c
@@ -23,7 +23,6 @@
 
 #include "config.h"
 
-#include <gdk/gdkx.h>
 #include <gdk/gdkkeysyms.h>
 #include <fcntl.h>
 #include <unistd.h>
diff --git a/src/screenshot-utils.c b/src/screenshot-utils.c
index 04c0c8e..9ad46c5 100644
--- a/src/screenshot-utils.c
+++ b/src/screenshot-utils.c
@@ -21,6 +21,11 @@
 #include "config.h"
 
 #include <gdk/gdkkeysyms.h>
+
+#if HAVE_X11
+#include <gdk/gdkx.h>
+#endif
+
 #include <gtk/gtk.h>
 #include <glib.h>
 #include <glib/gi18n.h>
@@ -33,10 +38,12 @@
 #endif
 
 #include "cheese-flash.h"
+
 #include "screenshot-application.h"
 #include "screenshot-config.h"
 #include "screenshot-utils.h"
 
+#ifdef HAVE_X11
 static GdkWindow *
 screenshot_find_active_window (void)
 {
@@ -271,6 +278,7 @@ screenshot_fallback_get_window_rect_coords (GdkWindow *window,
       screenshot_coordinates_out->height = height;
     }
 }
+#endif /* HAVE_X11 */
 
 void
 screenshot_play_sound_effect (const gchar *event_id,
@@ -305,6 +313,7 @@ screenshot_play_sound_effect (const gchar *event_id,
     ca_proplist_destroy (p);
 }
 
+#ifdef HAVE_X11
 static void
 screenshot_fallback_fire_flash (GdkWindow *window,
                                 GdkRectangle *rectangle)
@@ -584,6 +593,7 @@ screenshot_fallback_get_pixbuf (GdkRectangle *rectangle)
 
   return screenshot;
 }
+#endif /* HAVE_X11 */
 
 static GdkPixbuf *
 screenshot_shell_get_pixbuf (GdkRectangle *rectangle)
@@ -656,21 +666,29 @@ GdkPixbuf *
 screenshot_get_pixbuf (GdkRectangle *rectangle)
 {
   GdkPixbuf *screenshot = NULL;
-  gboolean force_fallback;
+  gboolean force_fallback = FALSE;
 
+#ifdef HAVE_X11
   force_fallback = g_getenv ("GNOME_SCREENSHOT_FORCE_FALLBACK") != NULL;
+#endif
   if (!force_fallback)
     {
       screenshot = screenshot_shell_get_pixbuf (rectangle);
       if (!screenshot)
+#ifdef HAVE_X11
         g_message ("Unable to use GNOME Shell's builtin screenshot interface, "
                    "resorting to fallback X11.");
-    }
+#else
+        g_message ("Unable to use GNOME Shell's builtin screenshot interface.");
+#endif
+  }
   else
     g_message ("Using fallback X11 as requested");
 
+#ifdef HAVE_X11
   if (!screenshot)
     screenshot = screenshot_fallback_get_pixbuf (rectangle);
+#endif /* HAVE_X11 */
 
   return screenshot;
 }
diff --git a/src/screenshot-utils.h b/src/screenshot-utils.h
index 0d83665..77e6b8c 100644
--- a/src/screenshot-utils.h
+++ b/src/screenshot-utils.h
@@ -20,7 +20,6 @@
 #pragma once
 
 #include <gtk/gtk.h>
-#include <gdk/gdkx.h>
 
 G_BEGIN_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]