client.c
changeset 342 a1901753deef
parent 327 96d09fd98e89
child 372 a9b4077ec058
equal deleted inserted replaced
341:e4dad4635250 342:a1901753deef
    26 static void
    26 static void
    27 resizetitle(Client *c)
    27 resizetitle(Client *c)
    28 {
    28 {
    29 	int i;
    29 	int i;
    30 
    30 
    31 	c->tw = 0;
    31 	c->tw = textw(c->name);
    32 	for(i = 0; i < ntags; i++)
       
    33 		if(c->tags[i])
       
    34 			c->tw += textw(tags[i]);
       
    35 	c->tw += textw(c->name);
       
    36 	if(c->tw > c->w)
    32 	if(c->tw > c->w)
    37 		c->tw = c->w + 2;
    33 		c->tw = c->w + 2;
    38 	c->tx = c->x + c->w - c->tw + 2;
    34 	c->tx = c->x + c->w - c->tw + 2;
    39 	c->ty = c->y;
    35 	c->ty = c->y;
    40 	if(isvisible(c))
    36 	if(isvisible(c))
    41 		XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
    37 		XMoveResizeWindow(dpy, c->twin, c->tx, c->ty, c->tw, c->th);
    42 	else
    38 	else
    43 		XMoveResizeWindow(dpy, c->title, c->tx + 2 * sw, c->ty, c->tw, c->th);
    39 		XMoveResizeWindow(dpy, c->twin, c->tx + 2 * sw, c->ty, c->tw, c->th);
    44 
    40 
    45 }
    41 }
    46 
    42 
    47 static void
    43 static void
    48 ungrabbutton(Client *c, unsigned int button, unsigned int modifier)
    44 ungrabbutton(Client *c, unsigned int button, unsigned int modifier)
    63 
    59 
    64 void
    60 void
    65 ban(Client *c)
    61 ban(Client *c)
    66 {
    62 {
    67 	XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
    63 	XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
    68 	XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
    64 	XMoveWindow(dpy, c->twin, c->tx + 2 * sw, c->ty);
    69 }
    65 }
    70 
    66 
    71 void
    67 void
    72 focus(Client *c)
    68 focus(Client *c)
    73 {
    69 {
   104 getctitle(Window w)
   100 getctitle(Window w)
   105 {
   101 {
   106 	Client *c;
   102 	Client *c;
   107 
   103 
   108 	for(c = clients; c; c = c->next)
   104 	for(c = clients; c; c = c->next)
   109 		if(c->title == w)
   105 		if(c->twin == w)
   110 			return c;
   106 			return c;
   111 	return NULL;
   107 	return NULL;
   112 }
   108 }
   113 
   109 
   114 void
   110 void
   212 	XGetTransientForHint(dpy, c->win, &trans);
   208 	XGetTransientForHint(dpy, c->win, &trans);
   213 	twa.override_redirect = 1;
   209 	twa.override_redirect = 1;
   214 	twa.background_pixmap = ParentRelative;
   210 	twa.background_pixmap = ParentRelative;
   215 	twa.event_mask = ExposureMask | EnterWindowMask;
   211 	twa.event_mask = ExposureMask | EnterWindowMask;
   216 
   212 
   217 	c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
   213 	c->twin = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
   218 			0, DefaultDepth(dpy, screen), CopyFromParent,
   214 			0, DefaultDepth(dpy, screen), CopyFromParent,
   219 			DefaultVisual(dpy, screen),
   215 			DefaultVisual(dpy, screen),
   220 			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
   216 			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
   221 
   217 
   222 	if(clients)
   218 	if(clients)
   240 	settitle(c);
   236 	settitle(c);
   241 	if(isvisible(c))
   237 	if(isvisible(c))
   242 		sel = c;
   238 		sel = c;
   243 	arrange(NULL);
   239 	arrange(NULL);
   244 	XMapWindow(dpy, c->win);
   240 	XMapWindow(dpy, c->win);
   245 	XMapWindow(dpy, c->title);
   241 	XMapWindow(dpy, c->twin);
   246 	if(isvisible(c))
   242 	if(isvisible(c))
   247 		focus(c);
   243 		focus(c);
   248 }
   244 }
   249 
   245 
   250 void
   246 void
   327 
   323 
   328 void
   324 void
   329 settitle(Client *c)
   325 settitle(Client *c)
   330 {
   326 {
   331 	char **list = NULL;
   327 	char **list = NULL;
   332 	int n;
   328 	int i, n;
   333 	XTextProperty name;
   329 	XTextProperty name;
   334 
   330 
   335 	name.nitems = 0;
   331 	name.nitems = 0;
   336 	c->name[0] = 0;
   332 	c->name[0] = 0;
   337 	XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
   333 	XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
   390 {
   386 {
   391 	XGrabServer(dpy);
   387 	XGrabServer(dpy);
   392 	XSetErrorHandler(xerrordummy);
   388 	XSetErrorHandler(xerrordummy);
   393 
   389 
   394 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
   390 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
   395 	XDestroyWindow(dpy, c->title);
   391 	XDestroyWindow(dpy, c->twin);
   396 
   392 
   397 	if(c->prev)
   393 	if(c->prev)
   398 		c->prev->next = c->next;
   394 		c->prev->next = c->next;
   399 	if(c->next)
   395 	if(c->next)
   400 		c->next->prev = c->prev;
   396 		c->next->prev = c->prev;