wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 6adf15ff8ee336e0c3bd1eff8d2b0223813746c4
parent ed397a40d10023747bb4f7a553c886cfb0ce3374
Author: Kris Maglione <jg@suckless.org>
Date:   Mon, 21 Jan 2008 01:21:37 -0500

Make the bar Xdnd aware (so you can DND between views). Fixed some window raising/moving bugs.

Diffstat:
cmd/wmii/Makefile | 1+
cmd/wmii/area.c | 1-
cmd/wmii/client.c | 3+--
cmd/wmii/column.c | 1-
cmd/wmii/dat.h | 10++++++----
cmd/wmii/event.c | 5++++-
cmd/wmii/ewmh.c | 7+++----
cmd/wmii/float.c | 1+
cmd/wmii/fns.h | 4++++
cmd/wmii/frame.c | 19++++++++++++-------
cmd/wmii/fs.c | 1-
cmd/wmii/main.c | 1+
cmd/wmii/message.c | 2+-
cmd/wmii/mouse.c | 1-
cmd/wmii/rule.c | 1-
cmd/wmii/x11.c | 9+++++----
cmd/wmii/xdnd.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
include/x11.h | 2+-
rc/rc.wmii.rc | 2+-
19 files changed, 118 insertions(+), 30 deletions(-)

diff --git a/cmd/wmii/Makefile b/cmd/wmii/Makefile @@ -31,6 +31,7 @@ OBJ = area \ printevent\ utf \ view \ + xdnd \ x11 \ xext \ ../util diff --git a/cmd/wmii/area.c b/cmd/wmii/area.c @@ -2,7 +2,6 @@ * See LICENSE file for license details. */ #include "dat.h" -#include <assert.h> #include <math.h> #include <limits.h> #include "fns.h" diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c @@ -3,7 +3,6 @@ * See LICENSE file for license details. */ #include "dat.h" -#include <assert.h> #include <ctype.h> #include <X11/Xatom.h> #include "fns.h" @@ -535,7 +534,7 @@ client_configure(Client *c) { void client_kill(Client *c, bool nice) { if(nice && (c->proto & ProtoDelete)) { - sendmessage(&c->w, "WM_PROTOCOLS", "WM_DELETE_WINDOW", 0, 0, 0); + sendmessage(&c->w, "WM_PROTOCOLS", xatom("WM_DELETE_WINDOW"), xtime, 0, 0, 0); ewmh_pingclient(c); } else diff --git a/cmd/wmii/column.c b/cmd/wmii/column.c @@ -3,7 +3,6 @@ * See LICENSE file for license details. */ #include "dat.h" -#include <assert.h> #include <math.h> #include <strings.h> #include "fns.h" diff --git a/cmd/wmii/dat.h b/cmd/wmii/dat.h @@ -5,6 +5,7 @@ #define _XOPEN_SOURCE 600 #define IXP_P9_STRUCTS #define IXP_NO_P9_ +#include <assert.h> #include <regexp9.h> #include <stdbool.h> #include <stdint.h> @@ -74,10 +75,11 @@ enum Protocols { }; enum DebugOpt { - DEvent = 1<<0, - DEwmh = 1<<1, - DFocus = 1<<2, - DGeneric= 1<<3, + DDnd = 1<<0, + DEvent = 1<<1, + DEwmh = 1<<2, + DFocus = 1<<3, + DGeneric= 1<<4, }; /* Data Structures */ diff --git a/cmd/wmii/event.c b/cmd/wmii/event.c @@ -111,7 +111,10 @@ clientmessage(XEvent *e) { XClientMessageEvent *ev; ev = &e->xclient; - ewmh_clientmessage(ev); + if(ewmh_clientmessage(ev)) + return; + if(xdnd_clientmessage(ev)) + return; } static void diff --git a/cmd/wmii/ewmh.c b/cmd/wmii/ewmh.c @@ -2,7 +2,6 @@ * See LICENSE file for license details. */ #include "dat.h" -#include <assert.h> #include <limits.h> #include "fns.h" @@ -152,7 +151,7 @@ ewmh_pingclient(Client *c) { if(e->ping) return; - sendmessage(&c->w, "WM_PROTOCOLS", Net("WM_PING"), c->w.w, 0, 0); + sendmessage(&c->w, "WM_PROTOCOLS", NET("WM_PING"), xtime, c->w.w, 0, 0); e->ping = xtime++; e->timer = ixp_settimer(&srv, PingTime, pingtimeout, c); } @@ -354,10 +353,10 @@ ewmh_clientmessage(XClientMessageEvent *e) { return 1; }else if(msg == xatom("WM_PROTOCOLS")) { + if(e->format != 32) + return 0; Dprint(DEwmh, "\t%A\n", l[0]); if(l[0] == NET("WM_PING")) { - if(e->format != 32) - return -1; if(e->window != scr.root.w) return -1; c = win2client(l[2]); diff --git a/cmd/wmii/float.c b/cmd/wmii/float.c @@ -28,6 +28,7 @@ float_detach(Frame *f) { v = f->view; a = f->area; sel = view_findarea(v, v->selcol, false); + assert(sel); pr = f->aprev; frame_remove(f); diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h @@ -206,6 +206,10 @@ Rectangle* view_rects(View*, uint *num, Frame *ignore); char* toutf8(const char*); char* toutf8n(const char*, size_t); +/* xdnd.c */ +int xdnd_clientmessage(XClientMessageEvent*); +void xdnd_init(void); + /* xext.c */ void randr_event(XEvent*); void randr_init(void); diff --git a/cmd/wmii/frame.c b/cmd/wmii/frame.c @@ -83,6 +83,7 @@ frame_insert(Frame *f, Frame *pos) { f->anext->aprev = f; if(a->floating) { + assert(f->sprev == nil); f->snext = a->stack; a->stack = f; if(f->snext) @@ -97,7 +98,7 @@ frame_restack(Frame *f, Frame *above) { a = f->area; if(!a->floating) return false; - if(above && above->area != a) + if(f->sprev == above) return false; if(f->sprev) @@ -139,15 +140,17 @@ bdown_event(Window *w, XButtonEvent *e) { if((e->state & def.mod) == def.mod) { switch(e->button) { case Button1: - mouse_resize(c, false, Center); focus(c, false); + mouse_resize(c, false, Center); + break; + case Button2: frame_restack(f, nil); - focus(c, false); /* Blech */ + view_restack(f->view); + focus(c, false); break; case Button3: - mouse_resize(c, false, quadrant(f->r, Pt(e->x_root, e->y_root))); - frame_restack(f, nil); focus(c, false); + mouse_resize(c, false, quadrant(f->r, Pt(e->x_root, e->y_root))); break; default: XAllowEvents(display, ReplayPointer, e->time); @@ -157,9 +160,11 @@ bdown_event(Window *w, XButtonEvent *e) { XUngrabPointer(display, e->time); }else{ if(e->button == Button1) { - if(frame_restack(f, nil)) + if(!e->subwindow) { + frame_restack(f, nil); view_restack(f->view); - else if(rect_haspoint_p(Pt(e->x, e->y), f->grabbox)) + } + if(rect_haspoint_p(Pt(e->x, e->y), f->grabbox)) mouse_resize(c, true, Center); else if(f->area->floating) if(!e->subwindow && !rect_haspoint_p(Pt(e->x, e->y), f->titlebar)) diff --git a/cmd/wmii/fs.c b/cmd/wmii/fs.c @@ -2,7 +2,6 @@ * See LICENSE file for license details. */ #include "dat.h" -#include <assert.h> #include <ctype.h> #include <stdarg.h> #include <time.h> diff --git a/cmd/wmii/main.c b/cmd/wmii/main.c @@ -465,6 +465,7 @@ main(int argc, char *argv[]) { | CWCursor); bar_init(s); } + xdnd_init(); screen->focus = nil; setfocus(screen->barwin, RevertToParent); diff --git a/cmd/wmii/message.c b/cmd/wmii/message.c @@ -2,7 +2,6 @@ * See LICENSE file for license details. */ #include "dat.h" -#include <assert.h> #include <ctype.h> #include "fns.h" @@ -76,6 +75,7 @@ char *symtab[] = { }; char *debugtab[] = { + "dnd", "event", "ewmh", "focus", diff --git a/cmd/wmii/mouse.c b/cmd/wmii/mouse.c @@ -2,7 +2,6 @@ * See LICENSE file for license details. */ #include "dat.h" -#include <assert.h> #include "fns.h" /* Here be dragons. */ diff --git a/cmd/wmii/rule.c b/cmd/wmii/rule.c @@ -3,7 +3,6 @@ */ #include "dat.h" -#include <assert.h> #include "fns.h" void diff --git a/cmd/wmii/x11.c b/cmd/wmii/x11.c @@ -6,7 +6,6 @@ #define ZR _ZR #define pointerwin __pointerwin #include "dat.h" -#include <assert.h> #include <math.h> #include <unistd.h> #include <bio.h> @@ -149,6 +148,8 @@ Wfmt(Fmt *f) { void initdisplay(void) { display = XOpenDisplay(nil); + if(display == nil) + fatal("Can't open display"); scr.screen = DefaultScreen(display); scr.colormap = DefaultColormap(display, scr.screen); scr.visual = DefaultVisual(display, scr.screen); @@ -601,15 +602,15 @@ xatom(char *name) { } void -sendmessage(Window *w, char *name, char *value, long l2, long l3, long l4) { +sendmessage(Window *w, char *name, long l0, long l1, long l2, long l3, long l4) { XClientMessageEvent e; e.type = ClientMessage; e.window = w->w; e.message_type = xatom(name); e.format = 32; - e.data.l[0] = xatom(value); - e.data.l[1] = xtime; + e.data.l[0] = l0; + e.data.l[1] = l1; e.data.l[2] = l2; e.data.l[3] = l3; e.data.l[4] = l4; diff --git a/cmd/wmii/xdnd.c b/cmd/wmii/xdnd.c @@ -0,0 +1,77 @@ +/* Copyright ©2008 Kris Maglione <fbsdaemon@gmail.com> + * See LICENSE file for license details. + */ +#include "dat.h" +#include "fns.h" + +void +xdnd_init(void) { + long l; + + l = 3; /* They are insane. Why is this an ATOM?! */ + changeprop_long(screen->barwin, "XdndAware", "ATOM", &l, 1); +} + +int +xdnd_clientmessage(XClientMessageEvent *e) { + static Bar *oldbar; + Rectangle r; + Point p; + long *l; + Bar *b; + long pos, siz; + int msg; + + msg = e->message_type; + l = e->data.l; + Dprint(DDnd, "ClientMessage: %A\n", msg); + + if(msg == xatom("XdndEnter")) { + if(e->format != 32) + return -1; + oldbar = nil; + return 1; + }else + if(msg == xatom("XdndLeave")) { + if(e->format != 32) + return -1; + oldbar = nil; + return 1; + }else + if(msg == xatom("XdndPosition")) { + if(e->format != 32) + return -1; + p.x = (ulong)l[2] >> 16; + p.y = (ulong)l[2] & 0xffff; + p = subpt(p, screen->barwin->r.min); + Dprint(DDnd, "\tp: %P\n", p); + /* XXX: This should be done in bar.c. */ + for(b=screen->bar[BarLeft]; b; b=b->next) + if(rect_haspoint_p(p, b->r)) { + if(b != oldbar) + event("LeftBarDND 1 %s\n", b->name); + break; + } + if(b == nil) + for(b=screen->bar[BarRight]; b; b=b->next) + if(rect_haspoint_p(p, b->r)) { + if(b != oldbar) + event("RightBarDND 1 %s\n", b->name); + break; + } + pos = 0; + siz = 0; + oldbar = b; + if(b) { + r = rectaddpt(b->r, screen->barwin->r.min); + Dprint(DDnd, "\tr: %R\n", r); + pos = (r.min.x<<16) | r.min.y; + siz = (Dx(r)<<16) | Dy(r); + } + sendmessage(window(l[0]), "XdndStatus", e->window, 0, pos, siz, 0); + return 1; + } + + return 0; +} + diff --git a/include/x11.h b/include/x11.h @@ -228,7 +228,7 @@ void warppointer(Point); Window* window(XWindow); long winprotocols(Window*); Atom xatom(char*); -void sendmessage(Window*, char*, char*, long, long, long); +void sendmessage(Window*, char*, long, long, long, long, long); XRectangle XRect(Rectangle); Rectangle gravitate(Rectangle dst, Rectangle src, Point grav); Rectangle insetrect(Rectangle, int); diff --git a/rc/rc.wmii.rc b/rc/rc.wmii.rc @@ -92,7 +92,7 @@ fn Event-Notice { { sleep $noticetimeout; wmiir xwrite $noticebar ' ' }& # Bug... xpid = $apid} -fn Event-LeftBarClick { +fn Event-LeftBar^(Click DND) { shift; wmiir xwrite /ctl view $*} fn Event-ClientMouseDown { client = $1; button = $2