mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-05-05 14:30:45 +09:00
Re-add escape button to go back to the previous page/close
This commit is contained in:
@@ -14,6 +14,8 @@
|
|||||||
#include <mglpp/graphics/Text.hpp>
|
#include <mglpp/graphics/Text.hpp>
|
||||||
#include <mglpp/system/Clock.hpp>
|
#include <mglpp/system/Clock.hpp>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
namespace gsr {
|
namespace gsr {
|
||||||
class DropdownButton;
|
class DropdownButton;
|
||||||
|
|
||||||
@@ -56,6 +58,7 @@ namespace gsr {
|
|||||||
private:
|
private:
|
||||||
void xi_setup();
|
void xi_setup();
|
||||||
void handle_xi_events();
|
void handle_xi_events();
|
||||||
|
void process_key_bindings(mgl::Event &event);
|
||||||
void xi_setup_fake_cursor();
|
void xi_setup_fake_cursor();
|
||||||
void xi_grab_all_devices();
|
void xi_grab_all_devices();
|
||||||
void xi_warp_pointer(mgl::vec2i position);
|
void xi_warp_pointer(mgl::vec2i position);
|
||||||
@@ -93,6 +96,12 @@ namespace gsr {
|
|||||||
|
|
||||||
void force_window_on_top();
|
void force_window_on_top();
|
||||||
private:
|
private:
|
||||||
|
using KeyBindingCallback = std::function<void()>;
|
||||||
|
struct KeyBinding {
|
||||||
|
mgl::Event::KeyEvent key_event;
|
||||||
|
KeyBindingCallback callback;
|
||||||
|
};
|
||||||
|
|
||||||
std::unique_ptr<mgl::Window> window;
|
std::unique_ptr<mgl::Window> window;
|
||||||
mgl::Event event;
|
mgl::Event event;
|
||||||
std::string resources_path;
|
std::string resources_path;
|
||||||
@@ -147,5 +156,7 @@ namespace gsr {
|
|||||||
int xi_opcode = 0;
|
int xi_opcode = 0;
|
||||||
XEvent *xi_input_xev = nullptr;
|
XEvent *xi_input_xev = nullptr;
|
||||||
XEvent *xi_output_xev = nullptr;
|
XEvent *xi_output_xev = nullptr;
|
||||||
|
|
||||||
|
std::array<KeyBinding, 1> key_bindings;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -362,6 +362,15 @@ namespace gsr {
|
|||||||
// TODO:
|
// TODO:
|
||||||
//xi_setup();
|
//xi_setup();
|
||||||
|
|
||||||
|
key_bindings[0].key_event.code = mgl::Keyboard::Escape;
|
||||||
|
key_bindings[0].key_event.alt = false;
|
||||||
|
key_bindings[0].key_event.control = false;
|
||||||
|
key_bindings[0].key_event.shift = false;
|
||||||
|
key_bindings[0].key_event.system = false;
|
||||||
|
key_bindings[0].callback = [this]() {
|
||||||
|
page_stack.pop();
|
||||||
|
};
|
||||||
|
|
||||||
memset(&window_texture, 0, sizeof(window_texture));
|
memset(&window_texture, 0, sizeof(window_texture));
|
||||||
|
|
||||||
std::optional<Config> new_config = read_config(gsr_info);
|
std::optional<Config> new_config = read_config(gsr_info);
|
||||||
@@ -528,6 +537,24 @@ namespace gsr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t key_event_to_bitmask(mgl::Event::KeyEvent key_event) {
|
||||||
|
return ((uint32_t)key_event.alt << (uint32_t)0)
|
||||||
|
| ((uint32_t)key_event.control << (uint32_t)1)
|
||||||
|
| ((uint32_t)key_event.shift << (uint32_t)2)
|
||||||
|
| ((uint32_t)key_event.system << (uint32_t)3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Overlay::process_key_bindings(mgl::Event &event) {
|
||||||
|
if(event.type != mgl::Event::KeyReleased)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const uint32_t event_key_bitmask = key_event_to_bitmask(event.key);
|
||||||
|
for(const KeyBinding &key_binding : key_bindings) {
|
||||||
|
if(event.key.code == key_binding.key_event.code && event_key_bitmask == key_event_to_bitmask(key_binding.key_event))
|
||||||
|
key_binding.callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Overlay::handle_events() {
|
void Overlay::handle_events() {
|
||||||
if(!visible || !window)
|
if(!visible || !window)
|
||||||
return;
|
return;
|
||||||
@@ -548,6 +575,8 @@ namespace gsr {
|
|||||||
|
|
||||||
if(!page_stack.on_event(event, *window, mgl::vec2f(0.0f, 0.0f)))
|
if(!page_stack.on_event(event, *window, mgl::vec2f(0.0f, 0.0f)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
process_key_bindings(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Overlay::draw() {
|
bool Overlay::draw() {
|
||||||
|
|||||||
Reference in New Issue
Block a user