Class: Uh::WM::Runner

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
EnvLogging
Defined in:
lib/uh/wm/runner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#actionsObject (readonly)

Returns the value of attribute actions.



20
21
22
# File 'lib/uh/wm/runner.rb', line 20

def actions
  @actions
end

#envObject (readonly)

Returns the value of attribute env.



20
21
22
# File 'lib/uh/wm/runner.rb', line 20

def env
  @env
end

#eventsObject (readonly)

Returns the value of attribute events.



20
21
22
# File 'lib/uh/wm/runner.rb', line 20

def events
  @events
end

#rulesObject (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, **options
  runner = new env, **options
  runner.evaluate_run_control
  runner.register_event_hooks
  runner.connect_manager
  runner.run_until { runner.stopped? }
  runner.terminate
end

Instance Method Details

#connect_managerObject



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_controlObject



43
44
45
# File 'lib/uh/wm/runner.rb', line 43

def evaluate_run_control
  RunControl.evaluate(env)
end

#managerObject



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_hooksObject



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

Returns:

  • (Boolean)


31
32
33
# File 'lib/uh/wm/runner.rb', line 31

def stopped?
  !!@stopped
end

#terminateObject



78
79
80
81
# File 'lib/uh/wm/runner.rb', line 78

def terminate
  log 'Terminating...'
  manager.disconnect
end

#workerObject



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