client.c
changeset 400 052657ff2e7b
parent 381 b00cc483d13b
child 403 6413ea66b1c2
equal deleted inserted replaced
399:74739798b0b2 400:052657ff2e7b
    80 }
    80 }
    81 
    81 
    82 void
    82 void
    83 focus(Client *c)
    83 focus(Client *c)
    84 {
    84 {
    85 	Client *old = sel;
    85 	Client *old;
    86 
    86 
    87 	if(!issel)
    87 	if(!issel)
    88 		return;
    88 		return;
    89 	if(!sel)
    89 	if(!sel)
    90 		sel = c;
    90 		sel = c;
    91 	else if(sel != c) {
    91 	else if(sel != c) {
    92 		if(sel->ismax)
    92 		if(maximized)
    93 			togglemax(NULL);
    93 			togglemax(NULL);
       
    94 		old = sel;
    94 		sel = c;
    95 		sel = c;
    95 		grabbuttons(old, False);
    96 		if(old) {
    96 		drawtitle(old);
    97 			grabbuttons(old, False);
    97 	}
    98 			drawtitle(old);
    98 	grabbuttons(c, True);
    99 		}
    99 	drawtitle(c);
   100 	}
   100 	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
   101 	if(c) {
       
   102 		grabbuttons(c, True);
       
   103 		drawtitle(c);
       
   104 		XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
       
   105 	}
       
   106 	else
       
   107 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
   101 }
   108 }
   102 
   109 
   103 Client *
   110 Client *
   104 getclient(Window w)
   111 getclient(Window w)
   105 {
   112 {
   245 		clients->prev = c;
   252 		clients->prev = c;
   246 	c->next = clients;
   253 	c->next = clients;
   247 	clients = c;
   254 	clients = c;
   248 
   255 
   249 	settitle(c);
   256 	settitle(c);
   250 	if(isvisible(c))
       
   251 		sel = c;
       
   252 	arrange(NULL);
   257 	arrange(NULL);
   253 	XMapWindow(dpy, c->win);
   258 	XMapWindow(dpy, c->win);
   254 	XMapWindow(dpy, c->twin);
   259 	XMapWindow(dpy, c->twin);
   255 	if(isvisible(c))
   260 	if(isvisible(c))
   256 		focus(c);
   261 		focus(c);
   364 
   369 
   365 void
   370 void
   366 togglemax(Arg *arg)
   371 togglemax(Arg *arg)
   367 {
   372 {
   368 	int ox, oy, ow, oh;
   373 	int ox, oy, ow, oh;
       
   374 	Client *c;
   369 	XEvent ev;
   375 	XEvent ev;
   370 
   376 
   371 	if(!sel)
   377 	if(!sel)
   372 		return;
   378 		return;
   373 
   379 
   374 	if((sel->ismax = !sel->ismax)) {
   380 	if((maximized = !maximized)) {
   375 		ox = sel->x;
   381 		ox = sel->x;
   376 		oy = sel->y;
   382 		oy = sel->y;
   377 		ow = sel->w;
   383 		ow = sel->w;
   378 		oh = sel->h;
   384 		oh = sel->h;
   379 		sel->x = sx;
   385 		sel->x = sx;
   380 		sel->y = sy + bh;
   386 		sel->y = sy + bh;
   381 		sel->w = sw - 2;
   387 		sel->w = sw - 2;
   382 		sel->h = sh - 2 - bh;
   388 		sel->h = sh - 2 - bh;
   383 
   389 
   384 		restack();
   390 		restack();
       
   391 		for(c = getnext(clients); c; c = getnext(c->next))
       
   392 			if(c != sel)
       
   393 				ban(c);
   385 		resize(sel, arrange == dofloat, TopLeft);
   394 		resize(sel, arrange == dofloat, TopLeft);
   386 
   395 
   387 		sel->x = ox;
   396 		sel->x = ox;
   388 		sel->y = oy;
   397 		sel->y = oy;
   389 		sel->w = ow;
   398 		sel->w = ow;
   390 		sel->h = oh;
   399 		sel->h = oh;
   391 	}
   400 	}
   392 	else
   401 	else
   393 		resize(sel, False, TopLeft);
   402 		arrange(NULL);
   394 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
   403 	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
   395 }
   404 }
   396 
   405 
   397 void
   406 void
   398 unmanage(Client *c)
   407 unmanage(Client *c)
   399 {
   408 {
   400 	Client *tc;
   409 	Client *tc, *fc;
   401 	Window trans;
   410 	Window trans;
   402 	XGrabServer(dpy);
   411 	XGrabServer(dpy);
   403 	XSetErrorHandler(xerrordummy);
   412 	XSetErrorHandler(xerrordummy);
   404 
   413 
   405 	XGetTransientForHint(dpy, c->win, &trans);
   414 	detach(c);
       
   415 	if(sel == c) {
       
   416 		XGetTransientForHint(dpy, c->win, &trans);
       
   417 		if(trans && (tc = getclient(trans)) && isvisible(tc))
       
   418 			fc = tc;
       
   419 		else
       
   420 			fc = getnext(clients);
       
   421 		focus(fc);
       
   422 	}
   406 
   423 
   407 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
   424 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
   408 	XDestroyWindow(dpy, c->twin);
   425 	XDestroyWindow(dpy, c->twin);
   409 
   426 
   410 	detach(c);
       
   411 	if(sel == c) {
       
   412 		if(trans && (tc = getclient(trans)) && isvisible(tc))
       
   413 			sel = tc;
       
   414 		else
       
   415 			sel = getnext(clients);
       
   416 	}
       
   417 	free(c->tags);
   427 	free(c->tags);
   418 	free(c);
   428 	free(c);
   419 
   429 
   420 	XSync(dpy, False);
   430 	XSync(dpy, False);
   421 	XSetErrorHandler(xerror);
   431 	XSetErrorHandler(xerror);
   422 	XUngrabServer(dpy);
   432 	XUngrabServer(dpy);
   423 	if(sel)
       
   424 		focus(sel);
       
   425 	arrange(NULL);
   433 	arrange(NULL);
   426 }
   434 }