summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Cardell Widerkrantz <mc@hack.org>2012-02-15 10:23:59 +0100
committerMichael Cardell Widerkrantz <mc@hack.org>2012-02-15 10:23:59 +0100
commit97a51653944b43aee9a6c4d9d4ac8fc99dddd287 (patch)
treedbc9fa5dfce63bd23f8527eac507fa62edce2172
parent4749170ecb656c64fd6a292325cf05fbe5bc3f65 (diff)
downloadmcwm-97a51653944b43aee9a6c4d9d4ac8fc99dddd287.zip
Use getatom() to get all the atoms we need instead of repeating code.
-rw-r--r--mcwm.c91
1 files changed, 31 insertions, 60 deletions
diff --git a/mcwm.c b/mcwm.c
index dc084b0..dcf6612 100644
--- a/mcwm.c
+++ b/mcwm.c
@@ -362,6 +362,7 @@ static void configurerequest(xcb_configure_request_event_t *e);
static void events(void);
static void printhelp(void);
static void sigcatch(int sig);
+static xcb_atom_t getatom(char *atom_name);
/* Function bodies. */
@@ -4041,6 +4042,31 @@ void sigcatch(int sig)
sigcode = sig;
}
+/*
+ * Get a defined atom from the X server.
+ */
+xcb_atom_t getatom(char *atom_name)
+{
+ xcb_intern_atom_cookie_t atom_cookie;
+ xcb_atom_t atom;
+ xcb_intern_atom_reply_t *rep;
+
+ atom_cookie = xcb_intern_atom(conn, 0, strlen(atom_name), atom_name);
+ rep = xcb_intern_atom_reply(conn, atom_cookie, NULL);
+ if (NULL != rep)
+ {
+ atom = rep->atom;
+ free(rep);
+ return atom;
+ }
+
+ /*
+ * XXX Note that we return 0 as an atom if anything goes wrong.
+ * Might become interesting.
+ */
+ return 0;
+}
+
int main(int argc, char **argv)
{
uint32_t mask = 0;
@@ -4146,67 +4172,12 @@ int main(int argc, char **argv)
conf.fixedcol = getcolor(fixedcol);
/* Get some atoms. */
- char *atom_name;
- xcb_intern_atom_cookie_t atom_cookie;
- xcb_intern_atom_cookie_t cookie_desktop;
- xcb_intern_atom_cookie_t cookie_delete_window;
- xcb_intern_atom_cookie_t cookie_protocols;
- xcb_intern_atom_reply_t *rep;
-
- atom_name = "_NET_WM_DESKTOP";
- cookie_desktop = xcb_intern_atom(conn,
- 0,
- strlen(atom_name),
- atom_name);
- rep = xcb_intern_atom_reply(conn,
- cookie_desktop,
- NULL);
- atom_desktop = rep->atom;
- free(rep);
-
-
- atom_name = "WM_DELETE_WINDOW";
- cookie_delete_window = xcb_intern_atom(conn,
- 0,
- strlen (atom_name),
- atom_name);
- rep = xcb_intern_atom_reply(conn,
- cookie_delete_window,
- NULL);
- wm_delete_window = rep->atom;
- free(rep);
-
-
- atom_name = "WM_CHANGE_STATE";
- atom_cookie = xcb_intern_atom(conn,
- 0,
- strlen(atom_name),
- atom_name);
- rep = xcb_intern_atom_reply(conn, atom_cookie, NULL);
- wm_change_state = rep->atom;
- free(rep);
-
- atom_name = "WM_STATE";
- atom_cookie = xcb_intern_atom(conn,
- 0,
- strlen(atom_name),
- atom_name);
- rep = xcb_intern_atom_reply(conn, atom_cookie, NULL);
- wm_state = rep->atom;
- free(rep);
+ atom_desktop = getatom("_NET_WM_DESKTOP");
+ wm_delete_window = getatom("WM_DELETE_WINDOW");
+ wm_change_state = getatom("WM_CHANGE_STATE");
+ wm_state = getatom("WM_STATE");
+ wm_protocols = getatom("WM_PROTOCOLS");
- atom_name = "WM_PROTOCOLS";
- cookie_protocols = xcb_intern_atom(conn,
- 0,
- strlen (atom_name),
- atom_name);
- rep = xcb_intern_atom_reply(conn,
- cookie_protocols,
- NULL);
- wm_protocols = rep->atom;
- free(rep);
-
-
/* Check for RANDR extension and configure. */
randrbase = setuprandr();