aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build7
-rw-r--r--project.conf2
-rw-r--r--src/Overlay.cpp3
-rw-r--r--src/main.cpp1
-rw-r--r--tools/gsr-global-hotkeys/hotplug.c2
-rw-r--r--tools/gsr-global-hotkeys/keyboard_event.c40
-rw-r--r--tools/gsr-global-hotkeys/keyboard_event.h29
-rw-r--r--tools/gsr-global-hotkeys/main.c74
8 files changed, 34 insertions, 124 deletions
diff --git a/meson.build b/meson.build
index 71ca451..6af905a 100644
--- a/meson.build
+++ b/meson.build
@@ -1,4 +1,4 @@
-project('gsr-ui', ['c', 'cpp'], version : '1.0.5', default_options : ['warning_level=2', 'cpp_std=c++17'], subproject_dir : 'depends')
+project('gsr-ui', ['c', 'cpp'], version : '1.0.6', default_options : ['warning_level=2', 'cpp_std=c++17'], subproject_dir : 'depends')
if get_option('buildtype') == 'debug'
add_project_arguments('-g3', language : ['c', 'cpp'])
@@ -71,7 +71,10 @@ executable(
'tools/gsr-global-hotkeys/main.c'
],
c_args : '-fstack-protector-all',
- install : true
+ install : true,
+ dependencies: [
+ dependency('x11'),
+ ]
)
executable(
diff --git a/project.conf b/project.conf
index 8d84466..13be6d0 100644
--- a/project.conf
+++ b/project.conf
@@ -1,7 +1,7 @@
[package]
name = "gsr-ui"
type = "executable"
-version = "1.0.5"
+version = "1.0.6"
platforms = ["posix"]
[lang.cpp]
diff --git a/src/Overlay.cpp b/src/Overlay.cpp
index aa14e3b..d71dd4e 100644
--- a/src/Overlay.cpp
+++ b/src/Overlay.cpp
@@ -782,9 +782,6 @@ namespace gsr {
update_compositor_texture(focused_monitor);
- top_bar_text = mgl::Text("GPU Screen Recorder", get_theme().top_bar_font);
- logo_sprite = mgl::Sprite(&get_theme().logo_texture);
-
bg_screenshot_overlay = mgl::Rectangle(mgl::vec2f(get_theme().window_width, get_theme().window_height));
top_bar_background = mgl::Rectangle(mgl::vec2f(get_theme().window_width, get_theme().window_height*0.06f).floor());
top_bar_text = mgl::Text("GPU Screen Recorder", get_theme().top_bar_font);
diff --git a/src/main.cpp b/src/main.cpp
index 9c20a81..c81bc8c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -37,6 +37,7 @@ static void disable_prime_run() {
unsetenv("__NV_PRIME_RENDER_OFFLOAD_PROVIDER");
unsetenv("__GLX_VENDOR_LIBRARY_NAME");
unsetenv("__VK_LAYER_NV_optimus");
+ unsetenv("DRI_PRIME");
}
static std::unique_ptr<gsr::GlobalHotkeysX11> register_x11_hotkeys(gsr::Overlay *overlay) {
diff --git a/tools/gsr-global-hotkeys/hotplug.c b/tools/gsr-global-hotkeys/hotplug.c
index ba3ef9c..7f07043 100644
--- a/tools/gsr-global-hotkeys/hotplug.c
+++ b/tools/gsr-global-hotkeys/hotplug.c
@@ -7,7 +7,7 @@
#include <unistd.h>
#include <sys/socket.h>
-/* LINUX */
+/* Linux */
#include <linux/types.h>
#include <linux/netlink.h>
diff --git a/tools/gsr-global-hotkeys/keyboard_event.c b/tools/gsr-global-hotkeys/keyboard_event.c
index bcfd616..d69bbec 100644
--- a/tools/gsr-global-hotkeys/keyboard_event.c
+++ b/tools/gsr-global-hotkeys/keyboard_event.c
@@ -13,10 +13,13 @@
#include <dirent.h>
#include <sys/poll.h>
-/* LINUX */
+/* Linux */
#include <linux/input.h>
#include <linux/uinput.h>
+/* System */
+#include <X11/keysym.h>
+
#define GSR_UI_VIRTUAL_KEYBOARD_NAME "gsr-ui virtual keyboard"
#define KEY_RELEASE 0
@@ -27,22 +30,6 @@
#define KEYCODE_TO_XKB_KEYCODE(key) ((key) + 8)
-#define XK_Shift_L 0xffe1 /* Left shift */
-#define XK_Shift_R 0xffe2 /* Right shift */
-#define XK_Control_L 0xffe3 /* Left control */
-#define XK_Control_R 0xffe4 /* Right control */
-#define XK_Alt_L 0xffe9 /* Left alt */
-#define XK_Alt_R 0xffea /* Right alt */
-#define XK_Super_L 0xffeb /* Left super */
-#define XK_Super_R 0xffec /* Right super */
-
-#define XK_z 0x007a
-#define XK_F7 0xffc4
-#define XK_F8 0xffc5
-#define XK_F9 0xffc6
-#define XK_F10 0xffc7
-#define XK_F11 0xffc8
-
static inline int count_num_bits_set(unsigned char c) {
int n = 0;
n += (c & 1);
@@ -137,8 +124,8 @@ static void keyboard_event_process_key_state_change(keyboard_event *self, struct
static uint32_t keycode_to_keysym(keyboard_event *self, uint16_t keycode) {
const unsigned long xkb_keycode = KEYCODE_TO_XKB_KEYCODE(keycode);
- if(self->x_context.display && self->x_context.XKeycodeToKeysym && xkb_keycode <= 255)
- return self->x_context.XKeycodeToKeysym(self->x_context.display, xkb_keycode, 0);
+ if(self->display && xkb_keycode <= 255)
+ return XKeycodeToKeysym(self->display, xkb_keycode, 0);
else
return 0;
}
@@ -184,6 +171,7 @@ static void keyboard_event_process_input_event_data(keyboard_event *self, event_
if(event.type == EV_KEY) {
keyboard_event_process_key_state_change(self, event, extra_data, fd);
+ /* We do this conversion from keycode to keysym back to keycode to support different keyboard layouts in the X server (which Wayland also uses to support Xwayland) */
uint32_t keycode = event.code;
const uint32_t keysym = keycode_to_keysym(self, event.code);
if(keysym)
@@ -458,12 +446,12 @@ static int setup_virtual_keyboard_input(const char *name) {
return fd;
}
-bool keyboard_event_init(keyboard_event *self, bool poll_stdout_error, bool exclusive_grab, keyboard_grab_type grab_type, x11_context x_context) {
+bool keyboard_event_init(keyboard_event *self, bool poll_stdout_error, bool exclusive_grab, keyboard_grab_type grab_type, Display *display) {
memset(self, 0, sizeof(*self));
self->stdout_event_index = -1;
self->hotplug_event_index = -1;
self->grab_type = grab_type;
- self->x_context = x_context;
+ self->display = display;
if(exclusive_grab) {
self->uinput_fd = setup_virtual_keyboard_input(GSR_UI_VIRTUAL_KEYBOARD_NAME);
@@ -543,18 +531,16 @@ static void on_device_added_callback(const char *devname, void *userdata) {
keyboard_event_try_add_device_if_keyboard(keyboard_ev, dev_input_filepath);
}
-#define MappingNotify 34
-
static void keyboard_event_poll_x11_events(keyboard_event *self) {
- if(!self->x_context.display || !self->x_context.XPending || !self->x_context.XNextEvent || !self->x_context.XRefreshKeyboardMapping)
+ if(!self->display)
return;
XEvent xev;
- while(self->x_context.XPending(self->x_context.display)) {
+ while(XPending(self->display)) {
xev.type = 0;
- self->x_context.XNextEvent(self->x_context.display, &xev);
+ XNextEvent(self->display, &xev);
if(xev.type == MappingNotify)
- self->x_context.XRefreshKeyboardMapping(xev.data);
+ XRefreshKeyboardMapping(&xev.xmapping);
}
}
diff --git a/tools/gsr-global-hotkeys/keyboard_event.h b/tools/gsr-global-hotkeys/keyboard_event.h
index 9904237..cd5e119 100644
--- a/tools/gsr-global-hotkeys/keyboard_event.h
+++ b/tools/gsr-global-hotkeys/keyboard_event.h
@@ -12,30 +12,13 @@
/* POSIX */
#include <sys/poll.h>
-/* LINUX */
+/* Linux */
#include <linux/input-event-codes.h>
-#define MAX_EVENT_POLLS 32
-
-typedef struct {
- union {
- int type;
- unsigned char data[192];
- };
-} XEvent;
+/* System */
+#include <X11/Xlib.h>
-typedef unsigned long (*XKeycodeToKeysym_FUNC)(void *display, unsigned char keycode, int index);
-typedef int (*XPending_FUNC)(void *display);
-typedef int (*XNextEvent_FUNC)(void *display, XEvent *event_return);
-typedef int (*XRefreshKeyboardMapping_FUNC)(void* event_map);
-
-typedef struct {
- void *display;
- XKeycodeToKeysym_FUNC XKeycodeToKeysym;
- XPending_FUNC XPending;
- XNextEvent_FUNC XNextEvent;
- XRefreshKeyboardMapping_FUNC XRefreshKeyboardMapping;
-} x11_context;
+#define MAX_EVENT_POLLS 32
typedef enum {
KEYBOARD_MODKEY_LALT = 1 << 0,
@@ -72,7 +55,7 @@ typedef struct {
int uinput_fd;
bool stdout_failed;
keyboard_grab_type grab_type;
- x11_context x_context;
+ Display *display;
hotplug_event hotplug_ev;
@@ -90,7 +73,7 @@ typedef struct {
/* Return true to allow other applications to receive the key input (when using exclusive grab) */
typedef bool (*key_callback)(uint32_t key, uint32_t modifiers, int press_status, void *userdata);
-bool keyboard_event_init(keyboard_event *self, bool poll_stdout_error, bool exclusive_grab, keyboard_grab_type grab_type, x11_context x_context);
+bool keyboard_event_init(keyboard_event *self, bool poll_stdout_error, bool exclusive_grab, keyboard_grab_type grab_type, Display *display);
void keyboard_event_deinit(keyboard_event *self);
/* If |timeout_milliseconds| is -1 then wait until an event is received */
diff --git a/tools/gsr-global-hotkeys/main.c b/tools/gsr-global-hotkeys/main.c
index b64d60f..9d7dd68 100644
--- a/tools/gsr-global-hotkeys/main.c
+++ b/tools/gsr-global-hotkeys/main.c
@@ -46,76 +46,12 @@ static void usage(void) {
fprintf(stderr, " --virtual Grab all virtual devices only.\n");
}
-typedef void* (*XOpenDisplay_FUNC)(const char*);
-typedef int (*XErrorHandler_FUNC)(void *display, void* error_event);
-typedef XErrorHandler_FUNC (*XSetErrorHandler_FUNC)(XErrorHandler_FUNC handler);
-
-static int x_ignore_error(void *display, void *ee) {
+static int x_ignore_error(Display *display, XErrorEvent *ee) {
(void)display;
(void)ee;
return 0;
}
-static x11_context setup_x11_context(void) {
- x11_context x_context = {0};
- XSetErrorHandler_FUNC XSetErrorHandler = NULL;
-
- void *x11_lib = dlopen("libX11.so.6", RTLD_LAZY);
- if(!x11_lib) {
- fprintf(stderr, "Warning: dlopen libX11.so.6 failed\n");
- return x_context;
- }
-
- XOpenDisplay_FUNC XOpenDisplay = dlsym(x11_lib, "XOpenDisplay");
- if(!XOpenDisplay) {
- fprintf(stderr, "Warning: dlsym XOpenDisplay failed\n");
- goto fail;
- }
-
- x_context.XKeycodeToKeysym = dlsym(x11_lib, "XKeycodeToKeysym");
- if(!x_context.XKeycodeToKeysym) {
- fprintf(stderr, "Warning: dlsym XKeycodeToKeysym failed\n");
- goto fail;
- }
-
- x_context.XPending = dlsym(x11_lib, "XPending");
- if(!x_context.XPending) {
- fprintf(stderr, "Warning: dlsym XPending failed\n");
- goto fail;
- }
-
- x_context.XNextEvent = dlsym(x11_lib, "XNextEvent");
- if(!x_context.XNextEvent) {
- fprintf(stderr, "Warning: dlsym XNextEvent failed\n");
- goto fail;
- }
-
- x_context.XRefreshKeyboardMapping = dlsym(x11_lib, "XRefreshKeyboardMapping");
- if(!x_context.XRefreshKeyboardMapping) {
- fprintf(stderr, "Warning: dlsym XRefreshKeyboardMapping failed\n");
- goto fail;
- }
-
- x_context.display = XOpenDisplay(NULL);
- if(!x_context.display) {
- fprintf(stderr, "Warning: XOpenDisplay failed\n");
- goto fail;
- }
-
- XSetErrorHandler = dlsym(x11_lib, "XSetErrorHandler");
- if(XSetErrorHandler)
- XSetErrorHandler(x_ignore_error);
- else
- fprintf(stderr, "Warning: dlsym XSetErrorHandler failed\n");
-
- return x_context;
-
- fail:
- memset(&x_context, 0, sizeof(x_context));
- dlclose(x11_lib);
- return x_context;
-}
-
int main(int argc, char **argv) {
keyboard_grab_type grab_type = KEYBOARD_GRAB_TYPE_ALL;
if(argc == 2) {
@@ -135,7 +71,11 @@ int main(int argc, char **argv) {
return 1;
}
- x11_context x_context = setup_x11_context();
+ Display *display = XOpenDisplay(NULL);
+ if(display)
+ XSetErrorHandler(x_ignore_error);
+ else
+ fprintf(stderr, "Warning: XOpenDisplay failed\n");
const uid_t user_id = getuid();
if(geteuid() != 0) {
@@ -146,7 +86,7 @@ int main(int argc, char **argv) {
}
keyboard_event keyboard_ev;
- if(!keyboard_event_init(&keyboard_ev, true, true, grab_type, x_context)) {
+ if(!keyboard_event_init(&keyboard_ev, true, true, grab_type, display)) {
fprintf(stderr, "Error: failed to setup hotplugging and no keyboard input devices were found\n");
setuid(user_id);
return 1;