[Xfce4-commits] [apps/xfdashboard] 16/19: Select window tracker backend based on Clutter backend in use.

noreply at xfce.org noreply at xfce.org
Fri Jun 16 10:56:47 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 c88b5ffb5d72fc454b96027b8c30e723ab65b679
Author: Stephan Haller <nomad at froevel.de>
Date:   Fri Jun 16 09:18:16 2017 +0200

    Select window tracker backend based on Clutter backend in use.
    
    Enhancement for issue GH #129
---
 libxfdashboard/gdk/window-tracker-backend-gdk.c | 42 ++++++++++++++
 libxfdashboard/gdk/window-tracker-backend-gdk.h |  2 +
 libxfdashboard/window-tracker-backend.c         | 73 ++++++++++++++++++-------
 libxfdashboard/x11/window-tracker-backend-x11.c | 16 ++++++
 libxfdashboard/x11/window-tracker-backend-x11.h |  2 +
 5 files changed, 115 insertions(+), 20 deletions(-)

diff --git a/libxfdashboard/gdk/window-tracker-backend-gdk.c b/libxfdashboard/gdk/window-tracker-backend-gdk.c
index 212e3fb..ee67224 100644
--- a/libxfdashboard/gdk/window-tracker-backend-gdk.c
+++ b/libxfdashboard/gdk/window-tracker-backend-gdk.c
@@ -759,3 +759,45 @@ void xfdashboard_window_tracker_backend_gdk_init(XfdashboardWindowTrackerBackend
 	/* Create window tracker instance */
 	priv->windowTracker=g_object_new(XFDASHBOARD_TYPE_WINDOW_TRACKER_X11, NULL);
 }
+
+/* IMPLEMENTATION: Public API */
+
+/**
+ * xfdashboard_window_tracker_backend_gdk_new:
+ *
+ * Creates a new #XfdashboardWindowTrackerBackendGDK backend for use with
+ * Clutter's GDK backend.
+ *
+ * Currently only the X11 backend of GDK is supported.
+ *
+ * Return value: The newly created #XfdashboardWindowTrackerBackend
+ */
+XfdashboardWindowTrackerBackend* xfdashboard_window_tracker_backend_gdk_new(void)
+{
+	GdkDisplay						*display;
+	gboolean						supported;
+
+	/* Check for supported windowing system */
+	supported=FALSE;
+
+	display=gdk_display_manager_get_default_display(gdk_display_manager_get());
+#ifdef GDK_WINDOWING_X11
+	if(!supported && GDK_IS_X11_DISPLAY(display))
+	{
+		XFDASHBOARD_DEBUG(NULL, WINDOWS, "GDK windowing system is X11");
+		supported=TRUE;
+	}
+#endif
+
+	/* If no supported windowing system was found, print a message and return
+	 * NULL to indicate an error.
+	 */
+	if(!supported)
+	{
+		XFDASHBOARD_DEBUG(NULL, WINDOWS, "Cannot create GDK window tracker backend as no supported backend found");
+		return(NULL);
+	}
+
+	/* Create window tracker backend and return it */
+	return(g_object_new(XFDASHBOARD_TYPE_WINDOW_TRACKER_BACKEND_GDK, NULL));
+}
diff --git a/libxfdashboard/gdk/window-tracker-backend-gdk.h b/libxfdashboard/gdk/window-tracker-backend-gdk.h
index 77b81f1..32b0f3c 100644
--- a/libxfdashboard/gdk/window-tracker-backend-gdk.h
+++ b/libxfdashboard/gdk/window-tracker-backend-gdk.h
@@ -69,6 +69,8 @@ struct _XfdashboardWindowTrackerBackendGDKClass
 /* Public API */
 GType xfdashboard_window_tracker_backend_gdk_get_type(void) G_GNUC_CONST;
 
+XfdashboardWindowTrackerBackend* xfdashboard_window_tracker_backend_gdk_new(void);
+
 G_END_DECLS
 
 #endif	/* __LIBXFDASHBOARD_WINDOW_TRACKER_BACKEND_GDK__ */
diff --git a/libxfdashboard/window-tracker-backend.c b/libxfdashboard/window-tracker-backend.c
index 8b7bcae..8bcbd03 100644
--- a/libxfdashboard/window-tracker-backend.c
+++ b/libxfdashboard/window-tracker-backend.c
@@ -72,6 +72,25 @@ void xfdashboard_window_tracker_backend_default_init(XfdashboardWindowTrackerBac
 
 /* IMPLEMENTATION: Public API */
 
+struct _XfdashboardWindowTrackerBackendMap
+{
+	const gchar							*backendID;
+	const gchar							*clutterBackendID;
+	XfdashboardWindowTrackerBackend*	(*createBackend)(void);
+};
+typedef struct _XfdashboardWindowTrackerBackendMap	XfdashboardWindowTrackerBackendMap;
+
+XfdashboardWindowTrackerBackendMap	_xfdashboard_window_tracker_backend_map[]=
+									{
+#ifdef CLUTTER_WINDOWING_X11
+										{ "x11", CLUTTER_WINDOWING_X11, xfdashboard_window_tracker_backend_x11_new },
+#endif
+#ifdef CLUTTER_WINDOWING_GDK
+										{ "gdk", CLUTTER_WINDOWING_GDK, xfdashboard_window_tracker_backend_gdk_new },
+#endif
+										{ NULL, NULL, NULL }
+									};
+
 /**
  * xfdashboard_window_tracker_backend_get_default:
  *
@@ -84,32 +103,46 @@ XfdashboardWindowTrackerBackend* xfdashboard_window_tracker_backend_get_default(
 {
 	if(G_UNLIKELY(_xfdashboard_window_tracker_backend_singleton==NULL))
 	{
-		GType			windowTrackerBackendType=G_TYPE_INVALID;
-		const gchar		*windowTrackerBackend;
-
-		/* Check if a specific backend was requested */
-		windowTrackerBackend=g_getenv("XFDASHBOARD_BACKEND");
+		XfdashboardWindowTrackerBackendMap	*iter;
 
-		if(g_strcmp0(windowTrackerBackend, "gdk")==0)
+		/* Iterate through list of available backends and check if any entry
+		 * matches the backend Clutter is using. If we can find a matching entry
+		 * then create our backend which interacts with Clutter's backend.
+		 */
+		for(iter=_xfdashboard_window_tracker_backend_map; !_xfdashboard_window_tracker_backend_singleton && iter->backendID; iter++)
 		{
-			windowTrackerBackendType=XFDASHBOARD_TYPE_WINDOW_TRACKER_BACKEND_GDK;
-		}
+			/* If this entry does not match backend Clutter, try next one */
+			if(!clutter_check_windowing_backend(iter->clutterBackendID)) continue;
 
-		/* If no specific backend was requested use default one */
-		if(windowTrackerBackendType==G_TYPE_INVALID)
-		{
-			windowTrackerBackendType=XFDASHBOARD_TYPE_WINDOW_TRACKER_BACKEND_X11;
+			/* The entry matches so try to create our backend */
 			XFDASHBOARD_DEBUG(NULL, WINDOWS,
-								"Using default backend %s",
-								g_type_name(windowTrackerBackendType));
+								"Found window tracker backend ID '%s' for clutter backend '%s'",
+								iter->backendID,
+								iter->clutterBackendID);
+
+			_xfdashboard_window_tracker_backend_singleton=(iter->createBackend)();
+			if(!_xfdashboard_window_tracker_backend_singleton)
+			{
+				XFDASHBOARD_DEBUG(NULL, WINDOWS,
+									"Could not create window tracker backend of ID '%s' for clutter backend '%s'",
+									iter->backendID,
+									iter->clutterBackendID);
+			}
+				else
+				{
+					XFDASHBOARD_DEBUG(_xfdashboard_window_tracker_backend_singleton, WINDOWS,
+										"Create window tracker backend of type %s with ID '%s' for clutter backend '%s'",
+										G_OBJECT_TYPE_NAME(_xfdashboard_window_tracker_backend_singleton),
+										iter->backendID,
+										iter->clutterBackendID);
+				}
 		}
 
-		/* Create singleton */
-		_xfdashboard_window_tracker_backend_singleton=XFDASHBOARD_WINDOW_TRACKER_BACKEND(g_object_new(windowTrackerBackendType, NULL));
-		XFDASHBOARD_DEBUG(_xfdashboard_window_tracker_backend_singleton, WINDOWS,
-							"Created window tracker of type %s for %s backend",
-							_xfdashboard_window_tracker_backend_singleton ? G_OBJECT_TYPE_NAME(_xfdashboard_window_tracker_backend_singleton) : "<<unknown>>",
-							windowTrackerBackend ? windowTrackerBackend : "default");
+		if(!_xfdashboard_window_tracker_backend_singleton)
+		{
+			g_critical(_("Cannot find any usable window tracker backend"));
+			return(NULL);
+		}
 	}
 		else g_object_ref(_xfdashboard_window_tracker_backend_singleton);
 
diff --git a/libxfdashboard/x11/window-tracker-backend-x11.c b/libxfdashboard/x11/window-tracker-backend-x11.c
index 6843c88..973d060 100644
--- a/libxfdashboard/x11/window-tracker-backend-x11.c
+++ b/libxfdashboard/x11/window-tracker-backend-x11.c
@@ -747,3 +747,19 @@ void xfdashboard_window_tracker_backend_x11_init(XfdashboardWindowTrackerBackend
 	/* Create window tracker instance */
 	priv->windowTracker=g_object_new(XFDASHBOARD_TYPE_WINDOW_TRACKER_X11, NULL);
 }
+
+
+/* IMPLEMENTATION: Public API */
+
+/**
+ * xfdashboard_window_tracker_backend_x11_new:
+ *
+ * Creates a new #XfdashboardWindowTrackerBackendX11 backend for use with
+ * Clutter's X11 backend.
+ *
+ * Return value: The newly created #XfdashboardWindowTrackerBackend
+ */
+XfdashboardWindowTrackerBackend* xfdashboard_window_tracker_backend_x11_new(void)
+{
+	return(g_object_new(XFDASHBOARD_TYPE_WINDOW_TRACKER_BACKEND_X11, NULL));
+}
diff --git a/libxfdashboard/x11/window-tracker-backend-x11.h b/libxfdashboard/x11/window-tracker-backend-x11.h
index b96a49b..5ec754a 100644
--- a/libxfdashboard/x11/window-tracker-backend-x11.h
+++ b/libxfdashboard/x11/window-tracker-backend-x11.h
@@ -69,6 +69,8 @@ struct _XfdashboardWindowTrackerBackendX11Class
 /* Public API */
 GType xfdashboard_window_tracker_backend_x11_get_type(void) G_GNUC_CONST;
 
+XfdashboardWindowTrackerBackend* xfdashboard_window_tracker_backend_x11_new(void);
+
 G_END_DECLS
 
 #endif	/* __LIBXFDASHBOARD_WINDOW_TRACKER_BACKEND_X11__ */

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


More information about the Xfce4-commits mailing list