Skip to content

Commit 17dd566

Browse files
mrsteve0924trigg
authored andcommitted
refresh icons at the same period interval as command_output
Reload icons specified by a filesystem path after command execution completes. This allows dynamic icons such as album art to update on the widget refresh interval while preserving the original behavior for static theme icons.
1 parent e42ebc6 commit 17dd566

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/panel/widgets/command-output.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
#include "command-output.hpp"
1515

1616
static sigc::connection label_set_from_command(std::string command_line,
17-
Gtk::Label& label)
17+
Gtk::Label& label, Gtk::Image* icon = nullptr,
18+
const std::string& icon_name = "")
1819
{
1920
command_line = "/bin/sh -c \"" + command_line + "\"";
2021

@@ -23,6 +24,7 @@ static sigc::connection label_set_from_command(std::string command_line,
2324
Glib::spawn_async_with_pipes("", Glib::shell_parse_argv(command_line),
2425
Glib::SpawnFlags::DO_NOT_REAP_CHILD | Glib::SpawnFlags::SEARCH_PATH_FROM_ENVP,
2526
Glib::SlotSpawnChildSetup{}, &pid, nullptr, &output_fd, nullptr);
27+
2628
return Glib::signal_child_watch().connect([=, &label] (Glib::Pid pid, int exit_status)
2729
{
2830
FILE *file = fdopen(output_fd, "r");
@@ -43,6 +45,14 @@ static sigc::connection label_set_from_command(std::string command_line,
4345
}
4446

4547
label.set_markup(output);
48+
49+
if (icon &&
50+
!icon_name.empty() &&
51+
(icon_name[0] == '/' ||
52+
icon_name.rfind("~/", 0) == 0))
53+
{
54+
IconProvider::image_set_icon(*icon, icon_name);
55+
}
4656
}, pid);
4757
}
4858

@@ -102,7 +112,7 @@ WfCommandOutputButtons::CommandOutput::CommandOutput(const std::string & name,
102112
const auto update_output = [=] ()
103113
{
104114
command_sig.disconnect();
105-
command_sig = label_set_from_command(command, main_label);
115+
command_sig = label_set_from_command(command, main_label, &icon, icon_name);
106116
};
107117

108118
signals.push_back(signal_clicked().connect(update_output));

0 commit comments

Comments
 (0)