Added "pinned" option for setxwinstate, addresses #4

This commit is contained in:
Jarcode
2018-06-02 09:28:13 -07:00
parent 279437dcd1
commit 4cc8a5e3ba
4 changed files with 38 additions and 20 deletions

2
glad

Submodule glad updated: ec01ac515d...c33992f23c

View File

@@ -74,7 +74,7 @@
"modal", "sticky", "maximized_vert", "maximized_horz", "modal", "sticky", "maximized_vert", "maximized_horz",
"shaded", "skip_taskbar", "skip_pager", "hidden", "fullscreen", "shaded", "skip_taskbar", "skip_pager", "hidden", "fullscreen",
"above", "below", "demands_attention", "focused" "above", "below", "demands_attention", "focused", "pinned"
This will add _NET_WM_STATE_(TYPE) atoms to _NET_WM_STATE, This will add _NET_WM_STATE_(TYPE) atoms to _NET_WM_STATE,
where (TYPE) is one of the window states listed (after being where (TYPE) is one of the window states listed (after being
@@ -89,6 +89,7 @@
// #request addxwinstate "skip_taskbar" // #request addxwinstate "skip_taskbar"
// #request addxwinstate "skip_pager" // #request addxwinstate "skip_pager"
// #request addxwinstate "above" // #request addxwinstate "above"
// #request addxwinstate "pinned"
/* PulseAudio source. Can be a number or a name of an audio /* PulseAudio source. Can be a number or a name of an audio
sink or device to record from. Set to "auto" to use the sink or device to record from. Set to "auto" to use the

50
xwin.c
View File

@@ -107,37 +107,51 @@ bool xwin_should_render(struct renderer* rd) {
return ret; return ret;
} }
static bool xwin_changeatom(struct gl_wcb* wcb, void* impl, const char* type, /* Create string copy on stack with upcase chars */
#define S_UPPER(in, out) char out[strlen(in) + 1]; \
do { \
for (size_t t = 0; t < sizeof(out) / sizeof(char); ++t) { \
char c = in[t]; \
switch (c) { \
case 'a' ... 'z': c -= 'a' - 'A'; \
default: out[t] = c; \
} \
} \
} while (0)
static void xwin_changeatom(struct gl_wcb* wcb, void* impl, const char* type,
const char* atom, const char* fmt, int mode) { const char* atom, const char* fmt, int mode) {
Window w = wcb->get_x11_window(impl); Window w = wcb->get_x11_window(impl);
Display* d = wcb->get_x11_display(); Display* d = wcb->get_x11_display();
Atom wtype = XInternAtom(d, atom, false); Atom wtype = XInternAtom(d, atom, false);
size_t len = strlen(type), t;
char formatted[len + 1];
for (t = 0; t < len + 1; ++t) {
char c = type[t];
switch (c) {
case 'a' ... 'z': c -= 'a' - 'A';
default: formatted[t] = c;
}
}
bool ret = !strcmp(formatted, "DESKTOP");
char buf[256]; char buf[256];
snprintf(buf, sizeof(buf), fmt, formatted); snprintf(buf, sizeof(buf), fmt, type);
Atom desk = XInternAtom(d, buf, false); Atom desk = XInternAtom(d, buf, false);
XChangeProperty(d, w, wtype, XA_ATOM, 32, mode, (unsigned char*) &desk, 1); XChangeProperty(d, w, wtype, XA_ATOM, 32, mode, (unsigned char*) &desk, 1);
return ret;
} }
/* Set window types defined by the EWMH standard, possible values: /* Set window types defined by the EWMH standard, possible values:
-> "desktop", "dock", "toolbar", "menu", "utility", "splash", "dialog", "normal" */ -> "desktop", "dock", "toolbar", "menu", "utility", "splash", "dialog", "normal" */
bool xwin_settype(struct gl_wcb* wcb, void* impl, const char* type) { bool xwin_settype(struct gl_wcb* wcb, void* impl, const char* rtype) {
return xwin_changeatom(wcb, impl, type, "_NET_WM_WINDOW_TYPE", S_UPPER(rtype, type);
"_NET_WM_WINDOW_TYPE_%s", PropModeReplace); xwin_changeatom(wcb, impl, type, "_NET_WM_WINDOW_TYPE",
"_NET_WM_WINDOW_TYPE_%s", PropModeReplace);
return !strcmp(type, "DESTKTOP");
} }
void xwin_addstate(struct gl_wcb* wcb, void* impl, const char* state) { void xwin_addstate(struct gl_wcb* wcb, void* impl, const char* rstate) {
xwin_changeatom(wcb, impl, state, "_NET_WM_STATE", "_NET_WM_STATE_%s", PropModeAppend); S_UPPER(rstate, state);
if (strcmp(state, "PINNED"))
xwin_changeatom(wcb, impl, state, "_NET_WM_STATE", "_NET_WM_STATE_%s", PropModeAppend);
else
xwin_setdesktop(wcb, impl, XWIN_ALL_DESKTOPS);
}
void xwin_setdesktop(struct gl_wcb* wcb, void* impl, unsigned long desktop) {
Window w = wcb->get_x11_window(impl);
Display* d = wcb->get_x11_display();
Atom wtype = XInternAtom(d, "_NET_WM_DESKTOP", false);
XChangeProperty(d, w, wtype, XA_CARDINAL, 32, PropModeReplace, (unsigned char*) &desktop, 1);
} }
static Drawable get_drawable(Display* d, Window w) { static Drawable get_drawable(Display* d, Window w) {

3
xwin.h
View File

@@ -1,5 +1,8 @@
#define XWIN_ALL_DESKTOPS 0xFFFFFFFF
bool xwin_should_render(struct renderer* rd); bool xwin_should_render(struct renderer* rd);
bool xwin_settype(struct gl_wcb* wcb, void* impl, const char* type); bool xwin_settype(struct gl_wcb* wcb, void* impl, const char* type);
void xwin_setdesktop(struct gl_wcb* wcb, void* impl, unsigned long desktop);
void xwin_addstate(struct gl_wcb* wcb, void* impl, const char* state); void xwin_addstate(struct gl_wcb* wcb, void* impl, const char* state);
unsigned int xwin_copyglbg(struct renderer* rd, unsigned int texture); unsigned int xwin_copyglbg(struct renderer* rd, unsigned int texture);