linux: Get the color scheme through xdg-desktop-portal (#11926)

The method has been tested on:
- Gnome 46 (Working)
- Gnome 40 (Not supported)

Tasks

- [x] Implements a draft which get and provides the user theme to
components which needs it
- [x] Implements a way to call the callback function when the theme is
updated
- [X] Cleans the code

Release notes:
- N/A
This commit is contained in:
citorva 2024-05-27 02:00:10 +02:00 committed by GitHub
parent b1cfd46d37
commit a84344a82e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 224 additions and 14 deletions

View file

@ -8,6 +8,7 @@ use std::io::Read;
use std::ops::{Deref, DerefMut};
use std::os::fd::{AsRawFd, FromRawFd};
use std::panic::Location;
use std::rc::Weak;
use std::{
path::{Path, PathBuf},
process::Command,
@ -27,11 +28,13 @@ use flume::{Receiver, Sender};
use futures::channel::oneshot;
use parking_lot::Mutex;
use time::UtcOffset;
use util::ResultExt;
use wayland_client::Connection;
use wayland_protocols::wp::cursor_shape::v1::client::wp_cursor_shape_device_v1::Shape;
use xkbcommon::xkb::{self, Keycode, Keysym, State};
use crate::platform::linux::wayland::WaylandClient;
use crate::platform::linux::xdg_desktop_portal::window_appearance;
use crate::{
px, Action, AnyWindowHandle, BackgroundExecutor, ClipboardItem, CosmicTextSystem, CursorStyle,
DisplayId, ForegroundExecutor, Keymap, Keystroke, LinuxDispatcher, Menu, MenuItem, Modifiers,
@ -86,6 +89,7 @@ pub(crate) struct LinuxCommon {
pub(crate) background_executor: BackgroundExecutor,
pub(crate) foreground_executor: ForegroundExecutor,
pub(crate) text_system: Arc<CosmicTextSystem>,
pub(crate) appearance: WindowAppearance,
pub(crate) callbacks: PlatformHandlers,
pub(crate) signal: LoopSignal,
}
@ -96,12 +100,18 @@ impl LinuxCommon {
let text_system = Arc::new(CosmicTextSystem::new());
let callbacks = PlatformHandlers::default();
let dispatcher = Arc::new(LinuxDispatcher::new(main_sender));
let dispatcher = Arc::new(LinuxDispatcher::new(main_sender.clone()));
let background_executor = BackgroundExecutor::new(dispatcher.clone());
let appearance = window_appearance(&background_executor)
.log_err()
.unwrap_or(WindowAppearance::Light);
let common = LinuxCommon {
background_executor: BackgroundExecutor::new(dispatcher.clone()),
background_executor,
foreground_executor: ForegroundExecutor::new(dispatcher.clone()),
text_system,
appearance,
callbacks,
signal,
};
@ -462,8 +472,8 @@ impl<P: LinuxClient + 'static> Platform for P {
})
}
fn window_appearance(&self) -> crate::WindowAppearance {
crate::WindowAppearance::Light
fn window_appearance(&self) -> WindowAppearance {
self.with_common(|common| common.appearance)
}
fn register_url_scheme(&self, _: &str) -> Task<anyhow::Result<()>> {