obs-hotkey.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /******************************************************************************
  2. Copyright (C) 2014-2015 by Ruwen Hahn <palana@stunned.de>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. typedef size_t obs_hotkey_id;
  19. typedef size_t obs_hotkey_pair_id;
  20. #ifndef SWIG
  21. #define OBS_INVALID_HOTKEY_ID (~(obs_hotkey_id)0)
  22. #define OBS_INVALID_HOTKEY_PAIR_ID (~(obs_hotkey_pair_id)0)
  23. #else
  24. const size_t OBS_INVALID_HOTKEY_ID = (size_t)-1;
  25. const size_t OBS_INVALID_HOTKEY_PAIR_ID = (size_t)-1;
  26. #endif
  27. #define XINPUT_MOUSE_LEN 33
  28. enum obs_key {
  29. #define OBS_HOTKEY(x) x,
  30. #include "obs-hotkeys.h"
  31. #undef OBS_HOTKEY
  32. OBS_KEY_LAST_VALUE //not an actual key
  33. };
  34. typedef enum obs_key obs_key_t;
  35. struct obs_key_combination {
  36. uint32_t modifiers;
  37. obs_key_t key;
  38. };
  39. typedef struct obs_key_combination obs_key_combination_t;
  40. typedef struct obs_hotkey obs_hotkey_t;
  41. typedef struct obs_hotkey_binding obs_hotkey_binding_t;
  42. enum obs_hotkey_registerer_type {
  43. OBS_HOTKEY_REGISTERER_FRONTEND,
  44. OBS_HOTKEY_REGISTERER_SOURCE,
  45. OBS_HOTKEY_REGISTERER_OUTPUT,
  46. OBS_HOTKEY_REGISTERER_ENCODER,
  47. OBS_HOTKEY_REGISTERER_SERVICE,
  48. };
  49. typedef enum obs_hotkey_registerer_type obs_hotkey_registerer_t;
  50. /* getter functions */
  51. EXPORT obs_hotkey_id obs_hotkey_get_id(const obs_hotkey_t *key);
  52. EXPORT const char *obs_hotkey_get_name(const obs_hotkey_t *key);
  53. EXPORT const char *obs_hotkey_get_description(const obs_hotkey_t *key);
  54. EXPORT obs_hotkey_registerer_t obs_hotkey_get_registerer_type(const obs_hotkey_t *key);
  55. EXPORT void *obs_hotkey_get_registerer(const obs_hotkey_t *key);
  56. EXPORT obs_hotkey_id obs_hotkey_get_pair_partner_id(const obs_hotkey_t *key);
  57. EXPORT obs_key_combination_t obs_hotkey_binding_get_key_combination(obs_hotkey_binding_t *binding);
  58. EXPORT obs_hotkey_id obs_hotkey_binding_get_hotkey_id(obs_hotkey_binding_t *binding);
  59. EXPORT obs_hotkey_t *obs_hotkey_binding_get_hotkey(obs_hotkey_binding_t *binding);
  60. /* setter functions */
  61. EXPORT void obs_hotkey_set_name(obs_hotkey_id id, const char *name);
  62. EXPORT void obs_hotkey_set_description(obs_hotkey_id id, const char *desc);
  63. EXPORT void obs_hotkey_pair_set_names(obs_hotkey_pair_id id, const char *name0, const char *name1);
  64. EXPORT void obs_hotkey_pair_set_descriptions(obs_hotkey_pair_id id, const char *desc0, const char *desc1);
  65. #ifndef SWIG
  66. struct obs_hotkeys_translations {
  67. const char *insert;
  68. const char *del;
  69. const char *home;
  70. const char *end;
  71. const char *page_up;
  72. const char *page_down;
  73. const char *num_lock;
  74. const char *scroll_lock;
  75. const char *caps_lock;
  76. const char *backspace;
  77. const char *tab;
  78. const char *print;
  79. const char *pause;
  80. const char *left;
  81. const char *right;
  82. const char *up;
  83. const char *down;
  84. const char *shift;
  85. const char *alt;
  86. const char *control;
  87. const char *meta; /* windows/super key */
  88. const char *menu;
  89. const char *space;
  90. const char *numpad_num; /* For example, "Numpad %1" */
  91. const char *numpad_divide;
  92. const char *numpad_multiply;
  93. const char *numpad_minus;
  94. const char *numpad_plus;
  95. const char *numpad_decimal;
  96. const char *apple_keypad_num; /* For example, "%1 (Keypad)" */
  97. const char *apple_keypad_divide;
  98. const char *apple_keypad_multiply;
  99. const char *apple_keypad_minus;
  100. const char *apple_keypad_plus;
  101. const char *apple_keypad_decimal;
  102. const char *apple_keypad_equal;
  103. const char *mouse_num; /* For example, "Mouse %1" */
  104. const char *escape;
  105. };
  106. /* This function is an optional way to provide translations for specific keys
  107. * that may not have translations. If the operating system can provide
  108. * translations for these keys, it will use the operating system's translation
  109. * over these translations. If no translations are specified, it will use
  110. * the default English translations for that specific operating system. */
  111. EXPORT void obs_hotkeys_set_translations_s(struct obs_hotkeys_translations *translations, size_t size);
  112. #endif
  113. #define obs_hotkeys_set_translations(translations) \
  114. obs_hotkeys_set_translations_s(translations, sizeof(struct obs_hotkeys_translations))
  115. EXPORT void obs_hotkeys_set_audio_hotkeys_translations(const char *mute, const char *unmute, const char *push_to_mute,
  116. const char *push_to_talk);
  117. EXPORT void obs_hotkeys_set_sceneitem_hotkeys_translations(const char *show, const char *hide);
  118. /* registering hotkeys (giving hotkeys a name and a function) */
  119. typedef void (*obs_hotkey_func)(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed);
  120. EXPORT obs_hotkey_id obs_hotkey_register_frontend(const char *name, const char *description, obs_hotkey_func func,
  121. void *data);
  122. EXPORT obs_hotkey_id obs_hotkey_register_encoder(obs_encoder_t *encoder, const char *name, const char *description,
  123. obs_hotkey_func func, void *data);
  124. EXPORT obs_hotkey_id obs_hotkey_register_output(obs_output_t *output, const char *name, const char *description,
  125. obs_hotkey_func func, void *data);
  126. EXPORT obs_hotkey_id obs_hotkey_register_service(obs_service_t *service, const char *name, const char *description,
  127. obs_hotkey_func func, void *data);
  128. EXPORT obs_hotkey_id obs_hotkey_register_source(obs_source_t *source, const char *name, const char *description,
  129. obs_hotkey_func func, void *data);
  130. typedef bool (*obs_hotkey_active_func)(void *data, obs_hotkey_pair_id id, obs_hotkey_t *hotkey, bool pressed);
  131. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_frontend(const char *name0, const char *description0,
  132. const char *name1, const char *description1,
  133. obs_hotkey_active_func func0, obs_hotkey_active_func func1,
  134. void *data0, void *data1);
  135. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_encoder(obs_encoder_t *encoder, const char *name0,
  136. const char *description0, const char *name1,
  137. const char *description1, obs_hotkey_active_func func0,
  138. obs_hotkey_active_func func1, void *data0, void *data1);
  139. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_output(obs_output_t *output, const char *name0,
  140. const char *description0, const char *name1,
  141. const char *description1, obs_hotkey_active_func func0,
  142. obs_hotkey_active_func func1, void *data0, void *data1);
  143. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_service(obs_service_t *service, const char *name0,
  144. const char *description0, const char *name1,
  145. const char *description1, obs_hotkey_active_func func0,
  146. obs_hotkey_active_func func1, void *data0, void *data1);
  147. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_source(obs_source_t *source, const char *name0,
  148. const char *description0, const char *name1,
  149. const char *description1, obs_hotkey_active_func func0,
  150. obs_hotkey_active_func func1, void *data0, void *data1);
  151. EXPORT void obs_hotkey_unregister(obs_hotkey_id id);
  152. EXPORT void obs_hotkey_pair_unregister(obs_hotkey_pair_id id);
  153. /* loading hotkeys (associating a hotkey with a physical key and modifiers) */
  154. EXPORT void obs_hotkey_load_bindings(obs_hotkey_id id, obs_key_combination_t *combinations, size_t num);
  155. EXPORT void obs_hotkey_load(obs_hotkey_id id, obs_data_array_t *data);
  156. EXPORT void obs_hotkeys_load_encoder(obs_encoder_t *encoder, obs_data_t *hotkeys);
  157. EXPORT void obs_hotkeys_load_output(obs_output_t *output, obs_data_t *hotkeys);
  158. EXPORT void obs_hotkeys_load_service(obs_service_t *service, obs_data_t *hotkeys);
  159. EXPORT void obs_hotkeys_load_source(obs_source_t *source, obs_data_t *hotkeys);
  160. EXPORT void obs_hotkey_pair_load(obs_hotkey_pair_id id, obs_data_array_t *data0, obs_data_array_t *data1);
  161. EXPORT obs_data_array_t *obs_hotkey_save(obs_hotkey_id id);
  162. EXPORT void obs_hotkey_pair_save(obs_hotkey_pair_id id, obs_data_array_t **p_data0, obs_data_array_t **p_data1);
  163. EXPORT obs_data_t *obs_hotkeys_save_encoder(obs_encoder_t *encoder);
  164. EXPORT obs_data_t *obs_hotkeys_save_output(obs_output_t *output);
  165. EXPORT obs_data_t *obs_hotkeys_save_service(obs_service_t *service);
  166. EXPORT obs_data_t *obs_hotkeys_save_source(obs_source_t *source);
  167. /* enumerating hotkeys */
  168. typedef bool (*obs_hotkey_enum_func)(void *data, obs_hotkey_id id, obs_hotkey_t *key);
  169. EXPORT void obs_enum_hotkeys(obs_hotkey_enum_func func, void *data);
  170. /* enumerating bindings */
  171. typedef bool (*obs_hotkey_binding_enum_func)(void *data, size_t idx, obs_hotkey_binding_t *binding);
  172. EXPORT void obs_enum_hotkey_bindings(obs_hotkey_binding_enum_func func, void *data);
  173. /* hotkey event control */
  174. EXPORT void obs_hotkey_inject_event(obs_key_combination_t hotkey, bool pressed);
  175. EXPORT void obs_hotkey_enable_background_press(bool enable);
  176. /* hotkey callback routing (trigger callbacks through e.g. a UI thread) */
  177. typedef void (*obs_hotkey_callback_router_func)(void *data, obs_hotkey_id id, bool pressed);
  178. EXPORT void obs_hotkey_set_callback_routing_func(obs_hotkey_callback_router_func func, void *data);
  179. EXPORT void obs_hotkey_trigger_routed_callback(obs_hotkey_id id, bool pressed);
  180. /* hotkey callbacks won't be processed if callback rerouting is enabled and no
  181. * router func is set */
  182. EXPORT void obs_hotkey_enable_callback_rerouting(bool enable);
  183. /* misc */
  184. typedef void (*obs_hotkey_atomic_update_func)(void *);
  185. EXPORT void obs_hotkey_update_atomic(obs_hotkey_atomic_update_func func, void *data);
  186. struct dstr;
  187. EXPORT void obs_key_to_str(obs_key_t key, struct dstr *str);
  188. EXPORT void obs_key_combination_to_str(obs_key_combination_t key, struct dstr *str);
  189. EXPORT obs_key_t obs_key_from_virtual_key(int code);
  190. EXPORT int obs_key_to_virtual_key(obs_key_t key);
  191. EXPORT const char *obs_key_to_name(obs_key_t key);
  192. EXPORT obs_key_t obs_key_from_name(const char *name);
  193. static inline bool obs_key_combination_is_empty(obs_key_combination_t combo)
  194. {
  195. return !combo.modifiers && combo.key == OBS_KEY_NONE;
  196. }
  197. #ifdef __cplusplus
  198. }
  199. #endif