Merge pull request #2417 from Cherser-s/sni-click-coordinate-fix
sni: fix passing relative coordinates to dbus methods
This commit is contained in:
commit
2d27e484c7
|
@ -91,6 +91,9 @@ class Bar {
|
||||||
bool vertical = false;
|
bool vertical = false;
|
||||||
Gtk::Window window;
|
Gtk::Window window;
|
||||||
|
|
||||||
|
int x_global;
|
||||||
|
int y_global;
|
||||||
|
|
||||||
#ifdef HAVE_SWAY
|
#ifdef HAVE_SWAY
|
||||||
std::string bar_id;
|
std::string bar_id;
|
||||||
#endif
|
#endif
|
||||||
|
@ -102,11 +105,16 @@ class Bar {
|
||||||
void setupAltFormatKeyForModule(const std::string &module_name);
|
void setupAltFormatKeyForModule(const std::string &module_name);
|
||||||
void setupAltFormatKeyForModuleList(const char *module_list_name);
|
void setupAltFormatKeyForModuleList(const char *module_list_name);
|
||||||
void setMode(const bar_mode &);
|
void setMode(const bar_mode &);
|
||||||
|
void onConfigure(GdkEventConfigure *ev);
|
||||||
|
void configureGlobalOffset(int width, int height);
|
||||||
|
void onOutputGeometryChanged();
|
||||||
|
|
||||||
/* Copy initial set of modes to allow customization */
|
/* Copy initial set of modes to allow customization */
|
||||||
bar_mode_map configured_modes = PRESET_MODES;
|
bar_mode_map configured_modes = PRESET_MODES;
|
||||||
std::string last_mode_{MODE_DEFAULT};
|
std::string last_mode_{MODE_DEFAULT};
|
||||||
|
|
||||||
|
struct bar_margins margins_;
|
||||||
|
|
||||||
std::unique_ptr<BarSurface> surface_impl_;
|
std::unique_ptr<BarSurface> surface_impl_;
|
||||||
Gtk::Box left_;
|
Gtk::Box left_;
|
||||||
Gtk::Box center_;
|
Gtk::Box center_;
|
||||||
|
|
|
@ -84,6 +84,8 @@ class Item : public sigc::trackable {
|
||||||
// visibility of items with Status == Passive
|
// visibility of items with Status == Passive
|
||||||
bool show_passive_ = false;
|
bool show_passive_ = false;
|
||||||
|
|
||||||
|
const Bar& bar_;
|
||||||
|
|
||||||
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
|
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
|
||||||
Glib::RefPtr<Gio::Cancellable> cancellable_;
|
Glib::RefPtr<Gio::Cancellable> cancellable_;
|
||||||
std::set<std::string_view> update_pending_;
|
std::set<std::string_view> update_pending_;
|
||||||
|
|
54
src/bar.cpp
54
src/bar.cpp
|
@ -481,6 +481,9 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
||||||
: output(w_output),
|
: output(w_output),
|
||||||
config(w_config),
|
config(w_config),
|
||||||
window{Gtk::WindowType::WINDOW_TOPLEVEL},
|
window{Gtk::WindowType::WINDOW_TOPLEVEL},
|
||||||
|
x_global(0),
|
||||||
|
y_global(0),
|
||||||
|
margins_{.top = 0, .right = 0, .bottom = 0, .left = 0},
|
||||||
left_(Gtk::ORIENTATION_HORIZONTAL, 0),
|
left_(Gtk::ORIENTATION_HORIZONTAL, 0),
|
||||||
center_(Gtk::ORIENTATION_HORIZONTAL, 0),
|
center_(Gtk::ORIENTATION_HORIZONTAL, 0),
|
||||||
right_(Gtk::ORIENTATION_HORIZONTAL, 0),
|
right_(Gtk::ORIENTATION_HORIZONTAL, 0),
|
||||||
|
@ -516,8 +519,6 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
||||||
uint32_t height = config["height"].isUInt() ? config["height"].asUInt() : 0;
|
uint32_t height = config["height"].isUInt() ? config["height"].asUInt() : 0;
|
||||||
uint32_t width = config["width"].isUInt() ? config["width"].asUInt() : 0;
|
uint32_t width = config["width"].isUInt() ? config["width"].asUInt() : 0;
|
||||||
|
|
||||||
struct bar_margins margins_;
|
|
||||||
|
|
||||||
if (config["margin-top"].isInt() || config["margin-right"].isInt() ||
|
if (config["margin-top"].isInt() || config["margin-right"].isInt() ||
|
||||||
config["margin-bottom"].isInt() || config["margin-left"].isInt()) {
|
config["margin-bottom"].isInt() || config["margin-left"].isInt()) {
|
||||||
margins_ = {
|
margins_ = {
|
||||||
|
@ -563,6 +564,10 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
||||||
margins_ = {.top = gaps, .right = gaps, .bottom = gaps, .left = gaps};
|
margins_ = {.top = gaps, .right = gaps, .bottom = gaps, .left = gaps};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.signal_configure_event().connect_notify(sigc::mem_fun(*this, &Bar::onConfigure));
|
||||||
|
output->monitor->property_geometry().signal_changed().connect(
|
||||||
|
sigc::mem_fun(*this, &Bar::onOutputGeometryChanged));
|
||||||
|
|
||||||
#ifdef HAVE_GTK_LAYER_SHELL
|
#ifdef HAVE_GTK_LAYER_SHELL
|
||||||
bool use_gls = config["gtk-layer-shell"].isBool() ? config["gtk-layer-shell"].asBool() : true;
|
bool use_gls = config["gtk-layer-shell"].isBool() ? config["gtk-layer-shell"].asBool() : true;
|
||||||
if (use_gls) {
|
if (use_gls) {
|
||||||
|
@ -674,6 +679,7 @@ void waybar::Bar::onMap(GdkEventAny*) {
|
||||||
*/
|
*/
|
||||||
auto gdk_window = window.get_window()->gobj();
|
auto gdk_window = window.get_window()->gobj();
|
||||||
surface = gdk_wayland_window_get_wl_surface(gdk_window);
|
surface = gdk_wayland_window_get_wl_surface(gdk_window);
|
||||||
|
configureGlobalOffset(gdk_window_get_width(gdk_window), gdk_window_get_height(gdk_window));
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::Bar::setVisible(bool value) {
|
void waybar::Bar::setVisible(bool value) {
|
||||||
|
@ -815,3 +821,47 @@ auto waybar::Bar::setupWidgets() -> void {
|
||||||
right_.pack_end(*module, false, false);
|
right_.pack_end(*module, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void waybar::Bar::onConfigure(GdkEventConfigure* ev) {
|
||||||
|
configureGlobalOffset(ev->width, ev->height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void waybar::Bar::configureGlobalOffset(int width, int height) {
|
||||||
|
auto monitor_geometry = *output->monitor->property_geometry().get_value().gobj();
|
||||||
|
auto position = config["position"].asString();
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
if (position == "bottom") {
|
||||||
|
if (width + margins_.left + margins_.right >= monitor_geometry.width)
|
||||||
|
x = margins_.left;
|
||||||
|
else
|
||||||
|
x = (monitor_geometry.width - width) / 2;
|
||||||
|
y = monitor_geometry.height - height - margins_.bottom;
|
||||||
|
} else if (position == "left") {
|
||||||
|
x = margins_.left;
|
||||||
|
if (height + margins_.top + margins_.bottom >= monitor_geometry.height)
|
||||||
|
y = margins_.top;
|
||||||
|
else
|
||||||
|
y = (monitor_geometry.height - height) / 2;
|
||||||
|
} else if (position == "right") {
|
||||||
|
x = monitor_geometry.width - width - margins_.right;
|
||||||
|
if (height + margins_.top + margins_.bottom >= monitor_geometry.height)
|
||||||
|
y = margins_.top;
|
||||||
|
else
|
||||||
|
y = (monitor_geometry.height - height) / 2;
|
||||||
|
} else {
|
||||||
|
// position is top
|
||||||
|
if (width + margins_.left + margins_.right >= monitor_geometry.width)
|
||||||
|
x = margins_.left;
|
||||||
|
else
|
||||||
|
x = (monitor_geometry.width - width) / 2;
|
||||||
|
y = margins_.top;
|
||||||
|
}
|
||||||
|
|
||||||
|
x_global = x + monitor_geometry.x;
|
||||||
|
y_global = y + monitor_geometry.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void waybar::Bar::onOutputGeometryChanged() {
|
||||||
|
configureGlobalOffset(window.get_width(), window.get_height());
|
||||||
|
}
|
||||||
|
|
|
@ -39,7 +39,8 @@ Item::Item(const std::string& bn, const std::string& op, const Json::Value& conf
|
||||||
object_path(op),
|
object_path(op),
|
||||||
icon_size(16),
|
icon_size(16),
|
||||||
effective_icon_size(0),
|
effective_icon_size(0),
|
||||||
icon_theme(Gtk::IconTheme::create()) {
|
icon_theme(Gtk::IconTheme::create()),
|
||||||
|
bar_(bar) {
|
||||||
if (config["icon-size"].isUInt()) {
|
if (config["icon-size"].isUInt()) {
|
||||||
icon_size = config["icon-size"].asUInt();
|
icon_size = config["icon-size"].asUInt();
|
||||||
}
|
}
|
||||||
|
@ -410,7 +411,8 @@ void Item::makeMenu() {
|
||||||
|
|
||||||
bool Item::handleClick(GdkEventButton* const& ev) {
|
bool Item::handleClick(GdkEventButton* const& ev) {
|
||||||
auto parameters = Glib::VariantContainerBase::create_tuple(
|
auto parameters = Glib::VariantContainerBase::create_tuple(
|
||||||
{Glib::Variant<int>::create(ev->x), Glib::Variant<int>::create(ev->y)});
|
{Glib::Variant<int>::create(ev->x_root + bar_.x_global),
|
||||||
|
Glib::Variant<int>::create(ev->y_root + bar_.y_global)});
|
||||||
if ((ev->button == 1 && item_is_menu) || ev->button == 3) {
|
if ((ev->button == 1 && item_is_menu) || ev->button == 3) {
|
||||||
makeMenu();
|
makeMenu();
|
||||||
if (gtk_menu != nullptr) {
|
if (gtk_menu != nullptr) {
|
||||||
|
|
Loading…
Reference in New Issue