mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Add option to manage program startup directly in the program
This commit is contained in:
2
TODO
2
TODO
@@ -114,3 +114,5 @@ Improve linux global hotkeys startup time by parsing /proc/bus/input/devices ins
|
||||
We can get the name of the running steam game without x11 by listing processes and finding the one that runs a program called "reaper" with the arguments SteamLaunch AppId=<number>. The binary comes after the -- argument, get the name of the game by parsing out name from that, in the format steamapps/common/<name>/.
|
||||
|
||||
All steam game names by ID are available at https://api.steampowered.com/ISteamApps/GetAppList/v2/. The name of a single game can be retrieved from http://store.steampowered.com/api/appdetails?appids=115800.
|
||||
|
||||
Dont put widget position to int position when scrolling. This makes the UI jitter when it's coming to a halt.
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "../GsrInfo.hpp"
|
||||
#include "../Config.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace gsr {
|
||||
class GsrPage;
|
||||
class PageStack;
|
||||
@@ -20,8 +22,12 @@ namespace gsr {
|
||||
void load();
|
||||
void save();
|
||||
void on_navigate_away_from_page() override;
|
||||
|
||||
// Called with (enable, exit_status)
|
||||
std::function<void(bool, int)> on_startup_changed;
|
||||
private:
|
||||
std::unique_ptr<Subsection> create_appearance_subsection(ScrollablePage *parent_page);
|
||||
std::unique_ptr<Subsection> create_startup_subsection(ScrollablePage *parent_page);
|
||||
void add_widgets();
|
||||
private:
|
||||
Config &config;
|
||||
@@ -30,5 +36,6 @@ namespace gsr {
|
||||
GsrPage *content_page_ptr = nullptr;
|
||||
PageStack *page_stack = nullptr;
|
||||
RadioButton *tint_color_radio_button_ptr = nullptr;
|
||||
RadioButton *startup_radio_button_ptr = nullptr;
|
||||
};
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "../GsrInfo.hpp"
|
||||
#include "../Config.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace gsr {
|
||||
class GsrPage;
|
||||
class PageStack;
|
||||
|
||||
@@ -979,6 +979,15 @@ namespace gsr {
|
||||
button->set_icon(&get_theme().settings_small_texture);
|
||||
button->on_click = [&]() {
|
||||
auto settings_page = std::make_unique<GlobalSettingsPage>(&gsr_info, config, &page_stack);
|
||||
settings_page->on_startup_changed = [&](bool enable, int exit_status) {
|
||||
if(exit_status == 0)
|
||||
return;
|
||||
|
||||
if(enable)
|
||||
show_notification("Failed to add GPU Screen Recorder to system startup", 3.0, mgl::Color(255, 0, 0), mgl::Color(255, 0, 0), NotificationType::NONE);
|
||||
else
|
||||
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);
|
||||
};
|
||||
page_stack.push(std::move(settings_page));
|
||||
};
|
||||
front_page_ptr->add_widget(std::move(button));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "../../include/gui/GlobalSettingsPage.hpp"
|
||||
|
||||
#include "../../include/Theme.hpp"
|
||||
#include "../../include/Process.hpp"
|
||||
#include "../../include/gui/GsrPage.hpp"
|
||||
#include "../../include/gui/PageStack.hpp"
|
||||
#include "../../include/gui/ScrollablePage.hpp"
|
||||
@@ -59,9 +60,40 @@ namespace gsr {
|
||||
return std::make_unique<Subsection>("Appearance", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
|
||||
}
|
||||
|
||||
std::unique_ptr<Subsection> GlobalSettingsPage::create_startup_subsection(ScrollablePage *parent_page) {
|
||||
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
auto startup_radio_button = std::make_unique<RadioButton>(&get_theme().body_font, RadioButton::Orientation::VERTICAL);
|
||||
startup_radio_button_ptr = startup_radio_button.get();
|
||||
startup_radio_button->add_item("Don't start this program on system startup", "dont_start_on_system_startup");
|
||||
startup_radio_button->add_item("Start this program on system startup", "start_on_system_startup");
|
||||
startup_radio_button->on_selection_changed = [&](const std::string&, const std::string &id) {
|
||||
bool enable = false;
|
||||
if(id == "dont_start_on_system_startup")
|
||||
enable = false;
|
||||
else if(id == "start_on_system_startup")
|
||||
enable = true;
|
||||
else
|
||||
return;
|
||||
|
||||
const char *args[] = { "systemctl", enable ? "enable" : "disable", "--user", "gpu-screen-recorder-ui", nullptr };
|
||||
std::string stdout_str;
|
||||
const int exit_status = exec_program_get_stdout(args, stdout_str);
|
||||
if(on_startup_changed)
|
||||
on_startup_changed(enable, exit_status);
|
||||
};
|
||||
list->add_widget(std::move(startup_radio_button));
|
||||
return std::make_unique<Subsection>("Startup", 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());
|
||||
scrollable_page->add_widget(create_appearance_subsection(scrollable_page.get()));
|
||||
|
||||
auto settings_list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||
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()));
|
||||
scrollable_page->add_widget(std::move(settings_list));
|
||||
|
||||
content_page_ptr->add_widget(std::move(scrollable_page));
|
||||
}
|
||||
|
||||
@@ -74,6 +106,11 @@ namespace gsr {
|
||||
tint_color_radio_button_ptr->set_selected_item(gpu_vendor_to_color_name(gsr_info->gpu_info.vendor));
|
||||
else
|
||||
tint_color_radio_button_ptr->set_selected_item(config.main_config.tint_color);
|
||||
|
||||
const char *args[] = { "systemctl", "is-enabled", "--quiet", "--user", "gpu-screen-recorder-ui", nullptr };
|
||||
std::string stdout_str;
|
||||
const int exit_status = exec_program_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);
|
||||
}
|
||||
|
||||
void GlobalSettingsPage::save() {
|
||||
|
||||
@@ -625,11 +625,11 @@ namespace gsr {
|
||||
|
||||
std::unique_ptr<RadioButton> SettingsPage::create_start_replay_automatically() {
|
||||
char fullscreen_text[256];
|
||||
snprintf(fullscreen_text, sizeof(fullscreen_text), "Turn on replay when starting a fullscreen application%s", gsr_info->system_info.display_server == DisplayServer::X11 ? "" : " (X11 only)");
|
||||
snprintf(fullscreen_text, sizeof(fullscreen_text), "Turn on replay when starting a fullscreen application%s", gsr_info->system_info.display_server == DisplayServer::X11 ? "" : " (X11 applications only)");
|
||||
|
||||
auto radiobutton = std::make_unique<RadioButton>(&get_theme().body_font, RadioButton::Orientation::VERTICAL);
|
||||
radiobutton->add_item("Don't turn on replay automatically", "dont_turn_on_automatically");
|
||||
radiobutton->add_item("Turn on replay at system startup", "turn_on_at_system_startup");
|
||||
radiobutton->add_item("Turn on replay when this program starts", "turn_on_at_system_startup");
|
||||
radiobutton->add_item(fullscreen_text, "turn_on_at_fullscreen");
|
||||
radiobutton->add_item("Turn on replay when power supply is connected", "turn_on_at_power_supply_connected");
|
||||
turn_on_replay_automatically_mode_ptr = radiobutton.get();
|
||||
@@ -638,7 +638,7 @@ namespace gsr {
|
||||
|
||||
std::unique_ptr<CheckBox> SettingsPage::create_save_replay_in_game_folder() {
|
||||
char text[256];
|
||||
snprintf(text, sizeof(text), "Save video in a folder with the name of the game%s", gsr_info->system_info.display_server == DisplayServer::X11 ? "" : " (X11 only)");
|
||||
snprintf(text, sizeof(text), "Save video in a folder with the name of the game%s", gsr_info->system_info.display_server == DisplayServer::X11 ? "" : " (X11 applications only)");
|
||||
auto checkbox = std::make_unique<CheckBox>(&get_theme().body_font, text);
|
||||
save_replay_in_game_folder_ptr = checkbox.get();
|
||||
return checkbox;
|
||||
@@ -719,7 +719,7 @@ namespace gsr {
|
||||
|
||||
std::unique_ptr<CheckBox> SettingsPage::create_save_recording_in_game_folder() {
|
||||
char text[256];
|
||||
snprintf(text, sizeof(text), "Save video in a folder with the name of the game%s", gsr_info->system_info.display_server == DisplayServer::X11 ? "" : " (X11 only)");
|
||||
snprintf(text, sizeof(text), "Save video in a folder with the name of the game%s", gsr_info->system_info.display_server == DisplayServer::X11 ? "" : " (X11 applications only)");
|
||||
auto checkbox = std::make_unique<CheckBox>(&get_theme().body_font, text);
|
||||
save_recording_in_game_folder_ptr = checkbox.get();
|
||||
return checkbox;
|
||||
|
||||
@@ -260,6 +260,8 @@ static bool keyboard_event_try_add_device_if_keyboard(keyboard_event *self, cons
|
||||
};
|
||||
|
||||
keyboard_event_fetch_update_key_states(self, &self->event_extra_data[self->num_event_polls], fd);
|
||||
if(self->event_extra_data[self->num_event_polls].num_keys_pressed > 0)
|
||||
fprintf(stderr, "Info: device not grabbed yet because some keys are still being pressed: /dev/input/event%d\n", dev_input_id);
|
||||
|
||||
++self->num_event_polls;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user