platform_helpers.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. def keyconfig_data_oskey_from_ctrl(keyconfig_data_src, filter_fn=None):
  19. keyconfig_data_dst = []
  20. for km_name, km_parms, km_items_data_src in keyconfig_data_src:
  21. km_items_data_dst = km_items_data_src.copy()
  22. items_dst = []
  23. km_items_data_dst["items"] = items_dst
  24. for item_src in km_items_data_src["items"]:
  25. item_op, item_event, item_prop = item_src
  26. if "ctrl" in item_event:
  27. if filter_fn is None or filter_fn(item_event):
  28. item_event = item_event.copy()
  29. item_event["oskey"] = item_event["ctrl"]
  30. del item_event["ctrl"]
  31. items_dst.append((item_op, item_event, item_prop))
  32. items_dst.append(item_src)
  33. keyconfig_data_dst.append((km_name, km_parms, km_items_data_dst))
  34. return keyconfig_data_dst
  35. def keyconfig_data_oskey_from_ctrl_for_macos(keyconfig_data_src):
  36. """Use for apple since Cmd is typically used in-place of Ctrl."""
  37. def filter_fn(item_event):
  38. if (item_event["type"] in {
  39. 'H',
  40. 'M',
  41. 'SPACE',
  42. 'W',
  43. }) and (
  44. item_event.get("ctrl") and
  45. (not item_event.get("alt")) and
  46. (not item_event.get("shift"))
  47. ):
  48. return False
  49. return True
  50. return keyconfig_data_oskey_from_ctrl(keyconfig_data_src, filter_fn)