Class: Uh::WM::Runner
- Inherits:
-
Object
- Object
- Uh::WM::Runner
- Extended by:
- Forwardable
- Includes:
- EnvLogging
- Defined in:
- lib/uh/wm/runner.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
Instance Method Summary collapse
- #connect_manager ⇒ Object
- #evaluate_run_control ⇒ Object
-
#initialize(env, manager: nil, stopped: false) ⇒ Runner
constructor
A new instance of Runner.
- #manager ⇒ Object
- #register_event_hooks ⇒ Object
- #run_until(&block) ⇒ Object
- #stop! ⇒ Object
- #stopped? ⇒ Boolean
- #terminate ⇒ Object
- #worker ⇒ Object
Constructor Details
#initialize(env, manager: nil, stopped: false) ⇒ Runner
Returns a new instance of Runner.
22 23 24 25 26 27 28 29 |
# File 'lib/uh/wm/runner.rb', line 22 def initialize env, manager: nil, stopped: false @env = env @events = Dispatcher.new @manager = manager @actions = ActionsHandler.new(@env, @events) @stopped = stopped @rules = @env.rules end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
20 21 22 |
# File 'lib/uh/wm/runner.rb', line 20 def actions @actions end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
20 21 22 |
# File 'lib/uh/wm/runner.rb', line 20 def env @env end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
20 21 22 |
# File 'lib/uh/wm/runner.rb', line 20 def events @events end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
20 21 22 |
# File 'lib/uh/wm/runner.rb', line 20 def rules @rules end |
Class Method Details
.run(env, **options) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/uh/wm/runner.rb', line 7 def run env, ** runner = new env, ** runner.evaluate_run_control runner.register_event_hooks runner.connect_manager runner.run_until { runner.stopped? } runner.terminate end |
Instance Method Details
#connect_manager ⇒ Object
53 54 55 56 |
# File 'lib/uh/wm/runner.rb', line 53 def connect_manager manager.connect @env.keybinds.each { |keysym, _| manager.grab_key *keysym } end |
#evaluate_run_control ⇒ Object
43 44 45 |
# File 'lib/uh/wm/runner.rb', line 43 def evaluate_run_control RunControl.evaluate(env) end |
#manager ⇒ Object
39 40 41 |
# File 'lib/uh/wm/runner.rb', line 39 def manager @manager ||= Manager.new(@events, @env.modifier, @env.modifier_ignore) end |
#register_event_hooks ⇒ Object
47 48 49 50 51 |
# File 'lib/uh/wm/runner.rb', line 47 def register_event_hooks %w[runner manager layout keybinds rules launcher] .map { |e| "register_#{e}_hooks".to_sym } .each { |e| send e } end |
#run_until(&block) ⇒ Object
72 73 74 75 76 |
# File 'lib/uh/wm/runner.rb', line 72 def run_until &block worker.watch @manager log "Working events with `#{worker.class}'" worker.work_events until block.call end |
#stop! ⇒ Object
35 36 37 |
# File 'lib/uh/wm/runner.rb', line 35 def stop! @stopped = true end |
#stopped? ⇒ Boolean
31 32 33 |
# File 'lib/uh/wm/runner.rb', line 31 def stopped? !!@stopped end |
#terminate ⇒ Object
78 79 80 81 |
# File 'lib/uh/wm/runner.rb', line 78 def terminate log 'Terminating...' manager.disconnect end |
#worker ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/uh/wm/runner.rb', line 58 def worker @worker ||= Workers.build(*(@env.worker)).tap do |w| w.before_watch { @manager.flush } w.on_read { @manager.handle_pending_events } w.on_read_next { @manager.handle_next_event } w.on_timeout do log_debug 'Worker timeout, ticking...' @events.emit :tick log_debug 'Flushing X output buffer' @manager.flush end end end |