Accept modifier in `key' run control keyword

This commit is contained in:
Thibault Jouan 2015-04-19 01:12:35 +00:00
parent 231e72df42
commit 6c7b01c9aa
3 changed files with 17 additions and 3 deletions

View File

@ -8,6 +8,14 @@ Feature: `key' run control keyword
When I press the alt+f keys
Then the output must contain "trigger f key code"
Scenario: defines code to run when given keys are pressed
Given uhwm is running with this run control file:
"""
key(:f, :shift) { puts 'trigger f key code' }
"""
When I press the alt+shift+f keys
Then the output must contain "trigger f key code"
Scenario: translates common key names to their X equivalent
Given uhwm is running with this run control file:
"""

View File

@ -28,8 +28,8 @@ module Uh
@env.modifier = mod
end
def key keysym, &block
@env.keybinds[translate_keysym keysym] = block
def key *keysyms, &block
@env.keybinds[translate_keysym *keysyms] = block
end
def worker type, **options
@ -39,7 +39,8 @@ module Uh
private
def translate_keysym keysym
def translate_keysym keysym, modifier = nil
return [translate_keysym(keysym)[0].to_sym, modifier] if modifier
translate_key = keysym.to_s.downcase.to_sym
translated_keysym = KEYSYM_TRANSLATIONS.key?(translate_key) ?
KEYSYM_TRANSLATIONS[translate_key] :

View File

@ -65,6 +65,11 @@ module Uh
expect(env.keybinds.keys).to include :f
end
it 'registers a combined keys binding in the env' do
rc.key :f, :shift, &code
expect(env.keybinds.keys).to include %i[f shift]
end
it 'registers given block with the key binding' do
rc.key :f, &code
expect(env.keybinds[:f].call).to eq :keybind_code