obs-hotkey.h 10 KB

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