Class: XlibObj::Window::EventHandler
- Inherits:
-
Object
- Object
- XlibObj::Window::EventHandler
- Defined in:
- lib/window/event_handler.rb
Instance Attribute Summary collapse
-
#display ⇒ Object
readonly
Returns the value of attribute display.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
- #handle(event) ⇒ Object
-
#initialize(display, window) ⇒ EventHandler
constructor
A new instance of EventHandler.
- #off(mask, event, handler = nil) ⇒ Object
- #on(mask, event, &handler) ⇒ Object
Constructor Details
#initialize(display, window) ⇒ EventHandler
Returns a new instance of EventHandler.
25 26 27 28 29 |
# File 'lib/window/event_handler.rb', line 25 def initialize(display, window) @display = display @window = window @event_handlers = {} end |
Instance Attribute Details
#display ⇒ Object (readonly)
Returns the value of attribute display.
31 32 33 |
# File 'lib/window/event_handler.rb', line 31 def display @display end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
31 32 33 |
# File 'lib/window/event_handler.rb', line 31 def window @window end |
Class Method Details
.remove(display, window) ⇒ Object
20 21 22 |
# File 'lib/window/event_handler.rb', line 20 def remove(display, window) @instances[display].delete(window.id) if @instances[display] end |
.singleton(display, window) ⇒ Object
15 16 17 18 |
# File 'lib/window/event_handler.rb', line 15 def singleton(display, window) @instances[display] ||= {} @instances[display][window.id] ||= new(display, window) end |
Instance Method Details
#destroy ⇒ Object
52 53 54 |
# File 'lib/window/event_handler.rb', line 52 def destroy self.class.remove(@display, @window) end |
#handle(event) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/window/event_handler.rb', line 43 def handle(event) # duplicate the event handlers hash so it can be modified in one of # its handlers @event_handlers.dup.each do |mask, handlers| next unless handlers[event.name] handlers[event.name].dup.each{ |handler| handler.call(event) } end end |
#off(mask, event, handler = nil) ⇒ Object
38 39 40 41 |
# File 'lib/window/event_handler.rb', line 38 def off(mask, event, handler = nil) remove_event_handler(mask, event, handler) remove_event_mask(mask) end |
#on(mask, event, &handler) ⇒ Object
33 34 35 36 |
# File 'lib/window/event_handler.rb', line 33 def on(mask, event, &handler) add_event_mask(mask) add_event_handler(mask, event, &handler) end |