mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Allow binding non alpha-numerical keys without a modifier
This commit is contained in:
@@ -139,8 +139,8 @@ namespace gsr {
|
|||||||
replay_config.start_stop_hotkey = {mgl::Keyboard::F10, HOTKEY_MOD_LALT | HOTKEY_MOD_LSHIFT};
|
replay_config.start_stop_hotkey = {mgl::Keyboard::F10, HOTKEY_MOD_LALT | HOTKEY_MOD_LSHIFT};
|
||||||
replay_config.save_hotkey = {mgl::Keyboard::F10, HOTKEY_MOD_LALT};
|
replay_config.save_hotkey = {mgl::Keyboard::F10, HOTKEY_MOD_LALT};
|
||||||
|
|
||||||
screenshot_config.take_screenshot_hotkey = {mgl::Keyboard::F1, HOTKEY_MOD_LALT};
|
screenshot_config.take_screenshot_hotkey = {mgl::Keyboard::Printscreen, 0};
|
||||||
screenshot_config.take_screenshot_region_hotkey = {mgl::Keyboard::F2, HOTKEY_MOD_LALT};
|
screenshot_config.take_screenshot_region_hotkey = {mgl::Keyboard::Printscreen, HOTKEY_MOD_LCTRL};
|
||||||
|
|
||||||
main_config.show_hide_hotkey = {mgl::Keyboard::Z, HOTKEY_MOD_LALT};
|
main_config.show_hide_hotkey = {mgl::Keyboard::Z, HOTKEY_MOD_LALT};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ extern "C" {
|
|||||||
#include <mgl/mgl.h>
|
#include <mgl/mgl.h>
|
||||||
}
|
}
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/keysym.h>
|
||||||
#include <linux/input-event-codes.h>
|
#include <linux/input-event-codes.h>
|
||||||
|
|
||||||
#define PIPE_READ 0
|
#define PIPE_READ 0
|
||||||
@@ -58,6 +59,10 @@ namespace gsr {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool x11_key_is_alpha_numerical(KeySym keysym) {
|
||||||
|
return (keysym >= XK_A && keysym <= XK_Z) || (keysym >= XK_a && keysym <= XK_z) || (keysym >= XK_0 && keysym <= XK_9);
|
||||||
|
}
|
||||||
|
|
||||||
GlobalHotkeysLinux::GlobalHotkeysLinux(GrabType grab_type) : grab_type(grab_type) {
|
GlobalHotkeysLinux::GlobalHotkeysLinux(GrabType grab_type) : grab_type(grab_type) {
|
||||||
for(int i = 0; i < 2; ++i) {
|
for(int i = 0; i < 2; ++i) {
|
||||||
read_pipes[i] = -1;
|
read_pipes[i] = -1;
|
||||||
@@ -173,7 +178,7 @@ namespace gsr {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hotkey.modifiers == 0) {
|
if(hotkey.modifiers == 0 && x11_key_is_alpha_numerical(hotkey.key)) {
|
||||||
//fprintf(stderr, "Error: GlobalHotkeysLinux::bind_key_press: hotkey requires a modifier\n");
|
//fprintf(stderr, "Error: GlobalHotkeysLinux::bind_key_press: hotkey requires a modifier\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -185,7 +190,12 @@ namespace gsr {
|
|||||||
const std::string modifiers_command = linux_keys_to_command_string(modifiers.data(), modifiers.size());
|
const std::string modifiers_command = linux_keys_to_command_string(modifiers.data(), modifiers.size());
|
||||||
|
|
||||||
char command[256];
|
char command[256];
|
||||||
const int command_size = snprintf(command, sizeof(command), "bind %s %d+%s\n", id.c_str(), (int)keycode, modifiers_command.c_str());
|
int command_size = 0;
|
||||||
|
if(modifiers_command.empty())
|
||||||
|
command_size = snprintf(command, sizeof(command), "bind %s %d\n", id.c_str(), (int)keycode);
|
||||||
|
else
|
||||||
|
command_size = snprintf(command, sizeof(command), "bind %s %d+%s\n", id.c_str(), (int)keycode, modifiers_command.c_str());
|
||||||
|
|
||||||
if(write(write_pipes[PIPE_WRITE], command, command_size) != command_size) {
|
if(write(write_pipes[PIPE_WRITE], command, command_size) != command_size) {
|
||||||
fprintf(stderr, "Error: GlobalHotkeysLinux::bind_key_press: failed to write command to gsr-global-hotkeys, error: %s\n", strerror(errno));
|
fprintf(stderr, "Error: GlobalHotkeysLinux::bind_key_press: failed to write command to gsr-global-hotkeys, error: %s\n", strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ namespace gsr {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool key_is_alpha_numerical(mgl::Keyboard::Key key) {
|
||||||
|
return key >= mgl::Keyboard::A && key <= mgl::Keyboard::Num9;
|
||||||
|
}
|
||||||
|
|
||||||
GlobalSettingsPage::GlobalSettingsPage(Overlay *overlay, const GsrInfo *gsr_info, Config &config, PageStack *page_stack) :
|
GlobalSettingsPage::GlobalSettingsPage(Overlay *overlay, const GsrInfo *gsr_info, Config &config, PageStack *page_stack) :
|
||||||
StaticPage(mgl::vec2f(get_theme().window_width, get_theme().window_height).floor()),
|
StaticPage(mgl::vec2f(get_theme().window_width, get_theme().window_height).floor()),
|
||||||
overlay(overlay),
|
overlay(overlay),
|
||||||
@@ -97,13 +101,13 @@ namespace gsr {
|
|||||||
|
|
||||||
mgl::Text title_text("Press a key combination to use for the hotkey \"" + hotkey_configure_action_name + "\":", get_theme().title_font);
|
mgl::Text title_text("Press a key combination to use for the hotkey \"" + hotkey_configure_action_name + "\":", get_theme().title_font);
|
||||||
mgl::Text hotkey_text(configure_hotkey_button->get_text(), get_theme().top_bar_font);
|
mgl::Text hotkey_text(configure_hotkey_button->get_text(), get_theme().top_bar_font);
|
||||||
mgl::Text description_text("The hotkey has to contain one or more of these keys: Alt, Ctrl, Shift and Super. Press Esc to cancel or Backspace to remove the hotkey.", get_theme().body_font);
|
mgl::Text description_text("Alpha-numerical keys can't be used alone in hotkeys, they have to be used one or more of these keys: Alt, Ctrl, Shift and Super.\nPress Esc to cancel or Backspace to remove the hotkey.", get_theme().body_font);
|
||||||
const float text_max_width = std::max(title_text.get_bounds().size.x, std::max(hotkey_text.get_bounds().size.x, description_text.get_bounds().size.x));
|
const float text_max_width = std::max(title_text.get_bounds().size.x, std::max(hotkey_text.get_bounds().size.x, description_text.get_bounds().size.x));
|
||||||
|
|
||||||
const float padding_horizontal = int(get_theme().window_height * 0.01f);
|
const float padding_horizontal = int(get_theme().window_height * 0.01f);
|
||||||
const float padding_vertical = int(get_theme().window_height * 0.01f);
|
const float padding_vertical = int(get_theme().window_height * 0.01f);
|
||||||
|
|
||||||
const mgl::vec2f bg_size = mgl::vec2f(text_max_width + padding_horizontal*2.0f, get_theme().window_height * 0.1f).floor();
|
const mgl::vec2f bg_size = mgl::vec2f(text_max_width + padding_horizontal*2.0f, get_theme().window_height * 0.13f).floor();
|
||||||
mgl::Rectangle bg_rect(mgl::vec2f(get_theme().window_width*0.5f - bg_size.x*0.5f, get_theme().window_height*0.5f - bg_size.y*0.5f).floor(), bg_size);
|
mgl::Rectangle bg_rect(mgl::vec2f(get_theme().window_width*0.5f - bg_size.x*0.5f, get_theme().window_height*0.5f - bg_size.y*0.5f).floor(), bg_size);
|
||||||
bg_rect.set_color(get_color_theme().page_bg_color);
|
bg_rect.set_color(get_color_theme().page_bg_color);
|
||||||
window.draw(bg_rect);
|
window.draw(bg_rect);
|
||||||
@@ -114,9 +118,16 @@ namespace gsr {
|
|||||||
window.draw(tint_rect);
|
window.draw(tint_rect);
|
||||||
|
|
||||||
title_text.set_position(mgl::vec2f(bg_rect.get_position() + mgl::vec2f(bg_rect.get_size().x*0.5f - title_text.get_bounds().size.x*0.5f, padding_vertical)).floor());
|
title_text.set_position(mgl::vec2f(bg_rect.get_position() + mgl::vec2f(bg_rect.get_size().x*0.5f - title_text.get_bounds().size.x*0.5f, padding_vertical)).floor());
|
||||||
|
description_text.set_position(mgl::vec2f(bg_rect.get_position() + mgl::vec2f(bg_rect.get_size().x*0.5f - description_text.get_bounds().size.x*0.5f, bg_rect.get_size().y - description_text.get_bounds().size.y - padding_vertical)).floor());
|
||||||
|
|
||||||
window.draw(title_text);
|
window.draw(title_text);
|
||||||
|
|
||||||
hotkey_text.set_position(mgl::vec2f(bg_rect.get_position() + bg_rect.get_size()*0.5f - hotkey_text.get_bounds().size*0.5f).floor());
|
const float title_text_bottom = title_text.get_position().y + title_text.get_bounds().size.y;
|
||||||
|
hotkey_text.set_position(
|
||||||
|
mgl::vec2f(
|
||||||
|
bg_rect.get_position().x + bg_rect.get_size().x*0.5f - hotkey_text.get_bounds().size.x*0.5f,
|
||||||
|
title_text_bottom + (description_text.get_position().y - title_text_bottom) * 0.5f - hotkey_text.get_bounds().size.y*0.5f
|
||||||
|
).floor());
|
||||||
window.draw(hotkey_text);
|
window.draw(hotkey_text);
|
||||||
|
|
||||||
const float caret_padding_x = int(0.001f * get_theme().window_height);
|
const float caret_padding_x = int(0.001f * get_theme().window_height);
|
||||||
@@ -124,7 +135,6 @@ namespace gsr {
|
|||||||
mgl::Rectangle caret_rect(hotkey_text.get_position() + mgl::vec2f(hotkey_text.get_bounds().size.x + caret_padding_x, hotkey_text.get_bounds().size.y*0.5f - caret_size.y*0.5f).floor(), caret_size);
|
mgl::Rectangle caret_rect(hotkey_text.get_position() + mgl::vec2f(hotkey_text.get_bounds().size.x + caret_padding_x, hotkey_text.get_bounds().size.y*0.5f - caret_size.y*0.5f).floor(), caret_size);
|
||||||
window.draw(caret_rect);
|
window.draw(caret_rect);
|
||||||
|
|
||||||
description_text.set_position(mgl::vec2f(bg_rect.get_position() + mgl::vec2f(bg_rect.get_size().x*0.5f - description_text.get_bounds().size.x*0.5f, bg_rect.get_size().y - description_text.get_bounds().size.y - padding_vertical)).floor());
|
|
||||||
window.draw(description_text);
|
window.draw(description_text);
|
||||||
};
|
};
|
||||||
hotkey_overlay->set_visible(false);
|
hotkey_overlay->set_visible(false);
|
||||||
@@ -525,7 +535,7 @@ namespace gsr {
|
|||||||
if(mgl::Keyboard::key_is_modifier(event.key.code)) {
|
if(mgl::Keyboard::key_is_modifier(event.key.code)) {
|
||||||
configure_config_hotkey.modifiers |= mgl_modifier_to_hotkey_modifier(event.key.code);
|
configure_config_hotkey.modifiers |= mgl_modifier_to_hotkey_modifier(event.key.code);
|
||||||
configure_hotkey_button->set_text(configure_config_hotkey.to_string());
|
configure_hotkey_button->set_text(configure_config_hotkey.to_string());
|
||||||
} else if(configure_config_hotkey.modifiers != 0) {
|
} else if(configure_config_hotkey.modifiers != 0 || !key_is_alpha_numerical(event.key.code)) {
|
||||||
configure_config_hotkey.key = event.key.code;
|
configure_config_hotkey.key = event.key.code;
|
||||||
configure_hotkey_button->set_text(configure_config_hotkey.to_string());
|
configure_hotkey_button->set_text(configure_config_hotkey.to_string());
|
||||||
configure_hotkey_stop_and_save();
|
configure_hotkey_stop_and_save();
|
||||||
|
|||||||
@@ -575,6 +575,13 @@ static int parse_u8(const char *str, int size) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_key_alpha_numerical(uint8_t key) {
|
||||||
|
return (key >= KEY_1 && key <= KEY_0)
|
||||||
|
|| (key >= KEY_Q && key <= KEY_P)
|
||||||
|
|| (key >= KEY_A && key <= KEY_L)
|
||||||
|
|| (key >= KEY_Z && key <= KEY_M);
|
||||||
|
}
|
||||||
|
|
||||||
static bool keyboard_event_parse_bind_keys(const char *str, int size, uint8_t *key, uint32_t *modifiers) {
|
static bool keyboard_event_parse_bind_keys(const char *str, int size, uint8_t *key, uint32_t *modifiers) {
|
||||||
*key = 0;
|
*key = 0;
|
||||||
*modifiers = 0;
|
*modifiers = 0;
|
||||||
@@ -609,13 +616,13 @@ static bool keyboard_event_parse_bind_keys(const char *str, int size, uint8_t *k
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == 0) {
|
if(*key == 0) {
|
||||||
fprintf(stderr, "Error: can't bind hotkey without a non-modifier key\n");
|
fprintf(stderr, "Error: can't bind hotkey without a non-modifier key\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(modifiers == 0) {
|
if(*modifiers == 0 && is_key_alpha_numerical(*key)) {
|
||||||
fprintf(stderr, "Error: can't bind hotkey without a modifier\n");
|
fprintf(stderr, "Error: can't bind hotkey without a modifier unless the key is a non alpha-numerical key\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user