Browse Source

made code more readable

main
Anselm R. Garbe 18 years ago
parent
commit
a05beb6585
5 changed files with 67 additions and 70 deletions
  1. +30
    -20
      client.c
  2. +6
    -14
      event.c
  3. +1
    -1
      kb.c
  4. +25
    -27
      mouse.c
  5. +5
    -8
      wm.h

+ 30
- 20
client.c View File

@ -43,6 +43,24 @@ update_name(Client *c)
draw_client(c);
}
void
update_size(Client *c)
{
XSizeHints size;
long msize;
if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
size.flags = PSize;
c->flags = size.flags;
c->basew = size.base_width;
c->baseh = size.base_height;
c->incw = size.width_inc;
c->inch = size.height_inc;
c->maxw = size.max_width;
c->maxh = size.max_height;
c->minw = size.min_width;
c->minh = size.min_height;
}
void
focus(Client *c)
{
@ -62,31 +80,24 @@ manage(Window w, XWindowAttributes *wa)
{
Client *c, **l;
XSetWindowAttributes twa;
long msize;
c = emallocz(sizeof(Client));
c->win = w;
c->r[RFloat].x = wa->x;
c->r[RFloat].y = wa->y;
c->r[RFloat].width = wa->width;
c->r[RFloat].height = wa->height;
c->x = wa->x;
c->y = wa->y;
c->w = wa->width;
c->h = wa->height;
update_size(c);
XSetWindowBorderWidth(dpy, c->win, 1);
XSelectInput(dpy, c->win, CLIENT_MASK);
XGetTransientForHint(dpy, c->win, &c->trans);
if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
c->size.flags = PSize;
c->fixedsize =
(c->size.flags & PMinSize && c->size.flags & PMaxSize
&& c->size.min_width == c->size.max_width
&& c->size.min_height == c->size.max_height);
update_name(c);
twa.override_redirect = 1;
twa.background_pixmap = ParentRelative;
twa.event_mask = ExposureMask;
c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
c->r[RFloat].width, barrect.height, 0,
DefaultDepth(dpy, screen), CopyFromParent,
c->title = XCreateWindow(dpy, root, c->x, c->y, c->w, barrect.height,
0, DefaultDepth(dpy, screen), CopyFromParent,
DefaultVisual(dpy, screen),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
@ -110,15 +121,14 @@ resize(Client *c)
{
XConfigureEvent e;
XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y,
c->r[RFloat].width, c->r[RFloat].height);
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
e.type = ConfigureNotify;
e.event = c->win;
e.window = c->win;
e.x = c->r[RFloat].x;
e.y = c->r[RFloat].y;
e.width = c->r[RFloat].width;
e.height = c->r[RFloat].height;
e.x = c->x;
e.y = c->y;
e.width = c->w;
e.height = c->h;
e.border_width = 0;
e.above = None;
e.override_redirect = False;


+ 6
- 14
event.c View File

@ -79,13 +79,13 @@ configurerequest(XEvent *e)
ev->value_mask &= ~CWSibling;
if((c = getclient(ev->window))) {
if(ev->value_mask & CWX)
c->r[RFloat].x = ev->x;
c->x = ev->x;
if(ev->value_mask & CWY)
c->r[RFloat].y = ev->y;
c->y = ev->y;
if(ev->value_mask & CWWidth)
c->r[RFloat].width = ev->width;
c->w = ev->width;
if(ev->value_mask & CWHeight)
c->r[RFloat].height = ev->height;
c->h = ev->height;
}
wc.x = ev->x;
@ -179,7 +179,6 @@ static void
propertynotify(XEvent *e)
{
XPropertyEvent *ev = &e->xproperty;
long msize;
Client *c;
if(ev->state == PropertyDelete)
@ -195,16 +194,9 @@ propertynotify(XEvent *e)
case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &c->trans);
break;
update_size(c);
case XA_WM_NORMAL_HINTS:
if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize)
|| !c->size.flags)
c->size.flags = PSize;
if(c->size.flags & PMinSize && c->size.flags & PMaxSize
&& c->size.min_width == c->size.max_width
&& c->size.min_height == c->size.max_height)
c->fixedsize = True;
else
c->fixedsize = False;
update_size(c);
break;
}
if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {


+ 1
- 1
kb.c View File

@ -8,7 +8,7 @@
#include <X11/keysym.h>
static const char *term[] = {
"xterm", "-u8", "-bg", "black", "-fg", "white", "-fn",
"xterm", "-bg", "black", "-fg", "white", "-fn",
"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0
};


+ 25
- 27
mouse.c View File

@ -16,22 +16,22 @@
static void
mmatch(Client *c, int x1, int y1, int x2, int y2)
{
c->r[RFloat].width = abs(x1 - x2);
c->r[RFloat].height = abs(y1 - y2);
c->r[RFloat].width -=
(c->r[RFloat].width - c->size.base_width) % c->size class="p">.width_inc;
c->r[RFloat].height -=
(c->r[RFloat].height - c->size.base_height) % c->size.height_inc;
if(c->size.min_width && c->r[RFloat].width < c->size.min_width)
c->r[RFloat].width = c->size.min_width;
if(c->size.min_height && c->r[RFloat].height < c->size.min_height)
c->r[RFloat].height = c->size.min_height;
if(c->size.max_width && c->r[RFloat].width > c->size.max_width)
c->r[RFloat].width = c->size.max_width;
if(c->size.max_height && c->r[RFloat].height > c->size.max_height)
c->r[RFloat].height = c->size.max_height;
c->r[RFloat].x = (x1 <= x2) ? x1 : x1 - c->r[RFloat].width;
c->r[RFloat].y = (y1 <= y2) ? y1 : y1 - c->r[RFloat].height;
c->w = abs(x1 - x2);
c->h = abs(y1 - y2);
if(c->incw)
c->w -= (c->w - c->basew) % c->incw;
if(c->inch)
c->h -= (c->h - c->baseh) % c->inch;
if(c->minw && c->w < c->minw)
c->w = c->minw;
if(c->minh && c->h < c->minh)
c->h = c->minh;
if(c->maxw && c->w > c->maxw)
c->w = c->maxw;
if(c->maxh && c->h > c->maxh)
c->h = c->maxh;
c->x = (x1 <= x2) ? x1 : x1 - c->w;
c->y = (y1 <= y2) ? y1 : y1 - c->h;
}
void
@ -40,14 +40,13 @@ mresize(Client *c)
XEvent ev;
int old_cx, old_cy;
old_cx = c->r[RFloat].x;
old_cy = c->r[RFloat].y;
old_cx = c->x;
old_cy = c->y;
if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
None, cursor[CurResize], CurrentTime) != GrabSuccess)
return;
XGrabServer(dpy);
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
c->r[RFloat].width, c->r[RFloat].height);
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
for(;;) {
XMaskEvent(dpy, MouseMask, &ev);
switch(ev.type) {
@ -55,7 +54,7 @@ mresize(Client *c)
case MotionNotify:
XUngrabServer(dpy);
mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
XResizeWindow(dpy, c->win, c->r[RFloat].width, c->r[RFloat].height);
XResizeWindow(dpy, c->win, c->w, c->h);
XGrabServer(dpy);
break;
case ButtonRelease:
@ -75,8 +74,8 @@ mmove(Client *c)
unsigned int dui;
Window dummy;
old_cx = c->r[RFloat].x;
old_cy = c->r[RFloat].y;
old_cx = c->x;
old_cy = c->y;
if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
None, cursor[CurMove], CurrentTime) != GrabSuccess)
return;
@ -88,10 +87,9 @@ mmove(Client *c)
default: break;
case MotionNotify:
XUngrabServer(dpy);
c->r[RFloat].x = old_cx + (ev.xmotion.x - x1);
c->r[RFloat].y = old_cy + (ev.xmotion.y - y1);
XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y,
c->r[RFloat].width, c->r[RFloat].height);
c->x = old_cx + (ev.xmotion.x - x1);
c->y = old_cy + (ev.xmotion.y - y1);
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
XGrabServer(dpy);
break;
case ButtonRelease:


+ 5
- 8
wm.h View File

@ -21,19 +21,15 @@ enum { NetSupported, NetWMName, NetLast };
/* cursor */
enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
/* rects */
enum { RFloat, RGrid, RLast };
struct Client {
char name[256];
char tag[256];
char name[256], tag[256];
int proto;
Bool fixedsize;
int x, y, w, h;
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
long flags;
Window win;
Window trans;
Window title;
XSizeHints size;
XRectangle r[RLast];
Client *next;
Client *snext;
};
@ -75,6 +71,7 @@ extern void focus(Client *c);
extern void update_name(Client *c);
extern void draw_client(Client *c);
extern void resize(Client *c);
extern void update_size(Client *c);
/* event.c */
extern unsigned int discard_events(long even_mask);


Loading…
Cancel
Save