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);
18namespace hi {
inline namespace v1 {
41 hilet
d1 = defer([&] {
51 hilet
d2 = defer([&] {
59 hilet
d3 = defer([&] {
99 r.push_back(language_tag{language});
103 r.push_back(language_tag{
"en"});
109[[
nodiscard]]
inline std::expected<std::locale, std::error_code> os_settings::gather_locale()
noexcept
111 if (
auto name = win32_GetUserDefaultLocaleName()) {
119[[
nodiscard]]
inline hi::theme_mode os_settings::gather_theme_mode()
123 "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
124 "AppsUseLightTheme")) {
125 return *
result ? theme_mode::light : theme_mode::dark;
129 return theme_mode::light;
133[[
nodiscard]]
inline hi::subpixel_orientation os_settings::gather_subpixel_orientation()
138 throw os_error(std::format(
"Could not get system parameter SPI_GETFONTSMOOTHING: {}",
get_last_error_message()));
143 return hi::subpixel_orientation::unknown;
150 throw os_error(std::format(
"Could not get system parameter SPI_GETFONTSMOOTHINGTYPE: {}",
get_last_error_message()));
155 return hi::subpixel_orientation::unknown;
162 throw os_error(std::format(
"Could not get system parameter SPI_GETCLEARTYPE: {}",
get_last_error_message()));
167 return hi::subpixel_orientation::unknown;
175 std::format(
"Could not get system parameter SPI_GETFONTSMOOTHINGORIENTATION: {}",
get_last_error_message()));
180 return hi::subpixel_orientation::horizontal_bgr;
183 return hi::subpixel_orientation::horizontal_rgb;
185 throw os_error(std::format(
"Unknown result from SPI_GETFONTSMOOTHINGORIENTATION: {}",
font_smooth_orientation));
190[[
nodiscard]]
inline bool os_settings::gather_uniform_HDR()
202[[
nodiscard]]
inline float os_settings::gather_double_click_distance()
206 throw os_error(
"Could not retrieve SM_CXDOUBLECLK");
211 throw os_error(
"Could not retrieve SM_CYDOUBLECLK");
214 hilet diameter =
std::max(width, height);
215 return diameter * 0.5f;
220 using namespace std::literals::chrono_literals;
224 throw os_error(std::format(
"Could not get system parameter SPI_GETKEYBOARDDELAY: {}",
get_last_error_message()));
228 constexpr auto bias = 250
ms;
229 constexpr auto gain = 250
ms;
236 using namespace std::literals::chrono_literals;
240 throw os_error(std::format(
"Could not get system parameter SPI_GETKEYBOARDSPEED: {}",
get_last_error_message()));
244 constexpr auto bias = 2.5f;
245 constexpr auto gain = 0.887f;
247 return std::chrono::duration_cast<std::chrono::milliseconds>(1000
ms /
rate);
252 using namespace std::literals::chrono_literals;
270 return std::max(gather_keyboard_repeat_delay(), gather_keyboard_repeat_interval());
273[[
nodiscard]]
inline float os_settings::gather_minimum_window_width()
277 throw os_error(
"Could not retrieve SM_CXMINTRACK");
282[[
nodiscard]]
inline float os_settings::gather_minimum_window_height()
286 throw os_error(
"Could not retrieve SM_CYMINTRACK");
292[[
nodiscard]]
inline float os_settings::gather_maximum_window_width()
296 throw os_error(
"Could not retrieve SM_CXMAXTRACK");
301[[
nodiscard]]
inline float os_settings::gather_maximum_window_height()
305 throw os_error(
"Could not retrieve SM_CYMAXTRACK");
311[[
nodiscard]]
inline uintptr_t os_settings::gather_primary_monitor_id()
313 hilet origin =
POINT{0, 0};
315 return std::bit_cast<uintptr_t>(
monitor);
318[[
nodiscard]]
inline aarectangle os_settings::gather_primary_monitor_rectangle()
322 throw os_error(
"Could not retrieve SM_CXSCREEN");
327 throw os_error(
"Could not retrieve SM_CYSCREEN");
334[[
nodiscard]]
inline aarectangle os_settings::gather_desktop_rectangle()
338 throw os_error(
"Could not retrieve SM_CYSCREEN");
346 throw os_error(
"Could not retrieve SM_CXVIRTUALSCREEN");
351 throw os_error(
"Could not retrieve SM_CYVIRTUALSCREEN");
364 using namespace std::literals;
372 if (
entry_sv.starts_with(
"GpuPreference=")) {
374 return policy::unspecified;
375 }
else if (
entry_sv.ends_with(
"=1")) {
376 return policy::low_power;
377 }
else if (
entry_sv.ends_with(
"=2")) {
378 return policy::high_performance;
380 hi_log_error(
"Unexpected GpuPreference value \"{}\".",
entry_sv);
381 return policy::unspecified;
386 hi_log_error(
"Could not find GpuPreference entry.");
387 return policy::unspecified;
389 }
else if (
result.error() == win32_error::file_not_found) {
390 return policy::unspecified;
394 return policy::unspecified;
Rules for working with win32 headers.
std::filesystem::path get_path(path_location location)
Get the single and only path.
Definition path_location_intf.hpp:112
@ executable_file
A single file where the current running executable is located.
@ bottom
Align to the bottom.
@ left
Align the text to the left side.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
std::string get_last_error_message()
Get the OS error message from the last error received on this thread.
Definition exception_win32_impl.hpp:31
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:377