diff --git a/window/src/os/wayland/connection.rs b/window/src/os/wayland/connection.rs index f917bdfcaddb..c85fb8aafb17 100644 --- a/window/src/os/wayland/connection.rs +++ b/window/src/os/wayland/connection.rs @@ -13,7 +13,7 @@ use wayland_client::{Connection as WConnection, EventQueue}; use crate::screen::{ScreenInfo, Screens}; use crate::spawn::SPAWN_QUEUE; -use crate::{Connection, ConnectionOps, ScreenRect}; +use crate::{Appearance, Connection, ConnectionOps, ScreenRect}; use super::state::WaylandState; use super::WaylandWindowInner; @@ -46,7 +46,11 @@ impl WaylandConnection { Ok(wayland_connection) } - pub(crate) fn advise_of_appearance_change(&self, _appearance: crate::Appearance) {} + pub(crate) fn advise_of_appearance_change(&self, appearance: crate::Appearance) { + for win in self.wayland_state.borrow().windows.borrow().values() { + win.borrow_mut().appearance_changed(appearance); + } + } fn run_message_loop_impl(&self) -> anyhow::Result<()> { const TOK_WL: usize = 0xffff_fffc; @@ -172,6 +176,18 @@ impl ConnectionOps for WaylandConnection { res } + fn get_appearance(&self) -> Appearance { + match promise::spawn::block_on(crate::os::xdg_desktop_portal::get_appearance()) { + Ok(Some(appearance)) => return appearance, + Ok(None) => {} + Err(err) => { + log::warn!("Unable to resolve appearance using xdg-desktop-portal: {err:#}"); + } + } + // fallback + Appearance::Light + } + fn screens(&self) -> anyhow::Result { log::trace!("Getting screens for wayland connection"); diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index e6cd1d4f6304..cb3fa44662e7 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -44,6 +44,7 @@ use wezterm_input_types::{ use crate::wayland::WaylandConnection; use crate::x11::KeyboardWithFallback; use crate::{ + Appearance, Clipboard, Connection, ConnectionOps, Dimensions, MouseCursor, Point, Rect, RequestedWindowGeometry, ResizeIncrement, ResolvedGeometry, Window, WindowEvent, WindowEventSender, WindowKeyEvent, WindowOps, WindowState, @@ -269,6 +270,8 @@ impl WaylandWindow { surface_to_pending.insert(surface.id(), Arc::clone(&pending_mouse)); } + let appearance = conn.get_appearance(); + let inner = Rc::new(RefCell::new(WaylandWindowInner { events: WindowEventSender::new(event_handler), surface_factor: 1.0, @@ -296,6 +299,7 @@ impl WaylandWindow { frame_callback: None, text_cursor: None, + appearance, config, @@ -520,7 +524,7 @@ pub struct WaylandWindowInner { invalidated: bool, // font_config: Rc, text_cursor: Option, - // appearance: Appearance, + appearance: Appearance, config: ConfigHandle, // cache the title for comparison to avoid spamming // the compositor with updates that don't actually change it @@ -1062,6 +1066,14 @@ impl WaylandWindowInner { self.text_cursor.take(); } + pub(crate) fn appearance_changed(&mut self, appearance: Appearance) { + if appearance != self.appearance { + self.appearance = appearance; + self.events + .dispatch(WindowEvent::AppearanceChanged(appearance)); + } + } + pub(super) fn keyboard_event( &mut self, mapper: &mut KeyboardWithFallback,