diff --git a/include/view-internal.h b/include/view-internal.h index 4271b90e..999b255c 100644 --- a/include/view-internal.h +++ b/include/view-internal.h @@ -124,8 +124,9 @@ struct RofiViewState struct { - int x; - int y; + int x; + int y; + widget *motion_target; } mouse; /** Regexs used for matching */ diff --git a/include/widgets/widget-internal.h b/include/widgets/widget-internal.h index 60e1d11c..0addb2b5 100644 --- a/include/widgets/widget-internal.h +++ b/include/widgets/widget-internal.h @@ -78,7 +78,7 @@ struct _widget void ( *update )( struct _widget * ); /** Handle mouse motion, used for dragging */ - gboolean ( *motion_notify )( struct _widget *, xcb_motion_notify_event_t * ); + gboolean ( *motion_notify )( struct _widget *, gint x, gint y ); int ( *get_desired_height )( struct _widget * ); diff --git a/include/widgets/widget.h b/include/widgets/widget.h index dcfe593d..3737380f 100644 --- a/include/widgets/widget.h +++ b/include/widgets/widget.h @@ -268,7 +268,7 @@ void widget_set_trigger_action_handler ( widget *wid, widget_trigger_action_cb c * TODO make this like clicked with callback. * returns TRUE when handled. */ -gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme ); +gboolean widget_motion_notify ( widget *wid, gint x, gint y ); /** * @param wid The widget handle diff --git a/source/view.c b/source/view.c index 43f8bb0c..2fe21de8 100644 --- a/source/view.c +++ b/source/view.c @@ -1410,8 +1410,11 @@ void rofi_view_itterrate ( RofiViewState *state, xcb_generic_event_t *event, xkb xcb_motion_notify_event_t xme = *( (xcb_motion_notify_event_t *) event ); state->mouse.x = xme.event_x; state->mouse.y = xme.event_y; - if ( widget_motion_notify ( WIDGET ( state->main_window ), &xme ) ) { - return; + if ( state->mouse.motion_target != NULL ) { + gint x = state->mouse.x; + gint y = state->mouse.y; + widget_xy_to_relative ( state->mouse.motion_target, &x, &y ); + widget_motion_notify ( state->mouse.motion_target, x, y ); } break; } diff --git a/source/widgets/box.c b/source/widgets/box.c index 9c9ccb89..a2fc6a95 100644 --- a/source/widgets/box.c +++ b/source/widgets/box.c @@ -297,24 +297,6 @@ static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint x, gin return NULL; } -static gboolean box_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme ) -{ - box *b = (box *) wid; - for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) { - widget * child = (widget *) iter->data; - if ( !child->enabled ) { - continue; - } - if ( widget_intersect ( child, xme->event_x, xme->event_y ) ) { - xcb_motion_notify_event_t rel = *xme; - rel.event_x -= child->x; - rel.event_y -= child->y; - return widget_motion_notify ( child, &rel ); - } - } - return FALSE; -} - box * box_create ( const char *name, boxType type ) { box *b = g_malloc0 ( sizeof ( box ) ); @@ -326,7 +308,6 @@ box * box_create ( const char *name, boxType type ) b->widget.resize = box_resize; b->widget.update = box_update; b->widget.find_mouse_target = box_find_mouse_target; - b->widget.motion_notify = box_motion_notify; b->widget.get_desired_height = box_get_desired_height; b->widget.enabled = rofi_theme_get_boolean ( WIDGET ( b ), "enabled", TRUE ); diff --git a/source/widgets/container.c b/source/widgets/container.c index 783f7ee4..6807ce15 100644 --- a/source/widgets/container.c +++ b/source/widgets/container.c @@ -100,18 +100,6 @@ static widget *container_find_mouse_target ( widget *wid, WidgetType type, gint return widget_find_mouse_target ( b->child, type, x, y ); } -static gboolean container_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme ) -{ - container *b = (container *) wid; - if ( widget_intersect ( b->child, xme->event_x, xme->event_y ) ) { - xcb_motion_notify_event_t rel = *xme; - rel.event_x -= b->child->x; - rel.event_y -= b->child->y; - return widget_motion_notify ( b->child, &rel ); - } - return FALSE; -} - container * container_create ( const char *name ) { container *b = g_malloc0 ( sizeof ( container ) ); @@ -122,7 +110,6 @@ container * container_create ( const char *name ) b->widget.resize = container_resize; b->widget.update = container_update; b->widget.find_mouse_target = container_find_mouse_target; - b->widget.motion_notify = container_motion_notify; b->widget.get_desired_height = container_get_desired_height; b->widget.enabled = rofi_theme_get_boolean ( WIDGET ( b ), "enabled", TRUE ); return b; diff --git a/source/widgets/scrollbar.c b/source/widgets/scrollbar.c index db4c1d17..b21066f7 100644 --- a/source/widgets/scrollbar.c +++ b/source/widgets/scrollbar.c @@ -83,7 +83,7 @@ static gboolean scrollbar_trigger_action ( widget *wid, MouseBindingMouseDefault return FALSE; } -static gboolean scrollbar_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme ) +static gboolean scrollbar_motion_notify ( widget *wid, G_GNUC_UNUSED gint x, gint y ) { /* FIXME: scoll scrollbar *sb = (scrollbar *) wid; diff --git a/source/widgets/widget.c b/source/widgets/widget.c index 2fd99863..b98ee45b 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -467,10 +467,10 @@ void widget_set_trigger_action_handler ( widget *wid, widget_trigger_action_cb c wid->trigger_action_cb_data = cb_data; } -gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme ) +gboolean widget_motion_notify ( widget *wid, gint x, gint y ) { if ( wid && wid->motion_notify ) { - wid->motion_notify ( wid, xme ); + wid->motion_notify ( wid, x, y ); } return FALSE;