mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-05-06 23:06:24 +09:00
Better global settings design, dont change startup setting in ui if systemctl command fails
This commit is contained in:
@@ -27,7 +27,8 @@ namespace gsr {
|
|||||||
|
|
||||||
mgl::vec2f get_size() override;
|
mgl::vec2f get_size() override;
|
||||||
|
|
||||||
std::function<void(const std::string &text, const std::string &id)> on_selection_changed;
|
// Return false to revert the change
|
||||||
|
std::function<bool(const std::string &text, const std::string &id)> on_selection_changed;
|
||||||
private:
|
private:
|
||||||
void update_if_dirty();
|
void update_if_dirty();
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ namespace gsr {
|
|||||||
get_color_theme().tint_color = mgl::Color(118, 185, 0);
|
get_color_theme().tint_color = mgl::Color(118, 185, 0);
|
||||||
else if(id == "intel")
|
else if(id == "intel")
|
||||||
get_color_theme().tint_color = mgl::Color(8, 109, 183);
|
get_color_theme().tint_color = mgl::Color(8, 109, 183);
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
list->add_widget(std::move(tint_color_radio_button));
|
list->add_widget(std::move(tint_color_radio_button));
|
||||||
return std::make_unique<Subsection>("Appearance", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
|
return std::make_unique<Subsection>("Appearance", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
|
||||||
@@ -62,10 +63,11 @@ namespace gsr {
|
|||||||
|
|
||||||
std::unique_ptr<Subsection> GlobalSettingsPage::create_startup_subsection(ScrollablePage *parent_page) {
|
std::unique_ptr<Subsection> GlobalSettingsPage::create_startup_subsection(ScrollablePage *parent_page) {
|
||||||
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
|
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
|
||||||
auto startup_radio_button = std::make_unique<RadioButton>(&get_theme().body_font, RadioButton::Orientation::VERTICAL);
|
list->add_widget(std::make_unique<Label>(&get_theme().body_font, "Start program on system startup?", get_color_theme().text_color));
|
||||||
|
auto startup_radio_button = std::make_unique<RadioButton>(&get_theme().body_font, RadioButton::Orientation::HORIZONTAL);
|
||||||
startup_radio_button_ptr = startup_radio_button.get();
|
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("Yes", "start_on_system_startup");
|
||||||
startup_radio_button->add_item("Start this program on system startup", "start_on_system_startup");
|
startup_radio_button->add_item("No", "dont_start_on_system_startup");
|
||||||
startup_radio_button->on_selection_changed = [&](const std::string&, const std::string &id) {
|
startup_radio_button->on_selection_changed = [&](const std::string&, const std::string &id) {
|
||||||
bool enable = false;
|
bool enable = false;
|
||||||
if(id == "dont_start_on_system_startup")
|
if(id == "dont_start_on_system_startup")
|
||||||
@@ -73,13 +75,14 @@ namespace gsr {
|
|||||||
else if(id == "start_on_system_startup")
|
else if(id == "start_on_system_startup")
|
||||||
enable = true;
|
enable = true;
|
||||||
else
|
else
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
const char *args[] = { "systemctl", enable ? "enable" : "disable", "--user", "gpu-screen-recorder-ui", nullptr };
|
const char *args[] = { "systemctl", enable ? "enable" : "disable", "--user", "gpu-screen-recorder-ui", nullptr };
|
||||||
std::string stdout_str;
|
std::string stdout_str;
|
||||||
const int exit_status = exec_program_on_host_get_stdout(args, stdout_str);
|
const int exit_status = exec_program_on_host_get_stdout(args, stdout_str);
|
||||||
if(on_startup_changed)
|
if(on_startup_changed)
|
||||||
on_startup_changed(enable, exit_status);
|
on_startup_changed(enable, exit_status);
|
||||||
|
return exit_status == 0;
|
||||||
};
|
};
|
||||||
list->add_widget(std::move(startup_radio_button));
|
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));
|
return std::make_unique<Subsection>("Startup", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
|
||||||
|
|||||||
@@ -35,12 +35,12 @@ namespace gsr {
|
|||||||
|
|
||||||
const bool mouse_inside = mgl::FloatRect(draw_pos, item_size).contains(mgl::vec2f(event.mouse_button.x, event.mouse_button.y));
|
const bool mouse_inside = mgl::FloatRect(draw_pos, item_size).contains(mgl::vec2f(event.mouse_button.x, event.mouse_button.y));
|
||||||
if(mouse_inside) {
|
if(mouse_inside) {
|
||||||
const size_t prev_selected_item = selected_item;
|
if(selected_item != i && on_selection_changed) {
|
||||||
|
if(!on_selection_changed(item.text.get_string(), item.id))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
selected_item = i;
|
selected_item = i;
|
||||||
|
|
||||||
if(selected_item != prev_selected_item && on_selection_changed)
|
|
||||||
on_selection_changed(item.text.get_string(), item.id);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,12 +158,12 @@ namespace gsr {
|
|||||||
for(size_t i = 0; i < items.size(); ++i) {
|
for(size_t i = 0; i < items.size(); ++i) {
|
||||||
auto &item = items[i];
|
auto &item = items[i];
|
||||||
if(item.id == id) {
|
if(item.id == id) {
|
||||||
const size_t prev_selected_item = selected_item;
|
if(trigger_event && (trigger_event_even_if_selection_not_changed || selected_item != i) && on_selection_changed) {
|
||||||
|
if(!on_selection_changed(item.text.get_string(), item.id))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
selected_item = i;
|
selected_item = i;
|
||||||
|
|
||||||
if(trigger_event && (trigger_event_even_if_selection_not_changed || selected_item != prev_selected_item) && on_selection_changed)
|
|
||||||
on_selection_changed(item.text.get_string(), item.id);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -516,6 +516,7 @@ namespace gsr {
|
|||||||
video_resolution_list_ptr->set_visible(!focused_selected && change_video_resolution_checkbox_ptr->is_checked());
|
video_resolution_list_ptr->set_visible(!focused_selected && change_video_resolution_checkbox_ptr->is_checked());
|
||||||
change_video_resolution_checkbox_ptr->set_visible(!focused_selected);
|
change_video_resolution_checkbox_ptr->set_visible(!focused_selected);
|
||||||
restore_portal_session_list_ptr->set_visible(portal_selected);
|
restore_portal_session_list_ptr->set_visible(portal_selected);
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
change_video_resolution_checkbox_ptr->on_changed = [this](bool checked) {
|
change_video_resolution_checkbox_ptr->on_changed = [this](bool checked) {
|
||||||
@@ -530,6 +531,8 @@ namespace gsr {
|
|||||||
|
|
||||||
if(estimated_file_size_ptr)
|
if(estimated_file_size_ptr)
|
||||||
estimated_file_size_ptr->set_visible(custom_selected);
|
estimated_file_size_ptr->set_visible(custom_selected);
|
||||||
|
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
video_quality_box_ptr->on_selection_changed("", video_quality_box_ptr->get_selected_id());
|
video_quality_box_ptr->on_selection_changed("", video_quality_box_ptr->get_selected_id());
|
||||||
|
|
||||||
@@ -705,6 +708,7 @@ namespace gsr {
|
|||||||
framerate_mode_list_ptr->set_visible(advanced_view);
|
framerate_mode_list_ptr->set_visible(advanced_view);
|
||||||
notifications_subsection_ptr->set_visible(advanced_view);
|
notifications_subsection_ptr->set_visible(advanced_view);
|
||||||
settings_scrollable_page_ptr->reset_scroll();
|
settings_scrollable_page_ptr->reset_scroll();
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
view_radio_button_ptr->on_selection_changed("Simple", "simple");
|
view_radio_button_ptr->on_selection_changed("Simple", "simple");
|
||||||
|
|
||||||
@@ -760,6 +764,7 @@ namespace gsr {
|
|||||||
framerate_mode_list_ptr->set_visible(advanced_view);
|
framerate_mode_list_ptr->set_visible(advanced_view);
|
||||||
notifications_subsection_ptr->set_visible(advanced_view);
|
notifications_subsection_ptr->set_visible(advanced_view);
|
||||||
settings_scrollable_page_ptr->reset_scroll();
|
settings_scrollable_page_ptr->reset_scroll();
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
view_radio_button_ptr->on_selection_changed("Simple", "simple");
|
view_radio_button_ptr->on_selection_changed("Simple", "simple");
|
||||||
}
|
}
|
||||||
@@ -860,6 +865,7 @@ namespace gsr {
|
|||||||
container_list_ptr->set_visible(custom_option);
|
container_list_ptr->set_visible(custom_option);
|
||||||
twitch_stream_key_entry_ptr->set_visible(twitch_option);
|
twitch_stream_key_entry_ptr->set_visible(twitch_option);
|
||||||
youtube_stream_key_entry_ptr->set_visible(youtube_option);
|
youtube_stream_key_entry_ptr->set_visible(youtube_option);
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
streaming_service_box_ptr->on_selection_changed("Twitch", "twitch");
|
streaming_service_box_ptr->on_selection_changed("Twitch", "twitch");
|
||||||
|
|
||||||
@@ -872,6 +878,7 @@ namespace gsr {
|
|||||||
framerate_mode_list_ptr->set_visible(advanced_view);
|
framerate_mode_list_ptr->set_visible(advanced_view);
|
||||||
notifications_subsection_ptr->set_visible(advanced_view);
|
notifications_subsection_ptr->set_visible(advanced_view);
|
||||||
settings_scrollable_page_ptr->reset_scroll();
|
settings_scrollable_page_ptr->reset_scroll();
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
view_radio_button_ptr->on_selection_changed("Simple", "simple");
|
view_radio_button_ptr->on_selection_changed("Simple", "simple");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user