Formatting fixes

This commit is contained in:
2025-10-29 19:32:44 +00:00
parent de595a0802
commit 2c253da55d
3 changed files with 43 additions and 69 deletions

View File

@@ -4,14 +4,14 @@ require "socket"
SOCK_PATH = "/tmp/kutu.sock" SOCK_PATH = "/tmp/kutu.sock"
client = Socket.new(:UNIX, :DGRAM)
cli_addr_path = "/tmp/kutu_client#{Process.pid}.sock" cli_addr_path = "/tmp/kutu_client#{Process.pid}.sock"
File.delete(cli_addr_path) if File.exist?(cli_addr_path) 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)) client = Socket.new :UNIX, :DGRAM
client.bind Socket.pack_sockaddr_un(cli_addr_path)
data, = client.recvfrom(1024) client.send ARGV.join(" "), 0, Socket.pack_sockaddr_un(SOCK_PATH)
data, = client.recvfrom 1024
puts data puts data

23
kutu.rb
View File

@@ -16,7 +16,7 @@ require 'socket'
if X.deploy >= 0 if X.deploy >= 0
puts "Started kutu WM for X11 successfully! :)" puts "Started kutu WM for X11 successfully! :)"
else else
raise "Failed to deploy X" raise "Failed to deploy X, try running using xinit or startx."
end end
@@ -72,28 +72,25 @@ load File.join(__dir__, "./src/ruby/bindings.rb")
# Setup unix socket # Setup unix socket
SOCK_PATH = "/tmp/kutu.sock" SOCK_PATH = "/tmp/kutu.sock"
File.delete(SOCK_PATH) if File.exist?(SOCK_PATH) File.delete SOCK_PATH if File.exist? SOCK_PATH
$socket = Socket.new(:UNIX, :DGRAM) $socket = Socket.new :UNIX, :DGRAM
$socket.bind(Socket.pack_sockaddr_un(SOCK_PATH)) $socket.bind Socket.pack_sockaddr_un(SOCK_PATH)
# Main loop # Main loop
loop do loop do
sleep 0.001
if IO.select([$socket], nil, nil, 0) if IO.select([$socket], nil, nil, 0)
command, sender = $socket.recvfrom(1024) command, sender = $socket.recvfrom 1024
reply = handle_command(command) reply = handle_command command
$socket.send(JSON.generate(reply), 0, sender) $socket.send JSON.generate(reply), 0, sender
end end
event_pointer = X.next_event event_pointer = X.next_event
if !event_pointer.null? handle_event X.translate_event(event_pointer) if !event_pointer.null?
event = X.translate_event(event_pointer)
handle_event(event)
end
X.flush X.flush
sleep 0.001
end end

View File

@@ -131,6 +131,19 @@ keybind 110 do |_event|
end end
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| keybind 118, 0 do |_event|
run "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause" run "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
end end
@@ -142,20 +155,11 @@ keybind 117, 0 do |_event|
select_workspace next_ws, monitor select_workspace next_ws, monitor
end end
keybind 117 do |_event| keybind 117 do |event|
pointer = X.get_pointer monitor = current_monitor
monitor = current_monitor pointer
next if monitor[:selected_workspace].zero? next if monitor[:selected_workspace].zero?
ws = monitor[:workspaces][(monitor[:selected_workspace] % (monitor[:workspaces].length - 1)) + 1]
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w| ws.drop ws.tiled_windows.length, $windows[event[:window]] if $windows[event[:window]]
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
end end
keybind 112, 0 do |_event| keybind 112, 0 do |_event|
@@ -165,20 +169,11 @@ keybind 112, 0 do |_event|
select_workspace next_ws, monitor select_workspace next_ws, monitor
end end
keybind 112 do |_event| keybind 112 do |event|
pointer = X.get_pointer monitor = current_monitor
monitor = current_monitor pointer
next if monitor[:selected_workspace].zero? next if monitor[:selected_workspace].zero?
ws = monitor[:workspaces][((monitor[:selected_workspace] - 2) % (monitor[:workspaces].length - 1)) + 1]
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w| ws.drop ws.tiled_windows.length, $windows[event[:window]] if $windows[event[:window]]
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
end end
keybind 27 do |_event| keybind 27 do |_event|
@@ -209,19 +204,10 @@ mousebind 9, 0 do |_event|
end end
mousebind 9 do |_event| mousebind 9 do |_event|
pointer = X.get_pointer monitor = current_monitor
monitor = current_monitor pointer
next if monitor[:selected_workspace].zero? next if monitor[:selected_workspace].zero?
ws = monitor[:workspaces][(monitor[:selected_workspace] % (monitor[:workspaces].length - 1)) + 1]
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w| ws.drop ws.tiled_windows.length, $windows[event[:window]] if $windows[event[:window]]
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
end end
mousebind 8, 0 do |_event| mousebind 8, 0 do |_event|
@@ -232,17 +218,8 @@ mousebind 8, 0 do |_event|
end end
mousebind 8 do |_event| mousebind 8 do |_event|
pointer = X.get_pointer monitor = current_monitor
monitor = current_monitor pointer
next if monitor[:selected_workspace].zero? next if monitor[:selected_workspace].zero?
ws = monitor[:workspaces][((monitor[:selected_workspace] - 2) % (monitor[:workspaces].length - 1)) + 1]
window = monitor[:workspaces][monitor[:selected_workspace]].windows.find do |w| ws.drop ws.tiled_windows.length, $windows[event[:window]] if $windows[event[:window]]
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
end end