7 #include <linux/input.h>
15 #define LOG_TAG "sdl_events"
23 static void grab_time(
char* stringtime)
28 gettimeofday(&tv, NULL);
31 struct tm cur_localtime;
32 localtime_r(&curtime, &cur_localtime);
33 strftime(T, 30,
"%Y-%d-%mT%H:%M:%S", &cur_localtime);
34 snprintf(stringtime, 30,
"%s.%ld", T, tv.tv_usec);
40 static void convert_mouse_position(
int* x,
int* y)
66 static int moreFrames = 0;
70 LOGI(
"Got SDL_KEY with state=%d code=%d keysym=%d xtkey=%d input_socket=%d", event->key.state,
71 event->key.keysym.scancode, event->key.keysym.sym, xtkey, input_socket);
74 static pthread_t pgrab_Thread;
76 if (xtkey == KEY_F7 && moreFrames == 0)
78 char strPrefix[] =
"log/video_F7_";
83 pthread_mutex_init(&grab_args.
mtx, NULL);
84 pthread_mutex_lock(&grab_args.
mtx);
85 pthread_create(&pgrab_Thread, NULL, (
void*) &
ffmpeg_grabber, &grab_args);
87 else if (xtkey == KEY_F8 && moreFrames == 1)
90 pthread_mutex_unlock(&grab_args.
mtx);
91 pthread_join(pgrab_Thread, NULL);
93 else if (event->type == SDL_KEYDOWN && xtkey == KEY_F6)
97 snprintf(snap_filename,
sizeof(snap_filename),
"log/snap_F6_%s.bmp", strTime);
98 LOGI(
"Saving snapshot %s", snap_filename);
105 snprintf(buffer,
BUF_SIZE,
"%s:%d:%d\n",
106 (event->key.state == SDL_PRESSED) ?
"KBDPR" :
"KBDRL", xtkey, event->key.state);
107 ret = send(input_socket, buffer, strlen(buffer), 0);
114 int x =
event->motion.x;
115 int y =
event->motion.y;
116 convert_mouse_position(&x, &y);
120 snprintf(buffer,
BUF_SIZE,
"MOUSE:%d:%d\n", x, y);
121 return send(input_socket, buffer, strlen(buffer), 0);
130 SDL_GetMouseState(&x, &y);
131 convert_mouse_position(&x, &y);
132 if (event->wheel.y > 0)
133 snprintf(buffer,
BUF_SIZE,
"WHEEL:%d:%d:1:0\n", x, y);
134 else if (event->wheel.y < 0)
135 snprintf(buffer,
BUF_SIZE,
"WHEEL:%d:%d:-1:0\n", x, y);
138 return send(input_socket, buffer, strlen(buffer), 0);
143 int x =
event->motion.x;
144 int y =
event->motion.y;
145 convert_mouse_position(&x, &y);
149 switch (event->button.button)
151 case SDL_BUTTON_LEFT:
152 if (event->button.state == SDL_PRESSED)
153 snprintf(buffer,
BUF_SIZE,
"MSBPR:%d:%d\n", x, y);
155 snprintf(buffer,
BUF_SIZE,
"MSBRL:%d:%d\n", x, y);
160 return send(input_socket, buffer, strlen(buffer), 0);
#define BUF_SIZE
Small, fixed-size buffers.
Struct holding the state of a recording (filename/lock)
int sdl_mouse_wheel(SDL_Event *event, socket_t input_socket)
Produce a mouse wheel event to the virtual input.
int socket_t
Alias to differenciate between regular ints and socket fds.
void grab_snapshot(char *snap_filename)
int g_width
Global variable for the window width.
int ffmpeg_grabber(void *arg)
Function passed to a thread in order to detect format encoding - encode frame- and write in a file...
int sdl_translate_event(SDL_Scancode scancode, SDL_Keycode keysym)
Convert an SDL scancode to a value read by the virtual input daemon.
Convert sdl events to uinput codes.
char record_filename[BUF_SIZE]
grabber records videos or snapshots from ampq messages
Produce virtual input events from SDL events.
#define SOCKET_ERROR
Alias for the recv() return value in case of error.
Define common buffer sizes.
#define LOGI(...)
Log at INFO level.
int sdl_key(SDL_Event *event, socket_t input_socket)
Produce a key press/release event to the virtual input.
int g_height
Global variable for the window height.
int sdl_mouse_motion(SDL_Event *event, socket_t input_socket)
Produce a mouse motion event to the virtual input.
int sdl_mouse_button(SDL_Event *event, socket_t input_socket)
Produce a mouse click event to the virtual input.