client.c
changeset 22 bd3a44353916
parent 21 3ef108a5ca0a
child 23 95ffdfd0a819
equal deleted inserted replaced
21:3ef108a5ca0a 22:bd3a44353916
   102 	Client *c, **l;
   102 	Client *c, **l;
   103 	XSetWindowAttributes twa;
   103 	XSetWindowAttributes twa;
   104 
   104 
   105 	c = emallocz(sizeof(Client));
   105 	c = emallocz(sizeof(Client));
   106 	c->win = w;
   106 	c->win = w;
   107 	c->x = wa->x;
   107 	c->tx = c->x = wa->x;
   108 	c->y = wa->y;
   108 	c->ty = c->y = wa->y;
   109 	c->w = wa->width;
   109 	c->tw = c->w = wa->width;
   110 	c->h = wa->height;
   110 	c->h = wa->height;
       
   111 	c->th = barrect.height;
   111 	update_size(c);
   112 	update_size(c);
   112 	XSetWindowBorderWidth(dpy, c->win, 1);
   113 	XSetWindowBorderWidth(dpy, c->win, 1);
       
   114 	XSetWindowBorder(dpy, c->win, brush.border);
   113 	XSelectInput(dpy, c->win, CLIENT_MASK);
   115 	XSelectInput(dpy, c->win, CLIENT_MASK);
   114 	XGetTransientForHint(dpy, c->win, &c->trans);
   116 	XGetTransientForHint(dpy, c->win, &c->trans);
   115 	twa.override_redirect = 1;
   117 	twa.override_redirect = 1;
   116 	twa.background_pixmap = ParentRelative;
   118 	twa.background_pixmap = ParentRelative;
   117 	twa.event_mask = ExposureMask;
   119 	twa.event_mask = SubstructureNotifyMask | ExposureMask;
   118 
   120 
   119 	c->title = XCreateWindow(dpy, root, c->x, c->y, c->w, barrect.height,
   121 	c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
   120 			0, DefaultDepth(dpy, screen), CopyFromParent,
   122 			0, DefaultDepth(dpy, screen), CopyFromParent,
   121 			DefaultVisual(dpy, screen),
   123 			DefaultVisual(dpy, screen),
   122 			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
   124 			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
   123 	update_name(c);
   125 	update_name(c);
   124 
   126 
   143 resize(Client *c)
   145 resize(Client *c)
   144 {
   146 {
   145 	XConfigureEvent e;
   147 	XConfigureEvent e;
   146 
   148 
   147 	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
   149 	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
   148 	XMoveResizeWindow(dpy, c->title, c->x + c->w / 3, c->y, 2 * c->w / 3, barrect.height);
       
   149 	e.type = ConfigureNotify;
   150 	e.type = ConfigureNotify;
   150 	e.event = c->win;
   151 	e.event = c->win;
   151 	e.window = c->win;
   152 	e.window = c->win;
   152 	e.x = c->x;
   153 	e.x = c->x;
   153 	e.y = c->y;
   154 	e.y = c->y;
   175 
   176 
   176 	XGrabServer(dpy);
   177 	XGrabServer(dpy);
   177 	XSetErrorHandler(dummy_error_handler);
   178 	XSetErrorHandler(dummy_error_handler);
   178 
   179 
   179 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
   180 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
   180 	XUnmapWindow(dpy, c->win);
       
   181 	XDestroyWindow(dpy, c->title);
   181 	XDestroyWindow(dpy, c->title);
   182 
   182 
   183 	for(l=&clients; *l && *l != c; l=&(*l)->next);
   183 	for(l=&clients; *l && *l != c; l=&(*l)->next);
   184 	eassert(*l == c);
   184 	eassert(*l == c);
   185 	*l = c->next;
   185 	*l = c->next;
   208 }
   208 }
   209 
   209 
   210 void
   210 void
   211 draw_client(Client *c)
   211 draw_client(Client *c)
   212 {
   212 {
   213 	if(!c)
       
   214 		return;
       
   215 	if(c == stack)
   213 	if(c == stack)
   216 		draw_bar();
   214 		draw_bar();
   217 
   215 
       
   216 	c->tw = textwidth(&brush.font, c->name) + labelheight(&brush.font);
       
   217 	c->tx = c->x + c->w - c->tw + 2;
       
   218 	c->ty = c->y;
       
   219 	XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
       
   220 
   218 	brush.rect.x = brush.rect.y = 0;
   221 	brush.rect.x = brush.rect.y = 0;
   219 	brush.rect.width = 2 * c->w / 3;
   222 	brush.rect.width = c->tw;
   220 	brush.rect.height = barrect.height;
   223 	brush.rect.height = c->th;
   221 
   224 
   222 	draw(dpy, &brush, True, c->name);
   225 	draw(dpy, &brush, True, c->name);
   223 	XCopyArea(dpy, brush.drawable, c->title, brush.gc, 0, 0,
   226 	XCopyArea(dpy, brush.drawable, c->title, brush.gc,
   224 			brush.rect.width, brush.rect.height, 0, 0);
   227 			0, 0, c->tw, c->th, 0, 0);
   225 	XFlush(dpy);
   228 	XFlush(dpy);
   226 }
   229 }