From e2fa49ecfea58d8ec77b633fcee66e2b7ed95467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Mon, 27 Jan 2014 23:16:08 +0100 Subject: [PATCH] Unified X atom initialization --- Makefile | 2 +- main.c | 2 +- window.c | 29 +++++++++++++++++------------ window.h | 12 +++++++++++- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index fa9d000..ee7077b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = git-20140131 +VERSION = git-20140202 PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man diff --git a/main.c b/main.c index f95b4f4..90916e3 100644 --- a/main.c +++ b/main.c @@ -682,7 +682,7 @@ void run(void) on_buttonpress(&ev.xbutton); break; case ClientMessage: - if ((Atom) ev.xclient.data.l[0] == wm_delete_win) + if ((Atom) ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW]) return; break; case ConfigureNotify: diff --git a/window.c b/window.c index 48a2419..faea963 100644 --- a/window.c +++ b/window.c @@ -42,8 +42,6 @@ static Cursor chand; static Cursor cwatch; static GC gc; -Atom wm_delete_win; - static struct { int ascent; int descent; @@ -54,6 +52,8 @@ static struct { static int fontheight; static int barheight; +Atom atoms[ATOM_COUNT]; + void win_init_font(Display *dpy, const char *fontstr) { int n; @@ -102,6 +102,9 @@ unsigned long win_alloc_color(win_t *win, const char *name) return col.pixel; } +#define INIT_ATOM_(atom) \ + atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False); + void win_init(win_t *win) { win_env_t *e; @@ -141,7 +144,12 @@ void win_init(win_t *win) /* actual min/max values set in win_update_sizehints() */ win->sizehints.flags |= PMinSize | PMaxSize; - wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False); + INIT_ATOM_(WM_DELETE_WINDOW); + INIT_ATOM_(_NET_WM_NAME); + INIT_ATOM_(_NET_WM_ICON_NAME); + INIT_ATOM_(_NET_WM_ICON); + INIT_ATOM_(_NET_WM_STATE); + INIT_ATOM_(_NET_WM_STATE_FULLSCREEN); } void win_update_sizehints(win_t *win) @@ -258,8 +266,7 @@ void win_open(win_t *win) icon_data[n++] = icon_colors[icons[i].data[j] & 0x0F]; } XChangeProperty(e->dpy, win->xwin, - XInternAtom(e->dpy, "_NET_WM_ICON", False), - XA_CARDINAL, 32, + atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32, i == 0 ? PropModeReplace : PropModeAppend, (unsigned char *) icon_data, n); } @@ -271,7 +278,7 @@ void win_open(win_t *win) classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv"; XSetClassHint(e->dpy, win->xwin, &classhint); - XSetWMProtocols(e->dpy, win->xwin, &wm_delete_win, 1); + XSetWMProtocols(e->dpy, win->xwin, &atoms[ATOM_WM_DELETE_WINDOW], 1); win->h -= win->bar.h; win_update_sizehints(win); @@ -379,10 +386,10 @@ void win_toggle_fullscreen(win_t *win) cm = &ev.xclient; cm->window = win->xwin; - cm->message_type = XInternAtom(win->env.dpy, "_NET_WM_STATE", False); + cm->message_type = atoms[ATOM__NET_WM_STATE]; cm->format = 32; cm->data.l[0] = win->fullscreen; - cm->data.l[1] = XInternAtom(win->env.dpy, "_NET_WM_STATE_FULLSCREEN", False); + cm->data.l[1] = atoms[ATOM__NET_WM_STATE_FULLSCREEN]; cm->data.l[2] = cm->data.l[3] = 0; XSendEvent(win->env.dpy, DefaultRootWindow(win->env.dpy), False, @@ -540,12 +547,10 @@ void win_set_title(win_t *win, const char *title) XStoreName(win->env.dpy, win->xwin, title); XSetIconName(win->env.dpy, win->xwin, title); - XChangeProperty(win->env.dpy, win->xwin, - XInternAtom(win->env.dpy, "_NET_WM_NAME", False), + XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_NAME], XInternAtom(win->env.dpy, "UTF8_STRING", False), 8, PropModeReplace, (unsigned char *) title, strlen(title)); - XChangeProperty(win->env.dpy, win->xwin, - XInternAtom(win->env.dpy, "_NET_WM_ICON_NAME", False), + XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_ICON_NAME], XInternAtom(win->env.dpy, "UTF8_STRING", False), 8, PropModeReplace, (unsigned char *) title, strlen(title)); } diff --git a/window.h b/window.h index 19a7171..b9e064d 100644 --- a/window.h +++ b/window.h @@ -29,6 +29,16 @@ enum { BAR_R_LEN = 64 }; +enum { + ATOM_WM_DELETE_WINDOW, + ATOM__NET_WM_NAME, + ATOM__NET_WM_ICON_NAME, + ATOM__NET_WM_ICON, + ATOM__NET_WM_STATE, + ATOM__NET_WM_STATE_FULLSCREEN, + ATOM_COUNT +}; + typedef struct { Display *dpy; int scr; @@ -67,7 +77,7 @@ typedef struct { } bar; } win_t; -extern Atom wm_delete_win; +extern Atom atoms[ATOM_COUNT]; void win_init(win_t*); void win_open(win_t*);