diff --git a/man/picom-inspect.1.adoc b/man/picom-inspect.1.adoc index f27fa840..7b33a889 100644 --- a/man/picom-inspect.1.adoc +++ b/man/picom-inspect.1.adoc @@ -19,12 +19,16 @@ DESCRIPTION OPTIONS ------- -*picom-inspect* accept the exact same set of options as *picom*. Naturally, most of those options will not be relevant. +*picom-inspect* accepts all options that *picom* does. Naturally, most of those options will not be relevant. These are some of the options you might find useful (See *picom*(1) for descriptions of what they do): *--config*, *--log-level*, *--log-file*, all the options related to rules. +*picom-inspect* also accepts some extra options: ::: + + *--monitor*:: Keep *picom-inspect* running in a loop, and dump information every time something changed about a window. + NOTES ----- *picom-inspect* is prototype right now. If you find any bug, for example, if rules are matched differently compared to *picom*, please submit bug reports to: diff --git a/src/config.h b/src/config.h index 89568e76..e75fe518 100644 --- a/src/config.h +++ b/src/config.h @@ -241,6 +241,8 @@ typedef struct options { bool print_diagnostics; /// Render to a separate window instead of taking over the screen bool debug_mode; + /// For picom-inspect only, dump windows in a loop + bool inspect_monitor; xcb_window_t inspect_win; // === General === /// Use the legacy backends? diff --git a/src/options.c b/src/options.c index b03e4e8e..e80af70c 100644 --- a/src/options.c +++ b/src/options.c @@ -59,6 +59,7 @@ struct picom_option { int has_arg; struct picom_arg arg; const char *help; + const char *argv0; }; static bool set_flag(const struct picom_option * /*opt*/, const struct picom_arg *arg, @@ -452,6 +453,8 @@ static const struct picom_option picom_options[] = { "window is fullscreen based only on its size and coordinates."}, [804] = {"realtime" , ENABLE(use_realtime_scheduling) , "Enable realtime scheduling. This might reduce latency, but might also cause " "other issues. Disable this if you see the compositor being killed."}, + [805] = {"monitor" , ENABLE(inspect_monitor) , "For picom-inspect, run in a loop and dump information every time something " + "changed about a window.", "picom-inspect"}, // Flags that takes an argument ['r'] = {"shadow-radius" , INTEGER(shadow_radius, 0, INT_MAX) , "The blur radius for shadows. (default 12)"}, @@ -634,12 +637,19 @@ static void usage(const char *argv0, int ret) { line_wrap = window_size.ws_col; } + const char *basename = strrchr(argv0, '/') ? strrchr(argv0, '/') + 1 : argv0; + size_t help_indent = 0; for (size_t i = 0; i < ARR_SIZE(picom_options); i++) { if (picom_options[i].help == NULL) { // Hide options with no help message. continue; } + if (picom_options[i].argv0 != NULL && + strcmp(picom_options[i].argv0, basename) != 0) { + // Hide options that are not for this program. + continue; + } auto option_len = strlen(picom_options[i].long_name) + 2 + 4; if (picom_options[i].arg.name) { option_len += strlen(picom_options[i].arg.name) + 1; @@ -654,6 +664,11 @@ static void usage(const char *argv0, int ret) { if (picom_options[i].help == NULL) { continue; } + if (picom_options[i].argv0 != NULL && + strcmp(picom_options[i].argv0, basename) != 0) { + // Hide options that are not for this program. + continue; + } size_t option_len = 8; fprintf(f, " "); if ((i > 'a' && i < 'z') || (i > 'A' && i < 'Z')) { @@ -943,10 +958,15 @@ bool get_cfg(options_t *opt, int argc, char *const *argv) { int o = 0, longopt_idx = -1; bool failed = false; optind = 1; + const char *basename = strrchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0]; while (-1 != (o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) { if (o == '?' || o == ':' || picom_options[o].arg.handler == NULL) { usage(argv[0], 1); failed = true; + } else if (picom_options[o].argv0 != NULL && + strcmp(picom_options[o].argv0, basename) != 0) { + log_error("Invalid option %s", argv[optind - 1]); + failed = true; } else if (!picom_options[o].arg.handler( &picom_options[o], &picom_options[o].arg, optarg, opt)) { failed = true; diff --git a/src/picom.c b/src/picom.c index 491a0d22..dcb5c5a9 100644 --- a/src/picom.c +++ b/src/picom.c @@ -2199,7 +2199,9 @@ static session_t *session_init(int argc, char **argv, Display *dpy, ps->o.backend = backend_find("dummy"); ps->o.print_diagnostics = false; ps->o.dbus = false; - ps->o.inspect_win = inspect_select_window(&ps->c); + if (!ps->o.inspect_monitor) { + ps->o.inspect_win = inspect_select_window(&ps->c); + } } ps->window_options_default = win_options_from_config(&ps->o); diff --git a/src/wm/win.c b/src/wm/win.c index 084f3f88..a0eddd57 100644 --- a/src/wm/win.c +++ b/src/wm/win.c @@ -1119,9 +1119,15 @@ void win_on_factor_change(session_t *ps, struct win *w) { 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)); + } inspect_dump_window(ps->c2_state, &ps->o, w); printf("\n"); - quit(ps); + if (!ps->o.inspect_monitor) { + quit(ps); + } } }