event.c
author arg@10ksloc.org
Fri, 21 Jul 2006 18:34:10 +0200
changeset 138 c1185dc7a36e
parent 137 77922a389fa8
child 139 22213b9a2114
permissions -rw-r--r--
some cleanups/fixes inspired by Jukka Salmi's feedback
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     1
/*
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     2
 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     3
 * See LICENSE file for license details.
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     4
 */
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
     5
#include "dwm.h"
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     6
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     7
#include <stdlib.h>
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     8
#include <X11/keysym.h>
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
     9
#include <X11/Xatom.h>
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    10
73
c2ddb9dbbd10 rearranged
Anselm R. Garbe <garbeam@wmii.de>
parents: 70
diff changeset
    11
#define ButtonMask      (ButtonPressMask | ButtonReleaseMask)
c2ddb9dbbd10 rearranged
Anselm R. Garbe <garbeam@wmii.de>
parents: 70
diff changeset
    12
#define MouseMask       (ButtonMask | PointerMotionMask)
c2ddb9dbbd10 rearranged
Anselm R. Garbe <garbeam@wmii.de>
parents: 70
diff changeset
    13
84
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 80
diff changeset
    14
/* CUSTOMIZE */
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 113
diff changeset
    15
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 113
diff changeset
    16
typedef struct {
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 113
diff changeset
    17
	unsigned long mod;
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 113
diff changeset
    18
	KeySym keysym;
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 113
diff changeset
    19
	void (*func)(Arg *arg);
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 113
diff changeset
    20
	Arg arg;
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 113
diff changeset
    21
} Key;
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 113
diff changeset
    22
111
2a1879e05d5a reapplied my default keybindings
arg@10ksloc.org
parents: 107
diff changeset
    23
const char *browse[] = { "firefox", NULL };
2a1879e05d5a reapplied my default keybindings
arg@10ksloc.org
parents: 107
diff changeset
    24
const char *gimp[] = { "gimp", NULL };
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    25
const char *term[] = { 
137
77922a389fa8 simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents: 133
diff changeset
    26
	"urxvt", "-tr", "+sb", "-bg", "black", "-fg", "white", "-cr", "white",
111
2a1879e05d5a reapplied my default keybindings
arg@10ksloc.org
parents: 107
diff changeset
    27
	"-fn", "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", NULL
2a1879e05d5a reapplied my default keybindings
arg@10ksloc.org
parents: 107
diff changeset
    28
};
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    29
const char *xlock[] = { "xlock", NULL };
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
    30
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 113
diff changeset
    31
static Key key[] = {
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    32
	/* modifier		key		function	arguments */
130
30d1302dbe3b sanitization of several clunky stuff, removed heretag (rarely of use), simplified pop(), changed shortcuts to always contain MODKEY
arg@10ksloc.org
parents: 125
diff changeset
    33
	{ MODKEY,		XK_0,		view,		{ .i = Tfnord } }, 
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    34
	{ MODKEY,		XK_1,		view,		{ .i = Tdev } }, 
130
30d1302dbe3b sanitization of several clunky stuff, removed heretag (rarely of use), simplified pop(), changed shortcuts to always contain MODKEY
arg@10ksloc.org
parents: 125
diff changeset
    35
	{ MODKEY,		XK_2,		view,		{ .i = Tnet } }, 
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    36
	{ MODKEY,		XK_3,		view,		{ .i = Twork } }, 
130
30d1302dbe3b sanitization of several clunky stuff, removed heretag (rarely of use), simplified pop(), changed shortcuts to always contain MODKEY
arg@10ksloc.org
parents: 125
diff changeset
    37
	{ MODKEY,		XK_4,		view,		{ .i = Tmisc} }, 
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    38
	{ MODKEY,		XK_j,		focusnext,	{ 0 } }, 
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    39
	{ MODKEY,		XK_k,		focusprev,	{ 0 } },
124
75576e44c1d8 made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents: 123
diff changeset
    40
	{ MODKEY,		XK_m,		togglemax,	{ 0 } }, 
75576e44c1d8 made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents: 123
diff changeset
    41
	{ MODKEY,		XK_space,	togglemode,	{ 0 } }, 
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    42
	{ MODKEY,		XK_Return,	zoom,		{ 0 } },
130
30d1302dbe3b sanitization of several clunky stuff, removed heretag (rarely of use), simplified pop(), changed shortcuts to always contain MODKEY
arg@10ksloc.org
parents: 125
diff changeset
    43
	{ MODKEY|ControlMask,	XK_0,		appendtag,	{ .i = Tfnord } }, 
30d1302dbe3b sanitization of several clunky stuff, removed heretag (rarely of use), simplified pop(), changed shortcuts to always contain MODKEY
arg@10ksloc.org
parents: 125
diff changeset
    44
	{ MODKEY|ControlMask,	XK_1,		appendtag,	{ .i = Tdev } }, 
30d1302dbe3b sanitization of several clunky stuff, removed heretag (rarely of use), simplified pop(), changed shortcuts to always contain MODKEY
arg@10ksloc.org
parents: 125
diff changeset
    45
	{ MODKEY|ControlMask,	XK_2,		appendtag,	{ .i = Tnet } }, 
30d1302dbe3b sanitization of several clunky stuff, removed heretag (rarely of use), simplified pop(), changed shortcuts to always contain MODKEY
arg@10ksloc.org
parents: 125
diff changeset
    46
	{ MODKEY|ControlMask,	XK_3,		appendtag,	{ .i = Twork } }, 
30d1302dbe3b sanitization of several clunky stuff, removed heretag (rarely of use), simplified pop(), changed shortcuts to always contain MODKEY
arg@10ksloc.org
parents: 125
diff changeset
    47
	{ MODKEY|ControlMask,	XK_4,		appendtag,	{ .i = Tmisc } }, 
30d1302dbe3b sanitization of several clunky stuff, removed heretag (rarely of use), simplified pop(), changed shortcuts to always contain MODKEY
arg@10ksloc.org
parents: 125
diff changeset
    48
	{ MODKEY|ShiftMask,	XK_0,		replacetag,	{ .i = Tfnord } }, 
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    49
	{ MODKEY|ShiftMask,	XK_1,		replacetag,	{ .i = Tdev } }, 
130
30d1302dbe3b sanitization of several clunky stuff, removed heretag (rarely of use), simplified pop(), changed shortcuts to always contain MODKEY
arg@10ksloc.org
parents: 125
diff changeset
    50
	{ MODKEY|ShiftMask,	XK_2,		replacetag,	{ .i = Tnet } }, 
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    51
	{ MODKEY|ShiftMask,	XK_3,		replacetag,	{ .i = Twork } }, 
130
30d1302dbe3b sanitization of several clunky stuff, removed heretag (rarely of use), simplified pop(), changed shortcuts to always contain MODKEY
arg@10ksloc.org
parents: 125
diff changeset
    52
	{ MODKEY|ShiftMask,	XK_4,		replacetag,	{ .i = Tmisc } }, 
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    53
	{ MODKEY|ShiftMask,	XK_c,		killclient,	{ 0 } }, 
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    54
	{ MODKEY|ShiftMask,	XK_g,		spawn,		{ .argv = gimp } },
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    55
	{ MODKEY|ShiftMask,	XK_l,		spawn,		{ .argv = xlock } },
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    56
	{ MODKEY|ShiftMask,	XK_q,		quit,		{ 0 } },
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    57
	{ MODKEY|ShiftMask,	XK_w,		spawn,		{ .argv = browse } },
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    58
	{ MODKEY|ShiftMask,	XK_Return,	spawn,		{ .argv = term } },
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
    59
};
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
    60
125
b4b8b4236599 cleaned the CUSTOMIZE flags
arg@10ksloc.org
parents: 124
diff changeset
    61
/* END CUSTOMIZE */
b4b8b4236599 cleaned the CUSTOMIZE flags
arg@10ksloc.org
parents: 124
diff changeset
    62
84
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 80
diff changeset
    63
/* static */
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
    64
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    65
static void
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    66
movemouse(Client *c)
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    67
{
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    68
	int x1, y1, ocx, ocy, di;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    69
	unsigned int dui;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    70
	Window dummy;
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    71
	XEvent ev;
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    72
115
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
    73
	ocx = c->x;
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
    74
	ocy = c->y;
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    75
	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
    76
			None, cursor[CurMove], CurrentTime) != GrabSuccess)
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    77
		return;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    78
	XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    79
	for(;;) {
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    80
		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    81
		switch (ev.type) {
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    82
		default: break;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    83
		case Expose:
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    84
			handler[Expose](&ev);
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    85
			break;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    86
		case MotionNotify:
79
aabebd6e61f3 fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents: 78
diff changeset
    87
			XSync(dpy, False);
115
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
    88
			c->x = ocx + (ev.xmotion.x - x1);
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
    89
			c->y = ocy + (ev.xmotion.y - y1);
99
a19556fe83b5 applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents: 95
diff changeset
    90
			resize(c, False, TopLeft);
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    91
			break;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    92
		case ButtonRelease:
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    93
			XUngrabPointer(dpy, CurrentTime);
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    94
			return;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    95
		}
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    96
	}
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    97
}
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    98
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
    99
static void
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   100
resizemouse(Client *c)
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   101
{
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   102
	int ocx, ocy;
99
a19556fe83b5 applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents: 95
diff changeset
   103
	Corner sticky;
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
   104
	XEvent ev;
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   105
115
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
   106
	ocx = c->x;
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
   107
	ocy = c->y;
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   108
	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   109
				None, cursor[CurResize], CurrentTime) != GrabSuccess)
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   110
		return;
115
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
   111
	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   112
	for(;;) {
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   113
		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   114
		switch(ev.type) {
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   115
		default: break;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   116
		case Expose:
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   117
			handler[Expose](&ev);
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   118
			break;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   119
		case MotionNotify:
79
aabebd6e61f3 fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents: 78
diff changeset
   120
			XSync(dpy, False);
115
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
   121
			c->w = abs(ocx - ev.xmotion.x);
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
   122
			c->h = abs(ocy - ev.xmotion.y);
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
   123
			c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
   124
			c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
105
3e74cc981e9b refactored Sanders code somewhat
arg@10ksloc.org
parents: 99
diff changeset
   125
			if(ocx <= ev.xmotion.x)
3e74cc981e9b refactored Sanders code somewhat
arg@10ksloc.org
parents: 99
diff changeset
   126
				sticky = (ocy <= ev.xmotion.y) ? TopLeft : BotLeft;
3e74cc981e9b refactored Sanders code somewhat
arg@10ksloc.org
parents: 99
diff changeset
   127
			else
3e74cc981e9b refactored Sanders code somewhat
arg@10ksloc.org
parents: 99
diff changeset
   128
				sticky = (ocy <= ev.xmotion.y) ? TopRight : BotRight;
99
a19556fe83b5 applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents: 95
diff changeset
   129
			resize(c, True, sticky);
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   130
			break;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   131
		case ButtonRelease:
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   132
			XUngrabPointer(dpy, CurrentTime);
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   133
			return;
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   134
		}
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   135
	}
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   136
}
73
c2ddb9dbbd10 rearranged
Anselm R. Garbe <garbeam@wmii.de>
parents: 70
diff changeset
   137
c2ddb9dbbd10 rearranged
Anselm R. Garbe <garbeam@wmii.de>
parents: 70
diff changeset
   138
static void
18
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   139
buttonpress(XEvent *e)
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   140
{
73
c2ddb9dbbd10 rearranged
Anselm R. Garbe <garbeam@wmii.de>
parents: 70
diff changeset
   141
	int x;
c2ddb9dbbd10 rearranged
Anselm R. Garbe <garbeam@wmii.de>
parents: 70
diff changeset
   142
	Arg a;
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
   143
	Client *c;
18
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   144
	XButtonPressedEvent *ev = &e->xbutton;
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   145
73
c2ddb9dbbd10 rearranged
Anselm R. Garbe <garbeam@wmii.de>
parents: 70
diff changeset
   146
	if(barwin == ev->window) {
80
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   147
		switch(ev->button) {
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   148
		default:
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   149
			x = 0;
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   150
			for(a.i = 0; a.i < TLast; a.i++) {
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   151
				x += textw(tags[a.i]);
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   152
				if(ev->x < x) {
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   153
					view(&a);
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   154
					break;
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   155
				}
73
c2ddb9dbbd10 rearranged
Anselm R. Garbe <garbeam@wmii.de>
parents: 70
diff changeset
   156
			}
80
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   157
			break;
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   158
		case Button4:
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   159
			a.i = (tsel + 1 < TLast) ? tsel + 1 : 0;
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   160
			view(&a);
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   161
			break;
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   162
		case Button5:
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   163
			a.i = (tsel - 1 >= 0) ? tsel - 1 : TLast - 1;
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   164
			view(&a);
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   165
			break;
73
c2ddb9dbbd10 rearranged
Anselm R. Garbe <garbeam@wmii.de>
parents: 70
diff changeset
   166
		}
c2ddb9dbbd10 rearranged
Anselm R. Garbe <garbeam@wmii.de>
parents: 70
diff changeset
   167
	}
58
1269bd127551 made barclick to select the specific tag
Anselm R. Garbe <garbeam@wmii.de>
parents: 55
diff changeset
   168
	else if((c = getclient(ev->window))) {
18
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   169
		switch(ev->button) {
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   170
		default:
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   171
			break;
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   172
		case Button1:
133
467ad2d3a6fa applied sanders maxfix patch
arg@10ksloc.org
parents: 130
diff changeset
   173
			if(!c->ismax && (arrange == dofloat || c->isfloat)) {
99
a19556fe83b5 applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents: 95
diff changeset
   174
				higher(c);
a19556fe83b5 applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents: 95
diff changeset
   175
				movemouse(c);
a19556fe83b5 applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents: 95
diff changeset
   176
			}
18
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   177
			break;
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   178
		case Button2:
26
e8f627998d6f simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents: 25
diff changeset
   179
			lower(c);
18
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   180
			break;
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   181
		case Button3:
133
467ad2d3a6fa applied sanders maxfix patch
arg@10ksloc.org
parents: 130
diff changeset
   182
			if(!c->ismax && (arrange == dofloat || c->isfloat)) {
99
a19556fe83b5 applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents: 95
diff changeset
   183
				higher(c);
a19556fe83b5 applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents: 95
diff changeset
   184
				resizemouse(c);
a19556fe83b5 applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents: 95
diff changeset
   185
			}
18
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   186
			break;
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   187
		}
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   188
	}
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   189
}
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   190
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   191
static void
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   192
configurerequest(XEvent *e)
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   193
{
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
   194
	Client *c;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   195
	XConfigureRequestEvent *ev = &e->xconfigurerequest;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   196
	XWindowChanges wc;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   197
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   198
	ev->value_mask &= ~CWSibling;
18
1efa34c6e1b6 added mouse-based resizals
Anselm R. Garbe <garbeam@wmii.de>
parents: 16
diff changeset
   199
	if((c = getclient(ev->window))) {
29
8ad86d0a6a53 added gravity stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 26
diff changeset
   200
		gravitate(c, True);
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   201
		if(ev->value_mask & CWX)
115
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
   202
			c->x = ev->x;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   203
		if(ev->value_mask & CWY)
115
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
   204
			c->y = ev->y;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   205
		if(ev->value_mask & CWWidth)
115
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
   206
			c->w = ev->width;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   207
		if(ev->value_mask & CWHeight)
115
329fd7dae530 removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling remembering two kinds of geometries is unnecessary, removed the randomized (x,y) setting on dofloat startup, was kind too random und unpredictable
arg@10ksloc.org
parents: 114
diff changeset
   208
			c->h = ev->height;
29
8ad86d0a6a53 added gravity stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 26
diff changeset
   209
		if(ev->value_mask & CWBorderWidth)
55
fcbf7213d96f continued with man page
Anselm R. Garbe <garbeam@wmii.de>
parents: 53
diff changeset
   210
			c->border = 1;
29
8ad86d0a6a53 added gravity stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 26
diff changeset
   211
		gravitate(c, False);
99
a19556fe83b5 applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents: 95
diff changeset
   212
		resize(c, True, TopLeft);
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   213
	}
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   214
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   215
	wc.x = ev->x;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   216
	wc.y = ev->y;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   217
	wc.width = ev->width;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   218
	wc.height = ev->height;
25
e238dc4844d7 fixed configurerequest
Anselm R. Garbe <garbeam@wmii.de>
parents: 23
diff changeset
   219
	wc.border_width = 1;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   220
	wc.sibling = None;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   221
	wc.stack_mode = Above;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   222
	ev->value_mask &= ~CWStackMode;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   223
	ev->value_mask |= CWBorderWidth;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   224
	XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
79
aabebd6e61f3 fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents: 78
diff changeset
   225
	XSync(dpy, False);
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   226
}
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   227
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   228
static void
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   229
destroynotify(XEvent *e)
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   230
{
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   231
	Client *c;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   232
	XDestroyWindowEvent *ev = &e->xdestroywindow;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   233
11
ea9c08ec4b48 added gridsel to gridwm
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   234
	if((c = getclient(ev->window)))
ea9c08ec4b48 added gridsel to gridwm
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
   235
		unmanage(c);
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   236
}
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   237
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   238
static void
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   239
enternotify(XEvent *e)
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   240
{
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
   241
	Client *c;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   242
	XCrossingEvent *ev = &e->xcrossing;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   243
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   244
	if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   245
		return;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   246
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   247
	if((c = getclient(ev->window)))
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   248
		focus(c);
26
e8f627998d6f simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents: 25
diff changeset
   249
	else if(ev->window == root)
31
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
   250
		issel = True;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   251
}
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   252
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   253
static void
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   254
expose(XEvent *e)
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   255
{
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
   256
	Client *c;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   257
	XExposeEvent *ev = &e->xexpose;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   258
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   259
	if(ev->count == 0) {
70
e5fff8249705 draw bar on exposure ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 63
diff changeset
   260
		if(barwin == ev->window)
74
5370ef170cc9 sanitized names
Anselm R. Garbe <garbeam@wmii.de>
parents: 73
diff changeset
   261
			drawstatus();
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   262
		else if((c = getctitle(ev->window)))
74
5370ef170cc9 sanitized names
Anselm R. Garbe <garbeam@wmii.de>
parents: 73
diff changeset
   263
			drawtitle(c);
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   264
	}
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   265
}
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   266
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   267
static void
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   268
keypress(XEvent *e)
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   269
{
138
c1185dc7a36e some cleanups/fixes inspired by Jukka Salmi's feedback
arg@10ksloc.org
parents: 137
diff changeset
   270
	static unsigned int len = sizeof(key) / sizeof(key[0]);
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   271
	unsigned int i;
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   272
	KeySym keysym;
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
   273
	XKeyEvent *ev = &e->xkey;
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   274
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   275
	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   276
	for(i = 0; i < len; i++)
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   277
		if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   278
			if(key[i].func)
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   279
				key[i].func(&key[i].arg);
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   280
			return;
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   281
		}
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   282
}
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   283
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   284
static void
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   285
leavenotify(XEvent *e)
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   286
{
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   287
	XCrossingEvent *ev = &e->xcrossing;
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   288
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   289
	if((ev->window == root) && !ev->same_screen)
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   290
		issel = True;
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   291
}
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   292
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   293
static void
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   294
maprequest(XEvent *e)
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   295
{
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
   296
	static XWindowAttributes wa;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   297
	XMapRequestEvent *ev = &e->xmaprequest;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   298
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   299
	if(!XGetWindowAttributes(dpy, ev->window, &wa))
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   300
		return;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   301
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   302
	if(wa.override_redirect) {
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   303
		XSelectInput(dpy, ev->window,
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   304
				(StructureNotifyMask | PropertyChangeMask));
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   305
		return;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   306
	}
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   307
10
703255003abb changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents: 9
diff changeset
   308
	if(!getclient(ev->window))
703255003abb changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents: 9
diff changeset
   309
		manage(ev->window, &wa);
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   310
}
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   311
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   312
static void
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   313
propertynotify(XEvent *e)
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   314
{
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
   315
	Client *c;
53
529901e6a227 added mini stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 43
diff changeset
   316
	Window trans;
123
61490330e90a cleaned up code
arg@10ksloc.org
parents: 121
diff changeset
   317
	XPropertyEvent *ev = &e->xproperty;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   318
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   319
	if(ev->state == PropertyDelete)
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   320
		return; /* ignore */
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   321
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   322
	if((c = getclient(ev->window))) {
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   323
		if(ev->atom == wmatom[WMProtocols]) {
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 74
diff changeset
   324
			c->proto = getproto(c->win);
30
2e0fb4130bfb new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents: 29
diff changeset
   325
			return;
2e0fb4130bfb new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents: 29
diff changeset
   326
		}
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   327
		switch (ev->atom) {
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   328
			default: break;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   329
			case XA_WM_TRANSIENT_FOR:
53
529901e6a227 added mini stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 43
diff changeset
   330
				XGetTransientForHint(dpy, c->win, &trans);
80
8125f908c80c several additions in mouse handling ;)
Anselm R. Garbe <garbeam@wmii.de>
parents: 79
diff changeset
   331
				if(!c->isfloat && (c->isfloat = (trans != 0)))
53
529901e6a227 added mini stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 43
diff changeset
   332
					arrange(NULL);
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   333
				break;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   334
			case XA_WM_NORMAL_HINTS:
74
5370ef170cc9 sanitized names
Anselm R. Garbe <garbeam@wmii.de>
parents: 73
diff changeset
   335
				setsize(c);
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   336
				break;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   337
		}
77
38c8f7f7d401 sanitized other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 76
diff changeset
   338
		if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
74
5370ef170cc9 sanitized names
Anselm R. Garbe <garbeam@wmii.de>
parents: 73
diff changeset
   339
			settitle(c);
5370ef170cc9 sanitized names
Anselm R. Garbe <garbeam@wmii.de>
parents: 73
diff changeset
   340
			drawtitle(c);
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   341
		}
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 11
diff changeset
   342
	}
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   343
}
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   344
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   345
static void
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   346
unmapnotify(XEvent *e)
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   347
{
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   348
	Client *c;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   349
	XUnmapEvent *ev = &e->xunmap;
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   350
10
703255003abb changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents: 9
diff changeset
   351
	if((c = getclient(ev->window)))
703255003abb changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents: 9
diff changeset
   352
		unmanage(c);
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
   353
}
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   354
84
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 80
diff changeset
   355
/* extern */
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   356
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   357
void (*handler[LASTEvent]) (XEvent *) = {
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   358
	[ButtonPress] = buttonpress,
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   359
	[ConfigureRequest] = configurerequest,
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   360
	[DestroyNotify] = destroynotify,
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   361
	[EnterNotify] = enternotify,
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   362
	[LeaveNotify] = leavenotify,
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   363
	[Expose] = expose,
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   364
	[KeyPress] = keypress,
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   365
	[MapRequest] = maprequest,
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   366
	[PropertyNotify] = propertynotify,
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   367
	[UnmapNotify] = unmapnotify
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   368
};
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   369
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   370
void
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   371
grabkeys()
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   372
{
138
c1185dc7a36e some cleanups/fixes inspired by Jukka Salmi's feedback
arg@10ksloc.org
parents: 137
diff changeset
   373
	static unsigned int len = sizeof(key) / sizeof(key[0]);
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   374
	unsigned int i;
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   375
	KeyCode code;
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   376
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   377
	for(i = 0; i < len; i++) {
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   378
		code = XKeysymToKeycode(dpy, key[i].keysym);
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   379
		XUngrabKey(dpy, code, key[i].mod, root);
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   380
		XGrabKey(dpy, code, key[i].mod, root, True,
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   381
				GrabModeAsync, GrabModeAsync);
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   382
	}
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   383
}