Fixed an issue that would cause a hidden bar to unhide when a workspace changed. (#771)

* Fixed an issue that would cause a hidden bar to unhide when a workspace is changed.

* Remove jsdoc for param that doesn't exist.
This commit is contained in:
Jas Singh
2025-02-15 00:01:51 -08:00
committed by GitHub
parent 4424a523bf
commit c309a73d2d
5 changed files with 100 additions and 23 deletions

View File

@@ -1,50 +1,109 @@
import { bind, Variable } from 'astal';
import { App } from 'astal/gtk3';
import AstalHyprland from 'gi://AstalHyprland?version=0.1';
import { BarVisibility } from 'src/cli/utils/BarVisibility';
import { forceUpdater } from 'src/components/bar/modules/workspaces/helpers';
import options from 'src/options';
const hyprlandService = AstalHyprland.get_default();
const { autoHide } = options.bar;
const focusedClient = (focusedClient: AstalHyprland.Client): void => {
const fullscreenBinding = bind(focusedClient, 'fullscreen');
/**
* Sets bar visibility for a specific monitor
*
* @param monitorId - The ID of the monitor
* @param isVisible - Whether the bar should be visible
*/
function setBarVisibility(monitorId: number, isVisible: boolean): void {
const barName = `bar-${monitorId}`;
if (!focusedClient) {
if (BarVisibility.get(barName)) {
App.get_window(barName)?.set_visible(isVisible);
}
}
/**
* Handles bar visibility when a client's fullscreen state changes
*
* @param client - The Hyprland client that gained focus
*/
function handleFullscreenClientVisibility(client: AstalHyprland.Client): void {
if (!client) {
return;
}
const fullscreenBinding = bind(client, 'fullscreen');
Variable.derive([bind(fullscreenBinding)], (isFullScreen) => {
if (autoHide.get() === 'fullscreen') {
App.get_window(`bar-${focusedClient.monitor.id}`)?.set_visible(!isFullScreen);
setBarVisibility(client.monitor.id, !isFullScreen);
}
});
};
}
export const initializeAutoHide = (): void => {
Variable.derive([bind(autoHide), bind(forceUpdater), bind(hyprlandService, 'workspaces')], (shouldAutohide) => {
if (shouldAutohide === 'never') {
hyprlandService.get_monitors().forEach((monitor) => {
App.get_window(`bar-${monitor.id}`)?.set_visible(true);
});
/**
* Shows bars on all monitors
*/
function showAllBars(): void {
const monitors = hyprlandService.get_monitors();
monitors.forEach((monitor) => {
if (BarVisibility.get(`bar-${monitor.id}`)) {
setBarVisibility(monitor.id, true);
}
});
}
hyprlandService.get_workspaces().map((workspace) => {
if (autoHide.get() === 'single-window') {
App.get_window(`bar-${workspace.monitor.id}`)?.set_visible(workspace.get_clients().length !== 1);
/**
* Updates bar visibility based on workspace window count
*/
function updateBarVisibilityByWindowCount(): void {
const monitors = hyprlandService.get_monitors();
const activeWorkspaces = monitors.map((monitor) => monitor.active_workspace);
activeWorkspaces.forEach((workspace) => {
const hasOneClient = workspace.get_clients().length !== 1;
setBarVisibility(workspace.monitor.id, hasOneClient);
});
}
/**
* Updates bar visibility based on workspace fullscreen state
*/
function updateBarVisibilityByFullscreen(): void {
hyprlandService.get_workspaces().forEach((workspace) => {
setBarVisibility(workspace.monitor.id, !workspace.hasFullscreen);
});
}
/**
* Initializes the auto-hide behavior for bars
* Manages visibility based on window count, fullscreen state, and user preferences
*/
export function initializeAutoHide(): void {
Variable.derive(
[
bind(autoHide),
bind(hyprlandService, 'workspaces'),
bind(forceUpdater),
bind(hyprlandService, 'focusedWorkspace'),
],
(hideMode) => {
if (hideMode === 'never') {
showAllBars();
} else if (hideMode === 'single-window') {
updateBarVisibilityByWindowCount();
}
});
});
},
);
Variable.derive([bind(hyprlandService, 'focusedClient')], (currentClient) => {
focusedClient(currentClient);
handleFullscreenClientVisibility(currentClient);
});
Variable.derive([bind(autoHide)], (shouldAutohide) => {
if (shouldAutohide === 'fullscreen') {
hyprlandService.get_workspaces().forEach((workspace) => {
App.get_window(`bar-${workspace.monitor.id}`)?.set_visible(!workspace.hasFullscreen);
});
Variable.derive([bind(autoHide)], (hideMode) => {
if (hideMode === 'fullscreen') {
updateBarVisibilityByFullscreen();
}
});
};
}

1
src/lib/types/cli.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
export type BarToggleStates = Record<string, boolean | undefined>;