diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index c791aa9f4..95189e510 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -3,6 +3,9 @@ on: pull_request: branches: [ master, stable* ] +permissions: + pull-requests: write + jobs: build: runs-on: ubuntu-latest diff --git a/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp b/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp index 3da64e82c..39e1af833 100644 --- a/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp +++ b/client/SDL/SDL2/dialogs/sdl_connection_dialog.cpp @@ -330,23 +330,16 @@ bool SDLConnectionDialog::createWindow() const size_t widget_width = 600; const size_t total_height = 300; - _window = SDL_CreateWindow( - _title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, widget_width, - total_height, SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS); - if (_window == nullptr) + auto flags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS; + auto rc = SDL_CreateWindowAndRenderer(widget_width, widget_height, flags, &_window, &_renderer); + if (rc != 0) { - widget_log_error(-1, "SDL_CreateWindow"); + widget_log_error(rc, "SDL_CreateWindowAndRenderer"); return false; } + SDL_SetWindowTitle(_window, _title.c_str()); setModal(); - _renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED); - if (_renderer == nullptr) - { - widget_log_error(-1, "SDL_CreateRenderer"); - return false; - } - SDL_Color res_bgcolor; switch (_type_active) { diff --git a/client/SDL/SDL2/dialogs/sdl_input_widgets.cpp b/client/SDL/SDL2/dialogs/sdl_input_widgets.cpp index 99e5270b8..9e9209b22 100644 --- a/client/SDL/SDL2/dialogs/sdl_input_widgets.cpp +++ b/client/SDL/SDL2/dialogs/sdl_input_widgets.cpp @@ -22,32 +22,22 @@ SdlInputWidgetList::SdlInputWidgetList(const std::string& title, const size_t total_width = widget_width + widget_width; const size_t input_height = labels.size() * (widget_heigth + vpadding) + vpadding; const size_t total_height = input_height + widget_heigth; - _window = SDL_CreateWindow( - title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, total_width, total_height, - SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS); - if (_window == nullptr) - { - widget_log_error(-1, "SDL_CreateWindow"); - } + + auto wflags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS; + auto rc = SDL_CreateWindowAndRenderer(total_width, total_height, wflags, &_window, &_renderer); + if (rc != 0) + widget_log_error(rc, "SDL_CreateWindowAndRenderer"); else { + SDL_SetWindowTitle(_window, title.c_str()); + for (size_t x = 0; x < labels.size(); x++) + _list.emplace_back(_renderer, labels[x], initial[x], flags[x], x, widget_width, + widget_heigth); - _renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED); - if (_renderer == nullptr) - { - widget_log_error(-1, "SDL_CreateRenderer"); - } - else - { - for (size_t x = 0; x < labels.size(); x++) - _list.emplace_back(_renderer, labels[x], initial[x], flags[x], x, widget_width, - widget_heigth); - - _buttons.populate(_renderer, buttonlabels, buttonids, total_width, - static_cast(input_height), static_cast(widget_width), - static_cast(widget_heigth)); - _buttons.set_highlight(0); - } + _buttons.populate(_renderer, buttonlabels, buttonids, total_width, + static_cast(input_height), static_cast(widget_width), + static_cast(widget_heigth)); + _buttons.set_highlight(0); } } diff --git a/client/SDL/SDL2/dialogs/sdl_selectlist.cpp b/client/SDL/SDL2/dialogs/sdl_selectlist.cpp index 20437cc77..200543113 100644 --- a/client/SDL/SDL2/dialogs/sdl_selectlist.cpp +++ b/client/SDL/SDL2/dialogs/sdl_selectlist.cpp @@ -9,37 +9,28 @@ SdlSelectList::SdlSelectList(const std::string& title, const std::vector buttonids = { INPUT_BUTTON_ACCEPT, INPUT_BUTTON_CANCEL }; - const std::vector buttonlabels = { "accept", "cancel" }; - _buttons.populate( - _renderer, buttonlabels, buttonids, widget_width, static_cast(total_height), - static_cast(widget_width / 2), static_cast(widget_height)); - _buttons.set_highlight(0); + SDL_Rect rect = { 0, 0, widget_width, widget_height }; + for (auto& label : labels) + { + _list.emplace_back(_renderer, label, rect); + rect.y += widget_height + vpadding; } + + const std::vector buttonids = { INPUT_BUTTON_ACCEPT, INPUT_BUTTON_CANCEL }; + const std::vector buttonlabels = { "accept", "cancel" }; + _buttons.populate(_renderer, buttonlabels, buttonids, widget_width, + static_cast(total_height), static_cast(widget_width / 2), + static_cast(widget_height)); + _buttons.set_highlight(0); } } diff --git a/client/SDL/SDL2/dialogs/sdl_widget.hpp b/client/SDL/SDL2/dialogs/sdl_widget.hpp index ebc7dbd49..a376ebff0 100644 --- a/client/SDL/SDL2/dialogs/sdl_widget.hpp +++ b/client/SDL/SDL2/dialogs/sdl_widget.hpp @@ -49,7 +49,9 @@ class SdlWidget { public: SdlWidget(SDL_Renderer* renderer, const SDL_Rect& rect, bool input); +#if defined(WITH_SDL_IMAGE_DIALOGS) SdlWidget(SDL_Renderer* renderer, const SDL_Rect& rect, SDL_RWops* ops); +#endif SdlWidget(SdlWidget&& other) noexcept; virtual ~SdlWidget(); diff --git a/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp b/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp index 85ff5a7b4..004e38cfa 100644 --- a/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp +++ b/client/SDL/SDL3/dialogs/sdl_connection_dialog.cpp @@ -326,23 +326,17 @@ bool SDLConnectionDialog::createWindow() const size_t widget_width = 600; const size_t total_height = 300; - _window = SDL_CreateWindow(_title.c_str(), widget_width, total_height, - SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_MOUSE_FOCUS | - SDL_WINDOW_INPUT_FOCUS); - if (_window == nullptr) + auto rc = SDL_CreateWindowAndRenderer(title.c_str(), widget_width, total_height, + SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_MOUSE_FOCUS | + SDL_WINDOW_INPUT_FOCUS, + &_window, &_renderer); + if (rc != 0) { - widget_log_error(-1, "SDL_CreateWindow"); + widget_log_error(rc, "SDL_CreateWindowAndRenderer"); return false; } setModal(); - _renderer = SDL_CreateRenderer(_window, nullptr, SDL_RENDERER_PRESENTVSYNC); - if (_renderer == nullptr) - { - widget_log_error(-1, "SDL_CreateRenderer"); - return false; - } - SDL_Color res_bgcolor; switch (_type_active) { diff --git a/client/SDL/SDL3/dialogs/sdl_input_widgets.cpp b/client/SDL/SDL3/dialogs/sdl_input_widgets.cpp index a185f54ab..532071906 100644 --- a/client/SDL/SDL3/dialogs/sdl_input_widgets.cpp +++ b/client/SDL/SDL3/dialogs/sdl_input_widgets.cpp @@ -22,32 +22,22 @@ SdlInputWidgetList::SdlInputWidgetList(const std::string& title, const size_t total_width = widget_width + widget_width; const size_t input_height = labels.size() * (widget_heigth + vpadding) + vpadding; const size_t total_height = input_height + widget_heigth; - _window = SDL_CreateWindow(title.c_str(), total_width, total_height, - SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_MOUSE_FOCUS | - SDL_WINDOW_INPUT_FOCUS); - if (_window == nullptr) - { - widget_log_error(-1, "SDL_CreateWindow"); - } + auto rc = SDL_CreateWindowAndRenderer(title.c_str(), total_width, total_height, + SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_MOUSE_FOCUS | + SDL_WINDOW_INPUT_FOCUS, + &_window, &_renderer); + if (rc != 0) + widget_log_error(rc, "SDL_CreateWindowAndRenderer"); else { + for (size_t x = 0; x < labels.size(); x++) + _list.emplace_back(_renderer, labels[x], initial[x], flags[x], x, widget_width, + widget_heigth); - _renderer = SDL_CreateRenderer(_window, nullptr, SDL_RENDERER_PRESENTVSYNC); - if (_renderer == nullptr) - { - widget_log_error(-1, "SDL_CreateRenderer"); - } - else - { - for (size_t x = 0; x < labels.size(); x++) - _list.emplace_back(_renderer, labels[x], initial[x], flags[x], x, widget_width, - widget_heigth); - - _buttons.populate(_renderer, buttonlabels, buttonids, total_width, - static_cast(input_height), static_cast(widget_width), - static_cast(widget_heigth)); - _buttons.set_highlight(0); - } + _buttons.populate(_renderer, buttonlabels, buttonids, total_width, + static_cast(input_height), static_cast(widget_width), + static_cast(widget_heigth)); + _buttons.set_highlight(0); } } diff --git a/client/SDL/SDL3/dialogs/sdl_selectlist.cpp b/client/SDL/SDL3/dialogs/sdl_selectlist.cpp index 3aaf00c18..adb1455f1 100644 --- a/client/SDL/SDL3/dialogs/sdl_selectlist.cpp +++ b/client/SDL/SDL3/dialogs/sdl_selectlist.cpp @@ -9,36 +9,27 @@ SdlSelectList::SdlSelectList(const std::string& title, const std::vector buttonids = { INPUT_BUTTON_ACCEPT, INPUT_BUTTON_CANCEL }; - const std::vector buttonlabels = { "accept", "cancel" }; - _buttons.populate( - _renderer, buttonlabels, buttonids, widget_width, static_cast(total_height), - static_cast(widget_width / 2), static_cast(widget_height)); - _buttons.set_highlight(0); - } + const std::vector buttonids = { INPUT_BUTTON_ACCEPT, INPUT_BUTTON_CANCEL }; + const std::vector buttonlabels = { "accept", "cancel" }; + _buttons.populate(_renderer, buttonlabels, buttonids, widget_width, + static_cast(total_height), static_cast(widget_width / 2), + static_cast(widget_height)); + _buttons.set_highlight(0); } } diff --git a/client/SDL/common/res/CMakeLists.txt b/client/SDL/common/res/CMakeLists.txt index ec7e9c787..f2f7fd8fe 100644 --- a/client/SDL/common/res/CMakeLists.txt +++ b/client/SDL/common/res/CMakeLists.txt @@ -19,6 +19,10 @@ add_executable(sdl-common-res2bin convert_res_to_c.cpp ) +set(FACTORY_SRCS "") +set(FACTORY_HDR "") +set(FACTORY_CLASSES "") + macro(convert_to_bin FILE FILE_TYPE) get_filename_component(FILE_NAME ${FILE} NAME) string(REGEX REPLACE "[^a-zA-Z0-9]" "_" TARGET_NAME ${FILE_NAME}) @@ -26,9 +30,16 @@ macro(convert_to_bin FILE FILE_TYPE) set(FILE_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin) set(FILE_BYPRODUCTS ${FILE_BIN_DIR}/${TARGET_NAME}.hpp ${FILE_BIN_DIR}/${TARGET_NAME}.cpp) - list(APPEND FACTORY_SRCS - ${FILE_BYPRODUCTS} + list(APPEND FACTORY_HDR + ${FILE_BIN_DIR}/${TARGET_NAME}.hpp ) + list(APPEND FACTORY_SRCS + ${FILE_BIN_DIR}/${TARGET_NAME}.cpp + ) + +list(APPEND FACTORY_CLASSES + ${TARGET_NAME} +) add_custom_command( OUTPUT ${FILE_BYPRODUCTS} @@ -68,14 +79,28 @@ if (SDL_USE_COMPILED_RESOURCES) if (WITH_SDL_IMAGE_DIALOGS) foreach(FILE ${RES_SVG_FILES}) - convert_to_bin("${FILE}" "images") + convert_to_bin("${FILE}" "images") endforeach() endif() foreach(FILE ${RES_FONT_FILES}) - convert_to_bin("${FILE}" "fonts") + convert_to_bin("${FILE}" "fonts") endforeach() add_definitions(-DSDL_USE_COMPILED_RESOURCES) + + set(FINIT ${CMAKE_CURRENT_BINARY_DIR}/resource-init.cpp) + list(APPEND FACTORY_SRCS ${FINIT}) + + write_file(${FINIT} "#include ") + foreach(HDR ${FACTORY_HDR}) + write_file(${FINIT} "#include <${HDR}>" APPEND) + endforeach() + + write_file(${FINIT} "void SDLResourceManager::init() {" APPEND) + foreach(CLASS ${FACTORY_CLASSES}) + write_file(${FINIT} "\t${CLASS}::init();" APPEND) + endforeach() + write_file(${FINIT} "}" APPEND) else() set(SDL_RESOURCE_ROOT ${CMAKE_INSTALL_FULL_DATAROOTDIR}/FreeRDP) if (WITH_BINARY_VERSIONING) @@ -97,9 +122,10 @@ else() ) endif() -add_library(sdl-common-client-res OBJECT +add_library(sdl-common-client-res STATIC ${RES_FILES} ${SRCS} + ${FACTORY_HDR} ${FACTORY_SRCS} ) set_property(TARGET sdl-common-client-res PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/client/SDL/common/res/convert_res_to_c.cpp b/client/SDL/common/res/convert_res_to_c.cpp index 8ef828adf..33e475a64 100644 --- a/client/SDL/common/res/convert_res_to_c.cpp +++ b/client/SDL/common/res/convert_res_to_c.cpp @@ -128,13 +128,14 @@ static int write_hpp_header(const fs::path& prg, const fs::path& file, const std << "#include \"sdl_resource_file.hpp\"" << std::endl << std::endl << "class " << name << " {" << std::endl + << "friend class SDLResourceManager;" << std::endl << "public:" << std::endl << name << "() = delete;" << std::endl << std::endl << "static std::string name();" << std::endl << "static std::string type();" << std::endl << std::endl - << "private:" << std::endl + << "protected:" << std::endl << "static std::vector init();" << std::endl << "static const SDLResourceFile _initializer;" << std::endl << std::endl diff --git a/client/SDL/common/res/sdl_resource_manager.cpp b/client/SDL/common/res/sdl_resource_manager.cpp index f036cf6c3..9fa160d27 100644 --- a/client/SDL/common/res/sdl_resource_manager.cpp +++ b/client/SDL/common/res/sdl_resource_manager.cpp @@ -93,5 +93,7 @@ std::map>& SDLResourceManager::resources { static std::map> resources = {}; + if (resources.empty()) + init(); return resources; } diff --git a/client/SDL/common/res/sdl_resource_manager.hpp b/client/SDL/common/res/sdl_resource_manager.hpp index eeda36506..b120520d2 100644 --- a/client/SDL/common/res/sdl_resource_manager.hpp +++ b/client/SDL/common/res/sdl_resource_manager.hpp @@ -47,4 +47,5 @@ class SDLResourceManager private: static std::map>& resources(); + static void init(); // implemented in generated file };