[widget] Make button press event statusbar indep
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
c20a2cb416
commit
34cd5504a7
48
event.c
48
event.c
|
@ -76,7 +76,7 @@ int
|
||||||
event_handle_buttonpress(void *data __attribute__ ((unused)),
|
event_handle_buttonpress(void *data __attribute__ ((unused)),
|
||||||
xcb_connection_t *connection, xcb_button_press_event_t *ev)
|
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));
|
const int nb_screen = xcb_setup_roots_length(xcb_get_setup(connection));
|
||||||
client_t *c;
|
client_t *c;
|
||||||
widget_node_t *w;
|
widget_node_t *w;
|
||||||
|
@ -94,44 +94,30 @@ event_handle_buttonpress(void *data __attribute__ ((unused)),
|
||||||
ev->event_x -= statusbar->sw->geometry.x;
|
ev->event_x -= statusbar->sw->geometry.x;
|
||||||
ev->event_y -= statusbar->sw->geometry.y;
|
ev->event_y -= statusbar->sw->geometry.y;
|
||||||
}
|
}
|
||||||
|
/* Need to transform coordinates like it was
|
||||||
|
* top/bottom */
|
||||||
switch(statusbar->position)
|
switch(statusbar->position)
|
||||||
{
|
{
|
||||||
case Top:
|
case Right:
|
||||||
case Bottom:
|
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)
|
for(w = statusbar->widgets; w; w = w->next)
|
||||||
if(ev->event_x >= w->area.x && ev->event_x < w->area.x + w->area.width
|
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)
|
&& 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;
|
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 if no widget match */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ struct widget_t
|
||||||
/** Update function */
|
/** Update function */
|
||||||
widget_tell_status_t (*tell)(widget_t *, const char *, const char *);
|
widget_tell_status_t (*tell)(widget_t *, const char *, const char *);
|
||||||
/** ButtonPressedEvent handler */
|
/** 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 */
|
/** Alignement */
|
||||||
alignment_t align;
|
alignment_t align;
|
||||||
/** Misc private data */
|
/** Misc private data */
|
||||||
|
|
8
widget.c
8
widget.c
|
@ -70,13 +70,15 @@ widget_getbyname(const char *name)
|
||||||
/** Common function for button press event on widget.
|
/** Common function for button press event on widget.
|
||||||
* It will look into configuration to find the callback function to call.
|
* It will look into configuration to find the callback function to call.
|
||||||
* \param w The widget node.
|
* \param w The widget node.
|
||||||
* \param statusbar The statusbar.
|
|
||||||
* \param ev The button press event the widget received.
|
* \param ev The button press event the widget received.
|
||||||
|
* \param screen The screen number.
|
||||||
|
* \param p The object where user clicked.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
widget_common_button_press(widget_node_t *w,
|
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;
|
button_t *b;
|
||||||
|
|
||||||
|
|
|
@ -191,10 +191,12 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
taglist_button_press(widget_node_t *w, statusbar_t *statusbar,
|
taglist_button_press(widget_node_t *w,
|
||||||
xcb_button_press_event_t *ev)
|
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;
|
button_t *b;
|
||||||
taglist_data_t *data = w->widget->data;
|
taglist_data_t *data = w->widget->data;
|
||||||
taglist_drawn_area_t *tda;
|
taglist_drawn_area_t *tda;
|
||||||
|
@ -202,14 +204,11 @@ taglist_button_press(widget_node_t *w, statusbar_t *statusbar,
|
||||||
tag_t *tag;
|
tag_t *tag;
|
||||||
|
|
||||||
/* Find the good drawn area list */
|
/* 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;
|
area = tda->area;
|
||||||
|
|
||||||
for(b = w->widget->buttons; b; b = b->next)
|
for(b = w->widget->buttons; b; b = b->next)
|
||||||
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct)
|
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)
|
for(tag = vscreen->tags; tag && area; tag = tag->next, area = area->next)
|
||||||
if(ev->event_x >= AREA_LEFT(*area)
|
if(ev->event_x >= AREA_LEFT(*area)
|
||||||
&& ev->event_x < AREA_RIGHT(*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);
|
luaA_dofunction(globalconf.L, b->fct, 1);
|
||||||
return;
|
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
|
static widget_tell_status_t
|
||||||
|
|
|
@ -172,8 +172,10 @@ tasklist_draw(draw_context_t *ctx, int screen,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tasklist_button_press(widget_node_t *w, statusbar_t *statusbar,
|
tasklist_button_press(widget_node_t *w,
|
||||||
xcb_button_press_event_t *ev)
|
xcb_button_press_event_t *ev,
|
||||||
|
int screen,
|
||||||
|
void *p __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
button_t *b;
|
button_t *b;
|
||||||
client_t *c;
|
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;
|
int n = 0, box_width = 0, i, ci = 0;
|
||||||
|
|
||||||
for(c = globalconf.clients; c; c = c->next)
|
for(c = globalconf.clients; c; c = c->next)
|
||||||
if(tasklist_isvisible(c, statusbar->screen, d->show))
|
if(tasklist_isvisible(c, screen, d->show))
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
if(!n)
|
if(!n)
|
||||||
|
@ -189,26 +191,15 @@ tasklist_button_press(widget_node_t *w, statusbar_t *statusbar,
|
||||||
|
|
||||||
box_width = w->area.width / n;
|
box_width = w->area.width / n;
|
||||||
|
|
||||||
switch(statusbar->position)
|
|
||||||
{
|
|
||||||
case Top:
|
|
||||||
case Bottom:
|
|
||||||
ci = (ev->event_x - w->area.x) / box_width;
|
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 */
|
/* found first visible client */
|
||||||
for(c = globalconf.clients;
|
for(c = globalconf.clients;
|
||||||
c && !tasklist_isvisible(c, statusbar->screen, d->show);
|
c && !tasklist_isvisible(c, screen, d->show);
|
||||||
c = c->next);
|
c = c->next);
|
||||||
/* found ci-th visible client */
|
/* found ci-th visible client */
|
||||||
for(i = 0; c ; c = c->next)
|
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)
|
if(i++ >= ci)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue