| @@ -42,8 +42,6 @@ static Cursor chand; |
| 42 | 42 | | static Cursor cwatch; |
| 43 | 43 | | static GC gc; |
| 44 | 44 | | |
| 45 | | − | Atom wm_delete_win; |
| 46 | | − | |
| 47 | 45 | | static struct { |
| 48 | 46 | | int ascent; |
| 49 | 47 | | int descent; |
| @@ -54,6 +52,8 @@ static struct { |
| 54 | 52 | | static int fontheight; |
| 55 | 53 | | static int barheight; |
| 56 | 54 | | |
| 55 | + | Atom atoms[ATOM_COUNT]; |
| 56 | + | |
| 57 | 57 | | void win_init_font(Display *dpy, const char *fontstr) |
| 58 | 58 | | { |
| 59 | 59 | | int n; |
| @@ -102,6 +102,9 @@ unsigned long win_alloc_color(win_t *win, const char *name) |
| 102 | 102 | | return col.pixel; |
| 103 | 103 | | } |
| 104 | 104 | | |
| 105 | + | #define INIT_ATOM_(atom) \ |
| 106 | + | atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False); |
| 107 | + | |
| 105 | 108 | | void win_init(win_t *win) |
| 106 | 109 | | { |
| 107 | 110 | | win_env_t *e; |
| @@ -141,7 +144,12 @@ void win_init(win_t *win) |
| 141 | 144 | | /* actual min/max values set in win_update_sizehints() */ |
| 142 | 145 | | win->sizehints.flags |= PMinSize | PMaxSize; |
| 143 | 146 | | |
| 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); |
| 145 | 153 | | } |
| 146 | 154 | | |
| 147 | 155 | | void win_update_sizehints(win_t *win) |
| @@ -258,8 +266,7 @@ void win_open(win_t *win) |
| 258 | 266 | | icon_data[n++] = icon_colors[icons[i].data[j] & 0x0F]; |
| 259 | 267 | | } |
| 260 | 268 | | 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, |
| 263 | 270 | | i == 0 ? PropModeReplace : PropModeAppend, |
| 264 | 271 | | (unsigned char *) icon_data, n); |
| 265 | 272 | | } |
| @@ -271,7 +278,7 @@ void win_open(win_t *win) |
| 271 | 278 | | classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv"; |
| 272 | 279 | | XSetClassHint(e->dpy, win->xwin, &classhint); |
| 273 | 280 | | |
| 274 | | − | XSetWMProtocols(e->dpy, win->xwin, &wm_delete_win, 1); |
| 281 | + | XSetWMProtocols(e->dpy, win->xwin, &atoms[ATOM_WM_DELETE_WINDOW], 1); |
| 275 | 282 | | |
| 276 | 283 | | win->h -= win->bar.h; |
| 277 | 284 | | win_update_sizehints(win); |
| @@ -379,10 +386,10 @@ void win_toggle_fullscreen(win_t *win) |
| 379 | 386 | | |
| 380 | 387 | | cm = &ev.xclient; |
| 381 | 388 | | 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]; |
| 383 | 390 | | cm->format = 32; |
| 384 | 391 | | 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]; |
| 386 | 393 | | cm->data.l[2] = cm->data.l[3] = 0; |
| 387 | 394 | | |
| 388 | 395 | | XSendEvent(win->env.dpy, DefaultRootWindow(win->env.dpy), False, |
| @@ -540,12 +547,10 @@ void win_set_title(win_t *win, const char *title) |
| 540 | 547 | | XStoreName(win->env.dpy, win->xwin, title); |
| 541 | 548 | | XSetIconName(win->env.dpy, win->xwin, title); |
| 542 | 549 | | |
| 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], |
| 545 | 551 | | XInternAtom(win->env.dpy, "UTF8_STRING", False), 8, |
| 546 | 552 | | 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], |
| 549 | 554 | | XInternAtom(win->env.dpy, "UTF8_STRING", False), 8, |
| 550 | 555 | | PropModeReplace, (unsigned char *) title, strlen(title)); |
| 551 | 556 | | } |