[Xfce4-commits] [apps/xfdashboard] 19/19: Improve handling of requesting a specific backend

noreply at xfce.org noreply at xfce.org
Fri Jun 16 10:56:50 CEST 2017


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

n   o   m   a   d       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/xfdashboard.

commit 3c0d4c2702994ee879753b57674ec6cdf6fd207b
Author: Stephan Haller <nomad at froevel.de>
Date:   Fri Jun 16 10:48:17 2017 +0200

    Improve handling of requesting a specific backend
    
    Enhancement for issue GH #129
---
 libxfdashboard/application.c            | 21 ++++++++++
 libxfdashboard/application.h            |  1 +
 libxfdashboard/window-tracker-backend.c | 74 +++++++++++++++++++++++++++++++++
 libxfdashboard/window-tracker-backend.h |  2 +
 xfdashboard/main.c                      | 34 ++++++++++-----
 5 files changed, 122 insertions(+), 10 deletions(-)

diff --git a/libxfdashboard/application.c b/libxfdashboard/application.c
index fff97f1..6f6b997 100644
--- a/libxfdashboard/application.c
+++ b/libxfdashboard/application.c
@@ -1484,6 +1484,27 @@ static void xfdashboard_application_init(XfdashboardApplication *self)
 /* IMPLEMENTATION: Public API */
 
 /**
+ * xfdashboard_application_has_default:
+ *
+ * Determine if the singleton instance of #XfdashboardApplication was created.
+ * If the singleton instance of #XfdashboardApplication was created, it can be
+ * retrieved with xfdashboard_application_get_default().
+ *
+ * This function is useful if only the availability of the singleton instance
+ * wants to be checked as xfdashboard_application_get_default() will create this
+ * singleton instance if not available.
+ *
+ * Return value: %TRUE if singleton instance of #XfdashboardApplication was
+ *   created or %FALSE if not.
+ */
+gboolean xfdashboard_application_has_default(void)
+{
+	if(G_LIKELY(_xfdashboard_application)) return(TRUE);
+
+	return(FALSE);
+}
+
+/**
  * xfdashboard_application_get_default:
  *
  * Retrieves the singleton instance of #XfdashboardApplication.
diff --git a/libxfdashboard/application.h b/libxfdashboard/application.h
index 1081607..7dd6cb7 100644
--- a/libxfdashboard/application.h
+++ b/libxfdashboard/application.h
@@ -131,6 +131,7 @@ struct _XfdashboardApplicationClass
 /* Public API */
 GType xfdashboard_application_get_type(void) G_GNUC_CONST;
 
+gboolean xfdashboard_application_has_default(void);
 XfdashboardApplication* xfdashboard_application_get_default(void);
 
 gboolean xfdashboard_application_is_daemonized(XfdashboardApplication *self);
diff --git a/libxfdashboard/window-tracker-backend.c b/libxfdashboard/window-tracker-backend.c
index b858c6d..824b15e 100644
--- a/libxfdashboard/window-tracker-backend.c
+++ b/libxfdashboard/window-tracker-backend.c
@@ -32,6 +32,7 @@
 
 #include <libxfdashboard/x11/window-tracker-backend-x11.h>
 #include <libxfdashboard/gdk/window-tracker-backend-gdk.h>
+#include <libxfdashboard/application.h>
 #include <libxfdashboard/marshal.h>
 #include <libxfdashboard/compat.h>
 #include <libxfdashboard/debug.h>
@@ -150,6 +151,79 @@ XfdashboardWindowTrackerBackend* xfdashboard_window_tracker_backend_get_default(
 }
 
 /**
+ * xfdashboard_window_tracker_backend_set_backend:
+ * @inBackend: the backend to use
+ *
+ * Sets the backend that xfdashboard should try to use. It will also restrict
+ * the backend Clutter should try to use. By default xfdashboard will select
+ * the backend automatically based on the backend Clutter uses.
+ *
+ * For example:
+ *
+ * |[<!-- language="C" -->
+ *   xfdashboard_window_tracker_backend_set_allowed_backends("x11");
+ * ]|
+ *
+ * Will make xfdashboard and Clutter use the X11 backend.
+ *
+ * Possible backends are: x11 and gdk.
+ *
+ * This function must be called before the first API call to xfdashboard or any
+ * library xfdashboard depends on like Clutter, GTK+ etc. This function can also
+ * be called only once.
+ */
+void xfdashboard_window_tracker_backend_set_backend(const gchar *inBackend)
+{
+#if CLUTTER_CHECK_VERSION(1, 16, 0)
+	XfdashboardWindowTrackerBackendMap	*iter;
+	static gboolean						wasSet=FALSE;
+
+	g_return_if_fail(inBackend && *inBackend);
+
+	/* Warn if this function was called more than once */
+	if(wasSet)
+	{
+		g_critical(_("Cannot set backend to '%s' because it the backend was already set"),
+					inBackend);
+		return;
+	}
+
+	/* Set flag that this function was called regardless of the result of this
+	 * function call.
+	 */
+	wasSet=TRUE;
+
+	/* Backend can only be set if application was not already created */
+	if(xfdashboard_application_has_default())
+	{
+		g_critical(_("Cannot set backend to '%s' because application is already initialized"),
+					inBackend);
+		return;
+	}
+
+	/* Iterate through list of available backends and lookup the requested
+	 * backend. If this entry is found, restrict Clutter backend as listed in
+	 * found entry and return.
+	 */
+	for(iter=_xfdashboard_window_tracker_backend_map; iter->backendID; iter++)
+	{
+		/* If this entry does not match requested backend, try next one */
+		if(g_strcmp0(iter->backendID, inBackend)!=0) continue;
+
+		/* The entry matches so restrict allowed backends in Clutter to the one
+		 * listed at this entry.
+		 */
+		clutter_set_windowing_backend(iter->clutterBackendID);
+
+		return;
+	}
+
+	/* If we get here the requested backend is unknown */
+	g_warning(_("Unknown backend '%s' - using default backend"), inBackend);
+#endif
+}
+
+/**
  * xfdashboard_window_tracker_backend_get_name:
  * @self: A #XfdashboardWindowTrackerBackend
  *
diff --git a/libxfdashboard/window-tracker-backend.h b/libxfdashboard/window-tracker-backend.h
index e583bb6..793527a 100644
--- a/libxfdashboard/window-tracker-backend.h
+++ b/libxfdashboard/window-tracker-backend.h
@@ -80,6 +80,8 @@ GType xfdashboard_window_tracker_backend_get_type(void) G_GNUC_CONST;
 
 XfdashboardWindowTrackerBackend* xfdashboard_window_tracker_backend_get_default(void);
 
+void xfdashboard_window_tracker_backend_set_backend(const gchar *inBackend);
+
 const gchar* xfdashboard_window_tracker_backend_get_name(XfdashboardWindowTrackerBackend *self);
 
 XfdashboardWindowTracker* xfdashboard_window_tracker_backend_get_window_tracker(XfdashboardWindowTrackerBackend *self);
diff --git a/xfdashboard/main.c b/xfdashboard/main.c
index 1f7f347..e22b840 100644
--- a/xfdashboard/main.c
+++ b/xfdashboard/main.c
@@ -26,13 +26,15 @@
 #endif
 
 #include <glib/gi18n-lib.h>
+#include <gtk/gtk.h>
 #include <clutter/clutter.h>
+#ifdef CLUTTER_WINDOWING_X11
 #include <clutter/x11/clutter-x11.h>
-#include <gtk/gtk.h>
+#endif
 #include <libxfce4util/libxfce4util.h>
-
 #include <libxfdashboard/application.h>
-#include <libxfdashboard/types.h>
+#include <libxfdashboard/window-tracker-backend.h>
+
 
 typedef struct _RestartData		RestartData;
 struct _RestartData
@@ -201,20 +203,32 @@ int main(int argc, char **argv)
 #endif
 
 #if CLUTTER_CHECK_VERSION(1, 16, 0)
-	/* Enforce X11 backend in Clutter if no specific backend was requesetd.
-	 * This function must be called before any other Clutter API function.
+	/* Enforce X11 backend in Clutter if no specific backend was requested via
+	 * the XFDASHBOARD_BACKEND environment variable. If this environment variable
+	 * is set, enforce this backend.
+	 *
+	 * This function must be called before any API function call at libxfdashboard
+	 * or other library API function like the one of Clutter, GTK+ etc.
 	 */
 	backend=g_getenv("XFDASHBOARD_BACKEND");
-	if(!backend ||
-		g_strcmp0(backend, "x11")==0)
+	if(backend)
 	{
-		clutter_set_windowing_backend("x11");
-		g_debug("Enforcing X11 backend");
+		xfdashboard_window_tracker_backend_set_backend(backend);
+		g_debug("Setting backend to '%s'", backend);
 	}
+		else
+		{
+			clutter_set_windowing_backend("x11");
+			g_debug("Enforcing X11 backend");
+		}
 #endif
 
-	/* Tell clutter to try to initialize an RGBA visual */
+#ifdef CLUTTER_WINDOWING_X11
+	/* Tell clutter to try to initialize an RGBA visual if the X11 backend is
+	 * used before fallback to default and use RGB visual without alpha channel.
+	 */
 	clutter_x11_set_use_argb_visual(TRUE);
+#endif
 
 	/* Initialize GTK+ and Clutter */
 	gtk_init(&argc, &argv);

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


More information about the Xfce4-commits mailing list