Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce support for GTK 4 #22

Open
mathiascode opened this issue Jun 2, 2021 · 11 comments
Open

Introduce support for GTK 4 #22

mathiascode opened this issue Jun 2, 2021 · 11 comments

Comments

@mathiascode
Copy link

As a long-term goal, support for GTK 4 should probably be introduced. GtkMenu is removed in GTK 4, which complicates this process somewhat.

@sunweaver
Copy link
Member

@mathiascode: any idea from your side?

People suggest switching over to GtkPopoverMenu for rendering, but those are extremely awful by design.

Another option could be to rip out GtkMenu from GTK-3, provide it as a separate library, make it work with GMenu datastructures, but render it like GtkMenu.

I suppose, that desktop environments like MATE, XFCE, etc. will also be whining about the removal of GtkMenu...

@tari01: your 5 ¢ on this?

@sunweaver
Copy link
Member

@tari01
Copy link
Member

tari01 commented Jun 2, 2021

We are entirely built around GtkMenuItem. ayatana-ido expands on that, libayatana-indicator hacks the rendering for it. I say we wait until the GTK people make a final decision on how they want this whole action <-> menu to work in the future...

Edit: I cannot imagine a functioning desktop environment without decent standard menus. I'm still hoping the GtkMenu will survive somehow. GTK cannot seriously expect MATE, XFCE, etc to completely rewrite their environment.

@mathiascode
Copy link
Author

I doubt GtkMenu will ever be considered again upstream. After some trial and error, I've spent a considerable amount of time porting Nicotine+'s menus from GtkMenu to GMenu + Gtk.Menu.new_from_model or Gtk.PopoverMenu.new_from_model_full, depending on the GTK version.

In GTK 4, GtkPopoverMenu has a new GTK_POPOVER_MENU_NESTED flag, which essentially restores the behavior of GtkMenu submenus. GtkPopover has a new set_has_arrow() function that removes the popover arrow.

The resulting code is here: https://github.com/Nicotine-Plus/nicotine-plus/blob/master/pynicotine/gtkgui/widgets/popupmenu.py

Some screenshots for clarity:
GTK 3:
gtk3

GTK 4:
gtk4

For plain menus, GtkPopoverMenu is certainly an improvement over its GTK 3 counterpart, but you're probably out of luck if you need direct access to menu item rendering.

@tari01
Copy link
Member

tari01 commented Jun 2, 2021

@mathiascode Thanks for sharing this. Once we've eliminated all the bugs and PRs from the entire Ayatana ecosystem, We'll do some major (re)coding :)

@DeedleFake
Copy link

Any updates on this? I recently ported my app's UI to Gtk4/Libadwaita and it looks great but I can't get a tray icon no matter what I try, as pretty much every single library for it seems to depend on Gtk3, and you can't link both versions simultaneously.

@hwittenborn
Copy link

hwittenborn commented Mar 14, 2023

It's really hacky, but the method I'm using in my application (you can find it here for reference) is creating my main GTK4 application, and then making my app's tray icon a separate app in GTK3. The two then communicate via DBus, and it works pretty much fine as long as you add in some error handling for when either side dies out. It's definitely a bit on the hacky side, but if you want an immediate solution I've found it to be quite effective.

I heard somewhere a while back that some application got something working in pure GTK4 to work with system trays, I forget where I saw it though.

@yochananmarqos
Copy link

@hwittenborn

I forget where I saw it though.

😉 👇

hwittenborn/celeste#25 (comment)

@hwittenborn
Copy link

Crud I don't know how I forgot about that, lol. That'd definitely be where though. I'm gonna have to look into what they do to see if I can find any clues.

@DeedleFake
Copy link

Any updates on this? I recently ported my app's UI to Gtk4/Libadwaita and it looks great but I can't get a tray icon no matter what I try, as pretty much every single library for it seems to depend on Gtk3, and you can't link both versions simultaneously.

Follow up: I recently tried the Fyne project's system tray implementation again again and it worked fine for my purposes. They've removed the Gtk3 dependency and it's now pure Go on Linux via a native D-Bus implementation. It's not perfect, especially as the D-Bus implementation is very inefficient and performs far more allocations than it probably should, but it works.

@mathiascode
Copy link
Author

Crud I don't know how I forgot about that, lol. That'd definitely be where though. I'm gonna have to look into what they do to see if I can find any clues.

It's a partial implementation of the StatusNotifierItem spec for our needs, communicating with the org.kde.StatusNotifierItem and com.canonical.dbusmenu D-Bus interfaces, and replacing libappindicator/libayatana-appindicator and libdbusmenu. A notable omission is submenu support, since we don't use them in Nicotine+.

The better long-term option would be to either replace libdbusmenu-gtk in libayatana-appindicator, or update it to use something else than GtkMenu. However, 1. it's a fair amount of work across the entire project if done properly (AyatanaIndicators/ayatana-ido#51), and 2. I'm personally not too fond of using the AppIndicator implementation due to past design decisions, such as omitting support for primary click actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants