mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
widget: Add motion grab support
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
parent
0555d15c46
commit
acc1fa45b9
7 changed files with 49 additions and 22 deletions
|
@ -69,6 +69,21 @@ typedef enum
|
|||
WIDGET_TYPE_SIDEBAR_MODI = SCOPE_MOUSE_SIDEBAR_MODI,
|
||||
} 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
|
||||
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b968248064c47a927d9f3ac8720cb11816ed2711
|
||||
Subproject commit cceed6c047369de55c123dea4371cfa9bdb147ce
|
Loading…
Reference in a new issue