void store_float_geom(struct ws_win *, struct swm_region *);
int floating_toggle_win(struct ws_win *);
void spawn_select(struct swm_region *, union arg *, char *, int *);
-unsigned char *get_win_name(Display *, Window, Atom, Atom, unsigned long *);
+unsigned char *get_win_name(Window);
int
-get_property(Window id, Atom atom, long count, Atom type,
- unsigned long *n, unsigned char **data)
+get_property(Window id, Atom atom, long count, Atom type, unsigned long *nitems,
+ unsigned long *nbytes, unsigned char **data)
{
int format, status;
- unsigned long tmp, extra;
- unsigned long *nitems;
+ unsigned long *nbytes_ret, *nitems_ret;
+ unsigned long nbytes_tmp, nitems_tmp;
Atom real;
- nitems = n != NULL ? n : &tmp;
+ nbytes_ret = nbytes != NULL ? nbytes : &nbytes_tmp;
+ nitems_ret = nitems != NULL ? nitems : &nitems_tmp;
+
status = XGetWindowProperty(display, id, atom, 0L, count, False, type,
- &real, &format, nitems, &extra, data);
+ &real, &format, nitems_ret, nbytes_ret, data);
if (status != Success)
return False;
for (i = 0; i < ScreenCount(display); i++) {
/* Get the support check window and destroy it */
success = get_property(screens[i].root, sup_check, 1, XA_WINDOW,
- &n, &data);
+ &n, NULL, &data);
if (success) {
id = data[0];
Atom type;
success = get_property(win->id, ewmh[_NET_WM_WINDOW_TYPE].atom, (~0L),
- XA_ATOM, &n, (void *)&data);
+ XA_ATOM, &n, NULL, (void *)&data);
if (!success) {
XFree(data);
win->ewmh_flags |= SWM_F_MANUAL;
success = get_property(win->id, ewmh[_NET_WM_STATE].atom,
- (~0L), XA_ATOM, &n, (void *)&states);
+ (~0L), XA_ATOM, &n, NULL, (void *)&states);
if (!success)
return;
bar_window_name(char *s, ssize_t sz, struct ws_win *cur_focus)
{
unsigned char *title;
- unsigned long len;
if (window_name_enabled && cur_focus != NULL) {
- if ((title = get_win_name(display, cur_focus->id, a_netwmname,
- a_utf8_string, &len)) != NULL) {
+ title = get_win_name(cur_focus->id);
+ if (title != NULL) {
DNPRINTF(SWM_D_BAR, "bar_window_name: title: %s\n",
title);
unsigned char *p = NULL;
unsigned long n;
- if (!get_property(w, astate, 2L, astate, &n, &p))
+ if (!get_property(w, astate, 2L, astate, &n, NULL, &p))
return (-1);
if (n != 0)
result = *((long *)p);
}
unsigned char *
-get_win_name(Display *dpy, Window win, Atom wname, Atom stype,
- unsigned long *slen)
+get_win_name(Window win)
{
- int status, retfmt;
- unsigned long nitems, nbytes, nextra;
unsigned char *prop = NULL;
- Atom rettype;
+ unsigned long nbytes, nitems;
- status = XGetWindowProperty(dpy, win, wname, 0L, 0L, False, stype,
- &rettype, &retfmt, &nitems, &nbytes, &prop);
- if (status != Success)
- return (NULL);
+ /* try _NET_WM_NAME first */
+ if (get_property(win, a_netwmname, 0L, a_utf8_string, NULL, &nbytes,
+ &prop)) {
+ XFree(prop);
+ if (get_property(win, a_netwmname, nbytes, a_utf8_string,
+ &nitems, NULL, &prop))
+ return (prop);
+ }
+
+ /* fallback to WM_NAME */
+ if (!get_property(win, a_wmname, 0L, a_string, NULL, &nbytes, &prop))
+ return (NULL);
XFree(prop);
+ if (get_property(win, a_wmname, nbytes, a_string, &nitems, NULL, &prop))
+ return (prop);
- status = XGetWindowProperty(dpy, win, wname, 0L, nbytes, False,
- stype, &rettype, &retfmt, &nitems, &nextra, &prop);
- if (status != Success) {
- XFree(prop);
- return (NULL);
- }
- if (rettype != stype) {
- XFree(prop);
- return (NULL);
- }
- *slen = nitems;
- return (prop);
+ return (NULL);
}
void
FILE *lfile;
unsigned char *name;
int count = 0;
- unsigned long len;
DNPRINTF(SWM_D_MISC, "uniconify\n");
if (win->iconic == 0)
continue;
- name = get_win_name(display, win->id, a_netwmname,
- a_utf8_string, &len);
+ name = get_win_name(win->id);
if (name == NULL)
continue;
fprintf(lfile, "%s.%lu\n", name, win->id);
TAILQ_FOREACH(win, &search_r->ws->winlist, entry) {
if (win->iconic == 0)
continue;
- name = get_win_name(display, win->id, a_netwmname,
- a_utf8_string, &len);
+ name = get_win_name(win->id);
if (name == NULL)
continue;
if (asprintf(&s, "%s.%lu", name, win->id) == -1) {