diff options
author | Quentin Glidic <sardemff7+git@sardemff7.net> | 2017-05-30 12:45:48 +0200 |
---|---|---|
committer | Quentin Glidic <sardemff7+git@sardemff7.net> | 2017-05-30 13:45:19 +0200 |
commit | acc1fa45b955fa2a771cb1a22c541086d1425a19 (patch) | |
tree | 3b41149930995b646f082441841b6c58b9ba98aa | |
parent | 0555d15c469d0dffbbfc33f351f4eed5882b3370 (diff) |
widget: Add motion grab support
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
-rw-r--r-- | include/widgets/widget.h | 21 | ||||
-rw-r--r-- | source/view.c | 22 | ||||
-rw-r--r-- | source/widgets/listview.c | 12 | ||||
-rw-r--r-- | source/widgets/scrollbar.c | 6 | ||||
-rw-r--r-- | source/widgets/textbox.c | 6 | ||||
-rw-r--r-- | source/widgets/widget.c | 2 | ||||
m--------- | subprojects/libnkutils | 0 |
7 files changed, 48 insertions, 21 deletions
diff --git a/include/widgets/widget.h b/include/widgets/widget.h index 3737380f..bcc45e1d 100644 --- a/include/widgets/widget.h +++ b/include/widgets/widget.h @@ -70,6 +70,21 @@ typedef enum } WidgetType; /** + * Whether and how the action was handled + */ +typedef enum +{ + /** The action was ignore and should bubble */ + WIDGET_TRIGGER_ACTION_RESULT_IGNORED, + /** The action was handled directly */ + WIDGET_TRIGGER_ACTION_RESULT_HANDLED, + /** The action was handled and should start the grab for motion events */ + WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN, + /** The action was handled and should stop the grab for motion events */ + WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END, +} WidgetTriggerActionResult; + +/** * @param widget The container widget itself * @param type The widget type searched for * @param x The X coordination of the mouse event relative to @widget @@ -90,9 +105,9 @@ typedef widget * ( *widget_find_mouse_target_cb )( widget *widget, WidgetType ty * * This callback should handle the action if relevant, and returns whether it did or not. * - * @returns Whether the action was handled or not + * @returns Whether the action was handled or not, see enum values for details */ -typedef gboolean ( *widget_trigger_action_cb )( widget *widget, guint action, gint x, gint y, void *user_data ); +typedef WidgetTriggerActionResult ( *widget_trigger_action_cb )( widget *widget, guint action, gint x, gint y, void *user_data ); /** Macro to get widget from an implementation (e.g. textbox/scrollbar) */ #define WIDGET( a ) ( (widget *) ( a ) ) @@ -249,7 +264,7 @@ widget *widget_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y * * @returns Whether the action was handled or not */ -gboolean widget_trigger_action ( widget *wid, guint action, gint x, gint y ); +WidgetTriggerActionResult widget_trigger_action ( widget *wid, guint action, gint x, gint y ); /** * @param wid The widget handle diff --git a/source/view.c b/source/view.c index 2fe21de8..db2890cc 100644 --- a/source/view.c +++ b/source/view.c @@ -1363,7 +1363,19 @@ gboolean rofi_view_trigger_action ( guint scope, gpointer user_data ) return FALSE; } widget_xy_to_relative ( target, &x, &y ); - return widget_trigger_action ( target, GPOINTER_TO_UINT ( user_data ), x, y ); + switch ( widget_trigger_action ( target, GPOINTER_TO_UINT ( user_data ), x, y ) ) + { + case WIDGET_TRIGGER_ACTION_RESULT_IGNORED: + return FALSE; + return TRUE; + case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END: + target = NULL; + case WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN: + state->mouse.motion_target = target; + case WIDGET_TRIGGER_ACTION_RESULT_HANDLED: + return TRUE; + } + break; } } return FALSE; @@ -1502,7 +1514,7 @@ static int rofi_view_calculate_height ( RofiViewState *state ) return height; } -static gboolean textbox_sidebar_modi_trigger_action ( widget *wid, MouseBindingMouseDefaultAction action, gint x, gint y, G_GNUC_UNUSED void *user_data ) +static WidgetTriggerActionResult textbox_sidebar_modi_trigger_action ( widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x, G_GNUC_UNUSED gint y, G_GNUC_UNUSED void *user_data ) { RofiViewState *state = ( RofiViewState *) user_data; unsigned int i; @@ -1512,7 +1524,7 @@ static gboolean textbox_sidebar_modi_trigger_action ( widget *wid, MouseBindingM } } if ( i == state->num_modi ) { - return FALSE; + return WIDGET_TRIGGER_ACTION_RESULT_IGNORED; } switch ( action ) @@ -1521,13 +1533,13 @@ static gboolean textbox_sidebar_modi_trigger_action ( widget *wid, MouseBindingM state->retv = MENU_QUICK_SWITCH | ( i & MENU_LOWER_MASK ); state->quit = TRUE; state->skip_absorb = TRUE; - return TRUE; + return WIDGET_TRIGGER_ACTION_RESULT_HANDLED; case MOUSE_CLICK_UP: case MOUSE_DCLICK_DOWN: case MOUSE_DCLICK_UP: break; } - return FALSE; + return WIDGET_TRIGGER_ACTION_RESULT_IGNORED; } // @TODO don't like this construction. diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 16df19c4..8d048bb6 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -219,7 +219,7 @@ static void listview_draw ( widget *wid, cairo_t *draw ) widget_draw ( WIDGET ( lv->scrollbar ), draw ); } -static gboolean listview_element_trigger_action ( widget *wid, MouseBindingListviewElementAction action, gint x, gint y, void *user_data ); +static WidgetTriggerActionResult listview_element_trigger_action ( widget *wid, MouseBindingListviewElementAction action, gint x, gint y, void *user_data ); static void listview_recompute_elements ( listview *lv ) { @@ -327,7 +327,7 @@ static widget *listview_find_mouse_target ( widget *wid, WidgetType type, gint x return target; } -static gboolean listview_trigger_action ( widget *wid, MouseBindingListviewAction action, G_GNUC_UNUSED gint x, G_GNUC_UNUSED gint y, G_GNUC_UNUSED void *user_data ) +static WidgetTriggerActionResult listview_trigger_action ( widget *wid, MouseBindingListviewAction action, G_GNUC_UNUSED gint x, G_GNUC_UNUSED gint y, G_GNUC_UNUSED void *user_data ) { listview *lv = (listview *) wid; switch ( action ) @@ -345,10 +345,10 @@ static gboolean listview_trigger_action ( widget *wid, MouseBindingListviewActio listview_nav_up ( lv ); break; } - return TRUE; + return WIDGET_TRIGGER_ACTION_RESULT_HANDLED; } -static gboolean listview_element_trigger_action ( widget *wid, MouseBindingListviewElementAction action, gint x, gint y, void *user_data ) +static WidgetTriggerActionResult listview_element_trigger_action ( widget *wid, MouseBindingListviewElementAction action, G_GNUC_UNUSED gint x, G_GNUC_UNUSED gint y, void *user_data ) { listview *lv = (listview *) user_data; unsigned int max = MIN ( lv->cur_elements, lv->req_elements - lv->last_offset ); @@ -356,7 +356,7 @@ static gboolean listview_element_trigger_action ( widget *wid, MouseBindingListv for ( i = 0; i < max && WIDGET ( lv->boxes[i] ) != wid; i++ ) { } if ( i == max ) { - return FALSE; + return WIDGET_TRIGGER_ACTION_RESULT_IGNORED; } gboolean custom = FALSE; @@ -372,7 +372,7 @@ static gboolean listview_element_trigger_action ( widget *wid, MouseBindingListv lv->mouse_activated ( lv, custom, lv->mouse_activated_data ); break; } - return TRUE; + return WIDGET_TRIGGER_ACTION_RESULT_HANDLED; } listview *listview_create ( const char *name, listview_update_callback cb, void *udata, unsigned int eh, gboolean reverse ) diff --git a/source/widgets/scrollbar.c b/source/widgets/scrollbar.c index 1dc1ad3c..bd5f7716 100644 --- a/source/widgets/scrollbar.c +++ b/source/widgets/scrollbar.c @@ -75,16 +75,16 @@ static void scrollbar_scroll ( scrollbar *sb, int y ) listview_set_selected ( (listview *) sb->widget.parent, scrollbar_scroll_get_line ( sb, y ) ); } -static gboolean scrollbar_trigger_action ( widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x, gint y, G_GNUC_UNUSED void *user_data ) +static WidgetTriggerActionResult scrollbar_trigger_action ( widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x, gint y, G_GNUC_UNUSED void *user_data ) { scrollbar *sb = (scrollbar *) wid; switch ( action ) { case MOUSE_CLICK_DOWN: - return TRUE; + return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN; case MOUSE_CLICK_UP: scrollbar_scroll ( sb, y ); - return TRUE; + return WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END; case MOUSE_DCLICK_DOWN: case MOUSE_DCLICK_UP: break; diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index f527b7a5..9fd9c0f5 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -106,7 +106,7 @@ static int textbox_get_desired_height ( widget *wid ) return height; } -static gboolean textbox_editable_trigger_action ( widget *wid, MouseBindingMouseDefaultAction action, gint x, gint y, G_GNUC_UNUSED void *user_data ) +static WidgetTriggerActionResult textbox_editable_trigger_action ( widget *wid, MouseBindingMouseDefaultAction action, gint x, gint y, G_GNUC_UNUSED void *user_data ) { textbox *tb = (textbox *) wid; switch ( action ) @@ -116,14 +116,14 @@ static gboolean textbox_editable_trigger_action ( widget *wid, MouseBindingMouse gint i; pango_layout_xy_to_index ( tb->layout, x * PANGO_SCALE, y * PANGO_SCALE, &i, NULL ); textbox_cursor ( tb, i ); - return TRUE; + return WIDGET_TRIGGER_ACTION_RESULT_HANDLED; } case MOUSE_CLICK_UP: case MOUSE_DCLICK_DOWN: case MOUSE_DCLICK_UP: break; } - return FALSE; + return WIDGET_TRIGGER_ACTION_RESULT_IGNORED; } textbox* textbox_create_full ( WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text ) diff --git a/source/widgets/widget.c b/source/widgets/widget.c index b98ee45b..353ab754 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -453,7 +453,7 @@ widget *widget_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y return NULL; } -gboolean widget_trigger_action ( widget *wid, guint action, gint x, gint y ) +WidgetTriggerActionResult widget_trigger_action ( widget *wid, guint action, gint x, gint y ) { if ( wid && wid->trigger_action ) { return wid->trigger_action ( wid, action, x, y, wid->trigger_action_cb_data ); diff --git a/subprojects/libnkutils b/subprojects/libnkutils -Subproject b968248064c47a927d9f3ac8720cb11816ed271 +Subproject cceed6c047369de55c123dea4371cfa9bdb147c |