integrated yiyus mouse.diff (though the bar click handling is slightly broken, I'm to tired to debug it now, yiyus could you please?) 5cd65f8c
Anselm R Garbe · 2008-06-11 20:41 2 file(s) · +111 −74
config.def.h +59 −25
39 39
/* key definitions */
40 40
#define MODKEY Mod1Mask
41 41
#define TAGKEYS(KEY,TAG) \
42 -
        { MODKEY,                       KEY,      view,           TAG }, \
43 -
        { MODKEY|ControlMask,           KEY,      toggleview,     TAG }, \
44 -
        { MODKEY|ShiftMask,             KEY,      tag,            TAG }, \
45 -
        { MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      TAG },
42 +
	{ MODKEY,                       KEY,      view,           {.ui = 1 << TAG} }, \
43 +
	{ MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
44 +
	{ MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
45 +
	{ MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },
46 46
47 47
/* helper for spawning shell commands */
48 48
#define SHCMD(cmd) { .v = (char*[]){ "/bin/sh", "-c", cmd, NULL } }
51 51
	/* modifier                     key        function        argument */
52 52
	{ MODKEY,                       XK_p,      spawn,          {.v = (char *[]){"dmenu_run", "-fn", FONT, "-nb", NORMBGCOLOR, "-nf", NORMFGCOLOR, "-sb", SELBGCOLOR, "-sf", SELFGCOLOR, NULL}} },
53 53
	{ MODKEY|ShiftMask,             XK_Return, spawn,          {.v = (char *[]){"uxterm", NULL}} },
54 -
	{ MODKEY,                       XK_b,      togglebar,      {0}},
55 -
	{ MODKEY,                       XK_j,      focusstack,     {.i = +1  }},
56 -
	{ MODKEY,                       XK_k,      focusstack,     {.i = -1  }},
57 -
	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05}},
58 -
	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05}},
59 -
	{ MODKEY,                       XK_m,      togglemax,      {0}},
60 -
	{ MODKEY,                       XK_Return, zoom,           {0}},
61 -
	{ MODKEY,                       XK_Tab,    view,           {0}},
62 -
	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0}},
63 -
	{ MODKEY,                       XK_space,  togglelayout,   {0}},
64 -
	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0}},
54 +
	{ MODKEY,                       XK_b,      togglebar,      {0} },
55 +
	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
56 +
	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
57 +
	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
58 +
	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
59 +
	{ MODKEY,                       XK_m,      togglemax,      {0} },
60 +
	{ MODKEY,                       XK_Return, zoom,           {0} },
61 +
	{ MODKEY,                       XK_Tab,    view,           {0} },
62 +
	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
63 +
	{ MODKEY,                       XK_space,  togglelayout,   {0} },
64 +
	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
65 65
	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
66 66
	{ MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
67 -
	TAGKEYS(                        XK_1,                      {.ui = 1 << 0} )
68 -
	TAGKEYS(                        XK_2,                      {.ui = 1 << 1} )
69 -
	TAGKEYS(                        XK_3,                      {.ui = 1 << 2} )
70 -
	TAGKEYS(                        XK_4,                      {.ui = 1 << 3} )
71 -
	TAGKEYS(                        XK_5,                      {.ui = 1 << 4} )
72 -
	TAGKEYS(                        XK_6,                      {.ui = 1 << 5} )
73 -
	TAGKEYS(                        XK_7,                      {.ui = 1 << 6} )
74 -
	TAGKEYS(                        XK_8,                      {.ui = 1 << 7} )
75 -
	TAGKEYS(                        XK_9,                      {.ui = 1 << 8} )
76 -
	{ MODKEY|ShiftMask,             XK_q,      quit,           {0}},
67 +
	TAGKEYS(                        XK_1,                      0)
68 +
	TAGKEYS(                        XK_2,                      1)
69 +
	TAGKEYS(                        XK_3,                      2)
70 +
	TAGKEYS(                        XK_4,                      3)
71 +
	TAGKEYS(                        XK_5,                      4)
72 +
	TAGKEYS(                        XK_6,                      5)
73 +
	TAGKEYS(                        XK_7,                      6)
74 +
	TAGKEYS(                        XK_8,                      7)
75 +
	TAGKEYS(                        XK_9,                      8)
76 +
	{ MODKEY|ShiftMask,             XK_q,      quit,           {0} },
77 77
};
78 +
79 +
/* button definitions */
80 +
#define TAGBUTTONS(TAG) \
81 +
	{ TAG,                  0,              Button1,        view,           {.ui = 1 << TAG} }, \
82 +
	{ TAG,                  0,              Button3,        toggleview,     {.ui = 1 << TAG} }, \
83 +
	{ TAG,                  MODKEY,         Button1,        tag,            {.ui = 1 << TAG} }, \
84 +
	{ TAG,                  MODKEY,         Button3,        toggletag,      {.ui = 1 << TAG} },
85 +
86 +
/* click can be a tag number (starting at 0),
87 +
 * ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
88 +
static Button buttons[] = {
89 +
	/* click                event mask      button          function        argument */
90 +
	{ ClkLtSymbol,          0,              Button1,        togglelayout,   {0} },
91 +
	{ ClkLtSymbol,          0,              Button3,        togglemax,      {0} },
92 +
	{ ClkWinTitle,          0,              Button1,        movemouse,      {0} },
93 +
	{ ClkWinTitle,          0,              Button2,        zoom,           {0} },
94 +
	{ ClkWinTitle,          0,              Button3,        resizemouse,    {0} },
95 +
	{ ClkWinTitle,          0,              Button4,        focusstack,     {.i = +1 } },
96 +
	{ ClkWinTitle,          0,              Button5,        focusstack,     {.i = -1 } },
97 +
	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
98 +
	{ ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
99 +
	{ ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
100 +
	{ ClkRootWin,           Button1Mask,    Button3,        spawn,          {.v = (char *[]){"uxterm", NULL}} },
101 +
	TAGBUTTONS(0)
102 +
	TAGBUTTONS(1)
103 +
	TAGBUTTONS(2)
104 +
	TAGBUTTONS(3)
105 +
	TAGBUTTONS(4)
106 +
	TAGBUTTONS(5)
107 +
	TAGBUTTONS(6)
108 +
	TAGBUTTONS(7)
109 +
	TAGBUTTONS(8)
110 +
};
111 +
dwm.c +52 −49
59 59
enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
60 60
enum { NetSupported, NetWMName, NetLast };              /* EWMH atoms */
61 61
enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
62 +
enum { ClkLtSymbol = -1, ClkStatusText = -2, ClkWinTitle = -3,
63 +
       ClkClientWin = -4, ClkRootWin = -5, ClkLast = -6};/* clicks */
62 64
63 65
/* typedefs */
64 66
typedef unsigned int uint;
65 67
typedef unsigned long ulong;
68 +
69 +
typedef union {
70 +
	int i;
71 +
	uint ui;
72 +
	float f;
73 +
	void *v;
74 +
} Arg;
75 +
76 +
typedef struct {
77 +
	uint click;
78 +
	uint mask;
79 +
	uint button;
80 +
	void (*func)(const Arg *arg);
81 +
	const Arg arg;
82 +
} Button;
83 +
66 84
typedef struct Client Client;
67 85
struct Client {
68 86
	char name[256];
91 109
		XFontStruct *xfont;
92 110
	} font;
93 111
} DC; /* draw context */
94 -
95 -
typedef union {
96 -
	int i;
97 -
	uint ui;
98 -
	float f;
99 -
	void *v;
100 -
} Arg;
101 112
102 113
typedef struct {
103 114
	uint mod;
157 168
static void manage(Window w, XWindowAttributes *wa);
158 169
static void mappingnotify(XEvent *e);
159 170
static void maprequest(XEvent *e);
160 -
static void movemouse(Client *c);
171 +
static void movemouse(const Arg *arg);
161 172
static Client *nexttiled(Client *c);
162 173
static void propertynotify(XEvent *e);
163 174
static void quit(const Arg *arg);
164 175
static void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
165 -
static void resizemouse(Client *c);
176 +
static void resizemouse(const Arg *arg);
166 177
static void restack(void);
167 178
static void run(void);
168 179
static void scan(void);
297 308
298 309
void
299 310
buttonpress(XEvent *e) {
300 -
	uint i, mask;
301 -
	int x;
311 +
	uint i, x, click;
302 312
	Client *c;
303 313
	XButtonPressedEvent *ev = &e->xbutton;
304 314
315 +
	click = ClkRootWin;
305 316
	if(ev->window == barwin) {
306 317
		x = 0;
307 -
		for(i = 0; i < LENGTH(tags); i++) {
318 +
		for(i = 0; i < LENGTH(tags) && ev->x >= x; i++) {
308 319
			x += TEXTW(tags[i]);
309 -
			if(ev->x < x) {
310 -
				mask = 1 << i;
311 -
				if(ev->button == Button1) {
312 -
					if(ev->state & MODKEY)
313 -
						tag((Arg*)&mask);
314 -
					else
315 -
						view((Arg*)&mask);
316 -
				}
317 -
				else if(ev->button == Button3) {
318 -
					if(ev->state & MODKEY)
319 -
						toggletag((Arg*)&mask);
320 -
					else
321 -
						toggleview((Arg*)&mask);
322 -
				}
323 -
				return;
324 -
			}
320 +
			if(i < LENGTH(tags) || ev->x <= x)
321 +
				click = i - 1;
322 +
			else if(ev->x < x + blw)
323 +
				click = ClkLtSymbol;
324 +
			else if(ev->x > wx + ww - TEXTW(stext))
325 +
				click = ClkStatusText;
326 +
			else
327 +
				click = ClkWinTitle;
325 328
		}
326 -
		if(ev->x < x + blw) {
327 -
			if(ev->button == Button1)
328 -
				togglelayout(NULL);
329 -
			else if(ev->button == Button3)
330 -
				togglemax(NULL);
331 -
		}
332 -
	}
333 -
	else if((c = getclient(ev->window))) {
334 -
		focus(c);
335 -
		if(CLEANMASK(ev->state) != MODKEY || (ismax && !c->isfixed))
336 -
			return;
337 -
		if(ev->button == Button1)
338 -
			movemouse(c);
339 -
		else if(ev->button == Button2)
340 -
			togglefloating(NULL);
341 -
		else if(ev->button == Button3 && !c->isfixed)
342 -
			resizemouse(c);
343 329
	}
330 +
	else if((c = getclient(ev->window)))
331 +
		click = ClkClientWin;
332 +
333 +
	for(i = 0; i < LENGTH(buttons); i++)
334 +
		if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
335 +
			buttons[i].func(&buttons[i].arg);
344 336
}
345 337
346 338
void
971 963
}
972 964
973 965
void
974 -
movemouse(Client *c) {
966 +
movemouse(const Arg *arg) {
975 967
	int x1, y1, ocx, ocy, di, nx, ny;
976 968
	uint dui;
969 +
	Client *c;
977 970
	Window dummy;
978 971
	XEvent ev;
979 972
973 +
	if(!(c = sel))
974 +
		return;
980 975
	restack();
981 976
	ocx = nx = c->x;
982 977
	ocy = ny = c->y;
984 979
	None, cursor[CurMove], CurrentTime) != GrabSuccess)
985 980
		return;
986 981
	XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
982 +
	if(x1 < c->x || x1 > c->x + c->w || y1 < c->y || y1 > c->y + c->h) {
983 +
		XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, 0, 0);
984 +
		x1 = c->x + 1;
985 +
		y1 = c->y + 1;
986 +
	}
987 987
	for(;;) {
988 988
		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
989 989
		switch (ev.type) {
1131 1131
}
1132 1132
1133 1133
void
1134 -
resizemouse(Client *c) {
1134 +
resizemouse(const Arg *arg) {
1135 1135
	int ocx, ocy;
1136 1136
	int nw, nh;
1137 +
	Client *c;
1137 1138
	XEvent ev;
1138 1139
1140 +
	if(!(c = sel))
1141 +
		return;
1139 1142
	restack();
1140 1143
	ocx = c->x;
1141 1144
	ocy = c->y;
1377 1380
			PropModeReplace, (unsigned char *) netatom, NetLast);
1378 1381
1379 1382
	/* select for events */
1380 -
	wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask
1383 +
	wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask
1381 1384
			|EnterWindowMask|LeaveWindowMask|StructureNotifyMask;
1382 1385
	XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
1383 1386
	XSelectInput(dpy, root, wa.event_mask);
1643 1646
void
1644 1647
view(const Arg *arg) {
1645 1648
	seltags ^= 1; /* toggle sel tagset */
1646 -
	if(arg && (arg->ui & TAGMASK))
1649 +
	if(arg && (arg->ui & TAGMASK) && (arg->ui & TAGMASK) != tagset[seltags ^ 1])
1647 1650
		tagset[seltags] = arg->i & TAGMASK;
1648 1651
	arrange();
1649 1652
}