aewl

diff client.c @ 76:4bd49f404f10

proceeded with cleaning up, sorting functions, etc
author Anselm R. Garbe <garbeam@wmii.de>
date Sat, 15 Jul 2006 17:00:56 +0200
parents f08271b7cb20
children 38c8f7f7d401
line diff
     1.1 --- a/client.c	Sat Jul 15 16:30:50 2006 +0200
     1.2 +++ b/client.c	Sat Jul 15 17:00:56 2006 +0200
     1.3 @@ -2,21 +2,14 @@
     1.4   * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
     1.5   * See LICENSE file for license details.
     1.6   */
     1.7 +#include "dwm.h"
     1.8  
     1.9  #include <stdlib.h>
    1.10 -#include <stdio.h>
    1.11  #include <string.h>
    1.12  #include <X11/Xatom.h>
    1.13  #include <X11/Xutil.h>
    1.14  
    1.15 -#include "dwm.h"
    1.16 -
    1.17 -void
    1.18 -ban(Client *c)
    1.19 -{
    1.20 -	XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
    1.21 -	XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
    1.22 -}
    1.23 +/* static functions */
    1.24  
    1.25  static void
    1.26  resizetitle(Client *c)
    1.27 @@ -35,84 +28,19 @@
    1.28  	XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
    1.29  }
    1.30  
    1.31 -void
    1.32 -settitle(Client *c)
    1.33 +static int
    1.34 +xerrordummy(Display *dsply, XErrorEvent *ee)
    1.35  {
    1.36 -	XTextProperty name;
    1.37 -	int n;
    1.38 -	char **list = NULL;
    1.39 -
    1.40 -	name.nitems = 0;
    1.41 -	c->name[0] = 0;
    1.42 -	XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
    1.43 -	if(!name.nitems)
    1.44 -		XGetWMName(dpy, c->win, &name);
    1.45 -	if(!name.nitems)
    1.46 -		return;
    1.47 -	if(name.encoding == XA_STRING)
    1.48 -		strncpy(c->name, (char *)name.value, sizeof(c->name));
    1.49 -	else {
    1.50 -		if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
    1.51 -				&& n > 0 && *list)
    1.52 -		{
    1.53 -			strncpy(c->name, *list, sizeof(c->name));
    1.54 -			XFreeStringList(list);
    1.55 -		}
    1.56 -	}
    1.57 -	XFree(name.value);
    1.58 -	resizetitle(c);
    1.59 +	return 0;
    1.60  }
    1.61  
    1.62 -void
    1.63 -setsize(Client *c)
    1.64 -{
    1.65 -	XSizeHints size;
    1.66 -	long msize;
    1.67 -	if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
    1.68 -		size.flags = PSize;
    1.69 -	c->flags = size.flags;
    1.70 -	if(c->flags & PBaseSize) {
    1.71 -		c->basew = size.base_width;
    1.72 -		c->baseh = size.base_height;
    1.73 -	}
    1.74 -	else
    1.75 -		c->basew = c->baseh = 0;
    1.76 -	if(c->flags & PResizeInc) {
    1.77 -		c->incw = size.width_inc;
    1.78 -		c->inch = size.height_inc;
    1.79 -	}
    1.80 -	else
    1.81 -		c->incw = c->inch = 0;
    1.82 -	if(c->flags & PMaxSize) {
    1.83 -		c->maxw = size.max_width;
    1.84 -		c->maxh = size.max_height;
    1.85 -	}
    1.86 -	else
    1.87 -		c->maxw = c->maxh = 0;
    1.88 -	if(c->flags & PMinSize) {
    1.89 -		c->minw = size.min_width;
    1.90 -		c->minh = size.min_height;
    1.91 -	}
    1.92 -	else
    1.93 -		c->minw = c->minh = 0;
    1.94 -	if(c->flags & PWinGravity)
    1.95 -		c->grav = size.win_gravity;
    1.96 -	else
    1.97 -		c->grav = NorthWestGravity;
    1.98 -}
    1.99 +/* extern functions */
   1.100  
   1.101  void
   1.102 -higher(Client *c)
   1.103 +ban(Client *c)
   1.104  {
   1.105 -	XRaiseWindow(dpy, c->win);
   1.106 -	XRaiseWindow(dpy, c->title);
   1.107 -}
   1.108 -
   1.109 -void
   1.110 -lower(Client *c)
   1.111 -{
   1.112 -	XLowerWindow(dpy, c->title);
   1.113 -	XLowerWindow(dpy, c->win);
   1.114 +	XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
   1.115 +	XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
   1.116  }
   1.117  
   1.118  void
   1.119 @@ -132,6 +60,137 @@
   1.120  }
   1.121  
   1.122  void
   1.123 +focusnext(Arg *arg)
   1.124 +{
   1.125 +	Client *c;
   1.126 +   
   1.127 +	if(!sel)
   1.128 +		return;
   1.129 +
   1.130 +	if(!(c = getnext(sel->next)))
   1.131 +		c = getnext(clients);
   1.132 +	if(c) {
   1.133 +		higher(c);
   1.134 +		c->revert = sel;
   1.135 +		focus(c);
   1.136 +	}
   1.137 +}
   1.138 +
   1.139 +void
   1.140 +focusprev(Arg *arg)
   1.141 +{
   1.142 +	Client *c;
   1.143 +
   1.144 +	if(!sel)
   1.145 +		return;
   1.146 +
   1.147 +	if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
   1.148 +		higher(c);
   1.149 +		focus(c);
   1.150 +	}
   1.151 +}
   1.152 +
   1.153 +Client *
   1.154 +getclient(Window w)
   1.155 +{
   1.156 +	Client *c;
   1.157 +	for(c = clients; c; c = c->next)
   1.158 +		if(c->win == w)
   1.159 +			return c;
   1.160 +	return NULL;
   1.161 +}
   1.162 +
   1.163 +Client *
   1.164 +getctitle(Window w)
   1.165 +{
   1.166 +	Client *c;
   1.167 +	for(c = clients; c; c = c->next)
   1.168 +		if(c->title == w)
   1.169 +			return c;
   1.170 +	return NULL;
   1.171 +}
   1.172 +
   1.173 +void
   1.174 +gravitate(Client *c, Bool invert)
   1.175 +{
   1.176 +	int dx = 0, dy = 0;
   1.177 +
   1.178 +	switch(c->grav) {
   1.179 +	case StaticGravity:
   1.180 +	case NorthWestGravity:
   1.181 +	case NorthGravity:
   1.182 +	case NorthEastGravity:
   1.183 +		dy = c->border;
   1.184 +		break;
   1.185 +	case EastGravity:
   1.186 +	case CenterGravity:
   1.187 +	case WestGravity:
   1.188 +		dy = -(c->h / 2) + c->border;
   1.189 +		break;
   1.190 +	case SouthEastGravity:
   1.191 +	case SouthGravity:
   1.192 +	case SouthWestGravity:
   1.193 +		dy = -c->h;
   1.194 +		break;
   1.195 +	default:
   1.196 +		break;
   1.197 +	}
   1.198 +
   1.199 +	switch (c->grav) {
   1.200 +	case StaticGravity:
   1.201 +	case NorthWestGravity:
   1.202 +	case WestGravity:
   1.203 +	case SouthWestGravity:
   1.204 +		dx = c->border;
   1.205 +		break;
   1.206 +	case NorthGravity:
   1.207 +	case CenterGravity:
   1.208 +	case SouthGravity:
   1.209 +		dx = -(c->w / 2) + c->border;
   1.210 +		break;
   1.211 +	case NorthEastGravity:
   1.212 +	case EastGravity:
   1.213 +	case SouthEastGravity:
   1.214 +		dx = -(c->w + c->border);
   1.215 +		break;
   1.216 +	default:
   1.217 +		break;
   1.218 +	}
   1.219 +
   1.220 +	if(invert) {
   1.221 +		dx = -dx;
   1.222 +		dy = -dy;
   1.223 +	}
   1.224 +	c->x += dx;
   1.225 +	c->y += dy;
   1.226 +}
   1.227 +
   1.228 +void
   1.229 +higher(Client *c)
   1.230 +{
   1.231 +	XRaiseWindow(dpy, c->win);
   1.232 +	XRaiseWindow(dpy, c->title);
   1.233 +}
   1.234 +
   1.235 +void
   1.236 +killclient(Arg *arg)
   1.237 +{
   1.238 +	if(!sel)
   1.239 +		return;
   1.240 +	if(sel->proto & WM_PROTOCOL_DELWIN)
   1.241 +		sendevent(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
   1.242 +	else
   1.243 +		XKillClient(dpy, sel->win);
   1.244 +}
   1.245 +
   1.246 +void
   1.247 +lower(Client *c)
   1.248 +{
   1.249 +	XLowerWindow(dpy, c->title);
   1.250 +	XLowerWindow(dpy, c->win);
   1.251 +}
   1.252 +
   1.253 +void
   1.254  manage(Window w, XWindowAttributes *wa)
   1.255  {
   1.256  	Client *c, **l;
   1.257 @@ -195,61 +254,18 @@
   1.258  }
   1.259  
   1.260  void
   1.261 -gravitate(Client *c, Bool invert)
   1.262 +maximize(Arg *arg)
   1.263  {
   1.264 -	int dx = 0, dy = 0;
   1.265 -
   1.266 -	switch(c->grav) {
   1.267 -	case StaticGravity:
   1.268 -	case NorthWestGravity:
   1.269 -	case NorthGravity:
   1.270 -	case NorthEastGravity:
   1.271 -		dy = c->border;
   1.272 -		break;
   1.273 -	case EastGravity:
   1.274 -	case CenterGravity:
   1.275 -	case WestGravity:
   1.276 -		dy = -(c->h / 2) + c->border;
   1.277 -		break;
   1.278 -	case SouthEastGravity:
   1.279 -	case SouthGravity:
   1.280 -	case SouthWestGravity:
   1.281 -		dy = -c->h;
   1.282 -		break;
   1.283 -	default:
   1.284 -		break;
   1.285 -	}
   1.286 -
   1.287 -	switch (c->grav) {
   1.288 -	case StaticGravity:
   1.289 -	case NorthWestGravity:
   1.290 -	case WestGravity:
   1.291 -	case SouthWestGravity:
   1.292 -		dx = c->border;
   1.293 -		break;
   1.294 -	case NorthGravity:
   1.295 -	case CenterGravity:
   1.296 -	case SouthGravity:
   1.297 -		dx = -(c->w / 2) + c->border;
   1.298 -		break;
   1.299 -	case NorthEastGravity:
   1.300 -	case EastGravity:
   1.301 -	case SouthEastGravity:
   1.302 -		dx = -(c->w + c->border);
   1.303 -		break;
   1.304 -	default:
   1.305 -		break;
   1.306 -	}
   1.307 -
   1.308 -	if(invert) {
   1.309 -		dx = -dx;
   1.310 -		dy = -dy;
   1.311 -	}
   1.312 -	c->x += dx;
   1.313 -	c->y += dy;
   1.314 +	if(!sel)
   1.315 +		return;
   1.316 +	sel->x = sx;
   1.317 +	sel->y = sy + bh;
   1.318 +	sel->w = sw - 2 * sel->border;
   1.319 +	sel->h = sh - 2 * sel->border - bh;
   1.320 +	higher(sel);
   1.321 +	resize(sel, False);
   1.322  }
   1.323  
   1.324 -
   1.325  void
   1.326  resize(Client *c, Bool inc)
   1.327  {
   1.328 @@ -290,10 +306,70 @@
   1.329  	XFlush(dpy);
   1.330  }
   1.331  
   1.332 -static int
   1.333 -xerrordummy(Display *dsply, XErrorEvent *ee)
   1.334 +void
   1.335 +setsize(Client *c)
   1.336  {
   1.337 -	return 0;
   1.338 +	XSizeHints size;
   1.339 +	long msize;
   1.340 +	if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
   1.341 +		size.flags = PSize;
   1.342 +	c->flags = size.flags;
   1.343 +	if(c->flags & PBaseSize) {
   1.344 +		c->basew = size.base_width;
   1.345 +		c->baseh = size.base_height;
   1.346 +	}
   1.347 +	else
   1.348 +		c->basew = c->baseh = 0;
   1.349 +	if(c->flags & PResizeInc) {
   1.350 +		c->incw = size.width_inc;
   1.351 +		c->inch = size.height_inc;
   1.352 +	}
   1.353 +	else
   1.354 +		c->incw = c->inch = 0;
   1.355 +	if(c->flags & PMaxSize) {
   1.356 +		c->maxw = size.max_width;
   1.357 +		c->maxh = size.max_height;
   1.358 +	}
   1.359 +	else
   1.360 +		c->maxw = c->maxh = 0;
   1.361 +	if(c->flags & PMinSize) {
   1.362 +		c->minw = size.min_width;
   1.363 +		c->minh = size.min_height;
   1.364 +	}
   1.365 +	else
   1.366 +		c->minw = c->minh = 0;
   1.367 +	if(c->flags & PWinGravity)
   1.368 +		c->grav = size.win_gravity;
   1.369 +	else
   1.370 +		c->grav = NorthWestGravity;
   1.371 +}
   1.372 +
   1.373 +void
   1.374 +settitle(Client *c)
   1.375 +{
   1.376 +	XTextProperty name;
   1.377 +	int n;
   1.378 +	char **list = NULL;
   1.379 +
   1.380 +	name.nitems = 0;
   1.381 +	c->name[0] = 0;
   1.382 +	XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
   1.383 +	if(!name.nitems)
   1.384 +		XGetWMName(dpy, c->win, &name);
   1.385 +	if(!name.nitems)
   1.386 +		return;
   1.387 +	if(name.encoding == XA_STRING)
   1.388 +		strncpy(c->name, (char *)name.value, sizeof(c->name));
   1.389 +	else {
   1.390 +		if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
   1.391 +				&& n > 0 && *list)
   1.392 +		{
   1.393 +			strncpy(c->name, *list, sizeof(c->name));
   1.394 +			XFreeStringList(list);
   1.395 +		}
   1.396 +	}
   1.397 +	XFree(name.value);
   1.398 +	resizetitle(c);
   1.399  }
   1.400  
   1.401  void
   1.402 @@ -325,26 +401,6 @@
   1.403  		focus(sel);
   1.404  }
   1.405  
   1.406 -Client *
   1.407 -getctitle(Window w)
   1.408 -{
   1.409 -	Client *c;
   1.410 -	for(c = clients; c; c = c->next)
   1.411 -		if(c->title == w)
   1.412 -			return c;
   1.413 -	return NULL;
   1.414 -}
   1.415 -
   1.416 -Client *
   1.417 -getclient(Window w)
   1.418 -{
   1.419 -	Client *c;
   1.420 -	for(c = clients; c; c = c->next)
   1.421 -		if(c->win == w)
   1.422 -			return c;
   1.423 -	return NULL;
   1.424 -}
   1.425 -
   1.426  void
   1.427  zoom(Arg *arg)
   1.428  {
   1.429 @@ -366,58 +422,3 @@
   1.430  	arrange(NULL);
   1.431  	focus(sel);
   1.432  }
   1.433 -
   1.434 -void
   1.435 -maximize(Arg *arg)
   1.436 -{
   1.437 -	if(!sel)
   1.438 -		return;
   1.439 -	sel->x = sx;
   1.440 -	sel->y = sy + bh;
   1.441 -	sel->w = sw - 2 * sel->border;
   1.442 -	sel->h = sh - 2 * sel->border - bh;
   1.443 -	higher(sel);
   1.444 -	resize(sel, False);
   1.445 -}
   1.446 -
   1.447 -void
   1.448 -focusprev(Arg *arg)
   1.449 -{
   1.450 -	Client *c;
   1.451 -
   1.452 -	if(!sel)
   1.453 -		return;
   1.454 -
   1.455 -	if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
   1.456 -		higher(c);
   1.457 -		focus(c);
   1.458 -	}
   1.459 -}
   1.460 -
   1.461 -void
   1.462 -focusnext(Arg *arg)
   1.463 -{
   1.464 -	Client *c;
   1.465 -   
   1.466 -	if(!sel)
   1.467 -		return;
   1.468 -
   1.469 -	if(!(c = getnext(sel->next)))
   1.470 -		c = getnext(clients);
   1.471 -	if(c) {
   1.472 -		higher(c);
   1.473 -		c->revert = sel;
   1.474 -		focus(c);
   1.475 -	}
   1.476 -}
   1.477 -
   1.478 -void
   1.479 -killclient(Arg *arg)
   1.480 -{
   1.481 -	if(!sel)
   1.482 -		return;
   1.483 -	if(sel->proto & WM_PROTOCOL_DELWIN)
   1.484 -		sendevent(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
   1.485 -	else
   1.486 -		XKillClient(dpy, sel->win);
   1.487 -}