dwm.c
changeset 1027 0735e86bbd49
parent 1026 bc0929d03388
child 1029 2388a478f146
equal deleted inserted replaced
1026:bc0929d03388 1027:0735e86bbd49
    55 enum { NetSupported, NetWMName, NetLast };		/* EWMH atoms */
    55 enum { NetSupported, NetWMName, NetLast };		/* EWMH atoms */
    56 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
    56 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
    57 
    57 
    58 /* typedefs */
    58 /* typedefs */
    59 typedef struct Client Client;
    59 typedef struct Client Client;
       
    60 
       
    61 struct Client {
       
    62 	char name[256];
       
    63 	int x, y, w, h;
       
    64 	int rx, ry, rw, rh; /* revert geometry */
       
    65 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
       
    66 	int minax, maxax, minay, maxay;
       
    67 	long flags;
       
    68 	unsigned int border, oldborder;
       
    69 	Bool isbanned, isfixed, ismax, isfloating, wasfloating;
       
    70 	Bool *tags;
       
    71 	Client *next;
       
    72 	Client *prev;
       
    73 	Client *snext;
       
    74 	Window win;
       
    75 };
    60 
    76 
    61 typedef struct {
    77 typedef struct {
    62 	int x, y, w, h;
    78 	int x, y, w, h;
    63 	unsigned long norm[ColLast];
    79 	unsigned long norm[ColLast];
    64 	unsigned long sel[ColLast];
    80 	unsigned long sel[ColLast];
   168 void unmapnotify(XEvent *e);
   184 void unmapnotify(XEvent *e);
   169 void updatebarpos(void);
   185 void updatebarpos(void);
   170 void updatesizehints(Client *c);
   186 void updatesizehints(Client *c);
   171 void updatetitle(Client *c);
   187 void updatetitle(Client *c);
   172 void view(const char *arg);
   188 void view(const char *arg);
       
   189 void viewprevtag(const char *arg);	/* views previous selected tags */
   173 int xerror(Display *dpy, XErrorEvent *ee);
   190 int xerror(Display *dpy, XErrorEvent *ee);
   174 int xerrordummy(Display *dsply, XErrorEvent *ee);
   191 int xerrordummy(Display *dsply, XErrorEvent *ee);
   175 int xerrorstart(Display *dsply, XErrorEvent *ee);
   192 int xerrorstart(Display *dsply, XErrorEvent *ee);
   176 void zoom(const char *arg);
   193 void zoom(const char *arg);
   177 
   194 
   217 #include "config.h"
   234 #include "config.h"
   218 
   235 
   219 /* Statically define the number of tags. */
   236 /* Statically define the number of tags. */
   220 unsigned int ntags = sizeof tags / sizeof tags[0];
   237 unsigned int ntags = sizeof tags / sizeof tags[0];
   221 Bool seltags[sizeof tags / sizeof tags[0]] = {[0] = True};
   238 Bool seltags[sizeof tags / sizeof tags[0]] = {[0] = True};
   222 
   239 Bool prevtags[sizeof tags / sizeof tags[0]] = {[0] = True};
   223 struct Client {
       
   224 	char name[256];
       
   225 	int x, y, w, h;
       
   226 	int rx, ry, rw, rh; /* revert geometry */
       
   227 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
       
   228 	int minax, maxax, minay, maxay;
       
   229 	long flags;
       
   230 	unsigned int border, oldborder;
       
   231 	Bool isbanned, isfixed, ismax, isfloating, wasfloating;
       
   232 	Bool tags[sizeof tags / sizeof tags[0]];
       
   233 	Client *next;
       
   234 	Client *prev;
       
   235 	Client *snext;
       
   236 	Window win;
       
   237 };
       
   238 
   240 
   239 /* functions*/
   241 /* functions*/
   240 void
   242 void
   241 applyrules(Client *c) {
   243 applyrules(Client *c) {
   242 	static char buf[512];
   244 	static char buf[512];
   263 	if(ch.res_class)
   265 	if(ch.res_class)
   264 		XFree(ch.res_class);
   266 		XFree(ch.res_class);
   265 	if(ch.res_name)
   267 	if(ch.res_name)
   266 		XFree(ch.res_name);
   268 		XFree(ch.res_name);
   267 	if(!matched)
   269 	if(!matched)
   268 		for(i = 0; i < ntags; i++)
   270 		memcpy(c->tags, seltags, sizeof seltags);
   269 			c->tags[i] = seltags[i];
       
   270 }
   271 }
   271 
   272 
   272 void
   273 void
   273 arrange(void) {
   274 arrange(void) {
   274 	Client *c;
   275 	Client *c;
  1000 	}
  1001 	}
  1001 }
  1002 }
  1002 
  1003 
  1003 void
  1004 void
  1004 manage(Window w, XWindowAttributes *wa) {
  1005 manage(Window w, XWindowAttributes *wa) {
  1005 	unsigned int i;
       
  1006 	Client *c, *t = NULL;
  1006 	Client *c, *t = NULL;
  1007 	Window trans;
  1007 	Window trans;
  1008 	Status rettrans;
  1008 	Status rettrans;
  1009 	XWindowChanges wc;
  1009 	XWindowChanges wc;
  1010 
  1010 
  1011 	c = emallocz(sizeof(Client));
  1011 	c = emallocz(sizeof(Client));
       
  1012 	c->tags = emallocz(sizeof seltags);
  1012 	c->win = w;
  1013 	c->win = w;
  1013 	c->x = wa->x;
  1014 	c->x = wa->x;
  1014 	c->y = wa->y;
  1015 	c->y = wa->y;
  1015 	c->w = wa->width;
  1016 	c->w = wa->width;
  1016 	c->h = wa->height;
  1017 	c->h = wa->height;
  1041 	grabbuttons(c, False);
  1042 	grabbuttons(c, False);
  1042 	updatetitle(c);
  1043 	updatetitle(c);
  1043 	if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
  1044 	if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
  1044 		for(t = clients; t && t->win != trans; t = t->next);
  1045 		for(t = clients; t && t->win != trans; t = t->next);
  1045 	if(t)
  1046 	if(t)
  1046 		for(i = 0; i < ntags; i++)
  1047 		memcpy(c->tags, t->tags, sizeof seltags);
  1047 			c->tags[i] = t->tags[i];
       
  1048 	applyrules(c);
  1048 	applyrules(c);
  1049 	if(!c->isfloating)
  1049 	if(!c->isfloating)
  1050 		c->isfloating = (rettrans == Success) || c->isfixed;
  1050 		c->isfloating = (rettrans == Success) || c->isfixed;
  1051 	attach(c);
  1051 	attach(c);
  1052 	attachstack(c);
  1052 	attachstack(c);
  1700 	detachstack(c);
  1700 	detachstack(c);
  1701 	if(sel == c)
  1701 	if(sel == c)
  1702 		focus(NULL);
  1702 		focus(NULL);
  1703 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
  1703 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
  1704 	setclientstate(c, WithdrawnState);
  1704 	setclientstate(c, WithdrawnState);
       
  1705 	free(c->tags);
  1705 	free(c);
  1706 	free(c);
  1706 	XSync(dpy, False);
  1707 	XSync(dpy, False);
  1707 	XSetErrorHandler(xerror);
  1708 	XSetErrorHandler(xerror);
  1708 	XUngrabServer(dpy);
  1709 	XUngrabServer(dpy);
  1709 	arrange();
  1710 	arrange();
  1836 
  1837 
  1837 void
  1838 void
  1838 view(const char *arg) {
  1839 view(const char *arg) {
  1839 	unsigned int i;
  1840 	unsigned int i;
  1840 
  1841 
       
  1842 	memcpy(prevtags, seltags, sizeof seltags);
  1841 	for(i = 0; i < ntags; i++)
  1843 	for(i = 0; i < ntags; i++)
  1842 		seltags[i] = arg == NULL;
  1844 		seltags[i] = arg == NULL;
  1843 	i = idxoftag(arg);
  1845 	i = idxoftag(arg);
  1844 	if(i >= 0 && i < ntags)
  1846 	if(i >= 0 && i < ntags)
  1845 		seltags[i] = True;
  1847 		seltags[i] = True;
       
  1848 	arrange();
       
  1849 }
       
  1850 
       
  1851 void
       
  1852 viewprevtag(const char *arg) {
       
  1853 	static Bool tmptags[sizeof tags / sizeof tags[0]];
       
  1854 
       
  1855 	memcpy(tmptags, seltags, sizeof seltags);
       
  1856 	memcpy(seltags, prevtags, sizeof seltags);
       
  1857 	memcpy(prevtags, tmptags, sizeof seltags);
  1846 	arrange();
  1858 	arrange();
  1847 }
  1859 }
  1848 
  1860 
  1849 void
  1861 void
  1850 zoom(const char *arg) {
  1862 zoom(const char *arg) {