obs-hotkey.h 9.4 KB

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