Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(win_api_layer): add implicit flag validation for setDisplayConfig #130

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
# Doxygen from Ubuntu is too old, need Doxygen >= 1.10
DOCS=OFF
else
DOCS=ON
DOCS=OFF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this for now. My other PR won't be so easy since it still installs Doxygen 1.13 on macOS.

fi

cmake \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace display_device {
/**
* @brief Direct wrapper around the SetDisplayConfig WinAPI.
*
* It implements no additional logic, just a direct pass-trough.
* It implements additional implicit validation logic.
*
* @param paths List of paths to pass.
* @param modes List of modes to pass.
Expand Down
28 changes: 21 additions & 7 deletions src/windows/win_api_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,27 @@ namespace display_device {

LONG
WinApiLayer::setDisplayConfig(std::vector<DISPLAYCONFIG_PATH_INFO> paths, std::vector<DISPLAYCONFIG_MODE_INFO> modes, UINT32 flags) {
// std::vector::data() "may or may not return a null pointer, if size() is 0", therefore we want to enforce nullptr...
return ::SetDisplayConfig(
paths.size(),
paths.empty() ? nullptr : paths.data(),
modes.size(),
modes.empty() ? nullptr : modes.data(),
flags);
const auto do_set_display_config { [&paths, &modes](const UINT32 final_flags) {
// std::vector::data() "may or may not return a null pointer, if size() is 0", therefore we want to enforce nullptr...
return ::SetDisplayConfig(
paths.size(),
paths.empty() ? nullptr : paths.data(),
modes.size(),
modes.empty() ? nullptr : modes.data(),
final_flags);
} };

if (flags & SDC_APPLY) {
auto validation_flags { flags };
validation_flags &= ~SDC_APPLY;
validation_flags |= SDC_VALIDATE;

if (const auto result = do_set_display_config(validation_flags); result != ERROR_SUCCESS) {
return result;
}
}

return do_set_display_config(flags);
}

std::optional<HdrState>
Expand Down
Loading