11#include " modules/sni/item.hpp"
22
3+ #include < atk/atk.h>
34#include < gdkmm/general.h>
45#include < glibmm/main.h>
6+ #include < gtkmm/cssprovider.h>
57#include < gtkmm/tooltip.h>
68#include < spdlog/spdlog.h>
79
@@ -38,6 +40,33 @@ namespace waybar::modules::SNI {
3840static const Glib::ustring SNI_INTERFACE_NAME = sn_item_interface_info()->name;
3941static const unsigned UPDATE_DEBOUNCE_TIME = 10 ;
4042
43+ namespace {
44+ Glib::RefPtr<Gtk::CssProvider> trayButtonCssProvider () {
45+ static auto provider = [] {
46+ auto css = Gtk::CssProvider::create ();
47+ css->load_from_data (R"CSS(
48+ .waybar-accessible-tray-button {
49+ padding: 0;
50+ margin: 0;
51+ min-width: 0;
52+ min-height: 0;
53+ border-width: 0;
54+ border-style: none;
55+ border-radius: 0;
56+ box-shadow: none;
57+ }
58+
59+ .waybar-accessible-tray-button > image {
60+ padding: 0;
61+ margin: 0;
62+ }
63+ )CSS" );
64+ return css;
65+ }();
66+ return provider;
67+ }
68+ } // namespace
69+
4170Item::Item (const std::string& bn, const std::string& op, const Json::Value& config, const Bar& bar,
4271 const std::function<void (Item&)>& on_ready,
4372 const std::function<void (Item&)>& on_invalidate, const std::function<void ()>& on_updated)
@@ -62,12 +91,22 @@ Item::Item(const std::string& bn, const std::string& op, const Json::Value& conf
6291
6392 auto & window = const_cast <Bar&>(bar).window ;
6493 window.signal_configure_event ().connect_notify (sigc::mem_fun (*this , &Item::onConfigure));
65- event_box.add (image);
66- event_box.add_events (Gdk::BUTTON_PRESS_MASK | Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
67- event_box.signal_button_press_event ().connect (sigc::mem_fun (*this , &Item::handleClick));
68- event_box.signal_scroll_event ().connect (sigc::mem_fun (*this , &Item::handleScroll));
69- event_box.signal_enter_notify_event ().connect (sigc::mem_fun (*this , &Item::handleMouseEnter));
70- event_box.signal_leave_notify_event ().connect (sigc::mem_fun (*this , &Item::handleMouseLeave));
94+ button.set_relief (Gtk::RELIEF_NONE);
95+ button.set_border_width (0 );
96+ button.set_focus_on_click (false );
97+ button.set_can_focus (false );
98+ button.get_style_context ()->add_class (" flat" );
99+ button.get_style_context ()->add_class (" waybar-accessible-tray-button" );
100+ button.get_style_context ()->add_provider (trayButtonCssProvider (),
101+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
102+ button.add (image);
103+ event_box.add (button);
104+ button.add_events (Gdk::BUTTON_PRESS_MASK | Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK |
105+ Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK);
106+ button.signal_button_press_event ().connect (sigc::mem_fun (*this , &Item::handleClick));
107+ button.signal_scroll_event ().connect (sigc::mem_fun (*this , &Item::handleScroll));
108+ button.signal_enter_notify_event ().connect (sigc::mem_fun (*this , &Item::handleMouseEnter));
109+ button.signal_leave_notify_event ().connect (sigc::mem_fun (*this , &Item::handleMouseLeave));
71110 // initial visibility
72111 event_box.show_all ();
73112 event_box.set_visible (show_passive_);
@@ -182,11 +221,10 @@ void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
182221 } else {
183222 setCustomIcon (id);
184223 }
224+ updateAccessibleName ();
185225 } else if (name == " Title" ) {
186226 title = get_variant<std::string>(value);
187- if (tooltip.text .empty ()) {
188- event_box.set_tooltip_markup (title);
189- }
227+ updateAccessibleName ();
190228 } else if (name == " Status" ) {
191229 setStatus (get_variant<Glib::ustring>(value));
192230 } else if (name == " IconName" ) {
@@ -205,9 +243,7 @@ void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
205243 attention_movie_name = get_variant<std::string>(value);
206244 } else if (name == " ToolTip" ) {
207245 tooltip = get_variant<ToolTip>(value);
208- if (!tooltip.text .empty ()) {
209- event_box.set_tooltip_markup (tooltip.text );
210- }
246+ updateAccessibleName ();
211247 } else if (name == " IconThemePath" ) {
212248 icon_theme_path = get_variant<std::string>(value);
213249 if (!icon_theme_path.empty ()) {
@@ -260,6 +296,29 @@ void Item::invalidate() {
260296 on_invalidate_ (*this );
261297}
262298
299+ void Item::updateAccessibleName () {
300+ if (!tooltip.text .empty ()) {
301+ button.set_tooltip_markup (tooltip.text );
302+ } else if (!title.empty ()) {
303+ button.set_tooltip_markup (title);
304+ }
305+
306+ std::string accessible_name;
307+ if (!title.empty ()) {
308+ accessible_name = title;
309+ } else if (!id.empty ()) {
310+ accessible_name = id;
311+ } else if (!tooltip.text .empty ()) {
312+ accessible_name = tooltip.text .raw ();
313+ } else {
314+ accessible_name = bus_name;
315+ }
316+
317+ if (auto * accessible = gtk_widget_get_accessible (GTK_WIDGET (button.gobj ())); accessible != nullptr ) {
318+ atk_object_set_name (accessible, accessible_name.c_str ());
319+ }
320+ }
321+
263322void Item::setCustomIcon (const std::string& id) {
264323 spdlog::debug (" SNI tray id: {}" , id);
265324
0 commit comments