HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
os_settings.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "theme_mode.hpp"
8#include "subpixel_orientation.hpp"
9#include "../i18n/module.hpp"
10#include "../geometry/module.hpp"
11#include "../utility/module.hpp"
12#include "../numeric/module.hpp"
13#include "../observer/module.hpp"
14#include "../loop.hpp"
15#include <vector>
16#include <mutex>
17
18namespace hi::inline v1 {
19
21public:
23 using callback_token = notifier_type::callback_token;
24 using callback_proto = notifier_type::callback_proto;
25
30 [[nodiscard]] static std::vector<language_tag> language_tags() noexcept
31 {
32 hi_axiom(_populated.load(std::memory_order::acquire));
33 hilet lock = std::scoped_lock(_mutex);
34 return _language_tags;
35 }
36
41 [[nodiscard]] static bool left_to_right() noexcept
42 {
43 hi_axiom(_populated.load(std::memory_order::acquire));
44 return _left_to_right.load(std::memory_order::relaxed);
45 }
46
49 [[nodiscard]] static hi::theme_mode theme_mode() noexcept
50 {
51 hi_axiom(_populated.load(std::memory_order::acquire));
52 return _theme_mode.load(std::memory_order::relaxed);
53 }
54
57 [[nodiscard]] static hi::subpixel_orientation subpixel_orientation() noexcept
58 {
59 hi_axiom(_populated.load(std::memory_order::acquire));
60 return _subpixel_orientation.load(std::memory_order::relaxed);
61 }
62
73 [[nodiscard]] static bool uniform_HDR() noexcept
74 {
75 hi_axiom(_populated.load(std::memory_order::acquire));
76 return _uniform_HDR.load(std::memory_order::relaxed);
77 }
78
81 [[nodiscard]] static std::chrono::milliseconds double_click_interval() noexcept
82 {
83 hi_axiom(_populated.load(std::memory_order::acquire));
84 return _double_click_interval.load(std::memory_order::relaxed);
85 }
86
89 [[nodiscard]] static float double_click_distance() noexcept
90 {
91 hi_axiom(_populated.load(std::memory_order::acquire));
92 return _double_click_distance.load(std::memory_order::relaxed);
93 }
94
99 [[nodiscard]] static std::chrono::milliseconds keyboard_repeat_delay() noexcept
100 {
101 hi_axiom(_populated.load(std::memory_order::acquire));
102 return _keyboard_repeat_delay.load(std::memory_order::relaxed);
103 }
104
110 {
111 hi_axiom(_populated.load(std::memory_order::acquire));
112 return _keyboard_repeat_interval.load(std::memory_order::relaxed);
113 }
114
119 [[nodiscard]] static std::chrono::milliseconds cursor_blink_delay() noexcept
120 {
121 hi_axiom(_populated.load(std::memory_order::acquire));
122 return _cursor_blink_delay.load(std::memory_order::relaxed);
123 }
124
130 [[nodiscard]] static std::chrono::milliseconds cursor_blink_interval() noexcept
131 {
132 hi_axiom(_populated.load(std::memory_order::acquire));
133 return _cursor_blink_interval.load(std::memory_order::relaxed);
134 }
135
140 [[nodiscard]] static float minimum_window_width() noexcept
141 {
142 hi_axiom(_populated.load(std::memory_order::acquire));
143 return _minimum_window_width.load(std::memory_order::relaxed);
144 }
145
150 [[nodiscard]] static float minimum_window_height() noexcept
151 {
152 hi_axiom(_populated.load(std::memory_order::acquire));
153 return _minimum_window_height.load(std::memory_order::relaxed);
154 }
155
160 [[nodiscard]] static float maximum_window_width() noexcept
161 {
162 hi_axiom(_populated.load(std::memory_order::acquire));
163 return _maximum_window_width.load(std::memory_order::relaxed);
164 }
165
170 [[nodiscard]] static float maximum_window_height() noexcept
171 {
172 hi_axiom(_populated.load(std::memory_order::acquire));
173 return _maximum_window_height.load(std::memory_order::relaxed);
174 }
175
180 [[nodiscard]] static aarectangle primary_monitor_rectangle() noexcept
181 {
182 hi_axiom(_populated.load(std::memory_order::acquire));
183 hilet lock = std::scoped_lock(_mutex);
184 return _primary_monitor_rectangle;
185 }
186
189 [[nodiscard]] static uintptr_t primary_monitor_id() noexcept
190 {
191 hi_axiom(_populated.load(std::memory_order::acquire));
192 return _primary_monitor_id.load(std::memory_order::relaxed);
193 }
194
199 [[nodiscard]] static aarectangle desktop_rectangle() noexcept
200 {
201 hi_axiom(_populated.load(std::memory_order::acquire));
202 hilet lock = std::scoped_lock(_mutex);
203 return _desktop_rectangle;
204 }
205
210 [[nodiscard]] static hi::policy policy() noexcept
211 {
212 return policy::unspecified;
213 }
214
219 [[nodiscard]] static hi::policy gpu_policy() noexcept
220 {
221 hi_axiom(_populated.load(std::memory_order::acquire));
222 return _gpu_policy.load(std::memory_order::relaxed);
223 }
224
246 [[nodiscard]] static std::vector<uuid> preferred_gpus(hi::policy performance_policy) noexcept;
247
250 static void gather() noexcept;
251
252 [[nodiscard]] static callback_token
253 subscribe(forward_of<callback_proto> auto&& callback, callback_flags flags = callback_flags::synchronous) noexcept
254 {
255 hilet lock = std::scoped_lock(_mutex);
256 return _notifier.subscribe(hi_forward(callback), flags);
257 }
258
263 static bool start_subsystem() noexcept
264 {
265 return hi::start_subsystem(_started, false, subsystem_init, subsystem_deinit);
266 }
267
268private:
269 static constexpr std::chrono::duration gather_interval = std::chrono::seconds(5);
270 static constexpr std::chrono::duration gather_minimum_interval = std::chrono::seconds(1);
271
272 static inline std::atomic<bool> _started = false;
273 static inline std::atomic<bool> _populated = false;
274 static inline unfair_mutex _mutex;
275 static inline loop::timer_callback_token _gather_cbt;
276 static inline utc_nanoseconds _gather_last_time;
277
278 static inline notifier_type _notifier;
279
280 static inline std::vector<language_tag> _language_tags = {};
281 static inline std::atomic<bool> _left_to_right = true;
282 static inline std::atomic<hi::theme_mode> _theme_mode = theme_mode::dark;
283 static inline std::atomic<bool> _uniform_HDR = false;
284 static inline std::atomic<hi::subpixel_orientation> _subpixel_orientation = hi::subpixel_orientation::unknown;
285 static inline std::atomic<std::chrono::milliseconds> _double_click_interval = std::chrono::milliseconds(500);
286 static inline std::atomic<float> _double_click_distance = 4.0f;
287 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_delay = std::chrono::milliseconds(250);
288 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_interval = std::chrono::milliseconds(33);
289 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_interval = std::chrono::milliseconds(1000);
290 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_delay = std::chrono::milliseconds(1000);
291 static inline std::atomic<float> _minimum_window_width = 40.0f;
292 static inline std::atomic<float> _minimum_window_height = 25.0f;
293 static inline std::atomic<float> _maximum_window_width = 1920.0f;
294 static inline std::atomic<float> _maximum_window_height = 1080.0f;
295 static inline std::atomic<uintptr_t> _primary_monitor_id = 0;
296 static inline aarectangle _primary_monitor_rectangle = aarectangle{0.0f, 0.0f, 1920.0f, 1080.0f};
297 static inline aarectangle _desktop_rectangle = aarectangle{0.0f, 0.0f, 1920.0f, 1080.0f};
298 static inline std::atomic<hi::policy> _gpu_policy = policy::unspecified;
299
300 [[nodiscard]] static bool subsystem_init() noexcept;
301 static void subsystem_deinit() noexcept;
302
303 [[nodiscard]] static std::vector<language_tag> gather_languages();
304 [[nodiscard]] static hi::theme_mode gather_theme_mode();
305 [[nodiscard]] static hi::subpixel_orientation gather_subpixel_orientation();
306 [[nodiscard]] static bool gather_uniform_HDR();
307 [[nodiscard]] static std::chrono::milliseconds gather_double_click_interval();
308 [[nodiscard]] static float gather_double_click_distance();
309 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_delay();
310 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_interval();
311 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_interval();
312 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_delay();
313 [[nodiscard]] static float gather_minimum_window_width();
314 [[nodiscard]] static float gather_minimum_window_height();
315 [[nodiscard]] static float gather_maximum_window_width();
316 [[nodiscard]] static float gather_maximum_window_height();
317 [[nodiscard]] static uintptr_t gather_primary_monitor_id();
318 [[nodiscard]] static aarectangle gather_primary_monitor_rectangle();
319 [[nodiscard]] static aarectangle gather_desktop_rectangle();
320 [[nodiscard]] static hi::policy gather_gpu_policy();
321};
322
323} // namespace hi::inline v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
T::value_type start_subsystem(T &check_variable, typename T::value_type off_value, typename T::value_type(*init_function)(), void(*deinit_function)())
Start a sub-system.
Definition subsystem.hpp:113
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:13
callback_flags
Definition callback_flags.hpp:11
geometry/margins.hpp
Definition cache.hpp:11
policy
The performance policy to use.
Definition policy.hpp:15
A notifier which can be used to call a set of registered callbacks.
Definition notifier.hpp:25
Definition os_settings.hpp:20
static std::chrono::milliseconds keyboard_repeat_delay() noexcept
Get the delay before the keyboard starts repeating.
Definition os_settings.hpp:99
static aarectangle primary_monitor_rectangle() noexcept
Get the rectangle of the primary monitor.
Definition os_settings.hpp:180
static bool start_subsystem() noexcept
Get the global os_settings instance.
Definition os_settings.hpp:263
static float maximum_window_height() noexcept
The maximum height a window is allowed to be.
Definition os_settings.hpp:170
static std::chrono::milliseconds keyboard_repeat_interval() noexcept
Get the keyboard repeat interval.
Definition os_settings.hpp:109
static hi::subpixel_orientation subpixel_orientation() noexcept
Get the configured light/dark theme mode.
Definition os_settings.hpp:57
static std::chrono::milliseconds cursor_blink_delay() noexcept
Get the cursor blink delay.
Definition os_settings.hpp:119
static aarectangle desktop_rectangle() noexcept
Get the rectangle describing the desktop.
Definition os_settings.hpp:199
static void gather() noexcept
Gather the settings from the operating system now.
static float double_click_distance() noexcept
Get the distance from the previous mouse position to detect double click.
Definition os_settings.hpp:89
static uintptr_t primary_monitor_id() noexcept
Get an opaque id of the primary monitor.
Definition os_settings.hpp:189
static hi::policy policy() noexcept
Get the global performance policy.
Definition os_settings.hpp:210
static std::vector< uuid > preferred_gpus(hi::policy performance_policy) noexcept
Get a list of GPUs ordered best to worst.
static float minimum_window_width() noexcept
The minimum width a window is allowed to be.
Definition os_settings.hpp:140
static float maximum_window_width() noexcept
The maximum width a window is allowed to be.
Definition os_settings.hpp:160
static bool left_to_right() noexcept
Check if the configured writing direction is left-to-right.
Definition os_settings.hpp:41
static float minimum_window_height() noexcept
The minimum height a window is allowed to be.
Definition os_settings.hpp:150
static std::chrono::milliseconds double_click_interval() noexcept
Get the mouse double click interval.
Definition os_settings.hpp:81
static bool uniform_HDR() noexcept
Whether SDR and HDR application can coexists on the same display.
Definition os_settings.hpp:73
static hi::policy gpu_policy() noexcept
Get the policy for selecting a GPU.
Definition os_settings.hpp:219
static std::vector< language_tag > language_tags() noexcept
Get the language tags for the configured languages.
Definition os_settings.hpp:30
static hi::theme_mode theme_mode() noexcept
Get the configured light/dark theme mode.
Definition os_settings.hpp:49
static std::chrono::milliseconds cursor_blink_interval() noexcept
Get the cursor blink interval.
Definition os_settings.hpp:130
True if T is a forwarded type of Forward.
Definition concepts.hpp:130