Skip to content

Commit af2b332

Browse files
committed
tolaria => [1 hypr][1 lua][3 spells]
1 parent 3b742fb commit af2b332

6 files changed

Lines changed: 179 additions & 87 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
- [add_rune](./spells/add_rune.spell) - Add a new [rune](runes-static-configuration-files) to the dotfiles, supports some customization options
88
- [allgst](./spells/allgst.spell) - Performs `git status` on every folder in the `cwd`.
9-
- [auto-start-steam](./spells/auto-start-steam.spell) - Auto starts steam if home assistant booted up the pc
109
- [battery_check](./spells/battery_check.spell) - Checks battery life and suspends if it's too low.
1110
- [bt-connect](./spells/bt-connect.spell)
1211
- [bulkrename](./spells/bulkrename.spell) - Bulk rename every file in the current directory using your default editor (Editor defined by $EDITOR or $VISUAL)
@@ -22,16 +21,17 @@
2221
- [k](./spells/k.spell) - Configure my keymap, I'm too lazy to configure X and udev
2322
- [lg-cast](./spells/lg-cast.spell) - Cast links from any pc to my tv
2423
- [make-magic-wall](./spells/make-magic-wall.spell) - make a small wallpaper big by surrouding with a solid color. Inspired by: https://github.com/chrisJuresh/paperWiz
24+
- [move-all-ws-to](./spells/move-all-ws-to.spell) - Moves all workspaces (except 10) to another monitor
2525
- [mtg-wallpapers](./spells/mtg-wallpapers.spell) - Downloads the last 6 wallpapers uploaded to https://magic.wizards.com/en/articles/media/wallpapers.
2626
- [new-rust-version](./spells/new-rust-version.spell)
2727
- [picker](./spells/picker.spell)
2828
- [playClipboard](./spells/playClipboard.spell) - Plays whatever is in the clipboard with xdg-open
2929
- [print](./spells/print.spell)
3030
- [projects](./spells/projects.spell) - Open dmenu, show me my projects, open a terminal in the selected one
3131
- [refresh_firefox](./spells/refresh_firefox.spell) - Refreshes firefox
32-
- [setup-remote-steam](./spells/setup-remote-steam.spell) - Starts steam and changes to a 16:9 resolution
3332
- [share](./spells/share.spell)
3433
- [ssh-menu](./spells/ssh-menu.spell) - A menu to quickly open ssh connections
34+
- [steamgr](./spells/steamgr.spell)
3535
- [syncspellbook](./spells/syncspellbook.spell) - Tries to synchronise with changes to the remote repository. Also runs [learnSpells](./learnSpells.sh) and [castRunes](./castRunes.sh)
3636
- [termFromHere](./spells/termFromHere.spell) - Opens a terminal in the same `cwd` as the focused `X` program.
3737
- [todo](./spells/todo.spell) - Write/remove a task to do later. Select an existing entry to remove it from the file, or type a new entry to add it.
@@ -43,12 +43,12 @@
4343

4444
## [Cantrips](./cantrips/): Cantrips are scripts lauched from dmenu using the [menu](./cantrips/menu.sh).
4545

46-
- [emoji](./cantrips/emoji.sh) - Give dmenu list of all unicode characters to copy. Shows the selected character in dunst if running.
47-
- [free-nitro](./cantrips/free-nitro.sh) - I don't feel like paying discord, so I just store emoji gifs and quickly copy them to the clipboard to paste in chat. 😎
48-
- [game](./cantrips/game.sh) - Launch steam games from /comfy/ dmenu/fzf/tofi
46+
- [01-m](./cantrips/01-m.sh) - Launches the music player controled using [m](./spells/m.spell)
47+
- [02-rename-ws](./cantrips/02-rename-ws.sh) - Dynamic [i3|bspwm|herbstluftwm] workspace renamer
48+
- [03-emoji](./cantrips/03-emoji.sh) - Give dmenu list of all unicode characters to copy. Shows the selected character in dunst if running.
49+
- [04-free-nitro](./cantrips/04-free-nitro.sh) - I don't feel like paying discord, so I just store emoji gifs and quickly copy them to the clipboard to paste in chat. 😎
50+
- [05-game](./cantrips/05-game.sh) - Launch steam games from /comfy/ dmenu/fzf/tofi
4951
- [menu](./cantrips/menu.sh) - The menu used to find and launch the cantrips
50-
- [rename-ws](./cantrips/rename-ws.sh) - Dynamic [i3|bspwm|herbstluftwm] workspace renamer
51-
- [youtube](./cantrips/youtube.sh) - Launches the music player controled using [m](./spells/m.spell)
5252

5353
## [Runes](./runes/): Static configuration files
5454

runes/hypr/hyprland.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ hl.on("hyprland.start", function()
5555
hl.exec_cmd("changeMeWallCicle")
5656
if hostname == "tolaria" then
5757
hl.exec_cmd("shyprctl daemon &>/tmp/mendess/shyprctl.log")
58-
hl.exec_cmd("auto-start-steam")
58+
hl.exec_cmd("steamgr check-and-auto-start")
5959
end
6060
end)
6161

runes/nvim/lua/boilerplate.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,13 @@ au.group('boilerplate', function()
121121
'}'
122122
)
123123
}
124+
au.FileType = {
125+
'sh',
126+
run_checked(
127+
'#!/usr/bin/env bash',
128+
'',
129+
'set -euo pipefail',
130+
''
131+
)
132+
}
124133
end)

spells/auto-start-steam.spell

Lines changed: 0 additions & 24 deletions
This file was deleted.

spells/setup-remote-steam.spell

Lines changed: 0 additions & 55 deletions
This file was deleted.

spells/steamgr.spell

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
check-and-auto-start() {
6+
until ping -c 1 pendrellvale.home; do
7+
sleep 1;
8+
done
9+
10+
HA_BEARER_TOKEN=$(cat ~/.config/hass-bearer-token)
11+
12+
entity_ids=(input_boolean.gaming_mode input_boolean.remote_gaming)
13+
14+
for entity_id in "${entity_ids[@]}"; do
15+
STATE=$(curl -s -H "Authorization: Bearer ${HA_BEARER_TOKEN}" \
16+
-H "Content-Type: application/json" \
17+
"http://homeassistant.pendrellvale.home/api/states/$entity_id" | jq -r '.state')
18+
19+
if [ "$STATE" == "on" ]; then
20+
echo "Woke by HA intent. Starting Steam..."
21+
22+
setup-remote-steam
23+
fi
24+
done
25+
}
26+
27+
setup-remote-steam-pipewire() {
28+
launch_steam() {
29+
__GL_GSYNC_ALLOWED=0 __GL_VRR_ALLOWED=0 steam \
30+
-pipewire \
31+
--enable-features=UseOzonePlatform \
32+
--ozone-platform=wayland \
33+
--enable-gpu-rasterization \
34+
--enable-zero-copy
35+
}
36+
pgrep steam || launch_steam &
37+
38+
pgrep ydotoold || ydotoold &
39+
TARGET_CLASS="hyprland-share-picker"
40+
echo "Listening for $TARGET_CLASS..."
41+
42+
while true; do
43+
WINDOW_INFO=$(hyprctl clients -j |
44+
jq ".[] | select(.class == \"$TARGET_CLASS\")")
45+
46+
if [ -n "$WINDOW_INFO" ]; then
47+
echo "Portal detected! Calculating coordinates..."
48+
49+
X=$(echo "$WINDOW_INFO" | jq '.at[0]')
50+
Y=$(echo "$WINDOW_INFO" | jq '.at[1]')
51+
WIDTH=$(echo "$WINDOW_INFO" | jq '.size[0]')
52+
HEIGHT=$(echo "$WINDOW_INFO" | jq '.size[1]')
53+
54+
CLICK_X=$(echo "($X + ($WIDTH / 2)) / 2" | bc -l | cut -d'.' -f1)
55+
CLICK_Y=$(echo "($Y + ($HEIGHT * 0.1)) / 2" | bc -l | cut -d'.' -f1)
56+
57+
echo "Simulating click at X: $CLICK_X, Y: $CLICK_Y"
58+
59+
ydotool mousemove -a "$CLICK_X" "$CLICK_Y"
60+
ydotool click 0xC0 # 0xC0 is the code for left mouse button down/up
61+
62+
break
63+
fi
64+
65+
sleep 0.5
66+
done
67+
68+
wait
69+
}
70+
71+
USE_PIPEWIRE=no
72+
GAME_MONITOR_PID=/tmp/game-monitor.pid
73+
74+
setup-remote-steam() {
75+
~/.local/bin/toggle-resolution 16:9
76+
hyprctl dispatch 'hl.dsp.focus({ workspace = "emptymn" })'
77+
[ -e $GAME_MONITOR_PID ] || game-monitor &
78+
if [[ "$USE_PIPEWIRE" = yes ]]; then
79+
setup-remote-steam-pipewire
80+
else
81+
pgrep steam || steam
82+
fi
83+
wait
84+
}
85+
86+
wait-for-steam() {
87+
until pgrep steam &>/dev/null; do
88+
printf "waiting for steam "
89+
date
90+
sleep 0.5
91+
done
92+
until ss -ltp sport = 27036 | grep steam -q; do
93+
printf "waiting for remote play "
94+
date
95+
sleep 0.5
96+
done
97+
}
98+
99+
STOP_GAME_MONITOR_SENTINEL=/tmp/stop-game-monitor
100+
101+
teardown-remote-steam() {
102+
touch "$STOP_GAME_MONITOR_SENTINEL"
103+
~/.local/bin/toggle-resolution 21:9
104+
}
105+
106+
game-monitor() {
107+
exec &>/tmp/game-monitor-$$.log
108+
cleanup() {
109+
rm $GAME_MONITOR_PID
110+
}
111+
trap cleanup EXIT
112+
rm -f $STOP_GAME_MONITOR_SENTINEL
113+
114+
echo "$$" > $GAME_MONITOR_PID
115+
116+
printf "PID: %s\n" "$(cat /tmp/game-monitor.pid)"
117+
handle() {
118+
echo "EV $(date): $*"
119+
case "$1" in
120+
'activewindow>>steam_app_858710') # Gravity Circuit
121+
sleep 1
122+
shyprctl dispatch 'hl.dsp.window.fullscreen({ action = "set" })'
123+
;;
124+
'activewindow>>steam_app_1086940,LariLauncher') # Bg3
125+
(
126+
pgrep ydotoold -a || ydotoold & disown
127+
sleep 5
128+
while [[ "$(hyprctl -j activewindow | jq .title -r)" == "LariLauncher" ]]; do
129+
echo clicking play on larian launcher
130+
ydotool mousemove -a 800 580
131+
ydotool click 0xC0
132+
sleep 0.5
133+
done
134+
) &
135+
;;
136+
'activewindow>>steam_app_1086940,Baldur'*)
137+
sleep 1
138+
shyprctl dispatch 'hl.dsp.window.fullscreen({ action = "set" })'
139+
;;
140+
esac
141+
}
142+
143+
while read -r line; do
144+
if [ -e "$STOP_GAME_MONITOR_SENTINEL" ]; then
145+
rm "$STOP_GAME_MONITOR_SENTINEL"
146+
exit 0
147+
fi
148+
handle "$line"
149+
done < <(
150+
socat -U - UNIX-CONNECT:"$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock"
151+
)
152+
}
153+
154+
case "$1" in
155+
check-and-auto-start|setup-remote-steam|wait-for-steam|teardown-remote-steam|game-monitor)
156+
"$1"
157+
;;
158+
*)
159+
echo "unknown command"
160+
exit 1
161+
;;
162+
esac

0 commit comments

Comments
 (0)