obs-hotkey.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /******************************************************************************
  2. Copyright (C) 2014-2015 by Ruwen Hahn <[email protected]>
  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. enum obs_key {
  28. #define OBS_HOTKEY(x) x,
  29. #include "obs-hotkeys.h"
  30. #undef OBS_HOTKEY
  31. OBS_KEY_LAST_VALUE //not an actual key
  32. };
  33. typedef enum obs_key obs_key_t;
  34. struct obs_key_combination {
  35. uint32_t modifiers;
  36. obs_key_t key;
  37. };
  38. typedef struct obs_key_combination obs_key_combination_t;
  39. typedef struct obs_hotkey obs_hotkey_t;
  40. typedef struct obs_hotkey_binding obs_hotkey_binding_t;
  41. enum obs_hotkey_registerer_type {
  42. OBS_HOTKEY_REGISTERER_FRONTEND,
  43. OBS_HOTKEY_REGISTERER_SOURCE,
  44. OBS_HOTKEY_REGISTERER_OUTPUT,
  45. OBS_HOTKEY_REGISTERER_ENCODER,
  46. OBS_HOTKEY_REGISTERER_SERVICE,
  47. };
  48. typedef enum obs_hotkey_registerer_type obs_hotkey_registerer_t;
  49. EXPORT obs_hotkey_id obs_hotkey_get_id(const obs_hotkey_t *key);
  50. EXPORT const char *obs_hotkey_get_name(const obs_hotkey_t *key);
  51. EXPORT const char *obs_hotkey_get_description(const obs_hotkey_t *key);
  52. EXPORT obs_hotkey_registerer_t obs_hotkey_get_registerer_type(
  53. const obs_hotkey_t *key);
  54. EXPORT void *obs_hotkey_get_registerer(const obs_hotkey_t *key);
  55. EXPORT obs_hotkey_id obs_hotkey_get_pair_partner_id(const obs_hotkey_t *key);
  56. EXPORT obs_key_combination_t obs_hotkey_binding_get_key_combination(
  57. obs_hotkey_binding_t *binding);
  58. EXPORT obs_hotkey_id obs_hotkey_binding_get_hotkey_id(
  59. obs_hotkey_binding_t *binding);
  60. EXPORT obs_hotkey_t *obs_hotkey_binding_get_hotkey(
  61. obs_hotkey_binding_t *binding);
  62. #ifndef SWIG
  63. struct obs_hotkeys_translations {
  64. const char *insert;
  65. const char *del;
  66. const char *home;
  67. const char *end;
  68. const char *page_up;
  69. const char *page_down;
  70. const char *num_lock;
  71. const char *scroll_lock;
  72. const char *caps_lock;
  73. const char *backspace;
  74. const char *tab;
  75. const char *print;
  76. const char *pause;
  77. const char *left;
  78. const char *right;
  79. const char *up;
  80. const char *down;
  81. const char *shift;
  82. const char *alt;
  83. const char *control;
  84. const char *meta; /* windows/super key */
  85. const char *menu;
  86. const char *space;
  87. const char *numpad_num; /* For example, "Numpad %1" */
  88. const char *numpad_divide;
  89. const char *numpad_multiply;
  90. const char *numpad_minus;
  91. const char *numpad_plus;
  92. const char *numpad_decimal;
  93. const char *apple_keypad_num; /* For example, "%1 (Keypad)" */
  94. const char *apple_keypad_divide;
  95. const char *apple_keypad_multiply;
  96. const char *apple_keypad_minus;
  97. const char *apple_keypad_plus;
  98. const char *apple_keypad_decimal;
  99. const char *apple_keypad_equal;
  100. const char *mouse_num; /* For example, "Mouse %1" */
  101. };
  102. /* This function is an optional way to provide translations for specific keys
  103. * that may not have translations. If the operating system can provide
  104. * translations for these keys, it will use the operating system's translation
  105. * over these translations. If no translations are specified, it will use
  106. * the default English translations for that specific operating system. */
  107. EXPORT void obs_hotkeys_set_translations_s(
  108. struct obs_hotkeys_translations *translations, size_t size);
  109. #endif
  110. #define obs_hotkeys_set_translations(translations) \
  111. obs_hotkeys_set_translations_s(translations, \
  112. sizeof(struct obs_hotkeys_translations))
  113. EXPORT void obs_hotkeys_set_audio_hotkeys_translations(
  114. const char *mute, const char *unmute,
  115. const char *push_to_mute, const char *push_to_talk);
  116. EXPORT void obs_hotkeys_set_sceneitem_hotkeys_translations(
  117. const char *show, const char *hide);
  118. /* registering hotkeys (giving hotkeys a name and a function) */
  119. typedef void (*obs_hotkey_func)(void *data,
  120. obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed);
  121. EXPORT obs_hotkey_id obs_hotkey_register_frontend(const char *name,
  122. const char *description, obs_hotkey_func func, void *data);
  123. EXPORT obs_hotkey_id obs_hotkey_register_encoder(obs_encoder_t *encoder,
  124. const char *name, const char *description,
  125. obs_hotkey_func func, void *data);
  126. EXPORT obs_hotkey_id obs_hotkey_register_output(obs_output_t *output,
  127. const char *name, const char *description,
  128. obs_hotkey_func func, void *data);
  129. EXPORT obs_hotkey_id obs_hotkey_register_service(obs_service_t *service,
  130. const char *name, const char *description,
  131. obs_hotkey_func func, void *data);
  132. EXPORT obs_hotkey_id obs_hotkey_register_source(obs_source_t *source,
  133. const char *name, const char *description,
  134. obs_hotkey_func func, void *data);
  135. typedef bool (*obs_hotkey_active_func)(void *data,
  136. obs_hotkey_pair_id id, obs_hotkey_t *hotkey, bool pressed);
  137. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_frontend(
  138. const char *name0, const char *description0,
  139. const char *name1, const char *description1,
  140. obs_hotkey_active_func func0, obs_hotkey_active_func func1,
  141. void *data0, void *data1);
  142. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_encoder(
  143. obs_encoder_t *encoder,
  144. const char *name0, const char *description0,
  145. const char *name1, const char *description1,
  146. obs_hotkey_active_func func0, obs_hotkey_active_func func1,
  147. void *data0, void *data1);
  148. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_output(
  149. obs_output_t *output,
  150. const char *name0, const char *description0,
  151. const char *name1, const char *description1,
  152. obs_hotkey_active_func func0, obs_hotkey_active_func func1,
  153. void *data0, void *data1);
  154. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_service(
  155. obs_service_t *service,
  156. const char *name0, const char *description0,
  157. const char *name1, const char *description1,
  158. obs_hotkey_active_func func0, obs_hotkey_active_func func1,
  159. void *data0, void *data1);
  160. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_source(
  161. obs_source_t *source,
  162. const char *name0, const char *description0,
  163. const char *name1, const char *description1,
  164. obs_hotkey_active_func func0, obs_hotkey_active_func func1,
  165. void *data0, void *data1);
  166. EXPORT void obs_hotkey_unregister(obs_hotkey_id id);
  167. EXPORT void obs_hotkey_pair_unregister(obs_hotkey_pair_id id);
  168. /* loading hotkeys (associating a hotkey with a physical key and modifiers) */
  169. EXPORT void obs_hotkey_load_bindings(obs_hotkey_id id,
  170. obs_key_combination_t *combinations, size_t num);
  171. EXPORT void obs_hotkey_load(obs_hotkey_id id, obs_data_array_t *data);
  172. EXPORT void obs_hotkeys_load_encoder(obs_encoder_t *encoder,
  173. obs_data_t *hotkeys);
  174. EXPORT void obs_hotkeys_load_output(obs_output_t *output, obs_data_t *hotkeys);
  175. EXPORT void obs_hotkeys_load_service(obs_service_t *service,
  176. obs_data_t *hotkeys);
  177. EXPORT void obs_hotkeys_load_source(obs_source_t *source, obs_data_t *hotkeys);
  178. EXPORT void obs_hotkey_pair_load(obs_hotkey_pair_id id, obs_data_array_t *data0,
  179. obs_data_array_t *data1);
  180. EXPORT obs_data_array_t *obs_hotkey_save(obs_hotkey_id id);
  181. EXPORT obs_data_t *obs_hotkeys_save_encoder(obs_encoder_t *encoder);
  182. EXPORT obs_data_t *obs_hotkeys_save_output(obs_output_t *output);
  183. EXPORT obs_data_t *obs_hotkeys_save_service(obs_service_t *service);
  184. EXPORT obs_data_t *obs_hotkeys_save_source(obs_source_t *source);
  185. /* enumerating hotkeys */
  186. typedef bool (*obs_hotkey_enum_func)(void *data,
  187. obs_hotkey_id id, obs_hotkey_t *key);
  188. EXPORT void obs_enum_hotkeys(obs_hotkey_enum_func func, void *data);
  189. /* enumerating bindings */
  190. typedef bool (*obs_hotkey_binding_enum_func)(void *data,
  191. size_t idx, obs_hotkey_binding_t* binding);
  192. EXPORT void obs_enum_hotkey_bindings(obs_hotkey_binding_enum_func func,
  193. void *data);
  194. /* hotkey event control */
  195. EXPORT void obs_hotkey_inject_event(obs_key_combination_t hotkey, bool pressed);
  196. EXPORT void obs_hotkey_enable_background_press(bool enable);
  197. EXPORT void obs_hotkey_enable_strict_modifiers(bool enable);
  198. /* hotkey callback routing (trigger callbacks through e.g. a UI thread) */
  199. typedef void (*obs_hotkey_callback_router_func)(void *data,
  200. obs_hotkey_id id, bool pressed);
  201. EXPORT void obs_hotkey_set_callback_routing_func(obs_hotkey_callback_router_func
  202. func, void *data);
  203. EXPORT void obs_hotkey_trigger_routed_callback(obs_hotkey_id id, bool pressed);
  204. /* hotkey callbacks won't be processed if callback rerouting is enabled and no
  205. * router func is set */
  206. EXPORT void obs_hotkey_enable_callback_rerouting(bool enable);
  207. /* misc */
  208. typedef void (*obs_hotkey_atomic_update_func)(void *);
  209. EXPORT void obs_hotkey_update_atomic(obs_hotkey_atomic_update_func func,
  210. void *data);
  211. struct dstr;
  212. EXPORT void obs_key_to_str(obs_key_t key, struct dstr *str);
  213. EXPORT void obs_key_combination_to_str(obs_key_combination_t key,
  214. struct dstr *str);
  215. EXPORT obs_key_t obs_key_from_virtual_key(int code);
  216. EXPORT int obs_key_to_virtual_key(obs_key_t key);
  217. EXPORT const char *obs_key_to_name(obs_key_t key);
  218. EXPORT obs_key_t obs_key_from_name(const char *name);
  219. static inline bool obs_key_combination_is_empty(obs_key_combination_t combo)
  220. {
  221. return !combo.modifiers && combo.key == OBS_KEY_NONE;
  222. }
  223. #ifdef __cplusplus
  224. }
  225. #endif