summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-11 21:24:10 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-11 21:24:10 +0200
commitb9da4b082eb658b4142b61c149212f414f7653b6 (patch)
tree146a4e480866d1497c3ec3ccf2b71305b07a5f03
parentupdated README (diff)
downloaddwm-b9da4b082eb658b4142b61c149212f414f7653b6.tar.gz
dwm-b9da4b082eb658b4142b61c149212f414f7653b6.zip
added mouse-based resizals
-rw-r--r--Makefile2
-rw-r--r--README10
-rw-r--r--client.c32
-rw-r--r--event.c30
-rw-r--r--kb.c (renamed from key.c)0
-rw-r--r--mouse.c100
-rw-r--r--wm.h26
7 files changed, 181 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index e324e5b..223f6f7 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
3 3
4include config.mk 4include config.mk
5 5
6WMSRC = bar.c client.c cmd.c draw.c event.c key.c util.c wm.c 6WMSRC = bar.c client.c cmd.c draw.c event.c kb.c mouse.c util.c wm.c
7WMOBJ = ${WMSRC:.c=.o} 7WMOBJ = ${WMSRC:.c=.o}
8MENSRC = menu.c draw.c util.c 8MENSRC = menu.c draw.c util.c
9MENOBJ = ${MENSRC:.c=.o} 9MENOBJ = ${MENSRC:.c=.o}
diff --git a/README b/README
index 4f46c8b..bd60b68 100644
--- a/README
+++ b/README
@@ -5,14 +5,6 @@ gridwm is an extremly fast, small, and automatic X11 window manager. It
5arranges all windows in a grid. 5arranges all windows in a grid.
6 6
7 7
8Configuration
9-------------
10You have to edit the source code for configuration, this WM is intended to
11provide sane defaults, if something doesn't fits your needs, edit config.h and
12maybe key.c. To change the status output edit that status variable definition
13in wm.c.
14
15
16Requirements 8Requirements
17------------ 9------------
18In order to build gridwm you need the Xlib header files. 10In order to build gridwm you need the Xlib header files.
@@ -46,6 +38,6 @@ This will start gridwm on display :1 of the host foo.bar.
46Configuration 38Configuration
47------------- 39-------------
48The configuration of gridwm is done by customizing the config.h source file. To 40The configuration of gridwm is done by customizing the config.h source file. To
49customize the key bindings edit key.c. To change the status output, edit the 41customize the key bindings edit kb.c. To change the status output, edit the
50status command definition in wm.c. 42status command definition in wm.c.
51 43
diff --git a/client.c b/client.c
index 9407f0a..e05fdd7 100644
--- a/client.c
+++ b/client.c
@@ -10,6 +10,8 @@
10#include "util.h" 10#include "util.h"
11#include "wm.h" 11#include "wm.h"
12 12
13#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
14
13void 15void
14update_name(Client *c) 16update_name(Client *c)
15{ 17{
@@ -70,7 +72,7 @@ manage(Window w, XWindowAttributes *wa)
70 c->r[RFloat].height = wa->height; 72 c->r[RFloat].height = wa->height;
71 c->border = wa->border_width; 73 c->border = wa->border_width;
72 XSetWindowBorderWidth(dpy, c->win, 0); 74 XSetWindowBorderWidth(dpy, c->win, 0);
73 XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | EnterWindowMask); 75 XSelectInput(dpy, c->win, CLIENT_MASK);
74 XGetTransientForHint(dpy, c->win, &c->trans); 76 XGetTransientForHint(dpy, c->win, &c->trans);
75 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags) 77 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
76 c->size.flags = PSize; 78 c->size.flags = PSize;
@@ -95,9 +97,34 @@ manage(Window w, XWindowAttributes *wa)
95 c->snext = stack; 97 c->snext = stack;
96 stack = c; 98 stack = c;
97 XMapWindow(dpy, c->win); 99 XMapWindow(dpy, c->win);
100 XGrabButton(dpy, AnyButton, Mod1Mask, c->win, False, ButtonPressMask,
101 GrabModeAsync, GrabModeSync, None, None);
98 focus(c); 102 focus(c);
99} 103}
100 104
105void
106resize(Client *c)
107{
108 XConfigureEvent e;
109
110 XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y,
111 c->r[RFloat].width, c->r[RFloat].height);
112 e.type = ConfigureNotify;
113 e.event = c->win;
114 e.window = c->win;
115 e.x = c->r[RFloat].x;
116 e.y = c->r[RFloat].y;
117 e.width = c->r[RFloat].width;
118 e.height = c->r[RFloat].height;
119 e.border_width = c->border;
120 e.above = None;
121 e.override_redirect = False;
122 XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
123 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
124 XSelectInput(dpy, c->win, CLIENT_MASK);
125 XFlush(dpy);
126}
127
101static int 128static int
102dummy_error_handler(Display *dpy, XErrorEvent *error) 129dummy_error_handler(Display *dpy, XErrorEvent *error)
103{ 130{
@@ -112,6 +139,7 @@ unmanage(Client *c)
112 XGrabServer(dpy); 139 XGrabServer(dpy);
113 XSetErrorHandler(dummy_error_handler); 140 XSetErrorHandler(dummy_error_handler);
114 141
142 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
115 XUnmapWindow(dpy, c->win); 143 XUnmapWindow(dpy, c->win);
116 XDestroyWindow(dpy, c->title); 144 XDestroyWindow(dpy, c->title);
117 145
@@ -126,7 +154,7 @@ unmanage(Client *c)
126 XFlush(dpy); 154 XFlush(dpy);
127 XSetErrorHandler(error_handler); 155 XSetErrorHandler(error_handler);
128 XUngrabServer(dpy); 156 XUngrabServer(dpy);
129 flush_events(EnterWindowMask); 157 discard_events(EnterWindowMask);
130 if(stack) 158 if(stack)
131 focus(stack); 159 focus(stack);
132} 160}
diff --git a/event.c b/event.c
index 344a0cc..ad4a16b 100644
--- a/event.c
+++ b/event.c
@@ -12,6 +12,7 @@
12#include "wm.h" 12#include "wm.h"
13 13
14/* local functions */ 14/* local functions */
15static void buttonpress(XEvent *e);
15static void configurerequest(XEvent *e); 16static void configurerequest(XEvent *e);
16static void destroynotify(XEvent *e); 17static void destroynotify(XEvent *e);
17static void enternotify(XEvent *e); 18static void enternotify(XEvent *e);
@@ -23,6 +24,7 @@ static void propertynotify(XEvent *e);
23static void unmapnotify(XEvent *e); 24static void unmapnotify(XEvent *e);
24 25
25void (*handler[LASTEvent]) (XEvent *) = { 26void (*handler[LASTEvent]) (XEvent *) = {
27 [ButtonPress] = buttonpress,
26 [ConfigureRequest] = configurerequest, 28 [ConfigureRequest] = configurerequest,
27 [DestroyNotify] = destroynotify, 29 [DestroyNotify] = destroynotify,
28 [EnterNotify] = enternotify, 30 [EnterNotify] = enternotify,
@@ -36,7 +38,7 @@ void (*handler[LASTEvent]) (XEvent *) = {
36}; 38};
37 39
38unsigned int 40unsigned int
39flush_events(long even_mask) 41discard_events(long even_mask)
40{ 42{
41 XEvent ev; 43 XEvent ev;
42 unsigned int n = 0; 44 unsigned int n = 0;
@@ -45,15 +47,37 @@ flush_events(long even_mask)
45} 47}
46 48
47static void 49static void
50buttonpress(XEvent *e)
51{
52 XButtonPressedEvent *ev = &e->xbutton;
53 Client *c;
54
55 if((c = getclient(ev->window))) {
56 switch(ev->button) {
57 default:
58 break;
59 case Button1:
60 mmove(c);
61 break;
62 case Button2:
63 XLowerWindow(dpy, c->win);
64 break;
65 case Button3:
66 mresize(c);
67 break;
68 }
69 }
70}
71
72static void
48configurerequest(XEvent *e) 73configurerequest(XEvent *e)
49{ 74{
50 XConfigureRequestEvent *ev = &e->xconfigurerequest; 75 XConfigureRequestEvent *ev = &e->xconfigurerequest;
51 XWindowChanges wc; 76 XWindowChanges wc;
52 Client *c; 77 Client *c;
53 78
54 c = getclient(ev->window);
55 ev->value_mask &= ~CWSibling; 79 ev->value_mask &= ~CWSibling;
56 if(c) { 80 if((c = getclient(ev->window))) {
57 if(ev->value_mask & CWX) 81 if(ev->value_mask & CWX)
58 c->r[RFloat].x = ev->x; 82 c->r[RFloat].x = ev->x;
59 if(ev->value_mask & CWY) 83 if(ev->value_mask & CWY)
diff --git a/key.c b/kb.c
index 7caae15..7caae15 100644
--- a/key.c
+++ b/kb.c
diff --git a/mouse.c b/mouse.c
new file mode 100644
index 0000000..2b5d63b
--- /dev/null
+++ b/mouse.c
@@ -0,0 +1,100 @@
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * (C)opyright MMVI Kris Maglione <fbsdaemon@gmail.com>
4 * See LICENSE file for license details.
5 */
6
7#include <stdlib.h>
8#include <string.h>
9#include <unistd.h>
10
11#include "wm.h"
12
13#define ButtonMask (ButtonPressMask | ButtonReleaseMask)
14#define MouseMask (ButtonMask | PointerMotionMask)
15
16static void
17mmatch(Client *c, int x1, int y1, int x2, int y2)
18{
19 c->r[RFloat].width = abs(x1 - x2);
20 c->r[RFloat].height = abs(y1 - y2);
21 c->r[RFloat].width -=
22 (c->r[RFloat].width - c->size.base_width) % c->size.width_inc;
23 c->r[RFloat].height -=
24 (c->r[RFloat].height - c->size.base_height) % c->size.height_inc;
25 if(c->size.min_width && c->r[RFloat].width < c->size.min_width)
26 c->r[RFloat].width = c->size.min_width;
27 if(c->size.min_height && c->r[RFloat].height < c->size.min_height)
28 c->r[RFloat].height = c->size.min_height;
29 if(c->size.max_width && c->r[RFloat].width > c->size.max_width)
30 c->r[RFloat].width = c->size.max_width;
31 if(c->size.max_height && c->r[RFloat].height > c->size.max_height)
32 c->r[RFloat].height = c->size.max_height;
33 c->r[RFloat].x = (x1 <= x2) ? x1 : x1 - c->r[RFloat].width;
34 c->r[RFloat].y = (y1 <= y2) ? y1 : y1 - c->r[RFloat].height;
35}
36
37void
38mresize(Client *c)
39{
40 XEvent ev;
41 int old_cx, old_cy;
42
43 old_cx = c->r[RFloat].x;
44 old_cy = c->r[RFloat].y;
45 if(XGrabPointer(dpy, c->win, False, MouseMask, GrabModeAsync, GrabModeAsync,
46 None, cursor[CurResize], CurrentTime) != GrabSuccess)
47 return;
48 XGrabServer(dpy);
49 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
50 c->r[RFloat].width, c->r[RFloat].height);
51 for(;;) {
52 XMaskEvent(dpy, MouseMask, &ev);
53 switch(ev.type) {
54 default: break;
55 case MotionNotify:
56 XUngrabServer(dpy);
57 mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
58 resize(c);
59 XGrabServer(dpy);
60 break;
61 case ButtonRelease:
62 XUngrabPointer(dpy, CurrentTime);
63 return;
64 }
65 }
66}
67
68void
69mmove(Client *c)
70{
71 XEvent ev;
72 int x1, y1, old_cx, old_cy, di;
73 unsigned int dui;
74 Window dummy;
75
76 old_cx = c->r[RFloat].x;
77 old_cy = c->r[RFloat].y;
78 if(XGrabPointer(dpy, c->win, False, MouseMask, GrabModeAsync, GrabModeAsync,
79 None, cursor[CurMove], CurrentTime) != GrabSuccess)
80 return;
81 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
82 XGrabServer(dpy);
83 for(;;) {
84 XMaskEvent(dpy, MouseMask, &ev);
85 switch (ev.type) {
86 default: break;
87 case MotionNotify:
88 XUngrabServer(dpy);
89 c->r[RFloat].x = old_cx + (ev.xmotion.x - x1);
90 c->r[RFloat].y = old_cy + (ev.xmotion.y - y1);
91 resize(c);
92 XGrabServer(dpy);
93 break;
94 case ButtonRelease:
95 XUngrabServer(dpy);
96 XUngrabPointer(dpy, CurrentTime);
97 return;
98 }
99 }
100}
diff --git a/wm.h b/wm.h
index 055ef62..7ee6103 100644
--- a/wm.h
+++ b/wm.h
@@ -11,6 +11,22 @@
11 11
12#define WM_PROTOCOL_DELWIN 1 12#define WM_PROTOCOL_DELWIN 1
13 13
14typedef struct Client Client;
15typedef struct Key Key;
16typedef enum Align Align;
17
18enum Align {
19 NORTH = 0x01,
20 EAST = 0x02,
21 SOUTH = 0x04,
22 WEST = 0x08,
23 NEAST = NORTH | EAST,
24 NWEST = NORTH | WEST,
25 SEAST = SOUTH | EAST,
26 SWEST = SOUTH | WEST,
27 CENTER = NEAST | SWEST
28};
29
14/* atoms */ 30/* atoms */
15enum { WMProtocols, WMDelete, WMLast }; 31enum { WMProtocols, WMDelete, WMLast };
16enum { NetSupported, NetWMName, NetLast }; 32enum { NetSupported, NetWMName, NetLast };
@@ -21,9 +37,6 @@ enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
21/* rects */ 37/* rects */
22enum { RFloat, RGrid, RLast }; 38enum { RFloat, RGrid, RLast };
23 39
24typedef struct Client Client;
25typedef struct Key Key;
26
27struct Client { 40struct Client {
28 char name[256]; 41 char name[256];
29 char tag[256]; 42 char tag[256];
@@ -75,14 +88,19 @@ extern Client *getclient(Window w);
75extern void focus(Client *c); 88extern void focus(Client *c);
76extern void update_name(Client *c); 89extern void update_name(Client *c);
77extern void draw_client(Client *c); 90extern void draw_client(Client *c);
91extern void resize(Client *c);
78 92
79/* event.c */ 93/* event.c */
80extern unsigned int flush_events(long even_mask); 94extern unsigned int discard_events(long even_mask);
81 95
82/* key.c */ 96/* key.c */
83extern void update_keys(); 97extern void update_keys();
84extern void keypress(XEvent *e); 98extern void keypress(XEvent *e);
85 99
100/* mouse.c */
101extern void mresize(Client *c);
102extern void mmove(Client *c);
103
86/* wm.c */ 104/* wm.c */
87extern int error_handler(Display *dpy, XErrorEvent *error); 105extern int error_handler(Display *dpy, XErrorEvent *error);
88extern void send_message(Window w, Atom a, long value); 106extern void send_message(Window w, Atom a, long value);