xkb_glfw.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //========================================================================
  2. // GLFW 3.4 XKB - www.glfw.org
  3. //------------------------------------------------------------------------
  4. // Copyright (c) 2018 Kovid Goyal <kovid@kovidgoyal.net>
  5. //
  6. // This software is provided 'as-is', without any express or implied
  7. // warranty. In no event will the authors be held liable for any damages
  8. // arising from the use of this software.
  9. //
  10. // Permission is granted to anyone to use this software for any purpose,
  11. // including commercial applications, and to alter it and redistribute it
  12. // freely, subject to the following restrictions:
  13. //
  14. // 1. The origin of this software must not be misrepresented; you must not
  15. // claim that you wrote the original software. If you use this software
  16. // in a product, an acknowledgment in the product documentation would
  17. // be appreciated but is not required.
  18. //
  19. // 2. Altered source versions must be plainly marked as such, and must not
  20. // be misrepresented as being the original software.
  21. //
  22. // 3. This notice may not be removed or altered from any source
  23. // distribution.
  24. //
  25. //========================================================================
  26. #pragma once
  27. #include <xkbcommon/xkbcommon.h>
  28. #include <xkbcommon/xkbcommon-compose.h>
  29. #ifdef _GLFW_X11
  30. #include <xkbcommon/xkbcommon-x11.h>
  31. #endif
  32. #include "ibus_glfw.h"
  33. typedef struct {
  34. struct xkb_state* state;
  35. struct xkb_state* clean_state;
  36. struct xkb_state* default_state;
  37. struct xkb_compose_state* composeState;
  38. xkb_mod_mask_t activeUnknownModifiers;
  39. unsigned int modifiers;
  40. } XKBStateGroup;
  41. typedef struct {
  42. struct xkb_context* context;
  43. struct xkb_keymap* keymap;
  44. struct xkb_keymap* default_keymap;
  45. XKBStateGroup states;
  46. xkb_mod_index_t controlIdx;
  47. xkb_mod_index_t altIdx;
  48. xkb_mod_index_t shiftIdx;
  49. xkb_mod_index_t superIdx;
  50. xkb_mod_index_t hyperIdx;
  51. xkb_mod_index_t metaIdx;
  52. xkb_mod_index_t capsLockIdx;
  53. xkb_mod_index_t numLockIdx;
  54. xkb_mod_mask_t controlMask;
  55. xkb_mod_mask_t altMask;
  56. xkb_mod_mask_t shiftMask;
  57. xkb_mod_mask_t superMask;
  58. xkb_mod_mask_t hyperMask;
  59. xkb_mod_mask_t metaMask;
  60. xkb_mod_mask_t capsLockMask;
  61. xkb_mod_mask_t numLockMask;
  62. xkb_mod_index_t unknownModifiers[256];
  63. _GLFWIBUSData ibus;
  64. #ifdef _GLFW_X11
  65. int32_t keyboard_device_id;
  66. bool available;
  67. bool detectable;
  68. int majorOpcode;
  69. int eventBase;
  70. int errorBase;
  71. int major;
  72. int minor;
  73. #endif
  74. } _GLFWXKBData;
  75. #ifdef _GLFW_X11
  76. bool glfw_xkb_set_x11_events_mask(void);
  77. bool glfw_xkb_update_x11_keyboard_id(_GLFWXKBData *xkb);
  78. #endif
  79. void glfw_xkb_release(_GLFWXKBData *xkb);
  80. bool glfw_xkb_create_context(_GLFWXKBData *xkb);
  81. bool glfw_xkb_compile_keymap(_GLFWXKBData *xkb, const char *map_str);
  82. void glfw_xkb_update_modifiers(_GLFWXKBData *xkb, xkb_mod_mask_t depressed, xkb_mod_mask_t latched, xkb_mod_mask_t locked, xkb_layout_index_t base_group, xkb_layout_index_t latched_group, xkb_layout_index_t locked_group);
  83. bool glfw_xkb_should_repeat(_GLFWXKBData *xkb, xkb_keycode_t keycode);
  84. const char* glfw_xkb_keysym_name(xkb_keysym_t sym);
  85. xkb_keysym_t glfw_xkb_sym_for_key(uint32_t key);
  86. void glfw_xkb_handle_key_event(_GLFWwindow *window, _GLFWXKBData *xkb, xkb_keycode_t keycode, int action);
  87. int glfw_xkb_keysym_from_name(const char *name, bool case_sensitive);
  88. void glfw_xkb_update_ime_state(_GLFWwindow *w, _GLFWXKBData *xkb, const GLFWIMEUpdateEvent *ev);
  89. void glfw_xkb_key_from_ime(_GLFWIBUSKeyEvent *ev, bool handled_by_ime, bool failed);
  90. void glfw_xkb_forwarded_key_from_ime(xkb_keysym_t keysym, unsigned int glfw_mods);