mirror of
https://github.com/0intro/wmii
synced 2024-12-24 04:16:50 +03:00
added button press event handling in wmiirc
This commit is contained in:
parent
63bcb2cd1f
commit
55ca4d6c23
@ -12,6 +12,7 @@ alloc_area(Page *p)
|
||||
{
|
||||
static unsigned short id = 1;
|
||||
Area *a = cext_emallocz(sizeof(Area));
|
||||
a->page = p;
|
||||
a->id = id++;
|
||||
p->area = (Area **)cext_array_attach((void **)p->area, a, sizeof(Area *), &p->areasz);
|
||||
p->narea++;
|
||||
@ -29,9 +30,10 @@ destroy_area(Area *a)
|
||||
}
|
||||
|
||||
int
|
||||
area_to_index(Page *p, Area *a)
|
||||
area_to_index(Area *a)
|
||||
{
|
||||
int i;
|
||||
Page *p = a->page;
|
||||
for(i = 0; i < p->narea; i++)
|
||||
if(p->area[i] == a)
|
||||
return i;
|
||||
|
@ -94,7 +94,7 @@ static void
|
||||
client_name_event(Client *c)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@ -106,9 +106,9 @@ focus_client(Client *c)
|
||||
Client *old = sel_client();
|
||||
|
||||
/* setup indexes */
|
||||
if(c->page != p) {
|
||||
focus_page(c->page);
|
||||
p = c->page;
|
||||
if(c->area->page != p) {
|
||||
focus_page(c->area->page);
|
||||
p = c->area->page;
|
||||
}
|
||||
for(i = 0; i < p->narea; i++) {
|
||||
Area *a = p->area[i];
|
||||
@ -167,7 +167,7 @@ configure_client(Client * c)
|
||||
e.window = c->win;
|
||||
e.x = c->rect.x;
|
||||
e.y = c->rect.y;
|
||||
if(c->page) {
|
||||
if(c->area) {
|
||||
e.x += c->frame.rect.x;
|
||||
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));
|
||||
free(name.value);
|
||||
}
|
||||
if(c->page)
|
||||
if(c->area)
|
||||
draw_client(c);
|
||||
client_name_event(c);
|
||||
break;
|
||||
@ -375,7 +375,6 @@ attach_client(Client *c)
|
||||
p = page[sel];
|
||||
|
||||
reparent_client(c, c->frame.win, c->rect.x, c->rect.y);
|
||||
c->page = p;
|
||||
|
||||
if(p->sel)
|
||||
attach_column(c);
|
||||
@ -384,6 +383,7 @@ attach_client(Client *c)
|
||||
a->client = (Client **)cext_array_attach((void **)a->client, c,
|
||||
sizeof(Client *), &a->clientsz);
|
||||
a->nclient++;
|
||||
c->area = a;
|
||||
}
|
||||
resize_client(c, &c->frame.rect, nil);
|
||||
map_client(c);
|
||||
@ -394,16 +394,16 @@ attach_client(Client *c)
|
||||
void
|
||||
detach_client(Client *c, Bool unmap)
|
||||
{
|
||||
if(c->page) {
|
||||
if(c->area) {
|
||||
size_t i;
|
||||
for(i = 0; i < nclient; i++)
|
||||
if(client[i]->revert == c)
|
||||
client[i]->revert = nil;
|
||||
|
||||
if(area_to_index(c->page, c->area) > 0)
|
||||
if(area_to_index(c->area) > 0)
|
||||
detach_column(c);
|
||||
else {
|
||||
Area *a = c->page->area[0];
|
||||
Area *a = c->area;
|
||||
cext_array_detach((void **)a->client, c, &a->clientsz);
|
||||
a->nclient--;
|
||||
if(!c->destroyed) {
|
||||
@ -419,7 +419,7 @@ detach_client(Client *c, Bool unmap)
|
||||
}
|
||||
}
|
||||
}
|
||||
c->page = nil;
|
||||
c->area = nil;
|
||||
if(c->revert)
|
||||
focus_client(c->revert);
|
||||
if(c->destroyed)
|
||||
@ -511,7 +511,7 @@ resize_client(Client *c, XRectangle *r, XPoint *pt)
|
||||
unsigned int bh = bar_height(c);
|
||||
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);
|
||||
else
|
||||
c->frame.rect = *r;
|
||||
@ -563,3 +563,13 @@ cid_to_index(Area *a, unsigned short id)
|
||||
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;
|
||||
}
|
||||
|
@ -81,8 +81,8 @@ update_column_width(Page *p)
|
||||
void
|
||||
detach_column(Client *c)
|
||||
{
|
||||
Page *p = c->page;
|
||||
Area *col = c->area;
|
||||
Page *p = col->page;
|
||||
|
||||
cext_array_detach((void **)col->client, c, &col->clientsz);
|
||||
if(!col->client[0]) {
|
||||
@ -111,8 +111,8 @@ match_horiz(Area *col, XRectangle *r)
|
||||
static void
|
||||
drop_resize(Client *c, XRectangle *new)
|
||||
{
|
||||
Page *p = c->page;
|
||||
Area *west = nil, *east = nil, *col = c->area;
|
||||
Page *p = col->page;
|
||||
Client *north = nil, *south = nil;
|
||||
size_t i;
|
||||
|
||||
@ -162,8 +162,8 @@ drop_resize(Client *c, XRectangle *new)
|
||||
static void
|
||||
drop_moving(Client *c, XRectangle *new, XPoint * pt)
|
||||
{
|
||||
Page *p = c->page;
|
||||
Area *tgt = nil, *src = c->area;
|
||||
Page *p = src->page;
|
||||
size_t i;
|
||||
|
||||
if(!pt)
|
||||
@ -209,8 +209,8 @@ resize_column(Client *c, XRectangle *r, XPoint *pt)
|
||||
void
|
||||
select_column(Client *c, char *arg)
|
||||
{
|
||||
Page *p = c->page;
|
||||
Area *col = c->area;
|
||||
Page *p = col->page;
|
||||
size_t i;
|
||||
|
||||
for(i = 0; (i < col->clientsz) && col->client[i] && (col->client[i] != c); i++);
|
||||
|
@ -68,7 +68,7 @@ handle_buttonpress(XEvent *e)
|
||||
size_t i;
|
||||
for(i = 0; i < nlabel; i++)
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -107,8 +107,8 @@ handle_buttonpress(XEvent *e)
|
||||
else if(ev->button == Button1)
|
||||
focus_client(c);
|
||||
}
|
||||
if(c) {
|
||||
snprintf(buf, sizeof(buf), "Button%dPress\n", ev->button);
|
||||
if(c && c->area) {
|
||||
snprintf(buf, sizeof(buf), "CB %d %d\n", client_to_index(c) + 1, ev->button);
|
||||
do_pend_fcall(buf);
|
||||
}
|
||||
}
|
||||
@ -126,7 +126,7 @@ handle_configurerequest(XEvent *e)
|
||||
|
||||
if(c) {
|
||||
|
||||
if(c->page) {
|
||||
if(c->area) {
|
||||
bw = c->frame.border;
|
||||
bh = bar_height(c);
|
||||
}
|
||||
@ -146,7 +146,7 @@ handle_configurerequest(XEvent *e)
|
||||
|
||||
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.y = wc.y = c->rect.y - (bh ? bh : 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.y = ev->y;
|
||||
if(c && c->page) {
|
||||
if(c && c->area) {
|
||||
/* if so, then bw and bh are already initialized */
|
||||
wc.x = bw;
|
||||
wc.y = (bh ? bh : bw);
|
||||
@ -245,7 +245,7 @@ handle_maprequest(XEvent *e)
|
||||
c = win_to_client(ev->window);
|
||||
if(!c)
|
||||
c = alloc_client(ev->window, &wa);
|
||||
if(!c->page)
|
||||
if(!c->area)
|
||||
attach_client(c);
|
||||
}
|
||||
|
||||
|
@ -1112,7 +1112,7 @@ xwrite(IXPConn *c, Fcall *fcall)
|
||||
return "increment value out of range 0, 1";
|
||||
def.inc = i;
|
||||
for(i = 0; i < nclient; i++)
|
||||
if(client[i]->page)
|
||||
if(client[i]->area)
|
||||
resize_client(client[i], &client[i]->frame.rect, 0);
|
||||
break;
|
||||
case Fgeom:
|
||||
@ -1175,7 +1175,7 @@ xwrite(IXPConn *c, Fcall *fcall)
|
||||
def.selcolor[fcall->count] = 0;
|
||||
blitz_loadcolor(dpy, screen, def.selcolor, &def.sel);
|
||||
for(i = 0; i < nclient; i++)
|
||||
if(client[i]->page == page[sel])
|
||||
if(client[i]->area->page == page[sel])
|
||||
draw_client(client[i]);
|
||||
break;
|
||||
case Fnormcolors:
|
||||
@ -1189,7 +1189,7 @@ xwrite(IXPConn *c, Fcall *fcall)
|
||||
def.normcolor[fcall->count] = 0;
|
||||
blitz_loadcolor(dpy, screen, def.normcolor, &def.norm);
|
||||
for(i = 0; i < nclient; i++)
|
||||
if(client[i]->page == page[sel])
|
||||
if(client[i]->area->page == page[sel])
|
||||
draw_client(client[i]);
|
||||
break;
|
||||
case Ffont:
|
||||
@ -1200,7 +1200,7 @@ xwrite(IXPConn *c, Fcall *fcall)
|
||||
XFreeFont(dpy, xfont);
|
||||
xfont = blitz_getfont(dpy, def.font);
|
||||
for(i = 0; i < nclient; i++) {
|
||||
if(!client[i]->page)
|
||||
if(!client[i]->area->page)
|
||||
continue;
|
||||
resize_client(client[i], &client[i]->frame.rect, 0);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ destroy_page(Page *p)
|
||||
if(page[sel])
|
||||
focus_page(page[sel]);
|
||||
else
|
||||
do_pend_fcall("NoPage\n");
|
||||
do_pend_fcall("PN -\n");
|
||||
}
|
||||
|
||||
void
|
||||
@ -95,16 +95,16 @@ focus_page(Page *p)
|
||||
sel = i;
|
||||
for(i = 0; i < nclient; 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);
|
||||
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);
|
||||
draw_client(c);
|
||||
}
|
||||
}
|
||||
if((c = sel_client_of_page(p)))
|
||||
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);
|
||||
XChangeProperty(dpy, root, net_atoms[NET_CURRENT_DESKTOP], XA_CARDINAL,
|
||||
32, PropModeReplace, (unsigned char *) &sel, 1);
|
||||
@ -260,17 +260,17 @@ select_page(char *arg)
|
||||
if(!npage || !arg)
|
||||
return;
|
||||
if(!strncmp(arg, "prev", 5)) {
|
||||
if(new > 0)
|
||||
for(new = 0; page[new]; new++);
|
||||
if(!new)
|
||||
new = npage;
|
||||
new--;
|
||||
} else if(!strncmp(arg, "next", 5)) {
|
||||
if(page[new + 1])
|
||||
if(new < npage - 1)
|
||||
new++;
|
||||
else
|
||||
new = 0;
|
||||
} else {
|
||||
int idx = cext_strtonum(arg, 0, npage, &err);
|
||||
if(idx < npage)
|
||||
if(idx && (idx - 1 < npage))
|
||||
new = idx;
|
||||
}
|
||||
focus_page(page[new]);
|
||||
|
@ -62,6 +62,7 @@ typedef struct Client Client;
|
||||
struct Area {
|
||||
unsigned short id;
|
||||
Client **client;
|
||||
Page *page;
|
||||
size_t clientsz;
|
||||
size_t sel;
|
||||
size_t nclient;
|
||||
@ -84,7 +85,6 @@ struct Client {
|
||||
unsigned int ignore_unmap;
|
||||
Bool destroyed;
|
||||
Bool maximized;
|
||||
Page *page;
|
||||
Area *area;
|
||||
Window win;
|
||||
Window trans;
|
||||
@ -196,7 +196,7 @@ unsigned int valid_mask, num_lock_mask;
|
||||
/* area.c */
|
||||
Area *alloc_area(Page *p);
|
||||
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);
|
||||
|
||||
/* bar.c */
|
||||
@ -226,6 +226,7 @@ Client *win_to_frame(Window w);
|
||||
void resize_client(Client *c, XRectangle * r, XPoint * pt);
|
||||
unsigned int bar_height(Client *c);
|
||||
int cid_to_index(Area *a, unsigned short id);
|
||||
int client_to_index(Client *c);
|
||||
|
||||
/* event.c */
|
||||
void init_x_event_handler();
|
||||
|
@ -10,12 +10,12 @@
|
||||
#include <X11/Xlib.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
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "%s\n", "usage: wmiiplumb [-v]\n");
|
||||
fprintf(stderr, "%s\n", "usage: wmiipsel [-v]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
dpy = XOpenDisplay(0);
|
||||
if(!dpy) {
|
||||
fprintf(stderr, "%s", "wmiiplumb: cannot open display\n");
|
||||
fprintf(stderr, "%s", "wmiipsel: cannot open display\n");
|
||||
exit(1);
|
||||
}
|
||||
xa_clip_string = XInternAtom(dpy, "PLUMB_STRING", False);
|
||||
|
23
rc/wmiirc
23
rc/wmiirc
@ -106,12 +106,29 @@ status &
|
||||
# EVENT LOOP
|
||||
wmiir read /event | \
|
||||
while(event=`{read}) {
|
||||
if(~ $event(1) P)
|
||||
if(~ $event(1) PN)
|
||||
xwrite /bar/1/data $event(2)
|
||||
if(~ $event(1) C) {
|
||||
text=`{echo $"event | sed 's/^C //g'}
|
||||
if(~ $event(1) CN) {
|
||||
text=`{echo $"event | sed 's/^CN //g'}
|
||||
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
|
||||
switch($event(2)) {
|
||||
case $MODKEY-Control-c
|
||||
|
Loading…
Reference in New Issue
Block a user