[Xfce4-commits] [apps/xfdashboard] 01/01: Implement actions to move focus to any registered focusable actor (focus-move-to).
noreply at xfce.org
noreply at xfce.org
Thu Apr 27 09:42:02 CEST 2017
This is an automated email from the git hooks/post-receive script.
nomad pushed a commit to branch master
in repository apps/xfdashboard.
commit 1787f82e77d3ce853a419a979c3e09a7d306fca1
Author: Stephan Haller <nomad at froevel.de>
Date: Thu Apr 27 09:39:52 2017 +0200
Implement actions to move focus to any registered focusable actor (focus-move-to).
This is useful at key bindings file to create a keyboard shortcut to focus a specific actor like the quicklaunch: <key code="<Ctrl>-q" source="XfdashboardFocusable" target="XfdashboardQuicklaunch" when="released">focus-move-to</key>
This commit fixes issue GH #145
---
libxfdashboard/focusable.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
libxfdashboard/focusable.h | 7 ++++++
2 files changed, 68 insertions(+)
diff --git a/libxfdashboard/focusable.c b/libxfdashboard/focusable.c
index bb05059..1cf72e1 100644
--- a/libxfdashboard/focusable.c
+++ b/libxfdashboard/focusable.c
@@ -70,6 +70,8 @@ enum
ACTION_SELECTION_MOVE_PREVIOUS,
ACTION_SELECTION_ACTIVATE,
+ ACTION_FOCUS_MOVE_TO,
+
SIGNAL_LAST
};
@@ -430,6 +432,23 @@ static gboolean _xfdashboard_focusable_selection_activate(XfdashboardFocusable *
return(CLUTTER_EVENT_STOP);
}
+/* Action signal to move focus to this focusable actor was emitted */
+static gboolean _xfdashboard_focusable_focus_move_to(XfdashboardFocusable *self,
+ XfdashboardFocusable *inSource,
+ const gchar *inAction,
+ ClutterEvent *inEvent)
+{
+ g_return_val_if_fail(XFDASHBOARD_IS_FOCUSABLE(self), CLUTTER_EVENT_PROPAGATE);
+ g_return_val_if_fail(inEvent, CLUTTER_EVENT_PROPAGATE);
+
+ /* Move focus to this focuables actor */
+ xfdashboard_focusable_move_focus_to(self);
+
+ /* All done so return and stop further processing of this event */
+ return(CLUTTER_EVENT_STOP);
+}
+
+
/* IMPLEMENTATION: GObject */
/* Interface initialization
@@ -460,6 +479,7 @@ void xfdashboard_focusable_default_init(XfdashboardFocusableInterface *iface)
iface->selection_move_page_up=_xfdashboard_focusable_selection_move_page_up;
iface->selection_move_page_down=_xfdashboard_focusable_selection_move_page_down;
iface->selection_activate=_xfdashboard_focusable_selection_activate;
+ iface->focus_move_to=_xfdashboard_focusable_focus_move_to;
/* Define signals and actions */
if(!initialized)
@@ -685,6 +705,20 @@ void xfdashboard_focusable_default_init(XfdashboardFocusableInterface *iface)
G_TYPE_STRING,
CLUTTER_TYPE_EVENT);
+ XfdashboardFocusableSignals[ACTION_FOCUS_MOVE_TO]=
+ g_signal_new("focus-move-to",
+ XFDASHBOARD_TYPE_FOCUSABLE,
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET(XfdashboardFocusableInterface, focus_move_to),
+ g_signal_accumulator_true_handled,
+ NULL,
+ _xfdashboard_marshal_BOOLEAN__OBJECT_STRING_BOXED,
+ G_TYPE_BOOLEAN,
+ 3,
+ XFDASHBOARD_TYPE_FOCUSABLE,
+ G_TYPE_STRING,
+ CLUTTER_TYPE_EVENT);
+
/* Set flag that base initialization was done for this interface */
initialized=TRUE;
}
@@ -995,3 +1029,30 @@ gboolean xfdashboard_focusable_activate_selection(XfdashboardFocusable *self, Cl
XFDASHBOARD_FOCUSABLE_WARN_NOT_IMPLEMENTED(self, "activate_selection");
return(FALSE);
}
+
+/* Move focus to this focusable actor */
+gboolean xfdashboard_focusable_move_focus_to(XfdashboardFocusable *self)
+{
+ XfdashboardFocusManager *focusManager;
+ gboolean success;
+
+ g_return_val_if_fail(XFDASHBOARD_IS_FOCUSABLE(self), FALSE);
+
+ success=FALSE;
+
+ /* Check if this focusable actor can get focus */
+ if(!xfdashboard_focusable_can_focus(self)) return(FALSE);
+
+ /* Get focus manager to change focus */
+ focusManager=xfdashboard_focus_manager_get_default();
+
+ /* Try to move focus to this focusable actor and check success */
+ xfdashboard_focus_manager_set_focus(focusManager, self);
+ if(xfdashboard_focus_manager_get_focus(focusManager)==self) success=TRUE;
+
+ /* Release allocated resources */
+ g_object_unref(focusManager);
+
+ /* Return success result to move focus */
+ return(success);
+}
diff --git a/libxfdashboard/focusable.h b/libxfdashboard/focusable.h
index 23ebe42..3291cf1 100644
--- a/libxfdashboard/focusable.h
+++ b/libxfdashboard/focusable.h
@@ -115,6 +115,11 @@ struct _XfdashboardFocusableInterface
XfdashboardFocusable *inSource,
const gchar *inAction,
ClutterEvent *inEvent);
+
+ gboolean (*focus_move_to)(XfdashboardFocusable *self,
+ XfdashboardFocusable *inSource,
+ const gchar *inAction,
+ ClutterEvent *inEvent);
};
/* Public API */
@@ -130,6 +135,8 @@ gboolean xfdashboard_focusable_set_selection(XfdashboardFocusable *self, Clutter
ClutterActor* xfdashboard_focusable_find_selection(XfdashboardFocusable *self, ClutterActor *inSelection, XfdashboardSelectionTarget inDirection);
gboolean xfdashboard_focusable_activate_selection(XfdashboardFocusable *self, ClutterActor *inSelection);
+gboolean xfdashboard_focusable_move_focus_to(XfdashboardFocusable *self);
+
G_END_DECLS
#endif /* __LIBXFDASHBOARD_FOCUSABLE__ */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list