client.c
changeset 964 777a9d9ce70b
parent 963 7416c26a14db
child 966 3ad7903c9e83
equal deleted inserted replaced
963:7416c26a14db 964:777a9d9ce70b
     5 #include <X11/Xatom.h>
     5 #include <X11/Xatom.h>
     6 #include <X11/Xutil.h>
     6 #include <X11/Xutil.h>
     7 
     7 
     8 /* static */
     8 /* static */
     9 
     9 
    10 static char config[128];
    10 static char prop[128];
    11 
    11 
    12 static void
    12 static void
    13 attachstack(Client *c) {
    13 attachstack(Client *c) {
    14 	c->snext = stack;
    14 	c->snext = stack;
    15 	stack = c;
    15 	stack = c;
   180 	else
   180 	else
   181 		XKillClient(dpy, sel->win);
   181 		XKillClient(dpy, sel->win);
   182 }
   182 }
   183 
   183 
   184 Bool
   184 Bool
   185 loadconfig(Client *c) {
   185 loadprops(Client *c) {
   186 	unsigned int i;
   186 	unsigned int i;
   187 	Bool result = False;
   187 	Bool result = False;
   188 	XTextProperty name;
   188 	XTextProperty name;
   189 
   189 
   190 	/* check if window has set a property */
   190 	/* check if window has set a property */
   191 	name.nitems = 0;
   191 	name.nitems = 0;
   192 	XGetTextProperty(dpy, c->win, &name, dwmconfig);
   192 	XGetTextProperty(dpy, c->win, &name, dwmprops);
   193 	if(name.nitems && name.encoding == XA_STRING) {
   193 	if(name.nitems && name.encoding == XA_STRING) {
   194 		strncpy(config, (char *)name.value, sizeof config - 1);
   194 		strncpy(prop, (char *)name.value, sizeof prop - 1);
   195 		config[sizeof config - 1] = '\0';
   195 		prop[sizeof prop - 1] = '\0';
   196 		XFree(name.value);
   196 		XFree(name.value);
   197 		for(i = 0; i < ntags && i < sizeof config - 1 && config[i] != '\0'; i++)
   197 		for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
   198 			if((c->tags[i] = config[i] == '1'))
   198 			if((c->tags[i] = prop[i] == '1'))
   199 				result = True;
   199 				result = True;
   200 		if(i < sizeof config - 1 && config[i] != '\0')
   200 		if(i < sizeof prop - 1 && prop[i] != '\0')
   201 			c->isfloating = config[i] == '1';
   201 			c->isfloating = prop[i] == '1';
   202 	}
   202 	}
   203 	return result;
   203 	return result;
   204 }
   204 }
   205 
   205 
   206 void
   206 void
   247 	if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
   247 	if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
   248 		for(t = clients; t && t->win != trans; t = t->next);
   248 		for(t = clients; t && t->win != trans; t = t->next);
   249 	if(t)
   249 	if(t)
   250 		for(i = 0; i < ntags; i++)
   250 		for(i = 0; i < ntags; i++)
   251 			c->tags[i] = t->tags[i];
   251 			c->tags[i] = t->tags[i];
   252 	if(!loadconfig(c))
   252 	if(!loadprops(c))
   253 		applyrules(c);
   253 		applyrules(c);
   254 	if(!c->isfloating)
   254 	if(!c->isfloating)
   255 		c->isfloating = (rettrans == Success) || c->isfixed;
   255 		c->isfloating = (rettrans == Success) || c->isfixed;
   256 	saveconfig(c);
   256 	saveprops(c);
   257 	attach(c);
   257 	attach(c);
   258 	attachstack(c);
   258 	attachstack(c);
   259 	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
   259 	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
   260 	ban(c);
   260 	ban(c);
   261 	arrange();
   261 	arrange();
   323 		XSync(dpy, False);
   323 		XSync(dpy, False);
   324 	}
   324 	}
   325 }
   325 }
   326 
   326 
   327 void
   327 void
   328 saveconfig(Client *c) {
   328 saveprops(Client *c) {
   329 	unsigned int i;
   329 	unsigned int i;
   330 
   330 
   331 	for(i = 0; i < ntags && i < sizeof config - 1; i++)
   331 	for(i = 0; i < ntags && i < sizeof prop - 1; i++)
   332 		config[i] = c->tags[i] ? '1' : '0';
   332 		prop[i] = c->tags[i] ? '1' : '0';
   333 	if(i < sizeof config - 1)
   333 	if(i < sizeof prop - 1)
   334 		config[i++] = c->isfloating ? '1' : '0';
   334 		prop[i++] = c->isfloating ? '1' : '0';
   335 	config[i] = '\0';
   335 	prop[i] = '\0';
   336 	XChangeProperty(dpy, c->win, dwmconfig, XA_STRING, 8,
   336 	XChangeProperty(dpy, c->win, dwmprops, XA_STRING, 8,
   337 			PropModeReplace, (unsigned char *)config, i);
   337 			PropModeReplace, (unsigned char *)prop, i);
   338 }
   338 }
   339 
   339 
   340 void
   340 void
   341 unban(Client *c) {
   341 unban(Client *c) {
   342 	if(!c->isbanned)
   342 	if(!c->isbanned)