Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions examples/win_level_request/main.rs
Original file line number Diff line number Diff line change
@@ -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));
}
14 changes: 12 additions & 2 deletions tmui/src/application_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -307,7 +307,7 @@ impl ApplicationWindow {
}

#[inline]
pub fn register_run_after<R: 'static + FnOnce(&mut Self) + Send>(&mut self, run_after: R) {
pub fn register_run_after<R: 'static + FnOnce(&mut Self)>(&mut self, run_after: R) {
self.run_after = Some(Box::new(run_after));
}

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion tmui/src/primitive/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tlib::{
object::ObjectId,
payload::PayloadWeight,
prelude::SystemCursorShape,
winit::window::WindowId,
winit::window::{WindowId, WindowLevel},
};

#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions tmui/src/runtime/windows_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down