diff --git a/rubywm.rb b/rubywm.rb index f4fbce0..36c4048 100644 --- a/rubywm.rb +++ b/rubywm.rb @@ -1,4 +1,7 @@ +# (C) 2024 Vidar Hokstad +# Licensed under the MIT license. +# # Based on TinyWM by Nick Welch # Lots of inspiration from Katriawm # https://www.uninformativ.de/git/katriawm/files.html @@ -11,20 +14,22 @@ require_relative 'window.rb' require_relative 'wm.rb' require_relative 'desktop.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 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 -d = TypeDispatcher.new(wm) +d = Dispatcher.new($wm) d.on(:client_message) do |ev| data = ev.data.unpack("V*") name = dpy.get_atom_name(ev.type) - p [name, data, ev] d.(name, ev.window, *data) end diff --git a/type_dispatcher.rb b/type_dispatcher.rb index 95d94cf..5f28999 100644 --- a/type_dispatcher.rb +++ b/type_dispatcher.rb @@ -1,5 +1,16 @@ -class TypeDispatcher - def initialize(target) +# # Dispatcher +# +# Dispatch `call(method, *args)` to `@target.on_(*args)` or `@on[method].call(*args)` +# where 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 @on = {} end