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:
@@ -1,6 +1,7 @@
|
|||||||
import { errorHandler } from 'src/lib/utils';
|
import { errorHandler } from 'src/lib/utils';
|
||||||
import { Command } from '../../types';
|
import { Command } from '../../types';
|
||||||
import { App } from 'astal/gtk3';
|
import { App } from 'astal/gtk3';
|
||||||
|
import { BarVisibility } from 'src/cli/utils/BarVisibility';
|
||||||
|
|
||||||
export const windowManagementCommands: Command[] = [
|
export const windowManagementCommands: Command[] = [
|
||||||
{
|
{
|
||||||
@@ -46,6 +47,8 @@ export const windowManagementCommands: Command[] = [
|
|||||||
|
|
||||||
App.toggle_window(windowName);
|
App.toggle_window(windowName);
|
||||||
|
|
||||||
|
BarVisibility.set(windowName, windowStatus === 'visible');
|
||||||
|
|
||||||
return windowStatus;
|
return windowStatus;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorHandler(error);
|
errorHandler(error);
|
||||||
|
|||||||
13
src/cli/utils/BarVisibility.ts
Normal file
13
src/cli/utils/BarVisibility.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { BarToggleStates } from 'src/lib/types/cli';
|
||||||
|
|
||||||
|
export class BarVisibility {
|
||||||
|
private static _toggleStates: BarToggleStates = {};
|
||||||
|
|
||||||
|
public static get(barName: string): boolean {
|
||||||
|
return this._toggleStates[barName] ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static set(barName: string, isVisible: boolean): void {
|
||||||
|
this._toggleStates[barName] = isVisible;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@ export const Cava = (): BarBoxChild => {
|
|||||||
return blockCharacters[Math.min(index, blockCharacters.length - 1)];
|
return blockCharacters[Math.min(index, blockCharacters.length - 1)];
|
||||||
})
|
})
|
||||||
.join(spacing);
|
.join(spacing);
|
||||||
|
|
||||||
return valueMap;
|
return valueMap;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,50 +1,109 @@
|
|||||||
import { bind, Variable } from 'astal';
|
import { bind, Variable } from 'astal';
|
||||||
import { App } from 'astal/gtk3';
|
import { App } from 'astal/gtk3';
|
||||||
import AstalHyprland from 'gi://AstalHyprland?version=0.1';
|
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 { forceUpdater } from 'src/components/bar/modules/workspaces/helpers';
|
||||||
import options from 'src/options';
|
import options from 'src/options';
|
||||||
|
|
||||||
const hyprlandService = AstalHyprland.get_default();
|
const hyprlandService = AstalHyprland.get_default();
|
||||||
const { autoHide } = options.bar;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fullscreenBinding = bind(client, 'fullscreen');
|
||||||
|
|
||||||
Variable.derive([bind(fullscreenBinding)], (isFullScreen) => {
|
Variable.derive([bind(fullscreenBinding)], (isFullScreen) => {
|
||||||
if (autoHide.get() === 'fullscreen') {
|
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) => {
|
* Shows bars on all monitors
|
||||||
if (shouldAutohide === 'never') {
|
*/
|
||||||
hyprlandService.get_monitors().forEach((monitor) => {
|
function showAllBars(): void {
|
||||||
App.get_window(`bar-${monitor.id}`)?.set_visible(true);
|
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') {
|
* Updates bar visibility based on workspace window count
|
||||||
App.get_window(`bar-${workspace.monitor.id}`)?.set_visible(workspace.get_clients().length !== 1);
|
*/
|
||||||
|
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) => {
|
Variable.derive([bind(hyprlandService, 'focusedClient')], (currentClient) => {
|
||||||
focusedClient(currentClient);
|
handleFullscreenClientVisibility(currentClient);
|
||||||
});
|
});
|
||||||
|
|
||||||
Variable.derive([bind(autoHide)], (shouldAutohide) => {
|
Variable.derive([bind(autoHide)], (hideMode) => {
|
||||||
if (shouldAutohide === 'fullscreen') {
|
if (hideMode === 'fullscreen') {
|
||||||
hyprlandService.get_workspaces().forEach((workspace) => {
|
updateBarVisibilityByFullscreen();
|
||||||
App.get_window(`bar-${workspace.monitor.id}`)?.set_visible(!workspace.hasFullscreen);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|||||||
1
src/lib/types/cli.d.ts
vendored
Normal file
1
src/lib/types/cli.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export type BarToggleStates = Record<string, boolean | undefined>;
|
||||||
Reference in New Issue
Block a user