mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #1211 from mswiger/fix_multi_display_tray_icon_scaling
Fix tray icon scaling on multi-display setups
This commit is contained in:
commit
8940c3bbe8
@ -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();
|
||||
|
||||
@ -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_;
|
||||
};
|
||||
|
@ -14,6 +14,8 @@
|
||||
#include <set>
|
||||
#include <string_view>
|
||||
|
||||
#include "bar.hpp"
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
struct ToolTip {
|
||||
@ -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;
|
||||
@ -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);
|
||||
|
@ -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()) + "-" +
|
||||
@ -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) {}
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
@ -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));
|
||||
@ -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);
|
||||
|
@ -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 "
|
||||
|
Loading…
Reference in New Issue
Block a user