mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Add buttons to exit program and to go back to old ui for flatpak
This commit is contained in:
@@ -56,6 +56,8 @@ namespace gsr {
|
||||
void save_replay();
|
||||
void show_notification(const char *str, double timeout_seconds, mgl::Color icon_color, mgl::Color bg_color, NotificationType notification_type);
|
||||
bool is_open() const;
|
||||
bool should_exit(std::string &reason) const;
|
||||
void exit();
|
||||
private:
|
||||
void xi_setup();
|
||||
void handle_xi_events();
|
||||
@@ -161,5 +163,8 @@ namespace gsr {
|
||||
|
||||
std::array<KeyBinding, 1> key_bindings;
|
||||
bool drawn_first_frame = false;
|
||||
|
||||
bool do_exit = false;
|
||||
std::string exit_reason;
|
||||
};
|
||||
}
|
||||
@@ -12,6 +12,7 @@ namespace gsr {
|
||||
class ScrollablePage;
|
||||
class Subsection;
|
||||
class RadioButton;
|
||||
class Button;
|
||||
|
||||
class GlobalSettingsPage : public StaticPage {
|
||||
public:
|
||||
@@ -25,9 +26,14 @@ namespace gsr {
|
||||
|
||||
// Called with (enable, exit_status)
|
||||
std::function<void(bool, int)> on_startup_changed;
|
||||
// Called with (reason)
|
||||
std::function<void(const char*)> on_click_exit_program_button;
|
||||
private:
|
||||
std::unique_ptr<Subsection> create_appearance_subsection(ScrollablePage *parent_page);
|
||||
std::unique_ptr<Subsection> create_startup_subsection(ScrollablePage *parent_page);
|
||||
std::unique_ptr<Button> create_exit_program_button();
|
||||
std::unique_ptr<Button> create_go_back_to_old_ui_button();
|
||||
std::unique_ptr<Subsection> create_application_options_subsection(ScrollablePage *parent_page);
|
||||
void add_widgets();
|
||||
private:
|
||||
Config &config;
|
||||
|
||||
@@ -836,7 +836,7 @@ namespace gsr {
|
||||
|
||||
if(!init_theme(resources_path)) {
|
||||
fprintf(stderr, "Error: failed to load theme\n");
|
||||
exit(1);
|
||||
::exit(1);
|
||||
}
|
||||
|
||||
mgl_window *win = window->internal_window();
|
||||
@@ -903,6 +903,7 @@ namespace gsr {
|
||||
button->add_item("Settings", "settings");
|
||||
button->set_item_icon("start", &get_theme().play_texture);
|
||||
button->set_item_icon("save", &get_theme().save_texture);
|
||||
button->set_item_icon("settings", &get_theme().settings_small_texture);
|
||||
button->on_click = [this](const std::string &id) {
|
||||
if(id == "settings") {
|
||||
auto replay_settings_page = std::make_unique<SettingsPage>(SettingsPage::Type::REPLAY, &gsr_info, config, &page_stack);
|
||||
@@ -928,6 +929,7 @@ namespace gsr {
|
||||
button->add_item("Settings", "settings");
|
||||
button->set_item_icon("start", &get_theme().play_texture);
|
||||
button->set_item_icon("pause", &get_theme().pause_texture);
|
||||
button->set_item_icon("settings", &get_theme().settings_small_texture);
|
||||
button->on_click = [this](const std::string &id) {
|
||||
if(id == "settings") {
|
||||
auto record_settings_page = std::make_unique<SettingsPage>(SettingsPage::Type::RECORD, &gsr_info, config, &page_stack);
|
||||
@@ -951,6 +953,7 @@ namespace gsr {
|
||||
button->add_item("Start", "start", "Alt+F8");
|
||||
button->add_item("Settings", "settings");
|
||||
button->set_item_icon("start", &get_theme().play_texture);
|
||||
button->set_item_icon("settings", &get_theme().settings_small_texture);
|
||||
button->on_click = [this](const std::string &id) {
|
||||
if(id == "settings") {
|
||||
auto stream_settings_page = std::make_unique<SettingsPage>(SettingsPage::Type::STREAM, &gsr_info, config, &page_stack);
|
||||
@@ -993,6 +996,10 @@ namespace gsr {
|
||||
show_notification("Failed to remove GPU Screen Recorder from system startup", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
}
|
||||
};
|
||||
settings_page->on_click_exit_program_button = [&](const char *reason) {
|
||||
do_exit = true;
|
||||
exit_reason = reason;
|
||||
};
|
||||
page_stack.push(std::move(settings_page));
|
||||
};
|
||||
front_page_ptr->add_widget(std::move(button));
|
||||
@@ -1223,6 +1230,17 @@ namespace gsr {
|
||||
return visible;
|
||||
}
|
||||
|
||||
bool Overlay::should_exit(std::string &reason) const {
|
||||
reason.clear();
|
||||
if(do_exit)
|
||||
reason = exit_reason;
|
||||
return do_exit;
|
||||
}
|
||||
|
||||
void Overlay::exit() {
|
||||
do_exit = true;
|
||||
}
|
||||
|
||||
void Overlay::update_notification_process_status() {
|
||||
if(notification_process <= 0)
|
||||
return;
|
||||
|
||||
@@ -85,6 +85,34 @@ namespace gsr {
|
||||
return std::make_unique<Subsection>("Startup", 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 = [&]() {
|
||||
if(on_click_exit_program_button)
|
||||
on_click_exit_program_button("exit");
|
||||
};
|
||||
return exit_program_button;
|
||||
}
|
||||
|
||||
std::unique_ptr<Button> GlobalSettingsPage::create_go_back_to_old_ui_button() {
|
||||
auto exit_program_button = std::make_unique<Button>(&get_theme().body_font, "Go back to the old UI", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120));
|
||||
exit_program_button->on_click = [&]() {
|
||||
if(on_click_exit_program_button)
|
||||
on_click_exit_program_button("back-to-old-ui");
|
||||
};
|
||||
return exit_program_button;
|
||||
}
|
||||
|
||||
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)
|
||||
list->add_widget(create_go_back_to_old_ui_button());
|
||||
return std::make_unique<Subsection>("Application options", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
void GlobalSettingsPage::add_widgets() {
|
||||
auto scrollable_page = std::make_unique<ScrollablePage>(content_page_ptr->get_inner_size());
|
||||
|
||||
@@ -92,6 +120,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_application_options_subsection(scrollable_page.get()));
|
||||
scrollable_page->add_widget(std::move(settings_list));
|
||||
|
||||
content_page_ptr->add_widget(std::move(scrollable_page));
|
||||
|
||||
10
src/main.cpp
10
src/main.cpp
@@ -283,8 +283,10 @@ int main(int argc, char **argv) {
|
||||
|
||||
// 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.
|
||||
|
||||
std::string exit_reason;
|
||||
mgl::Clock frame_delta_clock;
|
||||
while(running && mgl_is_connected_to_display_server()) {
|
||||
|
||||
while(running && mgl_is_connected_to_display_server() && !overlay->should_exit(exit_reason)) {
|
||||
const double frame_delta_seconds = frame_delta_clock.restart();
|
||||
gsr::set_frame_delta_seconds(frame_delta_seconds);
|
||||
|
||||
@@ -301,6 +303,12 @@ int main(int argc, char **argv) {
|
||||
gsr::deinit_theme();
|
||||
gsr::deinit_color_theme();
|
||||
mgl_deinit();
|
||||
global_hotkeys.reset();
|
||||
|
||||
if(exit_reason == "back-to-old-ui") {
|
||||
const char *args[] = { "gpu-screen-recorder-gtk", nullptr };
|
||||
execvp(args[0], (char* const*)args);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user