added button press event handling in wmiirc

This commit is contained in:
Anselm R. Garbe 2006-02-11 15:22:42 +01:00
parent 63bcb2cd1f
commit 55ca4d6c23
9 changed files with 74 additions and 44 deletions

View File

@ -12,6 +12,7 @@ alloc_area(Page *p)
{ {
static unsigned short id = 1; static unsigned short id = 1;
Area *a = cext_emallocz(sizeof(Area)); Area *a = cext_emallocz(sizeof(Area));
a->page = p;
a->id = id++; a->id = id++;
p->area = (Area **)cext_array_attach((void **)p->area, a, sizeof(Area *), &p->areasz); p->area = (Area **)cext_array_attach((void **)p->area, a, sizeof(Area *), &p->areasz);
p->narea++; p->narea++;
@ -29,9 +30,10 @@ destroy_area(Area *a)
} }
int int
area_to_index(Page *p, Area *a) area_to_index(Area *a)
{ {
int i; int i;
Page *p = a->page;
for(i = 0; i < p->narea; i++) for(i = 0; i < p->narea; i++)
if(p->area[i] == a) if(p->area[i] == a)
return i; return i;

View File

@ -94,7 +94,7 @@ static void
client_name_event(Client *c) client_name_event(Client *c)
{ {
char buf[256]; char buf[256];
snprintf(buf, sizeof(buf), "C %s\n", c->name); snprintf(buf, sizeof(buf), "CN %s\n", c->name);
do_pend_fcall(buf); do_pend_fcall(buf);
} }
@ -106,9 +106,9 @@ focus_client(Client *c)
Client *old = sel_client(); Client *old = sel_client();
/* setup indexes */ /* setup indexes */
if(c->page != p) { if(c->area->page != p) {
focus_page(c->page); focus_page(c->area->page);
p = c->page; p = c->area->page;
} }
for(i = 0; i < p->narea; i++) { for(i = 0; i < p->narea; i++) {
Area *a = p->area[i]; Area *a = p->area[i];
@ -167,7 +167,7 @@ configure_client(Client * c)
e.window = c->win; e.window = c->win;
e.x = c->rect.x; e.x = c->rect.x;
e.y = c->rect.y; e.y = c->rect.y;
if(c->page) { if(c->area) {
e.x += c->frame.rect.x; e.x += c->frame.rect.x;
e.y += c->frame.rect.y; e.y += c->frame.rect.y;
} }
@ -224,7 +224,7 @@ handle_client_property(Client *c, XPropertyEvent *e)
cext_strlcpy(c->name, (char*) name.value, sizeof(c->name)); cext_strlcpy(c->name, (char*) name.value, sizeof(c->name));
free(name.value); free(name.value);
} }
if(c->page) if(c->area)
draw_client(c); draw_client(c);
client_name_event(c); client_name_event(c);
break; break;
@ -375,7 +375,6 @@ attach_client(Client *c)
p = page[sel]; p = page[sel];
reparent_client(c, c->frame.win, c->rect.x, c->rect.y); reparent_client(c, c->frame.win, c->rect.x, c->rect.y);
c->page = p;
if(p->sel) if(p->sel)
attach_column(c); attach_column(c);
@ -384,6 +383,7 @@ attach_client(Client *c)
a->client = (Client **)cext_array_attach((void **)a->client, c, a->client = (Client **)cext_array_attach((void **)a->client, c,
sizeof(Client *), &a->clientsz); sizeof(Client *), &a->clientsz);
a->nclient++; a->nclient++;
c->area = a;
} }
resize_client(c, &c->frame.rect, nil); resize_client(c, &c->frame.rect, nil);
map_client(c); map_client(c);
@ -394,16 +394,16 @@ attach_client(Client *c)
void void
detach_client(Client *c, Bool unmap) detach_client(Client *c, Bool unmap)
{ {
if(c->page) { if(c->area) {
size_t i; size_t i;
for(i = 0; i < nclient; i++) for(i = 0; i < nclient; i++)
if(client[i]->revert == c) if(client[i]->revert == c)
client[i]->revert = nil; client[i]->revert = nil;
if(area_to_index(c->page, c->area) > 0) if(area_to_index(c->area) > 0)
detach_column(c); detach_column(c);
else { else {
Area *a = c->page->area[0]; Area *a = c->area;
cext_array_detach((void **)a->client, c, &a->clientsz); cext_array_detach((void **)a->client, c, &a->clientsz);
a->nclient--; a->nclient--;
if(!c->destroyed) { if(!c->destroyed) {
@ -419,7 +419,7 @@ detach_client(Client *c, Bool unmap)
} }
} }
} }
c->page = nil; c->area = nil;
if(c->revert) if(c->revert)
focus_client(c->revert); focus_client(c->revert);
if(c->destroyed) if(c->destroyed)
@ -511,7 +511,7 @@ resize_client(Client *c, XRectangle *r, XPoint *pt)
unsigned int bh = bar_height(c); unsigned int bh = bar_height(c);
unsigned int bw = c->frame.border; unsigned int bw = c->frame.border;
if(area_to_index(c->page, c->area) > 0) if(area_to_index(c->area) > 0)
resize_column(c, r, pt); resize_column(c, r, pt);
else else
c->frame.rect = *r; c->frame.rect = *r;
@ -563,3 +563,13 @@ cid_to_index(Area *a, unsigned short id)
return -1; return -1;
} }
int
client_to_index(Client *c)
{
int i;
Area *a = c->area;
for(i = 0; i < a->nclient; i++)
if(a->client[i] == c)
return i;
return -1;
}

View File

@ -81,8 +81,8 @@ update_column_width(Page *p)
void void
detach_column(Client *c) detach_column(Client *c)
{ {
Page *p = c->page;
Area *col = c->area; Area *col = c->area;
Page *p = col->page;
cext_array_detach((void **)col->client, c, &col->clientsz); cext_array_detach((void **)col->client, c, &col->clientsz);
if(!col->client[0]) { if(!col->client[0]) {
@ -111,8 +111,8 @@ match_horiz(Area *col, XRectangle *r)
static void static void
drop_resize(Client *c, XRectangle *new) drop_resize(Client *c, XRectangle *new)
{ {
Page *p = c->page;
Area *west = nil, *east = nil, *col = c->area; Area *west = nil, *east = nil, *col = c->area;
Page *p = col->page;
Client *north = nil, *south = nil; Client *north = nil, *south = nil;
size_t i; size_t i;
@ -162,8 +162,8 @@ drop_resize(Client *c, XRectangle *new)
static void static void
drop_moving(Client *c, XRectangle *new, XPoint * pt) drop_moving(Client *c, XRectangle *new, XPoint * pt)
{ {
Page *p = c->page;
Area *tgt = nil, *src = c->area; Area *tgt = nil, *src = c->area;
Page *p = src->page;
size_t i; size_t i;
if(!pt) if(!pt)
@ -209,8 +209,8 @@ resize_column(Client *c, XRectangle *r, XPoint *pt)
void void
select_column(Client *c, char *arg) select_column(Client *c, char *arg)
{ {
Page *p = c->page;
Area *col = c->area; Area *col = c->area;
Page *p = col->page;
size_t i; size_t i;
for(i = 0; (i < col->clientsz) && col->client[i] && (col->client[i] != c); i++); for(i = 0; (i < col->clientsz) && col->client[i] && (col->client[i] != c); i++);

View File

@ -68,7 +68,7 @@ handle_buttonpress(XEvent *e)
size_t i; size_t i;
for(i = 0; i < nlabel; i++) for(i = 0; i < nlabel; i++)
if(blitz_ispointinrect(ev->x, ev->y, &label[i]->rect)) { if(blitz_ispointinrect(ev->x, ev->y, &label[i]->rect)) {
snprintf(buf, sizeof(buf), "L%d B%d\n", i, ev->button); snprintf(buf, sizeof(buf), "LB %d %d\n", i + 1, ev->button);
do_pend_fcall(buf); do_pend_fcall(buf);
} }
} }
@ -107,8 +107,8 @@ handle_buttonpress(XEvent *e)
else if(ev->button == Button1) else if(ev->button == Button1)
focus_client(c); focus_client(c);
} }
if(c) { if(c && c->area) {
snprintf(buf, sizeof(buf), "Button%dPress\n", ev->button); snprintf(buf, sizeof(buf), "CB %d %d\n", client_to_index(c) + 1, ev->button);
do_pend_fcall(buf); do_pend_fcall(buf);
} }
} }
@ -126,7 +126,7 @@ handle_configurerequest(XEvent *e)
if(c) { if(c) {
if(c->page) { if(c->area) {
bw = c->frame.border; bw = c->frame.border;
bh = bar_height(c); bh = bar_height(c);
} }
@ -146,7 +146,7 @@ handle_configurerequest(XEvent *e)
gravitate(c, bh ? bh : bw, bw, 0); gravitate(c, bh ? bh : bw, bw, 0);
if(c->page) { if(c->area) {
c->frame.rect.x = wc.x = c->rect.x - bw; c->frame.rect.x = wc.x = c->rect.x - bw;
c->frame.rect.y = wc.y = c->rect.y - (bh ? bh : bw); c->frame.rect.y = wc.y = c->rect.y - (bh ? bh : bw);
c->frame.rect.width = wc.width = c->rect.width + 2 * bw; c->frame.rect.width = wc.width = c->rect.width + 2 * bw;
@ -161,7 +161,7 @@ handle_configurerequest(XEvent *e)
wc.x = ev->x; wc.x = ev->x;
wc.y = ev->y; wc.y = ev->y;
if(c && c->page) { if(c && c->area) {
/* if so, then bw and bh are already initialized */ /* if so, then bw and bh are already initialized */
wc.x = bw; wc.x = bw;
wc.y = (bh ? bh : bw); wc.y = (bh ? bh : bw);
@ -245,7 +245,7 @@ handle_maprequest(XEvent *e)
c = win_to_client(ev->window); c = win_to_client(ev->window);
if(!c) if(!c)
c = alloc_client(ev->window, &wa); c = alloc_client(ev->window, &wa);
if(!c->page) if(!c->area)
attach_client(c); attach_client(c);
} }

View File

@ -1112,7 +1112,7 @@ xwrite(IXPConn *c, Fcall *fcall)
return "increment value out of range 0, 1"; return "increment value out of range 0, 1";
def.inc = i; def.inc = i;
for(i = 0; i < nclient; i++) for(i = 0; i < nclient; i++)
if(client[i]->page) if(client[i]->area)
resize_client(client[i], &client[i]->frame.rect, 0); resize_client(client[i], &client[i]->frame.rect, 0);
break; break;
case Fgeom: case Fgeom:
@ -1175,7 +1175,7 @@ xwrite(IXPConn *c, Fcall *fcall)
def.selcolor[fcall->count] = 0; def.selcolor[fcall->count] = 0;
blitz_loadcolor(dpy, screen, def.selcolor, &def.sel); blitz_loadcolor(dpy, screen, def.selcolor, &def.sel);
for(i = 0; i < nclient; i++) for(i = 0; i < nclient; i++)
if(client[i]->page == page[sel]) if(client[i]->area->page == page[sel])
draw_client(client[i]); draw_client(client[i]);
break; break;
case Fnormcolors: case Fnormcolors:
@ -1189,7 +1189,7 @@ xwrite(IXPConn *c, Fcall *fcall)
def.normcolor[fcall->count] = 0; def.normcolor[fcall->count] = 0;
blitz_loadcolor(dpy, screen, def.normcolor, &def.norm); blitz_loadcolor(dpy, screen, def.normcolor, &def.norm);
for(i = 0; i < nclient; i++) for(i = 0; i < nclient; i++)
if(client[i]->page == page[sel]) if(client[i]->area->page == page[sel])
draw_client(client[i]); draw_client(client[i]);
break; break;
case Ffont: case Ffont:
@ -1200,7 +1200,7 @@ xwrite(IXPConn *c, Fcall *fcall)
XFreeFont(dpy, xfont); XFreeFont(dpy, xfont);
xfont = blitz_getfont(dpy, def.font); xfont = blitz_getfont(dpy, def.font);
for(i = 0; i < nclient; i++) { for(i = 0; i < nclient; i++) {
if(!client[i]->page) if(!client[i]->area->page)
continue; continue;
resize_client(client[i], &client[i]->frame.rect, 0); resize_client(client[i], &client[i]->frame.rect, 0);
} }

View File

@ -74,7 +74,7 @@ destroy_page(Page *p)
if(page[sel]) if(page[sel])
focus_page(page[sel]); focus_page(page[sel]);
else else
do_pend_fcall("NoPage\n"); do_pend_fcall("PN -\n");
} }
void void
@ -95,16 +95,16 @@ focus_page(Page *p)
sel = i; sel = i;
for(i = 0; i < nclient; i++) { for(i = 0; i < nclient; i++) {
c = client[i]; c = client[i];
if(old && (c->page == old)) if(old && (c->area && c->area->page == old))
XMoveWindow(dpy, c->frame.win, 2 * rect.width, 2 * rect.height); XMoveWindow(dpy, c->frame.win, 2 * rect.width, 2 * rect.height);
else if(c->page == p) { else if(c->area && c->area->page == p) {
XMoveWindow(dpy, c->frame.win, c->frame.rect.x, c->frame.rect.y); XMoveWindow(dpy, c->frame.win, c->frame.rect.x, c->frame.rect.y);
draw_client(c); draw_client(c);
} }
} }
if((c = sel_client_of_page(p))) if((c = sel_client_of_page(p)))
focus_client(c); focus_client(c);
snprintf(buf, sizeof(buf), "P %d\n", sel + 1); snprintf(buf, sizeof(buf), "PN %d\n", sel + 1);
do_pend_fcall(buf); do_pend_fcall(buf);
XChangeProperty(dpy, root, net_atoms[NET_CURRENT_DESKTOP], XA_CARDINAL, XChangeProperty(dpy, root, net_atoms[NET_CURRENT_DESKTOP], XA_CARDINAL,
32, PropModeReplace, (unsigned char *) &sel, 1); 32, PropModeReplace, (unsigned char *) &sel, 1);
@ -260,17 +260,17 @@ select_page(char *arg)
if(!npage || !arg) if(!npage || !arg)
return; return;
if(!strncmp(arg, "prev", 5)) { if(!strncmp(arg, "prev", 5)) {
if(new > 0) if(!new)
for(new = 0; page[new]; new++); new = npage;
new--; new--;
} else if(!strncmp(arg, "next", 5)) { } else if(!strncmp(arg, "next", 5)) {
if(page[new + 1]) if(new < npage - 1)
new++; new++;
else else
new = 0; new = 0;
} else { } else {
int idx = cext_strtonum(arg, 0, npage, &err); int idx = cext_strtonum(arg, 0, npage, &err);
if(idx < npage) if(idx && (idx - 1 < npage))
new = idx; new = idx;
} }
focus_page(page[new]); focus_page(page[new]);

View File

@ -62,6 +62,7 @@ typedef struct Client Client;
struct Area { struct Area {
unsigned short id; unsigned short id;
Client **client; Client **client;
Page *page;
size_t clientsz; size_t clientsz;
size_t sel; size_t sel;
size_t nclient; size_t nclient;
@ -84,7 +85,6 @@ struct Client {
unsigned int ignore_unmap; unsigned int ignore_unmap;
Bool destroyed; Bool destroyed;
Bool maximized; Bool maximized;
Page *page;
Area *area; Area *area;
Window win; Window win;
Window trans; Window trans;
@ -196,7 +196,7 @@ unsigned int valid_mask, num_lock_mask;
/* area.c */ /* area.c */
Area *alloc_area(Page *p); Area *alloc_area(Page *p);
void destroy_area(Area *a); void destroy_area(Area *a);
int area_to_index(Page *p, Area *a); int area_to_index(Area *a);
int aid_to_index(Page *p, unsigned short id); int aid_to_index(Page *p, unsigned short id);
/* bar.c */ /* bar.c */
@ -226,6 +226,7 @@ Client *win_to_frame(Window w);
void resize_client(Client *c, XRectangle * r, XPoint * pt); void resize_client(Client *c, XRectangle * r, XPoint * pt);
unsigned int bar_height(Client *c); unsigned int bar_height(Client *c);
int cid_to_index(Area *a, unsigned short id); int cid_to_index(Area *a, unsigned short id);
int client_to_index(Client *c);
/* event.c */ /* event.c */
void init_x_event_handler(); void init_x_event_handler();

View File

@ -10,12 +10,12 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
static char version[] = "wmiiplumb - " VERSION ", (C)opyright MMIV-MMVI Anselm R. Garbe\n"; static char version[] = "wmiipsel - " VERSION ", (C)opyright MMIV-MMVI Anselm R. Garbe\n";
static void static void
usage() usage()
{ {
fprintf(stderr, "%s\n", "usage: wmiiplumb [-v]\n"); fprintf(stderr, "%s\n", "usage: wmiipsel [-v]\n");
exit(1); exit(1);
} }
@ -59,7 +59,7 @@ main(int argc, char **argv)
} }
dpy = XOpenDisplay(0); dpy = XOpenDisplay(0);
if(!dpy) { if(!dpy) {
fprintf(stderr, "%s", "wmiiplumb: cannot open display\n"); fprintf(stderr, "%s", "wmiipsel: cannot open display\n");
exit(1); exit(1);
} }
xa_clip_string = XInternAtom(dpy, "PLUMB_STRING", False); xa_clip_string = XInternAtom(dpy, "PLUMB_STRING", False);

View File

@ -106,12 +106,29 @@ status &
# EVENT LOOP # EVENT LOOP
wmiir read /event | \ wmiir read /event | \
while(event=`{read}) { while(event=`{read}) {
if(~ $event(1) P) if(~ $event(1) PN)
xwrite /bar/1/data $event(2) xwrite /bar/1/data $event(2)
if(~ $event(1) C) { if(~ $event(1) CN) {
text=`{echo $"event | sed 's/^C //g'} text=`{echo $"event | sed 's/^CN //g'}
xwrite /bar/2/data $"text xwrite /bar/2/data $"text
} }
if(~ $event(1) LB) { # label button press
switch($event(3)) { # button
case 1
if(~ $event(2) 1) { # label
xwrite /ctl pager
}
if not {
xwrite /ctl 'select next'
}
case 3
xwrite /ctl 'select prev'
case 4
xwrite /ctl 'select next'
case 5
xwrite /ctl 'select prev'
}
}
if(~ $event(1) K) { # key press if(~ $event(1) K) { # key press
switch($event(2)) { switch($event(2)) {
case $MODKEY-Control-c case $MODKEY-Control-c