⚡ ags(workspaces, arg-handler): drop variable on ::destroy, better help messages
changed `show-ws-numbers` command to `peek-workspace-num`
This commit is contained in:
@@ -3,50 +3,62 @@ import { Gtk, Widget } from "astal/gtk3";
|
||||
import AstalHyprland from "gi://AstalHyprland";
|
||||
import { getAppIcon } from "../../scripts/apps";
|
||||
|
||||
const hyprland = AstalHyprland.get_default();
|
||||
export const showWorkspaceNumbers = new Variable<boolean>(false);
|
||||
let showWsNum: (Variable<boolean>|undefined);
|
||||
export const showWorkspaceNumber = (show: boolean) =>
|
||||
showWsNum?.set(show);
|
||||
|
||||
|
||||
export function Workspaces(): Gtk.Widget {
|
||||
|
||||
const workspaceSpacing = 4;
|
||||
showWsNum = new Variable<boolean>(false);
|
||||
|
||||
return new Widget.EventBox({
|
||||
onScroll: (_, event) =>
|
||||
event.delta_y > 0 ? hyprland.dispatch("workspace", "e-1") : hyprland.dispatch("workspace", "e+1"),
|
||||
onHover: () => showWorkspaceNumbers.set(true),
|
||||
onHoverLost: () => showWorkspaceNumbers.set(false),
|
||||
event.delta_y > 0 ?
|
||||
AstalHyprland.get_default().dispatch("workspace", "e-1")
|
||||
: AstalHyprland.get_default().dispatch("workspace", "e+1"),
|
||||
onHover: () => showWorkspaceNumber(true),
|
||||
onHoverLost: () => showWorkspaceNumber(false),
|
||||
onDestroy: () => {
|
||||
showWsNum?.drop();
|
||||
showWsNum = undefined;
|
||||
},
|
||||
child: new Widget.Box({
|
||||
className: "workspaces",
|
||||
spacing: workspaceSpacing,
|
||||
children: bind(hyprland, "workspaces").as((workspaces) => {
|
||||
const sortedWorkspaces = workspaces.filter(ws => ws.id > 0).sort(
|
||||
(a: AstalHyprland.Workspace, b: AstalHyprland.Workspace) => a.get_id() - b.get_id());
|
||||
spacing: 4,
|
||||
children: bind(AstalHyprland.get_default(), "workspaces").as((workspaces) =>
|
||||
workspaces.filter((ws) => ws.id > 0).sort((a, b) => a.id - b.id).map((workspace) => {
|
||||
const className = Variable.derive([
|
||||
bind(AstalHyprland.get_default(), "focusedWorkspace"),
|
||||
showWsNum!()
|
||||
], (focusedWs, showWsNumbers) =>
|
||||
`${focusedWs.id === workspace.id ? "focus" : ""} ${showWsNumbers ? "show" : ""}`
|
||||
);
|
||||
|
||||
return sortedWorkspaces.map((workspace: AstalHyprland.Workspace) =>
|
||||
new Widget.EventBox({
|
||||
className: Variable.derive([
|
||||
bind(hyprland, "focusedWorkspace"),
|
||||
showWorkspaceNumbers()
|
||||
], (focusedWs, showWsNumbers) =>
|
||||
`${focusedWs.id === workspace.id ? "focus" : ""} ${showWsNumbers ? "show" : ""}`
|
||||
)(),
|
||||
const tooltipText = Variable.derive([
|
||||
bind(workspace, "lastClient"),
|
||||
bind(AstalHyprland.get_default(), "focusedWorkspace")
|
||||
], (lastClient, focusWs) => focusWs.id === workspace.id ? "" :
|
||||
`Workspace ${workspace.id}${ lastClient ? ` - ${
|
||||
!lastClient.title.toLowerCase().includes(lastClient.class) ?
|
||||
`${lastClient.get_class()}: `
|
||||
: ""
|
||||
} ${lastClient.title}` : "" }`
|
||||
);
|
||||
|
||||
return new Widget.EventBox({
|
||||
className: className(),
|
||||
onClickRelease: () => workspace.focus(),
|
||||
tooltipText: Variable.derive([
|
||||
bind(workspace, "lastClient"),
|
||||
bind(hyprland, "focusedWorkspace")
|
||||
], (lastClient, focusWs) => focusWs.id === workspace.id ? "" :
|
||||
`Workspace ${workspace.id}${ lastClient ? ` - ${
|
||||
!lastClient.title.toLowerCase().includes(lastClient.class) ?
|
||||
`${lastClient.get_class()}: `
|
||||
: ""
|
||||
} ${lastClient.title}` : "" }`
|
||||
)(),
|
||||
tooltipText: tooltipText(),
|
||||
onDestroy: () => {
|
||||
className.drop();
|
||||
tooltipText.drop();
|
||||
},
|
||||
child: new Widget.Box({
|
||||
children: bind(workspace, "lastClient").as((lastClient) => [
|
||||
new Widget.Revealer({
|
||||
transitionDuration: 200,
|
||||
transitionType: Gtk.RevealerTransitionType.SLIDE_LEFT,
|
||||
revealChild: showWorkspaceNumbers(),
|
||||
revealChild: showWsNum!(),
|
||||
child: new Widget.Label({
|
||||
label: bind(workspace, "id").as(String),
|
||||
className: "id",
|
||||
@@ -55,7 +67,7 @@ export function Workspaces(): Gtk.Widget {
|
||||
} as Widget.RevealerProps),
|
||||
new Widget.Icon({
|
||||
className: "last-app-icon",
|
||||
visible: bind(hyprland, "focusedWorkspace").as(focusedWorkspace =>
|
||||
visible: bind(AstalHyprland.get_default(), "focusedWorkspace").as(focusedWorkspace =>
|
||||
workspace.id === focusedWorkspace.id ?
|
||||
false
|
||||
: Boolean(lastClient)),
|
||||
@@ -66,9 +78,9 @@ export function Workspaces(): Gtk.Widget {
|
||||
} as Widget.IconProps)
|
||||
])
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.EventBoxProps)
|
||||
)
|
||||
})
|
||||
} as Widget.EventBoxProps);
|
||||
})
|
||||
)
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.EventBoxProps);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user