Skip to content

Commit

Permalink
Merge branch 'dev' into feat/wayland-display
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Sep 26, 2024
2 parents 40e6c79 + 2ee007a commit d74b870
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/is-always-on-top.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Add `Window::is_always_on_top` method to check if a window is always on top on macOS, Linux and Windows.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## \[0.30.2]

- [`016e122c`](https://github.com/tauri-apps/tao/commit/016e122c5f10eb61f8abe052a888950a460e0804) ([#978](https://github.com/tauri-apps/tao/pull/978) by [@Legend-Master](https://github.com/tauri-apps/tao/../../Legend-Master)) Fix changing the theme activates the window on Windows

## \[0.30.1]

- [`ad652e50`](https://github.com/tauri-apps/tao/commit/ad652e50bfca1195481cd347ccaa486818f9334d) ([#969](https://github.com/tauri-apps/tao/pull/969) by [@CampioneDev](https://github.com/tauri-apps/tao/../../CampioneDev)) On iOS, implement `application:openURL:options:` to handle custom URL schemes.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tao"
version = "0.30.1"
version = "0.30.2"
description = "Cross-platform window manager library."
authors = [
"Tauri Programme within The Commons Conservancy",
Expand Down
5 changes: 5 additions & 0 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ impl Window {
false
}

pub fn is_always_on_top(&self) -> bool {
log::warn!("`Window::is_always_on_top` is ignored on Android");
false
}

pub fn set_resizable(&self, _resizeable: bool) {
warn!("`Window::set_resizable` is ignored on Android")
}
Expand Down
5 changes: 5 additions & 0 deletions src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ impl Inner {
false
}

pub fn is_always_on_top(&self) -> bool {
log::warn!("`Window::is_always_on_top` is ignored on iOS");
false
}

pub fn request_redraw(&self) {
unsafe {
if self.gl_or_metal_backed {
Expand Down
13 changes: 13 additions & 0 deletions src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct Window {
position: Rc<(AtomicI32, AtomicI32)>,
size: Rc<(AtomicI32, AtomicI32)>,
maximized: Rc<AtomicBool>,
is_always_on_top: Rc<AtomicBool>,
minimized: Rc<AtomicBool>,
fullscreen: RefCell<Option<Fullscreen>>,
inner_size_constraints: RefCell<WindowSizeConstraints>,
Expand Down Expand Up @@ -266,11 +267,14 @@ impl Window {
let max_clone = maximized.clone();
let minimized = Rc::new(AtomicBool::new(false));
let minimized_clone = minimized.clone();
let is_always_on_top = Rc::new(AtomicBool::new(attributes.always_on_top));
let is_always_on_top_clone = is_always_on_top.clone();

window.connect_window_state_event(move |_, event| {
let state = event.new_window_state();
max_clone.store(state.contains(WindowState::MAXIMIZED), Ordering::Release);
minimized_clone.store(state.contains(WindowState::ICONIFIED), Ordering::Release);
is_always_on_top_clone.store(state.contains(WindowState::ABOVE), Ordering::Release);
glib::Propagation::Proceed
});

Expand Down Expand Up @@ -312,6 +316,7 @@ impl Window {
size,
maximized,
minimized,
is_always_on_top,
fullscreen: RefCell::new(attributes.fullscreen),
inner_size_constraints: RefCell::new(attributes.inner_size_constraints),
preferred_theme: RefCell::new(preferred_theme),
Expand Down Expand Up @@ -362,11 +367,14 @@ impl Window {
let max_clone = maximized.clone();
let minimized = Rc::new(AtomicBool::new(false));
let minimized_clone = minimized.clone();
let is_always_on_top = Rc::new(AtomicBool::new(false));
let is_always_on_top_clone = is_always_on_top.clone();

window.connect_window_state_event(move |_, event| {
let state = event.new_window_state();
max_clone.store(state.contains(WindowState::MAXIMIZED), Ordering::Release);
minimized_clone.store(state.contains(WindowState::ICONIFIED), Ordering::Release);
is_always_on_top_clone.store(state.contains(WindowState::ABOVE), Ordering::Release);
glib::Propagation::Proceed
});

Expand All @@ -391,6 +399,7 @@ impl Window {
size,
maximized,
minimized,
is_always_on_top,
fullscreen: RefCell::new(None),
inner_size_constraints: RefCell::new(WindowSizeConstraints::default()),
preferred_theme: RefCell::new(None),
Expand Down Expand Up @@ -587,6 +596,10 @@ impl Window {
}
}

pub fn is_always_on_top(&self) -> bool {
self.is_always_on_top.load(Ordering::Acquire)
}

pub fn is_maximized(&self) -> bool {
self.maximized.load(Ordering::Acquire)
}
Expand Down
5 changes: 5 additions & 0 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,11 @@ impl UnownedWindow {
is_visible == YES
}

#[inline]
pub fn is_always_on_top(&self) -> bool {
unsafe { self.ns_window.level() == ffi::kCGFloatingWindowLevelKey }
}

#[inline]
pub fn is_maximized(&self) -> bool {
self.is_zoomed()
Expand Down
11 changes: 8 additions & 3 deletions src/platform_impl/windows/dark_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use windows::{
Foundation::{BOOL, HANDLE, HMODULE, HWND, WPARAM},
Graphics::Dwm::{DwmSetWindowAttribute, DWMWINDOWATTRIBUTE},
System::LibraryLoader::*,
UI::{Accessibility::*, WindowsAndMessaging::*},
UI::{Accessibility::*, Input::KeyboardAndMouse::GetActiveWindow, WindowsAndMessaging::*},
},
};

Expand Down Expand Up @@ -187,9 +187,14 @@ fn refresh_titlebar_theme_color(hwnd: HWND, is_dark_mode: bool) {
&dark_mode as *const BOOL as *const c_void,
std::mem::size_of::<BOOL>() as u32,
);
if GetActiveWindow() == hwnd {
DefWindowProcW(hwnd, WM_NCACTIVATE, None, None);
DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None);
} else {
DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None);
DefWindowProcW(hwnd, WM_NCACTIVATE, None, None);
}
}
unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, None, None) };
unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None) };
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,14 @@ impl Window {
window_state.window_flags.contains(WindowFlags::MAXIMIZED)
}

#[inline]
pub fn is_always_on_top(&self) -> bool {
let window_state = self.window_state.lock();
window_state
.window_flags
.contains(WindowFlags::ALWAYS_ON_TOP)
}

#[inline]
pub fn is_minimized(&self) -> bool {
unsafe { IsIconic(self.hwnd()) }.as_bool()
Expand Down
10 changes: 10 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,16 @@ impl Window {
self.window.is_focused()
}

/// Indicates whether the window is always on top of other windows.
///
/// ## Platform-specific
///
/// - **iOS / Android:** Unsupported.
#[inline]
pub fn is_always_on_top(&self) -> bool {
self.window.is_always_on_top()
}

/// Sets whether the window is resizable or not.
///
/// Note that making the window unresizable doesn't exempt you from handling `Resized`, as that event can still be
Expand Down

0 comments on commit d74b870

Please sign in to comment.