import { Gtk } from "ags/gtk4"; import { getAppIcon, getSymbolicIcon } from "../../../modules/apps"; import { Separator } from "../../../widget/Separator"; import { generalConfig } from "../../../config"; import { createBinding, createComputed, createState, For, With } from "ags"; import { variableToBoolean } from "../../../modules/utils"; import AstalHyprland from "gi://AstalHyprland"; const [showNumbers, setShowNumbers] = createState(false); export const showWorkspaceNumber = (show: boolean) => setShowNumbers(show); export const Workspaces = () => { const workspaces = createBinding(AstalHyprland.get_default(), "workspaces"), defaultWorkspaces = workspaces.as(wss => wss.filter(ws => ws.id > 0).sort((a, b) => a.id - b.id)), specialWorkspaces = workspaces.as(wss => wss.filter(ws => ws.id < 0).sort((a, b) => a.id - b.id)), focusedWorkspace = createBinding(AstalHyprland.get_default(), "focusedWorkspace"); return wss.length <= 1), generalConfig.bindProperty("workspaces.hide_if_single", "boolean") ], (hideable, enabled) => enabled && hideable ? false : true )}> {(ws: AstalHyprland.Workspace) => { name = name.replace(/^special\:/, ""); return name.charAt(0).toUpperCase().concat(name.substring(1, name.length)); })} onClicked={() => AstalHyprland.get_default().dispatch( "togglespecialworkspace", ws.name.replace(/^special[:]/, "") )}> {(lastClient: AstalHyprland.Client|null) => lastClient && getSymbolicIcon(initialClass) ?? getAppIcon(initialClass) ?? "application-x-executable-symbolic")} /> } } self.set_flags(Gtk.EventControllerScrollFlags.VERTICAL)} onScroll={(_, __, dy) => { dy > 0 ? AstalHyprland.get_default().dispatch("workspace", "e-1") : AstalHyprland.get_default().dispatch("workspace", "e+1"); return true; }} /> setShowNumbers(true)} onLeave={() => setShowNumbers(false)} /> {(ws: AstalHyprland.Workspace, i) => { const showId = createComputed([ generalConfig.bindProperty("workspaces.always_show_id", "boolean").as(Boolean), generalConfig.bindProperty("workspaces.enable_helper", "boolean").as(Boolean), showNumbers, i ], (alwaysShowIds, enableHelper, showIds, i) => { if(enableHelper && !alwaysShowIds) { const previousWorkspace = defaultWorkspaces.get()[i-1]; const nextWorkspace = defaultWorkspaces.get()[i+1]; if((defaultWorkspaces.get().filter((_, ii) => ii < i).length > 0 && previousWorkspace?.id < (ws.id-1)) || (defaultWorkspaces.get().filter((_, ii) => ii > i).length > 0 && nextWorkspace?.id > (ws.id+1)) || (i === 0 && ws.id > 1)) { return true; } } return alwaysShowIds || showIds; }); return `workspace ${focusedWs.id === ws.id ? "focus" : ""} ${ showWsNumbers ? "show" : ""}` )} tooltipText={createComputed([ createBinding(ws, "lastClient"), createBinding(AstalHyprland.get_default(), "focusedWorkspace") ], (lastClient, focusWs) => focusWs.id === ws.id ? "" : `workspace ${ws.id}${ lastClient ? ` - ${ !lastClient.title.toLowerCase().includes(lastClient.class) ? `${lastClient.get_class()}: ` : "" } ${lastClient.title}` : "" }` )} onClicked={() => focusedWorkspace.get()?.id !== ws.id && ws.focus()}> {(lastClient: AstalHyprland.Client) => fws.id !== ws.id ? Gtk.RevealerTransitionType.SLIDE_LEFT : Gtk.RevealerTransitionType.SLIDE_RIGHT )}> {lastClient && getSymbolicIcon(initialClass) ?? getAppIcon(initialClass) ?? "application-x-executable-symbolic")} hexpand vexpand visible={createBinding(AstalHyprland.get_default(), "focusedWorkspace") .as(fws => fws.id !== ws.id)} />} } }} }