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 "i18n/module.hpp"
8#include "theme/module.hpp"
9#include "GFX/module.hpp"
10#include "geometry/module.hpp"
11#include "utility/module.hpp"
12#include "loop.hpp"
13#include "notifier.hpp"
14#include <vector>
15#include <mutex>
16
17namespace hi::inline v1 {
18
20public:
22 using callback_token = notifier_type::callback_token;
23 using callback_proto = notifier_type::callback_proto;
24
29 [[nodiscard]] static std::vector<language_tag> language_tags() noexcept
30 {
31 hi_axiom(_populated.load(std::memory_order::acquire));
32 hilet lock = std::scoped_lock(_mutex);
33 return _language_tags;
34 }
35
40 [[nodiscard]] static language_tag language_tag() noexcept
41 {
42 hi_axiom(_populated.load(std::memory_order::acquire));
43 return _language_tag.load(std::memory_order::relaxed);
44 }
45
50 [[nodiscard]] static bool left_to_right() noexcept
51 {
52 hi_axiom(_populated.load(std::memory_order::acquire));
53 return _left_to_right.load(std::memory_order::relaxed);
54 }
55
60 [[nodiscard]] static bool right_to_left() noexcept
61 {
62 return not left_to_right();
63 }
64
67 [[nodiscard]] static hi::theme_mode theme_mode() noexcept
68 {
69 hi_axiom(_populated.load(std::memory_order::acquire));
70 return _theme_mode.load(std::memory_order::relaxed);
71 }
72
75 [[nodiscard]] static hi::subpixel_orientation subpixel_orientation() noexcept
76 {
77 hi_axiom(_populated.load(std::memory_order::acquire));
78 return _subpixel_orientation.load(std::memory_order::relaxed);
79 }
80
91 [[nodiscard]] static bool uniform_HDR() noexcept
92 {
93 hi_axiom(_populated.load(std::memory_order::acquire));
94 return _uniform_HDR.load(std::memory_order::relaxed);
95 }
96
99 [[nodiscard]] static std::chrono::milliseconds double_click_interval() noexcept
100 {
101 hi_axiom(_populated.load(std::memory_order::acquire));
102 return _double_click_interval.load(std::memory_order::relaxed);
103 }
104
107 [[nodiscard]] static float double_click_distance() noexcept
108 {
109 hi_axiom(_populated.load(std::memory_order::acquire));
110 return _double_click_distance.load(std::memory_order::relaxed);
111 }
112
117 [[nodiscard]] static std::chrono::milliseconds keyboard_repeat_delay() noexcept
118 {
119 hi_axiom(_populated.load(std::memory_order::acquire));
120 return _keyboard_repeat_delay.load(std::memory_order::relaxed);
121 }
122
128 {
129 hi_axiom(_populated.load(std::memory_order::acquire));
130 return _keyboard_repeat_interval.load(std::memory_order::relaxed);
131 }
132
137 [[nodiscard]] static std::chrono::milliseconds cursor_blink_delay() noexcept
138 {
139 hi_axiom(_populated.load(std::memory_order::acquire));
140 return _cursor_blink_delay.load(std::memory_order::relaxed);
141 }
142
148 [[nodiscard]] static std::chrono::milliseconds cursor_blink_interval() noexcept
149 {
150 hi_axiom(_populated.load(std::memory_order::acquire));
151 return _cursor_blink_interval.load(std::memory_order::relaxed);
152 }
153
158 [[nodiscard]] static int minimum_window_width() noexcept
159 {
160 hi_axiom(_populated.load(std::memory_order::acquire));
161 return _minimum_window_width.load(std::memory_order::relaxed);
162 }
163
168 [[nodiscard]] static int minimum_window_height() noexcept
169 {
170 hi_axiom(_populated.load(std::memory_order::acquire));
171 return _minimum_window_height.load(std::memory_order::relaxed);
172 }
173
178 [[nodiscard]] static int maximum_window_width() noexcept
179 {
180 hi_axiom(_populated.load(std::memory_order::acquire));
181 return _maximum_window_width.load(std::memory_order::relaxed);
182 }
183
188 [[nodiscard]] static int maximum_window_height() noexcept
189 {
190 hi_axiom(_populated.load(std::memory_order::acquire));
191 return _maximum_window_height.load(std::memory_order::relaxed);
192 }
193
198 [[nodiscard]] static aarectanglei primary_monitor_rectangle() noexcept
199 {
200 hi_axiom(_populated.load(std::memory_order::acquire));
201 hilet lock = std::scoped_lock(_mutex);
202 return _primary_monitor_rectangle;
203 }
204
207 [[nodiscard]] static uintptr_t primary_monitor_id() noexcept
208 {
209 hi_axiom(_populated.load(std::memory_order::acquire));
210 return _primary_monitor_id.load(std::memory_order::relaxed);
211 }
212
217 [[nodiscard]] static aarectanglei desktop_rectangle() noexcept
218 {
219 hi_axiom(_populated.load(std::memory_order::acquire));
220 hilet lock = std::scoped_lock(_mutex);
221 return _desktop_rectangle;
222 }
223
226 static void gather() noexcept;
227
228 [[nodiscard]] static callback_token
229 subscribe(forward_of<callback_proto> auto&& callback, callback_flags flags = callback_flags::synchronous) noexcept
230 {
231 hilet lock = std::scoped_lock(_mutex);
232 return _notifier.subscribe(hi_forward(callback), flags);
233 }
234
239 static bool start_subsystem() noexcept
240 {
241 return hi::start_subsystem(_started, false, subsystem_init, subsystem_deinit);
242 }
243
244private:
245 static constexpr std::chrono::duration gather_interval = std::chrono::seconds(5);
246 static constexpr std::chrono::duration gather_minimum_interval = std::chrono::seconds(1);
247
248 static inline std::atomic<bool> _started = false;
249 static inline std::atomic<bool> _populated = false;
250 static inline unfair_mutex _mutex;
251 static inline loop::timer_callback_token _gather_cbt;
252 static inline utc_nanoseconds _gather_last_time;
253
254 static inline notifier_type _notifier;
255
256 static inline std::vector<hi::language_tag> _language_tags = {};
257 static inline std::atomic<bool> _left_to_right = true;
258 static inline std::atomic<hi::language_tag> _language_tag = hi::language_tag{"en-US"};
259 static inline std::atomic<hi::theme_mode> _theme_mode = theme_mode::dark;
260 static inline std::atomic<bool> _uniform_HDR = false;
261 static inline std::atomic<hi::subpixel_orientation> _subpixel_orientation = hi::subpixel_orientation::unknown;
262 static inline std::atomic<std::chrono::milliseconds> _double_click_interval = std::chrono::milliseconds(500);
263 static inline std::atomic<float> _double_click_distance = 4.0f;
264 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_delay = std::chrono::milliseconds(250);
265 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_interval = std::chrono::milliseconds(33);
266 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_interval = std::chrono::milliseconds(1000);
267 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_delay = std::chrono::milliseconds(1000);
268 static inline std::atomic<int> _minimum_window_width = 40;
269 static inline std::atomic<int> _minimum_window_height = 25;
270 static inline std::atomic<int> _maximum_window_width = 1920;
271 static inline std::atomic<int> _maximum_window_height = 1080;
272 static inline std::atomic<uintptr_t> _primary_monitor_id = 0;
273 static inline aarectanglei _primary_monitor_rectangle = aarectanglei{0, 0, 1920, 1080};
274 static inline aarectanglei _desktop_rectangle = aarectanglei{0, 0, 1920, 1080};
275
276 [[nodiscard]] static bool subsystem_init() noexcept;
277 static void subsystem_deinit() noexcept;
278
279 [[nodiscard]] static std::vector<hi::language_tag> gather_languages();
280 [[nodiscard]] static hi::theme_mode gather_theme_mode();
281 [[nodiscard]] static hi::subpixel_orientation gather_subpixel_orientation();
282 [[nodiscard]] static bool gather_uniform_HDR();
283 [[nodiscard]] static std::chrono::milliseconds gather_double_click_interval();
284 [[nodiscard]] static float gather_double_click_distance();
285 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_delay();
286 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_interval();
287 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_interval();
288 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_delay();
289 [[nodiscard]] static int gather_minimum_window_width();
290 [[nodiscard]] static int gather_minimum_window_height();
291 [[nodiscard]] static int gather_maximum_window_width();
292 [[nodiscard]] static int gather_maximum_window_height();
293 [[nodiscard]] static uintptr_t gather_primary_monitor_id();
294 [[nodiscard]] static aarectanglei gather_primary_monitor_rectangle();
295 [[nodiscard]] static aarectanglei gather_desktop_rectangle();
296};
297
298} // 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
The IETF BCP 47 language tag.
Definition language_tag.hpp:25
A notifier which can be used to call a set of registered callbacks.
Definition notifier.hpp:25
Definition os_settings.hpp:19
static int maximum_window_height() noexcept
The maximum height a window is allowed to be.
Definition os_settings.hpp:188
static std::chrono::milliseconds keyboard_repeat_delay() noexcept
Get the delay before the keyboard starts repeating.
Definition os_settings.hpp:117
static bool start_subsystem() noexcept
Get the global os_settings instance.
Definition os_settings.hpp:239
static std::chrono::milliseconds keyboard_repeat_interval() noexcept
Get the keyboard repeat interval.
Definition os_settings.hpp:127
static hi::subpixel_orientation subpixel_orientation() noexcept
Get the configured light/dark theme mode.
Definition os_settings.hpp:75
static std::chrono::milliseconds cursor_blink_delay() noexcept
Get the cursor blink delay.
Definition os_settings.hpp:137
static aarectanglei desktop_rectangle() noexcept
Get the rectangle describing the desktop.
Definition os_settings.hpp:217
static int minimum_window_width() noexcept
The minimum width a window is allowed to be.
Definition os_settings.hpp:158
static aarectanglei primary_monitor_rectangle() noexcept
Get the rectangle of the primary monitor.
Definition os_settings.hpp:198
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:107
static uintptr_t primary_monitor_id() noexcept
Get an opaque id of the primary monitor.
Definition os_settings.hpp:207
static language_tag language_tag() noexcept
Get the primary language_tag.
Definition os_settings.hpp:40
static int minimum_window_height() noexcept
The minimum height a window is allowed to be.
Definition os_settings.hpp:168
static bool left_to_right() noexcept
Check if the configured writing direction is left-to-right.
Definition os_settings.hpp:50
static int maximum_window_width() noexcept
The maximum width a window is allowed to be.
Definition os_settings.hpp:178
static std::chrono::milliseconds double_click_interval() noexcept
Get the mouse double click interval.
Definition os_settings.hpp:99
static bool uniform_HDR() noexcept
Whether SDR and HDR application can coexists on the same display.
Definition os_settings.hpp:91
static std::vector< language_tag > language_tags() noexcept
Get the language tags for the configured languages.
Definition os_settings.hpp:29
static hi::theme_mode theme_mode() noexcept
Get the configured light/dark theme mode.
Definition os_settings.hpp:67
static bool right_to_left() noexcept
Check if the configured writing direction is right-to-left.
Definition os_settings.hpp:60
static std::chrono::milliseconds cursor_blink_interval() noexcept
Get the cursor blink interval.
Definition os_settings.hpp:148
True if T is a forwarded type of Forward.
Definition concepts.hpp:130