Skip to content

Commit

Permalink
merge notification center to master
Browse files Browse the repository at this point in the history
  • Loading branch information
NamorNiradnug committed Aug 3, 2022
2 parents e50c6e4 + 76e2b39 commit b15a9e2
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/panel/meson.build
Expand Up @@ -4,6 +4,7 @@ widget_sources = ['widgets/battery.cpp',
'widgets/launchers.cpp',
'widgets/network.cpp',
'widgets/spacing.cpp',
'widgets/fastrun.cpp',
'widgets/window-list/window-list.cpp',
'widgets/window-list/toplevel.cpp',
'widgets/notifications/daemon.cpp',
Expand Down
3 changes: 3 additions & 0 deletions src/panel/panel.cpp
Expand Up @@ -18,6 +18,7 @@
#include "widgets/battery.hpp"
#include "widgets/menu.hpp"
#include "widgets/clock.hpp"
#include "widgets/fastrun.hpp"
#include "widgets/launchers.hpp"
#include "widgets/network.hpp"
#include "widgets/spacing.hpp"
Expand Down Expand Up @@ -197,6 +198,8 @@ class WayfirePanel::impl
return Widget(new WayfireLaunchers());
if (name == "clock")
return Widget(new WayfireClock());
if (name == "fastrun")
return Widget(new WayfireFastRun());
if (name == "network")
return Widget(new WayfireNetworkInfo());
if (name == "battery")
Expand Down
105 changes: 105 additions & 0 deletions src/panel/widgets/fastrun.cpp
@@ -0,0 +1,105 @@
#include "fastrun.hpp"
#include <map>
#include <iostream>
#include <gtkmm/button.h>
#include <glibmm/spawn.h>

WfFastRunCmd::WfFastRunCmd(command_info cmd) : Gtk::Button()
{
icon.set_from_icon_name(cmd.icon, Gtk::ICON_SIZE_DND);
label.set_label(cmd.name);
box.add(icon);
box.add(label);
icon.show();
label.show();

add(box);
box.show();

// Unfortunately tooltips don't work well in GTK3 popovers
// https://gitlab.gnome.org/GNOME/gtk/issues/1708
// set_tooltip_text(cmd.cmd);
get_style_context()->add_class("flat");
signal_clicked().connect_notify([=] {
Glib::spawn_command_line_async(cmd.cmd);
});
}

void WayfireFastRun::init(Gtk::HBox *container)
{
button = std::make_unique<WayfireMenuButton>("panel");
icon.set_from_icon_name("system-run", Gtk::ICON_SIZE_LARGE_TOOLBAR);
icon.show();
button->add(icon);

auto popover = button->get_popover();
popover->add(button_box);

container->pack_start(*button, false, false);

button->show_all();

handle_config_reload();
}

static bool begins_with(const std::string &str, const std::string &prefix)
{
return str.substr(0, prefix.size()) == prefix;
}

void WayfireFastRun::handle_config_reload()
{
for (auto child : button_box.get_children())
{
button_box.remove(*child);
}

auto section = WayfireShellApp::get().config.get_section("panel");
const std::string command_prefix = "fastrun_cmd_";
const std::string icon_prefix = "fastrun_icon_";
const std::string name_prefix = "fastrun_name_";

std::map<std::string, command_info> commands_info;

for (auto opt : section->get_registered_options())
{
if (begins_with(opt->get_name(), command_prefix) && !opt->get_value_str().empty())
{
auto cmd_name = opt->get_name().substr(command_prefix.size());
commands_info.insert({ cmd_name, { opt->get_value_str(), "system-run", opt->get_value_str() }});
}
if (begins_with(opt->get_name(), icon_prefix))
{
auto cmd_name = opt->get_name().substr(icon_prefix.size());
if (commands_info.count(cmd_name))
{
commands_info[cmd_name].icon = opt->get_value_str();
}
else
{
std::cout << "There is no fastrun command " << cmd_name << ", the command itself should be declared before its icon.\n";
}
}
if (begins_with(opt->get_name(), name_prefix))
{
auto cmd_name = opt->get_name().substr(name_prefix.size());
if (commands_info.count(cmd_name))
{
commands_info[cmd_name].name = opt->get_value_str();
}
else
{
std::cout << "There is no fastrun command " << cmd_name << ", the command itself should be declared before its 'pretty name'.\n";
}
}
}

for (const auto &[_, cmd] : commands_info)
{
auto command = new WfFastRunCmd(cmd);
button_box.add(*command);
}

button_box.show_all();
}

39 changes: 39 additions & 0 deletions src/panel/widgets/fastrun.hpp
@@ -0,0 +1,39 @@
#ifndef WIDGETS_FASTRUN_HPP
#define WIDGETS_FASTRUN_HPP

#include "../widget.hpp"

#include <gtkmm/buttonbox.h>
#include <vector>
#include <gtkmm/image.h>
#include "wf-popover.hpp"

struct command_info
{
std::string cmd, icon, name;
};

class WfFastRunCmd : public Gtk::Button
{
Gtk::HBox box;
Gtk::Image icon;
Gtk::Label label;

public:
WfFastRunCmd(command_info cmd);
};

/* Widget which allows to run commands in two clicks.
*/
class WayfireFastRun : public WayfireWidget
{
Gtk::Image icon;
std::unique_ptr<WayfireMenuButton> button;
Gtk::VButtonBox button_box;

public:
void init(Gtk::HBox *container) override;
void handle_config_reload() override;
};

#endif /* end of include guard: WIDGETS_CLOCK_HPP */

0 comments on commit b15a9e2

Please sign in to comment.