From d54e29d3758f8abd0f97508ff89de46e739a0931 Mon Sep 17 00:00:00 2001 From: Jim Date: Thu, 20 Mar 2025 11:05:22 +0100 Subject: [PATCH] macOS: Add `movable_by_window_background` option to viewport (#5412) Add an option called `movable_by_window_background` alongside a new builder method. When set to true, the window is movable by dragging its background ([Apple Docs](https://developer.apple.com/documentation/appkit/nswindow/ismovablebywindowbackground)) This is exclusive to macOS systems, similar to `fullsize_content_view`. * [x] I have followed the instructions in the PR template --- crates/egui-winit/src/lib.rs | 4 +++- crates/egui/src/viewport.rs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index e7c5ffe8..1c47d7eb 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -1615,6 +1615,7 @@ pub fn create_winit_window_attributes( // macOS: fullsize_content_view: _fullsize_content_view, + movable_by_window_background: _movable_by_window_background, title_shown: _title_shown, titlebar_buttons_shown: _titlebar_buttons_shown, titlebar_shown: _titlebar_shown, @@ -1761,7 +1762,8 @@ pub fn create_winit_window_attributes( .with_title_hidden(!_title_shown.unwrap_or(true)) .with_titlebar_buttons_hidden(!_titlebar_buttons_shown.unwrap_or(true)) .with_titlebar_transparent(!_titlebar_shown.unwrap_or(true)) - .with_fullsize_content_view(_fullsize_content_view.unwrap_or(false)); + .with_fullsize_content_view(_fullsize_content_view.unwrap_or(false)) + .with_movable_by_window_background(_movable_by_window_background.unwrap_or(false)); } window_attributes diff --git a/crates/egui/src/viewport.rs b/crates/egui/src/viewport.rs index 791b34c7..9aba6991 100644 --- a/crates/egui/src/viewport.rs +++ b/crates/egui/src/viewport.rs @@ -291,6 +291,7 @@ pub struct ViewportBuilder { // macOS: pub fullsize_content_view: Option, + pub movable_by_window_background: Option, pub title_shown: Option, pub titlebar_buttons_shown: Option, pub titlebar_shown: Option, @@ -432,6 +433,15 @@ impl ViewportBuilder { self } + /// macOS: Set to `true` to allow the window to be moved by dragging the background. + /// + /// Enabling this feature can result in unexpected behaviour with draggable UI widgets such as sliders. + #[inline] + pub fn with_movable_by_background(mut self, value: bool) -> Self { + self.movable_by_window_background = Some(value); + self + } + /// macOS: Set to `false` to hide the window title. #[inline] pub fn with_title_shown(mut self, title_shown: bool) -> Self { @@ -640,6 +650,7 @@ impl ViewportBuilder { visible: new_visible, drag_and_drop: new_drag_and_drop, fullsize_content_view: new_fullsize_content_view, + movable_by_window_background: new_movable_by_window_background, title_shown: new_title_shown, titlebar_buttons_shown: new_titlebar_buttons_shown, titlebar_shown: new_titlebar_shown, @@ -825,6 +836,13 @@ impl ViewportBuilder { recreate_window = true; } + if new_movable_by_window_background.is_some() + && self.movable_by_window_background != new_movable_by_window_background + { + self.movable_by_window_background = new_movable_by_window_background; + recreate_window = true; + } + if new_drag_and_drop.is_some() && self.drag_and_drop != new_drag_and_drop { self.drag_and_drop = new_drag_and_drop; recreate_window = true;