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:
retrozinndev
2025-05-13 15:06:14 -03:00
parent cfacd675e3
commit 88129a8f97
3 changed files with 76 additions and 61 deletions
+27 -25
View File
@@ -2,10 +2,11 @@ import { Wireplumber } from "./volume";
import { Windows } from "../windows"; import { Windows } from "../windows";
import { restartInstance } from "./reload-handler"; import { restartInstance } from "./reload-handler";
import { showWorkspaceNumbers } from "../widget/bar/Workspaces"; import { AstalIO, timeout } from "astal";
import { timeout } from "astal";
import { Runner } from "../runner/Runner"; import { Runner } from "../runner/Runner";
import { showWorkspaceNumber } from "../widget/bar/Workspaces";
let wsTimeout: (AstalIO.Time|undefined);
export function handleArguments(request: string): any { export function handleArguments(request: string): any {
const args: Array<string> = request.split(" "); const args: Array<string> = request.split(" ");
@@ -36,12 +37,15 @@ export function handleArguments(request: string): any {
: Runner.close(); : Runner.close();
return "Opening runner..." return "Opening runner..."
case "show-ws-numbers": case "peek-workspace-num":
if(!showWorkspaceNumbers.get()) { if(wsTimeout) return "Workspace numbers are already showing";
showWorkspaceNumbers.set(true);
timeout(2200, () => showWorkspaceNumbers.set(false)); showWorkspaceNumber(true);
} wsTimeout = timeout(2200, () => {
return "Showing numbers"; showWorkspaceNumber(false);
wsTimeout = undefined;
});
return "Toggled workspace numbers";
default: default:
return "command not found! try checking help"; return "command not found! try checking help";
@@ -141,14 +145,10 @@ function handleVolumeArgs(args: Array<string>) {
return ` return `
Control speaker and microphone volumes easily! Control speaker and microphone volumes easily!
Options: Options:
sink-set [number]: set sink(speaker) volume with [number], 0 to ${Wireplumber.getDefault().getMaxSinkVolume() || 100}. (sink|source)-set [number]: set speaker/microphone volume.
sink-mute: toggle mute for the sink(speaker) device. (sink|source)-mute: toggle mute for the speaker/microphone device.
sink-increase [number]: increases sink(speaker) volume with [number]. (sink|source)-increase [number]: increases speaker/microphone volume.
sink-decrease [number]: decreases sink(speaker) volume with [number]. (sink|source)-decrease [number]: decreases speaker/microphone volume.
source-set [number]: set source(microphone) volume with [number], 0 to ${Wireplumber.getDefault().getMaxSourceVolume() || 100}.
source-mute: toggle mute for the source(microphone) device.
source-increase [number]: increases source(microphone) volume with [number].
source-decrease [number]: decreases source(microphone) volume with [number]
`.trim(); `.trim();
} }
} }
@@ -157,16 +157,18 @@ function getHelp(): string {
return `Manage Astal Windows and do more stuff. From return `Manage Astal Windows and do more stuff. From
retrozinndev's Hyprland Dots, using Astal and AGS by Aylur. retrozinndev's Hyprland Dots, using Astal and AGS by Aylur.
Options: Window and Audio options:
open [window_name]: sets specified window's visibility to true. open [window]: opens the specified window.
close [window_name]: sets specified window's visibility to false. close [window]: closes all instances of specified window.
toggle [window_name]: toggles visibility of specified window. toggle [window]: toggle-open/close the specified window.
windows: shows available windows to control. windows: list shell windows.
reload: creates a new astal instance and removes this one. reload: quit this instance and start a new one.
volume: wireplumber volume controller, see "volume help". volume: speaker and microphone volume controller, see "volume help".
runner [initial_text]: open the application runner.
show-ws-numbers: show or hide workspace numbers in bar.
h, help: shows this help message. h, help: shows this help message.
Other options:
runner [initial_text]: open the application runner, optionally add an initial search.
peek-workspace-num: peek the workspace numbers on bar window.
2025 (c) retrozinndev's Hyprland-Dots, licensed under the MIT License. 2025 (c) retrozinndev's Hyprland-Dots, licensed under the MIT License.
https://github.com/retrozinndev/Hyprland-Dots https://github.com/retrozinndev/Hyprland-Dots
+46 -34
View File
@@ -3,50 +3,62 @@ import { Gtk, Widget } from "astal/gtk3";
import AstalHyprland from "gi://AstalHyprland"; import AstalHyprland from "gi://AstalHyprland";
import { getAppIcon } from "../../scripts/apps"; import { getAppIcon } from "../../scripts/apps";
const hyprland = AstalHyprland.get_default(); let showWsNum: (Variable<boolean>|undefined);
export const showWorkspaceNumbers = new Variable<boolean>(false); export const showWorkspaceNumber = (show: boolean) =>
showWsNum?.set(show);
export function Workspaces(): Gtk.Widget { export function Workspaces(): Gtk.Widget {
showWsNum = new Variable<boolean>(false);
const workspaceSpacing = 4;
return new Widget.EventBox({ return new Widget.EventBox({
onScroll: (_, event) => onScroll: (_, event) =>
event.delta_y > 0 ? hyprland.dispatch("workspace", "e-1") : hyprland.dispatch("workspace", "e+1"), event.delta_y > 0 ?
onHover: () => showWorkspaceNumbers.set(true), AstalHyprland.get_default().dispatch("workspace", "e-1")
onHoverLost: () => showWorkspaceNumbers.set(false), : AstalHyprland.get_default().dispatch("workspace", "e+1"),
onHover: () => showWorkspaceNumber(true),
onHoverLost: () => showWorkspaceNumber(false),
onDestroy: () => {
showWsNum?.drop();
showWsNum = undefined;
},
child: new Widget.Box({ child: new Widget.Box({
className: "workspaces", className: "workspaces",
spacing: workspaceSpacing, spacing: 4,
children: bind(hyprland, "workspaces").as((workspaces) => { children: bind(AstalHyprland.get_default(), "workspaces").as((workspaces) =>
const sortedWorkspaces = workspaces.filter(ws => ws.id > 0).sort( workspaces.filter((ws) => ws.id > 0).sort((a, b) => a.id - b.id).map((workspace) => {
(a: AstalHyprland.Workspace, b: AstalHyprland.Workspace) => a.get_id() - b.get_id()); 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) => const tooltipText = Variable.derive([
new Widget.EventBox({ bind(workspace, "lastClient"),
className: Variable.derive([ bind(AstalHyprland.get_default(), "focusedWorkspace")
bind(hyprland, "focusedWorkspace"), ], (lastClient, focusWs) => focusWs.id === workspace.id ? "" :
showWorkspaceNumbers() `Workspace ${workspace.id}${ lastClient ? ` - ${
], (focusedWs, showWsNumbers) => !lastClient.title.toLowerCase().includes(lastClient.class) ?
`${focusedWs.id === workspace.id ? "focus" : ""} ${showWsNumbers ? "show" : ""}` `${lastClient.get_class()}: `
)(), : ""
} ${lastClient.title}` : "" }`
);
return new Widget.EventBox({
className: className(),
onClickRelease: () => workspace.focus(), onClickRelease: () => workspace.focus(),
tooltipText: Variable.derive([ tooltipText: tooltipText(),
bind(workspace, "lastClient"), onDestroy: () => {
bind(hyprland, "focusedWorkspace") className.drop();
], (lastClient, focusWs) => focusWs.id === workspace.id ? "" : tooltipText.drop();
`Workspace ${workspace.id}${ lastClient ? ` - ${ },
!lastClient.title.toLowerCase().includes(lastClient.class) ?
`${lastClient.get_class()}: `
: ""
} ${lastClient.title}` : "" }`
)(),
child: new Widget.Box({ child: new Widget.Box({
children: bind(workspace, "lastClient").as((lastClient) => [ children: bind(workspace, "lastClient").as((lastClient) => [
new Widget.Revealer({ new Widget.Revealer({
transitionDuration: 200, transitionDuration: 200,
transitionType: Gtk.RevealerTransitionType.SLIDE_LEFT, transitionType: Gtk.RevealerTransitionType.SLIDE_LEFT,
revealChild: showWorkspaceNumbers(), revealChild: showWsNum!(),
child: new Widget.Label({ child: new Widget.Label({
label: bind(workspace, "id").as(String), label: bind(workspace, "id").as(String),
className: "id", className: "id",
@@ -55,7 +67,7 @@ export function Workspaces(): Gtk.Widget {
} as Widget.RevealerProps), } as Widget.RevealerProps),
new Widget.Icon({ new Widget.Icon({
className: "last-app-icon", className: "last-app-icon",
visible: bind(hyprland, "focusedWorkspace").as(focusedWorkspace => visible: bind(AstalHyprland.get_default(), "focusedWorkspace").as(focusedWorkspace =>
workspace.id === focusedWorkspace.id ? workspace.id === focusedWorkspace.id ?
false false
: Boolean(lastClient)), : Boolean(lastClient)),
@@ -66,9 +78,9 @@ export function Workspaces(): Gtk.Widget {
} as Widget.IconProps) } as Widget.IconProps)
]) ])
} as Widget.BoxProps) } as Widget.BoxProps)
} as Widget.EventBoxProps) } as Widget.EventBoxProps);
) })
}) )
} as Widget.BoxProps) } as Widget.BoxProps)
} as Widget.EventBoxProps); } as Widget.EventBoxProps);
} }
+3 -2
View File
@@ -8,7 +8,7 @@ bind = $mainMod, F11, fullscreen
bind = , Print, exec, sh $XDG_CONFIG_HOME/hypr/scripts/screenshot.sh bind = , Print, exec, sh $XDG_CONFIG_HOME/hypr/scripts/screenshot.sh
bind = $mainMod, Print, exec, sh $XDG_CONFIG_HOME/hypr/scripts/screenshot.sh full bind = $mainMod, Print, exec, sh $XDG_CONFIG_HOME/hypr/scripts/screenshot.sh full
# Test-only bind, used by developer # Test-only bind, restarts colorshell
bind = $mainMod, F7, exec, ags request reload bind = $mainMod, F7, exec, ags request reload
bind = $mainMod, K, exec, $terminal bind = $mainMod, K, exec, $terminal
@@ -23,7 +23,8 @@ bind = $mainMod, L, exec, hyprlock
bind = $mainMod, V, exec, astal runner '>' || sh $XDG_CONFIG_HOME/hypr/scripts/clipboard-menu.sh bind = $mainMod, V, exec, astal runner '>' || sh $XDG_CONFIG_HOME/hypr/scripts/clipboard-menu.sh
bind = $mainMod, W, exec, astal runner '##' bind = $mainMod, W, exec, astal runner '##'
bind = $mainMod, $mainMod_L, exec, astal show-ws-numbers # bind = $mainMod, $mainMod_L, exec, astal toggle apps-window
bind = $mainMod, $mainMod_l, exec, astal peek-workspace-num
bind = , XF86AudioLowerVolume, exec, astal volume sink-decrease 5 || wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- # Decrease volume bind = , XF86AudioLowerVolume, exec, astal volume sink-decrease 5 || wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- # Decrease volume
bind = , XF86AudioRaiseVolume, exec, astal volume sink-increase 5 || wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ # Increase volume bind = , XF86AudioRaiseVolume, exec, astal volume sink-increase 5 || wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ # Increase volume