From 88ae3e3606dda34ebdea8ebc2a82fca97e953fda Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Thu, 16 Feb 2006 01:05:16 +0100 Subject: [PATCH] removed spawn.c, removed wmiiwarp.c (instead use warp action on /ctl), spawning is not necessary, remove exec on page heuristic (too crappy, instead I'll use class hints again, they are at least more reliable) --- Makefile | 3 +-- cmd/Makefile | 5 +--- cmd/wm/Makefile | 3 +-- cmd/wm/client.c | 5 +++- cmd/wm/event.c | 6 ----- cmd/wm/fs.c | 9 +++---- cmd/wm/mouse.c | 23 ++++++++++++++++++ cmd/wm/page.c | 39 +++++++++--------------------- cmd/wm/spawn.c | 27 --------------------- cmd/wm/wm.c | 3 +-- cmd/wm/wm.h | 4 ++-- cmd/wmiiwarp.c | 64 ------------------------------------------------- rc/wmiirc | 2 ++ 13 files changed, 51 insertions(+), 142 deletions(-) delete mode 100644 cmd/wm/spawn.c delete mode 100644 cmd/wmiiwarp.c diff --git a/Makefile b/Makefile index 84ac0b7b..935a091b 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,7 @@ include config.mk SUBDIRS = libcext liblitz libixp cmd -BIN = cmd/wm/wmii cmd/wm/wmiiwm cmd/wmiimenu \ - cmd/wmiipsel cmd/wmiir cmd/wmiiwarp +BIN = cmd/wm/wmii cmd/wm/wmiiwm cmd/wmiimenu cmd/wmiipsel cmd/wmiir MAN1 = cmd/wm/wmii.1 cmd/wm/wmiiwm.1 \ cmd/wmiimenu.1 cmd/wmiir.1 diff --git a/cmd/Makefile b/cmd/Makefile index 01bda9a8..d296acc5 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -15,10 +15,7 @@ OBJ_r = ${SRC_r:.c=.o} SRC_psel = wmiipsel.c OBJ_psel = ${SRC_psel:.c=.o} -SRC_warp = wmiiwarp.c -OBJ_warp = ${SRC_warp:.c=.o} - -all: wmiimenu wmiir wmiipsel wmiiwarp +all: wmiimenu wmiir wmiipsel @echo built wmii commands .c.o: diff --git a/cmd/wm/Makefile b/cmd/wm/Makefile index e7151486..d862946a 100644 --- a/cmd/wm/Makefile +++ b/cmd/wm/Makefile @@ -9,8 +9,7 @@ LDFLAGS += -L../../liblitz -llitz -L../../libixp -lixp -L../../libcext -lcext # Solaris # LDFLAGS += -lsocket -SRC = area.c bar.c fs.c wm.c kb.c client.c event.c mouse.c page.c\ - column.c spawn.c +SRC = area.c bar.c fs.c wm.c kb.c client.c event.c mouse.c page.c column.c OBJ = ${SRC:.c=.o} all: wmiiwm diff --git a/cmd/wm/client.c b/cmd/wm/client.c index d651c1d5..f472d806 100644 --- a/cmd/wm/client.c +++ b/cmd/wm/client.c @@ -369,6 +369,7 @@ void attach_client(Client *c) { Page *p; + char buf[32]; if(!page) p = alloc_page(); else @@ -389,6 +390,9 @@ attach_client(Client *c) map_client(c); XMapWindow(dpy, c->frame.win); focus_client(c); + snprintf(buf, sizeof(buf), "CA %d %d %d %d\n", c->frame.rect.x, c->frame.rect.y, + c->frame.rect.width, c->frame.rect.height); + broadcast_event(buf); } void @@ -574,7 +578,6 @@ client_to_index(Client *c) return -1; } - void select_client(Client *c, char *arg) { diff --git a/cmd/wm/event.c b/cmd/wm/event.c index 5c3cff78..3302bbb7 100644 --- a/cmd/wm/event.c +++ b/cmd/wm/event.c @@ -242,12 +242,6 @@ handle_maprequest(XEvent *e) return; } - /* attach heuristic support */ - if(aqsz && aq[0]) { - focus_page(0); - cext_array_detach((void **)aq, aq[0], &aqsz); - } - /* there're client which send map requests twice */ c = win_to_client(ev->window); if(!c) diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c index f3d6a8dc..7360298b 100644 --- a/cmd/wm/fs.c +++ b/cmd/wm/fs.c @@ -1064,14 +1064,15 @@ xwrite(IXPConn *c, Fcall *fcall) attach_detached_client(); else if(!strncmp(buf, "select", 6)) select_page(&buf[7]); + else if(!strncmp(buf, "warp ", 5)) { + char *err; + if((err = warp_mouse(&buf[5]))) + return err; + } else return Enocommand; break; case Dpage: - if(!strncmp(buf, "exec ", 5)) { - aq = (Page **)cext_array_attach((void **)aq, page[i1], sizeof(Page *), &aqsz); - spawn(&buf[5]); - } break; case Darea: if(!strncmp(buf, "select ", 7)) { diff --git a/cmd/wm/mouse.c b/cmd/wm/mouse.c index 94ef613f..19475015 100644 --- a/cmd/wm/mouse.c +++ b/cmd/wm/mouse.c @@ -4,6 +4,7 @@ */ #include +#include #include #include "wm.h" @@ -625,3 +626,25 @@ ungrab_mouse(Window w, unsigned long mod, unsigned int button) XUngrabButton(dpy, button, mod | num_lock_mask | LockMask, w); } } + +char * +warp_mouse(char *arg) +{ + const char *errstr; + char *sx = arg, *sy; + unsigned int x, y; + sy = strchr(sx, ' '); + if(!sy) + return "invalid argument"; + *sy = 0; + sy++; + x = cext_strtonum(sx, 0, rect.width, &errstr); + if(errstr) + return "invalid x argument"; + y = cext_strtonum(sy, 0, rect.height, &errstr); + if(errstr) + return "invalid y argument"; + XWarpPointer(dpy, None, root, 0, 0, 0, 0, x, y); + XSync(dpy, False); + return nil; +} diff --git a/cmd/wm/page.c b/cmd/wm/page.c index 3c2dbe52..6725c08a 100644 --- a/cmd/wm/page.c +++ b/cmd/wm/page.c @@ -10,20 +10,6 @@ #include "wm.h" -/* -static void select_client(void *obj, char *arg); -static void xexec(void *obj, char *arg); -*/ - -/* action table for /?/ namespace */ -/* -Action page_acttbl[] = { - {"swap", swap_client}, - {"select", select_client}, - {0, 0} -}; -*/ - Page * alloc_page() { @@ -44,14 +30,6 @@ void destroy_page(Page *p) { unsigned int i; - size_t naqueue = 0; - - for(i = 0; (i < aqsz) && aq[i]; i++) - if(aq[i] == p) - naqueue++; - for(i = 0; i < naqueue; i++) - cext_array_detach((void **)aq, p, &aqsz); - for(i = 0; i < p->narea; i++) destroy_area(p->area[i]); free(p->area); @@ -61,12 +39,15 @@ destroy_page(Page *p) cext_array_detach((void **)page, p, &pagesz); npage--; + + for(i = 0; i < npage; i++) { + if(page[i]->revert == p) + page[i]->revert = nil; + XChangeProperty(dpy, root, net_atoms[NET_NUMBER_OF_DESKTOPS], XA_CARDINAL, + 32, PropModeReplace, (unsigned char *) &i, 1); + } + free(p); - - for(i = 0; i < npage; i++); - XChangeProperty(dpy, root, net_atoms[NET_NUMBER_OF_DESKTOPS], XA_CARDINAL, - 32, PropModeReplace, (unsigned char *) &i, 1); - if(npage) focus_page(page[sel]); else @@ -96,6 +77,9 @@ focus_page(Page *p) return; } + if(sel == i) + return; + page[i]->revert = page[sel]; sel = i; for(i = 0; i < nclient; i++) { c = client[i]; @@ -179,4 +163,3 @@ select_page(char *arg) } focus_page(page[new]); } - diff --git a/cmd/wm/spawn.c b/cmd/wm/spawn.c deleted file mode 100644 index 999680af..00000000 --- a/cmd/wm/spawn.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * (C)opyright MMIV-MMVI Anselm R. Garbe - * See LICENSE file for license details. - */ - -#include -#include -#include -#include - -#include "wm.h" - -void -spawn(char *cmd) -{ - if(fork() == 0) { - if(fork() == 0) { - setsid(); - close(ConnectionNumber(dpy)); - execlp("rc", "rc", "-c", cmd, (char *) 0); - perror("failed"); - exit(1); - } - exit(0); - } - wait(0); -} diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c index 33c0f425..b9c436e5 100644 --- a/cmd/wm/wm.c +++ b/cmd/wm/wm.c @@ -629,10 +629,9 @@ main(int argc, char *argv[]) ixp_server_open_conn(&srv, ConnectionNumber(dpy), check_x_event, nil); init_x_event_handler(); - ndet = npage = nclient = aqsz = detsz = pagesz = clientsz = sel = 0; + ndet = npage = nclient = detsz = pagesz = clientsz = sel = 0; page = nil; client = det = nil; - aq = nil; key = nil; keysz = nkey = 0; diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h index 1ccd1ab4..e41da09f 100644 --- a/cmd/wm/wm.h +++ b/cmd/wm/wm.h @@ -75,6 +75,7 @@ struct Page { size_t areasz; size_t narea; size_t sel; + Page *revert; }; struct Client { @@ -137,8 +138,6 @@ Page **page; size_t npage; size_t pagesz; size_t sel; -Page **aq; -size_t aqsz; Client **det; size_t ndet; size_t detsz; @@ -258,6 +257,7 @@ Align xy_to_align(XRectangle * rect, int x, int y); void drop_move(Client *c, XRectangle *new, XPoint *pt); void grab_mouse(Window w, unsigned long mod, unsigned int button); void ungrab_mouse(Window w, unsigned long mod, unsigned int button); +char *warp_mouse(char *arg); /* page.c */ Page *alloc_page(); diff --git a/cmd/wmiiwarp.c b/cmd/wmiiwarp.c deleted file mode 100644 index 96ada3ce..00000000 --- a/cmd/wmiiwarp.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * (C)opyright MMIV-MMVI Anselm R. Garbe - * See LICENSE file for license details. - */ - -#include -#include -#include - -#include -#include -#include - -#include "cext.h" - -static char version[] = "wmiiwarp - " VERSION ", (C)opyright MMIV-MMVI Anselm R. Garbe\n"; - -static void -usage() -{ - fprintf(stderr, "%s", "usage: wmiiwarp [-v]\n"); - exit(1); -} - -int -main(int argc, char **argv) -{ - Display *dpy; - int x, y; - const char *errstr; - - /* command line args */ - if(argc < 2) - usage(); - if(!strncmp(argv[1], "-v", 2)) { - fprintf(stdout, "%s", version); - exit(0); - } - dpy = XOpenDisplay(0); - if(!dpy) { - fprintf(stderr, "%s", "wmiiwarp: cannot open display\n"); - exit(1); - } - if((argc == 2) && !strncmp(argv[1], "center", 7)) { - x = DisplayWidth(dpy, DefaultScreen(dpy)) / 2; - y = DisplayHeight(dpy, DefaultScreen(dpy)) / 2; - } else if(argc == 3) { - x = cext_strtonum(argv[1], 0, DisplayWidth(dpy, DefaultScreen(dpy)), &errstr); - if(errstr) { - fprintf(stderr, "wmiiwarp: invalid x value: '%s'\n", errstr); - usage(); - } - y = cext_strtonum(argv[2], 0, DisplayHeight(dpy, DefaultScreen(dpy)), &errstr); - if(errstr) { - fprintf(stderr, "wmiiwarp: invalid y value: '%s'\n", errstr); - usage(); - } - } - XWarpPointer(dpy, None, RootWindow(dpy, DefaultScreen(dpy)), - 0, 0, 0, 0, x, y); - XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); - XCloseDisplay(dpy); - return 0; -} diff --git a/rc/wmiirc b/rc/wmiirc index 3e060ad0..c61e18c3 100755 --- a/rc/wmiirc +++ b/rc/wmiirc @@ -112,6 +112,8 @@ while(event=`{read}) { text=`{echo $"event | sed 's/^CN //g'} xwrite /bar/2/data $"text } + if(~ $event(1) CA) + xwrite /ctl 'warp '^`{echo $event(2) + 10 | bc}^' '^`{echo $event(3) + 10 | bc} if(~ $event(1) LB) { # label button press switch($event(3)) { # button case 1