sway workspace switching

This commit is contained in:
end-4 2024-01-25 13:15:58 +07:00
parent 830f6a780d
commit f14d3146db
3 changed files with 27 additions and 8 deletions

View file

@ -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

View file

@ -32,12 +32,12 @@ const TrackProgress = () => {
}) })
} }
const moveToRelativeWorkspace = async (self, num) => { const switchToRelativeWorkspace = async (self, num) => {
try { try {
const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default; const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default;
Hyprland.sendMessage(`dispatch workspace ${num > 0 ? '+' : ''}${num}`); Hyprland.sendMessage(`dispatch workspace ${num > 0 ? '+' : ''}${num}`);
} catch { } 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({ return Widget.EventBox({
onScrollUp: (self) => moveToRelativeWorkspace(self, -1), onScrollUp: (self) => switchToRelativeWorkspace(self, -1),
onScrollDown: (self) => moveToRelativeWorkspace(self, +1), onScrollDown: (self) => switchToRelativeWorkspace(self, +1),
onPrimaryClickRelease: () => showMusicControls.setValue(!showMusicControls.value), onPrimaryClickRelease: () => showMusicControls.setValue(!showMusicControls.value),
onSecondaryClickRelease: () => execAsync(['bash', '-c', 'playerctl next || playerctl position `bc <<< "100 * $(playerctl metadata mpris:length) / 1000000 / 100"` &']), onSecondaryClickRelease: () => execAsync(['bash', '-c', 'playerctl next || playerctl position `bc <<< "100 * $(playerctl metadata mpris:length) / 1000000 / 100"` &']),
onMiddleClickRelease: () => execAsync('playerctl play-pause').catch(print), onMiddleClickRelease: () => execAsync('playerctl play-pause').catch(print),

View file

@ -167,18 +167,18 @@ const BarGroup = ({ child }) => Widget.Box({
] ]
}); });
const moveToRelativeWorkspace = async (self, num) => { const switchToRelativeWorkspace = async (self, num) => {
try { try {
const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default; const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default;
Hyprland.sendMessage(`dispatch workspace ${num > 0 ? '+' : ''}${num}`); Hyprland.sendMessage(`dispatch workspace ${num > 0 ? '+' : ''}${num}`);
} catch { } catch {
console.log(`TODO: Sway workspace ${num > 0 ? '+' : ''}${num}`); execAsync([`${App.configDir}/scripts/sway/swayToRelativeWs.sh`, `${num}`]).catch(print);
} }
} }
export default () => Widget.EventBox({ export default () => Widget.EventBox({
onScrollUp: (self) => moveToRelativeWorkspace(self, -1), onScrollUp: (self) => switchToRelativeWorkspace(self, -1),
onScrollDown: (self) => moveToRelativeWorkspace(self, +1), onScrollDown: (self) => switchToRelativeWorkspace(self, +1),
onPrimaryClick: () => App.toggleWindow('sideright'), onPrimaryClick: () => App.toggleWindow('sideright'),
child: Widget.Box({ child: Widget.Box({
className: 'spacing-h-5', className: 'spacing-h-5',