120
kutu.rb
120
kutu.rb
@@ -74,28 +74,89 @@ at_exit { X.cleanup }
|
||||
|
||||
$monitors = X.get_monitors
|
||||
|
||||
$monitors.each do |monitor|
|
||||
puts "Monitor: #{monitor[:x]} #{monitor[:y]} #{monitor[:width]} #{monitor[:height]}"
|
||||
end
|
||||
|
||||
$workspaces = {}
|
||||
$windows = {}
|
||||
|
||||
class Window
|
||||
attr_reader :window_id
|
||||
$keybind_actions = {}
|
||||
$mousebind_actions = {}
|
||||
|
||||
def keybind(key, &block)
|
||||
X.add_keybind key
|
||||
$keybind_actions[key] = block
|
||||
end
|
||||
|
||||
def mousebind(btn, &block)
|
||||
X.add_mousebind btn
|
||||
$mousebind_actions[btn] = block if block
|
||||
end
|
||||
|
||||
class Node
|
||||
attr_accessor :size
|
||||
|
||||
def initialize
|
||||
@size = 0
|
||||
end
|
||||
end
|
||||
|
||||
class Window << Node
|
||||
attr_accessor :window_id
|
||||
|
||||
def initialize(window_id)
|
||||
@window_id = window_id
|
||||
super()
|
||||
end
|
||||
|
||||
def each_leaf(&block)
|
||||
block.call(self)
|
||||
end
|
||||
end
|
||||
|
||||
class WindowBlock << Node
|
||||
attr_accessor :children, :direction, :size
|
||||
|
||||
def initialize()
|
||||
@children = []
|
||||
end
|
||||
|
||||
def add_node(node)
|
||||
@children << node
|
||||
end
|
||||
|
||||
def each_leaf(&block)
|
||||
node.children.each do |child|
|
||||
child.each_leaf(&block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class RootWindowBlock << WindowBlock
|
||||
attr_accessor :x, :y, :width, :height
|
||||
|
||||
def initialize(workspace)
|
||||
super()
|
||||
@x = workspace.x
|
||||
@y = workspace.y
|
||||
@width = workspace.width
|
||||
@height = workspace.height
|
||||
@direction = :vertical
|
||||
end
|
||||
end
|
||||
|
||||
class Workspace
|
||||
attr_reader :windows, :name, :screen
|
||||
attr_reader :name, :monitor, :x, :y, :width, :height
|
||||
|
||||
def initialize(name)
|
||||
@windows = {}
|
||||
def initialize(name, monitor = 0)
|
||||
@tiled_root_block = RootWindowBlock.new(self)
|
||||
@untiled_windows = []
|
||||
@name = name
|
||||
@screen = :main
|
||||
@monitor = monitor
|
||||
end
|
||||
|
||||
def windows
|
||||
windows = []
|
||||
@untiled_windows.each { |w| windows << w }
|
||||
@tiled_root_block.each_leaf() { |w| windows << w }
|
||||
windows
|
||||
end
|
||||
|
||||
def add(window_id)
|
||||
@@ -144,11 +205,22 @@ EVENT_TYPES = {
|
||||
|
||||
$workspaces[:main] = Workspace.new(:main)
|
||||
|
||||
X.add_keybind 24
|
||||
X.add_keybind 25
|
||||
X.add_keybind 26
|
||||
X.add_mousebind 1
|
||||
X.add_mousebind 3
|
||||
keybind(24) do |event|
|
||||
X.kill event[:window]
|
||||
end
|
||||
|
||||
keybind(25) do |_event|
|
||||
pid = spawn("kitty")
|
||||
Process.detach pid
|
||||
end
|
||||
|
||||
keybind(26) do |_event|
|
||||
$workspaces.each_value(&:close_all)
|
||||
exit 1
|
||||
end
|
||||
|
||||
mousebind(1)
|
||||
mousebind(3)
|
||||
|
||||
$mouse_state = -1
|
||||
$mouse_window = -1
|
||||
@@ -178,6 +250,9 @@ 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
|
||||
when :mouse_drag
|
||||
screen_bounds = $monitors[0]
|
||||
mouse_pos = X.get_pointer
|
||||
@@ -204,21 +279,12 @@ loop do
|
||||
$geom_start = nil
|
||||
end
|
||||
when :key_press
|
||||
case event[:btn]
|
||||
when 24
|
||||
X.kill event[:window]
|
||||
when 25
|
||||
pid = spawn("kitty")
|
||||
Process.detach pid
|
||||
when 26
|
||||
$workspaces.each_value do |workspace|
|
||||
workspace.close_all
|
||||
end
|
||||
exit 1
|
||||
if $keybind_actions[event[:btn]]
|
||||
$keybind_actions[event[:btn]].call(event)
|
||||
end
|
||||
when :key_release
|
||||
# TODO
|
||||
when :configured
|
||||
# TODO
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user