2023-10-31 08:32:40 -04:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-31 08:32:40 -04:00
|
|
|
import { Box } from 'resource:///com/github/Aylur/ags/widget.js';
|
2024-01-13 23:38:31 -05:00
|
|
|
import * as VARS from './variables.ts';
|
2023-10-30 22:00:46 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const PADDING = 34;
|
|
|
|
const MARGIN = 9;
|
2023-10-30 22:00:46 -04:00
|
|
|
const DEFAULT_STYLE = `
|
|
|
|
min-width: ${VARS.SCREEN.X * VARS.SCALE}px;
|
2023-11-21 01:29:46 -05:00
|
|
|
min-height: ${(VARS.SCREEN.Y * VARS.SCALE) - (VARS.MARGIN / 2)}px;
|
2023-10-30 22:00:46 -04:00
|
|
|
border-radius: 10px;
|
|
|
|
`;
|
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
// Types
|
2024-01-13 23:38:31 -05:00
|
|
|
import AgsBox from 'types/widgets/box.ts';
|
|
|
|
import AgsRevealer from 'types/widgets/revealer.ts';
|
|
|
|
import AgsCenterBox from 'types/widgets/centerbox.ts';
|
|
|
|
import AgsEventBox from 'types/widgets/eventbox.ts';
|
2023-12-23 01:14:21 -05:00
|
|
|
|
2023-10-30 22:00:46 -04:00
|
|
|
|
|
|
|
export const Highlighter = () => Box({
|
2023-11-07 10:56:12 -05:00
|
|
|
vpack: 'start',
|
|
|
|
hpack: 'start',
|
2023-12-23 01:14:21 -05:00
|
|
|
class_name: 'workspace active',
|
2023-11-07 10:56:12 -05:00
|
|
|
css: DEFAULT_STYLE,
|
2023-10-30 22:00:46 -04:00
|
|
|
});
|
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
export const updateCurrentWorkspace = (main: AgsBox, highlighter: AgsBox) => {
|
2023-10-30 22:00:46 -04:00
|
|
|
const currentId = Hyprland.active.workspace.id;
|
|
|
|
const row = Math.floor((currentId - 1) / VARS.WORKSPACE_PER_ROW);
|
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
const rowObject = (main.children[0] as AgsBox).children[row] as AgsRevealer;
|
|
|
|
const workspaces = ((((rowObject.child as AgsCenterBox)
|
|
|
|
.center_widget as AgsEventBox)
|
|
|
|
.child as AgsBox)
|
|
|
|
.get_children() as Array<AgsRevealer>)
|
|
|
|
.filter((w) => w.reveal_child);
|
2023-12-23 01:14:21 -05:00
|
|
|
|
|
|
|
const currentIndex = workspaces.findIndex(
|
|
|
|
(w) => w.attribute.id === currentId,
|
|
|
|
);
|
2024-01-15 16:04:09 -05:00
|
|
|
const left = currentIndex * ((VARS.SCREEN.X * VARS.SCALE) + 2 + PADDING);
|
2023-11-21 01:29:46 -05:00
|
|
|
const height = row * ((VARS.SCREEN.Y * VARS.SCALE) + (PADDING / 2));
|
2023-10-30 22:00:46 -04:00
|
|
|
|
2023-11-07 12:31:39 -05:00
|
|
|
highlighter.setCss(`
|
2023-10-30 22:00:46 -04:00
|
|
|
${DEFAULT_STYLE}
|
2023-11-21 01:29:46 -05:00
|
|
|
margin-left: ${MARGIN + left}px;
|
|
|
|
margin-top: ${MARGIN + height}px;
|
2023-10-30 22:00:46 -04:00
|
|
|
`);
|
|
|
|
};
|