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

Port to GTK4 #105

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Port to GTK4 #105

wants to merge 14 commits into from

Conversation

Ferdi265
Copy link
Contributor

@Ferdi265 Ferdi265 commented Sep 15, 2024

This PR ports SwayOSD to GTK4. Applies on top of #104. Fixes #75. Fixes #101.

A lot of changes to prepare for this were already done, but GTK4 changes a lot more which had to be worked around. Note that this branch currently does not work out of the box (Wayland protocol errors) due to an upstream gtk4-layer-shell issue. The upstream fix is merged, but not yet released.

Main changes:

  • syntax for clone! macro has changed (#[strong] instead of @strong and , instead of =>)
  • GDK Display no longer has useful monitor added/removed signals
    • the alternative is to use the .monitors() ListModel, which is non-generic and has an ugly API. seems to work though.
  • StyleContext is deprecated and its API changed
    • CSSProviders still exist, but the API looks different, I managed to make it compile, but I'm not 100% sure it's correct
  • Some Widget/Container APIs changed
    • Monitor no longer has workarea(), switched to geometry(), hope that's the same.
    • Window has set_child() instead of add()
    • Box now has append() instead of add()
      • Box no longer has a simple way of iterating through all children, which sucks
      • somehow removing Box children doesn't work you need to be very careful when iterating to make remove work, since it seems to be a linked-list-like structure.
    • Image no longer has a size_allocate signal, but realize is hopefully similar
    • The logic for updating the layer shell margin was changed to (a) work properly in GTK4 and (b) work properly with output scale changes

TODO

  • Make it compile
  • Make it work without crashing
  • Fix visual changes and bugs

@Ferdi265
Copy link
Contributor Author

This will probably take a while to be finished, but since there is now at least a compiling gtk4 codebase, hopefully it will be less daunting for other people to help.

@Ferdi265
Copy link
Contributor Author

Ferdi265 commented Sep 17, 2024

I figured out how to make it work (including a bug reproducer for gtk4-layer-shell), will push once it's cleaned up :)

The current version runs, but doesn't correctly handle changes in output size or scale (since connect_map() leads to crashes). I'm also working on a fix for gtk4-layer-shell.

@Ferdi265
Copy link
Contributor Author

Ferdi265 commented Sep 20, 2024

Fix for upstream gtk4-layer-shell issue: wmww/gtk4-layer-shell#49

With that fix it doesn't crash any more. I also changed the margin code so it is always updated when its inputs change, which is more reliable than relying on connect_map() and hoping everything is ready at that point and doesn't change any more. I also worked around a bug with GTK4's output scale sometimes being incorrect (it never goes back to 1.0 scale after being at 2.0 even if I change the output scale back in sway) by manually transforming the output size into window coordinates (this fixes #101).

The main issue remaining is some "Channel Send error: sending into a closed channel" errors printed on stderr, I probably did something wrong while porting the MainContext::channel() usage to async_channel (I should check whether this also happens in #104 and fix both)

- some icons are broken
- clearing osd window doesn't work
- gtk4_layer_shell crashes more often than not
we need to get the next sibling before we remove it from the box.
some icons (notably volume icons) don't seem to be detected by has_icon
properly in all cases, but the icon is drawn correctly. Use
gio::ThemedIcon directly and pass "missing-symbolic" as a fallback name
through there to avoid checking explicitly.
This ensures the window margin is always correct. This also fixes an
annoying issue where the monitor scale factor is not always correct (it
never changes back to scale 1 if it was scale 2 at some point) by
transforming the monitor height into window coordinates manually.

Fixes ErikReider#101.
@Ferdi265
Copy link
Contributor Author

The main issue remaining is some "Channel Send error: sending into a closed channel" errors printed on stderr, I probably did something wrong while porting the MainContext::channel() usage to async_channel (I should check whether this also happens in #104 and fix both)

Channel issue is now fixed with the latest rebase.

@Ferdi265 Ferdi265 changed the title [WIP] Port to GTK4 Port to GTK4 Sep 22, 2024
@Ferdi265
Copy link
Contributor Author

Should be mostly ready for review now. It looks slightly different than the GTK3 version (GTK4 has more default padding), but looks like it works quite well. I've switched to it as my daily driver.

Still depends on the upstream gtk4-layer-shell fix PR

@Ferdi265 Ferdi265 marked this pull request as ready for review September 22, 2024 12:56
@werdahias
Copy link
Contributor

awesome, thanks for your work !

@NullVoxPopuli
Copy link

excited for this!

@Ferdi265
Copy link
Contributor Author

Ferdi265 commented Oct 23, 2024

I've been running this branch as my daily driver for the last month and haven't seen any crashes, but it seems to hang sometimes, requiring a restart to get responsive again. I'll try to run a debug build for the next week or two to see if I can figure out the issue.

@NullVoxPopuli
Copy link

This is working great -- I had to install some deps to compile it, but 10/10 would install/compile again

@Ferdi265
Copy link
Contributor Author

Ferdi265 commented Oct 26, 2024

The upstream gtk4-layer-shell fix for the crash issue has just been merged, but hasn't been released yet.

@Ferdi265
Copy link
Contributor Author

Ferdi265 commented Oct 27, 2024

I've been running this branch as my daily driver for the last month and haven't seen any crashes, but it seems to hang sometimes, requiring a restart to get responsive again. I'll try to run a debug build for the next week or two to see if I can figure out the issue.

The libinput dbus signal listener was hanging in Sender::send_blocking(). This seems to happen mostly when SwayOSD is started as a systemd user service on system startup, seems like a timing issue.

I changed the code to spawn an async task on the MainContext and use an async send().await there instead. Let's see if this fixes the issue. If this doesn't occur in the next two weeks or so in my testing I'll consider this fixed.

UPDATE: I haven't seen the issue last week, so I've changed to running a release build instead of a debug build and if it still doesn't appear I consider this fixed.

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

Successfully merging this pull request may close these issues.

Top Margin is applied inconsistently on sway, and is wildly wrong with fractional scaling Port to GTK4 ?
3 participants