/* See LICENSE file for copyright and license details. */
#include "dwm.h"
#include <stdlib.h>
-#include <string.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
/* static */
-static char buf[128];
-
static void
attachstack(Client *c) {
c->snext = stack;
ban(Client *c) {
if(c->isbanned)
return;
- XUnmapWindow(dpy, c->win);
- setclientstate(c, IconicState);
+ XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
c->isbanned = True;
- c->unmapped++;
}
void
XKillClient(dpy, sel->win);
}
-Bool
-getprops(Client *c) {
- unsigned int i;
- Bool result = False;
-
- if(gettextprop(c->win, dwmprops, buf, sizeof buf)) {
- for(i = 0; i < ntags && i < sizeof buf - 1 && buf[i] != '\0'; i++)
- if((c->tags[i] = buf[i] == '1'))
- result = True;
- if(i < sizeof buf - 1 && buf[i] != '\0')
- c->isfloating = buf[i] == '1';
- }
- return result;
-}
-
void
manage(Window w, XWindowAttributes *wa) {
unsigned int i;
if(t)
for(i = 0; i < ntags; i++)
c->tags[i] = t->tags[i];
- if(!getprops(c))
- applyrules(c);
+ applyrules(c);
if(!c->isfloating)
c->isfloating = (rettrans == Success) || c->isfixed;
- setprops(c);
attach(c);
attachstack(c);
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
ban(c);
+ XMapWindow(dpy, c->win);
arrange();
}
}
}
-void
-setprops(Client *c) {
- unsigned int i;
-
- for(i = 0; i < ntags && i < sizeof buf - 1; i++)
- buf[i] = c->tags[i] ? '1' : '0';
- if(i < sizeof buf - 1)
- buf[i++] = c->isfloating ? '1' : '0';
- buf[i] = '\0';
- XChangeProperty(dpy, c->win, dwmprops, XA_STRING, 8,
- PropModeReplace, (unsigned char *)buf, i);
-}
-
void
unban(Client *c) {
if(!c->isbanned)
return;
- XMapWindow(dpy, c->win);
- setclientstate(c, NormalState);
+ XMoveWindow(dpy, c->win, c->x, c->y);
c->isbanned = False;
}
void
-unmanage(Client *c, long state) {
+unmanage(Client *c) {
XWindowChanges wc;
wc.border_width = c->oldborder;
if(sel == c)
focus(NULL);
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
- setclientstate(c, state);
+ setclientstate(c, WithdrawnState);
free(c->tags);
free(c);
XSync(dpy, False);
XSetErrorHandler(xerror);
XUngrabServer(dpy);
- if(state != NormalState)
- arrange();
+ arrange();
}
void
# flags
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
LDFLAGS = -s ${LIBS}
-#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
-#LDFLAGS = -g ${LIBS}
+CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
+LDFLAGS = -g ${LIBS}
# Solaris
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
int rx, ry, rw, rh; /* revert geometry */
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int minax, maxax, minay, maxay;
- int unmapped;
long flags;
unsigned int border, oldborder;
Bool isbanned, isfixed, ismax, isfloating;
extern unsigned int bh, blw, bpos; /* bar height, bar layout label width, bar position */
extern unsigned int ntags, numlockmask; /* number of tags, numlock mask */
extern void (*handler[LASTEvent])(XEvent *); /* event handler */
-extern Atom dwmprops, wmatom[WMLast], netatom[NetLast];
+extern Atom wmatom[WMLast], netatom[NetLast];
extern Bool selscreen, *seltags; /* seltags is array of Bool */
extern Client *clients, *sel, *stack; /* global client list and stack */
extern Cursor cursor[CurLast];
void detach(Client *c); /* detaches c from global client list */
void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */
void killclient(const char *arg); /* kill sel nicely */
-Bool getprops(Client *c); /* gets client properties */
void manage(Window w, XWindowAttributes *wa); /* manage new client */
void resize(Client *c, int x, int y,
int w, int h, Bool sizehints); /* resize with given coordinates c*/
-void setprops(Client *c); /* sets client properties */
void unban(Client *c); /* unbans c */
-void unmanage(Client *c, long state); /* unmanage c */
+void unmanage(Client *c); /* unmanage c */
void updatesizehints(Client *c); /* update the size hint variables of c */
void updatetitle(Client *c); /* update the name of c */
Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */
Bool isfloating(void); /* returns True if floating layout is enabled */
Bool isvisible(Client *c); /* returns True if client is visible */
-void getdwmprops(void); /* gets dwm properties */
Client *nexttiled(Client *c); /* returns tiled successor of c */
void restack(void); /* restores z layers of all clients */
void setlayout(const char *arg); /* sets layout, NULL means next layout */
XDestroyWindowEvent *ev = &e->xdestroywindow;
if((c = getclient(ev->window)))
- unmanage(c, WithdrawnState);
+ unmanage(c);
}
static void
Client *c;
XUnmapEvent *ev = &e->xunmap;
- if((c = getclient(ev->window)) && (ev->event == root)) {
- if(ev->send_event || c->unmapped-- == 0)
- unmanage(c, WithdrawnState);
- }
+ if((c = getclient(ev->window)))
+ unmanage(c);
}
/* extern */
unsigned int bh, ntags;
unsigned int bpos = BARPOS;
unsigned int numlockmask = 0;
-Atom dwmprops, wmatom[WMLast], netatom[NetLast];
+Atom wmatom[WMLast], netatom[NetLast];
Bool *seltags;
Bool selscreen = True;
Client *clients = NULL;
close(STDIN_FILENO);
while(stack) {
unban(stack);
- unmanage(stack, NormalState);
+ unmanage(stack);
}
if(dc.font.set)
XFreeFontSet(dpy, dc.font.set);
XSetWindowAttributes wa;
/* init atoms */
- dwmprops = XInternAtom(dpy, "_DWM_PROPERTIES", False);
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False);
XSetFont(dpy, dc.gc, dc.font.xfont->fid);
/* multihead support */
selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
- getdwmprops();
}
/*
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
-#include <X11/Xatom.h>
#include <X11/Xutil.h>
/* static */
TAGS
RULES
-static char buf[512];
static unsigned int nrules = 0;
static unsigned int nlayouts = 0;
static unsigned int ltidx = 0; /* default */
resize(c, c->x, c->y, c->w, c->h, True);
}
-static void
-setdwmprops(void) {
- unsigned int i;
-
- for(i = 0; i < ntags && i < sizeof buf - 1; i++)
- buf[i] = seltags[i] ? '1' : '0';
- if(i < sizeof buf - 1)
- buf[i++] = (char)ltidx + '0';
- buf[i] = '\0';
- XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
- PropModeReplace, (unsigned char *)buf, i);
-}
-
LAYOUTS
/* extern */
void
applyrules(Client *c) {
+ static char buf[512];
unsigned int i, j;
regmatch_t tmp;
Bool matched = False;
return False;
}
-void
-getdwmprops(void) {
- unsigned int i;
-
- if(gettextprop(root, dwmprops, buf, sizeof buf)) {
- for(i = 0; i < ntags && i < sizeof buf - 1 && buf[i] != '\0'; i++)
- seltags[i] = buf[i] == '1';
- if(i < sizeof buf - 1 && buf[i] != '\0') {
- if((unsigned int)(buf[i] - '0') < nlayouts)
- ltidx = buf[i] - '0';
- }
- }
-}
-
Client *
nexttiled(Client *c) {
for(; c && (c->isfloating || !isvisible(c)); c = c->next);
void
setlayout(const char *arg) {
- int i;
+ unsigned int i;
if(!arg) {
if(++ltidx == nlayouts)
ltidx = 0;;
}
else {
- i = atoi(arg);
- if(i < 0 || i >= nlayouts)
+ for(i = 0; i < nlayouts; i++)
+ if(arg == layouts[i].symbol)
+ break;
+ if(i == nlayouts)
return;
ltidx = i;
}
arrange();
else
drawstatus();
- setdwmprops();
}
void
i = idxoftag(arg);
if(i >= 0 && i < ntags)
sel->tags[i] = True;
- setprops(sel);
arrange();
}
if(!sel || isfloating())
return;
sel->isfloating = !sel->isfloating;
- if(sel->isfloating) {
+ if(sel->isfloating)
resize(sel, sel->x, sel->y, sel->w, sel->h, True);
- setprops(sel);
- }
arrange();
}
for(j = 0; j < ntags && !sel->tags[j]; j++);
if(j == ntags)
sel->tags[i] = True;
- setprops(sel);
arrange();
}
for(j = 0; j < ntags && !seltags[j]; j++);
if(j == ntags)
seltags[i] = True; /* cannot toggle last view */
- setdwmprops();
arrange();
}
i = idxoftag(arg);
if(i >= 0 && i < ntags)
seltags[i] = True;
- setdwmprops();
arrange();
}