Merge pull request #438 from alebastr/tray-fixes

Tray fixes
This commit is contained in:
Alex 2019-08-29 11:03:09 +02:00 committed by GitHub
commit baaeda0ab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -46,7 +46,12 @@ class Item : public sigc::trackable {
std::string menu;
DbusmenuGtkMenu* dbus_menu = nullptr;
Gtk::Menu* gtk_menu = nullptr;
bool item_is_menu = false;
/**
* ItemIsMenu flag means that the item only supports the context menu.
* Default value is true because libappindicator supports neither ItemIsMenu nor Activate method
* while compliant SNI implementation would always reset the flag to desired value.
*/
bool item_is_menu = true;
private:
void proxyReady(Glib::RefPtr<Gio::AsyncResult>& result);
@ -60,7 +65,7 @@ class Item : public sigc::trackable {
Glib::RefPtr<Gdk::Pixbuf> extractPixBuf(GVariant* variant);
Glib::RefPtr<Gdk::Pixbuf> getIconByName(const std::string& name, int size);
static void onMenuDestroyed(Item* self, GObject* old_menu_pointer);
void makeMenu(GdkEventButton* const& ev);
void makeMenu();
bool handleClick(GdkEventButton* const& /*ev*/);
Glib::RefPtr<Gio::DBus::Proxy> proxy_;

View File

@ -128,6 +128,7 @@ void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
}
} else if (name == "Menu") {
menu = get_variant<std::string>(value);
makeMenu();
} else if (name == "ItemIsMenu") {
item_is_menu = get_variant<bool>(value);
}
@ -319,7 +320,7 @@ void Item::onMenuDestroyed(Item* self, GObject* old_menu_pointer) {
}
}
void Item::makeMenu(GdkEventButton* const& ev) {
void Item::makeMenu() {
if (gtk_menu == nullptr && !menu.empty()) {
dbus_menu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data());
if (dbus_menu != nullptr) {
@ -334,8 +335,8 @@ void Item::makeMenu(GdkEventButton* const& ev) {
bool Item::handleClick(GdkEventButton* const& ev) {
auto parameters = Glib::VariantContainerBase::create_tuple(
{Glib::Variant<int>::create(ev->x), Glib::Variant<int>::create(ev->y)});
if ((ev->button == 1 && (item_is_menu || !menu.empty())) || ev->button == 3) {
makeMenu(ev);
if ((ev->button == 1 && item_is_menu) || ev->button == 3) {
makeMenu();
if (gtk_menu != nullptr) {
#if GTK_CHECK_VERSION(3, 22, 0)
gtk_menu->popup_at_pointer(reinterpret_cast<GdkEvent*>(ev));