From b99c7db73eb62204568c21d9542dce5388d4d356 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Wed, 14 Feb 2024 18:02:14 +0000 Subject: [PATCH] x: wid_get_text_prop doesn't need the whole session_t Signed-off-by: Yuxuan Shui --- src/c2.c | 3 ++- src/win.c | 12 ++++++++---- src/x.c | 12 +++++------- src/x.h | 4 ++-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/c2.c b/src/c2.c index 140d2746..e039821f 100644 --- a/src/c2.c +++ b/src/c2.c @@ -1509,7 +1509,8 @@ static inline void c2_match_once_leaf(session_t *ps, const struct managed_win *w else { char **strlst = NULL; int nstr = 0; - if (wid_get_text_prop(ps, wid, pleaf->tgtatom, &strlst, &nstr)) { + if (wid_get_text_prop(&ps->c, ps->atoms, wid, pleaf->tgtatom, + &strlst, &nstr)) { if (pleaf->index < 0 && nstr > 0 && strlen(strlst[0]) > 0) { ntargets = to_u32_checked(nstr); targets = (const char **)strlst; diff --git a/src/win.c b/src/win.c index a9660227..9a0e193e 100644 --- a/src/win.c +++ b/src/win.c @@ -658,12 +658,14 @@ int win_update_name(session_t *ps, struct managed_win *w) { return 0; } - if (!(wid_get_text_prop(ps, w->client_win, ps->atoms->a_NET_WM_NAME, &strlst, &nstr))) { + if (!(wid_get_text_prop(&ps->c, ps->atoms, w->client_win, + ps->atoms->a_NET_WM_NAME, &strlst, &nstr))) { log_debug("(%#010x): _NET_WM_NAME unset, falling back to " "WM_NAME.", w->client_win); - if (!wid_get_text_prop(ps, w->client_win, ps->atoms->aWM_NAME, &strlst, &nstr)) { + if (!wid_get_text_prop(&ps->c, ps->atoms, w->client_win, + ps->atoms->aWM_NAME, &strlst, &nstr)) { log_debug("Unsetting window name for %#010x", w->client_win); free(w->name); w->name = NULL; @@ -690,7 +692,8 @@ static int win_update_role(session_t *ps, struct managed_win *w) { char **strlst = NULL; int nstr = 0; - if (!wid_get_text_prop(ps, w->client_win, ps->atoms->aWM_WINDOW_ROLE, &strlst, &nstr)) { + if (!wid_get_text_prop(&ps->c, ps->atoms, w->client_win, + ps->atoms->aWM_WINDOW_ROLE, &strlst, &nstr)) { return -1; } @@ -1876,7 +1879,8 @@ bool win_update_class(session_t *ps, struct managed_win *w) { w->class_general = NULL; // Retrieve the property string list - if (!wid_get_text_prop(ps, w->client_win, ps->atoms->aWM_CLASS, &strlst, &nstr)) { + if (!wid_get_text_prop(&ps->c, ps->atoms, w->client_win, ps->atoms->aWM_CLASS, + &strlst, &nstr)) { return false; } diff --git a/src/x.c b/src/x.c index f33142b2..a5f25ab2 100644 --- a/src/x.c +++ b/src/x.c @@ -182,10 +182,9 @@ xcb_window_t wid_get_prop_window(struct x_connection *c, xcb_window_t wid, xcb_a /** * Get the value of a text property of a window. */ -bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char ***pstrlst, - int *pnstr) { - assert(ps->server_grabbed); - auto prop_info = x_get_prop_info(&ps->c, wid, prop); +bool wid_get_text_prop(struct x_connection *c, struct atom *atoms, xcb_window_t wid, + xcb_atom_t prop, char ***pstrlst, int *pnstr) { + auto prop_info = x_get_prop_info(c, wid, prop); auto type = prop_info.type; auto format = prop_info.format; auto length = prop_info.length; @@ -194,8 +193,7 @@ bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char ** return false; } - if (type != XCB_ATOM_STRING && type != ps->atoms->aUTF8_STRING && - type != ps->atoms->aC_STRING) { + if (type != XCB_ATOM_STRING && type != atoms->aUTF8_STRING && type != atoms->aC_STRING) { log_warn("Text property %d of window %#010x has unsupported type: %d", prop, wid, type); return false; @@ -210,7 +208,7 @@ bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char ** xcb_generic_error_t *e = NULL; auto word_count = (length + 4 - 1) / 4; auto r = xcb_get_property_reply( - ps->c.c, xcb_get_property(ps->c.c, 0, wid, prop, type, 0, word_count), &e); + c->c, xcb_get_property(c->c, 0, wid, prop, type, 0, word_count), &e); if (!r) { log_debug_x_error(e, "Failed to get window property for %#010x", wid); free(e); diff --git a/src/x.h b/src/x.h index f465b22a..78cd55d2 100644 --- a/src/x.h +++ b/src/x.h @@ -261,8 +261,8 @@ xcb_window_t wid_get_prop_window(struct x_connection *c, xcb_window_t wid, xcb_a * array * @param[out] pnstr Number of strings in the array */ -bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, char ***pstrlst, - int *pnstr); +bool wid_get_text_prop(struct x_connection *c, struct atom *atoms, xcb_window_t wid, + xcb_atom_t prop, char ***pstrlst, int *pnstr); const xcb_render_pictforminfo_t * x_get_pictform_for_visual(struct x_connection *, xcb_visualid_t);