mirror of
https://codeberg.org/nsxiv/nsxiv
synced 2024-11-15 12:13:10 +00:00
Unified X atom initialization
This commit is contained in:
parent
f6510b0a04
commit
e2fa49ecfe
2
Makefile
2
Makefile
@ -1,4 +1,4 @@
|
|||||||
VERSION = git-20140131
|
VERSION = git-20140202
|
||||||
|
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
MANPREFIX = $(PREFIX)/share/man
|
MANPREFIX = $(PREFIX)/share/man
|
||||||
|
2
main.c
2
main.c
@ -682,7 +682,7 @@ void run(void)
|
|||||||
on_buttonpress(&ev.xbutton);
|
on_buttonpress(&ev.xbutton);
|
||||||
break;
|
break;
|
||||||
case ClientMessage:
|
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;
|
return;
|
||||||
break;
|
break;
|
||||||
case ConfigureNotify:
|
case ConfigureNotify:
|
||||||
|
29
window.c
29
window.c
@ -42,8 +42,6 @@ static Cursor chand;
|
|||||||
static Cursor cwatch;
|
static Cursor cwatch;
|
||||||
static GC gc;
|
static GC gc;
|
||||||
|
|
||||||
Atom wm_delete_win;
|
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
int ascent;
|
int ascent;
|
||||||
int descent;
|
int descent;
|
||||||
@ -54,6 +52,8 @@ static struct {
|
|||||||
static int fontheight;
|
static int fontheight;
|
||||||
static int barheight;
|
static int barheight;
|
||||||
|
|
||||||
|
Atom atoms[ATOM_COUNT];
|
||||||
|
|
||||||
void win_init_font(Display *dpy, const char *fontstr)
|
void win_init_font(Display *dpy, const char *fontstr)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
@ -102,6 +102,9 @@ unsigned long win_alloc_color(win_t *win, const char *name)
|
|||||||
return col.pixel;
|
return col.pixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define INIT_ATOM_(atom) \
|
||||||
|
atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False);
|
||||||
|
|
||||||
void win_init(win_t *win)
|
void win_init(win_t *win)
|
||||||
{
|
{
|
||||||
win_env_t *e;
|
win_env_t *e;
|
||||||
@ -141,7 +144,12 @@ void win_init(win_t *win)
|
|||||||
/* actual min/max values set in win_update_sizehints() */
|
/* actual min/max values set in win_update_sizehints() */
|
||||||
win->sizehints.flags |= PMinSize | PMaxSize;
|
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)
|
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];
|
icon_data[n++] = icon_colors[icons[i].data[j] & 0x0F];
|
||||||
}
|
}
|
||||||
XChangeProperty(e->dpy, win->xwin,
|
XChangeProperty(e->dpy, win->xwin,
|
||||||
XInternAtom(e->dpy, "_NET_WM_ICON", False),
|
atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32,
|
||||||
XA_CARDINAL, 32,
|
|
||||||
i == 0 ? PropModeReplace : PropModeAppend,
|
i == 0 ? PropModeReplace : PropModeAppend,
|
||||||
(unsigned char *) icon_data, n);
|
(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";
|
classhint.res_name = options->res_name != NULL ? options->res_name : "sxiv";
|
||||||
XSetClassHint(e->dpy, win->xwin, &classhint);
|
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->h -= win->bar.h;
|
||||||
win_update_sizehints(win);
|
win_update_sizehints(win);
|
||||||
@ -379,10 +386,10 @@ void win_toggle_fullscreen(win_t *win)
|
|||||||
|
|
||||||
cm = &ev.xclient;
|
cm = &ev.xclient;
|
||||||
cm->window = win->xwin;
|
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->format = 32;
|
||||||
cm->data.l[0] = win->fullscreen;
|
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;
|
cm->data.l[2] = cm->data.l[3] = 0;
|
||||||
|
|
||||||
XSendEvent(win->env.dpy, DefaultRootWindow(win->env.dpy), False,
|
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);
|
XStoreName(win->env.dpy, win->xwin, title);
|
||||||
XSetIconName(win->env.dpy, win->xwin, title);
|
XSetIconName(win->env.dpy, win->xwin, title);
|
||||||
|
|
||||||
XChangeProperty(win->env.dpy, win->xwin,
|
XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_NAME],
|
||||||
XInternAtom(win->env.dpy, "_NET_WM_NAME", False),
|
|
||||||
XInternAtom(win->env.dpy, "UTF8_STRING", False), 8,
|
XInternAtom(win->env.dpy, "UTF8_STRING", False), 8,
|
||||||
PropModeReplace, (unsigned char *) title, strlen(title));
|
PropModeReplace, (unsigned char *) title, strlen(title));
|
||||||
XChangeProperty(win->env.dpy, win->xwin,
|
XChangeProperty(win->env.dpy, win->xwin, atoms[ATOM__NET_WM_ICON_NAME],
|
||||||
XInternAtom(win->env.dpy, "_NET_WM_ICON_NAME", False),
|
|
||||||
XInternAtom(win->env.dpy, "UTF8_STRING", False), 8,
|
XInternAtom(win->env.dpy, "UTF8_STRING", False), 8,
|
||||||
PropModeReplace, (unsigned char *) title, strlen(title));
|
PropModeReplace, (unsigned char *) title, strlen(title));
|
||||||
}
|
}
|
||||||
|
12
window.h
12
window.h
@ -29,6 +29,16 @@ enum {
|
|||||||
BAR_R_LEN = 64
|
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 {
|
typedef struct {
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
int scr;
|
int scr;
|
||||||
@ -67,7 +77,7 @@ typedef struct {
|
|||||||
} bar;
|
} bar;
|
||||||
} win_t;
|
} win_t;
|
||||||
|
|
||||||
extern Atom wm_delete_win;
|
extern Atom atoms[ATOM_COUNT];
|
||||||
|
|
||||||
void win_init(win_t*);
|
void win_init(win_t*);
|
||||||
void win_open(win_t*);
|
void win_open(win_t*);
|
||||||
|
Loading…
Reference in New Issue
Block a user