summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Glidic <sardemff7+git@sardemff7.net>2021-10-28 06:33:12 +0000
committerQuentin Glidic <sardemff7+git@sardemff7.net>2021-10-28 06:33:12 +0000
commitbde8175d393d8dbd8998268480a370e6daf9370e (patch)
treef29d8fd9503f45c8e568511dca5e4db662841c03
parentf24cbe270e62bb9454d663fd50e012777b3d92d5 (diff)
gitmodules: Update libnkutils
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
-rw-r--r--include/view.h12
-rw-r--r--include/widgets/widget.h14
-rw-r--r--source/keyb.c13
-rw-r--r--source/view.c44
-rw-r--r--source/widgets/widget.c15
m---------subprojects/libnkutils0
-rw-r--r--test/mode-test.c5
7 files changed, 89 insertions, 14 deletions
diff --git a/include/view.h b/include/view.h
index 01cfa04b..1971ad7e 100644
--- a/include/view.h
+++ b/include/view.h
@@ -170,8 +170,16 @@ void rofi_view_restart(RofiViewState *state);
*
* @returns TRUE if action was handled.
*/
-gboolean rofi_view_trigger_action(RofiViewState *state, BindingsScope scope,
- guint action);
+gboolean rofi_view_check_action(RofiViewState *state, BindingsScope scope,
+ guint action);
+
+/**
+ * @param state The handle to the view
+ * @param scope The scope of the action
+ * @param action The action
+ */
+void rofi_view_trigger_action(RofiViewState *state, BindingsScope scope,
+ guint action);
/**
* @param state The handle to the view
diff --git a/include/widgets/widget.h b/include/widgets/widget.h
index e4139d02..aa64b84f 100644
--- a/include/widgets/widget.h
+++ b/include/widgets/widget.h
@@ -290,6 +290,20 @@ widget *widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y);
* Trigger an action on widget.
* param x and param y are relative to param wid .
*
+ * @returns Whether the action would be handled or not
+ */
+WidgetTriggerActionResult widget_check_action(widget *wid, guint action,
+ gint x, gint y);
+
+/**
+ * @param wid The widget handle
+ * @param action The action to trigger
+ * @param x A pointer to the x coordinate of the click
+ * @param y A pointer to the y coordinate of the click
+ *
+ * Trigger an action on widget.
+ * param x and param y are relative to param wid .
+ *
* @returns Whether the action was handled or not
*/
WidgetTriggerActionResult widget_trigger_action(widget *wid, guint action,
diff --git a/source/keyb.c b/source/keyb.c
index 6b32af02..d2bab474 100644
--- a/source/keyb.c
+++ b/source/keyb.c
@@ -142,9 +142,14 @@ void setup_abe ( void )
}
}
-static gboolean binding_trigger_action ( guint64 scope, G_GNUC_UNUSED gpointer target, gpointer user_data )
+static gboolean binding_check_action ( guint64 scope, G_GNUC_UNUSED gpointer target, gpointer user_data )
{
- return rofi_view_trigger_action ( rofi_view_get_active (), scope, GPOINTER_TO_UINT ( user_data ) );
+ return rofi_view_check_action ( rofi_view_get_active (), scope, GPOINTER_TO_UINT ( user_data ) ) ? NK_BINDINGS_BINDING_TRIGGERED : NK_BINDINGS_BINDING_NOT_TRIGGERED;
+}
+
+static void binding_trigger_action ( guint64 scope, G_GNUC_UNUSED gpointer target, gpointer user_data )
+{
+ rofi_view_trigger_action ( rofi_view_get_active (), scope, GPOINTER_TO_UINT ( user_data ) );
}
guint key_binding_get_action_from_name ( const char *name )
@@ -171,7 +176,7 @@ gboolean parse_keys_abe ( NkBindings *bindings )
// Iter over bindings.
const char *const sep = ",";
for ( char *entry = strtok_r ( keystr, sep, &sp ); entry != NULL; entry = strtok_r ( NULL, sep, &sp ) ) {
- if ( !nk_bindings_add_binding ( bindings, b->scope, entry, binding_trigger_action, GUINT_TO_POINTER ( b->id ), NULL, &error ) ) {
+ if ( !nk_bindings_add_binding ( bindings, b->scope, entry, binding_check_action, binding_trigger_action, GUINT_TO_POINTER ( b->id ), NULL, &error ) ) {
char *str = g_markup_printf_escaped ( "Failed to set binding <i>%s</i> for: <i>%s (%s)</i>:\n\t<span size=\"smaller\" style=\"italic\">%s</span>\n",
b->binding, b->comment, b->name, error->message );
g_string_append ( error_msg, str );
@@ -191,7 +196,7 @@ gboolean parse_keys_abe ( NkBindings *bindings )
for ( gsize i = SCOPE_MIN_FIXED; i <= SCOPE_MAX_FIXED; ++i ) {
for ( gsize j = 1; j < G_N_ELEMENTS ( mouse_default_bindings ); ++j ) {
- nk_bindings_add_binding ( bindings, i, mouse_default_bindings[j], binding_trigger_action, GSIZE_TO_POINTER ( j ), NULL, NULL );
+ nk_bindings_add_binding ( bindings, i, mouse_default_bindings[j], binding_check_action, binding_trigger_action, GSIZE_TO_POINTER ( j ), NULL, NULL );
}
}
diff --git a/source/view.c b/source/view.c
index 3010a08d..27994eb1 100644
--- a/source/view.c
+++ b/source/view.c
@@ -1470,12 +1470,10 @@ static void rofi_view_trigger_global_action(KeyBindingAction action) {
}
}
-gboolean rofi_view_trigger_action(RofiViewState *state, BindingsScope scope,
- guint action) {
- rofi_view_set_user_timeout(NULL);
+gboolean rofi_view_check_action(RofiViewState *state, BindingsScope scope,
+ guint action) {
switch (scope) {
case SCOPE_GLOBAL:
- rofi_view_trigger_global_action(action);
return TRUE;
case SCOPE_MOUSE_LISTVIEW:
case SCOPE_MOUSE_LISTVIEW_ELEMENT:
@@ -1489,22 +1487,54 @@ gboolean rofi_view_trigger_action(RofiViewState *state, BindingsScope scope,
return FALSE;
}
widget_xy_to_relative(target, &x, &y);
- switch (widget_trigger_action(target, action, x, y)) {
+ switch (widget_check_action(target, action, x, y)) {
case WIDGET_TRIGGER_ACTION_RESULT_IGNORED:
return FALSE;
case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END:
+ case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN:
+ case WIDGET_TRIGGER_ACTION_RESULT_HANDLED:
+ return TRUE;
+ }
+ break;
+ }
+ }
+ return FALSE;
+}
+
+void rofi_view_trigger_action(RofiViewState *state, BindingsScope scope,
+ guint action) {
+ rofi_view_set_user_timeout(NULL);
+ switch (scope) {
+ case SCOPE_GLOBAL:
+ rofi_view_trigger_global_action(action);
+ return;
+ case SCOPE_MOUSE_LISTVIEW:
+ case SCOPE_MOUSE_LISTVIEW_ELEMENT:
+ case SCOPE_MOUSE_EDITBOX:
+ case SCOPE_MOUSE_SCROLLBAR:
+ case SCOPE_MOUSE_MODE_SWITCHER: {
+ gint x = state->mouse.x, y = state->mouse.y;
+ widget *target = widget_find_mouse_target(WIDGET(state->main_window),
+ (WidgetType)scope, x, y);
+ if (target == NULL) {
+ return;
+ }
+ widget_xy_to_relative(target, &x, &y);
+ switch (widget_trigger_action(target, action, x, y)) {
+ case WIDGET_TRIGGER_ACTION_RESULT_IGNORED:
+ return;
+ case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END:
target = NULL;
/* FALLTHRU */
case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN:
state->mouse.motion_target = target;
/* FALLTHRU */
case WIDGET_TRIGGER_ACTION_RESULT_HANDLED:
- return TRUE;
+ return;
}
break;
}
}
- return FALSE;
}
void rofi_view_handle_text(RofiViewState *state, char *text) {
diff --git a/source/widgets/widget.c b/source/widgets/widget.c
index aaaea1f8..3eb5debd 100644
--- a/source/widgets/widget.c
+++ b/source/widgets/widget.c
@@ -548,6 +548,21 @@ widget *widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y) {
return NULL;
}
+WidgetTriggerActionResult widget_check_action(widget *wid, guint action,
+ gint x, gint y) {
+ if (wid == NULL) {
+ return FALSE;
+ }
+ if (wid->trigger_action == NULL) {
+ return FALSE;
+ }
+ /*
+ * TODO: We should probably add a check_action callback to the widgets
+ * to do extra checks
+ */
+ return WIDGET_TRIGGER_ACTION_RESULT_HANDLED;
+}
+
WidgetTriggerActionResult widget_trigger_action(widget *wid, guint action,
gint x, gint y) {
if (wid == NULL) {
diff --git a/subprojects/libnkutils b/subprojects/libnkutils
-Subproject 6164bacaef10031ce77380499cfad2ae818ab6b
+Subproject 24377c9d163b520778ce6511f3d649e1dc4521d
diff --git a/test/mode-test.c b/test/mode-test.c
index 2c4c7216..8b76d65d 100644
--- a/test/mode-test.c
+++ b/test/mode-test.c
@@ -97,10 +97,13 @@ RofiViewState * rofi_view_get_active ( void )
{
return NULL;
}
-gboolean rofi_view_trigger_action ( G_GNUC_UNUSED RofiViewState *state, G_GNUC_UNUSED BindingsScope scope, G_GNUC_UNUSED guint action )
+gboolean rofi_view_check_action ( G_GNUC_UNUSED RofiViewState *state, G_GNUC_UNUSED BindingsScope scope, G_GNUC_UNUSED guint action )
{
return FALSE;
}
+void rofi_view_trigger_action ( G_GNUC_UNUSED RofiViewState *state, G_GNUC_UNUSED BindingsScope scope, G_GNUC_UNUSED guint action )
+{
+}
void display_startup_notification ( G_GNUC_UNUSED RofiHelperExecuteContext *context, G_GNUC_UNUSED GSpawnChildSetupFunc *child_setup, G_GNUC_UNUSED gpointer *user_data )
{