From 640ef0437814dbc4df57a275cbadecb368ad0950 Mon Sep 17 00:00:00 2001 From: Richard Grenville Date: Sun, 10 Nov 2013 10:13:18 +0800 Subject: [PATCH] Misc: Add properties to the registration window Add WM_CLASS, COMPTON_VERSION, and _NET_WM_PID properties to the registration window, to ease the development of pcman's compton-conf. --- compton.c | 27 +++++++++++++++++++++++++-- compton.h | 23 ++++++++++++++++++++--- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/compton.c b/compton.c index 770721596..7adfba179 100644 --- a/compton.c +++ b/compton.c @@ -4543,8 +4543,31 @@ register_cm(session_t *ps) { if (ps->redirected) XCompositeUnredirectWindow(ps->dpy, ps->reg_win, CompositeRedirectManual); - Xutf8SetWMProperties(ps->dpy, ps->reg_win, "xcompmgr", "xcompmgr", - NULL, 0, NULL, NULL, NULL); + { + XClassHint *h = XAllocClassHint(); + if (h) { + h->res_name = "compton"; + h->res_class = "xcompmgr"; + } + Xutf8SetWMProperties(ps->dpy, ps->reg_win, "xcompmgr", "xcompmgr", + NULL, 0, NULL, NULL, h); + cxfree(h); + } + + // Set _NET_WM_PID + { + long pid = getpid(); + if (!XChangeProperty(ps->dpy, ps->reg_win, + get_atom(ps, "_NET_WM_PID"), XA_CARDINAL, 32, PropModeReplace, + (unsigned char *) &pid, 1)) { + printf_errf("(): Failed to set _NET_WM_PID."); + } + } + + // Set COMPTON_VERSION + if (!wid_set_text_prop(ps, ps->reg_win, get_atom(ps, "COMPTON_VERSION"), COMPTON_VERSION)) { + printf_errf("(): Failed to set COMPTON_VERSION."); + } { unsigned len = strlen(REGISTER_PROP) + 2; diff --git a/compton.h b/compton.h index cb16111a8..42ce5e7f2 100644 --- a/compton.h +++ b/compton.h @@ -337,9 +337,7 @@ isdamagenotify(session_t *ps, const XEvent *ev) { */ static inline XTextProperty * make_text_prop(session_t *ps, char *str) { - XTextProperty *pprop = malloc(sizeof(XTextProperty)); - if (!pprop) - printf_errfq(1, "(): Failed to allocate memory."); + XTextProperty *pprop = cmalloc(1, XTextProperty); if (XmbTextListToTextProperty(ps->dpy, &str, 1, XStringStyle, pprop)) { cxfree(pprop->value); @@ -350,6 +348,25 @@ make_text_prop(session_t *ps, char *str) { return pprop; } + +/** + * Set a single-string text property on a window. + */ +static inline bool +wid_set_text_prop(session_t *ps, Window wid, Atom prop_atom, char *str) { + XTextProperty *pprop = make_text_prop(ps, str); + if (!pprop) { + printf_errf("(\"%s\"): Failed to make text property.", str); + return false; + } + + XSetTextProperty(ps->dpy, wid, pprop, prop_atom); + cxfree(pprop->value); + cxfree(pprop); + + return true; +} + static void run_fade(session_t *ps, win *w, unsigned steps);