Skip to content

Commit

Permalink
Merge pull request Alexays#1211 from mswiger/fix_multi_display_tray_i…
Browse files Browse the repository at this point in the history
…con_scaling

Fix tray icon scaling on multi-display setups
  • Loading branch information
Alexays committed Aug 20, 2021
2 parents 51f2c6b + 2d80d31 commit 8940c3b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
5 changes: 4 additions & 1 deletion include/modules/sni/host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
#include <glibmm/refptr.h>
#include <json/json.h>
#include <tuple>
#include "bar.hpp"
#include "modules/sni/item.hpp"

namespace waybar::modules::SNI {

class Host {
public:
Host(const std::size_t id, const Json::Value&, const std::function<void(std::unique_ptr<Item>&)>&,
Host(const std::size_t id, const Json::Value&, const Bar&,
const std::function<void(std::unique_ptr<Item>&)>&,
const std::function<void(std::unique_ptr<Item>&)>&);
~Host();

Expand All @@ -36,6 +38,7 @@ class Host {
GCancellable* cancellable_ = nullptr;
SnWatcher* watcher_ = nullptr;
const Json::Value& config_;
const Bar& bar_;
const std::function<void(std::unique_ptr<Item>&)> on_add_;
const std::function<void(std::unique_ptr<Item>&)> on_remove_;
};
Expand Down
5 changes: 4 additions & 1 deletion include/modules/sni/item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <set>
#include <string_view>

#include "bar.hpp"

namespace waybar::modules::SNI {

struct ToolTip {
Expand All @@ -23,7 +25,7 @@ struct ToolTip {

class Item : public sigc::trackable {
public:
Item(const std::string&, const std::string&, const Json::Value&);
Item(const std::string&, const std::string&, const Json::Value&, const Bar&);
~Item() = default;

std::string bus_name;
Expand Down Expand Up @@ -56,6 +58,7 @@ class Item : public sigc::trackable {
bool item_is_menu = true;

private:
void onConfigure(GdkEventConfigure* ev);
void proxyReady(Glib::RefPtr<Gio::AsyncResult>& result);
void setProperty(const Glib::ustring& name, Glib::VariantBase& value);
void setStatus(const Glib::ustring& value);
Expand Down
5 changes: 3 additions & 2 deletions src/modules/sni/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace waybar::modules::SNI {

Host::Host(const std::size_t id, const Json::Value& config,
Host::Host(const std::size_t id, const Json::Value& config, const Bar& bar,
const std::function<void(std::unique_ptr<Item>&)>& on_add,
const std::function<void(std::unique_ptr<Item>&)>& on_remove)
: bus_name_("org.kde.StatusNotifierHost-" + std::to_string(getpid()) + "-" +
Expand All @@ -13,6 +13,7 @@ Host::Host(const std::size_t id, const Json::Value& config,
bus_name_id_(Gio::DBus::own_name(Gio::DBus::BusType::BUS_TYPE_SESSION, bus_name_,
sigc::mem_fun(*this, &Host::busAcquired))),
config_(config),
bar_(bar),
on_add_(on_add),
on_remove_(on_remove) {}

Expand Down Expand Up @@ -136,7 +137,7 @@ void Host::addRegisteredItem(std::string service) {
return bus_name == item->bus_name && object_path == item->object_path;
});
if (it == items_.end()) {
items_.emplace_back(new Item(bus_name, object_path, config_));
items_.emplace_back(new Item(bus_name, object_path, config_, bar_));
on_add_(items_.back());
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/modules/sni/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace waybar::modules::SNI {
static const Glib::ustring SNI_INTERFACE_NAME = sn_item_interface_info()->name;
static const unsigned UPDATE_DEBOUNCE_TIME = 10;

Item::Item(const std::string& bn, const std::string& op, const Json::Value& config)
Item::Item(const std::string& bn, const std::string& op, const Json::Value& config, const Bar& bar)
: bus_name(bn),
object_path(op),
icon_size(16),
Expand All @@ -54,6 +54,9 @@ Item::Item(const std::string& bn, const std::string& op, const Json::Value& conf
if (config["show-passive-items"].isBool()) {
show_passive_ = config["show-passive-items"].asBool();
}

auto &window = const_cast<Bar &>(bar).window;
window.signal_configure_event().connect_notify(sigc::mem_fun(*this, &Item::onConfigure));
event_box.add(image);
event_box.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
event_box.signal_button_press_event().connect(sigc::mem_fun(*this, &Item::handleClick));
Expand All @@ -73,6 +76,10 @@ Item::Item(const std::string& bn, const std::string& op, const Json::Value& conf
interface);
}

void Item::onConfigure(GdkEventConfigure* ev) {
this->updateImage();
}

void Item::proxyReady(Glib::RefPtr<Gio::AsyncResult>& result) {
try {
this->proxy_ = Gio::DBus::Proxy::create_for_bus_finish(result);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/sni/tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
: AModule(config, "tray", id),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
watcher_(SNI::Watcher::getInstance()),
host_(nb_hosts_, config, std::bind(&Tray::onAdd, this, std::placeholders::_1),
host_(nb_hosts_, config, bar, std::bind(&Tray::onAdd, this, std::placeholders::_1),
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
spdlog::warn(
"For a functional tray you must have libappindicator-* installed and export "
Expand Down

0 comments on commit 8940c3b

Please sign in to comment.