Class: Uh::WM::RunControl
- Inherits:
-
Object
- Object
- Uh::WM::RunControl
- Defined in:
- lib/uh/wm/run_control.rb
Overview
Provides the context and behavior for run control file evaluation.
Constant Summary collapse
- KEYSYM_TRANSLATIONS =
Key sym translations for key bindings.
{ backspace: :BackSpace, enter: :Return, return: :Return, tab: :Tab }.freeze
Class Method Summary collapse
-
.evaluate(env) ⇒ Object
private
Builds an instance and evaluates any run control file defined in the given Env instance.
Instance Method Summary collapse
-
#evaluate(code, path) ⇒ Object
private
Evaluates run control code.
-
#initialize(env) ⇒ RunControl
constructor
private
A new instance of RunControl.
-
#key(*keysyms, &block) ⇒ Object
Registers a key binding.
-
#launch(&block) ⇒ Object
Declares code to execute on window manager connection.
-
#layout(arg, options = {}) ⇒ Object
Defines the layout with either a layout class or an instance with optional layout options.
-
#modifier(keysym, ignore: []) ⇒ Object
Defines the modifier masks to use for key bindings.
-
#rule(selectors = '', &block) ⇒ Object
Declares a client rule.
-
#worker(type, **options) ⇒ Object
Configures the worker.
Constructor Details
#initialize(env) ⇒ RunControl
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RunControl.
27 28 29 |
# File 'lib/uh/wm/run_control.rb', line 27 def initialize env @env = env end |
Class Method Details
.evaluate(env) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds an instance and evaluates any run control file defined in the given Env instance
18 19 20 21 22 |
# File 'lib/uh/wm/run_control.rb', line 18 def evaluate env rc_path = File.(env.rc_path) rc = new env rc.evaluate File.read(rc_path), rc_path if File.exist?(rc_path) end |
Instance Method Details
#evaluate(code, path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Evaluates run control code
35 36 37 38 39 |
# File 'lib/uh/wm/run_control.rb', line 35 def evaluate code, path instance_eval code, path rescue ::StandardError, ::ScriptError => e raise RunControlEvaluationError, e., e.backtrace end |
#key(*keysyms, &block) ⇒ Object
Registers a key binding
53 54 55 |
# File 'lib/uh/wm/run_control.rb', line 53 def key *keysyms, &block @env.keybinds[translate_keysym *keysyms] = block end |
#launch(&block) ⇒ Object
Declares code to execute on window manager connection
62 63 64 |
# File 'lib/uh/wm/run_control.rb', line 62 def launch &block @env.launch = block end |
#layout(arg, options = {}) ⇒ Object
Defines the layout with either a layout class or an instance with optional layout options. When given only a hash, configures options for the default layout and ignores the ‘options` parameter.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/uh/wm/run_control.rb', line 78 def layout arg, = {} case arg when Class if .any? @env.layout = arg.new else @env.layout_class = arg end when Hash @env. = arg else @env.layout = arg end end |
#modifier(keysym, ignore: []) ⇒ Object
Defines the modifier masks to use for key bindings
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/uh/wm/run_control.rb', line 98 def modifier keysym, ignore: [] [keysym, *ignore].each do |mod| unless KEY_MODIFIERS.keys.include? mod fail RunControlArgumentError, "invalid modifier keysym `#{mod.inspect}'" end end @env.modifier = keysym @env.modifier_ignore = [*ignore] end |
#rule(selectors = '', &block) ⇒ Object
Declares a client rule
118 119 120 |
# File 'lib/uh/wm/run_control.rb', line 118 def rule selectors = '', &block [*selectors].each { |selector| @env.rules[/\A#{selector}/i] = block } end |
#worker(type, **options) ⇒ Object
Configures the worker
132 133 134 135 136 137 |
# File 'lib/uh/wm/run_control.rb', line 132 def worker type, ** unless Workers.type? type fail RunControlArgumentError, "invalid worker type `#{type}'" end @env.worker = [type, ] end |