#include "../../include/gui/GlobalSettingsPage.hpp" #include "../../include/Overlay.hpp" #include "../../include/GlobalHotkeys.hpp" #include "../../include/Theme.hpp" #include "../../include/Process.hpp" #include "../../include/gui/GsrPage.hpp" #include "../../include/gui/PageStack.hpp" #include "../../include/gui/ScrollablePage.hpp" #include "../../include/gui/Subsection.hpp" #include "../../include/gui/List.hpp" #include "../../include/gui/Label.hpp" #include "../../include/gui/RadioButton.hpp" #include "../../include/gui/LineSeparator.hpp" #include "../../include/gui/CustomRendererWidget.hpp" #include #include extern "C" { #include } #include #include #include #ifndef GSR_UI_VERSION #define GSR_UI_VERSION "Unknown" #endif #ifndef GSR_FLATPAK_VERSION #define GSR_FLATPAK_VERSION "Unknown" #endif namespace gsr { static const char* gpu_vendor_to_color_name(GpuVendor vendor) { switch(vendor) { case GpuVendor::UNKNOWN: return "amd"; case GpuVendor::AMD: return "amd"; case GpuVendor::INTEL: return "intel"; case GpuVendor::NVIDIA: return "nvidia"; } return "amd"; } static const char* gpu_vendor_to_string(GpuVendor vendor) { switch(vendor) { case GpuVendor::UNKNOWN: return "Unknown"; case GpuVendor::AMD: return "AMD"; case GpuVendor::INTEL: return "Intel"; case GpuVendor::NVIDIA: return "NVIDIA"; } return "unknown"; } static uint32_t mgl_modifier_to_hotkey_modifier(mgl::Keyboard::Key modifier_key) { switch(modifier_key) { case mgl::Keyboard::LControl: return HOTKEY_MOD_LCTRL; case mgl::Keyboard::LShift: return HOTKEY_MOD_LSHIFT; case mgl::Keyboard::LAlt: return HOTKEY_MOD_LALT; case mgl::Keyboard::LSystem: return HOTKEY_MOD_LSUPER; case mgl::Keyboard::RControl: return HOTKEY_MOD_RCTRL; case mgl::Keyboard::RShift: return HOTKEY_MOD_RSHIFT; case mgl::Keyboard::RAlt: return HOTKEY_MOD_RALT; case mgl::Keyboard::RSystem: return HOTKEY_MOD_RSUPER; default: return 0; } return 0; } static std::vector hotkey_modifiers_to_mgl_keys(uint32_t modifiers) { std::vector result; if(modifiers & HOTKEY_MOD_LCTRL) result.push_back(mgl::Keyboard::LControl); if(modifiers & HOTKEY_MOD_LSHIFT) result.push_back(mgl::Keyboard::LShift); if(modifiers & HOTKEY_MOD_LALT) result.push_back(mgl::Keyboard::LAlt); if(modifiers & HOTKEY_MOD_LSUPER) result.push_back(mgl::Keyboard::LSystem); if(modifiers & HOTKEY_MOD_RCTRL) result.push_back(mgl::Keyboard::RControl); if(modifiers & HOTKEY_MOD_RSHIFT) result.push_back(mgl::Keyboard::RShift); if(modifiers & HOTKEY_MOD_RALT) result.push_back(mgl::Keyboard::RAlt); if(modifiers & HOTKEY_MOD_RSUPER) result.push_back(mgl::Keyboard::RSystem); return result; } static std::string config_hotkey_to_string(ConfigHotkey config_hotkey) { std::string result; const std::vector modifier_keys = hotkey_modifiers_to_mgl_keys(config_hotkey.modifiers); for(const mgl::Keyboard::Key modifier_key : modifier_keys) { if(!result.empty()) result += " + "; result += mgl::Keyboard::key_to_string(modifier_key); } if(config_hotkey.key != 0) { if(!result.empty()) result += " + "; result += mgl::Keyboard::key_to_string((mgl::Keyboard::Key)config_hotkey.key); } return result; } GlobalSettingsPage::GlobalSettingsPage(Overlay *overlay, const GsrInfo *gsr_info, Config &config, PageStack *page_stack) : StaticPage(mgl::vec2f(get_theme().window_width, get_theme().window_height).floor()), overlay(overlay), config(config), gsr_info(gsr_info), page_stack(page_stack) { auto content_page = std::make_unique(); content_page->add_button("Back", "back", get_color_theme().page_bg_color); content_page->on_click = [page_stack](const std::string &id) { if(id == "back") page_stack->pop(); }; content_page_ptr = content_page.get(); add_widget(std::move(content_page)); add_widgets(); load(); auto hotkey_overlay = std::make_unique(get_size()); hotkey_overlay->draw_handler = [this](mgl::Window &window, mgl::vec2f, mgl::vec2f) { Button *configure_hotkey_button = configure_hotkey_get_button_by_active_type(); if(!configure_hotkey_button) return; mgl::Text title_text("Press a key combination to use for the hotkey \"Start/stop recording\":", get_theme().title_font); mgl::Text hotkey_text(configure_hotkey_button->get_text(), get_theme().top_bar_font); mgl::Text description_text("The hotkey has to contain one or more of these keys: Alt, Ctrl, Shift and Super. Press Esc to cancel.", get_theme().body_font); const float text_max_width = std::max(title_text.get_bounds().size.x, std::max(hotkey_text.get_bounds().size.x, description_text.get_bounds().size.x)); const float padding_horizontal = int(get_theme().window_height * 0.01f); const float padding_vertical = int(get_theme().window_height * 0.01f); const mgl::vec2f bg_size = mgl::vec2f(text_max_width + padding_horizontal*2.0f, get_theme().window_height * 0.1f).floor(); mgl::Rectangle bg_rect(mgl::vec2f(get_theme().window_width*0.5f - bg_size.x*0.5f, get_theme().window_height*0.5f - bg_size.y*0.5f).floor(), bg_size); bg_rect.set_color(get_color_theme().page_bg_color); window.draw(bg_rect); const mgl::vec2f tint_size = mgl::vec2f(bg_size.x, 0.004f * get_theme().window_height).floor(); mgl::Rectangle tint_rect(bg_rect.get_position() - mgl::vec2f(0.0f, tint_size.y), tint_size); tint_rect.set_color(get_color_theme().tint_color); window.draw(tint_rect); title_text.set_position(mgl::vec2f(bg_rect.get_position() + mgl::vec2f(bg_rect.get_size().x*0.5f - title_text.get_bounds().size.x*0.5f, padding_vertical)).floor()); window.draw(title_text); //const float description_bottom = description_text.get_position().y + description_text.get_bounds().size.y; //const float remaining_height = (bg_rect.get_position().y + bg_rect.get_size().y) - description_bottom; hotkey_text.set_position(mgl::vec2f(bg_rect.get_position() + bg_rect.get_size()*0.5f - hotkey_text.get_bounds().size*0.5f).floor()); window.draw(hotkey_text); description_text.set_position(mgl::vec2f(bg_rect.get_position() + mgl::vec2f(bg_rect.get_size().x*0.5f - description_text.get_bounds().size.x*0.5f, bg_rect.get_size().y - description_text.get_bounds().size.y - padding_vertical)).floor()); window.draw(description_text); }; hotkey_overlay->set_visible(false); hotkey_overlay_ptr = hotkey_overlay.get(); add_widget(std::move(hotkey_overlay)); } std::unique_ptr GlobalSettingsPage::create_appearance_subsection(ScrollablePage *parent_page) { auto list = std::make_unique(List::Orientation::VERTICAL); list->add_widget(std::make_unique