118
kutu.rb
118
kutu.rb
@@ -74,28 +74,89 @@ at_exit { X.cleanup }
|
|||||||
|
|
||||||
$monitors = X.get_monitors
|
$monitors = X.get_monitors
|
||||||
|
|
||||||
$monitors.each do |monitor|
|
|
||||||
puts "Monitor: #{monitor[:x]} #{monitor[:y]} #{monitor[:width]} #{monitor[:height]}"
|
|
||||||
end
|
|
||||||
|
|
||||||
$workspaces = {}
|
$workspaces = {}
|
||||||
$windows = {}
|
$windows = {}
|
||||||
|
|
||||||
class Window
|
$keybind_actions = {}
|
||||||
attr_reader :window_id
|
$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)
|
def initialize(window_id)
|
||||||
@window_id = 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
|
||||||
end
|
end
|
||||||
|
|
||||||
class Workspace
|
class Workspace
|
||||||
attr_reader :windows, :name, :screen
|
attr_reader :name, :monitor, :x, :y, :width, :height
|
||||||
|
|
||||||
def initialize(name)
|
def initialize(name, monitor = 0)
|
||||||
@windows = {}
|
@tiled_root_block = RootWindowBlock.new(self)
|
||||||
|
@untiled_windows = []
|
||||||
@name = name
|
@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
|
end
|
||||||
|
|
||||||
def add(window_id)
|
def add(window_id)
|
||||||
@@ -144,11 +205,22 @@ EVENT_TYPES = {
|
|||||||
|
|
||||||
$workspaces[:main] = Workspace.new(:main)
|
$workspaces[:main] = Workspace.new(:main)
|
||||||
|
|
||||||
X.add_keybind 24
|
keybind(24) do |event|
|
||||||
X.add_keybind 25
|
X.kill event[:window]
|
||||||
X.add_keybind 26
|
end
|
||||||
X.add_mousebind 1
|
|
||||||
X.add_mousebind 3
|
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_state = -1
|
||||||
$mouse_window = -1
|
$mouse_window = -1
|
||||||
@@ -178,6 +250,9 @@ loop do
|
|||||||
$mouse_window = event[:window]
|
$mouse_window = event[:window]
|
||||||
$mouse_pos_start = X.get_pointer
|
$mouse_pos_start = X.get_pointer
|
||||||
$geom_start = X.get_geometry event[:window]
|
$geom_start = X.get_geometry event[:window]
|
||||||
|
if $mousebind_actions[event[:btn]]
|
||||||
|
$mousebind_actions[event[:btn]].call(event)
|
||||||
|
end
|
||||||
when :mouse_drag
|
when :mouse_drag
|
||||||
screen_bounds = $monitors[0]
|
screen_bounds = $monitors[0]
|
||||||
mouse_pos = X.get_pointer
|
mouse_pos = X.get_pointer
|
||||||
@@ -204,17 +279,8 @@ loop do
|
|||||||
$geom_start = nil
|
$geom_start = nil
|
||||||
end
|
end
|
||||||
when :key_press
|
when :key_press
|
||||||
case event[:btn]
|
if $keybind_actions[event[:btn]]
|
||||||
when 24
|
$keybind_actions[event[:btn]].call(event)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
when :key_release
|
when :key_release
|
||||||
# TODO
|
# TODO
|
||||||
|
|||||||
Reference in New Issue
Block a user