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
@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
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
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
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
Logs a separator string, can help during debug
# File lib/uh/wm/actions_handler.rb, line 66 def log_separator log '- ' * 24 end
Forwards unhandled messages prefixed with `layout_` to the layout, without the prefix @example
layout_foo # delegates to `layout.foo'
# 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
Requests the window manager to terminate
# File lib/uh/wm/actions_handler.rb, line 89 def quit log 'Quit requested' @events.emit :quit end
Checks method existence in layout @api private
# File lib/uh/wm/actions_handler.rb, line 96 def respond_to_missing? m, _ m.to_s =~ /\Alayout_/ || super end
Private Instance Methods
# File lib/uh/wm/actions_handler.rb, line 102 def layout_method m m.to_s.gsub(/\Alayout_/, 'handle_').to_sym end