diff --git a/event.c b/event.c index 16d312c5..5f93884a 100644 --- a/event.c +++ b/event.c @@ -76,7 +76,7 @@ int event_handle_buttonpress(void *data __attribute__ ((unused)), xcb_connection_t *connection, xcb_button_press_event_t *ev) { - int screen; + int screen, tmp; const int nb_screen = xcb_setup_roots_length(xcb_get_setup(connection)); client_t *c; widget_node_t *w; @@ -94,44 +94,30 @@ event_handle_buttonpress(void *data __attribute__ ((unused)), ev->event_x -= statusbar->sw->geometry.x; ev->event_y -= statusbar->sw->geometry.y; } + /* Need to transform coordinates like it was + * top/bottom */ switch(statusbar->position) { - case Top: - case Bottom: - for(w = statusbar->widgets; w; w = w->next) - if(ev->event_x >= w->area.x && ev->event_x < w->area.x + w->area.width - && ev->event_y >= w->area.y && ev->event_y < w->area.y + w->area.height) - { - w->widget->button_press(w, statusbar, ev); - return 0; - } - break; case Right: - for(w = statusbar->widgets; w; w = w->next) - if(ev->event_y > w->area.x && ev->event_y < w->area.x + w->area.width - && statusbar->sw->geometry.width - ev->event_x >= w->area.y - && statusbar->sw->geometry.width - ev->event_x - < w->area.y + w->area.height) - { - w->widget->button_press(w, statusbar, ev); - return 0; - } + tmp = ev->event_y; + ev->event_y = statusbar->height - ev->event_x; + ev->event_x = tmp; break; case Left: - for(w = statusbar->widgets; w; w = w->next) - if(statusbar->sw->geometry.height - ev->event_y >= w->area.x - && statusbar->sw->geometry.height - ev->event_y - < w->area.x + w->area.width - && ev->event_x >= w->area.y - && ev->event_x < w->area.y + w->area.height) - { - w->widget->button_press(w, statusbar, ev); - return 0; - } + tmp = ev->event_y; + ev->event_y = ev->event_x; + ev->event_x = statusbar->width - tmp; break; default: break; } + for(w = statusbar->widgets; w; w = w->next) + if(ev->event_x >= w->area.x && ev->event_x < w->area.x + w->area.width + && ev->event_y >= w->area.y && ev->event_y < w->area.y + w->area.height) + { + w->widget->button_press(w, ev, statusbar->screen, statusbar); + return 0; + } /* return if no widget match */ return 0; } diff --git a/structs.h b/structs.h index 0ff164a5..45d3dd8c 100644 --- a/structs.h +++ b/structs.h @@ -140,7 +140,7 @@ struct widget_t /** Update function */ widget_tell_status_t (*tell)(widget_t *, const char *, const char *); /** ButtonPressedEvent handler */ - void (*button_press)(widget_node_t *, statusbar_t *, xcb_button_press_event_t *); + void (*button_press)(widget_node_t *, xcb_button_press_event_t *, int, void *); /** Alignement */ alignment_t align; /** Misc private data */ diff --git a/widget.c b/widget.c index 09a182a8..4b903937 100644 --- a/widget.c +++ b/widget.c @@ -70,13 +70,15 @@ widget_getbyname(const char *name) /** Common function for button press event on widget. * It will look into configuration to find the callback function to call. * \param w The widget node. - * \param statusbar The statusbar. * \param ev The button press event the widget received. + * \param screen The screen number. + * \param p The object where user clicked. */ static void widget_common_button_press(widget_node_t *w, - statusbar_t *statusbar __attribute__ ((unused)), - xcb_button_press_event_t *ev) + xcb_button_press_event_t *ev, + int screen __attribute__ ((unused)), + void *p __attribute__ ((unused))) { button_t *b; diff --git a/widgets/taglist.c b/widgets/taglist.c index 93eb3249..f45554ed 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -191,10 +191,12 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w, } static void -taglist_button_press(widget_node_t *w, statusbar_t *statusbar, - xcb_button_press_event_t *ev) +taglist_button_press(widget_node_t *w, + xcb_button_press_event_t *ev, + int screen, + void *object) { - screen_t *vscreen = &globalconf.screens[statusbar->screen]; + screen_t *vscreen = &globalconf.screens[screen]; button_t *b; taglist_data_t *data = w->widget->data; taglist_drawn_area_t *tda; @@ -202,44 +204,19 @@ taglist_button_press(widget_node_t *w, statusbar_t *statusbar, tag_t *tag; /* Find the good drawn area list */ - for(tda = data->drawn_area; tda && tda->object != statusbar; tda = tda->next); + for(tda = data->drawn_area; tda && tda->object != object; tda = tda->next); area = tda->area; for(b = w->widget->buttons; b; b = b->next) if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct) - switch(statusbar->position) - { - default: - for(tag = vscreen->tags; tag && area; tag = tag->next, area = area->next) - if(ev->event_x >= AREA_LEFT(*area) - && ev->event_x < AREA_RIGHT(*area)) - { - luaA_tag_userdata_new(tag); - luaA_dofunction(globalconf.L, b->fct, 1); - return; - } - break; - case Right: - for(tag = vscreen->tags; tag && area; tag = tag->next, area = area->next) - if(ev->event_y >= AREA_LEFT(*area) - && ev->event_y < AREA_RIGHT(*area)) - { - luaA_tag_userdata_new(tag); - luaA_dofunction(globalconf.L, b->fct, 1); - return; - } - break; - case Left: - for(tag = vscreen->tags; tag && area; tag = tag->next, area = area->next) - if(statusbar->width - ev->event_y >= AREA_LEFT(*area) - && statusbar->width - ev->event_y < AREA_RIGHT(*area)) - { - luaA_tag_userdata_new(tag); - luaA_dofunction(globalconf.L, b->fct, 1); - return; - } - break; - } + for(tag = vscreen->tags; tag && area; tag = tag->next, area = area->next) + if(ev->event_x >= AREA_LEFT(*area) + && ev->event_x < AREA_RIGHT(*area)) + { + luaA_tag_userdata_new(tag); + luaA_dofunction(globalconf.L, b->fct, 1); + return; + } } static widget_tell_status_t diff --git a/widgets/tasklist.c b/widgets/tasklist.c index b92abfa7..a84317a4 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -172,8 +172,10 @@ tasklist_draw(draw_context_t *ctx, int screen, } static void -tasklist_button_press(widget_node_t *w, statusbar_t *statusbar, - xcb_button_press_event_t *ev) +tasklist_button_press(widget_node_t *w, + xcb_button_press_event_t *ev, + int screen, + void *p __attribute__ ((unused))) { button_t *b; client_t *c; @@ -181,7 +183,7 @@ tasklist_button_press(widget_node_t *w, statusbar_t *statusbar, int n = 0, box_width = 0, i, ci = 0; for(c = globalconf.clients; c; c = c->next) - if(tasklist_isvisible(c, statusbar->screen, d->show)) + if(tasklist_isvisible(c, screen, d->show)) n++; if(!n) @@ -189,26 +191,15 @@ tasklist_button_press(widget_node_t *w, statusbar_t *statusbar, box_width = w->area.width / n; - switch(statusbar->position) - { - case Top: - case Bottom: - ci = (ev->event_x - w->area.x) / box_width; - break; - case Right: - ci = (ev->event_y - w->area.x) / box_width; - break; - default: - ci = ((statusbar->width - ev->event_y) - w->area.x) / box_width; - break; - } + ci = (ev->event_x - w->area.x) / box_width; + /* found first visible client */ for(c = globalconf.clients; - c && !tasklist_isvisible(c, statusbar->screen, d->show); + c && !tasklist_isvisible(c, screen, d->show); c = c->next); /* found ci-th visible client */ for(i = 0; c ; c = c->next) - if(tasklist_isvisible(c, statusbar->screen, d->show)) + if(tasklist_isvisible(c, screen, d->show)) if(i++ >= ci) break;