summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Cardell Widerkrantz <mc@hack.org>2010-09-13 15:23:41 +0200
committerMichael Cardell Widerkrantz <mc@hack.org>2010-09-13 15:23:41 +0200
commit6c906ce28327d71b6f9b8ae50e3e1db12ec26a19 (patch)
tree689fe709bd6ae5f4e53ddd11555ea68b354b8fe6
parentfd0130149260fc19c0c5ba22ef6c64e02bd29fb4 (diff)
downloadmcwm-6c906ce28327d71b6f9b8ae50e3e1db12ec26a19.zip
Added delete window functionality. This is a patch from Christian
Neukirchen, chneukirchen at the domain gmail.com. I only changed the default key and moved a flush.
-rw-r--r--NEWS5
-rw-r--r--config.h2
-rw-r--r--mcwm.c60
3 files changed, 64 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index bde6c7b..c50a2c2 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@
User visible changes
+2010-09-08
+
+ * New key: MODKEY + End closes window. Patch from Christian
+ Neukirchen, who used MODKEY + ESC instead.
+
2010-08-23
* Obey window coordinates when doing initial mapping if the client
diff --git a/config.h b/config.h
index fdd58bc..4d53c0c 100644
--- a/config.h
+++ b/config.h
@@ -75,4 +75,4 @@
#define USERKEY_TOPRIGHT XK_U
#define USERKEY_BOTLEFT XK_B
#define USERKEY_BOTRIGHT XK_N
-
+#define USERKEY_DELETE XK_End
diff --git a/mcwm.c b/mcwm.c
index 2b8137d..1d00b74 100644
--- a/mcwm.c
+++ b/mcwm.c
@@ -111,6 +111,7 @@ typedef enum {
KEY_U,
KEY_B,
KEY_N,
+ KEY_END,
KEY_MAX
} key_enum_t;
@@ -192,7 +193,8 @@ struct keys
{ USERKEY_TOPLEFT, 0 },
{ USERKEY_TOPRIGHT, 0 },
{ USERKEY_BOTLEFT, 0 },
- { USERKEY_BOTRIGHT, 0 }
+ { USERKEY_BOTRIGHT, 0 },
+ { USERKEY_DELETE, 0 }
};
/* Global configuration. */
@@ -211,6 +213,9 @@ xcb_atom_t atom_desktop; /*
* on.
*/
+xcb_atom_t wm_delete_window; /* WM_DELETE_WINDOW event to close windows. */
+xcb_atom_t wm_protocols; /* WM_PROTOCOLS. */
+
/* Functions declerations. */
@@ -253,6 +258,7 @@ void topleft(void);
void topright(void);
void botleft(void);
void botright(void);
+void deletewin(void);
void handle_keypress(xcb_key_press_event_t *ev);
void printhelp(void);
void sigcatch(int sig);
@@ -2163,6 +2169,50 @@ void botright(void)
xcb_flush(conn);
}
+void deletewin(void)
+{
+ xcb_get_property_cookie_t cookie;
+ xcb_get_wm_protocols_reply_t protocols;
+ bool use_delete = false;
+ uint32_t i;
+
+ if (NULL == focuswin)
+ {
+ return;
+ }
+
+ /* Check if WM_DELETE is supported. */
+ cookie = xcb_get_wm_protocols_unchecked(conn, focuswin->id, wm_protocols);
+ if (xcb_get_wm_protocols_reply(conn, cookie, &protocols, NULL) == 1) {
+ for (i = 0; i < protocols.atoms_len; i++)
+ if (protocols.atoms[i] == wm_delete_window)
+ use_delete = true;
+ }
+
+ xcb_get_wm_protocols_reply_wipe(&protocols);
+
+ if (use_delete)
+ {
+ xcb_client_message_event_t ev = {
+ .response_type = XCB_CLIENT_MESSAGE,
+ .format = 32,
+ .sequence = 0,
+ .window = focuswin->id,
+ .type = wm_protocols,
+ .data.data32 = { wm_delete_window, XCB_CURRENT_TIME }
+ };
+
+ xcb_send_event(conn, false, focuswin->id,
+ XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
+ }
+ else
+ {
+ xcb_kill_client(conn, focuswin->id);
+ }
+
+ xcb_flush(conn);
+}
+
void handle_keypress(xcb_key_press_event_t *ev)
{
int i;
@@ -2314,6 +2364,10 @@ void handle_keypress(xcb_key_press_event_t *ev)
case KEY_N:
botright();
break;
+
+ case KEY_END:
+ deletewin();
+ break;
default:
/* Ignore other keys. */
@@ -2993,8 +3047,10 @@ int main(int argc, char **argv)
conf.unfocuscol = getcolor(unfocuscol);
conf.fixedcol = getcolor(fixedcol);
- /* Get an atom. */
+ /* Get some atoms. */
atom_desktop = xcb_atom_get(conn, "_NET_WM_DESKTOP");
+ wm_delete_window = xcb_atom_get(conn, "WM_DELETE_WINDOW");
+ wm_protocols = xcb_atom_get(conn, "WM_PROTOCOLS");
/* Loop over all clients and set up stuff. */
if (0 != setupscreen())