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:
parent
b1cfd46d37
commit
a84344a82e
7 changed files with 224 additions and 14 deletions
|
@ -2,7 +2,7 @@ use std::any::Any;
|
|||
use std::cell::{Ref, RefCell, RefMut};
|
||||
use std::ffi::c_void;
|
||||
use std::num::NonZeroU32;
|
||||
use std::ops::Range;
|
||||
use std::ops::{Deref, Range};
|
||||
use std::ptr::NonNull;
|
||||
use std::rc::{Rc, Weak};
|
||||
use std::sync::Arc;
|
||||
|
@ -10,6 +10,7 @@ use std::sync::Arc;
|
|||
use blade_graphics as gpu;
|
||||
use collections::{HashMap, HashSet};
|
||||
use futures::channel::oneshot::Receiver;
|
||||
use parking_lot::Mutex;
|
||||
use raw_window_handle as rwh;
|
||||
use wayland_backend::client::ObjectId;
|
||||
use wayland_client::protocol::wl_region::WlRegion;
|
||||
|
@ -70,6 +71,7 @@ pub struct WaylandWindowState {
|
|||
acknowledged_first_configure: bool,
|
||||
pub surface: wl_surface::WlSurface,
|
||||
decoration: Option<zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1>,
|
||||
appearance: WindowAppearance,
|
||||
blur: Option<org_kde_kwin_blur::OrgKdeKwinBlur>,
|
||||
toplevel: xdg_toplevel::XdgToplevel,
|
||||
viewport: Option<wp_viewport::WpViewport>,
|
||||
|
@ -100,6 +102,7 @@ impl WaylandWindowState {
|
|||
xdg_surface: xdg_surface::XdgSurface,
|
||||
toplevel: xdg_toplevel::XdgToplevel,
|
||||
decoration: Option<zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1>,
|
||||
appearance: WindowAppearance,
|
||||
viewport: Option<wp_viewport::WpViewport>,
|
||||
client: WaylandClientStatePtr,
|
||||
globals: Globals,
|
||||
|
@ -158,6 +161,7 @@ impl WaylandWindowState {
|
|||
maximized: false,
|
||||
callbacks: Callbacks::default(),
|
||||
client,
|
||||
appearance,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,6 +219,7 @@ impl WaylandWindow {
|
|||
globals: Globals,
|
||||
client: WaylandClientStatePtr,
|
||||
params: WindowParams,
|
||||
appearance: WindowAppearance,
|
||||
) -> (Self, ObjectId) {
|
||||
let surface = globals.compositor.create_surface(&globals.qh, ());
|
||||
let xdg_surface = globals
|
||||
|
@ -251,6 +256,7 @@ impl WaylandWindow {
|
|||
xdg_surface,
|
||||
toplevel,
|
||||
decoration,
|
||||
appearance,
|
||||
viewport,
|
||||
client,
|
||||
globals,
|
||||
|
@ -571,6 +577,15 @@ impl WaylandWindowStatePtr {
|
|||
fun(focus);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_appearance(&mut self, appearance: WindowAppearance) {
|
||||
self.state.borrow_mut().appearance = appearance;
|
||||
|
||||
let mut callbacks = self.callbacks.borrow_mut();
|
||||
if let Some(ref mut fun) = callbacks.appearance_changed {
|
||||
(fun)()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl rwh::HasWindowHandle for WaylandWindow {
|
||||
|
@ -618,9 +633,8 @@ impl PlatformWindow for WaylandWindow {
|
|||
self.borrow().scale
|
||||
}
|
||||
|
||||
// todo(linux)
|
||||
fn appearance(&self) -> WindowAppearance {
|
||||
WindowAppearance::Light
|
||||
self.borrow().appearance
|
||||
}
|
||||
|
||||
// todo(linux)
|
||||
|
@ -777,7 +791,7 @@ impl PlatformWindow for WaylandWindow {
|
|||
}
|
||||
|
||||
fn on_appearance_changed(&self, callback: Box<dyn FnMut()>) {
|
||||
// todo(linux)
|
||||
self.0.callbacks.borrow_mut().appearance_changed = Some(callback);
|
||||
}
|
||||
|
||||
fn draw(&self, scene: &Scene) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue