Skip to content

Commit

Permalink
fix wez#4985 - reimplement get_appearance for wayland
Browse files Browse the repository at this point in the history
- was dropped with wayland reimplementation (wez#4777, 3eaba4e)
- get appearance from xdg desktop portal
- advise all windows of appearance changes and reload config
  • Loading branch information
MartinNowak committed Mar 9, 2024
1 parent 22424c3 commit 778daa3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
20 changes: 18 additions & 2 deletions window/src/os/wayland/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<crate::screen::Screens> {
log::trace!("Getting screens for wayland connection");

Expand Down
14 changes: 13 additions & 1 deletion window/src/os/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -296,6 +299,7 @@ impl WaylandWindow {
frame_callback: None,

text_cursor: None,
appearance,

config,

Expand Down Expand Up @@ -520,7 +524,7 @@ pub struct WaylandWindowInner {
invalidated: bool,
// font_config: Rc<FontConfiguration>,
text_cursor: Option<Rect>,
// appearance: Appearance,
appearance: Appearance,
config: ConfigHandle,
// cache the title for comparison to avoid spamming
// the compositor with updates that don't actually change it
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 778daa3

Please sign in to comment.