Add remote commands support

This commit is contained in:
2025-10-29 17:27:23 +00:00
parent 11806119df
commit a21e716475
13 changed files with 238 additions and 115 deletions

49
kutu.rb
View File

@@ -5,6 +5,12 @@
require_relative "./src/ruby/X-kutu"
# Require dependencies
require 'json'
require 'socket'
# Initialize X
if X.deploy >= 0
@@ -14,13 +20,14 @@ else
end
# Require modules
# Require submodules
load File.join(__dir__, "./src/ruby/utils.rb")
load File.join(__dir__, "./src/ruby/controller.rb")
load File.join(__dir__, "./src/ruby/window.rb")
load File.join(__dir__, "./src/ruby/workspace.rb")
load File.join(__dir__, "./src/ruby/events.rb")
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
@@ -36,11 +43,15 @@ end
$monitors = {}
$windows = {}
$all_windows = []
$keybind_actions = {}
$mousebind_actions = {}
$mouse_data = {}
$root = X.get_root
$rect = {}
@@ -60,9 +71,31 @@ run File.join(__dir__, "./src/shell/startup.sh")
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
event = X.wait_for_event
handle_event event
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