UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
keyboard_control.h File Reference
#include "utils/macros.h"
#include <cinttypes>
#include <cstddef>
#include <memory>
Include dependency graph for keyboard_control.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  keyboard_control
 

Macros

#define K_ALT(x)
 
#define K_CTRL(x)
 
#define K_CTRL_DOWN   0x1b5b313b3542LL
 
#define K_CTRL_UP   0x1b5b313b3541LL
 
#define K_DOWN   0x1b5b42
 
#define K_LEFT   0x1b5b44
 
#define K_PGDOWN   0x1b5b367e
 
#define K_PGUP   0x1b5b357e
 
#define K_RIGHT   0x1b5b43
 
#define K_UP   0x1b5b41
 
#define MAX_KEYCODE_NAME_LEN   8
 

Functions

EXTERN_C void get_keycode_name (int64_t ch, char *buf, size_t buflen) __attribute__((used))
 
EXTERN_C bool keycontrol_register_key (struct module *sender_mod, int64_t key, const char *message, const char *description) __attribute__((used))
 Registers callback message for given key.
 
EXTERN_C void keycontrol_send_key (struct module *root, int64_t key) __attribute__((used))
 
EXTERN_C void restore_old_tio (void)
 

Detailed Description

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file keyboard_control.h.

Macro Definition Documentation

◆ K_ALT

#define K_ALT ( x)
Value:
('\033' << 8 | (x))

Definition at line 79 of file keyboard_control.h.

Referenced by display_gl_process_key(), get_ansi_code(), and translate_glfw_to_ug().

◆ K_CTRL

#define K_CTRL ( x)
Value:
(1 + ((x) >= 'A' && (x) <= 'Z' ? (x) - 'A' + 'a' : (x)) - 'a')

Definition at line 76 of file keyboard_control.h.

Referenced by keyboard_control::impl::run(), translate_glfw_to_ug(), translate_sdl_key_to_ug(), and keyboard_control::impl::usage().

◆ K_CTRL_DOWN

#define K_CTRL_DOWN   0x1b5b313b3542LL

◆ K_CTRL_UP

#define K_CTRL_UP   0x1b5b313b3541LL

◆ K_DOWN

#define K_DOWN   0x1b5b42

◆ K_LEFT

#define K_LEFT   0x1b5b44

◆ K_PGDOWN

#define K_PGDOWN   0x1b5b367e

◆ K_PGUP

#define K_PGUP   0x1b5b357e

◆ K_RIGHT

#define K_RIGHT   0x1b5b43

◆ K_UP

◆ MAX_KEYCODE_NAME_LEN

#define MAX_KEYCODE_NAME_LEN   8

Definition at line 81 of file keyboard_control.h.

Referenced by glfw_key_callback().

Function Documentation

◆ get_keycode_name()

EXTERN_C void get_keycode_name ( int64_t ch,
char * buf,
size_t buflen )

Definition at line 1063 of file keyboard_control.cpp.

1063 {
1064 if (buflen == 0) {
1065 return;
1066 }
1067 string name = get_keycode_representation(ch);
1068 strncpy(buf, name.c_str(), buflen - 1);
1069 buf[buflen - 1] = '\0';
1070}
static string get_keycode_representation(int64_t ch)
const char * name
Definition settings.cpp:193

References get_keycode_representation(), and name.

Referenced by gl_show_help(), and glfw_key_callback().

Here is the call graph for this function:

◆ keycontrol_register_key()

EXTERN_C bool keycontrol_register_key ( struct module * receiver_mod,
int64_t key,
const char * message,
const char * description )

Registers callback message for given key.

message_universal message type is always sent

Parameters
[in]sender_modmodule that should receive the message for key
[in]messagetext that will be passed back to receiver_mod if key was pressed
[in]descriptionoptional decription that will be displayed in keyboard control help (may be NULL)

Definition at line 1041 of file keyboard_control.cpp.

1041 {
1042 assert(strchr(message, '#') == nullptr && (description == nullptr || strchr(description, '#') == nullptr));
1043 char receiver_path[1024];
1044 if (!module_get_path_str(receiver_mod, receiver_path, sizeof receiver_path)) {
1045 log_msg(LOG_LEVEL_ERROR, MOD_NAME "Cannot format format path for sender!\n");
1046 return false;
1047 }
1048 struct msg_universal *m = (struct msg_universal *) new_message(sizeof(struct msg_universal));
1049 if (description == nullptr) {
1051 }
1052 snprintf(m->text, sizeof m->text, "map #%" PRId64 " %s %s#%s", key, receiver_path, message, description);
1053 struct response *r = send_message_sync(get_root_module(receiver_mod), "keycontrol", (struct message *) m, 100, SEND_MESSAGE_FLAG_QUIET | SEND_MESSAGE_FLAG_NO_STORE);
1054 if (response_get_status(r) != RESPONSE_OK) {
1055 log_msg(LOG_LEVEL_ERROR, MOD_NAME "Cannot register keyboard control (error %d)!\n", response_get_status(r));
1056 free_response(r);
1057 return false;
1058 }
1059 free_response(r);
1060 return true;
1061}
static void new_message(struct module *m)
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
bool module_get_path_str(struct module *mod, char *buf, size_t buflen)
Definition module.c:408
struct module * get_root_module(struct module *node)
Definition module.c:203
#define MOD_NAME
struct response * send_message_sync(struct module *root, const char *const_path, struct message *msg, int timeout_ms, int flags)
Sends message without waiting for response.
int response_get_status(struct response *r)
void free_response(struct response *r)
#define SEND_MESSAGE_FLAG_QUIET
do not print error messages on console (recv not found/queue full)
Definition messaging.h:171
#define RESPONSE_OK
Definition messaging.h:57
#define SEND_MESSAGE_FLAG_NO_STORE
if receiver doesn't exist, doesn't store it and retur 404 instead
Definition messaging.h:172
struct message m
Definition messaging.h:156
const char * description
Definition cineform.cpp:126
const char * key
Definition cineform.cpp:125

References description, free_response(), get_root_module(), key, LOG_LEVEL_ERROR, log_msg(), MOD_NAME, module_get_path_str(), new_message(), response_get_status(), RESPONSE_OK, SEND_MESSAGE_FLAG_NO_STORE, SEND_MESSAGE_FLAG_QUIET, send_message_sync(), and msg_universal::text.

Referenced by display_gl_init(), display_sdl2_init(), display_sdl_init(), and playback_register_keyboard_ctl().

Here is the call graph for this function:

◆ keycontrol_send_key()

EXTERN_C void keycontrol_send_key ( struct module * root,
int64_t key )
Todo
all UG core functions should have the 'used' attribute

Definition at line 1024 of file keyboard_control.cpp.

1024 {
1025 struct msg_universal *m = (struct msg_universal *) new_message(sizeof(struct msg_universal));
1026 snprintf(m->text, sizeof m->text, "press %" PRId64, key);
1027 struct response *r = send_message_sync(root, "keycontrol", (struct message *) m, 100, SEND_MESSAGE_FLAG_QUIET | SEND_MESSAGE_FLAG_NO_STORE);
1028 if (response_get_status(r) != RESPONSE_OK) {
1029 log_msg(LOG_LEVEL_ERROR, MOD_NAME "Cannot set key to keycontrol (error %d)!\n", response_get_status(r));
1030 }
1031 free_response(r);
1032}

References free_response(), key, LOG_LEVEL_ERROR, log_msg(), MOD_NAME, new_message(), response_get_status(), RESPONSE_OK, SEND_MESSAGE_FLAG_NO_STORE, SEND_MESSAGE_FLAG_QUIET, send_message_sync(), and msg_universal::text.

Referenced by display_sdl2_run(), and glfw_key_callback().

Here is the call graph for this function:

◆ restore_old_tio()

EXTERN_C void restore_old_tio ( void )

Definition at line 188 of file keyboard_control.cpp.

189{
190#ifdef HAVE_TERMIOS_H
191 struct sigaction sa, sa_old;
192 memset(&sa, 0, sizeof sa);
193 sa.sa_handler = SIG_IGN;
194 sigemptyset(&sa.sa_mask);
195 sigaction(SIGTTOU, &sa, &sa_old);
196 /* set the new settings immediately */
197 /* restore the former settings */
198 tcsetattr(STDIN_FILENO,TCSANOW,&old_tio);
199 sigaction(SIGTTOU, &sa_old, NULL);
200#endif
201}

Referenced by crash_signal_handler(), keyboard_control::impl::read_command(), and keyboard_control::impl::start().