Skip to content
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

fix #4985 - reimplement get_appearance for wayland #5135

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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