Skip to content

Commit

Permalink
c2: c2_match_once_leaf_string doesn't need the whole session_t
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Feb 15, 2024
1 parent 12fc4f2 commit 0fb51ff
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/c2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1597,8 +1597,8 @@ static bool c2_string_op(const c2_l_t *leaf, const char *target) {
unreachable();
}

static bool
c2_match_once_leaf_string(session_t *ps, const struct managed_win *w, const c2_l_t *leaf) {
static bool c2_match_once_leaf_string(struct x_connection *c, struct atom *atoms,
const struct managed_win *w, const c2_l_t *leaf) {

const char **targets = NULL;
const char **targets_free = NULL;
Expand Down Expand Up @@ -1626,12 +1626,12 @@ c2_match_once_leaf_string(session_t *ps, const struct managed_win *w, const c2_l
if (leaf->index < 0) {

Check warning on line 1626 in src/c2.c

View check run for this annotation

Codecov / codecov/patch

src/c2.c#L1624-L1626

Added lines #L1624 - L1626 were not covered by tests
// index < 0 means match any index
// Get length of property in 32-bit multiples
auto prop_info = x_get_prop_info(&ps->c, wid, leaf->tgtatom);
auto prop_info = x_get_prop_info(c, wid, leaf->tgtatom);
word_count = to_int_checked((prop_info.length + 4 - 1) / 4);
offset = 0;

Check warning on line 1631 in src/c2.c

View check run for this annotation

Codecov / codecov/patch

src/c2.c#L1629-L1631

Added lines #L1629 - L1631 were not covered by tests
}
winprop_t prop =
x_get_prop_with_offset(&ps->c, wid, leaf->tgtatom, offset, word_count,
x_get_prop_with_offset(c, wid, leaf->tgtatom, offset, word_count,
c2_get_atom_type(leaf), leaf->format);

Check warning on line 1635 in src/c2.c

View check run for this annotation

Codecov / codecov/patch

src/c2.c#L1634-L1635

Added lines #L1634 - L1635 were not covered by tests

ntargets = (leaf->index < 0 ? prop.nitems : min2(prop.nitems, 1));
Expand All @@ -1642,7 +1642,7 @@ c2_match_once_leaf_string(session_t *ps, const struct managed_win *w, const c2_l
xcb_atom_t atom = (xcb_atom_t)winprop_get_int(prop, i);
if (atom) {
xcb_get_atom_name_reply_t *reply = xcb_get_atom_name_reply(

Check warning on line 1644 in src/c2.c

View check run for this annotation

Codecov / codecov/patch

src/c2.c#L1641-L1644

Added lines #L1641 - L1644 were not covered by tests
ps->c.c, xcb_get_atom_name(ps->c.c, atom), NULL);
c->c, xcb_get_atom_name(c->c, atom), NULL);
if (reply) {
targets[i] = targets_free_inner[i] = strndup(
xcb_get_atom_name_name(reply),
Expand All @@ -1657,7 +1657,7 @@ c2_match_once_leaf_string(session_t *ps, const struct managed_win *w, const c2_l
char **strlst = NULL;
int nstr = 0;
int index = max2(0, leaf->index);
if (wid_get_text_prop(&ps->c, ps->atoms, wid, leaf->tgtatom, &strlst, &nstr)) {
if (wid_get_text_prop(c, atoms, wid, leaf->tgtatom, &strlst, &nstr)) {
if (leaf->index < 0 && nstr > 0 && strlen(strlst[0]) > 0) {
ntargets = to_u32_checked(nstr);
targets = (const char **)strlst;
Expand Down Expand Up @@ -1727,7 +1727,7 @@ c2_match_once_leaf(session_t *ps, const struct managed_win *w, const c2_l_t *lea
// Deal with integer patterns
case C2_L_PTINT: return c2_match_once_leaf_int(ps, w, leaf);
// String patterns
case C2_L_PTSTRING: return c2_match_once_leaf_string(ps, w, leaf);
case C2_L_PTSTRING: return c2_match_once_leaf_string(&ps->c, ps->atoms, w, leaf);
default:
log_error("Unknown pattern type %d.", leaf->ptntype);
assert(false);

Check warning on line 1733 in src/c2.c

View check run for this annotation

Codecov / codecov/patch

src/c2.c#L1731-L1733

Added lines #L1731 - L1733 were not covered by tests
Expand Down

0 comments on commit 0fb51ff

Please sign in to comment.