This commit is contained in:
Vidar Hokstad 2024-01-21 00:06:50 +00:00
parent 67d0e1465a
commit 2cb2f4ac19
2 changed files with 22 additions and 6 deletions

View file

@ -1,4 +1,7 @@
# (C) 2024 Vidar Hokstad <vidar@hokstad.com>
# Licensed under the MIT license.
#
# Based on TinyWM by Nick Welch # Based on TinyWM by Nick Welch
# Lots of inspiration from Katriawm # Lots of inspiration from Katriawm
# https://www.uninformativ.de/git/katriawm/files.html # https://www.uninformativ.de/git/katriawm/files.html
@ -11,20 +14,22 @@ require_relative 'window.rb'
require_relative 'wm.rb' require_relative 'wm.rb'
require_relative 'desktop.rb' require_relative 'desktop.rb'
require_relative 'tiled.rb' require_relative 'tiled.rb'
require_relative '../type_dispatcher' require_relative 'type_dispatcher'
require_relative 'geom.rb'
require_relative 'leaf.rb'
require_relative 'node.rb'
Thread.abort_on_exception = true Thread.abort_on_exception = true
dpy = X11::Display.new dpy = X11::Display.new
wm = WindowManager.new(dpy, num_desktops: 10) $wm = WindowManager.new(dpy, num_desktops: 10)
# FIXME: This can also go into the WindowManager class # FIXME: This can also go into the WindowManager class
d = TypeDispatcher.new(wm) d = Dispatcher.new($wm)
d.on(:client_message) do |ev| d.on(:client_message) do |ev|
data = ev.data.unpack("V*") data = ev.data.unpack("V*")
name = dpy.get_atom_name(ev.type) name = dpy.get_atom_name(ev.type)
p [name, data, ev]
d.(name, ev.window, *data) d.(name, ev.window, *data)
end end

View file

@ -1,5 +1,16 @@
class TypeDispatcher # # Dispatcher
def initialize(target) #
# Dispatch `call(method, *args)` to `@target.on_<name>(*args)` or `@on[method].call(*args)`
# where <name> is a cleaned up string representation of method, so that:
#
# dispatch.(X11::Form::MotionNotify, arg1, arg2)
#
# Becomes:
#
# @target.on_motion_notify(arg1, arg2)
#
class Dispatcher
def initialize(target=nil)
@target = target @target = target
@on = {} @on = {}
end end