Files
custum-hyprpanel/src/components/bar/utils/monitors.ts
Jas Singh b6b58edf76 Fix: Improved GDK to Hyprland monitor mapping logic. (#867)
* Feat: Improved GDK<->Hyprland monitor mapping logic.

* Update src/components/bar/utils/GdkMonitorMapper.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix type issue.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-03-28 01:52:25 -07:00

42 lines
1.5 KiB
TypeScript

import { BarLayout, BarLayouts } from 'src/lib/types/options';
/**
* Returns the bar layout configuration for a specific monitor
*
* @param monitor - Monitor ID number
* @param layouts - Object containing layout configurations for different monitors
* @returns BarLayout configuration for the specified monitor, falling back to default if not found
*/
export const getLayoutForMonitor = (monitor: number, layouts: BarLayouts): BarLayout => {
const matchingKey = Object.keys(layouts).find((key) => key === monitor.toString());
const wildcard = Object.keys(layouts).find((key) => key === '*');
if (matchingKey) {
return layouts[matchingKey];
}
if (wildcard) {
return layouts[wildcard];
}
return {
left: ['dashboard', 'workspaces', 'windowtitle'],
middle: ['media'],
right: ['volume', 'network', 'bluetooth', 'battery', 'systray', 'clock', 'notifications'],
};
};
/**
* Checks if a bar layout configuration is empty
*
* @param layout - Bar layout configuration to check
* @returns boolean indicating if all sections of the layout are empty
*/
export const isLayoutEmpty = (layout: BarLayout): boolean => {
const isLeftSectionEmpty = !Array.isArray(layout.left) || layout.left.length === 0;
const isRightSectionEmpty = !Array.isArray(layout.right) || layout.right.length === 0;
const isMiddleSectionEmpty = !Array.isArray(layout.middle) || layout.middle.length === 0;
return isLeftSectionEmpty && isRightSectionEmpty && isMiddleSectionEmpty;
};