diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index d94bf28e5..07867c815 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -4,6 +4,7 @@ use super::pointer::*; use crate::connection::ConnectionOps; use crate::os::wayland::connection::WaylandConnection; use crate::os::xkeysyms::keysym_to_keycode; +use crate::WindowConfigHandle; use crate::{ Clipboard, Connection, Dimensions, MouseCursor, Point, ScreenPoint, Window, WindowCallbacks, WindowOps, WindowOpsMut, @@ -166,6 +167,7 @@ impl WaylandWindow { width: usize, height: usize, callbacks: Box, + _config: Option<&WindowConfigHandle>, ) -> anyhow::Result { let conn = WaylandConnection::get() .ok_or_else(|| { diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rs index e2a9c0d67..30a5b473b 100644 --- a/window/src/os/windows/window.rs +++ b/window/src/os/windows/window.rs @@ -1,5 +1,6 @@ use super::*; use crate::connection::ConnectionOps; +use crate::WindowConfigHandle; use crate::{ config, Clipboard, Dimensions, KeyCode, KeyEvent, Modifiers, MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, Point, Rect, ScreenPoint, WindowCallbacks, @@ -367,7 +368,12 @@ impl Window { width: usize, height: usize, callbacks: Box, + config: Option<&WindowConfigHandle>, ) -> anyhow::Result { + let config = match config { + Some(c) => Arc::clone(c), + None => crate::config(), + }; let inner = Rc::new(RefCell::new(WindowInner { hwnd: HWindow(null_mut()), callbacks: RefCell::new(callbacks), diff --git a/window/src/os/x11/window.rs b/window/src/os/x11/window.rs index ed0ec7377..e67d59d7e 100644 --- a/window/src/os/x11/window.rs +++ b/window/src/os/x11/window.rs @@ -1,9 +1,9 @@ use super::*; use crate::bitmaps::*; -use crate::configuration::config; use crate::connection::ConnectionOps; use crate::os::xkeysyms; use crate::os::{Connection, Window}; +use crate::WindowConfigHandle; use crate::{ Clipboard, Dimensions, MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, Point, Rect, ScreenPoint, Size, WindowCallbacks, WindowDecorations, WindowOps, WindowOpsMut, @@ -73,6 +73,7 @@ pub(crate) struct XWindowInner { cursor: Option, cursors: HashMap, XcbCursor>, copy_and_paste: CopyAndPaste, + config: WindowConfigHandle, gl_state: Option>, } @@ -611,7 +612,7 @@ impl XWindowInner { xcb::ClientMessageData::from_data32(data), ), ); - self.adjust_decorations(config().decorations())?; + self.adjust_decorations(self.config.decorations())?; Ok(()) } @@ -700,7 +701,12 @@ impl XWindow { width: usize, height: usize, callbacks: Box, + config: Option<&WindowConfigHandle>, ) -> anyhow::Result { + let config = match config { + Some(c) => Arc::clone(c), + None => crate::config(), + }; let conn = Connection::get() .ok_or_else(|| { anyhow!( @@ -781,6 +787,7 @@ impl XWindow { cursor: None, cursors: HashMap::new(), gl_state: None, + config: Arc::clone(&config), })) }; @@ -802,7 +809,7 @@ impl XWindow { window .lock() .unwrap() - .adjust_decorations(config().decorations())?; + .adjust_decorations(config.decorations())?; let window_handle = Window::X11(XWindow::from_id(window_id)); @@ -849,8 +856,9 @@ impl WindowOpsMut for XWindowInner { self.set_fullscreen_hint(!fullscreen).ok(); } - fn config_did_change(&mut self, _config: &WindowConfigHandle) { - let _ = self.adjust_decorations(config().decorations()); + fn config_did_change(&mut self, config: &WindowConfigHandle) { + self.config = Arc::clone(config); + let _ = self.adjust_decorations(config.decorations()); } fn set_inner_size(&mut self, width: usize, height: usize) { @@ -937,7 +945,7 @@ impl WindowOps for XWindow { fn config_did_change(&self, config: &WindowConfigHandle) -> Future<()> { let config = Arc::clone(config); - XConnection::with_window_inner(self.0, |inner| { + XConnection::with_window_inner(self.0, move |inner| { inner.config_did_change(&config); Ok(()) }) diff --git a/window/src/os/x_and_wayland.rs b/window/src/os/x_and_wayland.rs index 69282bb60..fd77c6a67 100644 --- a/window/src/os/x_and_wayland.rs +++ b/window/src/os/x_and_wayland.rs @@ -7,6 +7,7 @@ use crate::os::wayland::connection::WaylandConnection; use crate::os::wayland::window::WaylandWindow; use crate::os::x11::connection::XConnection; use crate::os::x11::window::XWindow; +use crate::WindowConfigHandle; use crate::{config, Clipboard, MouseCursor, ScreenPoint, WindowCallbacks, WindowOps}; use promise::*; use std::any::Any; @@ -51,12 +52,13 @@ impl Connection { width: usize, height: usize, callbacks: Box, + config: Option<&WindowConfigHandle>, ) -> anyhow::Result { match self { - Self::X11(_) => XWindow::new_window(class_name, name, width, height, callbacks), + Self::X11(_) => XWindow::new_window(class_name, name, width, height, callbacks, config), #[cfg(feature = "wayland")] Self::Wayland(_) => { - WaylandWindow::new_window(class_name, name, width, height, callbacks) + WaylandWindow::new_window(class_name, name, width, height, callbacks, config) } } } @@ -110,10 +112,11 @@ impl Window { width: usize, height: usize, callbacks: Box, + config: Option<&WindowConfigHandle>, ) -> anyhow::Result { Connection::get() .unwrap() - .new_window(class_name, name, width, height, callbacks) + .new_window(class_name, name, width, height, callbacks, config) } }