Compare commits

..

4 Commits

Author SHA1 Message Date
d1e13093c5 Rearrange files 2025-10-30 10:37:05 +00:00
e22fbbd504 Focus new windows 2025-10-29 19:34:49 +00:00
2c253da55d Formatting fixes 2025-10-29 19:32:44 +00:00
de595a0802 Final touches 2025-10-29 18:17:59 +00:00
11 changed files with 262 additions and 180 deletions

17
bin/kutu-run.rb Executable file
View File

@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
require "socket"
SOCK_PATH = "/tmp/kutu.sock"
cli_addr_path = "/tmp/kutu_client#{Process.pid}.sock"
File.delete cli_addr_path if File.exist? cli_addr_path
client = Socket.new :UNIX, :DGRAM
client.bind Socket.pack_sockaddr_un(cli_addr_path)
client.send ARGV.join(" "), 0, Socket.pack_sockaddr_un(SOCK_PATH)
data, = client.recvfrom 1024
puts data

96
bin/kutu.rb Executable file
View File

@@ -0,0 +1,96 @@
#!/usr/bin/env ruby
# Require X-kutu library for all x11 functions
require_relative "../src/ruby/X-kutu"
# Require dependencies
require 'json'
require 'socket'
# Initialize X
if X.deploy >= 0
puts "Started kutu WM for X11 successfully! :)"
else
raise "Failed to deploy X, try running using xinit or startx."
end
# Require submodules
require_relative "../src/ruby/utils"
require_relative "../src/ruby/controller"
require_relative "../src/ruby/window"
require_relative "../src/ruby/workspace"
require_relative "../src/ruby/events"
require_relative "../src/ruby/commands"
# Cleanup on exit
at_exit do
X.cleanup
puts "Exited kutu WM, sadly :("
end
# Globals
$monitors = {}
$windows = {}
$all_windows = []
$keybind_actions = {}
$mousebind_actions = {}
$mouse_data = {}
$root = X.get_root
$rect = {}
# Initialize monitors
load_monitors!
# Run startup script
run File.join(__dir__, "../src/shell/startup.sh")
# Add keybinds
load File.join(__dir__, "../src/ruby/bindings.rb")
# Setup unix socket
SOCK_PATH = "/tmp/kutu.sock"
File.delete SOCK_PATH if File.exist? SOCK_PATH
$socket = Socket.new :UNIX, :DGRAM
$socket.bind Socket.pack_sockaddr_un(SOCK_PATH)
# Main loop
loop do
sleep 0.001
if IO.select([$socket], nil, nil, 0)
command, sender = $socket.recvfrom 1024
reply = handle_command command
$socket.send JSON.generate(reply), 0, sender
end
event_pointer = X.next_event
handle_event X.translate_event(event_pointer) if !event_pointer.null?
X.flush
end

View File

@@ -1,17 +0,0 @@
#!/usr/bin/env ruby
require "socket"
SOCK_PATH = "/tmp/kutu.sock"
client = Socket.new(:UNIX, :DGRAM)
cli_addr_path = "/tmp/kutu_client#{Process.pid}.sock"
File.delete(cli_addr_path) if File.exist?(cli_addr_path)
client.bind(Socket.pack_sockaddr_un(cli_addr_path))
client.send(ARGV.join(" "), 0, Socket.pack_sockaddr_un(SOCK_PATH))
data, = client.recvfrom(1024)
puts data

101
kutu.rb
View File

@@ -1,101 +0,0 @@
#!/usr/bin/env ruby
# Require X-kutu library for all x11 functions
require_relative "./src/ruby/X-kutu"
# Require dependencies
require 'json'
require 'socket'
# Initialize X
if X.deploy >= 0
puts "Started kutu WM for X11 successfully! :)"
else
raise "Failed to deploy X"
end
# Require submodules
require_relative "./src/ruby/utils"
require_relative "./src/ruby/controller"
require_relative "./src/ruby/window"
require_relative "./src/ruby/workspace"
require_relative "./src/ruby/events"
require_relative "./src/ruby/commands"
# Cleanup on exit
at_exit do
X.cleanup
puts "Exited kutu WM, sadly :("
end
# Globals
$monitors = {}
$windows = {}
$all_windows = []
$keybind_actions = {}
$mousebind_actions = {}
$mouse_data = {}
$root = X.get_root
$rect = {}
# Initialize monitors
load_monitors!
# Run startup script
run File.join(__dir__, "./src/shell/startup.sh")
# Add keybinds
load File.join(__dir__, "./src/ruby/bindings.rb")
# Setup unix socket
SOCK_PATH = "/tmp/kutu.sock"
File.delete(SOCK_PATH) if File.exist?(SOCK_PATH)
$socket = Socket.new(:UNIX, :DGRAM)
$socket.bind(Socket.pack_sockaddr_un(SOCK_PATH))
# Main loop
loop do
if IO.select([$socket], nil, nil, 0)
command, sender = $socket.recvfrom(1024)
reply = handle_command(command)
$socket.send(JSON.generate(reply), 0, sender)
end
event_pointer = X.next_event
if !event_pointer.null?
event = X.translate_event(event_pointer)
handle_event(event)
end
X.flush
sleep 0.001
end

View File

@@ -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/bin/"* "$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/bin to your PATH to run 'kutu.rb' and 'kutu-run.rb' from anywhere:"
echo "export PATH=\"\$PATH:$DIR/bin\""
fi
echo -e "\e[32mAll done! Build successful.\e[0m"

View File

@@ -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|
@@ -95,6 +131,19 @@ keybind 110 do |_event|
end
end
keybind 115 do |event|
monitor = current_monitor
persistence_path = File.join(__dir__, ".num.json")
persistence = File.exist?(persistence_path) ?
JSON.parse(File.read(persistence_path), symbolize_names: true) :
{}
ws = monitor[:workspaces][
monitor[:selected_workspace] == 0 ?
monitor[:workspaces][persistence[$monitors.key(monitor)]&.[](:saved) || 1] : 0
]
ws.drop ws.tiled_windows.length, $windows[event[:window]] if $windows[event[:window]]
end
keybind 118, 0 do |_event|
run "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
end
@@ -106,20 +155,11 @@ keybind 117, 0 do |_event|
select_workspace next_ws, monitor
end
keybind 117 do |_event|
pointer = X.get_pointer
monitor = current_monitor pointer
keybind 117 do |event|
monitor = current_monitor
next if monitor[:selected_workspace].zero?
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w|
pointer[:x] >= w.x &&
pointer[:x] < w.x + w.width &&
pointer[:y] >= w.y &&
pointer[:y] < w.y + w.height
end
next_ws = (monitor[:selected_workspace] % (monitor[:workspaces].length - 1)) + 1
monitor[:workspaces][next_ws].drop monitor[:workspaces][next_ws].tiled_windows.length, window if window
ws = monitor[:workspaces][(monitor[:selected_workspace] % (monitor[:workspaces].length - 1)) + 1]
ws.drop ws.tiled_windows.length, $windows[event[:window]] if $windows[event[:window]]
end
keybind 112, 0 do |_event|
@@ -129,20 +169,11 @@ keybind 112, 0 do |_event|
select_workspace next_ws, monitor
end
keybind 112 do |_event|
pointer = X.get_pointer
monitor = current_monitor pointer
keybind 112 do |event|
monitor = current_monitor
next if monitor[:selected_workspace].zero?
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w|
pointer[:x] >= w.x &&
pointer[:x] < w.x + w.width &&
pointer[:y] >= w.y &&
pointer[:y] < w.y + w.height
end
next_ws = ((monitor[:selected_workspace] - 2) % (monitor[:workspaces].length - 1)) + 1
monitor[:workspaces][next_ws].drop monitor[:workspaces][next_ws].tiled_windows.length, window if window
ws = monitor[:workspaces][((monitor[:selected_workspace] - 2) % (monitor[:workspaces].length - 1)) + 1]
ws.drop ws.tiled_windows.length, $windows[event[:window]] if $windows[event[:window]]
end
keybind 27 do |_event|
@@ -161,7 +192,6 @@ keybind 39 do |event|
window.toggle_floating if window
end
mousebind 1
mousebind 3
@@ -174,19 +204,10 @@ mousebind 9, 0 do |_event|
end
mousebind 9 do |_event|
pointer = X.get_pointer
monitor = current_monitor pointer
monitor = current_monitor
next if monitor[:selected_workspace].zero?
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w|
pointer[:x] >= w.x &&
pointer[:x] < w.x + w.width &&
pointer[:y] >= w.y &&
pointer[:y] < w.y + w.height
end
next_ws = (monitor[:selected_workspace] % (monitor[:workspaces].length - 1)) + 1
monitor[:workspaces][next_ws].drop monitor[:workspaces][next_ws].tiled_windows.length, window if window
ws = monitor[:workspaces][(monitor[:selected_workspace] % (monitor[:workspaces].length - 1)) + 1]
ws.drop ws.tiled_windows.length, $windows[event[:window]] if $windows[event[:window]]
end
mousebind 8, 0 do |_event|
@@ -197,17 +218,8 @@ mousebind 8, 0 do |_event|
end
mousebind 8 do |_event|
pointer = X.get_pointer
monitor = current_monitor pointer
monitor = current_monitor
next if monitor[:selected_workspace].zero?
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w|
pointer[:x] >= w.x &&
pointer[:x] < w.x + w.width &&
pointer[:y] >= w.y &&
pointer[:y] < w.y + w.height
end
next_ws = ((monitor[:selected_workspace] - 2) % (monitor[:workspaces].length - 1)) + 1
monitor[:workspaces][next_ws].drop monitor[:workspaces][next_ws].tiled_windows.length, window if window
ws = monitor[:workspaces][((monitor[:selected_workspace] - 2) % (monitor[:workspaces].length - 1)) + 1]
ws.drop ws.tiled_windows.length, $windows[event[:window]] if $windows[event[:window]]
end

View File

@@ -45,6 +45,7 @@ def handle_event(event)
X.send_to_top window if above.include?("ABOVE")
end
end
X.focus event[:window]
when :mouse_press

View File

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

9
src/shell/caffiene.sh Executable file
View File

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

34
src/shell/power.sh Executable file
View File

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

17
src/shell/run.sh Executable file
View File

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