X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=scrotwm.c;h=789aca0707d075a8dfa66d9c18b7cb210467dca8;hb=739a5e6e3218529604d7a36cda21910719897e7b;hp=bc891bab21ddb8c6c0ca9bc23231a9d4d00438cc;hpb=79e879c9eec53536b37f0b089f68a693821af9dd;p=spectrwm.git diff --git a/scrotwm.c b/scrotwm.c index bc891ba..789aca0 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -563,20 +563,22 @@ struct ewmh_hint { 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, 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; @@ -670,7 +672,7 @@ teardown_ewmh(void) 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]; @@ -691,7 +693,7 @@ ewmh_autoquirk(struct ws_win *win) 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); @@ -877,7 +879,7 @@ ewmh_get_win_state(struct ws_win *win) 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; @@ -1354,10 +1356,9 @@ void 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) { - title = get_win_name(display, cur_focus->id, &len); + title = get_win_name(cur_focus->id); if (title != NULL) { DNPRINTF(SWM_D_BAR, "bar_window_name: title: %s\n", title); @@ -1651,7 +1652,7 @@ getstate(Window w) 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); @@ -3313,31 +3314,28 @@ iconify(struct swm_region *r, union arg *args) } unsigned char * -get_win_name(Display *dpy, Window win, 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, a_netwmname, 0L, 0L, False, - a_utf8_string, &rettype, &retfmt, &nitems, &nbytes, &prop); - if (status != Success) - return (NULL); - XFree(prop); - - status = XGetWindowProperty(dpy, win, a_netwmname, 0L, nbytes, False, - a_utf8_string, &rettype, &retfmt, &nitems, &nextra, &prop); - if (status != Success) { + /* try _NET_WM_NAME first */ + if (get_property(win, a_netwmname, 0L, a_utf8_string, NULL, &nbytes, + &prop)) { XFree(prop); - return (NULL); + if (get_property(win, a_netwmname, nbytes, a_utf8_string, + &nitems, NULL, &prop)) + return (prop); } - if (rettype != a_utf8_string) { - XFree(prop); + + /* fallback to WM_NAME */ + if (!get_property(win, a_wmname, 0L, a_string, NULL, &nbytes, &prop)) return (NULL); - } - *slen = nitems; - return (prop); + XFree(prop); + if (get_property(win, a_wmname, nbytes, a_string, &nitems, NULL, &prop)) + return (prop); + + return (NULL); } void @@ -3347,7 +3345,6 @@ uniconify(struct swm_region *r, union arg *args) FILE *lfile; unsigned char *name; int count = 0; - unsigned long len; DNPRINTF(SWM_D_MISC, "uniconify\n"); @@ -3379,7 +3376,7 @@ uniconify(struct swm_region *r, union arg *args) if (win->iconic == 0) continue; - name = get_win_name(display, win->id, &len); + name = get_win_name(win->id); if (name == NULL) continue; fprintf(lfile, "%s.%lu\n", name, win->id); @@ -3536,7 +3533,7 @@ search_resp_uniconify(char *resp, unsigned long len) TAILQ_FOREACH(win, &search_r->ws->winlist, entry) { if (win->iconic == 0) continue; - name = get_win_name(display, win->id, &len); + name = get_win_name(win->id); if (name == NULL) continue; if (asprintf(&s, "%s.%lu", name, win->id) == -1) {