[client,sdl] add nodiscard to functions

This commit is contained in:
akallabeth
2026-01-23 19:45:10 +01:00
parent 845ef25997
commit 4c15ec1b99
34 changed files with 235 additions and 192 deletions

View File

@@ -34,5 +34,5 @@ class SDL3ResourceManager : public SDLResourceManager
SDL3ResourceManager& operator=(const SDL3ResourceManager& other) = delete;
SDL3ResourceManager& operator=(SDL3ResourceManager&& other) = delete;
static SDL_IOStream* get(const std::string& type, const std::string& id);
[[nodiscard]] static SDL_IOStream* get(const std::string& type, const std::string& id);
};

View File

@@ -37,7 +37,7 @@ class SdlBlendModeGuard
SdlBlendModeGuard& operator=(const SdlBlendModeGuard& other) = delete;
SdlBlendModeGuard& operator=(SdlBlendModeGuard&& other) = delete;
bool update(SDL_BlendMode mode);
[[nodiscard]] bool update(SDL_BlendMode mode);
private:
SDL_BlendMode _restore_mode = SDL_BLENDMODE_INVALID;

View File

@@ -31,8 +31,8 @@ SdlButton::SdlButton(std::shared_ptr<SDL_Renderer>& renderer, const std::string&
_highlightcolor = { 0xcd, 0xca, 0x35, 0x60 };
_mouseovercolor = { 0x66, 0xff, 0x66, 0x60 };
_fontcolor = { 0xd1, 0xcf, 0xcd, 0xff };
update_text(label);
update();
(void)update_text(label);
(void)update();
}
SdlButton::SdlButton(SdlButton&& other) noexcept = default;

View File

@@ -95,8 +95,10 @@ bool SdlButtonList::update()
{
for (auto& btn : _list)
{
btn->highlight(btn == _highlighted);
btn->mouseover(btn == _mouseover);
if (!btn->highlight(btn == _highlighted))
return false;
if (!btn->mouseover(btn == _mouseover))
return false;
if (!btn->update())
return false;

View File

@@ -17,17 +17,17 @@ class SdlButtonList
SdlButtonList& operator=(const SdlButtonList& other) = delete;
SdlButtonList& operator=(SdlButtonList&& other) = delete;
bool populate(std::shared_ptr<SDL_Renderer>& renderer, const std::vector<std::string>& labels,
const std::vector<int>& ids, Sint32 total_width, Sint32 offsetY, Sint32 width,
Sint32 height);
[[nodiscard]] bool populate(std::shared_ptr<SDL_Renderer>& renderer,
const std::vector<std::string>& labels, const std::vector<int>& ids,
Sint32 total_width, Sint32 offsetY, Sint32 width, Sint32 height);
bool update();
std::shared_ptr<SdlButton> get_selected(const SDL_MouseButtonEvent& button);
std::shared_ptr<SdlButton> get_selected(float x, float y);
[[nodiscard]] bool update();
[[nodiscard]] std::shared_ptr<SdlButton> get_selected(const SDL_MouseButtonEvent& button);
[[nodiscard]] std::shared_ptr<SdlButton> get_selected(float x, float y);
bool set_highlight_next(bool reset = false);
bool set_highlight(size_t index);
bool set_mouseover(float x, float y);
[[nodiscard]] bool set_highlight_next(bool reset = false);
[[nodiscard]] bool set_highlight(size_t index);
[[nodiscard]] bool set_mouseover(float x, float y);
void clear();

View File

@@ -34,7 +34,7 @@ static const Uint32 hpadding = 5;
SDLConnectionDialog::SDLConnectionDialog(rdpContext* context) : _context(context)
{
hide();
(void)hide();
}
SDLConnectionDialog::~SDLConnectionDialog()
@@ -109,7 +109,8 @@ bool SDLConnectionDialog::updateMsg(SdlConnectionDialogWrapper::MsgType type)
case SdlConnectionDialogWrapper::MSG_WARN:
case SdlConnectionDialogWrapper::MSG_ERROR:
_type_active = type;
createWindow();
if (!createWindow())
return false;
break;
case SdlConnectionDialogWrapper::MSG_DISCARD:
resetTimer();
@@ -192,7 +193,8 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
if (visible())
{
auto& ev = reinterpret_cast<const SDL_KeyboardEvent&>(event);
update();
if (!update())
return false;
switch (event.key.key)
{
case SDLK_RETURN:
@@ -206,7 +208,8 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
}
break;
case SDLK_TAB:
_buttons.set_highlight_next();
if (!_buttons.set_highlight_next())
return false;
break;
default:
break;
@@ -220,8 +223,10 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
{
auto& ev = reinterpret_cast<const SDL_MouseMotionEvent&>(event);
_buttons.set_mouseover(event.button.x, event.button.y);
update();
if (!_buttons.set_mouseover(event.button.x, event.button.y))
return false;
if (!update())
return false;
return windowID == ev.windowID;
}
return false;
@@ -230,7 +235,8 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
if (visible())
{
auto& ev = reinterpret_cast<const SDL_MouseButtonEvent&>(event);
update();
if (!update())
return false;
auto button = _buttons.get_selected(event.button);
if (button)
@@ -249,7 +255,8 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
if (visible())
{
auto& ev = reinterpret_cast<const SDL_MouseWheelEvent&>(event);
update();
if (!update())
return false;
return windowID == ev.windowID;
}
return false;
@@ -258,7 +265,8 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
if (visible())
{
auto& ev = reinterpret_cast<const SDL_TouchFingerEvent&>(event);
update();
if (!update())
return false;
return windowID == ev.windowID;
}
return false;
@@ -276,8 +284,10 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
}
break;
default:
update();
setModal();
if (!update())
return false;
if (!setModal())
return false;
break;
}
@@ -304,7 +314,8 @@ bool SDLConnectionDialog::createWindow()
if (!reset(_title, widget_width, total_height))
return false;
setModal();
if (!setModal())
return false;
SDL_Color res_bgcolor;
switch (_type_active)
@@ -369,19 +380,25 @@ bool SDLConnectionDialog::createWindow()
#endif
widget_cfg_t w{ textcolor, _backgroundcolor, { _renderer, rect } };
w.widget.set_wrap(true, widget_width);
if (!w.widget.set_wrap(true, widget_width))
return false;
_list.emplace_back(std::move(w));
rect.y += widget_height + vpadding;
const std::vector<int> buttonids = { 1 };
const std::vector<std::string> buttonlabels = { "cancel" };
_buttons.populate(_renderer, buttonlabels, buttonids, widget_width,
total_height - widget_height - vpadding,
static_cast<Sint32>(widget_width / 2), static_cast<Sint32>(widget_height));
_buttons.set_highlight(0);
if (!_buttons.populate(_renderer, buttonlabels, buttonids, widget_width,
total_height - widget_height - vpadding,
static_cast<Sint32>(widget_width / 2),
static_cast<Sint32>(widget_height)))
return false;
if (!_buttons.set_highlight(0))
return false;
SDL_ShowWindow(_window.get());
SDL_RaiseWindow(_window.get());
if (!SDL_ShowWindow(_window.get()))
return false;
if (!SDL_RaiseWindow(_window.get()))
return false;
return true;
}
@@ -455,7 +472,7 @@ Uint32 SDLConnectionDialog::timeout(void* pvthis, [[maybe_unused]] SDL_TimerID t
[[maybe_unused]] Uint32 intervalMS)
{
auto self = static_cast<SDLConnectionDialog*>(pvthis);
self->hide();
(void)self->hide();
self->_running = false;
return 0;
}

View File

@@ -42,40 +42,40 @@ class SDLConnectionDialog : public SdlWidgetList
SDLConnectionDialog& operator=(const SDLConnectionDialog& other) = delete;
SDLConnectionDialog& operator=(SDLConnectionDialog&& other) = delete;
bool setTitle(const char* fmt, ...);
bool showInfo(const char* fmt, ...);
bool showWarn(const char* fmt, ...);
bool showError(const char* fmt, ...);
[[nodiscard]] bool setTitle(const char* fmt, ...);
[[nodiscard]] bool showInfo(const char* fmt, ...);
[[nodiscard]] bool showWarn(const char* fmt, ...);
[[nodiscard]] bool showError(const char* fmt, ...);
bool show();
bool hide();
[[nodiscard]] bool show();
[[nodiscard]] bool hide();
bool running() const;
bool wait(bool ignoreRdpContextQuit = false);
[[nodiscard]] bool running() const;
[[nodiscard]] bool wait(bool ignoreRdpContextQuit = false);
bool handle(const SDL_Event& event);
[[nodiscard]] bool handle(const SDL_Event& event);
bool visible() const override;
[[nodiscard]] bool visible() const override;
protected:
bool updateInternal() override;
[[nodiscard]] bool updateInternal() override;
private:
bool createWindow();
[[nodiscard]] bool createWindow();
void destroyWindow();
bool updateMsg(SdlConnectionDialogWrapper::MsgType type);
[[nodiscard]] bool updateMsg(SdlConnectionDialogWrapper::MsgType type);
bool setModal();
[[nodiscard]] bool setModal();
bool show(SdlConnectionDialogWrapper::MsgType type, const char* fmt, va_list ap);
bool show(SdlConnectionDialogWrapper::MsgType type);
[[nodiscard]] bool show(SdlConnectionDialogWrapper::MsgType type, const char* fmt, va_list ap);
[[nodiscard]] bool show(SdlConnectionDialogWrapper::MsgType type);
static std::string print(const char* fmt, va_list ap);
bool setTimer(Uint32 timeoutMS = 15000);
[[nodiscard]] static std::string print(const char* fmt, va_list ap);
[[nodiscard]] bool setTimer(Uint32 timeoutMS = 15000);
void resetTimer();
static Uint32 timeout(void* pvthis, SDL_TimerID timerID, Uint32 intervalMS);
[[nodiscard]] static Uint32 timeout(void* pvthis, SDL_TimerID timerID, Uint32 intervalMS);
struct widget_cfg_t
{

View File

@@ -166,7 +166,7 @@ void SdlConnectionDialogWrapper::handleShow()
if (arg.hasTitle() && _connection_dialog)
{
_connection_dialog->setTitle(arg.title().c_str());
(void)_connection_dialog->setTitle(arg.title().c_str());
}
if (arg.hasType() && arg.hasMessage())
@@ -175,19 +175,19 @@ void SdlConnectionDialogWrapper::handleShow()
{
case SdlConnectionDialogWrapper::MSG_INFO:
if (_connection_dialog)
_connection_dialog->showInfo(arg.message().c_str());
(void)_connection_dialog->showInfo(arg.message().c_str());
else
WLog_Print(_log, WLOG_INFO, "%s", arg.message().c_str());
break;
case SdlConnectionDialogWrapper::MSG_WARN:
if (_connection_dialog)
_connection_dialog->showWarn(arg.message().c_str());
(void)_connection_dialog->showWarn(arg.message().c_str());
else
WLog_Print(_log, WLOG_WARN, "%s", arg.message().c_str());
break;
case SdlConnectionDialogWrapper::MSG_ERROR:
if (_connection_dialog)
_connection_dialog->showError(arg.message().c_str());
(void)_connection_dialog->showError(arg.message().c_str());
else
WLog_Print(_log, WLOG_ERROR, "%s", arg.message().c_str());
break;
@@ -199,9 +199,9 @@ void SdlConnectionDialogWrapper::handleShow()
if (arg.hasVisibility() && _connection_dialog)
{
if (arg.visible())
_connection_dialog->show();
(void)_connection_dialog->show();
else
_connection_dialog->hide();
(void)_connection_dialog->hide();
}
}
}

View File

@@ -57,10 +57,10 @@ class SdlConnectionDialogWrapper
void create(rdpContext* context);
void destroy();
bool isRunning() const;
bool isVisible() const;
[[nodiscard]] bool isRunning() const;
[[nodiscard]] bool isVisible() const;
bool handleEvent(const SDL_Event& event);
[[nodiscard]] bool handleEvent(const SDL_Event& event);
WINPR_ATTR_FORMAT_ARG(2, 3)
void setTitle(WINPR_FORMAT_ARG const char* fmt, ...);

View File

@@ -25,32 +25,35 @@
#include "../sdl_types.hpp"
#include "../sdl_utils.hpp"
BOOL sdl_authenticate_ex(freerdp* instance, char** username, char** password, char** domain,
rdp_auth_reason reason);
BOOL sdl_choose_smartcard(freerdp* instance, SmartcardCertInfo** cert_list, DWORD count,
DWORD* choice, BOOL gateway);
[[nodiscard]] BOOL sdl_authenticate_ex(freerdp* instance, char** username, char** password,
char** domain, rdp_auth_reason reason);
[[nodiscard]] BOOL sdl_choose_smartcard(freerdp* instance, SmartcardCertInfo** cert_list,
DWORD count, DWORD* choice, BOOL gateway);
SSIZE_T sdl_retry_dialog(freerdp* instance, const char* what, size_t current, void* userarg);
[[nodiscard]] SSIZE_T sdl_retry_dialog(freerdp* instance, const char* what, size_t current,
void* userarg);
DWORD sdl_verify_certificate_ex(freerdp* instance, const char* host, UINT16 port,
const char* common_name, const char* subject, const char* issuer,
const char* fingerprint, DWORD flags);
[[nodiscard]] DWORD sdl_verify_certificate_ex(freerdp* instance, const char* host, UINT16 port,
const char* common_name, const char* subject,
const char* issuer, const char* fingerprint,
DWORD flags);
DWORD sdl_verify_changed_certificate_ex(freerdp* instance, const char* host, UINT16 port,
const char* common_name, const char* subject,
const char* issuer, const char* new_fingerprint,
const char* old_subject, const char* old_issuer,
const char* old_fingerprint, DWORD flags);
[[nodiscard]] DWORD
sdl_verify_changed_certificate_ex(freerdp* instance, const char* host, UINT16 port,
const char* common_name, const char* subject, const char* issuer,
const char* new_fingerprint, const char* old_subject,
const char* old_issuer, const char* old_fingerprint, DWORD flags);
int sdl_logon_error_info(freerdp* instance, UINT32 data, UINT32 type);
[[nodiscard]] int sdl_logon_error_info(freerdp* instance, UINT32 data, UINT32 type);
BOOL sdl_present_gateway_message(freerdp* instance, UINT32 type, BOOL isDisplayMandatory,
BOOL isConsentMandatory, size_t length, const WCHAR* message);
[[nodiscard]] BOOL sdl_present_gateway_message(freerdp* instance, UINT32 type,
BOOL isDisplayMandatory, BOOL isConsentMandatory,
size_t length, const WCHAR* message);
BOOL sdl_message_dialog_show(const char* title, const char* message, Sint32 flags);
BOOL sdl_cert_dialog_show(const char* title, const char* message);
BOOL sdl_scard_dialog_show(const char* title, Sint32 count, const char** list);
BOOL sdl_auth_dialog_show(const SDL_UserAuthArg* args);
[[nodiscard]] BOOL sdl_message_dialog_show(const char* title, const char* message, Sint32 flags);
[[nodiscard]] BOOL sdl_cert_dialog_show(const char* title, const char* message);
[[nodiscard]] BOOL sdl_scard_dialog_show(const char* title, Sint32 count, const char** list);
[[nodiscard]] BOOL sdl_auth_dialog_show(const SDL_UserAuthArg* args);
void sdl_dialogs_init();
void sdl_dialogs_uninit();

View File

@@ -36,7 +36,7 @@ class SdlInputWidget : public SdlSelectableWidget
~SdlInputWidget() override;
std::string text() const;
[[nodiscard]] std::string text() const;
private:
void init();

View File

@@ -40,8 +40,8 @@ SdlInputWidgetPair::SdlInputWidgetPair(std::shared_ptr<SDL_Renderer>& renderer,
static_cast<float>(offset * (height + _vpadding)),
static_cast<float>(width), static_cast<float>(height) })
{
_label.update_text(label);
update_input_text(initial);
(void)_label.update_text(label);
(void)update_input_text(initial);
}
SdlInputWidgetPair::SdlInputWidgetPair(SdlInputWidgetPair&& other) noexcept = default;

View File

@@ -45,22 +45,22 @@ class SdlInputWidgetPair
SdlInputWidgetPair& operator=(const SdlInputWidgetPair& other) = delete;
SdlInputWidgetPair& operator=(SdlInputWidgetPair&& other) = delete;
bool set_mouseover(bool mouseOver);
bool set_highlight(bool highlight);
[[nodiscard]] bool set_mouseover(bool mouseOver);
[[nodiscard]] bool set_highlight(bool highlight);
bool set_str(const std::string& text);
bool remove_str(size_t count);
bool append_str(const std::string& text);
[[nodiscard]] bool set_str(const std::string& text);
[[nodiscard]] bool remove_str(size_t count);
[[nodiscard]] bool append_str(const std::string& text);
[[nodiscard]] const SDL_FRect& input_rect() const;
[[nodiscard]] std::string value() const;
[[nodiscard]] bool readonly() const;
bool update();
[[nodiscard]] bool update();
protected:
bool update_input_text(const std::string& txt);
[[nodiscard]] bool update_input_text(const std::string& txt);
Uint32 _vpadding = 5;
Uint32 _hpadding = 10;

View File

@@ -55,10 +55,10 @@ SdlInputWidgetPairList::SdlInputWidgetPairList(const std::string& title,
m_list.emplace_back(widget);
}
_buttons.populate(_renderer, buttonlabels, buttonids, total_width,
static_cast<Sint32>(input_height), static_cast<Sint32>(widget_width),
static_cast<Sint32>(widget_heigth));
_buttons.set_highlight(0);
(void)_buttons.populate(
_renderer, buttonlabels, buttonids, total_width, static_cast<Sint32>(input_height),
static_cast<Sint32>(widget_width), static_cast<Sint32>(widget_heigth));
(void)_buttons.set_highlight(0);
m_currentActiveTextInput = selected;
}
}
@@ -211,7 +211,8 @@ int SdlInputWidgetPairList::run(std::vector<std::string>& result)
if (cur)
{
auto text = SDL_GetClipboardText();
cur->set_str(text);
if (!cur->set_str(text))
throw;
}
}
break;
@@ -245,7 +246,8 @@ int SdlInputWidgetPairList::run(std::vector<std::string>& result)
throw;
}
_buttons.set_mouseover(event.button.x, event.button.y);
if (!_buttons.set_mouseover(event.button.x, event.button.y))
throw;
}
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:

View File

@@ -41,11 +41,11 @@ class SdlInputWidgetPairList : public SdlWidgetList
SdlInputWidgetPairList& operator=(const SdlInputWidgetPairList& other) = delete;
SdlInputWidgetPairList& operator=(SdlInputWidgetPairList&& other) = delete;
int run(std::vector<std::string>& result);
[[nodiscard]] int run(std::vector<std::string>& result);
protected:
bool updateInternal() override;
ssize_t get_index(const SDL_MouseButtonEvent& button);
[[nodiscard]] bool updateInternal() override;
[[nodiscard]] ssize_t get_index(const SDL_MouseButtonEvent& button);
private:
enum
@@ -54,9 +54,9 @@ class SdlInputWidgetPairList : public SdlWidgetList
INPUT_BUTTON_CANCEL = -2
};
ssize_t next(ssize_t current);
[[nodiscard]] ssize_t next(ssize_t current);
[[nodiscard]] bool valid(ssize_t current) const;
std::shared_ptr<SdlInputWidgetPair> get(ssize_t index);
[[nodiscard]] std::shared_ptr<SdlInputWidgetPair> get(ssize_t index);
std::vector<std::shared_ptr<SdlInputWidgetPair>> m_list;
ssize_t m_currentActiveTextInput = -1;

View File

@@ -37,7 +37,7 @@ SdlSelectWidget::SdlSelectWidget(std::shared_ptr<SDL_Renderer>& renderer, const
{
_backgroundcolor = { 0x69, 0x66, 0x63, 0xff };
_fontcolor = { 0xd1, 0xcf, 0xcd, 0xff };
update_text(label);
(void)update_text(label);
}
SdlSelectWidget::~SdlSelectWidget() = default;

View File

@@ -23,10 +23,10 @@ SdlSelectList::SdlSelectList(const std::string& title, const std::vector<std::st
const std::vector<int> buttonids = { INPUT_BUTTON_ACCEPT, INPUT_BUTTON_CANCEL };
const std::vector<std::string> buttonlabels = { "accept", "cancel" };
_buttons.populate(_renderer, buttonlabels, buttonids, widget_width,
static_cast<Sint32>(total_height), static_cast<Sint32>(widget_width / 2),
static_cast<Sint32>(widget_height));
_buttons.set_highlight(0);
(void)_buttons.populate(
_renderer, buttonlabels, buttonids, widget_width, static_cast<Sint32>(total_height),
static_cast<Sint32>(widget_width / 2), static_cast<Sint32>(widget_height));
(void)_buttons.set_highlight(0);
}
}
@@ -111,7 +111,8 @@ int SdlSelectList::run()
throw;
}
_buttons.set_mouseover(event.button.x, event.button.y);
if (!_buttons.set_mouseover(event.button.x, event.button.y))
throw;
}
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
@@ -147,7 +148,8 @@ int SdlSelectList::run()
throw;
}
update();
if (!update())
throw;
}
}
catch (...)
@@ -186,7 +188,7 @@ void SdlSelectList::reset_mouseover()
{
for (auto& cur : _list)
{
cur.mouseover(false);
(void)cur.mouseover(false);
}
}
@@ -194,6 +196,6 @@ void SdlSelectList::reset_highlight()
{
for (auto& cur : _list)
{
cur.highlight(false);
(void)cur.highlight(false);
}
}

View File

@@ -21,10 +21,10 @@ class SdlSelectList : public SdlWidgetList
SdlSelectList& operator=(const SdlSelectList& other) = delete;
SdlSelectList& operator=(SdlSelectList&& other) = delete;
int run();
[[nodiscard]] int run();
protected:
bool updateInternal() override;
[[nodiscard]] bool updateInternal() override;
private:
enum

View File

@@ -36,11 +36,11 @@ class SdlSelectableWidget : public SdlWidget
SdlSelectableWidget& operator=(const SdlSelectableWidget& other) = delete;
SdlSelectableWidget& operator=(SdlSelectableWidget&& other) = delete;
bool highlight(bool enable);
bool mouseover(bool enable);
[[nodiscard]] bool highlight(bool enable);
[[nodiscard]] bool mouseover(bool enable);
protected:
bool updateInternal() override;
[[nodiscard]] bool updateInternal() override;
SDL_Color _highlightcolor = { 0xcd, 0xca, 0x35, 0x60 };
SDL_Color _mouseovercolor = { 0x66, 0xff, 0x66, 0x60 };

View File

@@ -51,12 +51,12 @@ SdlWidget::SdlWidget(std::shared_ptr<SDL_Renderer>& renderer, const SDL_FRect& r
auto ops = SDL3ResourceManager::get(SDLResourceManager::typeFonts(),
"OpenSans-VariableFont_wdth,wght.ttf");
if (!ops)
widget_log_error(false, "SDLResourceManager::get");
(void)widget_log_error(false, "SDLResourceManager::get");
else
{
_font = std::shared_ptr<TTF_Font>(TTF_OpenFontIO(ops, true, 64), TTF_CloseFont);
if (!_font)
widget_log_error(false, "TTF_OpenFontRW");
(void)widget_log_error(false, "TTF_OpenFontRW");
}
}
@@ -72,7 +72,7 @@ SdlWidget::SdlWidget(std::shared_ptr<SDL_Renderer>& renderer, const SDL_FRect& r
_image = std::shared_ptr<SDL_Texture>(IMG_LoadTexture_IO(renderer.get(), ops, 1),
SDL_DestroyTexture);
if (!_image)
widget_log_error(false, "IMG_LoadTexture_IO");
(void)widget_log_error(false, "IMG_LoadTexture_IO");
}
}
#endif
@@ -95,7 +95,7 @@ std::shared_ptr<SDL_Texture> SdlWidget::render_text(const std::string& text, SDL
TTF_RenderText_Blended(_font.get(), text.c_str(), 0, fgcolor), SDL_DestroySurface);
if (!surface)
{
widget_log_error(false, "TTF_RenderText_Blended");
(void)widget_log_error(false, "TTF_RenderText_Blended");
return nullptr;
}
@@ -103,13 +103,13 @@ std::shared_ptr<SDL_Texture> SdlWidget::render_text(const std::string& text, SDL
SDL_CreateTextureFromSurface(_renderer.get(), surface.get()), SDL_DestroyTexture);
if (!texture)
{
widget_log_error(false, "SDL_CreateTextureFromSurface");
(void)widget_log_error(false, "SDL_CreateTextureFromSurface");
return nullptr;
}
if (!_engine)
{
widget_log_error(false, "TTF_CreateRendererTextEngine");
(void)widget_log_error(false, "TTF_CreateRendererTextEngine");
return nullptr;
}
@@ -118,14 +118,14 @@ std::shared_ptr<SDL_Texture> SdlWidget::render_text(const std::string& text, SDL
if (!txt)
{
widget_log_error(false, "TTF_CreateText");
(void)widget_log_error(false, "TTF_CreateText");
return nullptr;
}
int w = 0;
int h = 0;
if (!TTF_GetTextSize(txt.get(), &w, &h))
{
widget_log_error(false, "TTF_GetTextSize");
(void)widget_log_error(false, "TTF_GetTextSize");
return nullptr;
}
@@ -170,7 +170,7 @@ std::shared_ptr<SDL_Texture> SdlWidget::render_text_wrapped(const std::string& t
SDL_DestroySurface);
if (!surface)
{
widget_log_error(false, "TTF_RenderText_Blended");
(void)widget_log_error(false, "TTF_RenderText_Blended");
return nullptr;
}
@@ -181,7 +181,7 @@ std::shared_ptr<SDL_Texture> SdlWidget::render_text_wrapped(const std::string& t
SDL_CreateTextureFromSurface(_renderer.get(), surface.get()), SDL_DestroyTexture);
if (!texture)
{
widget_log_error(false, "SDL_CreateTextureFromSurface");
(void)widget_log_error(false, "SDL_CreateTextureFromSurface");
return nullptr;
}
@@ -313,7 +313,10 @@ bool SdlWidget::update_text(const std::string& text)
auto w = SDL_GetNumberProperty(propId, SDL_PROP_TEXTURE_WIDTH_NUMBER, -1);
auto h = SDL_GetNumberProperty(propId, SDL_PROP_TEXTURE_HEIGHT_NUMBER, -1);
if (w < 0 || h < 0)
widget_log_error(false, "SDL_GetTextureProperties");
{
if (!widget_log_error(false, "SDL_GetTextureProperties"))
return false;
}
src.w = static_cast<float>(w);
src.h = static_cast<float>(h);
}

View File

@@ -59,19 +59,19 @@ class SdlWidget
SdlWidget& operator=(const SdlWidget& other) = delete;
SdlWidget& operator=(SdlWidget&& other) = delete;
bool fill(SDL_Color color) const;
bool fill(const std::vector<SDL_Color>& colors) const;
bool update_text(const std::string& text);
[[nodiscard]] bool fill(SDL_Color color) const;
[[nodiscard]] bool fill(const std::vector<SDL_Color>& colors) const;
[[nodiscard]] bool update_text(const std::string& text);
[[nodiscard]] bool wrap() const;
bool set_wrap(bool wrap = true, size_t width = 0);
[[nodiscard]] bool set_wrap(bool wrap = true, size_t width = 0);
[[nodiscard]] const SDL_FRect& rect() const;
bool update();
[[nodiscard]] bool update();
#define widget_log_error(res, what) SdlWidget::error_ex(res, what, __FILE__, __LINE__, __func__)
static bool error_ex(bool success, const char* what, const char* file, size_t line,
const char* fkt);
[[nodiscard]] static bool error_ex(bool success, const char* what, const char* file,
size_t line, const char* fkt);
protected:
std::shared_ptr<SDL_Renderer> _renderer;
@@ -83,11 +83,13 @@ class SdlWidget
virtual bool updateInternal();
private:
bool draw_rect(const SDL_FRect& rect, SDL_Color color) const;
std::shared_ptr<SDL_Texture> render_text(const std::string& text, SDL_Color fgcolor,
SDL_FRect& src, SDL_FRect& dst) const;
std::shared_ptr<SDL_Texture> render_text_wrapped(const std::string& text, SDL_Color fgcolor,
SDL_FRect& src, SDL_FRect& dst) const;
[[nodiscard]] bool draw_rect(const SDL_FRect& rect, SDL_Color color) const;
[[nodiscard]] std::shared_ptr<SDL_Texture>
render_text(const std::string& text, SDL_Color fgcolor, SDL_FRect& src, SDL_FRect& dst) const;
[[nodiscard]] std::shared_ptr<SDL_Texture> render_text_wrapped(const std::string& text,
SDL_Color fgcolor,
SDL_FRect& src,
SDL_FRect& dst) const;
std::shared_ptr<TTF_Font> _font = nullptr;
std::shared_ptr<SDL_Texture> _image = nullptr;

View File

@@ -14,7 +14,7 @@ bool SdlWidgetList::reset(const std::string& title, size_t width, size_t height)
_renderer = std::shared_ptr<SDL_Renderer>(renderer, SDL_DestroyRenderer);
_window = std::shared_ptr<SDL_Window>(window, SDL_DestroyWindow);
if (!rc)
widget_log_error(rc, "SDL_CreateWindowAndRenderer");
(void)widget_log_error(rc, "SDL_CreateWindowAndRenderer");
return rc;
}
@@ -47,8 +47,10 @@ bool SdlWidgetList::update()
if (!visible())
return true;
clearWindow();
updateInternal();
if (!clearWindow())
return false;
if (!updateInternal())
return false;
if (!_buttons.update())
return false;
auto rc = SDL_RenderPresent(_renderer.get());

View File

@@ -18,14 +18,14 @@ class SdlWidgetList
SdlWidgetList& operator=(SdlWidgetList&& other) = delete;
virtual ~SdlWidgetList();
virtual bool reset(const std::string& title, size_t width, size_t height);
[[nodiscard]] virtual bool reset(const std::string& title, size_t width, size_t height);
[[nodiscard]] virtual bool visible() const;
protected:
bool update();
virtual bool clearWindow();
virtual bool updateInternal() = 0;
[[nodiscard]] bool update();
[[nodiscard]] virtual bool clearWindow();
[[nodiscard]] virtual bool updateInternal() = 0;
std::shared_ptr<SDL_Window> _window;
std::shared_ptr<SDL_Renderer> _renderer;

View File

@@ -37,7 +37,7 @@
// NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
const char mime_text_utf8[] = mime_text_plain ";charset=utf-8";
static const std::vector<const char*>& s_mime_text()
[[nodiscard]] static const std::vector<const char*>& s_mime_text()
{
static std::vector<const char*> values;
if (values.empty())
@@ -58,7 +58,7 @@ static const char s_mime_html[] = "text/html";
#define BMP_MIME_LIST "image/bmp", "image/x-bmp", "image/x-MS-bmp", "image/x-win-bitmap"
static const std::vector<const char*>& s_mime_bitmap()
[[nodiscard]] static const std::vector<const char*>& s_mime_bitmap()
{
static std::vector<const char*> values;
if (values.empty())
@@ -68,7 +68,7 @@ static const std::vector<const char*>& s_mime_bitmap()
return values;
}
static const std::vector<const char*>& s_mime_image()
[[nodiscard]] static const std::vector<const char*>& s_mime_image()
{
static std::vector<const char*> values;
if (values.empty())
@@ -144,7 +144,7 @@ sdlClip::~sdlClip()
{
cliprdr_file_context_free(_file);
ClipboardDestroy(_system);
(void)CloseHandle(_event);
std::ignore = CloseHandle(_event);
}
bool sdlClip::init(CliprdrClientContext* clip)
@@ -876,7 +876,7 @@ const void* sdlClip::ClipDataCb(void* userdata, const char* mime_type, size_t* s
clip->_request_queue.pop();
if (clip->_request_queue.empty())
(void)ResetEvent(clip->_event);
std::ignore = ResetEvent(clip->_event);
if (request.success())
{

View File

@@ -57,8 +57,8 @@ class sdlDispContext
[[nodiscard]] bool addTimer();
bool updateMonitor(SDL_WindowID id);
bool updateMonitors(SDL_EventType type, SDL_DisplayID displayID);
[[nodiscard]] bool updateMonitor(SDL_WindowID id);
[[nodiscard]] bool updateMonitors(SDL_EventType type, SDL_DisplayID displayID);
[[nodiscard]] static UINT DisplayControlCaps(DispClientContext* disp, UINT32 maxNumMonitors,
UINT32 maxMonitorAreaFactorA,

View File

@@ -207,7 +207,8 @@ static int sdl_run(SdlContext* sdl)
SDLConnectionDialogHider hider(sdl);
auto title = static_cast<const char*>(windowEvent.user.data1);
auto msg = static_cast<const char*>(windowEvent.user.data2);
sdl_cert_dialog_show(title, msg);
if (!sdl_cert_dialog_show(title, msg))
return -1;
}
break;
case SDL_EVENT_USER_SHOW_DIALOG:
@@ -215,7 +216,8 @@ static int sdl_run(SdlContext* sdl)
SDLConnectionDialogHider hider(sdl);
auto title = static_cast<const char*>(windowEvent.user.data1);
auto msg = static_cast<const char*>(windowEvent.user.data2);
sdl_message_dialog_show(title, msg, windowEvent.user.code);
if (!sdl_message_dialog_show(title, msg, windowEvent.user.code))
return -1;
}
break;
case SDL_EVENT_USER_SCARD_DIALOG:
@@ -223,14 +225,16 @@ static int sdl_run(SdlContext* sdl)
SDLConnectionDialogHider hider(sdl);
auto title = static_cast<const char*>(windowEvent.user.data1);
auto msg = static_cast<const char**>(windowEvent.user.data2);
sdl_scard_dialog_show(title, windowEvent.user.code, msg);
if (!sdl_scard_dialog_show(title, windowEvent.user.code, msg))
return -1;
}
break;
case SDL_EVENT_USER_AUTH_DIALOG:
{
SDLConnectionDialogHider hider(sdl);
sdl_auth_dialog_show(
reinterpret_cast<const SDL_UserAuthArg*>(windowEvent.padding));
if (!sdl_auth_dialog_show(
reinterpret_cast<const SDL_UserAuthArg*>(windowEvent.padding)))
return -1;
}
break;
case SDL_EVENT_USER_UPDATE:

View File

@@ -283,7 +283,7 @@ static const scancode_entry_t map[] = {
ENTRY(SDL_SCANCODE_MEDIA_FAST_FORWARD, RDP_SCANCODE_UNKNOWN)
};
static UINT32 sdl_get_kbd_flags()
[[nodiscard]] static UINT32 sdl_get_kbd_flags()
{
UINT32 flags = 0;
@@ -374,7 +374,7 @@ BOOL sdlInput::keyboard_set_ime_status(rdpContext* context, UINT16 imeId, UINT32
return TRUE;
}
static const std::map<std::string, uint32_t>& getSdlMap()
[[nodiscard]] static const std::map<std::string, uint32_t>& getSdlMap()
{
static std::map<std::string, uint32_t> s_map = {
{ "KMOD_LSHIFT", SDL_KMOD_LSHIFT }, { "KMOD_RSHIFT", SDL_KMOD_RSHIFT },
@@ -399,7 +399,7 @@ static const std::map<std::string, uint32_t>& getSdlMap()
return s_map;
}
static std::string modbyvalue(uint32_t val)
[[nodiscard]] static std::string modbyvalue(uint32_t val)
{
for (const auto& v : getSdlMap())
{
@@ -411,7 +411,7 @@ static std::string modbyvalue(uint32_t val)
return "KMOD_UNKNONW";
}
static std::string masktostr(uint32_t mask)
[[nodiscard]] static std::string masktostr(uint32_t mask)
{
if (mask == 0)
return "<NONE>";
@@ -470,7 +470,7 @@ uint32_t sdlInput::prefToMask()
return mod;
}
static const char* sdl_scancode_name(Uint32 scancode)
[[nodiscard]] static const char* sdl_scancode_name(Uint32 scancode)
{
for (const auto& cur : map)
{
@@ -481,7 +481,7 @@ static const char* sdl_scancode_name(Uint32 scancode)
return "SDL_SCANCODE_UNKNOWN";
}
static Uint32 sdl_scancode_val(const char* scancodeName)
[[nodiscard]] static Uint32 sdl_scancode_val(const char* scancodeName)
{
for (const auto& cur : map)
{
@@ -493,7 +493,7 @@ static Uint32 sdl_scancode_val(const char* scancodeName)
}
#if defined(WITH_DEBUG_SDL_KBD_EVENTS)
static const char* sdl_rdp_scancode_name(UINT32 scancode)
[[nodiscard]] static const char* sdl_rdp_scancode_name(UINT32 scancode)
{
for (const auto& cur : map)
{
@@ -504,7 +504,7 @@ static const char* sdl_rdp_scancode_name(UINT32 scancode)
return "RDP_SCANCODE_UNKNOWN";
}
static UINT32 sdl_rdp_scancode_val(const char* scancodeName)
[[nodiscard]] static UINT32 sdl_rdp_scancode_val(const char* scancodeName)
{
for (const auto& cur : map)
{

View File

@@ -81,7 +81,8 @@ int sdl_list_monitors([[maybe_unused]] SdlContext* sdl)
return 0;
}
static BOOL sdl_apply_mon_max_size(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
[[nodiscard]] static BOOL sdl_apply_mon_max_size(SdlContext* sdl, UINT32* pMaxWidth,
UINT32* pMaxHeight)
{
int32_t left = 0;
int32_t right = 0;
@@ -113,7 +114,7 @@ static BOOL sdl_apply_mon_max_size(SdlContext* sdl, UINT32* pMaxWidth, UINT32* p
return TRUE;
}
static BOOL sdl_apply_max_size(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
[[nodiscard]] static BOOL sdl_apply_max_size(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
{
WINPR_ASSERT(sdl);
WINPR_ASSERT(pMaxWidth);
@@ -170,14 +171,15 @@ static BOOL sdl_apply_max_size(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxH
return TRUE;
}
static Uint32 scale(Uint32 val, float scale)
[[nodiscard]] static Uint32 scale(Uint32 val, float scale)
{
const auto dval = static_cast<float>(val);
const auto sval = dval / scale;
return static_cast<Uint32>(sval);
}
static BOOL sdl_apply_monitor_properties(rdpMonitor& monitor, SDL_DisplayID id, bool isPrimary)
[[nodiscard]] static BOOL sdl_apply_monitor_properties(rdpMonitor& monitor, SDL_DisplayID id,
bool isPrimary)
{
float dpi = SDL_GetDisplayContentScale(id);
@@ -248,7 +250,7 @@ static BOOL sdl_apply_monitor_properties(rdpMonitor& monitor, SDL_DisplayID id,
return TRUE;
}
static BOOL sdl_apply_display_properties(SdlContext* sdl)
[[nodiscard]] static BOOL sdl_apply_display_properties(SdlContext* sdl)
{
WINPR_ASSERT(sdl);
@@ -285,7 +287,8 @@ static BOOL sdl_apply_display_properties(SdlContext* sdl)
monitors.size());
}
static BOOL sdl_detect_single_window(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
[[nodiscard]] static BOOL sdl_detect_single_window(SdlContext* sdl, UINT32* pMaxWidth,
UINT32* pMaxHeight)
{
WINPR_ASSERT(sdl);
WINPR_ASSERT(pMaxWidth);

View File

@@ -37,7 +37,7 @@ typedef struct
void* data;
} sdlPointer;
static BOOL sdl_Pointer_New(rdpContext* context, rdpPointer* pointer)
[[nodiscard]] static BOOL sdl_Pointer_New(rdpContext* context, rdpPointer* pointer)
{
auto ptr = reinterpret_cast<sdlPointer*>(pointer);
@@ -90,14 +90,14 @@ static void sdl_Pointer_Free(rdpContext* context, rdpPointer* pointer)
}
}
static BOOL sdl_Pointer_SetDefault(rdpContext* context)
[[nodiscard]] static BOOL sdl_Pointer_SetDefault(rdpContext* context)
{
WINPR_UNUSED(context);
return sdl_push_user_event(SDL_EVENT_USER_POINTER_DEFAULT);
}
static BOOL sdl_Pointer_Set(rdpContext* context, rdpPointer* pointer)
[[nodiscard]] static BOOL sdl_Pointer_Set(rdpContext* context, rdpPointer* pointer)
{
WINPR_UNUSED(context);
return sdl_push_user_event(SDL_EVENT_USER_POINTER_SET, pointer);
@@ -178,14 +178,14 @@ BOOL sdl_Pointer_Set_Process(SdlContext* sdl)
return TRUE;
}
static BOOL sdl_Pointer_SetNull(rdpContext* context)
[[nodiscard]] static BOOL sdl_Pointer_SetNull(rdpContext* context)
{
WINPR_UNUSED(context);
return sdl_push_user_event(SDL_EVENT_USER_POINTER_NULL);
}
static BOOL sdl_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
[[nodiscard]] static BOOL sdl_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
{
WINPR_UNUSED(context);
WINPR_ASSERT(context);

View File

@@ -96,7 +96,7 @@ namespace sdl::utils
SCALE_MODE_WAYLAND
};
HighDpiScaleMode platformScaleMode();
[[nodiscard]] HighDpiScaleMode platformScaleMode();
[[nodiscard]] std::string windowTitle(const rdpSettings* settings);

View File

@@ -26,8 +26,8 @@ extern "C"
{
#endif
BOOL sdl_webview_get_access_token(freerdp* instance, AccessTokenType tokenType, char** token,
size_t count, ...);
[[nodiscard]] BOOL sdl_webview_get_access_token(freerdp* instance, AccessTokenType tokenType,
char** token, size_t count, ...);
#ifdef __cplusplus
}

View File

@@ -21,4 +21,5 @@
#include <string>
bool webview_impl_run(const std::string& title, const std::string& url, std::string& code);
[[nodiscard]] bool webview_impl_run(const std::string& title, const std::string& url,
std::string& code);

View File

@@ -33,20 +33,21 @@ class SDLResourceManager
SDLResourceManager operator=(const SDLResourceManager& other) = delete;
SDLResourceManager& operator=(SDLResourceManager&& other) = delete;
static std::string typeFonts();
static std::string typeImages();
[[nodiscard]] static std::string typeFonts();
[[nodiscard]] static std::string typeImages();
protected:
static void insert(const std::string& type, const std::string& id,
const std::vector<unsigned char>& data);
static const std::vector<unsigned char>* data(const std::string& type, const std::string& id);
static std::string filename(const std::string& type, const std::string& id);
[[nodiscard]] static const std::vector<unsigned char>* data(const std::string& type,
const std::string& id);
[[nodiscard]] static std::string filename(const std::string& type, const std::string& id);
static bool useCompiledResources();
[[nodiscard]] static bool useCompiledResources();
private:
static std::map<std::string, std::vector<unsigned char>>& resources();
[[nodiscard]] static std::map<std::string, std::vector<unsigned char>>& resources();
#if defined(SDL_USE_COMPILED_RESOURCES)
static void init(); // implemented in generated file
#endif

View File

@@ -27,7 +27,7 @@
class SdlPref
{
public:
static std::shared_ptr<SdlPref>
[[nodiscard]] static std::shared_ptr<SdlPref>
instance(const std::string& name = SdlPref::get_default_file(false));
[[nodiscard]] std::string get_pref_file(bool systemConfigOnly = false) const;
@@ -63,6 +63,7 @@ class SdlPref
[[nodiscard]] bool is_user_config_enabled() const;
static std::string get_default_file(bool systemConfigOnly);
static std::string item_to_str(WINPR_JSON* item, const std::string& fallback = "");
[[nodiscard]] static std::string get_default_file(bool systemConfigOnly);
[[nodiscard]] static std::string item_to_str(WINPR_JSON* item,
const std::string& fallback = "");
};