class Uh::WM::ActionsHandler

Provides a context with helper methods for key bindings ({RunControl#key}), client rules ({RunControl#rule}) and the {Launcher} ({RunControl#launch}).

Public Class Methods

new(env, events) click to toggle source

@api private @param env [Env] An environment @param events [Dispatcher] A dispatcher

# File lib/uh/wm/actions_handler.rb, line 19
def initialize env, events
  @env    = env
  @events = events
end

Public Instance Methods

evaluate(code = nil, &block) click to toggle source

Evaluates action code given as normal argument or block parameter @api private @param code [Proc] Action code @param block [Proc] Action code

# File lib/uh/wm/actions_handler.rb, line 28
def evaluate code = nil, &block
  if code
    instance_exec &code
  else
    instance_exec &block
  end
end
execute(command) click to toggle source

Executes given command. Forks twice, creates a new session and makes the new process the session leader and process group leader of a new process group. The new process has no controlling terminal. Refer to `fork(2)` and `setsid(2)` for more detail.

`command` argument is executed with `Kernel#exec`.

@param command [String, Array] Command to execute

# File lib/uh/wm/actions_handler.rb, line 44
def execute command
  log "Execute: #{command}"
  pid = fork do
    fork do
      Process.setsid
      begin
        exec command
      rescue Errno::ENOENT => e
        log_error "ExecuteError: #{e}"
      end
    end
  end
  Process.waitpid pid
end
kill_current() click to toggle source

Kills layout current client (focused) with {Client#kill}

# File lib/uh/wm/actions_handler.rb, line 60
def kill_current
  return unless layout.current_client
  layout.current_client.kill
end
log_separator() click to toggle source

Logs a separator string, can help during debug

# File lib/uh/wm/actions_handler.rb, line 66
def log_separator
  log '- ' * 24
end
method_missing(m, *args, &block) click to toggle source

Forwards unhandled messages prefixed with `layout_` to the layout, without the prefix @example

layout_foo # delegates to `layout.foo'
Calls superclass method
# File lib/uh/wm/actions_handler.rb, line 74
def method_missing m, *args, &block
  if respond_to? m
    meth = layout_method m
    log "#{layout.class.name}##{meth} #{args.inspect}"
    begin
      layout.send meth, *args
    rescue NoMethodError
      log_error "Layout does not implement `#{meth}'"
    end
  else
    super
  end
end
quit() click to toggle source

Requests the window manager to terminate

# File lib/uh/wm/actions_handler.rb, line 89
def quit
  log 'Quit requested'
  @events.emit :quit
end
respond_to_missing?(m, _) click to toggle source

Checks method existence in layout @api private

Calls superclass method
# File lib/uh/wm/actions_handler.rb, line 96
def respond_to_missing? m, _
  m.to_s =~ /\Alayout_/ || super
end

Private Instance Methods

layout_method(m) click to toggle source
# File lib/uh/wm/actions_handler.rb, line 102
def layout_method m
  m.to_s.gsub(/\Alayout_/, 'handle_').to_sym
end