summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorQuentin Glidic <sardemff7+git@sardemff7.net>2017-05-30 12:37:11 +0200
committerQuentin Glidic <sardemff7+git@sardemff7.net>2017-05-30 13:44:05 +0200
commit30da7e587a2a1e90c4338af4d07e5bd3be77ecc3 (patch)
tree0604ead2dbca852f42818679a2fd72f0c0fa2f69 /source
parent6a750669d7b4bcdc3758a2308cc35a7bd4ab97e3 (diff)
widget: Add widget_xy_to_relative helper
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Diffstat (limited to 'source')
-rw-r--r--source/view.c4
-rw-r--r--source/widgets/box.c12
-rw-r--r--source/widgets/container.c18
-rw-r--r--source/widgets/listview.c26
-rw-r--r--source/widgets/widget.c11
5 files changed, 33 insertions, 38 deletions
diff --git a/source/view.c b/source/view.c
index cad77b2c..43f8bb0c 100644
--- a/source/view.c
+++ b/source/view.c
@@ -1358,11 +1358,11 @@ gboolean rofi_view_trigger_action ( guint scope, gpointer user_data )
case SCOPE_MOUSE_SIDEBAR_MODI:
{
gint x = state->mouse.x, y = state->mouse.y;
- widget *target = widget_find_mouse_target ( WIDGET ( state->main_window ), scope, &x, &y );
+ widget *target = widget_find_mouse_target ( WIDGET ( state->main_window ), scope, x, y );
if ( target == NULL ) {
return FALSE;
}
-
+ widget_xy_to_relative ( target, &x, &y );
return widget_trigger_action ( target, GPOINTER_TO_UINT ( user_data ), x, y );
}
}
diff --git a/source/widgets/box.c b/source/widgets/box.c
index 2224858a..9c9ccb89 100644
--- a/source/widgets/box.c
+++ b/source/widgets/box.c
@@ -277,7 +277,7 @@ static void box_resize ( widget *widget, short w, short h )
}
}
-static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint *x, gint *y )
+static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
{
box *b = (box *) wid;
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
@@ -285,13 +285,11 @@ static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint *x, gi
if ( !child->enabled ) {
continue;
}
- if ( widget_intersect ( child, *x, *y ) ) {
- gint rx = *x - child->x;
- gint ry = *y - child->y;
- widget *target = widget_find_mouse_target ( child, type, &rx, &ry );
+ if ( widget_intersect ( child, x, y ) ) {
+ gint rx = x - child->x;
+ gint ry = y - child->y;
+ widget *target = widget_find_mouse_target ( child, type, rx, ry );
if ( target != NULL ) {
- *x = rx;
- *y = ry;
return target;
}
}
diff --git a/source/widgets/container.c b/source/widgets/container.c
index a7f16652..783f7ee4 100644
--- a/source/widgets/container.c
+++ b/source/widgets/container.c
@@ -88,24 +88,18 @@ static void container_resize ( widget *widget, short w, short h )
}
}
-static widget *container_find_mouse_target ( widget *wid, WidgetType type, gint *x, gint *y )
+static widget *container_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
{
container *b = (container *) wid;
- if ( !widget_intersect ( b->child, *x, *y ) ) {
+ if ( !widget_intersect ( b->child, x, y ) ) {
return NULL;
}
- gint rx = *x - b->child->x;
- gint ry = *y - b->child->y;
- widget *target = widget_find_mouse_target ( b->child, type, &rx, &ry );
- if ( target == NULL ) {
- return NULL;
- }
-
- *x = rx;
- *y = ry;
- return target;
+ x -= b->child->x;
+ y -= b->child->y;
+ 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;
diff --git a/source/widgets/listview.c b/source/widgets/listview.c
index d121988d..16df19c4 100644
--- a/source/widgets/listview.c
+++ b/source/widgets/listview.c
@@ -302,35 +302,29 @@ static void listview_resize ( widget *wid, short w, short h )
widget_queue_redraw ( wid );
}
-static widget *listview_find_mouse_target ( widget *wid, WidgetType type, gint *x, gint *y )
+static widget *listview_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
{
widget *target = NULL;
gint rx, ry;
listview *lv = (listview *) wid;
- if ( widget_enabled ( WIDGET ( lv->scrollbar ) ) && widget_intersect ( WIDGET ( lv->scrollbar ), *x, *y ) ) {
- rx = *x - widget_get_x_pos ( WIDGET ( lv->scrollbar ) );
- ry = *y - widget_get_y_pos ( WIDGET ( lv->scrollbar ) );
- target = widget_find_mouse_target ( WIDGET ( lv->scrollbar ), type, &rx, &ry );
+ if ( widget_enabled ( WIDGET ( lv->scrollbar ) ) && widget_intersect ( WIDGET ( lv->scrollbar ), x, y ) ) {
+ rx = x - widget_get_x_pos ( WIDGET ( lv->scrollbar ) );
+ ry = y - widget_get_y_pos ( WIDGET ( lv->scrollbar ) );
+ target = widget_find_mouse_target ( WIDGET ( lv->scrollbar ), type, rx, ry );
}
unsigned int max = MIN ( lv->cur_elements, lv->req_elements - lv->last_offset );
unsigned int i;
for ( i = 0; i < max && target == NULL; i++ ) {
widget *w = WIDGET ( lv->boxes[i] );
- if ( widget_intersect ( w, *x, *y ) ) {
- rx = *x - widget_get_x_pos ( w );
- ry = *y - widget_get_y_pos ( w );
- target = widget_find_mouse_target ( w, type, &rx, &ry );
+ if ( widget_intersect ( w, x, y ) ) {
+ rx = x - widget_get_x_pos ( w );
+ ry = y - widget_get_y_pos ( w );
+ target = widget_find_mouse_target ( w, type, rx, ry );
}
}
- if ( target != NULL ) {
- *x = rx;
- *y = ry;
- return target;
- }
-
- return NULL;
+ 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 )
diff --git a/source/widgets/widget.c b/source/widgets/widget.c
index b55bb404..2fd99863 100644
--- a/source/widgets/widget.c
+++ b/source/widgets/widget.c
@@ -395,6 +395,15 @@ int widget_get_y_pos ( widget *widget )
return 0;
}
+void widget_xy_to_relative ( widget *widget, gint *x, gint *y )
+{
+ *x -= widget->x;
+ *y -= widget->y;
+ if ( widget->parent != NULL ) {
+ widget_xy_to_relative ( widget->parent, x, y );
+ }
+}
+
void widget_update ( widget *widget )
{
// When (desired )size of widget changes.
@@ -426,7 +435,7 @@ gboolean widget_need_redraw ( widget *wid )
return FALSE;
}
-widget *widget_find_mouse_target ( widget *wid, WidgetType type, gint *x, gint *y )
+widget *widget_find_mouse_target ( widget *wid, WidgetType type, gint x, gint y )
{
if ( !wid ) {
return NULL;