diff --git a/kutu.rb b/kutu.rb index 22803a4..86a7e39 100755 --- a/kutu.rb +++ b/kutu.rb @@ -50,8 +50,6 @@ $mousebind_actions = {} $mouse_data = {} - - $root = X.get_root $rect = {} diff --git a/compile.sh b/setup.sh old mode 100755 new mode 100644 similarity index 59% rename from compile.sh rename to setup.sh index bc09d84..db55e1e --- a/compile.sh +++ b/setup.sh @@ -24,3 +24,17 @@ if [ ! -f "$DIR/build/X-kutu.so" ]; then else echo "Success: $DIR/build/X-kutu.so is compiled." fi + +for f in "$DIR/kutu-run.rb" "$DIR/kutu.rb" "$DIR/src/shell/"*; do + chmod +x "$f" || { + echo "Error: Failed to chmod $f" >&2 + exit 1 + } +done + +if ! command -v kutu.rb >/dev/null 2>&1 || ! command -v kutu-run.rb >/dev/null 2>&1; then + echo "Tip: Add $DIR to your PATH to run 'kutu.rb' and 'kutu-run.rb' from anywhere:" + echo "export PATH=\"\$PATH:$DIR\"" +fi + +echo -e "\e[32mAll done! Build successful.\e[0m" diff --git a/src/ruby/bindings.rb b/src/ruby/bindings.rb index 45faf70..cc36ea7 100644 --- a/src/ruby/bindings.rb +++ b/src/ruby/bindings.rb @@ -11,23 +11,56 @@ keybind 25 do |_event| end keybind 26 do |_event| - run "~/dotfiles/scripts/power.sh" + run File.join(__dir__, "../shell/power.sh") end keybind 123, 0 do |_event| - run "pactl set-sink-volume @DEFAULT_SINK@ +5%;vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n1);dunstify 'Volume Adjusted' '' -h int:value:$vol -r 997" + run %q( + pactl set-sink-volume @DEFAULT_SINK@ +5%; + vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n1); + dunstify "Volume Adjusted" "" -h int:value:$vol -r 997 + ) end keybind 122, 0 do |_event| - run "pactl set-sink-volume @DEFAULT_SINK@ -5%;vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n1);dunstify 'Volume Adjusted' '' -h int:value:$vol -r 997" + run %q( + pactl set-sink-volume @DEFAULT_SINK@ -5%; + vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n1); + dunstify "Volume Adjusted" "" -h int:value:$vol -r 997 + ) end keybind 121, 0 do |_event| - run "pactl set-sink-mute @DEFAULT_SINK@ toggle;vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n1);dunstify 'Volume Adjusted' '' -h int:value:$vol -r 997" + run %q( + pactl set-sink-mute @DEFAULT_SINK@ toggle; + vol=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\\+%' | head -n1); + dunstify "Volume Adjusted" "" -h int:value:$vol -r 997 + ) end keybind 38 do |_event| - run "maim -c 0.3,0.5,1.0,0.8 -s | tee /tmp/screenshot_temp.png | xclip -selection clipboard -t image/png && if [ -s '/tmp/screenshot_temp.png' ]; then mv /tmp/screenshot_temp.png ~/screenshots/$(date +%Y-%m-%d_%H:%M:%S).png; fi" + run %Q( + maim -c 0.3,0.5,1.0,0.8 -s | tee /tmp/screenshot_temp.png | xclip -selection clipboard -t image/png; + if [ -s '/tmp/screenshot_temp.png' ]; then + mv /tmp/screenshot_temp.png ~/screenshots/$(date +%Y-%m-%d_%H:%M:%S).png; + fi + ) +end + +keybind 232, 0 do |_event| + run %q( + brightnessctl set 5%-; + pct=$(brightnessctl -m | cut -d, -f4 | tr -d ' %'); + dunstify "Brightness" "" -h int:value:$pct -r 998 + ) +end + +keybind 233, 0 do |_event| + run %q( + brightnessctl set 5%+; + pct=$(brightnessctl -m | cut -d, -f4 | tr -d ' %'); + dunstify "Brightness" "" -h int:value:$pct -r 998 + ) end keybind 54 do |_event| @@ -39,7 +72,7 @@ keybind 53 do |_event| end keybind 40 do |_event| - run "~/dotfiles/scripts/run.sh" + run File.join(__dir__, "../shell/run.sh") end keybind 33 do |_event| @@ -47,7 +80,7 @@ keybind 33 do |_event| end keybind 45 do |_event| - run "~/dotfiles/scripts/caffiene.sh" + run File.join(__dir__, "../shell/caffiene.sh") end keybind 56 do |_event| @@ -75,8 +108,11 @@ keybind 57 do |_event| end keybind 110, 0 do |_event| - run "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause;" \ - "dbus-send --print-reply --dest=$(busctl --user list | grep -oP 'org.mpris.MediaPlayer2.firefox.instance_1_\d+') /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause" + run %q( + dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause; + dbus-send --print-reply --dest=$(busctl --user list | grep -oP 'org.mpris.MediaPlayer2.firefox.instance_1_\\d+') \ + /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause + ) end keybind 110 do |_event| @@ -161,7 +197,6 @@ keybind 39 do |event| window.toggle_floating if window end - mousebind 1 mousebind 3 diff --git a/src/ruby/utils.rb b/src/ruby/utils.rb index d4c8c2c..6f364bb 100644 --- a/src/ruby/utils.rb +++ b/src/ruby/utils.rb @@ -9,8 +9,8 @@ def mousebind(btn, mod = 1, &block) end -def run(command) - pid = spawn command +def run(cmd) + pid = spawn "bash", "-c", cmd Process.detach pid end diff --git a/src/shell/caffiene.sh b/src/shell/caffiene.sh new file mode 100755 index 0000000..f28916f --- /dev/null +++ b/src/shell/caffiene.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +if [[ "$(xset q | awk '/timeout:/ {print $2}')" == "0" ]]; then + xset s on + xset +dpms +else + xset s off + xset -dpms +fi diff --git a/src/shell/power.sh b/src/shell/power.sh new file mode 100755 index 0000000..bf4f707 --- /dev/null +++ b/src/shell/power.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -euo pipefail + +opts=" +󰒲 Suspend + Stop KutuWM + Shutdown +󰜉 Reboot" + +sel=$(printf "%s\n" "$opts" | dmenu -i -p "Select Power Option:" \ + -nf '#e0af68' -nb '#1f2335' -sb '#f7768e' -sf '#1a1b26' -fn 'HurmitNerdFont-16') + +# user pressed Esc +[ -z "$sel" ] && exit 0 + +case "$sel" in +*Shutdown*) + confirm=$(printf "No\nYes" | dmenu -i -p "Are you sure you want to shutdown? :" \ + -nf '#e0af68' -nb '#1f2335' -sb '#f7768e' -sf '#1a1b26' -fn 'HurmitNerdFont-16') + [ "$confirm" = "Yes" ] && exec shutdown -h now + ;; +*Reboot*) + confirm=$(printf "No\nYes" | dmenu -i -p "Are you sure you want to reboot? :" \ + -nf '#e0af68' -nb '#1f2335' -sb '#f7768e' -sf '#1a1b26' -fn 'HurmitNerdFont-16') + [ "$confirm" = "Yes" ] && exec reboot + ;; +*Stop\ KutuWM*) + exec kutu-run.rb stop + ;; +*Suspend*) + ~/dotfiles/scripts/lock.sh & + exec systemctl suspend + ;; +esac diff --git a/src/shell/run.sh b/src/shell/run.sh new file mode 100755 index 0000000..f351154 --- /dev/null +++ b/src/shell/run.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +choice=$( + ( + printf "%s\n" godot mvox mox aseprite terraria + compgen -c + ) | + grep -v -E '^(if|fi|case|esac|for|done|while|until|select|function|return|continue|break|time|exec|source|alias|builtin|read|export|unset|local|set|declare|typeset|:|\.|\[|coproc|l|ll|ls|then|else|elif|do|in|\{|\}|!|\[\[|\]\]|_.*|compgen)$' | + sort | + dmenu -i -p "Enter command  " \ + -nf '#4abaaf' -nb '#1f2335' -sb '#7aa2f7' -sf '#102030' -fn 'HurmitNerdFont-16' +) + +[ -z "$choice" ] && exit 0 + +fish -c "$choice" >/dev/null 2>&1 & +disown