mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Add option to disable hotkeys, add gsr-ui-cli tool to control gsr-ui remotely
This commit is contained in:
@@ -58,6 +58,7 @@ namespace gsr {
|
||||
return {
|
||||
{"main.config_file_version", &config.main_config.config_file_version},
|
||||
{"main.software_encoding_warning_shown", &config.main_config.software_encoding_warning_shown},
|
||||
{"main.enable_hotkeys", &config.main_config.enable_hotkeys},
|
||||
{"main.tint_color", &config.main_config.tint_color},
|
||||
|
||||
{"streaming.record_options.record_area_option", &config.streaming_config.record_options.record_area_option},
|
||||
|
||||
@@ -487,6 +487,7 @@ namespace gsr {
|
||||
}
|
||||
|
||||
close_gpu_screen_recorder_output();
|
||||
deinit_color_theme();
|
||||
}
|
||||
|
||||
void Overlay::xi_setup() {
|
||||
@@ -1261,6 +1262,10 @@ namespace gsr {
|
||||
do_exit = true;
|
||||
}
|
||||
|
||||
const Config& Overlay::get_config() const {
|
||||
return config;
|
||||
}
|
||||
|
||||
void Overlay::update_notification_process_status() {
|
||||
if(notification_process <= 0)
|
||||
return;
|
||||
|
||||
@@ -88,6 +88,27 @@ namespace gsr {
|
||||
return std::make_unique<Subsection>("Startup", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
std::unique_ptr<Subsection> GlobalSettingsPage::create_hotkey_subsection(ScrollablePage *parent_page) {
|
||||
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
auto enable_hotkeys_radio_button = std::make_unique<RadioButton>(&get_theme().body_font, RadioButton::Orientation::HORIZONTAL);
|
||||
enable_hotkeys_radio_button_ptr = enable_hotkeys_radio_button.get();
|
||||
enable_hotkeys_radio_button->add_item("Enable hotkeys and restart", "enable_hotkeys");
|
||||
enable_hotkeys_radio_button->add_item("Disable hotkeys and restart", "disable_hotkeys");
|
||||
enable_hotkeys_radio_button->on_selection_changed = [&](const std::string&, const std::string &id) {
|
||||
if(!on_click_exit_program_button)
|
||||
return true;
|
||||
|
||||
if(id == "enable_hotkeys")
|
||||
on_click_exit_program_button("restart");
|
||||
else if(id == "disable_hotkeys")
|
||||
on_click_exit_program_button("restart");
|
||||
|
||||
return true;
|
||||
};
|
||||
list->add_widget(std::move(enable_hotkeys_radio_button));
|
||||
return std::make_unique<Subsection>("Hotkeys", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
std::unique_ptr<Button> GlobalSettingsPage::create_exit_program_button() {
|
||||
auto exit_program_button = std::make_unique<Button>(&get_theme().body_font, "Exit program", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120));
|
||||
exit_program_button->on_click = [&]() {
|
||||
@@ -108,7 +129,6 @@ namespace gsr {
|
||||
|
||||
std::unique_ptr<Subsection> GlobalSettingsPage::create_application_options_subsection(ScrollablePage *parent_page) {
|
||||
const bool inside_flatpak = getenv("FLATPAK_ID") != NULL;
|
||||
|
||||
auto list = std::make_unique<List>(List::Orientation::HORIZONTAL);
|
||||
list->add_widget(create_exit_program_button());
|
||||
if(inside_flatpak)
|
||||
@@ -123,6 +143,7 @@ namespace gsr {
|
||||
settings_list->set_spacing(0.018f);
|
||||
settings_list->add_widget(create_appearance_subsection(scrollable_page.get()));
|
||||
settings_list->add_widget(create_startup_subsection(scrollable_page.get()));
|
||||
settings_list->add_widget(create_hotkey_subsection(scrollable_page.get()));
|
||||
settings_list->add_widget(create_application_options_subsection(scrollable_page.get()));
|
||||
scrollable_page->add_widget(std::move(settings_list));
|
||||
|
||||
@@ -143,10 +164,13 @@ namespace gsr {
|
||||
std::string stdout_str;
|
||||
const int exit_status = exec_program_on_host_get_stdout(args, stdout_str);
|
||||
startup_radio_button_ptr->set_selected_item(exit_status == 0 ? "start_on_system_startup" : "dont_start_on_system_startup", false, false);
|
||||
|
||||
enable_hotkeys_radio_button_ptr->set_selected_item(config.main_config.enable_hotkeys ? "enable_hotkeys" : "disable_hotkeys", false, false);
|
||||
}
|
||||
|
||||
void GlobalSettingsPage::save() {
|
||||
config.main_config.tint_color = tint_color_radio_button_ptr->get_selected_id();
|
||||
config.main_config.enable_hotkeys = enable_hotkeys_radio_button_ptr->get_selected_id() == "enable_hotkeys";
|
||||
save_config(config);
|
||||
}
|
||||
}
|
||||
68
src/main.cpp
68
src/main.cpp
@@ -1,5 +1,4 @@
|
||||
#include "../include/GsrInfo.hpp"
|
||||
#include "../include/Theme.hpp"
|
||||
#include "../include/Overlay.hpp"
|
||||
#include "../include/GlobalHotkeysX11.hpp"
|
||||
#include "../include/GlobalHotkeysLinux.hpp"
|
||||
@@ -134,6 +133,43 @@ static std::unique_ptr<gsr::GlobalHotkeysLinux> register_linux_hotkeys(gsr::Over
|
||||
return global_hotkeys;
|
||||
}
|
||||
|
||||
static void rpc_add_commands(gsr::Rpc *rpc, gsr::Overlay *overlay) {
|
||||
rpc->add_handler("show_ui", [overlay](const std::string &name) {
|
||||
fprintf(stderr, "rpc command executed: %s\n", name.c_str());
|
||||
overlay->show();
|
||||
});
|
||||
|
||||
rpc->add_handler("toggle-show", [overlay](const std::string &name) {
|
||||
fprintf(stderr, "rpc command executed: %s\n", name.c_str());
|
||||
overlay->toggle_show();
|
||||
});
|
||||
|
||||
rpc->add_handler("toggle-record", [overlay](const std::string &name) {
|
||||
fprintf(stderr, "rpc command executed: %s\n", name.c_str());
|
||||
overlay->toggle_record();
|
||||
});
|
||||
|
||||
rpc->add_handler("toggle-pause", [overlay](const std::string &name) {
|
||||
fprintf(stderr, "rpc command executed: %s\n", name.c_str());
|
||||
overlay->toggle_pause();
|
||||
});
|
||||
|
||||
rpc->add_handler("toggle-stream", [overlay](const std::string &name) {
|
||||
fprintf(stderr, "rpc command executed: %s\n", name.c_str());
|
||||
overlay->toggle_stream();
|
||||
});
|
||||
|
||||
rpc->add_handler("toggle-replay", [overlay](const std::string &name) {
|
||||
fprintf(stderr, "rpc command executed: %s\n", name.c_str());
|
||||
overlay->toggle_replay();
|
||||
});
|
||||
|
||||
rpc->add_handler("replay-save", [overlay](const std::string &name) {
|
||||
fprintf(stderr, "rpc command executed: %s\n", name.c_str());
|
||||
overlay->save_replay();
|
||||
});
|
||||
}
|
||||
|
||||
static bool is_gsr_ui_virtual_keyboard_running() {
|
||||
FILE *f = fopen("/proc/bus/input/devices", "rb");
|
||||
if(!f)
|
||||
@@ -271,20 +307,19 @@ int main(int argc, char **argv) {
|
||||
|
||||
fprintf(stderr, "Info: gsr ui is now ready, waiting for inputs. Press alt+z to show/hide the overlay\n");
|
||||
|
||||
auto overlay = std::make_unique<gsr::Overlay>(resources_path, std::move(gsr_info), std::move(capture_options), egl_funcs);
|
||||
if(launch_action == LaunchAction::LAUNCH_SHOW)
|
||||
overlay->show();
|
||||
|
||||
auto rpc = std::make_unique<gsr::Rpc>();
|
||||
if(!rpc->create("gsr-ui"))
|
||||
fprintf(stderr, "Error: Failed to create rpc, commands won't be received\n");
|
||||
|
||||
auto overlay = std::make_unique<gsr::Overlay>(resources_path, std::move(gsr_info), std::move(capture_options), egl_funcs);
|
||||
rpc_add_commands(rpc.get(), overlay.get());
|
||||
|
||||
rpc->add_handler("show_ui", [&](const std::string&) {
|
||||
overlay->show();
|
||||
});
|
||||
|
||||
std::unique_ptr<gsr::GlobalHotkeys> global_hotkeys = register_linux_hotkeys(overlay.get());
|
||||
|
||||
if(launch_action == LaunchAction::LAUNCH_SHOW)
|
||||
overlay->show();
|
||||
std::unique_ptr<gsr::GlobalHotkeys> global_hotkeys = nullptr;
|
||||
if(overlay->get_config().main_config.enable_hotkeys)
|
||||
global_hotkeys = register_linux_hotkeys(overlay.get());
|
||||
|
||||
// TODO: Add hotkeys in Overlay when using x11 global hotkeys. The hotkeys in Overlay should duplicate each key that is used for x11 global hotkeys.
|
||||
|
||||
@@ -296,7 +331,10 @@ int main(int argc, char **argv) {
|
||||
gsr::set_frame_delta_seconds(frame_delta_seconds);
|
||||
|
||||
rpc->poll();
|
||||
global_hotkeys->poll_events();
|
||||
|
||||
if(global_hotkeys)
|
||||
global_hotkeys->poll_events();
|
||||
|
||||
overlay->handle_events(global_hotkeys.get());
|
||||
if(!overlay->draw()) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
@@ -306,15 +344,17 @@ int main(int argc, char **argv) {
|
||||
|
||||
fprintf(stderr, "Info: shutting down!\n");
|
||||
rpc.reset();
|
||||
global_hotkeys.reset();
|
||||
if(global_hotkeys)
|
||||
global_hotkeys.reset();
|
||||
overlay.reset();
|
||||
gsr::deinit_theme();
|
||||
gsr::deinit_color_theme();
|
||||
mgl_deinit();
|
||||
|
||||
if(exit_reason == "back-to-old-ui") {
|
||||
const char *args[] = { "gpu-screen-recorder-gtk", "use-old-ui", nullptr };
|
||||
execvp(args[0], (char* const*)args);
|
||||
} else if(exit_reason == "restart") {
|
||||
const char *args[] = { "gsr-ui", nullptr };
|
||||
execvp(args[0], (char* const*)args);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user