diff options
| -rw-r--r-- | client.c | 33 | ||||
| -rw-r--r-- | cmd.c | 14 | ||||
| -rw-r--r-- | event.c | 50 | ||||
| -rw-r--r-- | menu.c | 2 | ||||
| -rw-r--r-- | wm.c | 66 | ||||
| -rw-r--r-- | wm.h | 24 |
6 files changed, 153 insertions, 36 deletions
| @@ -10,8 +10,8 @@ | |||
| 10 | #include "util.h" | 10 | #include "util.h" |
| 11 | #include "wm.h" | 11 | #include "wm.h" |
| 12 | 12 | ||
| 13 | static void | 13 | void |
| 14 | update_client_name(Client *c) | 14 | update_name(Client *c) |
| 15 | { | 15 | { |
| 16 | XTextProperty name; | 16 | XTextProperty name; |
| 17 | int n; | 17 | int n; |
| @@ -38,6 +38,20 @@ update_client_name(Client *c) | |||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | void | 40 | void |
| 41 | focus(Client *c) | ||
| 42 | { | ||
| 43 | Client **l; | ||
| 44 | for(l=&stack; *l && *l != c; l=&(*l)->snext); | ||
| 45 | eassert(*l == c); | ||
| 46 | *l = c->snext; | ||
| 47 | c->snext = stack; | ||
| 48 | stack = c; | ||
| 49 | XRaiseWindow(dpy, c->win); | ||
| 50 | XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); | ||
| 51 | XFlush(dpy); | ||
| 52 | } | ||
| 53 | |||
| 54 | void | ||
| 41 | manage(Window w, XWindowAttributes *wa) | 55 | manage(Window w, XWindowAttributes *wa) |
| 42 | { | 56 | { |
| 43 | Client *c, **l; | 57 | Client *c, **l; |
| @@ -59,7 +73,7 @@ manage(Window w, XWindowAttributes *wa) | |||
| 59 | (c->size.flags & PMinSize && c->size.flags & PMaxSize | 73 | (c->size.flags & PMinSize && c->size.flags & PMaxSize |
| 60 | && c->size.min_width == c->size.max_width | 74 | && c->size.min_width == c->size.max_width |
| 61 | && c->size.min_height == c->size.max_height); | 75 | && c->size.min_height == c->size.max_height); |
| 62 | update_client_name(c); | 76 | update_name(c); |
| 63 | twa.override_redirect = 1; | 77 | twa.override_redirect = 1; |
| 64 | twa.background_pixmap = ParentRelative; | 78 | twa.background_pixmap = ParentRelative; |
| 65 | twa.event_mask = ExposureMask; | 79 | twa.event_mask = ExposureMask; |
| @@ -73,9 +87,10 @@ manage(Window w, XWindowAttributes *wa) | |||
| 73 | for(l=&clients; *l; l=&(*l)->next); | 87 | for(l=&clients; *l; l=&(*l)->next); |
| 74 | c->next = *l; /* *l == nil */ | 88 | c->next = *l; /* *l == nil */ |
| 75 | *l = c; | 89 | *l = c; |
| 76 | XMapRaised(dpy, c->win); | 90 | c->snext = stack; |
| 77 | XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); | 91 | stack = c; |
| 78 | XFlush(dpy); | 92 | XMapWindow(dpy, c->win); |
| 93 | focus(c); | ||
| 79 | } | 94 | } |
| 80 | 95 | ||
| 81 | static int | 96 | static int |
| @@ -98,12 +113,15 @@ unmanage(Client *c) | |||
| 98 | for(l=&clients; *l && *l != c; l=&(*l)->next); | 113 | for(l=&clients; *l && *l != c; l=&(*l)->next); |
| 99 | eassert(*l == c); | 114 | eassert(*l == c); |
| 100 | *l = c->next; | 115 | *l = c->next; |
| 116 | for(l=&stack; *l && *l != c; l=&(*l)->snext); | ||
| 117 | eassert(*l == c); | ||
| 118 | *l = c->snext; | ||
| 101 | free(c); | 119 | free(c); |
| 102 | 120 | ||
| 103 | XFlush(dpy); | 121 | XFlush(dpy); |
| 104 | XSetErrorHandler(error_handler); | 122 | XSetErrorHandler(error_handler); |
| 105 | XUngrabServer(dpy); | 123 | XUngrabServer(dpy); |
| 106 | /*flush_masked_events(EnterWindowMask); ? */ | 124 | flush_events(EnterWindowMask); |
| 107 | } | 125 | } |
| 108 | 126 | ||
| 109 | 127 | ||
| @@ -116,3 +134,4 @@ getclient(Window w) | |||
| 116 | return c; | 134 | return c; |
| 117 | return NULL; | 135 | return NULL; |
| 118 | } | 136 | } |
| 137 | |||
| @@ -18,3 +18,17 @@ quit(char *arg) | |||
| 18 | fputs("quit\n", stderr); | 18 | fputs("quit\n", stderr); |
| 19 | running = False; | 19 | running = False; |
| 20 | } | 20 | } |
| 21 | |||
| 22 | void | ||
| 23 | kill(char *arg) | ||
| 24 | { | ||
| 25 | Client *c = stack; | ||
| 26 | |||
| 27 | if(!c) | ||
| 28 | return; | ||
| 29 | if(c->proto & WM_PROTOCOL_DELWIN) | ||
| 30 | send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]); | ||
| 31 | else | ||
| 32 | XKillClient(dpy, c->win); | ||
| 33 | } | ||
| 34 | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | #include <X11/keysym.h> | 9 | #include <X11/keysym.h> |
| 10 | #include <X11/Xatom.h> | ||
| 10 | 11 | ||
| 11 | #include "wm.h" | 12 | #include "wm.h" |
| 12 | 13 | ||
| @@ -35,7 +36,7 @@ void (*handler[LASTEvent]) (XEvent *) = { | |||
| 35 | }; | 36 | }; |
| 36 | 37 | ||
| 37 | unsigned int | 38 | unsigned int |
| 38 | flush_masked_events(long even_mask) | 39 | flush_events(long even_mask) |
| 39 | { | 40 | { |
| 40 | XEvent ev; | 41 | XEvent ev; |
| 41 | unsigned int n = 0; | 42 | unsigned int n = 0; |
| @@ -91,25 +92,18 @@ destroynotify(XEvent *e) | |||
| 91 | static void | 92 | static void |
| 92 | enternotify(XEvent *e) | 93 | enternotify(XEvent *e) |
| 93 | { | 94 | { |
| 94 | #if 0 | ||
| 95 | XCrossingEvent *ev = &e->xcrossing; | 95 | XCrossingEvent *ev = &e->xcrossing; |
| 96 | Client *c; | 96 | Client *c; |
| 97 | 97 | ||
| 98 | if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) | 98 | if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) |
| 99 | return; | 99 | return; |
| 100 | 100 | ||
| 101 | if((c = client_of_win(ev->window))) { | 101 | if((c = getclient(ev->window))) |
| 102 | Frame *f = c->sel; | 102 | focus(c); |
| 103 | Area *a = f->area; | ||
| 104 | if(a->mode == Colmax) | ||
| 105 | c = a->sel->client; | ||
| 106 | focus(c, False); | ||
| 107 | } | ||
| 108 | else if(ev->window == root) { | 103 | else if(ev->window == root) { |
| 109 | sel_screen = True; | 104 | sel_screen = True; |
| 110 | draw_frames(); | 105 | /*draw_frames();*/ |
| 111 | } | 106 | } |
| 112 | #endif | ||
| 113 | } | 107 | } |
| 114 | 108 | ||
| 115 | static void | 109 | static void |
| @@ -137,9 +131,7 @@ expose(XEvent *e) | |||
| 137 | static void | 131 | static void |
| 138 | keymapnotify(XEvent *e) | 132 | keymapnotify(XEvent *e) |
| 139 | { | 133 | { |
| 140 | #if 0 | ||
| 141 | update_keys(); | 134 | update_keys(); |
| 142 | #endif | ||
| 143 | } | 135 | } |
| 144 | 136 | ||
| 145 | static void | 137 | static void |
| @@ -164,16 +156,40 @@ maprequest(XEvent *e) | |||
| 164 | static void | 156 | static void |
| 165 | propertynotify(XEvent *e) | 157 | propertynotify(XEvent *e) |
| 166 | { | 158 | { |
| 167 | #if 0 | ||
| 168 | XPropertyEvent *ev = &e->xproperty; | 159 | XPropertyEvent *ev = &e->xproperty; |
| 160 | long msize; | ||
| 169 | Client *c; | 161 | Client *c; |
| 170 | 162 | ||
| 171 | if(ev->state == PropertyDelete) | 163 | if(ev->state == PropertyDelete) |
| 172 | return; /* ignore */ | 164 | return; /* ignore */ |
| 173 | 165 | ||
| 174 | if((c = client_of_win(ev->window))) | 166 | if(ev->atom == wm_atom[WMProtocols]) { |
| 175 | prop_client(c, ev); | 167 | c->proto = win_proto(c->win); |
| 176 | #endif | 168 | return; |
| 169 | } | ||
| 170 | if((c = getclient(ev->window))) { | ||
| 171 | switch (ev->atom) { | ||
| 172 | default: break; | ||
| 173 | case XA_WM_TRANSIENT_FOR: | ||
| 174 | XGetTransientForHint(dpy, c->win, &c->trans); | ||
| 175 | break; | ||
| 176 | case XA_WM_NORMAL_HINTS: | ||
| 177 | if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) | ||
| 178 | || !c->size.flags) | ||
| 179 | c->size.flags = PSize; | ||
| 180 | if(c->size.flags & PMinSize && c->size.flags & PMaxSize | ||
| 181 | && c->size.min_width == c->size.max_width | ||
| 182 | && c->size.min_height == c->size.max_height) | ||
| 183 | c->fixedsize = True; | ||
| 184 | else | ||
| 185 | c->fixedsize = False; | ||
| 186 | break; | ||
| 187 | } | ||
| 188 | if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) { | ||
| 189 | update_name(c); | ||
| 190 | /*draw_frame(c->sel);*/ | ||
| 191 | } | ||
| 192 | } | ||
| 177 | } | 193 | } |
| 178 | 194 | ||
| 179 | static void | 195 | static void |
| @@ -304,7 +304,7 @@ kpress(XKeyEvent * e) | |||
| 304 | } | 304 | } |
| 305 | break; | 305 | break; |
| 306 | default: | 306 | default: |
| 307 | if((num == 1) && !iscntrl((int) buf[0])) { | 307 | if(num && !iscntrl((int) buf[0])) { |
| 308 | buf[num] = 0; | 308 | buf[num] = 0; |
| 309 | if(len > 0) | 309 | if(len > 0) |
| 310 | strncat(text, buf, sizeof(text)); | 310 | strncat(text, buf, sizeof(text)); |
| @@ -16,18 +16,18 @@ | |||
| 16 | /* X structs */ | 16 | /* X structs */ |
| 17 | Display *dpy; | 17 | Display *dpy; |
| 18 | Window root, barwin; | 18 | Window root, barwin; |
| 19 | Atom net_atom[NetLast]; | 19 | Atom wm_atom[WMLast], net_atom[NetLast]; |
| 20 | Cursor cursor[CurLast]; | 20 | Cursor cursor[CurLast]; |
| 21 | XRectangle rect, barrect; | 21 | XRectangle rect, barrect; |
| 22 | Bool running = True; | 22 | Bool running = True; |
| 23 | Bool sel_screen; | ||
| 23 | 24 | ||
| 24 | char *bartext, tag[256]; | 25 | char *bartext, tag[256]; |
| 25 | int screen, sel_screen; | 26 | int screen; |
| 26 | 27 | ||
| 27 | Brush brush = {0}; | 28 | Brush brush = {0}; |
| 28 | Client *clients = NULL; | 29 | Client *clients = NULL; |
| 29 | 30 | Client *stack = NULL; | |
| 30 | enum { WM_PROTOCOL_DELWIN = 1 }; | ||
| 31 | 31 | ||
| 32 | static Bool other_wm_running; | 32 | static Bool other_wm_running; |
| 33 | static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; | 33 | static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; |
| @@ -62,6 +62,62 @@ scan_wins() | |||
| 62 | XFree(wins); | 62 | XFree(wins); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | static int | ||
| 66 | win_property(Window w, Atom a, Atom t, long l, unsigned char **prop) | ||
| 67 | { | ||
| 68 | Atom real; | ||
| 69 | int format; | ||
| 70 | unsigned long res, extra; | ||
| 71 | int status; | ||
| 72 | |||
| 73 | status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, | ||
| 74 | &res, &extra, prop); | ||
| 75 | |||
| 76 | if(status != Success || *prop == 0) { | ||
| 77 | return 0; | ||
| 78 | } | ||
| 79 | if(res == 0) { | ||
| 80 | free((void *) *prop); | ||
| 81 | } | ||
| 82 | return res; | ||
| 83 | } | ||
| 84 | |||
| 85 | int | ||
| 86 | win_proto(Window w) | ||
| 87 | { | ||
| 88 | Atom *protocols; | ||
| 89 | long res; | ||
| 90 | int protos = 0; | ||
| 91 | int i; | ||
| 92 | |||
| 93 | res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, | ||
| 94 | ((unsigned char **) &protocols)); | ||
| 95 | if(res <= 0) { | ||
| 96 | return protos; | ||
| 97 | } | ||
| 98 | for(i = 0; i < res; i++) { | ||
| 99 | if(protocols[i] == wm_atom[WMDelete]) | ||
| 100 | protos |= WM_PROTOCOL_DELWIN; | ||
| 101 | } | ||
| 102 | free((char *) protocols); | ||
| 103 | return protos; | ||
| 104 | } | ||
| 105 | |||
| 106 | void | ||
| 107 | send_message(Window w, Atom a, long value) | ||
| 108 | { | ||
| 109 | XEvent e; | ||
| 110 | |||
| 111 | e.type = ClientMessage; | ||
| 112 | e.xclient.window = w; | ||
| 113 | e.xclient.message_type = a; | ||
| 114 | e.xclient.format = 32; | ||
| 115 | e.xclient.data.l[0] = value; | ||
| 116 | e.xclient.data.l[1] = CurrentTime; | ||
| 117 | XSendEvent(dpy, w, False, NoEventMask, &e); | ||
| 118 | XFlush(dpy); | ||
| 119 | } | ||
| 120 | |||
| 65 | /* | 121 | /* |
| 66 | * There's no way to check accesses to destroyed windows, thus | 122 | * There's no way to check accesses to destroyed windows, thus |
| 67 | * those cases are ignored (especially on UnmapNotify's). | 123 | * those cases are ignored (especially on UnmapNotify's). |
| @@ -160,6 +216,8 @@ main(int argc, char *argv[]) | |||
| 160 | x_error_handler = XSetErrorHandler(error_handler); | 216 | x_error_handler = XSetErrorHandler(error_handler); |
| 161 | 217 | ||
| 162 | /* init atoms */ | 218 | /* init atoms */ |
| 219 | wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); | ||
| 220 | wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); | ||
| 163 | net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); | 221 | net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); |
| 164 | net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); | 222 | net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); |
| 165 | 223 | ||
| @@ -9,7 +9,10 @@ | |||
| 9 | 9 | ||
| 10 | #include <X11/Xutil.h> | 10 | #include <X11/Xutil.h> |
| 11 | 11 | ||
| 12 | #define WM_PROTOCOL_DELWIN 1 | ||
| 13 | |||
| 12 | /* atoms */ | 14 | /* atoms */ |
| 15 | enum { WMProtocols, WMDelete, WMLast }; | ||
| 13 | enum { NetSupported, NetWMName, NetLast }; | 16 | enum { NetSupported, NetWMName, NetLast }; |
| 14 | 17 | ||
| 15 | /* cursor */ | 18 | /* cursor */ |
| @@ -25,6 +28,7 @@ struct Client { | |||
| 25 | char name[256]; | 28 | char name[256]; |
| 26 | char tag[256]; | 29 | char tag[256]; |
| 27 | unsigned int border; | 30 | unsigned int border; |
| 31 | int proto; | ||
| 28 | Bool fixedsize; | 32 | Bool fixedsize; |
| 29 | Window win; | 33 | Window win; |
| 30 | Window trans; | 34 | Window trans; |
| @@ -44,18 +48,17 @@ struct Key { | |||
| 44 | 48 | ||
| 45 | extern Display *dpy; | 49 | extern Display *dpy; |
| 46 | extern Window root, barwin; | 50 | extern Window root, barwin; |
| 47 | extern Atom net_atom[NetLast]; | 51 | extern Atom wm_atom[WMLast], net_atom[NetLast]; |
| 48 | extern Cursor cursor[CurLast]; | 52 | extern Cursor cursor[CurLast]; |
| 49 | extern XRectangle rect, barrect; | 53 | extern XRectangle rect, barrect; |
| 50 | extern Bool running; | 54 | extern Bool running, sel_screen, grid; |
| 51 | extern Bool grid; | ||
| 52 | extern void (*handler[LASTEvent]) (XEvent *); | 55 | extern void (*handler[LASTEvent]) (XEvent *); |
| 53 | 56 | ||
| 54 | extern int screen, sel_screen; | 57 | extern int screen; |
| 55 | extern char *bartext, tag[256]; | 58 | extern char *bartext, tag[256]; |
| 56 | 59 | ||
| 57 | extern Brush brush; | 60 | extern Brush brush; |
| 58 | extern Client *clients; | 61 | extern Client *clients, *stack; |
| 59 | 62 | ||
| 60 | /* bar.c */ | 63 | /* bar.c */ |
| 61 | extern void draw_bar(); | 64 | extern void draw_bar(); |
| @@ -66,8 +69,13 @@ extern void quit(char *arg); | |||
| 66 | 69 | ||
| 67 | /* client.c */ | 70 | /* client.c */ |
| 68 | extern void manage(Window w, XWindowAttributes *wa); | 71 | extern void manage(Window w, XWindowAttributes *wa); |
| 69 | void unmanage(Client *c); | 72 | extern void unmanage(Client *c); |
| 70 | extern Client * getclient(Window w); | 73 | extern Client *getclient(Window w); |
| 74 | extern void focus(Client *c); | ||
| 75 | extern void update_name(Client *c); | ||
| 76 | |||
| 77 | /* event.c */ | ||
| 78 | extern unsigned int flush_events(long even_mask); | ||
| 71 | 79 | ||
| 72 | /* key.c */ | 80 | /* key.c */ |
| 73 | extern void update_keys(); | 81 | extern void update_keys(); |
| @@ -75,3 +83,5 @@ extern void keypress(XEvent *e); | |||
| 75 | 83 | ||
| 76 | /* wm.c */ | 84 | /* wm.c */ |
| 77 | extern int error_handler(Display *dpy, XErrorEvent *error); | 85 | extern int error_handler(Display *dpy, XErrorEvent *error); |
| 86 | extern void send_message(Window w, Atom a, long value); | ||
| 87 | extern int win_proto(Window w); | ||
