diff --git a/.config/ags/scripts/sway/swayToRelativeWs.sh b/.config/ags/scripts/sway/swayToRelativeWs.sh new file mode 100755 index 00000000..d4800190 --- /dev/null +++ b/.config/ags/scripts/sway/swayToRelativeWs.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# Get the current workspace number +current=$(swaymsg -t get_workspaces | gojq '.[] | select(.focused==true) | .num') + +# Check if a number was passed as an argument +if [[ "$1" =~ ^[+-]?[0-9]+$ ]]; then + new_workspace=$((current + $1)) +else + new_workspace=$((current + 1)) +fi + +# Check if the new workspace number is out of bounds +if [[ $new_workspace -lt 1 ]]; then + exit 0 +fi + +# Switch to the new workspace +swaymsg workspace $new_workspace \ No newline at end of file diff --git a/.config/ags/widgets/bar/music.js b/.config/ags/widgets/bar/music.js index 7d9116ab..7bcfcd10 100644 --- a/.config/ags/widgets/bar/music.js +++ b/.config/ags/widgets/bar/music.js @@ -32,12 +32,12 @@ const TrackProgress = () => { }) } -const moveToRelativeWorkspace = async (self, num) => { +const switchToRelativeWorkspace = async (self, num) => { try { const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default; Hyprland.sendMessage(`dispatch workspace ${num > 0 ? '+' : ''}${num}`); } catch { - console.log(`TODO: Sway workspace ${num > 0 ? '+' : ''}${num}`); + execAsync([`${App.configDir}/scripts/sway/swayToRelativeWs.sh`, `${num}`]).catch(print); } } @@ -85,8 +85,8 @@ export default () => { }) }) return Widget.EventBox({ - onScrollUp: (self) => moveToRelativeWorkspace(self, -1), - onScrollDown: (self) => moveToRelativeWorkspace(self, +1), + onScrollUp: (self) => switchToRelativeWorkspace(self, -1), + onScrollDown: (self) => switchToRelativeWorkspace(self, +1), onPrimaryClickRelease: () => showMusicControls.setValue(!showMusicControls.value), onSecondaryClickRelease: () => execAsync(['bash', '-c', 'playerctl next || playerctl position `bc <<< "100 * $(playerctl metadata mpris:length) / 1000000 / 100"` &']), onMiddleClickRelease: () => execAsync('playerctl play-pause').catch(print), diff --git a/.config/ags/widgets/bar/system.js b/.config/ags/widgets/bar/system.js index 71b6daee..4358c80c 100644 --- a/.config/ags/widgets/bar/system.js +++ b/.config/ags/widgets/bar/system.js @@ -167,18 +167,18 @@ const BarGroup = ({ child }) => Widget.Box({ ] }); -const moveToRelativeWorkspace = async (self, num) => { +const switchToRelativeWorkspace = async (self, num) => { try { const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default; Hyprland.sendMessage(`dispatch workspace ${num > 0 ? '+' : ''}${num}`); } catch { - console.log(`TODO: Sway workspace ${num > 0 ? '+' : ''}${num}`); + execAsync([`${App.configDir}/scripts/sway/swayToRelativeWs.sh`, `${num}`]).catch(print); } } export default () => Widget.EventBox({ - onScrollUp: (self) => moveToRelativeWorkspace(self, -1), - onScrollDown: (self) => moveToRelativeWorkspace(self, +1), + onScrollUp: (self) => switchToRelativeWorkspace(self, -1), + onScrollDown: (self) => switchToRelativeWorkspace(self, +1), onPrimaryClick: () => App.toggleWindow('sideright'), child: Widget.Box({ className: 'spacing-h-5',