Skip to content

Commit

Permalink
x: wid_get_text_prop doesn't need the whole session_t
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
  • Loading branch information
yshui committed Feb 16, 2024
1 parent 7c15a14 commit b99c7db
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/c2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions src/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 5 additions & 7 deletions src/x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/x.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b99c7db

Please sign in to comment.