zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
35.33k stars 1.79k forks source link

linux: Implement `should_auto_hide_scrollbars` #11973

Closed bajrangCoder closed 5 days ago

bajrangCoder commented 2 weeks ago

Implemented the should_auto_hide_scrollbars method for Linux. This method uses the gsettings GNOME utility to retrieve the setting. The gsettings utility comes pre-installed on many desktop environments such as KDE, GNOME, and others.

The method has been tested on:

Release Notes:

apricotbucket28 commented 2 weeks ago

I think it might be better to use zbus to read system settings. We not only need this but also:

e.g. to get this value via dbus you can run gdbus call -e -d org.freedesktop.portal.Desktop -o /org/freedesktop/portal/desktop -m org.freedesktop.portal.Settings.Read '"org.gnome.desktop.interface"' '"overlay-scrolling"'

bajrangCoder commented 2 weeks ago

I think it might be better to use zbus to read system settings. We not only need this but also:

e.g. to get this value via dbus you can run gdbus call -e -d org.freedesktop.portal.Desktop -o /org/freedesktop/portal/desktop -m org.freedesktop.portal.Settings.Read '"org.gnome.desktop.interface"' '"overlay-scrolling"'

Initially, I considered using the ashpd xdg library, which relies on zbus, to retrieve these settings. However, this approach requires asynchronous calls, and in zed, making a function asynchronous involves spawning tasks (as I observed in the codebase). Additionally, we need to implement equivalent macOS code, as the maintainer has mentioned in several conversations. Therefore, I believe this alternative solution would be more suitable here. But I'm ready to modify it. 😊

We can also get several other settings value by just changing key in this approach

mikayla-maki commented 2 weeks ago

Well, the only reason the code is working right now is that we block the main thread until that external Command completes. How about we try using the zbus approach, but use the same blocking IO, something like:

self.with_common(|common| {
   common.background_executor.block(zbus_async_call)
})

If that doesn't work out, maybe because zbus noticeably lags Zed or the borrowing doesn't work, then we could also try changing this should_auto_hide_scrollbars() API to return a Task<bool>, and do the async spawning as you mentioned. Then we would have change the Zed codebase, which shouldn't be too hard :)

bbb651 commented 2 weeks ago

The only problem with the org.freedesktop.portal.Settings portal is that it expose show all settings, but only a subset of them. For example the one telling you which of the close, maximize, minimize should be visible, in what order and on which side, and some mouse related ones especially around accessibility like double click speed, aren’t exposed. We should still use it when we can, and fill the gap with gsettings when absolutely necessary.

bajrangCoder commented 2 weeks ago

Well, the only reason the code is working right now is that we block the main thread until that external Command completes. How about we try using the zbus approach, but use the same blocking IO, something like:

self.with_common(|common| {
   common.background_executor.block(zbus_async_call)
})

If that doesn't work out, maybe because zbus noticeably lags Zed or the borrowing doesn't work, then we could also try changing this should_auto_hide_scrollbars() API to return a Task<bool>, and do the async spawning as you mentioned. Then we would have change the Zed codebase, which shouldn't be too hard :)

Ok , soon I will commit the zbus implementation

mikayla-maki commented 6 days ago

Note, that this PR has built some nice infrastructure for getting events from xdg into Zed: https://github.com/zed-industries/zed/pull/11926.

Might be good to improve that approach with this configuration setting :)