Krolyxon
Commit e2fa49e

Branches

Refs →

nsxive2fa49e

Unified X atom initialization

Author
Bert Münnich
Date
2014-01-27 23:16 +0100
Committer
Bert Münnich · 2014-02-02 14:36 +0100
Parent
f6510b0
Commit
e2fa49ecfea58d8ec77b633fcee66e2b7ed95467

+30 −15

4 files changed

  1. M Makefile +1 −1
  2. M main.c +1 −1
  3. M window.c +17 −12
  4. M window.h +11 −1
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20140131
1+VERSION = git-20140202
22
33 PREFIX = /usr/local
44 MANPREFIX = $(PREFIX)/share/man
M main.c View
@@ -682,7 +682,7 @@ void run(void)
682682 on_buttonpress(&ev.xbutton);
683683 break;
684684 case ClientMessage:
685− if ((Atom) ev.xclient.data.l[0] == wm_delete_win)
685+ if ((Atom) ev.xclient.data.l[0] == atoms[ATOM_WM_DELETE_WINDOW])
686686 return;
687687 break;
688688 case ConfigureNotify:
M window.c View
@@ -42,8 +42,6 @@ static Cursor chand;
4242 static Cursor cwatch;
4343 static GC gc;
4444
45−Atom wm_delete_win;
46−
4745 static struct {
4846 int ascent;
4947 int descent;
@@ -54,6 +52,8 @@ static struct {
5452 static int fontheight;
5553 static int barheight;
5654
55+Atom atoms[ATOM_COUNT];
56+
5757 void win_init_font(Display *dpy, const char *fontstr)
5858 {
5959 int n;
@@ -102,6 +102,9 @@ unsigned long win_alloc_color(win_t *win, const char *name)
102102 return col.pixel;
103103 }
104104
105+#define INIT_ATOM_(atom) \
106+ atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False);
107+
105108 void win_init(win_t *win)
106109 {
107110 win_env_t *e;
@@ -141,7 +144,12 @@ void win_init(win_t *win)
141144 /* actual min/max values set in win_update_sizehints() */
142145 win->sizehints.flags |= PMinSize | PMaxSize;
143146
144− wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False);
147+ INIT_ATOM_(WM_DELETE_WINDOW);
148+ INIT_ATOM_(_NET_WM_NAME);
149+ INIT_ATOM_(_NET_WM_ICON_NAME);
150+ INIT_ATOM_(_NET_WM_ICON);
151+ INIT_ATOM_(_NET_WM_STATE);
152+ INIT_ATOM_(_NET_WM_STATE_FULLSCREEN);
145153 }
146154
147155 void win_update_sizehints(win_t *win)
@@ -258,8 +266,7 @@ void win_open(win_t *win)
258266 icon_data[n++] = icon_colors[icons[i].data[j] & 0x0F];
259267 }
260268 XChangeProperty(e->dpy, win->xwin,
261− XInternAtom(e->dpy, "_NET_WM_ICON", False),
262− XA_CARDINAL, 32,
269+ atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32,
263270 i == 0 ? PropModeReplace : PropModeAppend,
264271 (unsigned char *) icon_data, n);
265272 }
@@ -271,7 +278,7 @@ void win_open(win_t *win)
271278 classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv";
272279 XSetClassHint(e->dpy, win->xwin, &classhint);
273280
274− XSetWMProtocols(e->dpy, win->xwin, &wm_delete_win, 1);
281+ XSetWMProtocols(e->dpy, win->xwin, &atoms[ATOM_WM_DELETE_WINDOW], 1);
275282
276283 win->h -= win->bar.h;
277284 win_update_sizehints(win);
@@ -379,10 +386,10 @@ void win_toggle_fullscreen(win_t *win)
379386
380387 cm = &ev.xclient;
381388 cm->window = win->xwin;
382− cm->message_type = XInternAtom(win->env.dpy, "_NET_WM_STATE", False);
389+ cm->message_type = atoms[ATOM__NET_WM_STATE];
383390 cm->format = 32;
384391 cm->data.l[0] = win->fullscreen;
385− cm->data.l[1] = XInternAtom(win->env.dpy, "_NET_WM_STATE_FULLSCREEN", False);
392+ cm->data.l[1] = atoms[ATOM__NET_WM_STATE_FULLSCREEN];
386393 cm->data.l[2] = cm->data.l[3] = 0;
387394
388395 XSendEvent(win->env.dpy, DefaultRootWindow(win->env.dpy), False,
@@ -540,12 +547,10 @@ void win_set_title(win_t *win, const char *title)
540547 XStoreName(win->env.dpy, win->xwin, title);
541548 XSetIconName(win->env.dpy, win->xwin, title);
542549
543− XChangeProperty(win->env.dpy, win->xwin,
544− XInternAtom(win->env.dpy, "_NET_WM_NAME", False),
550+ XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_NAME],
545551 XInternAtom(win->env.dpy, "UTF8_STRING", False), 8,
546552 PropModeReplace, (unsigned char *) title, strlen(title));
547− XChangeProperty(win->env.dpy, win->xwin,
548− XInternAtom(win->env.dpy, "_NET_WM_ICON_NAME", False),
553+ XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_ICON_NAME],
549554 XInternAtom(win->env.dpy, "UTF8_STRING", False), 8,
550555 PropModeReplace, (unsigned char *) title, strlen(title));
551556 }
M window.h View
@@ -29,6 +29,16 @@ enum {
2929 BAR_R_LEN = 64
3030 };
3131
32+enum {
33+ ATOM_WM_DELETE_WINDOW,
34+ ATOM__NET_WM_NAME,
35+ ATOM__NET_WM_ICON_NAME,
36+ ATOM__NET_WM_ICON,
37+ ATOM__NET_WM_STATE,
38+ ATOM__NET_WM_STATE_FULLSCREEN,
39+ ATOM_COUNT
40+};
41+
3242 typedef struct {
3343 Display *dpy;
3444 int scr;
@@ -67,7 +77,7 @@ typedef struct {
6777 } bar;
6878 } win_t;
6979
70−extern Atom wm_delete_win;
80+extern Atom atoms[ATOM_COUNT];
7181
7282 void win_init(win_t*);
7383 void win_open(win_t*);