[hackers] [wmii] Added support for the MWM borderless hint, since apps seem to break without it.

From: Kris Maglione <jg_AT_suckless.org>
Date: Fri, 01 Jun 2007 01:09:49 -0000

changeset: 2105:2205ca9eb791
user: Kris Maglione <jg_AT_suckless.org>
date: Sat Apr 21 01:13:40 2007 -0400
summary: Added support for the MWM borderless hint, since apps seem to break without it.

diff -r 0854dc582fba -r 2205ca9eb791 cmd/wmii/client.c
--- a/cmd/wmii/client.c Fri Apr 20 19:35:46 2007 -0400
+++ b/cmd/wmii/client.c Sat Apr 21 01:13:40 2007 -0400
@@ -48,6 +48,7 @@ create_client(XWindow w, XWindowAttribut
         prop_client(c, xatom("WM_NORMAL_HINTS"));
         prop_client(c, xatom("WM_HINTS"));
         prop_client(c, xatom("WM_NAME"));
+ prop_client(c, xatom("_MOTIF_WM_HINTS"));
 
         XSetWindowBorderWidth(display, w, 0);
         XAddToSaveSet(display, w);
@@ -80,6 +81,7 @@ create_client(XWindow w, XWindowAttribut
                 }
 
         write_event("CreateClient 0x%x\n", c->w.w);
+ manage_client(c);
         return c;
 }
 
@@ -95,7 +97,7 @@ gravclient(Client *c, Rectangle rd) {
         WinHints *h;
 
         h = c->w.hints;
- r = client2frame(nil, c->w.r);
+ r = client2frame(c->sel, c->w.r);
         sp = Pt(def.border, labelh(def.font));
 
         if(eqrect(rd, ZR)) {
@@ -164,6 +166,7 @@ destroy_client(Client *c) {
 
 void
 manage_client(Client *c) {
+ Rectangle r;
         Client *trans;
         char *tags;
 
@@ -176,7 +179,6 @@ manage_client(Client *c) {
 
         free(tags);
 
- gravclient(c, c->w.r);
         reparent_client(c, c->framewin, Pt(def.border, labelh(def.font)));
 
         if(!strlen(c->tags))
@@ -184,9 +186,14 @@ manage_client(Client *c) {
         else
                 apply_tags(c, c->tags);
 
+ r = gravclient(c, c->w.r);
+ if(c->sel->area->floating)
+ resize_client(c, &r);
+ else
+ c->sel->revert = r;
+
         if(!starting)
                 update_views();
- XSync(display, False);
 
         if(c->sel->view == screen->sel)
                 focus(c, True);
@@ -527,6 +534,44 @@ set_urgent(Client *c, Bool urgent, Bool
         }
 }
 
+static void
+updatemwm(Client *c) {
+ enum {
+ All = 1<<0,
+ Border = 1<<1,
+ Title = 1<<3,
+ };
+ Rectangle r;
+ ulong *ret, decor;
+ Atom real;
+ int n;
+
+ decor = 0;
+ n = getproperty(&c->w, "_MOTIF_WM_HINTS", "_MOTIF_WM_HINTS", &real,
+ 2L, (uchar**)&ret, 1L);
+ if(n == 0) {
+ c->borderless = 0;
+ c->titleless = 0;
+ }else {
+ decor = *ret;
+ free(ret);
+
+ if(c->sel)
+ r = frame2client(c->sel, c->sel->r);
+
+ if(decor&All)
+ decor ^= ~0;
+ c->borderless = ((decor&Border)==0);
+ c->titleless = ((decor&Title)==0);
+
+ if(c->sel) {
+ r = client2frame(c->sel, c->sel->r);
+ resize_client(c, &r);
+ draw_frame(c->sel);
+ }
+ }
+}
+
 void
 prop_client(Client *c, Atom a) {
         XWMHints *wmh;
@@ -535,6 +580,8 @@ prop_client(Client *c, Atom a) {
                 c->proto = winprotocols(&c->w);
         else if(a == xatom("_NET_WM_NAME"))
                 goto wmname;
+ else if(a == xatom("_MOTIF_WM_HINTS"))
+ updatemwm(c);
         else switch (a) {
         case XA_WM_TRANSIENT_FOR:
                 XGetTransientForHint(display, c->w.w, &c->trans);
diff -r 0854dc582fba -r 2205ca9eb791 cmd/wmii/dat.h
--- a/cmd/wmii/dat.h Fri Apr 20 19:35:46 2007 -0400
+++ b/cmd/wmii/dat.h Sat Apr 21 01:13:40 2007 -0400
@@ -128,6 +128,8 @@ struct Client {
         Bool fixedsize;
         Bool fullscreen;
         Bool urgent;
+ Bool borderless;
+ Bool titleless;
         int unmapped;
         Window w;
         XWindow trans;
diff -r 0854dc582fba -r 2205ca9eb791 cmd/wmii/event.c
--- a/cmd/wmii/event.c Fri Apr 20 19:35:46 2007 -0400
+++ b/cmd/wmii/event.c Sat Apr 21 01:13:40 2007 -0400
@@ -260,7 +260,7 @@ maprequest(XEvent *e) {
                 return;
         }
         if(!win2client(ev->window))
- manage_client(create_client(ev->window, &wa));
+ create_client(ev->window, &wa);
 }
 
 static void
diff -r 0854dc582fba -r 2205ca9eb791 cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Fri Apr 20 19:35:46 2007 -0400
+++ b/cmd/wmii/fns.h Sat Apr 21 01:13:40 2007 -0400
@@ -197,6 +197,7 @@ uint labelh(Font*);
 uint labelh(Font*);
 Atom xatom(char*);
 void freestringlist(char**);
+ulong getproperty(Window *w, char *prop, char *type, Atom *actual, ulong offset, uchar **ret, ulong length);
 char *gettextproperty(Window*, char*);
 int gettextlistproperty(Window *w, char *name, char **ret[]);
 void changeproperty(Window*, char *prop, char *type, int width, uchar *data, int n);
diff -r 0854dc582fba -r 2205ca9eb791 cmd/wmii/frame.c
--- a/cmd/wmii/frame.c Fri Apr 20 19:35:46 2007 -0400
+++ b/cmd/wmii/frame.c Sat Apr 21 01:13:40 2007 -0400
@@ -23,9 +23,7 @@ create_frame(Client *c, View *v) {
         }
         else{
                 c->sel = f;
- f->r = c->r;
- f->r.max.x += 2 * def.border;
- f->r.max.y += frame_delta_h();
+ f->r = client2frame(f, c->w.r);
                 f->revert = f->r;
         }
         f->collapsed = False;
@@ -94,42 +92,17 @@ frame_to_top(Frame *f) {
                 return False;
 
         if(f->sprev)
- f->sprev = f->snext;
+ f->sprev->snext = f->snext;
         if(f->snext)
- f->snext = f->sprev;
+ f->snext->sprev = f->sprev;
 
         f->snext = a->stack;
         a->stack = f;
+ f->sprev = nil;
         if(f->snext)
                 f->snext->sprev = f;
 
         return True;
-}
-
-Rectangle
-frame2client(Frame *f, Rectangle r) {
- if(f == nil || f->area->floating) {
- r.max.x -= def.border * 2;
- r.max.y -= frame_delta_h();
- }else {
- r.max.x -= 2;
- r.max.y -= labelh(def.font) + 1;
- }
- r.max.x = max(r.min.x+1, r.max.x);
- r.max.y = max(r.min.y+1, r.max.y);
- return r;
-}
-
-Rectangle
-client2frame(Frame *f, Rectangle r) {
- if(f == nil || f->area->floating) {
- r.max.x += def.border * 2;
- r.max.y += frame_delta_h();
- }else {
- r.max.x += 2;
- r.max.y += labelh(def.font) + 1;
- }
- return r;
 }
 
 /* Handlers */
@@ -232,6 +205,48 @@ Handlers framehandler = {
         .motion = motion_event,
 };
 
+Rectangle
+frame2client(Frame *f, Rectangle r) {
+ if(f == nil || f->area == nil || f->area->floating) {
+ r.max.x -= def.border * 2;
+ r.max.y -= frame_delta_h();
+ if(f) {
+ if(f->client->borderless) {
+ r.max.x += 2 * def.border;
+ r.max.y += def.border;
+ }
+ if(f->client->titleless)
+ r.max.y += labelh(def.font);
+ }
+ }else {
+ r.max.x -= 2;
+ r.max.y -= labelh(def.font) + 1;
+ }
+ r.max.x = max(r.min.x+1, r.max.x);
+ r.max.y = max(r.min.y+1, r.max.y);
+ return r;
+}
+
+Rectangle
+client2frame(Frame *f, Rectangle r) {
+ if(f == nil || f->area == nil || f->area->floating) {
+ r.max.x += def.border * 2;
+ r.max.y += frame_delta_h();
+ if(f) {
+ if(f->client->borderless) {
+ r.max.x -= 2 * def.border;
+ r.max.y -= def.border;
+ }
+ if(f->client->titleless)
+ r.max.y -= labelh(def.font);
+ }
+ }else {
+ r.max.x += 2;
+ r.max.y += labelh(def.font) + 1;
+ }
+ return r;
+}
+
 void
 resize_frame(Frame *f, Rectangle r) {
         Align stickycorner;
@@ -265,7 +280,11 @@ resize_frame(Frame *f, Rectangle r) {
                 f->crect = f->r;
         }
 
- pt.y = labelh(def.font);
+ pt = ZP;
+ if(!f->client->borderless)
+ pt.y += 1;
+ if(!f->client->titleless)
+ pt.y += labelh(def.font) - 1;
 
         if(f->area->floating) {
                 if(c->fullscreen) {
diff -r 0854dc582fba -r 2205ca9eb791 cmd/wmii/main.c
--- a/cmd/wmii/main.c Fri Apr 20 19:35:46 2007 -0400
+++ b/cmd/wmii/main.c Sat Apr 21 01:13:40 2007 -0400
@@ -48,14 +48,14 @@ scan_wins() {
                         if(wa.override_redirect || XGetTransientForHint(display, wins[i], &d1))
                                 continue;
                         if(wa.map_state == IsViewable)
- manage_client(create_client(wins[i], &wa));
+ create_client(wins[i], &wa);
                 }
                 for(i = 0; i < num; i++) {
                         if(!XGetWindowAttributes(display, wins[i], &wa))
                                 continue;
                         if((XGetTransientForHint(display, wins[i], &d1))
                         && (wa.map_state == IsViewable))
- manage_client(create_client(wins[i], &wa));
+ create_client(wins[i], &wa);
                 }
         }
         if(wins)
diff -r 0854dc582fba -r 2205ca9eb791 cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Fri Apr 20 19:35:46 2007 -0400
+++ b/cmd/wmii/mouse.c Sat Apr 21 01:13:40 2007 -0400
@@ -386,24 +386,42 @@ mouse_resizecolframe(Frame *f, Align ali
         if(align&EAST)
                 d = d->next;
 
- if(align&NORTH) {
- r.min.y = (f->aprev ? f->aprev->r.min.y : screen->r.min.y);
- r.max.y = f->r.max.y;
- }else {
- r.min.y = f->r.min.y;
- r.max.y = (f->anext ? f->anext->r.max.y : a->r.max.y);
- }
- if(align&WEST) {
- r.min.x = (a->prev ? a->prev->r.min.x : screen->r.min.x);
- r.max.x = a->r.max.x;
- }else {
- r.min.x = a->r.min.x;
- r.max.x = (a->next ? a->next->r.max.x : screen->r.max.x);
- }
         min.x = Dx(screen->r)/NCOL;
         min.y = frame_delta_h() + labelh(def.font);
- r.min = addpt(r.min, min);
- r.max = subpt(r.max, min);
+ if(align&NORTH) {
+ if(f->aprev) {
+ r.min.y = f->aprev->r.min.y + min.y;
+ r.max.y = f->r.max.y - min.y;
+ }else {
+ r.min.y = a->r.min.y;
+ r.max.y = r.min.y + 1;
+ }
+ }else {
+ if(f->anext) {
+ r.max.y = f->anext->r.max.y - min.y;
+ r.min.y = f->r.min.y + min.y;
+ }else {
+ r.max.y = a->r.max.y;
+ r.min.y = r.max.y - 1;
+ }
+ }
+ if(align&WEST) {
+ if(a->prev) {
+ r.min.x = a->prev->r.min.x + min.x;
+ r.max.x = a->r.max.x - min.x;
+ }else {
+ r.min.x = a->r.min.x;
+ r.max.x = r.min.x + 1;
+ }
+ }else {
+ if(a->next) {
+ r.max.x = a->next->r.max.x - min.x;
+ r.min.x = a->r.min.x + min.x;
+ }else {
+ r.max.x = a->r.max.x;
+ r.min.x = r.max.x - 1;
+ }
+ }
 
         cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
         mapwin(cwin);
@@ -447,27 +465,25 @@ mouse_resizecolframe(Frame *f, Align ali
                         reshapewin(hwin, r);
                         break;
                 case ButtonRelease:
+ r = f->r;
                         if(align&WEST)
                                 r.min.x = pt.x;
                         else
                                 r.max.x = pt.x;
- if(align&NORTH) {
+ if(align&NORTH)
                                 r.min.y = pt.y;
- r.max.y = f->r.max.y;
- }else {
- r.min.y = f->r.min.y;
+ else
                                 r.max.y = pt.y;
- }
                         resize_colframe(f, &r);
-
+
                         if(align&WEST)
- pt.x = f->r.min.x + 1;
+ pt.x = f->r.min.x + 4;
                         else
- pt.x = f->r.max.x - 2;
+ pt.x = f->r.max.x - 4;
                         if(align&NORTH)
- pt.y = f->r.min.y + 1;
+ pt.y = f->r.min.y + 4;
                         else
- pt.y = f->r.max.y - 2;
+ pt.y = f->r.max.y - 4;
                         warppointer(pt);
                         goto done;
                 }
@@ -657,7 +673,7 @@ do_mouse_resize(Client *c, Bool opaque,
         }
 
         origin = frect = f->r;
- rects = rects_of_view(f->area->view, &num, (opaque ? c->frame : nil));
+ rects = rects_of_view(f->area->view, &num, c->frame);
 
         cur = cursor_of_quad(align);
         if((align==CENTER) && !opaque)
@@ -704,8 +720,6 @@ do_mouse_resize(Client *c, Bool opaque,
                 warppointer(d);
                 flushevents(PointerMotionMask, False);
         }
-
- unmap_client(c, IconicState);
 
         for(;;) {
                 XMaskEvent(display, MouseMask | ExposureMask, &ev);
@@ -747,8 +761,6 @@ do_mouse_resize(Client *c, Bool opaque,
                                         pt.y = screen->brect.min.y - 1;
                                 warppointer(pt);
                         }
-
- map_client(c);
 
                         free(rects);
                         XUngrabPointer(display, CurrentTime);
diff -r 0854dc582fba -r 2205ca9eb791 cmd/wmii/x11.c
--- a/cmd/wmii/x11.c Fri Apr 20 19:35:46 2007 -0400
+++ b/cmd/wmii/x11.c Sat Apr 21 01:13:40 2007 -0400
@@ -269,30 +269,21 @@ uint
 uint
 winprotocols(Window *w) {
         Atom *protocols;
- Atom real, delete;
- ulong nitems, extra;
- int i, format, status, protos;
-
- status = XGetWindowProperty(
- display, w->w, xatom("_WM_PROTOCOLS"),
- /* offset, length, delete, req_type */
- 0L, 20L, False, xatom("ATOM"),
- /* type, format, nitems, extra bytes returns */
- &real, &format, &nitems, &extra,
- /* property return */
- (uchar**)&protocols);
-
- if(status != Success || protocols == nil)
+ Atom actual, delete;
+ int i, n, protos;
+
+ n = getproperty(w, "_WM_PROTOCOLS", "ATOM", &actual, 0L, (uchar**)&protocols, 20L);
+ if(n == 0)
                 return 0;
 
         protos = 0;
         delete = xatom("WM_DELETE_WINDOW");
- for(i = 0; i < nitems; i++) {
+ for(i = 0; i < n; i++) {
                 if(protocols[i] == delete)
                         protos |= WM_PROTOCOL_DELWIN;
         }
 
- XFree(protocols);
+ free(protocols);
         return protos;
 }
 
@@ -557,6 +548,25 @@ freestringlist(char *list[]) {
         XFreeStringList(list);
 }
 
+ulong
+getproperty(Window *w, char *prop, char *type, Atom *actual, ulong offset, uchar **ret, ulong length) {
+ Atom typea;
+ ulong n, extra;
+ int status, format;
+
+ typea = (type ? xatom(type) : 0L);
+
+ status = XGetWindowProperty(display, w->w,
+ xatom(prop), offset, length, False /* delete */,
+ typea, actual, &format, &n, &extra, ret);
+
+ if(status != Success)
+ return 0;
+ if(n == 0)
+ free(*ret);
+ return n;
+}
+
 int
 gettextlistproperty(Window *w, char *name, char **ret[]) {
         XTextProperty prop;
@@ -701,23 +711,23 @@ sethints(Window *w) {
                 xs.win_gravity = NorthWestGravity;
 
         switch (xs.win_gravity) {
- case EastGravity:case CenterGravity:case WestGravity:
+ case EastGravity: case CenterGravity: case WestGravity:
                 p.y = 1;
                 break;
- case SouthEastGravity:case SouthGravity:case SouthWestGravity:
+ case SouthEastGravity: case SouthGravity: case SouthWestGravity:
                 p.y = 2;
                 break;
         }
         switch (xs.win_gravity) {
- case NorthGravity:case CenterGravity:case SouthGravity:
+ case NorthGravity: case CenterGravity: case SouthGravity:
                 p.x = 1;
                 break;
- case NorthEastGravity:case EastGravity:case SouthEastGravity:
+ case NorthEastGravity: case EastGravity: case SouthEastGravity:
                 p.x = 2;
                 break;
         }
         h->grav = p;
- h->gravstatic = (xs.win_gravity&StaticGravity) == 0;
+ h->gravstatic = (xs.win_gravity==StaticGravity);
 }
 
 Rectangle
Received on Fri Jun 01 2007 - 03:09:48 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:57:00 UTC