diff --git a/examples/Cargo.toml b/examples/Cargo.toml index ac98cb1..b41ec63 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -161,6 +161,10 @@ path = "split_pane_layout/main.rs" name = "tree_view" path = "tree_view/main.rs" +[[bin]] +name = "win_level_request" +path = "win_level_request/main.rs" + [[bin]] name = "win_widget" path = "win_widget/main.rs" diff --git a/examples/win_level_request/main.rs b/examples/win_level_request/main.rs new file mode 100644 index 0000000..0e75c2d --- /dev/null +++ b/examples/win_level_request/main.rs @@ -0,0 +1,20 @@ +use tlib::winit::window::WindowLevel; +use tmui::{application::Application, application_window::ApplicationWindow, prelude::*}; + +fn main() { + log4rs::init_file("examples/log4rs.yaml", Default::default()).unwrap(); + + let app = Application::builder() + .width(1280) + .height(800) + .title("") + .build(); + + app.connect_activate(build_ui); + + app.run(); +} + +fn build_ui(window: &mut ApplicationWindow) { + window.register_run_after(move |win| win.set_window_level(WindowLevel::AlwaysOnTop)); +} diff --git a/tmui/src/application_window.rs b/tmui/src/application_window.rs index 90f32b2..e815c98 100644 --- a/tmui/src/application_window.rs +++ b/tmui/src/application_window.rs @@ -43,7 +43,7 @@ use tlib::{ object::{ObjectImpl, ObjectSubclass}, skia_safe::ClipOp, values::FromValue, - winit::window::WindowId, + winit::window::{WindowId, WindowLevel}, }; use self::animation::frame_animator::{FrameAnimatorMgr, ReflectFrameAnimator}; @@ -307,7 +307,7 @@ impl ApplicationWindow { } #[inline] - pub fn register_run_after(&mut self, run_after: R) { + pub fn register_run_after(&mut self, run_after: R) { self.run_after = Some(Box::new(run_after)); } @@ -375,6 +375,16 @@ impl ApplicationWindow { self.send_message(Message::WindowRestoreRequest(self.winit_id.unwrap())) } + #[inline] + pub fn set_window_level(&mut self, level: WindowLevel) { + if self.platform_type == PlatformType::Ipc { + error!("Can not restore window on slave side of shared memory application."); + return; + } + + self.send_message(Message::WindowLevelRequest(self.winit_id.unwrap(), level)) + } + #[inline] pub fn window_layout_change(&mut self) { Self::layout_of(self.id()).layout_change(self, false) diff --git a/tmui/src/primitive/message.rs b/tmui/src/primitive/message.rs index 3f8cf69..2ad0056 100644 --- a/tmui/src/primitive/message.rs +++ b/tmui/src/primitive/message.rs @@ -8,7 +8,7 @@ use tlib::{ object::ObjectId, payload::PayloadWeight, prelude::SystemCursorShape, - winit::window::WindowId, + winit::window::{WindowId, WindowLevel}, }; #[allow(clippy::large_enum_variant)] @@ -50,6 +50,9 @@ pub(crate) enum Message { /// Request window position. WindowPositionRequest(WindowId, Point), + /// Request window level. + WindowLevelRequest(WindowId, WindowLevel), + /// Sub window calling response. WindowResponse( WindowId, @@ -123,6 +126,11 @@ impl Debug for Message { .field(arg0) .field(arg1) .finish(), + Self::WindowLevelRequest(arg0, arg1) => f + .debug_tuple("WindowLevelRequest") + .field(arg0) + .field(arg1) + .finish(), Self::WindowResponse(arg0, _) => f.debug_tuple("WindowResponse").field(arg0).finish(), Self::WindowMoved(arg0, arg1) => f .debug_tuple("WindowMoved") diff --git a/tmui/src/runtime/windows_process.rs b/tmui/src/runtime/windows_process.rs index 5eff1ec..f24dc7d 100644 --- a/tmui/src/runtime/windows_process.rs +++ b/tmui/src/runtime/windows_process.rs @@ -648,6 +648,13 @@ impl<'a, T: 'static + Copy + Send + Sync, M: 'static + Copy + Send + Sync> window.winit_window().set_outer_position(PhysicalPosition::new(pos.x(), pos.y())); } + Message::WindowLevelRequest(window_id, level) => { + let window = self.windows.get(&window_id.into()).unwrap_or_else(|| { + panic!("Can not find window with id {:?}", window_id) + }); + window.winit_window().set_window_level(level); + } + Message::WindowResponse(window_id, closure) => { let window = self.windows.get(&window_id.into()).unwrap_or_else(|| { panic!("Can not find window with id {:?}", window_id)