feat(settings): add system title bar toggle
Add option to use OS native window decorations instead of the custom QBZ title bar. Uses Tauri setDecorations() API to toggle at runtime. Disables "Hide title bar" toggle when system bar is active.
This commit is contained in:
1 parent
be5a80a381
commit
7b5bd166d4
6 files changed
+69
-7
No files matched your search
@@ -5,12 +5,17 @@
|
||||
*
|
||||
* Settings:
|
||||
* - hideTitleBar: Remove title bar completely for tiling WM users (default: false)
|
||||
* - useSystemTitleBar: Use OS native window decorations instead of custom title bar (default: false)
|
||||
*/
|
||||
|
||||
import { getCurrentWindow } from '@tauri-apps/api/window';
|
||||
|
||||
const STORAGE_KEY_HIDE = 'qbz-hide-titlebar';
|
||||
const STORAGE_KEY_SYSTEM = 'qbz-use-system-titlebar';
|
||||
|
||||
// State
|
||||
let hideTitleBar = false;
|
||||
let useSystemTitleBar = false;
|
||||
|
||||
// Listeners
|
||||
const listeners = new Set<() => void>();
|
||||
@@ -30,6 +35,17 @@ export function initTitleBarStore(): void {
|
||||
if (savedHide !== null) {
|
||||
hideTitleBar = savedHide === 'true';
|
||||
}
|
||||
|
||||
const savedSystem = localStorage.getItem(STORAGE_KEY_SYSTEM);
|
||||
if (savedSystem !== null) {
|
||||
useSystemTitleBar = savedSystem === 'true';
|
||||
}
|
||||
|
||||
if (useSystemTitleBar) {
|
||||
getCurrentWindow().setDecorations(true).catch((e) => {
|
||||
console.error('[TitleBarStore] Failed to enable system decorations:', e);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[TitleBarStore] Failed to initialize:', e);
|
||||
}
|
||||
@@ -45,25 +61,33 @@ export function subscribe(listener: () => void): () => void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current setting
|
||||
* Get current hide setting
|
||||
*/
|
||||
export function getHideTitleBar(): boolean {
|
||||
return hideTitleBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the title bar should be visible
|
||||
* Get current system title bar setting
|
||||
*/
|
||||
export function getUseSystemTitleBar(): boolean {
|
||||
return useSystemTitleBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the custom title bar should be visible
|
||||
* Hidden when either system title bar is active or hide mode is on
|
||||
*/
|
||||
export function shouldShowTitleBar(): boolean {
|
||||
return !hideTitleBar;
|
||||
return !hideTitleBar && !useSystemTitleBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title bar height for layout calculations
|
||||
* Returns 0 if title bar is hidden, 32 otherwise
|
||||
* Returns 0 if title bar is hidden or system title bar is active, 32 otherwise
|
||||
*/
|
||||
export function getTitleBarHeight(): number {
|
||||
return hideTitleBar ? 0 : 32;
|
||||
return (hideTitleBar || useSystemTitleBar) ? 0 : 32;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,8 +103,26 @@ export function setHideTitleBar(value: boolean): void {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to use system (OS native) title bar
|
||||
* Toggles Tauri window decorations and hides the custom title bar
|
||||
*/
|
||||
export function setUseSystemTitleBar(value: boolean): void {
|
||||
useSystemTitleBar = value;
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY_SYSTEM, String(value));
|
||||
} catch (e) {
|
||||
console.error('[TitleBarStore] Failed to save system titlebar setting:', e);
|
||||
}
|
||||
getCurrentWindow().setDecorations(value).catch((e) => {
|
||||
console.error('[TitleBarStore] Failed to set window decorations:', e);
|
||||
});
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
export interface TitleBarState {
|
||||
hideTitleBar: boolean;
|
||||
useSystemTitleBar: boolean;
|
||||
showTitleBar: boolean;
|
||||
titleBarHeight: number;
|
||||
}
|
||||
@@ -88,6 +130,7 @@ export interface TitleBarState {
|
||||
export function getTitleBarState(): TitleBarState {
|
||||
return {
|
||||
hideTitleBar,
|
||||
useSystemTitleBar,
|
||||
showTitleBar: shouldShowTitleBar(),
|
||||
titleBarHeight: getTitleBarHeight()
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user