9#include "os_settings_intf.hpp"
10#include "../win32/win32.hpp"
11#include "../telemetry/telemetry.hpp"
12#include "../utility/utility.hpp"
13#include "../path/path.hpp"
14#include "../macros.hpp"
16hi_export_module(hikogui.settings.os_settings : impl);
18hi_export
namespace hi {
inline namespace v1 {
41 auto const d1 = defer([&] {
51 auto const d2 = defer([&] {
59 auto const d3 = defer([&] {
99 r.push_back(language_tag{language});
103 r.push_back(language_tag{
"en"});
109[[
nodiscard]] hi_inline std::expected<std::locale, std::error_code> os_settings::gather_locale()
noexcept
111 if (
auto name = win32_GetUserDefaultLocaleName()) {
121 if (
auto locale = gather_locale()) {
131 auto locale_tag = language_tag{locale->name()};
145 return languages.front().expand().left_to_right();
152[[
nodiscard]] hi_inline hi::theme_mode os_settings::gather_theme_mode()
156 "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
157 "AppsUseLightTheme")) {
158 return *
result ? theme_mode::light : theme_mode::dark;
162 return theme_mode::light;
166[[
nodiscard]] hi_inline hi::subpixel_orientation os_settings::gather_subpixel_orientation()
171 throw os_error(std::format(
"Could not get system parameter SPI_GETFONTSMOOTHING: {}",
get_last_error_message()));
176 return hi::subpixel_orientation::unknown;
183 throw os_error(std::format(
"Could not get system parameter SPI_GETFONTSMOOTHINGTYPE: {}",
get_last_error_message()));
188 return hi::subpixel_orientation::unknown;
195 throw os_error(std::format(
"Could not get system parameter SPI_GETCLEARTYPE: {}",
get_last_error_message()));
200 return hi::subpixel_orientation::unknown;
208 std::format(
"Could not get system parameter SPI_GETFONTSMOOTHINGORIENTATION: {}",
get_last_error_message()));
213 return hi::subpixel_orientation::horizontal_bgr;
216 return hi::subpixel_orientation::horizontal_rgb;
218 throw os_error(std::format(
"Unknown result from SPI_GETFONTSMOOTHINGORIENTATION: {}",
font_smooth_orientation));
223[[
nodiscard]] hi_inline
bool os_settings::gather_uniform_HDR()
235[[
nodiscard]] hi_inline
float os_settings::gather_double_click_distance()
239 throw os_error(
"Could not retrieve SM_CXDOUBLECLK");
244 throw os_error(
"Could not retrieve SM_CYDOUBLECLK");
247 auto const diameter =
std::max(width, height);
248 return diameter * 0.5f;
253 using namespace std::literals::chrono_literals;
257 throw os_error(std::format(
"Could not get system parameter SPI_GETKEYBOARDDELAY: {}",
get_last_error_message()));
261 constexpr auto bias = 250
ms;
262 constexpr auto gain = 250
ms;
269 using namespace std::literals::chrono_literals;
273 throw os_error(std::format(
"Could not get system parameter SPI_GETKEYBOARDSPEED: {}",
get_last_error_message()));
277 constexpr auto bias = 2.5f;
278 constexpr auto gain = 0.887f;
280 return std::chrono::duration_cast<std::chrono::milliseconds>(1000
ms /
rate);
285 using namespace std::literals::chrono_literals;
303 return std::max(gather_keyboard_repeat_delay(), gather_keyboard_repeat_interval());
306[[
nodiscard]] hi_inline
float os_settings::gather_minimum_window_width()
310 throw os_error(
"Could not retrieve SM_CXMINTRACK");
315[[
nodiscard]] hi_inline
float os_settings::gather_minimum_window_height()
319 throw os_error(
"Could not retrieve SM_CYMINTRACK");
325[[
nodiscard]] hi_inline
float os_settings::gather_maximum_window_width()
329 throw os_error(
"Could not retrieve SM_CXMAXTRACK");
334[[
nodiscard]] hi_inline
float os_settings::gather_maximum_window_height()
338 throw os_error(
"Could not retrieve SM_CYMAXTRACK");
344[[
nodiscard]] hi_inline uintptr_t os_settings::gather_primary_monitor_id()
346 auto const origin =
POINT{0, 0};
348 return std::bit_cast<uintptr_t>(
monitor);
351[[
nodiscard]] hi_inline aarectangle os_settings::gather_primary_monitor_rectangle()
355 throw os_error(
"Could not retrieve SM_CXSCREEN");
360 throw os_error(
"Could not retrieve SM_CYSCREEN");
367[[
nodiscard]] hi_inline aarectangle os_settings::gather_desktop_rectangle()
371 throw os_error(
"Could not retrieve SM_CYSCREEN");
379 throw os_error(
"Could not retrieve SM_CXVIRTUALSCREEN");
384 throw os_error(
"Could not retrieve SM_CYVIRTUALSCREEN");
397 using namespace std::literals;
405 if (
entry_sv.starts_with(
"GpuPreference=")) {
407 return policy::unspecified;
408 }
else if (
entry_sv.ends_with(
"=1")) {
409 return policy::low_power;
410 }
else if (
entry_sv.ends_with(
"=2")) {
411 return policy::high_performance;
413 hi_log_error(
"Unexpected GpuPreference value \"{}\".",
entry_sv);
414 return policy::unspecified;
419 hi_log_error(
"Could not find GpuPreference entry.");
420 return policy::unspecified;
422 }
else if (
result.error() == win32_error::file_not_found) {
423 return policy::unspecified;
427 return policy::unspecified;
Rules for working with win32 headers.
@ bottom
Align to the bottom.
@ left
Align the text to the left side.
std::filesystem::path executable_file() noexcept
Get the full path to this executable.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
std::expected< T, win32_error > win32_RegGetValue(HKEY key, std::string_view path, std::string_view name)=delete
Read from the registry value.
Definition winreg.hpp:282
hi_export std::string get_last_error_message()
Get the OS error message from the last error received on this thread.
Definition exception_win32_impl.hpp:30
policy
The performance policy to use.
Definition policy.hpp:18
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378