fix(desktop): lock appbar to edge

This commit is contained in:
2026-07-25 20:14:58 +08:00
parent 1e1718caee
commit 81ffe64446
5 changed files with 13 additions and 118 deletions

View File

@@ -12,7 +12,7 @@ use windows::{
UI::{
Shell::{
DefSubclassProc, RemoveWindowSubclass, SHAppBarMessage, SetWindowSubclass,
ABE_LEFT, ABE_RIGHT, ABM_ACTIVATE, ABM_NEW, ABM_QUERYPOS, ABM_REMOVE, ABM_SETPOS,
ABE_RIGHT, ABM_ACTIVATE, ABM_NEW, ABM_QUERYPOS, ABM_REMOVE, ABM_SETPOS,
ABM_WINDOWPOSCHANGED, ABN_POSCHANGED, APPBARDATA,
},
WindowsAndMessaging::{
@@ -27,7 +27,6 @@ const SUBCLASS_ID: usize = 0x5341_4142; // "SAAB" (SenlinAI AppBar)
static CALLBACK_MESSAGE: AtomicU32 = AtomicU32::new(0);
static REGISTERED_HWND: AtomicIsize = AtomicIsize::new(0);
static EDGE: AtomicU32 = AtomicU32::new(ABE_RIGHT);
static LAYOUT_IN_PROGRESS: AtomicBool = AtomicBool::new(false);
/// Registers the main App window as a right-edge AppBar.
@@ -65,12 +64,6 @@ pub fn register(hwnd: HWND) -> Result<()> {
Ok(())
}
/// Repositions the AppBar after the App UI selects the left or right edge.
pub fn set_edge(hwnd: HWND, left: bool) -> Result<()> {
EDGE.store(if left { ABE_LEFT } else { ABE_RIGHT }, Ordering::Release);
layout(hwnd)
}
/// Removes the AppBar reservation before the Tauri window is destroyed.
pub fn unregister() {
let raw_hwnd = REGISTERED_HWND.swap(0, Ordering::AcqRel);
@@ -137,23 +130,14 @@ fn layout_inner(hwnd: HWND) -> Result<()> {
};
unsafe { GetMonitorInfoW(monitor, &mut monitor_info).ok()? };
let edge = EDGE.load(Ordering::Acquire);
let mut data = appbar_data(hwnd);
data.uEdge = edge;
data.uEdge = ABE_RIGHT;
data.rc = monitor_info.rcMonitor;
if edge == ABE_LEFT {
data.rc.right = data.rc.left + width;
} else {
data.rc.left = data.rc.right - width;
}
data.rc.left = data.rc.right - width;
unsafe {
SHAppBarMessage(ABM_QUERYPOS, &mut data);
if edge == ABE_LEFT {
data.rc.right = data.rc.left + width;
} else {
data.rc.left = data.rc.right - width;
}
data.rc.left = data.rc.right - width;
SHAppBarMessage(ABM_SETPOS, &mut data);
SetWindowPos(
hwnd,