Skip to content

Commit

Permalink
inspect: support inspection of the new window rules
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Aug 9, 2024
1 parent c1227b7 commit ccefc60
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 43 deletions.
4 changes: 4 additions & 0 deletions src/c2.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ c2_condition *c2_new_true(struct list_node *list);
for (c2_condition *i = \
list_is_empty((list)) ? NULL : c2_condition_list_entry((list)->next); \
i; i = c2_condition_list_next(list, i))
#define c2_condition_list_foreach_rev(list, i) \
for (c2_condition *i = \
list_is_empty((list)) ? NULL : c2_condition_list_entry((list)->prev); \
i; i = c2_condition_list_prev(list, i))

#define c2_condition_list_foreach_safe(list, i, n) \
for (c2_condition *i = \
Expand Down
135 changes: 111 additions & 24 deletions src/inspect.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "common.h"
#include "config.h"
#include "log.h"
#include "utils/console.h"
#include "utils/dynarr.h"
#include "utils/str.h"
#include "wm/defs.h"
#include "wm/win.h"
#include "x.h"
Expand Down Expand Up @@ -97,33 +100,33 @@ static bool c2_match_and_log(const struct list_node *list, const struct c2_state
return false;
}

#define BOLD(str) "\033[1m" str "\033[0m"

void inspect_dump_window(const struct c2_state *state, const struct options *opts,
const struct win *w) {
printf("Checking " BOLD("transparent-clipping-exclude") ":\n");
c2_match_and_log(&opts->transparent_clipping_blacklist, state, w, false);
printf("Checking " BOLD("shadow-exclude") ":\n");
c2_match_and_log(&opts->shadow_blacklist, state, w, false);
printf("Checking " BOLD("fade-exclude") ":\n");
c2_match_and_log(&opts->fade_blacklist, state, w, false);
printf("Checking " BOLD("clip-shadow-above") ":\n");
c2_match_and_log(&opts->shadow_clip_list, state, w, true);
printf("Checking " BOLD("focus-exclude") ":\n");
c2_match_and_log(&opts->focus_blacklist, state, w, false);
printf("Checking " BOLD("invert-color-include") ":\n");
c2_match_and_log(&opts->invert_color_list, state, w, false);
printf("Checking " BOLD("blur-background-exclude") ":\n");
c2_match_and_log(&opts->blur_background_blacklist, state, w, false);
printf("Checking " BOLD("unredir-if-possible-exclude") ":\n");
c2_match_and_log(&opts->unredir_if_possible_blacklist, state, w, false);
printf("Checking " BOLD("rounded-corners-exclude") ":\n");
c2_match_and_log(&opts->rounded_corners_blacklist, state, w, false);
if (list_is_empty(&opts->rules)) {
printf("Checking " BOLD("transparent-clipping-exclude") ":\n");
c2_match_and_log(&opts->transparent_clipping_blacklist, state, w, false);
printf("Checking " BOLD("shadow-exclude") ":\n");
c2_match_and_log(&opts->shadow_blacklist, state, w, false);
printf("Checking " BOLD("fade-exclude") ":\n");
c2_match_and_log(&opts->fade_blacklist, state, w, false);
printf("Checking " BOLD("clip-shadow-above") ":\n");
c2_match_and_log(&opts->shadow_clip_list, state, w, true);
printf("Checking " BOLD("focus-exclude") ":\n");
c2_match_and_log(&opts->focus_blacklist, state, w, false);
printf("Checking " BOLD("invert-color-include") ":\n");
c2_match_and_log(&opts->invert_color_list, state, w, false);
printf("Checking " BOLD("blur-background-exclude") ":\n");
c2_match_and_log(&opts->blur_background_blacklist, state, w, false);
printf("Checking " BOLD("unredir-if-possible-exclude") ":\n");
c2_match_and_log(&opts->unredir_if_possible_blacklist, state, w, false);
printf("Checking " BOLD("rounded-corners-exclude") ":\n");
c2_match_and_log(&opts->rounded_corners_blacklist, state, w, false);

printf("Checking " BOLD("opacity-rule") ":\n");
c2_match_and_log(&opts->opacity_rules, state, w, true);
printf("Checking " BOLD("corner-radius-rule") ":\n");
c2_match_and_log(&opts->corner_radius_rules, state, w, true);
printf("Checking " BOLD("opacity-rule") ":\n");
c2_match_and_log(&opts->opacity_rules, state, w, true);
printf("Checking " BOLD("corner-radius-rule") ":\n");
c2_match_and_log(&opts->corner_radius_rules, state, w, true);
}

printf("\nHere are some rule(s) that match this window:\n");
if (w->name != NULL) {
Expand Down Expand Up @@ -151,3 +154,87 @@ void inspect_dump_window(const struct c2_state *state, const struct options *opt
}
printf(" border_width = %d\n", w->g.border_width);
}

void inspect_dump_window_maybe_options(struct window_maybe_options wopts) {
bool nothing = true;
printf(" Applying:\n");
if (wopts.shadow != TRI_UNKNOWN) {
printf(" shadow = %s\n", wopts.shadow == TRI_TRUE ? "true" : "false");
nothing = false;
}
if (wopts.fade != TRI_UNKNOWN) {
printf(" fade = %s\n", wopts.fade == TRI_TRUE ? "true" : "false");
nothing = false;
}
if (wopts.blur_background != TRI_UNKNOWN) {
printf(" blur_background = %s\n",
wopts.blur_background == TRI_TRUE ? "true" : "false");
nothing = false;
}
if (wopts.invert_color != TRI_UNKNOWN) {
printf(" invert_color = %s\n",
wopts.invert_color == TRI_TRUE ? "true" : "false");
nothing = false;
}
if (wopts.clip_shadow_above != TRI_UNKNOWN) {
printf(" clip_shadow_above = %s\n",
wopts.clip_shadow_above == TRI_TRUE ? "true" : "false");
nothing = false;
}
if (wopts.transparent_clipping != TRI_UNKNOWN) {
printf(" transparent_clipping = %s\n",
wopts.transparent_clipping == TRI_TRUE ? "true" : "false");
nothing = false;
}
if (wopts.full_shadow != TRI_UNKNOWN) {
printf(" full_shadow = %s\n",
wopts.full_shadow == TRI_TRUE ? "true" : "false");
nothing = false;
}
if (wopts.unredir != WINDOW_UNREDIR_INVALID) {
const char *str = NULL;
switch (wopts.unredir) {
case WINDOW_UNREDIR_WHEN_POSSIBLE_ELSE_TERMINATE: str = "true"; break;
case WINDOW_UNREDIR_TERMINATE: str = "false"; break;
case WINDOW_UNREDIR_FORCED: str = "\"forced\""; break;
case WINDOW_UNREDIR_PASSIVE: str = "\"passive\""; break;
case WINDOW_UNREDIR_WHEN_POSSIBLE: str = "\"preferred\""; break;
default: unreachable();
}
printf(" unredir = %s\n", str);
nothing = false;
}
if (!safe_isnan(wopts.opacity)) {
printf(" opacity = %f\n", wopts.opacity);
nothing = false;
}
if (!safe_isnan(wopts.dim)) {
printf(" dim = %f\n", wopts.dim);
nothing = false;
}
if (wopts.corner_radius >= 0) {
printf(" corner_radius = %d\n", wopts.corner_radius);
nothing = false;
}

char **animation_triggers = dynarr_new(char *, 0);
for (int i = 0; i <= ANIMATION_TRIGGER_LAST; i++) {
if (wopts.animations[i].script != NULL) {
char *name = NULL;
casprintf(&name, "\"%s\"", animation_trigger_names[i]);
dynarr_push(animation_triggers, name);
}
}
if (dynarr_len(animation_triggers) > 0) {
char *animation_triggers_str = dynarr_join(animation_triggers, ", ");
printf(" animations = { triggers = [%s]; }\n", animation_triggers_str);
free(animation_triggers_str);
nothing = false;
} else {
dynarr_free_pod(animation_triggers);
}

if (nothing) {
printf(" (nothing)\n");
}
}
5 changes: 4 additions & 1 deletion src/inspect.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

#pragma once
#include <xcb/xcb.h>
#include "wm/win.h"

struct x_connection;
struct c2_state;
struct options;
struct win;

int inspect_main(int argc, char **argv, const char *config_file);
xcb_window_t inspect_select_window(struct x_connection *c);
void inspect_dump_window(const struct c2_state *state, const struct options *opts,
const struct win *w);
void inspect_dump_window_maybe_options(struct window_maybe_options wopts);
2 changes: 1 addition & 1 deletion src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "compiler.h"
#include "log.h"
#include "utils/console.h"
#include "utils/misc.h"

thread_local struct log *tls_logger;
Expand Down Expand Up @@ -274,7 +275,6 @@ static void file_logger_destroy(struct log_target *tgt) {
free(tgt);
}

#define ANSI(x) "\033[" x "m"
static const char *terminal_colorize_begin(enum log_level level) {
switch (level) {
case LOG_LEVEL_TRACE: return ANSI("30;2");
Expand Down
45 changes: 28 additions & 17 deletions src/wm/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "picom.h"
#include "region.h"
#include "render.h"
#include "utils/console.h"
#include "utils/misc.h"
#include "x.h"

Expand Down Expand Up @@ -1004,20 +1005,25 @@ void win_update_opacity_rule(session_t *ps, struct win *w) {
w->options.opacity = opacity;
}

struct win_update_rule_params {
struct win *w;
struct session *ps;
struct window_maybe_options options;
};

static bool win_update_rule(struct session *ps, struct win *w, const c2_condition *rule) {
static bool
win_update_rule(struct session *ps, struct win *w, const c2_condition *rule, bool inspect) {
void *pdata = NULL;
if (!c2_match_one(ps->c2_state, w, rule, &pdata)) {
if (inspect) {
printf(" %s ... ", c2_condition_to_str(rule));
}
bool matched = c2_match_one(ps->c2_state, w, rule, &pdata);
if (inspect) {
printf("%s\n", matched ? ANSI("1;32") "matched\033[0m" : "not matched");
}
if (!matched) {
return false;
}

auto wopts_next = (struct window_maybe_options *)pdata;
w->options = win_maybe_options_fold(w->options, *wopts_next);
if (inspect) {
inspect_dump_window_maybe_options(*wopts_next);
}
w->options = win_maybe_options_fold(*wopts_next, w->options);
return false;
}

Expand All @@ -1028,12 +1034,19 @@ static bool win_update_rule(struct session *ps, struct win *w, const c2_conditio
*/
void win_on_factor_change(session_t *ps, struct win *w) {
auto wid = win_client_id(w, /*fallback_to_self=*/true);
bool inspect = (ps->o.inspect_win != XCB_NONE && win_id(w) == ps->o.inspect_win) ||
ps->o.inspect_monitor;
log_debug("Window %#010x, client %#010x (%s) factor change", win_id(w), wid, w->name);
c2_window_state_update(ps->c2_state, &w->c2_state, ps->c.c, wid, win_id(w));
// Focus and is_fullscreen needs to be updated first, as other rules might depend
// on the focused state of the window
win_update_is_fullscreen(ps, w);

if (ps->o.inspect_monitor) {
printf("Window %#010x (Client %#010x):\n======\n\n", win_id(w),
win_client_id(w, /*fallback_to_self=*/true));
}

assert(w->window_types != 0);
if (list_is_empty(&ps->o.rules)) {
bool focused = win_is_focused(ps, w);
Expand Down Expand Up @@ -1089,8 +1102,11 @@ void win_on_factor_change(session_t *ps, struct win *w) {
} else {
w->options = WIN_MAYBE_OPTIONS_DEFAULT;
assert(w->state == WSTATE_MAPPED);
c2_condition_list_foreach(&ps->o.rules, i) {
win_update_rule(ps, w, i);
if (inspect) {
printf("Checking " BOLD("window rules") ":\n");
}
c2_condition_list_foreach_rev(&ps->o.rules, i) {
win_update_rule(ps, w, i, inspect);
}
if (safe_isnan(w->options.opacity) && w->has_opacity_prop) {
w->options.opacity = ((double)w->opacity_prop) / OPAQUE;
Expand All @@ -1114,12 +1130,7 @@ void win_on_factor_change(session_t *ps, struct win *w) {
w->options.paint = TRI_FALSE;
}

if ((ps->o.inspect_win != XCB_NONE && win_id(w) == ps->o.inspect_win) ||
ps->o.inspect_monitor) {
if (ps->o.inspect_monitor) {
printf("Window %#010x (Client %#010x):\n\n", win_id(w),
win_client_id(w, /*fallback_to_self=*/true));
}
if (inspect) {
inspect_dump_window(ps->c2_state, &ps->o, w);
printf("\n");
if (!ps->o.inspect_monitor) {
Expand Down

0 comments on commit ccefc60

Please sign in to comment.