Try completing event list

This commit is contained in:
2025-10-01 06:26:33 +01:00
parent ecf522bd8f
commit 2eed7c1dad
4 changed files with 83 additions and 17 deletions

47
kutu.rb
View File

@@ -57,16 +57,29 @@ at_exit { X.cleanup }
$monitors = {}
xrandr_output = `xrandr --query`
connected = xrandr_output.each_line.select { |line| line.include?(" connected") }
connected.sort_by! { |line| line.include?(" primary") ? 0 : 1 }
connected.first(2).each_with_index do |line, index|
next unless line =~ /(\d+)x(\d+)\+(\d+)\+(\d+)/
w, h, x, y = $1.to_i, $2.to_i, $3.to_i, $4.to_i
key = index.zero? ? :primary : :secondary
$monitors[key] = { x: x, y: y, width: w, height: h }
def refresh_monitors
$monitors.clear
xrandr_output = `xrandr --query`
connected = xrandr_output.each_line.select { |line| line.include?(" connected") }
connected.sort_by! { |line| line.include?(" primary") ? 0 : 1 }
connected.first(2).each_with_index do |line, index|
next unless line =~ /(\d+)x(\d+)\+(\d+)\+(\d+)/
w, h, x, y = $1.to_i, $2.to_i, $3.to_i, $4.to_i
key = index.zero? ? :primary : :secondary
$monitors[key] = { x: x, y: y, width: w, height: h }
end
end
refresh_monitors
# def get_wm_normal_hints(window_id)
# xprop_output = `xprop -id 0x#{window_id.to_s(16)} WM_NORMAL_HINTS`
# return {} unless xprop_output =~ /WM_NORMAL_HINTS\(([^)]+)\):\s*(.*)/
# hints = {}
# # TODO: parse the output properly
# hints
# end
$workspaces = {}
$windows = {}
@@ -92,10 +105,12 @@ class Node
end
class Window < Node
attr_accessor :window_id, :x, :y, :width, :height
attr_accessor :window_id, :x, :y, :width, :height#, :state
def initialize(window_id)
@window_id = window_id
# @state = :widthrawn # :iconic, :withdrawn, :normal
# ADD: properties for https://tronche.com/gui/x/icccm/sec-4.html#s-4 sec 4.1.2.(3, 4)
super()
end
@@ -226,6 +241,7 @@ EVENT_TYPES = {
1 => :create,
2 => :close,
3 => :enter,
-1 => :show_after,
4 => :show,
5 => :mouse_press,
6 => :mouse_drag,
@@ -265,21 +281,22 @@ loop do
event = X.wait_for_event
case EVENT_TYPES[event[:type]]
when :create
if event[:override_redirect].zero?
X.subscribe event[:window]
X.focus event[:window]
end
next unless event[:override_redirect].zero?
X.subscribe event[:window]
X.focus event[:window]
when :close
X.kill event[:window]
$windows[event[:window]]&.remove event[:window]
when :enter
X.focus event[:window]
X.send_to_top event[:window]
when :show
X.show event[:window]
when :show_after
next unless event[:override_redirect].zero?
X.focus event[:window]
$workspaces[:main].add event[:window] if $windows[event[:window]].nil?
$workspaces[:main].tiled_root_block.compute_geometry!
when :show
X.show event[:window]
when :mouse_press
next if event[:is_root] != 0
X.send_to_top event[:window]