[widget] Make button press event statusbar indep

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-03 11:40:50 +02:00
parent c20a2cb416
commit 34cd5504a7
5 changed files with 45 additions and 89 deletions

48
event.c
View File

@ -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:
case Right:
tmp = ev->event_y;
ev->event_y = statusbar->height - ev->event_x;
ev->event_x = tmp;
break;
case Left:
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, statusbar, ev);
w->widget->button_press(w, ev, statusbar->screen, statusbar);
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;
}
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;
}
break;
default:
break;
}
/* return if no widget match */
return 0;
}

View File

@ -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 */

View File

@ -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;

View File

@ -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,14 +204,11 @@ 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))
@ -218,28 +217,6 @@ taglist_button_press(widget_node_t *w, statusbar_t *statusbar,
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;
}
}
static widget_tell_status_t

View File

@ -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;
}
/* 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;