[Xfce4-commits] [apps/xfdashboard] 04/04: Make hot-corner plugin configurable

noreply at xfce.org noreply at xfce.org
Sun Feb 14 16:13:29 CET 2016


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

nomad pushed a commit to branch master
in repository apps/xfdashboard.

commit 5d23581562685a14538c7d40339161090ecdbe6a
Author: Stephan Haller <nomad at froevel.de>
Date:   Sun Feb 14 16:13:08 2016 +0100

    Make hot-corner plugin configurable
---
 plugins/hot-corner/hot-corner.c | 324 ++++++++++++++++++++++++++++++++++++----
 plugins/hot-corner/hot-corner.h |  24 ++-
 2 files changed, 316 insertions(+), 32 deletions(-)

diff --git a/plugins/hot-corner/hot-corner.c b/plugins/hot-corner/hot-corner.c
index 9f95944..f5c43f3 100644
--- a/plugins/hot-corner/hot-corner.c
+++ b/plugins/hot-corner/hot-corner.c
@@ -34,15 +34,6 @@
 #include <window-tracker.h>
 #include <application.h>
 
-/* Definitions */
-typedef enum
-{
-	XFDASHBOARD_HOT_CORNER_AREA_TOP_LEFT=0,
-	XFDASHBOARD_HOT_CORNER_AREA_TOP_RIGHT,
-	XFDASHBOARD_HOT_CORNER_AREA_BOTTOM_LEFT,
-	XFDASHBOARD_HOT_CORNER_AREA_BOTTOM_RIGHT,
-} XfdashboardHotCornerArea;
-
 
 /* Define this class in GObject system */
 G_DEFINE_DYNAMIC_TYPE(XfdashboardHotCorner,
@@ -59,26 +50,78 @@ XFDASHBOARD_DEFINE_PLUGIN_TYPE(xfdashboard_hot_corner);
 struct _XfdashboardHotCornerPrivate
 {
 	/* Properties related */
-	XfdashboardHotCornerArea	hotCornerArea;
-	gint						activationRadius;
-	GTimeSpan					activationMicroseconds;
+	XfdashboardHotCornerActivationCorner	activationCorner;
+	gint									activationRadius;
+	gint64									activationDuration;
 
 	/* Instance related */
-	XfdashboardApplication		*application;
-	XfdashboardWindowTracker	*windowTracker;
-	GdkWindow					*rootWindow;
-	GdkDeviceManager			*deviceManager;
-
-	guint						timeoutID;
-	GDateTime					*enteredTime;
-	gboolean					wasHandledRecently;
+	XfdashboardApplication					*application;
+	XfdashboardWindowTracker				*windowTracker;
+	GdkWindow								*rootWindow;
+	GdkDeviceManager						*deviceManager;
+
+	guint									timeoutID;
+	GDateTime								*enteredTime;
+	gboolean								wasHandledRecently;
+
+	XfconfChannel							*xfconfChannel;
+	guint									xfconfActivationCornerBindingID;
+	guint									xfconfActivationRadiusBindingID;
+	guint									xfconfActivationDurationBindingID;
+};
+
+/* Properties */
+enum
+{
+	PROP_0,
+
+	PROP_ACTIVATION_CORNER,
+	PROP_ACTIVATION_RADIUS,
+	PROP_ACTIVATION_DURATION,
+
+	PROP_LAST
 };
 
+static GParamSpec* XfdashboardHotCornerProperties[PROP_LAST]={ 0, };
+
+
+/* IMPLEMENTATION: Enum XFDASHBOARD_TYPE_HOT_CORNER_ACTIVATION_CORNER */
+
+GType xfdashboard_hot_corner_activation_corner_get_type(void)
+{
+	static volatile gsize	g_define_type_id__volatile=0;
+
+	if(g_once_init_enter(&g_define_type_id__volatile))
+	{
+		static const GEnumValue values[]=
+		{
+			{ XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_TOP_LEFT, "XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_TOP_LEFT", "top-left" },
+			{ XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_TOP_RIGHT, "XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_TOP_RIGHT", "top-right" },
+			{ XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_BOTTOM_LEFT, "XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_BOTTOM_LEFT", "bottom-left" },
+			{ XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_BOTTOM_RIGHT, "XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_BOTTOM_RIGHT", "bottom-right" },
+			{ 0, NULL, NULL }
+		};
+
+		GType	g_define_type_id=g_enum_register_static(g_intern_static_string("XfdashboardHotCornerActivationCorner"), values);
+		g_once_init_leave(&g_define_type_id__volatile, g_define_type_id);
+	}
+
+	return(g_define_type_id__volatile);
+}
+
 
 /* IMPLEMENTATION: Private variables and methods */
 #define POLL_POINTER_POSITION_INTERVAL			100
-#define POLL_POINTER_ACTIVATION_RADIUS			4
-#define POLL_POINTER_ACTIVATION_MILLISECONDS	300
+
+#define ACTIVATION_CORNER_XFCONF_PROP			"/plugins/"PLUGIN_ID"/activation-corner"
+#define DEFAULT_ACTIVATION_CORNER				XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_TOP_LEFT
+
+#define ACTIVATION_RADIUS_XFCONF_PROP			"/plugins/"PLUGIN_ID"/activation-radius"
+#define DEFAULT_ACTIVATION_RADIUS				4
+
+#define ACTIVATION_DURATION_XFCONF_PROP			"/plugins/"PLUGIN_ID"/activation-duration"
+#define DEFAULT_ACTIVATION_DURATION				300
+
 
 typedef struct _XfdashboardHotCornerBox		XfdashboardHotCornerBox;
 struct _XfdashboardHotCornerBox
@@ -148,30 +191,30 @@ static gboolean _xfdashboard_hot_corner_check_hot_corner(gpointer inUserData)
 		}
 
 	/* Get rectangle where pointer must be inside to activate hot corner */
-	switch(priv->hotCornerArea)
+	switch(priv->activationCorner)
 	{
-		case XFDASHBOARD_HOT_CORNER_AREA_TOP_RIGHT:
+		case XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_TOP_RIGHT:
 			hotCornerRect.x2=monitorRect.x2;
 			hotCornerRect.x1=MAX(monitorRect.x2-priv->activationRadius, monitorRect.x1);
 			hotCornerRect.y1=monitorRect.y1;
 			hotCornerRect.y2=MIN(monitorRect.y1+priv->activationRadius, monitorRect.y2);
 			break;
 
-		case XFDASHBOARD_HOT_CORNER_AREA_BOTTOM_LEFT:
+		case XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_BOTTOM_LEFT:
 			hotCornerRect.x1=monitorRect.x1;
 			hotCornerRect.x2=MIN(monitorRect.x1+priv->activationRadius, monitorRect.x2);
 			hotCornerRect.y2=monitorRect.y2;
 			hotCornerRect.y1=MAX(monitorRect.y2-priv->activationRadius, monitorRect.y1);
 			break;
 
-		case XFDASHBOARD_HOT_CORNER_AREA_BOTTOM_RIGHT:
+		case XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_BOTTOM_RIGHT:
 			hotCornerRect.x2=monitorRect.x2;
 			hotCornerRect.x1=MAX(monitorRect.x2-priv->activationRadius, monitorRect.x1);
 			hotCornerRect.y2=monitorRect.y2;
 			hotCornerRect.y1=MAX(monitorRect.y2-priv->activationRadius, monitorRect.y1);
 			break;
 
-		case XFDASHBOARD_HOT_CORNER_AREA_TOP_LEFT:
+		case XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_TOP_LEFT:
 		default:
 			hotCornerRect.x1=monitorRect.x1;
 			hotCornerRect.x2=MIN(monitorRect.x1+priv->activationRadius, monitorRect.x2);
@@ -225,7 +268,7 @@ static gboolean _xfdashboard_hot_corner_check_hot_corner(gpointer inUserData)
 	timeDiff=g_date_time_difference(currentTime, priv->enteredTime);
 	g_date_time_unref(currentTime);
 
-	if(timeDiff<priv->activationMicroseconds) return(G_SOURCE_CONTINUE);
+	if(timeDiff<(priv->activationDuration*G_TIME_SPAN_MILLISECOND)) return(G_SOURCE_CONTINUE);
 
 	/* Activation duration reached so activate application if suspended or suspend it
 	 * if active currently.
@@ -254,6 +297,29 @@ static void _xfdashboard_hot_corner_dispose(GObject *inObject)
 	XfdashboardHotCornerPrivate		*priv=self->priv;
 
 	/* Release allocated resources */
+	if(priv->xfconfActivationCornerBindingID)
+	{
+		xfconf_g_property_unbind(priv->xfconfActivationCornerBindingID);
+		priv->xfconfActivationCornerBindingID=0;
+	}
+
+	if(priv->xfconfActivationRadiusBindingID)
+	{
+		xfconf_g_property_unbind(priv->xfconfActivationRadiusBindingID);
+		priv->xfconfActivationRadiusBindingID=0;
+	}
+
+	if(priv->xfconfActivationDurationBindingID)
+	{
+		xfconf_g_property_unbind(priv->xfconfActivationDurationBindingID);
+		priv->xfconfActivationDurationBindingID=0;
+	}
+
+	if(priv->xfconfChannel)
+	{
+		priv->xfconfChannel=NULL;
+	}
+
 	if(priv->enteredTime)
 	{
 		g_date_time_unref(priv->enteredTime);
@@ -276,6 +342,62 @@ static void _xfdashboard_hot_corner_dispose(GObject *inObject)
 	G_OBJECT_CLASS(xfdashboard_hot_corner_parent_class)->dispose(inObject);
 }
 
+/* Set/get properties */
+static void _xfdashboard_hot_corner_set_property(GObject *inObject,
+													guint inPropID,
+													const GValue *inValue,
+													GParamSpec *inSpec)
+{
+	XfdashboardHotCorner			*self=XFDASHBOARD_HOT_CORNER(inObject);
+
+	switch(inPropID)
+	{
+		case PROP_ACTIVATION_CORNER:
+			xfdashboard_hot_corner_set_activation_corner(self, g_value_get_enum(inValue));
+			break;
+
+		case PROP_ACTIVATION_RADIUS:
+			xfdashboard_hot_corner_set_activation_radius(self, g_value_get_int(inValue));
+			break;
+
+		case PROP_ACTIVATION_DURATION:
+			xfdashboard_hot_corner_set_activation_duration(self, g_value_get_uint64(inValue));
+			break;
+
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(inObject, inPropID, inSpec);
+			break;
+	}
+}
+
+static void _xfdashboard_hot_corner_get_property(GObject *inObject,
+													guint inPropID,
+													GValue *outValue,
+													GParamSpec *inSpec)
+{
+	XfdashboardHotCorner			*self=XFDASHBOARD_HOT_CORNER(inObject);
+	XfdashboardHotCornerPrivate		*priv=self->priv;
+
+	switch(inPropID)
+	{
+		case PROP_ACTIVATION_CORNER:
+			g_value_set_enum(outValue, priv->activationCorner);
+			break;
+
+		case PROP_ACTIVATION_RADIUS:
+			g_value_set_int(outValue, priv->activationRadius);
+			break;
+
+		case PROP_ACTIVATION_DURATION:
+			g_value_set_uint64(outValue, priv->activationDuration);
+			break;
+
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(inObject, inPropID, inSpec);
+			break;
+	}
+}
+
 /* Class initialization
  * Override functions in parent classes and define properties
  * and signals
@@ -286,9 +408,38 @@ void xfdashboard_hot_corner_class_init(XfdashboardHotCornerClass *klass)
 
 	/* Override functions */
 	gobjectClass->dispose=_xfdashboard_hot_corner_dispose;
+	gobjectClass->set_property=_xfdashboard_hot_corner_set_property;
+	gobjectClass->get_property=_xfdashboard_hot_corner_get_property;
 
 	/* Set up private structure */
 	g_type_class_add_private(klass, sizeof(XfdashboardHotCornerPrivate));
+
+	/* Define properties */
+	XfdashboardHotCornerProperties[PROP_ACTIVATION_CORNER]=
+		g_param_spec_enum("activation-corner",
+							_("Activation corner"),
+							_("The hot corner where to trigger the application to suspend or to resume"),
+							XFDASHBOARD_TYPE_HOT_CORNER_ACTIVATION_CORNER,
+							DEFAULT_ACTIVATION_CORNER,
+							G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+	XfdashboardHotCornerProperties[PROP_ACTIVATION_RADIUS]=
+		g_param_spec_int("activation-radius",
+							_("Activation radius"),
+							_("The radius around hot corner where the pointer must be inside"),
+							0, G_MAXINT,
+							DEFAULT_ACTIVATION_RADIUS,
+							G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+	XfdashboardHotCornerProperties[PROP_ACTIVATION_DURATION]=
+		g_param_spec_uint64("activation-duration",
+							_("Activation duration"),
+							_("The time in milliseconds the pointer must stay inside the radius at hot corner to trigger"),
+							0, G_MAXUINT64,
+							DEFAULT_ACTIVATION_DURATION,
+							G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+	g_object_class_install_properties(gobjectClass, PROP_LAST, XfdashboardHotCornerProperties);
 }
 
 /* Class finalization */
@@ -308,8 +459,9 @@ void xfdashboard_hot_corner_init(XfdashboardHotCorner *self)
 	self->priv=priv=XFDASHBOARD_HOT_CORNER_GET_PRIVATE(self);
 
 	/* Set up default values */
-	priv->hotCornerArea=XFDASHBOARD_HOT_CORNER_AREA_TOP_LEFT;
-	priv->activationRadius=POLL_POINTER_ACTIVATION_RADIUS;
+	priv->activationCorner=DEFAULT_ACTIVATION_CORNER;
+	priv->activationRadius=DEFAULT_ACTIVATION_RADIUS;
+	priv->activationDuration=DEFAULT_ACTIVATION_DURATION;
 
 	priv->windowTracker=xfdashboard_window_tracker_get_default();
 	priv->rootWindow=NULL;
@@ -317,9 +469,9 @@ void xfdashboard_hot_corner_init(XfdashboardHotCorner *self)
 
 	priv->timeoutID=0;
 	priv->enteredTime=NULL;
-	priv->activationMicroseconds=POLL_POINTER_ACTIVATION_MILLISECONDS*G_TIME_SPAN_MILLISECOND;
 	priv->wasHandledRecently=FALSE;
 	priv->application=xfdashboard_application_get_default();
+	priv->xfconfChannel=xfdashboard_application_get_xfconf_channel(priv->application);
 
 	/* Get device manager for polling pointer position */
 	if(xfdashboard_application_is_daemonized(priv->application))
@@ -352,8 +504,34 @@ void xfdashboard_hot_corner_init(XfdashboardHotCorner *self)
 		{
 			g_warning(_("Disabling hot-corner plugin because application is not running as daemon."));
 		}
+
+	/* Bind to xfconf to react on changes */
+	priv->xfconfActivationCornerBindingID=
+		xfconf_g_property_bind(priv->xfconfChannel,
+								ACTIVATION_CORNER_XFCONF_PROP,
+								G_TYPE_STRING,
+								self,
+								"activation-corner");
+
+	priv->xfconfActivationRadiusBindingID=
+		xfconf_g_property_bind(priv->xfconfChannel,
+								ACTIVATION_RADIUS_XFCONF_PROP,
+								G_TYPE_INT,
+								self,
+								"activation-radius");
+
+	priv->xfconfActivationDurationBindingID=
+		xfconf_g_property_bind(priv->xfconfChannel,
+								ACTIVATION_DURATION_XFCONF_PROP,
+								G_TYPE_INT64,
+								self,
+								"activation-duration");
 }
 
+
+/* IMPLEMENTATION: Public API */
+
+/* Create new instance */
 XfdashboardHotCorner* xfdashboard_hot_corner_new(void)
 {
 	GObject		*hotCorner;
@@ -363,3 +541,87 @@ XfdashboardHotCorner* xfdashboard_hot_corner_new(void)
 
 	return(XFDASHBOARD_HOT_CORNER(hotCorner));
 }
+
+/* Get/set hot corner */
+XfdashboardHotCornerActivationCorner xfdashboard_hot_corner_get_activation_corner(XfdashboardHotCorner *self)
+{
+	g_return_val_if_fail(XFDASHBOARD_IS_HOT_CORNER(self), XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_TOP_LEFT);
+
+	return(self->priv->activationCorner);
+}
+
+void xfdashboard_hot_corner_set_activation_corner(XfdashboardHotCorner *self, XfdashboardHotCornerActivationCorner inCorner)
+{
+	XfdashboardHotCornerPrivate		*priv;
+
+	g_return_if_fail(XFDASHBOARD_IS_HOT_CORNER(self));
+	g_return_if_fail(inCorner<=XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_BOTTOM_RIGHT);
+
+	priv=self->priv;
+
+	/* Set value if changed */
+	if(priv->activationCorner!=inCorner)
+	{
+		/* Set value */
+		priv->activationCorner=inCorner;
+
+		/* Notify about property change */
+		g_object_notify_by_pspec(G_OBJECT(self), XfdashboardHotCornerProperties[PROP_ACTIVATION_CORNER]);
+	}
+}
+
+/* Get/set radius around hot corner */
+gint xfdashboard_hot_corner_get_activation_radius(XfdashboardHotCorner *self)
+{
+	g_return_val_if_fail(XFDASHBOARD_IS_HOT_CORNER(self), 0);
+
+	return(self->priv->activationRadius);
+}
+
+void xfdashboard_hot_corner_set_activation_radius(XfdashboardHotCorner *self, gint inRadius)
+{
+	XfdashboardHotCornerPrivate		*priv;
+
+	g_return_if_fail(XFDASHBOARD_IS_HOT_CORNER(self));
+	g_return_if_fail(inRadius>0);
+
+	priv=self->priv;
+
+	/* Set value if changed */
+	if(priv->activationRadius!=inRadius)
+	{
+		/* Set value */
+		priv->activationRadius=inRadius;
+
+		/* Notify about property change */
+		g_object_notify_by_pspec(G_OBJECT(self), XfdashboardHotCornerProperties[PROP_ACTIVATION_RADIUS]);
+	}
+}
+
+/* Get/set duration when to trigger hot corner */
+gint64 xfdashboard_hot_corner_get_activation_duration(XfdashboardHotCorner *self)
+{
+	g_return_val_if_fail(XFDASHBOARD_IS_HOT_CORNER(self), 0);
+
+	return(self->priv->activationDuration);
+}
+
+void xfdashboard_hot_corner_set_activation_duration(XfdashboardHotCorner *self, gint64 inDuration)
+{
+	XfdashboardHotCornerPrivate		*priv;
+
+	g_return_if_fail(XFDASHBOARD_IS_HOT_CORNER(self));
+	g_return_if_fail(inDuration>0);
+
+	priv=self->priv;
+
+	/* Set value if changed */
+	if(priv->activationDuration!=inDuration)
+	{
+		/* Set value */
+		priv->activationDuration=inDuration;
+
+		/* Notify about property change */
+		g_object_notify_by_pspec(G_OBJECT(self), XfdashboardHotCornerProperties[PROP_ACTIVATION_DURATION]);
+	}
+}
diff --git a/plugins/hot-corner/hot-corner.h b/plugins/hot-corner/hot-corner.h
index 7b894f8..8428b2b 100644
--- a/plugins/hot-corner/hot-corner.h
+++ b/plugins/hot-corner/hot-corner.h
@@ -28,6 +28,20 @@
 
 G_BEGIN_DECLS
 
+/* Public definitions */
+typedef enum /*< prefix=XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER >*/
+{
+	XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_TOP_LEFT=0,
+	XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_TOP_RIGHT,
+	XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_BOTTOM_LEFT,
+	XFDASHBOARD_HOT_CORNER_ACTIVATION_CORNER_BOTTOM_RIGHT,
+} XfdashboardHotCornerActivationCorner;
+
+GType xfdashboard_hot_corner_activation_corner_get_type(void) G_GNUC_CONST;
+#define XFDASHBOARD_TYPE_HOT_CORNER_ACTIVATION_CORNER	(xfdashboard_hot_corner_activation_corner_get_type())
+
+
+/* Object declaration */
 #define XFDASHBOARD_TYPE_HOT_CORNER				(xfdashboard_hot_corner_get_type())
 #define XFDASHBOARD_HOT_CORNER(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), XFDASHBOARD_TYPE_HOT_CORNER, XfdashboardHotCorner))
 #define XFDASHBOARD_IS_HOT_CORNER(obj)			(G_TYPE_CHECK_INSTANCE_TYPE((obj), XFDASHBOARD_TYPE_HOT_CORNER))
@@ -57,12 +71,20 @@ struct _XfdashboardHotCornerClass
 
 /* Public API */
 GType xfdashboard_hot_corner_get_type(void) G_GNUC_CONST;
-void xfdashboard_hot_corner_type_register(GTypeModule *inModule);
 
 XFDASHBOARD_DECLARE_PLUGIN_TYPE(xfdashboard_hot_corner);
 
 XfdashboardHotCorner* xfdashboard_hot_corner_new(void);
 
+XfdashboardHotCornerActivationCorner xfdashboard_hot_corner_get_activation_corner(XfdashboardHotCorner *self);
+void xfdashboard_hot_corner_set_activation_corner(XfdashboardHotCorner *self, const XfdashboardHotCornerActivationCorner inCorner);
+
+gint xfdashboard_hot_corner_get_activation_radius(XfdashboardHotCorner *self);
+void xfdashboard_hot_corner_set_activation_radius(XfdashboardHotCorner *self, gint inRadius);
+
+gint64 xfdashboard_hot_corner_get_activation_duration(XfdashboardHotCorner *self);
+void xfdashboard_hot_corner_set_activation_duration(XfdashboardHotCorner *self, gint64 inDuration);
+
 G_END_DECLS
 
 #endif

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


More information about the Xfce4-commits mailing list