This commit is contained in:
2025-09-29 16:06:42 +01:00
parent 908e1d39e2
commit 1c9e62f9a3
3 changed files with 26 additions and 25 deletions

34
kutu.rb
View File

@@ -67,7 +67,6 @@ end
if X.deploy < 0
raise "Failed to deploy X"
exit 1
end
at_exit { X.cleanup }
@@ -98,12 +97,12 @@ class Node
end
end
class Window << Node
class Window < Node
attr_accessor :window_id
def initialize(window_id)
@window_id = window_id
super()
super
end
def each_leaf(&block)
@@ -111,11 +110,12 @@ class Window << Node
end
end
class WindowBlock << Node
class WindowBlock < Node
attr_accessor :children, :direction, :size
def initialize()
@children = []
super
end
def add_node(node)
@@ -129,11 +129,11 @@ class WindowBlock << Node
end
end
class RootWindowBlock << WindowBlock
class RootWindowBlock < WindowBlock
attr_accessor :x, :y, :width, :height
def initialize(workspace)
super()
super
@x = workspace.x
@y = workspace.y
@width = workspace.width
@@ -155,7 +155,7 @@ class Workspace
def windows
windows = []
@untiled_windows.each { |w| windows << w }
@tiled_root_block.each_leaf() { |w| windows << w }
@tiled_root_block.each_leaf { |w| windows << w }
windows
end
@@ -172,7 +172,7 @@ class Workspace
def close_all
@windows.each_key do |window|
X.kill window
self.remove window
remove window
end
end
@@ -229,7 +229,7 @@ loop do
event = X.wait_for_event
case EVENT_TYPES[event[:type]]
when :create
if event[:override_redirect] == 0
if event[:override_redirect].zero?
X.subscribe event[:window]
X.focus event[:window]
$workspaces[:main].add event[:window]
@@ -250,19 +250,17 @@ loop do
$mouse_window = event[:window]
$mouse_pos_start = X.get_pointer
$geom_start = X.get_geometry event[:window]
if $mousebind_actions[event[:btn]]
$mousebind_actions[event[:btn]].call(event)
end
$mousebind_actions[event[:btn]]&.call(event)
when :mouse_drag
screen_bounds = $monitors[0]
screen_bounds = X.get_screen # TODO: use monitor
mouse_pos = X.get_pointer
dx = mouse_pos[:x] - $mouse_pos_start[:x]
dy = mouse_pos[:y] - $mouse_pos_start[:y]
if $mouse_state == 1
new_x = [[$geom_start[:x] + dx, screen_bounds[:x]].max,
screen_bounds[:x] + screen_bounds[:width] - $geom_start[:width]].min
screen_bounds[:x] + screen_bounds[:width] - $geom_start[:width]].min
new_y = [[$geom_start[:y] + dy, screen_bounds[:y]].max,
screen_bounds[:y] + screen_bounds[:height] - $geom_start[:height]].min
screen_bounds[:y] + screen_bounds[:height] - $geom_start[:height]].min
X.move_window $mouse_window, new_x, new_y
elsif $mouse_state == 3
X.resize_window $mouse_window,
@@ -279,12 +277,10 @@ loop do
$geom_start = nil
end
when :key_press
if $keybind_actions[event[:btn]]
$keybind_actions[event[:btn]].call(event)
end
$keybind_actions[event[:btn]]&.call(event)
when :key_release
# TODO
when :configured
# TODO
end
end
end