Skip to content

Commit

Permalink
x11: get initial appearance from generic connection
Browse files Browse the repository at this point in the history
Right now the initial appearance retrieval uses the x11 connection
interface, which completely circumvents the already existing more
complete implementation in x_and_wayland.rs.
The latter implementation is strictly better, because it first attempts
getting the appearance from the XDG desktop portal and then falls back
to the X11 interface, whereas right now we are only using the X11
interface.

Before this patch there was a very weird issue for folks using the OS
system dark mode with the following config snippet:
```
color_scheme = scheme_for_appearance(wezterm.gui.get_appearance())
```

The color_scheme on startup would be correct, but there would be a very
weird problem where sometimes wezterm ignores the first time that the
portal notifies about a colorscheme change. All following colorscheme
change notifications would be processed correctly.

The source of the bug was an inconsistent retrieval of the appearance
setting:
- The Lua API used the XDG desktop portal
- The internal appearance used the X11 specific connection at startup

For example due to this, the internal appearance variable could have
stored "Dark" from the X11 connection, but the actual appearance from
the XDG desktop portal was "Light".
If then the XDG desktop portal changes to "Dark", the
appearance_changed() method would dismiss the update with the following
check because self.appearance was "Dark":
```
if appearance != self.appearance
```
It is only after that, that the internal inconsistency would have been
solved and following appearance changes would succeed and update the
colorscheme.

To fix this problem, we now read the appearance setting from the generic
connection which is consistent with the Lua wezterm.gui.get_appearance()
API.

refs: wez#2258
  • Loading branch information
vimpostor committed Jul 15, 2022
1 parent 8484248 commit 4d4a706
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions window/src/os/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,13 +972,13 @@ impl XWindow {
Some(c) => c.clone(),
None => config::configuration(),
};
let conn = Connection::get()
let connection = Connection::get()
.ok_or_else(|| {
anyhow!(
"new_window must be called on the gui thread after Connection::init has succeeded",
)
})?
.x11();
})?;
let conn = connection.x11();

let ResolvedGeometry {
x,
Expand Down Expand Up @@ -1044,7 +1044,7 @@ impl XWindow {

events.assign_window(Window::X11(XWindow::from_id(window_id)));

let appearance = conn.get_appearance();
let appearance = connection.get_appearance();

Arc::new(Mutex::new(XWindowInner {
title: String::new(),
Expand Down

0 comments on commit 4d4a706

Please sign in to comment.