Skip to content

Commit

Permalink
fix modifier filter no key header bug
Browse files Browse the repository at this point in the history
  • Loading branch information
loggerhead committed May 19, 2016
1 parent cfe2722 commit 933cf5d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion easy_karabiner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '0.5.0'
__version__ = '0.5.1'

19 changes: 12 additions & 7 deletions easy_karabiner/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def escape_filter_name(cls, class_name, name_val):
elif class_name == 'DeviceProductFilter':
name_val = 'DeviceProduct::%s' % name_val
elif class_name == 'ModifierFilter':
name_val = KeymapCreater.get_karabiner_format_key(name_val)
name_val = KeymapCreater.get_karabiner_format_key(name_val, key_header='ModifierFlag')
return name_val


Expand Down Expand Up @@ -211,16 +211,21 @@ def create(cls, raw_keymap):
raise exception.InvalidKeymapException(raw_keymap)

@classmethod
def get_karabiner_format_key(cls, key):
if len(key.split('::', 1)) < 2:
def get_karabiner_format_key(cls, key, key_header=None):
key_parts = key.split('::', 1)

if len(key_parts) < 2:
key = query.get_key_alias(key.lower()) or key

for k in [key, key.upper(), key.lower()]:
key_header = query.KeyHeaderQuery.query(k)
if key_header:
return "%s::%s" % (key_header, k)
predefined_header = query.KeyHeaderQuery.query(k)
if predefined_header:
return "%s::%s" % (predefined_header, k)

return key
if key_header:
return "%s::%s" % (key_header, key_parts[-1])
else:
return key


class DefinitionCreater(object):
Expand Down
2 changes: 1 addition & 1 deletion easy_karabiner/factory.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class KeymapCreater(object):
def create(cls, raw_keymap: RawKeymap) -> KeyToKeyBase: ...

@classmethod
def get_karabiner_format_key(cls, key: str) -> str: ...
def get_karabiner_format_key(cls, key: str, key_header: str = None) -> str: ...


class DefinitionCreater(object):
Expand Down
4 changes: 4 additions & 0 deletions samples/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# device
'CHERRY_3494': ['0x046a', '0x0011'],
'UIElementRole::自定义UI组件': '用作 filter',
# modifierdef
'Modifier::KEYLOCK': '',
}

MAPS = [
Expand All @@ -17,4 +19,6 @@
['alt X', 'Xee³.app', ['Finder', 'cmd']],
['__FlipScrollWheel__', 'flipscrollwheel_vertical', ['Xee³.app', 'built_in_keyboard_and_trackpad']],
['ctrl cmd F', 'cmd F', ['VIRTUALMACHINE']],
['alt', 'none', ['KEYLOCK']],
['cmd', 'none', ['Modifier::KEYLOCK']],
]
12 changes: 12 additions & 0 deletions samples/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<vendorname>built_in_keyboard_and_trackpad_VENDOR</vendorname>
<vendorid>0x05ac</vendorid>
</devicevendordef>
<modifierdef>KEYLOCK</modifierdef>
<replacementdef>
<replacementname>可以是中文</replacementname>
<replacementvalue>比如, hello, Xee³</replacementvalue>
Expand Down Expand Up @@ -110,6 +111,17 @@
KeyCode::F, ModifierFlag::COMMAND_L
</autogen>
</block>
<block>
<modifier_only>ModifierFlag::KEYLOCK</modifier_only>
<autogen> __KeyToKey__
KeyCode::OPTION_L,
KeyCode::NONE
</autogen>
<autogen> __KeyToKey__
KeyCode::COMMAND_L,
KeyCode::NONE
</autogen>
</block>
</item>
</item>
</root>

0 comments on commit 933cf5d

Please sign in to comment.