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

From: Kris Maglione <jg_AT_suckless.org>
Date: Mon Jan 21 08:36:27 2008

changeset: 2246:4b4844b25103
user: Kris Maglione <jg_AT_suckless.org>
date: Mon Jan 21 01:21:37 2008 -0500
summary: Make the bar Xdnd aware (so you can DND between views). Fixed some window raising/moving bugs.

diff -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/Makefile
--- a/cmd/wmii/Makefile Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/Makefile Mon Jan 21 01:21:37 2008 -0500
@@ -31,6 +31,7 @@ OBJ = area \
         printevent\
         utf \
         view \
+ xdnd \
         x11 \
         xext \
         ../util
diff -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/area.c
--- a/cmd/wmii/area.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/area.c Mon Jan 21 01:21:37 2008 -0500
@@ -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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/client.c
--- a/cmd/wmii/client.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/client.c Mon Jan 21 01:21:37 2008 -0500
@@ -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 @@ void
 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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/column.c
--- a/cmd/wmii/column.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/column.c Mon Jan 21 01:21:37 2008 -0500
@@ -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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/dat.h
--- a/cmd/wmii/dat.h Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/dat.h Mon Jan 21 01:21:37 2008 -0500
@@ -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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/event.c
--- a/cmd/wmii/event.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/event.c Mon Jan 21 01:21:37 2008 -0500
@@ -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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/ewmh.c
--- a/cmd/wmii/ewmh.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/ewmh.c Mon Jan 21 01:21:37 2008 -0500
@@ -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 *
                 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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/float.c
--- a/cmd/wmii/float.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/float.c Mon Jan 21 01:21:37 2008 -0500
@@ -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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/fns.h Mon Jan 21 01:21:37 2008 -0500
@@ -206,6 +206,10 @@ char* toutf8(const char*);
 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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/frame.c
--- a/cmd/wmii/frame.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/frame.c Mon Jan 21 01:21:37 2008 -0500
@@ -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:
+ focus(c, false);
                         mouse_resize(c, false, Center);
+ break;
+ case Button2:
+ frame_restack(f, nil);
+ view_restack(f->view);
                         focus(c, false);
- frame_restack(f, nil);
- focus(c, false); /* Blech */
                         break;
                 case Button3:
+ focus(c, false);
                         mouse_resize(c, false, quadrant(f->r, Pt(e->x_root, e->y_root)));
- frame_restack(f, nil);
- focus(c, false);
                         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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/fs.c
--- a/cmd/wmii/fs.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/fs.c Mon Jan 21 01:21:37 2008 -0500
@@ -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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/main.c
--- a/cmd/wmii/main.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/main.c Mon Jan 21 01:21:37 2008 -0500
@@ -465,6 +465,7 @@ main(int argc, char *argv[]) {
                                 | CWCursor);
                 bar_init(s);
         }
+ xdnd_init();
 
         screen->focus = nil;
         setfocus(screen->barwin, RevertToParent);
diff -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/message.c
--- a/cmd/wmii/message.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/message.c Mon Jan 21 01:21:37 2008 -0500
@@ -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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/mouse.c Mon Jan 21 01:21:37 2008 -0500
@@ -2,7 +2,6 @@
  * See LICENSE file for license details.
  */
 #include "dat.h"
-#include <assert.h>
 #include "fns.h"
 
 /* Here be dragons. */
diff -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/rule.c
--- a/cmd/wmii/rule.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/rule.c Mon Jan 21 01:21:37 2008 -0500
@@ -3,7 +3,6 @@
  */
 
 #include "dat.h"
-#include <assert.h>
 #include "fns.h"
 
 void
diff -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/x11.c
--- a/cmd/wmii/x11.c Sun Jan 20 19:10:40 2008 -0500
+++ b/cmd/wmii/x11.c Mon Jan 21 01:21:37 2008 -0500
@@ -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 @@ void
 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 -r 5c70ed7d56d3 -r 4b4844b25103 cmd/wmii/xdnd.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/wmii/xdnd.c Mon Jan 21 01:21:37 2008 -0500
@@ -0,0 +1,77 @@
+/* Copyright ©2008 Kris Maglione <fbsdaemon_AT_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 -r 5c70ed7d56d3 -r 4b4844b25103 include/x11.h
--- a/include/x11.h Sun Jan 20 19:10:40 2008 -0500
+++ b/include/x11.h Mon Jan 21 01:21:37 2008 -0500
@@ -228,7 +228,7 @@ Window* window(XWindow);
 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 -r 5c70ed7d56d3 -r 4b4844b25103 rc/rc.wmii.rc
--- a/rc/rc.wmii.rc Sun Jan 20 19:10:40 2008 -0500
+++ b/rc/rc.wmii.rc Mon Jan 21 01:21:37 2008 -0500
@@ -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
Received on Mon Jan 21 2008 - 08:36:27 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:59:04 UTC