Add debug log message to print each bar's widget tree

This is very useful when writing CSS that affects more than just a
single widget. Pass `-l debug` to enable debug logging and show this
information.

Example output:

    [2020-11-30 12:38:51.141] [debug] GTK widget tree:
    window#waybar.background.bottom.eDP-1.:dir(ltr)
      decoration:dir(ltr)
      box.horizontal:dir(ltr)
        box.horizontal.modules-left:dir(ltr)
          widget:dir(ltr)
            box#workspaces.horizontal:dir(ltr)
          widget:dir(ltr)
            label#mode:dir(ltr)
          widget:dir(ltr)
            label#window:dir(ltr)
        box.horizontal.modules-center:dir(ltr)
        box.horizontal.modules-right:dir(ltr)
          widget:dir(ltr)
            box#tray.horizontal:dir(ltr)
          widget:dir(ltr)
            label#idle_inhibitor:dir(ltr)
          widget:dir(ltr)
            label#pulseaudio:dir(ltr)
          widget:dir(ltr)
            label#network:dir(ltr)
          widget:dir(ltr)
            label#cpu:dir(ltr)
          widget:dir(ltr)
            label#memory:dir(ltr)
          widget:dir(ltr)
            label#temperature:dir(ltr)
          widget:dir(ltr)
            label#backlight:dir(ltr)
          widget:dir(ltr)
            label#battery:dir(ltr)
          widget:dir(ltr)
            label#clock:dir(ltr)
This commit is contained in:
Thomas Hebb 2020-11-30 12:05:18 -08:00
parent ad40511358
commit 85df7ce2da

View File

@ -460,6 +460,16 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
setupWidgets();
window.show_all();
if (spdlog::should_log(spdlog::level::debug)) {
// Unfortunately, this function isn't in the C++ bindings, so we have to call the C version.
char* gtk_tree = gtk_style_context_to_string(
window.get_style_context()->gobj(),
(GtkStyleContextPrintFlags)(GTK_STYLE_CONTEXT_PRINT_RECURSE |
GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE));
spdlog::debug("GTK widget tree:\n{}", gtk_tree);
g_free(gtk_tree);
}
}
void waybar::Bar::onMap(GdkEventAny*) {