obs-hotkey.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. EXPORT void obs_hotkeys_set_sceneitem_hotkeys_translations(
  110. const char *show, const char *hide);
  111. /* registering hotkeys (giving hotkeys a name and a function) */
  112. typedef void (*obs_hotkey_func)(void *data,
  113. obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed);
  114. EXPORT obs_hotkey_id obs_hotkey_register_frontend(const char *name,
  115. const char *description, obs_hotkey_func func, void *data);
  116. EXPORT obs_hotkey_id obs_hotkey_register_encoder(obs_encoder_t *encoder,
  117. const char *name, const char *description,
  118. obs_hotkey_func func, void *data);
  119. EXPORT obs_hotkey_id obs_hotkey_register_output(obs_output_t *output,
  120. const char *name, const char *description,
  121. obs_hotkey_func func, void *data);
  122. EXPORT obs_hotkey_id obs_hotkey_register_service(obs_service_t *service,
  123. const char *name, const char *description,
  124. obs_hotkey_func func, void *data);
  125. EXPORT obs_hotkey_id obs_hotkey_register_source(obs_source_t *source,
  126. const char *name, const char *description,
  127. obs_hotkey_func func, void *data);
  128. typedef bool (*obs_hotkey_active_func)(void *data,
  129. obs_hotkey_pair_id id, obs_hotkey_t *hotkey, bool pressed);
  130. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_frontend(
  131. 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(
  136. obs_encoder_t *encoder,
  137. const char *name0, const char *description0,
  138. const char *name1, const char *description1,
  139. obs_hotkey_active_func func0, obs_hotkey_active_func func1,
  140. void *data0, void *data1);
  141. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_output(
  142. obs_output_t *output,
  143. const char *name0, const char *description0,
  144. const char *name1, const char *description1,
  145. obs_hotkey_active_func func0, obs_hotkey_active_func func1,
  146. void *data0, void *data1);
  147. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_service(
  148. obs_service_t *service,
  149. const char *name0, const char *description0,
  150. const char *name1, const char *description1,
  151. obs_hotkey_active_func func0, obs_hotkey_active_func func1,
  152. void *data0, void *data1);
  153. EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_source(
  154. obs_source_t *source,
  155. const char *name0, const char *description0,
  156. const char *name1, const char *description1,
  157. obs_hotkey_active_func func0, obs_hotkey_active_func func1,
  158. void *data0, void *data1);
  159. EXPORT void obs_hotkey_unregister(obs_hotkey_id id);
  160. EXPORT void obs_hotkey_pair_unregister(obs_hotkey_pair_id id);
  161. /* loading hotkeys (associating a hotkey with a physical key and modifiers) */
  162. EXPORT void obs_hotkey_load_bindings(obs_hotkey_id id,
  163. obs_key_combination_t *combinations, size_t num);
  164. EXPORT void obs_hotkey_load(obs_hotkey_id id, obs_data_array_t *data);
  165. EXPORT void obs_hotkeys_load_encoder(obs_encoder_t *encoder,
  166. obs_data_t *hotkeys);
  167. EXPORT void obs_hotkeys_load_output(obs_output_t *output, obs_data_t *hotkeys);
  168. EXPORT void obs_hotkeys_load_service(obs_service_t *service,
  169. obs_data_t *hotkeys);
  170. EXPORT void obs_hotkeys_load_source(obs_source_t *source, obs_data_t *hotkeys);
  171. EXPORT void obs_hotkey_pair_load(obs_hotkey_pair_id id, obs_data_array_t *data0,
  172. obs_data_array_t *data1);
  173. EXPORT obs_data_array_t *obs_hotkey_save(obs_hotkey_id id);
  174. EXPORT obs_data_t *obs_hotkeys_save_encoder(obs_encoder_t *encoder);
  175. EXPORT obs_data_t *obs_hotkeys_save_output(obs_output_t *output);
  176. EXPORT obs_data_t *obs_hotkeys_save_service(obs_service_t *service);
  177. EXPORT obs_data_t *obs_hotkeys_save_source(obs_source_t *source);
  178. /* enumerating hotkeys */
  179. typedef bool (*obs_hotkey_enum_func)(void *data,
  180. obs_hotkey_id id, obs_hotkey_t *key);
  181. EXPORT void obs_enum_hotkeys(obs_hotkey_enum_func func, void *data);
  182. /* enumerating bindings */
  183. typedef bool (*obs_hotkey_binding_enum_func)(void *data,
  184. size_t idx, obs_hotkey_binding_t* binding);
  185. EXPORT void obs_enum_hotkey_bindings(obs_hotkey_binding_enum_func func,
  186. void *data);
  187. /* hotkey event control */
  188. EXPORT void obs_hotkey_inject_event(obs_key_combination_t hotkey, bool pressed);
  189. EXPORT void obs_hotkey_enable_background_press(bool enable);
  190. EXPORT void obs_hotkey_enable_strict_modifiers(bool enable);
  191. /* hotkey callback routing (trigger callbacks through e.g. a UI thread) */
  192. typedef void (*obs_hotkey_callback_router_func)(void *data,
  193. obs_hotkey_id id, bool pressed);
  194. EXPORT void obs_hotkey_set_callback_routing_func(obs_hotkey_callback_router_func
  195. func, void *data);
  196. EXPORT void obs_hotkey_trigger_routed_callback(obs_hotkey_id id, bool pressed);
  197. /* hotkey callbacks won't be processed if callback rerouting is enabled and no
  198. * router func is set */
  199. EXPORT void obs_hotkey_enable_callback_rerouting(bool enable);
  200. /* misc */
  201. typedef void (*obs_hotkey_atomic_update_func)(void *);
  202. EXPORT void obs_hotkey_update_atomic(obs_hotkey_atomic_update_func func,
  203. void *data);
  204. struct dstr;
  205. EXPORT void obs_key_to_str(obs_key_t key, struct dstr *str);
  206. EXPORT void obs_key_combination_to_str(obs_key_combination_t key,
  207. struct dstr *str);
  208. EXPORT obs_key_t obs_key_from_virtual_key(int code);
  209. EXPORT int obs_key_to_virtual_key(obs_key_t key);
  210. EXPORT const char *obs_key_to_name(obs_key_t key);
  211. EXPORT obs_key_t obs_key_from_name(const char *name);
  212. inline bool obs_key_combination_is_empty(obs_key_combination_t combo)
  213. {
  214. return !combo.modifiers && combo.key == OBS_KEY_NONE;
  215. }
  216. #ifdef __cplusplus
  217. }
  218. #endif