From 1ca9fb3555e51bc2dfa15ff278bc869bfd935a41 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 4 Mar 2021 08:02:13 -0800 Subject: [PATCH] x11: allow disabling the titlebar I've kept resizing in there because it doesn't appear to render a border in mutter and seems useful. I think I'll probably change WindowDecorations to bitflags so that the user can control this, but first need to verify what windows supports for this. --- window/src/os/x11/window.rs | 28 +++++++++++++++++++++++----- window/src/os/x_and_wayland.rs | 8 ++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/window/src/os/x11/window.rs b/window/src/os/x11/window.rs index 11b9c641f..0c94a3a1d 100644 --- a/window/src/os/x11/window.rs +++ b/window/src/os/x11/window.rs @@ -1,11 +1,12 @@ use super::*; use crate::bitmaps::*; +use crate::configuration::config; use crate::connection::ConnectionOps; use crate::os::xkeysyms; use crate::os::{Connection, Window}; use crate::{ Clipboard, Dimensions, MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, - Point, Rect, ScreenPoint, Size, WindowCallbacks, WindowOps, WindowOpsMut, + Point, Rect, ScreenPoint, Size, WindowCallbacks, WindowDecorations, WindowOps, WindowOpsMut, }; use anyhow::{anyhow, Context as _}; use promise::{Future, Promise}; @@ -610,11 +611,12 @@ impl XWindowInner { xcb::ClientMessageData::from_data32(data), ), ); + self.adjust_decorations(config().decorations() == WindowDecorations::Full)?; Ok(()) } - #[allow(dead_code, clippy::identity_op)] + #[allow(clippy::identity_op)] fn adjust_decorations(&mut self, enable: bool) -> anyhow::Result<()> { // Set the motif hints to disable decorations. // See https://stackoverflow.com/a/1909708 @@ -627,19 +629,21 @@ impl XWindowInner { status: u32, } - const HINTS_FUNCTIONS: u32 = 1 << 0; const HINTS_DECORATIONS: u32 = 1 << 1; const FUNC_ALL: u32 = 1 << 0; const FUNC_RESIZE: u32 = 1 << 1; + /* + const HINTS_FUNCTIONS: u32 = 1 << 0; const FUNC_MOVE: u32 = 1 << 2; const FUNC_MINIMIZE: u32 = 1 << 3; const FUNC_MAXIMIZE: u32 = 1 << 4; const FUNC_CLOSE: u32 = 1 << 5; + */ let hints = MwmHints { flags: HINTS_DECORATIONS, functions: 0, - decorations: if enable { FUNC_ALL } else { 0 }, + decorations: if enable { FUNC_ALL } else { FUNC_RESIZE }, input_mode: 0, status: 0, }; @@ -785,7 +789,10 @@ impl XWindow { &[conn.atom_delete], ); - // window.lock().unwrap().disable_decorations()?; + window + .lock() + .unwrap() + .adjust_decorations(config().decorations() == WindowDecorations::Full)?; let window_handle = Window::X11(XWindow::from_id(window_id)); @@ -832,6 +839,10 @@ impl WindowOpsMut for XWindowInner { self.set_fullscreen_hint(!fullscreen).ok(); } + fn config_did_change(&mut self) { + let _ = self.adjust_decorations(config().decorations() == WindowDecorations::Full); + } + fn set_inner_size(&mut self, width: usize, height: usize) { xcb::configure_window( self.conn().conn(), @@ -914,6 +925,13 @@ impl WindowOps for XWindow { }) } + fn config_did_change(&self) -> Future<()> { + XConnection::with_window_inner(self.0, |inner| { + inner.config_did_change(); + Ok(()) + }) + } + fn show(&self) -> Future<()> { XConnection::with_window_inner(self.0, |inner| { inner.show(); diff --git a/window/src/os/x_and_wayland.rs b/window/src/os/x_and_wayland.rs index 57de313b1..268c55dca 100644 --- a/window/src/os/x_and_wayland.rs +++ b/window/src/os/x_and_wayland.rs @@ -142,6 +142,14 @@ impl WindowOps for Window { } } + fn config_did_change(&self) -> Future<()> { + match self { + Self::X11(x) => x.config_did_change(), + #[cfg(feature = "wayland")] + Self::Wayland(w) => w.config_did_change(), + } + } + fn show(&self) -> Future<()> { match self { Self::X11(x) => x.show(),