[hackers] [dwm] added an creatnotify event handler

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Mon Jun 04 11:53:39 2007

changeset: 915:67104d329f06
tag: tip
user: Anselm R. Garbe <arg_AT_suckless.org>
date: Mon Jun 04 11:50:48 2007 +0200
summary: added an creatnotify event handler

diff -r dad36921af06 -r 67104d329f06 client.c
--- a/client.c Mon Jun 04 11:37:33 2007 +0200
+++ b/client.c Mon Jun 04 11:50:48 2007 +0200
@@ -94,6 +94,14 @@ attach(Client *c) {
                 clients->prev = c;
         c->next = clients;
         clients = c;
+}
+
+void
+ban(Client *c) {
+ if (c->isbanned)
+ return;
+ XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
+ c->isbanned = True;
 }
 
 void
@@ -299,82 +307,11 @@ togglefloating(const char *arg) {
 }
 
 void
-updatesizehints(Client *c) {
- long msize;
- XSizeHints size;
-
- if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
- size.flags = PSize;
- c->flags = size.flags;
- if(c->flags & PBaseSize) {
- c->basew = size.base_width;
- c->baseh = size.base_height;
- }
- else if(c->flags & PMinSize) {
- c->basew = size.min_width;
- c->baseh = size.min_height;
- }
- else
- c->basew = c->baseh = 0;
- if(c->flags & PResizeInc) {
- c->incw = size.width_inc;
- c->inch = size.height_inc;
- }
- else
- c->incw = c->inch = 0;
- if(c->flags & PMaxSize) {
- c->maxw = size.max_width;
- c->maxh = size.max_height;
- }
- else
- c->maxw = c->maxh = 0;
- if(c->flags & PMinSize) {
- c->minw = size.min_width;
- c->minh = size.min_height;
- }
- else if(c->flags & PBaseSize) {
- c->minw = size.base_width;
- c->minh = size.base_height;
- }
- else
- c->minw = c->minh = 0;
- if(c->flags & PAspect) {
- c->minax = size.min_aspect.x;
- c->maxax = size.max_aspect.x;
- c->minay = size.min_aspect.y;
- c->maxay = size.max_aspect.y;
- }
- else
- c->minax = c->maxax = c->minay = c->maxay = 0;
- c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
- && c->maxw == c->minw && c->maxh == c->minh);
-}
-
-void
-updatetitle(Client *c) {
- char **list = NULL;
- int n;
- XTextProperty name;
-
- name.nitems = 0;
- c->name[0] = 0;
- XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
- if(!name.nitems)
- XGetWMName(dpy, c->win, &name);
- if(!name.nitems)
- return;
- if(name.encoding == XA_STRING)
- strncpy(c->name, (char *)name.value, sizeof c->name - 1);
- else {
- if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
- && n > 0 && *list)
- {
- strncpy(c->name, *list, sizeof c->name - 1);
- XFreeStringList(list);
- }
- }
- c->name[sizeof c->name - 1] = '\0';
- XFree(name.value);
+unban(Client *c) {
+ if (!c->isbanned)
+ return;
+ XMoveWindow(dpy, c->win, c->x, c->y);
+ c->isbanned = False;
 }
 
 void
@@ -399,3 +336,82 @@ unmanage(Client *c) {
         XUngrabServer(dpy);
         lt->arrange();
 }
+
+void
+updatesizehints(Client *c) {
+ long msize;
+ XSizeHints size;
+
+ if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
+ size.flags = PSize;
+ c->flags = size.flags;
+ if(c->flags & PBaseSize) {
+ c->basew = size.base_width;
+ c->baseh = size.base_height;
+ }
+ else if(c->flags & PMinSize) {
+ c->basew = size.min_width;
+ c->baseh = size.min_height;
+ }
+ else
+ c->basew = c->baseh = 0;
+ if(c->flags & PResizeInc) {
+ c->incw = size.width_inc;
+ c->inch = size.height_inc;
+ }
+ else
+ c->incw = c->inch = 0;
+ if(c->flags & PMaxSize) {
+ c->maxw = size.max_width;
+ c->maxh = size.max_height;
+ }
+ else
+ c->maxw = c->maxh = 0;
+ if(c->flags & PMinSize) {
+ c->minw = size.min_width;
+ c->minh = size.min_height;
+ }
+ else if(c->flags & PBaseSize) {
+ c->minw = size.base_width;
+ c->minh = size.base_height;
+ }
+ else
+ c->minw = c->minh = 0;
+ if(c->flags & PAspect) {
+ c->minax = size.min_aspect.x;
+ c->maxax = size.max_aspect.x;
+ c->minay = size.min_aspect.y;
+ c->maxay = size.max_aspect.y;
+ }
+ else
+ c->minax = c->maxax = c->minay = c->maxay = 0;
+ c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
+ && c->maxw == c->minw && c->maxh == c->minh);
+}
+
+void
+updatetitle(Client *c) {
+ char **list = NULL;
+ int n;
+ XTextProperty name;
+
+ name.nitems = 0;
+ c->name[0] = 0;
+ XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
+ if(!name.nitems)
+ XGetWMName(dpy, c->win, &name);
+ if(!name.nitems)
+ return;
+ if(name.encoding == XA_STRING)
+ strncpy(c->name, (char *)name.value, sizeof c->name - 1);
+ else {
+ if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
+ && n > 0 && *list)
+ {
+ strncpy(c->name, *list, sizeof c->name - 1);
+ XFreeStringList(list);
+ }
+ }
+ c->name[sizeof c->name - 1] = '\0';
+ XFree(name.value);
+}
diff -r dad36921af06 -r 67104d329f06 dwm.h
--- a/dwm.h Mon Jun 04 11:37:33 2007 +0200
+++ b/dwm.h Mon Jun 04 11:50:48 2007 +0200
@@ -96,6 +96,7 @@ extern Window root, barwin;
 
 /* client.c */
 void attach(Client *c); /* attaches c to global client list */
+void ban(Client *c); /* bans c */
 void configure(Client *c); /* send synthetic configure event */
 void detach(Client *c); /* detaches c from global client list */
 void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */
@@ -104,9 +105,10 @@ void resize(Client *c, int x, int y,
 void resize(Client *c, int x, int y,
                 int w, int h, Bool sizehints); /* resize with given coordinates c*/
 void togglefloating(const char *arg); /* toggles sel between floating/tiled state */
+void unban(Client *c); /* unbans c */
+void unmanage(Client *c); /* destroy c */
 void updatesizehints(Client *c); /* update the size hint variables of c */
 void updatetitle(Client *c); /* update the name of c */
-void unmanage(Client *c); /* destroy c */
 
 /* draw.c */
 void drawstatus(void); /* draw the bar */
diff -r dad36921af06 -r 67104d329f06 event.c
--- a/event.c Mon Jun 04 11:37:33 2007 +0200
+++ b/event.c Mon Jun 04 11:50:48 2007 +0200
@@ -225,6 +225,19 @@ configurenotify(XEvent *e) {
 }
 
 static void
+createnotify(XEvent *e) {
+ static XWindowAttributes wa;
+ XCreateWindowEvent *ev = &e->xcreatewindow;
+
+ if(!XGetWindowAttributes(dpy, ev->window, &wa))
+ return;
+ if(wa.override_redirect)
+ return;
+ if(!getclient(ev->window) && (wa.map_state == IsViewable))
+ manage(ev->window, &wa);
+}
+
+static void
 destroynotify(XEvent *e) {
         Client *c;
         XDestroyWindowEvent *ev = &e->xdestroywindow;
@@ -350,6 +363,7 @@ void (*handler[LASTEvent]) (XEvent *) =
         [ButtonPress] = buttonpress,
         [ConfigureRequest] = configurerequest,
         [ConfigureNotify] = configurenotify,
+ [CreateNotify] = createnotify,
         [DestroyNotify] = destroynotify,
         [EnterNotify] = enternotify,
         [LeaveNotify] = leavenotify,
diff -r dad36921af06 -r 67104d329f06 layout.c
--- a/layout.c Mon Jun 04 11:37:33 2007 +0200
+++ b/layout.c Mon Jun 04 11:50:48 2007 +0200
@@ -10,22 +10,6 @@ static unsigned int nlayouts = 0;
 static unsigned int nlayouts = 0;
 static unsigned int masterw = MASTERWIDTH;
 static unsigned int nmaster = NMASTER;
-
-static void
-ban(Client *c) {
- if (c->isbanned)
- return;
- XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
- c->isbanned = True;
-}
-
-static void
-unban(Client *c) {
- if (!c->isbanned)
- return;
- XMoveWindow(dpy, c->win, c->x, c->y);
- c->isbanned = False;
-}
 
 static void
 tile(void) {
Received on Mon Jun 04 2007 - 11:53:39 UTC

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