-
-
Notifications
You must be signed in to change notification settings - Fork 386
feat(linux): Add support for system color scheme using xdg-desktop-portal #1141
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
efc732b
feat(linux): Add support for system color scheme using xdg-desktop-po…
haecker-felix 9ecb5ea
fix(linux): Downgrade ashpd to 0.7 to be able to compile tao with rus…
haecker-felix 7c04b06
Use dbus-rs instead of ashpd/zbus
haecker-felix 317d439
fix: Emit ThemeChanged events
haecker-felix 8b6795a
Merge remote-tracking branch 'origin/dev' into color-scheme
FabianLars 0c2c526
re-add feature flag
FabianLars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| tao: minor | ||
| --- | ||
|
|
||
| Use the Linux XDG Desktop Portal to add support for the system color scheme. Needs `dbus` feature flag. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #[cfg(feature = "dbus")] | ||
| use dbus::{ | ||
| arg::Variant, | ||
| blocking::{Connection, SyncConnection}, | ||
| message::MatchRule, | ||
| Error, | ||
| }; | ||
| use gtk::glib::{ControlFlow, MainContext, Priority, Sender}; | ||
| use log::warn; | ||
| use std::{thread, time::Duration}; | ||
|
|
||
| use crate::{ | ||
| platform_impl::{platform::window::WindowRequest, WindowId}, | ||
| window::Theme, | ||
| }; | ||
|
|
||
| pub fn theme() -> Result<Theme, Error> { | ||
| let conn = Connection::new_session()?; | ||
| let proxy = conn.with_proxy( | ||
| "org.freedesktop.portal.Desktop", | ||
| "/org/freedesktop/portal/desktop", | ||
| Duration::from_secs(5), | ||
| ); | ||
|
|
||
| let result: (Variant<Variant<u32>>,) = proxy.method_call( | ||
| "org.freedesktop.portal.Settings", | ||
| "Read", | ||
| ("org.freedesktop.appearance", "color-scheme"), | ||
| )?; | ||
|
|
||
| Ok(color_scheme_to_theme(result.0 .0 .0)) | ||
| } | ||
|
|
||
| pub fn receive_theme_changed(window_tx: Sender<(WindowId, WindowRequest)>) -> Result<(), Error> { | ||
| let conn = SyncConnection::new_session()?; | ||
| let match_rule = MatchRule::new_signal("org.freedesktop.portal.Settings", "SettingChanged"); | ||
| let (tx, rx) = MainContext::channel(Priority::DEFAULT); | ||
|
|
||
| conn.add_match(match_rule, move |_: (), _, msg| { | ||
| let mut iter = msg.iter_init(); | ||
| if let (Ok("org.freedesktop.appearance"), Ok("color-scheme"), Ok(value)) = ( | ||
| iter.read::<&str>(), // Namespace | ||
| iter.read::<&str>(), // Key | ||
| iter.read::<Variant<u32>>(), // Value | ||
| ) { | ||
| if let Err(e) = tx.send(color_scheme_to_theme(value.0)) { | ||
| warn!("Failed to send theme change via channel: {}", e); | ||
| } | ||
| } | ||
| true | ||
| })?; | ||
|
|
||
| rx.attach(None, move |theme| { | ||
| if let Err(e) = window_tx.send((WindowId::dummy(), WindowRequest::SetTheme(Some(theme)))) { | ||
| warn!("Failed to send theme change request: {}", e); | ||
| ControlFlow::Break | ||
| } else { | ||
| ControlFlow::Continue | ||
| } | ||
| }); | ||
|
|
||
| thread::spawn(move || loop { | ||
| if let Err(e) = conn.process(Duration::from_secs(5)) { | ||
| warn!("D-Bus message processing error: {}", e); | ||
| break; | ||
| } | ||
| }); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn color_scheme_to_theme(color_scheme: u32) -> Theme { | ||
| match color_scheme { | ||
| 1 => Theme::Dark, // Prefer Dark | ||
| 2 => Theme::Light, // Prefer Light | ||
| _ => Theme::Light, // No Preference, default to Light | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.