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/language_tag.hpp"
8#include "i18n/language.hpp"
9#include "GUI/theme_mode.hpp"
11#include "geometry/module.hpp"
12#include "utility/module.hpp"
13#include "loop.hpp"
14#include "notifier.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
42 [[nodiscard]] static std::vector<language *> languages() noexcept
43 {
44 hi_axiom(_populated.load(std::memory_order::acquire));
45 hilet lock = std::scoped_lock(_mutex);
46 return _languages;
47 }
48
55 [[nodiscard]] static unicode_bidi_class writing_direction() noexcept
56 {
57 hi_axiom(_populated.load(std::memory_order::acquire));
58 return _writing_direction.load(std::memory_order::relaxed);
59 }
60
65 [[nodiscard]] static bool left_to_right() noexcept
66 {
67 return writing_direction() == unicode_bidi_class::L;
68 }
69
74 [[nodiscard]] static bool right_to_left() noexcept
75 {
76 return not left_to_right();
77 }
78
81 [[nodiscard]] static hi::theme_mode theme_mode() noexcept
82 {
83 hi_axiom(_populated.load(std::memory_order::acquire));
84 return _theme_mode.load(std::memory_order::relaxed);
85 }
86
89 [[nodiscard]] static hi::subpixel_orientation subpixel_orientation() noexcept
90 {
91 hi_axiom(_populated.load(std::memory_order::acquire));
92 return _subpixel_orientation.load(std::memory_order::relaxed);
93 }
94
105 [[nodiscard]] static bool uniform_HDR() noexcept
106 {
107 hi_axiom(_populated.load(std::memory_order::acquire));
108 return _uniform_HDR.load(std::memory_order::relaxed);
109 }
110
113 [[nodiscard]] static std::chrono::milliseconds double_click_interval() noexcept
114 {
115 hi_axiom(_populated.load(std::memory_order::acquire));
116 return _double_click_interval.load(std::memory_order::relaxed);
117 }
118
121 [[nodiscard]] static float double_click_distance() noexcept
122 {
123 hi_axiom(_populated.load(std::memory_order::acquire));
124 return _double_click_distance.load(std::memory_order::relaxed);
125 }
126
131 [[nodiscard]] static std::chrono::milliseconds keyboard_repeat_delay() noexcept
132 {
133 hi_axiom(_populated.load(std::memory_order::acquire));
134 return _keyboard_repeat_delay.load(std::memory_order::relaxed);
135 }
136
142 {
143 hi_axiom(_populated.load(std::memory_order::acquire));
144 return _keyboard_repeat_interval.load(std::memory_order::relaxed);
145 }
146
151 [[nodiscard]] static std::chrono::milliseconds cursor_blink_delay() noexcept
152 {
153 hi_axiom(_populated.load(std::memory_order::acquire));
154 return _cursor_blink_delay.load(std::memory_order::relaxed);
155 }
156
162 [[nodiscard]] static std::chrono::milliseconds cursor_blink_interval() noexcept
163 {
164 hi_axiom(_populated.load(std::memory_order::acquire));
165 return _cursor_blink_interval.load(std::memory_order::relaxed);
166 }
167
172 [[nodiscard]] static int minimum_window_width() noexcept
173 {
174 hi_axiom(_populated.load(std::memory_order::acquire));
175 return _minimum_window_width.load(std::memory_order::relaxed);
176 }
177
182 [[nodiscard]] static int minimum_window_height() noexcept
183 {
184 hi_axiom(_populated.load(std::memory_order::acquire));
185 return _minimum_window_height.load(std::memory_order::relaxed);
186 }
187
192 [[nodiscard]] static int maximum_window_width() noexcept
193 {
194 hi_axiom(_populated.load(std::memory_order::acquire));
195 return _maximum_window_width.load(std::memory_order::relaxed);
196 }
197
202 [[nodiscard]] static int maximum_window_height() noexcept
203 {
204 hi_axiom(_populated.load(std::memory_order::acquire));
205 return _maximum_window_height.load(std::memory_order::relaxed);
206 }
207
212 [[nodiscard]] static aarectanglei primary_monitor_rectangle() noexcept
213 {
214 hi_axiom(_populated.load(std::memory_order::acquire));
215 hilet lock = std::scoped_lock(_mutex);
216 return _primary_monitor_rectangle;
217 }
218
221 [[nodiscard]] static uintptr_t primary_monitor_id() noexcept
222 {
223 hi_axiom(_populated.load(std::memory_order::acquire));
224 return _primary_monitor_id.load(std::memory_order::relaxed);
225 }
226
231 [[nodiscard]] static aarectanglei desktop_rectangle() noexcept
232 {
233 hi_axiom(_populated.load(std::memory_order::acquire));
234 hilet lock = std::scoped_lock(_mutex);
235 return _desktop_rectangle;
236 }
237
240 static void gather() noexcept;
241
242 [[nodiscard]] static callback_token
243 subscribe(forward_of<callback_proto> auto&& callback, callback_flags flags = callback_flags::synchronous) noexcept
244 {
245 hilet lock = std::scoped_lock(_mutex);
246 return _notifier.subscribe(hi_forward(callback), flags);
247 }
248
253 static bool start_subsystem() noexcept
254 {
255 return hi::start_subsystem(_started, false, subsystem_init, subsystem_deinit);
256 }
257
258private:
259 static constexpr std::chrono::duration gather_interval = std::chrono::seconds(5);
260 static constexpr std::chrono::duration gather_minimum_interval = std::chrono::seconds(1);
261
262 static inline std::atomic<bool> _started = false;
263 static inline std::atomic<bool> _populated = false;
264 static inline unfair_mutex _mutex;
265 static inline loop::timer_callback_token _gather_cbt;
266 static inline utc_nanoseconds _gather_last_time;
267
268 static inline notifier_type _notifier;
269
270 static inline std::vector<language_tag> _language_tags = {};
271 static inline std::vector<language *> _languages = {};
272 static inline std::atomic<hi::unicode_bidi_class> _writing_direction = hi::unicode_bidi_class::L;
273 static inline std::atomic<hi::theme_mode> _theme_mode = theme_mode::dark;
274 static inline std::atomic<bool> _uniform_HDR = false;
275 static inline std::atomic<hi::subpixel_orientation> _subpixel_orientation = hi::subpixel_orientation::unknown;
276 static inline std::atomic<std::chrono::milliseconds> _double_click_interval = std::chrono::milliseconds(500);
277 static inline std::atomic<float> _double_click_distance = 4.0f;
278 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_delay = std::chrono::milliseconds(250);
279 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_interval = std::chrono::milliseconds(33);
280 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_interval = std::chrono::milliseconds(1000);
281 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_delay = std::chrono::milliseconds(1000);
282 static inline std::atomic<int> _minimum_window_width = 40;
283 static inline std::atomic<int> _minimum_window_height = 25;
284 static inline std::atomic<int> _maximum_window_width = 1920;
285 static inline std::atomic<int> _maximum_window_height = 1080;
286 static inline std::atomic<uintptr_t> _primary_monitor_id = 0;
287 static inline aarectanglei _primary_monitor_rectangle = aarectanglei{0, 0, 1920, 1080};
288 static inline aarectanglei _desktop_rectangle = aarectanglei{0, 0, 1920, 1080};
289
290 [[nodiscard]] static bool subsystem_init() noexcept;
291 static void subsystem_deinit() noexcept;
292
293 [[nodiscard]] static std::vector<language_tag> gather_languages();
294 [[nodiscard]] static hi::theme_mode gather_theme_mode();
295 [[nodiscard]] static hi::subpixel_orientation gather_subpixel_orientation();
296 [[nodiscard]] static bool gather_uniform_HDR();
297 [[nodiscard]] static std::chrono::milliseconds gather_double_click_interval();
298 [[nodiscard]] static float gather_double_click_distance();
299 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_delay();
300 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_interval();
301 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_interval();
302 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_delay();
303 [[nodiscard]] static int gather_minimum_window_width();
304 [[nodiscard]] static int gather_minimum_window_height();
305 [[nodiscard]] static int gather_maximum_window_width();
306 [[nodiscard]] static int gather_maximum_window_height();
307 [[nodiscard]] static uintptr_t gather_primary_monitor_id();
308 [[nodiscard]] static aarectanglei gather_primary_monitor_rectangle();
309 [[nodiscard]] static aarectanglei gather_desktop_rectangle();
310};
311
312} // namespace hi::inline v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
#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
unicode_bidi_class
Bidirectional class Unicode Standard Annex #9: https://unicode.org/reports/tr9/.
Definition unicode_bidi_class.hpp:16
geometry/margins.hpp
Definition cache.hpp:11
A notifier which can be used to call a set of registered callbacks.
Definition notifier.hpp:25
Definition os_settings.hpp:20
static int maximum_window_height() noexcept
The maximum height a window is allowed to be.
Definition os_settings.hpp:202
static std::chrono::milliseconds keyboard_repeat_delay() noexcept
Get the delay before the keyboard starts repeating.
Definition os_settings.hpp:131
static unicode_bidi_class writing_direction() noexcept
Get the configured writing direction.
Definition os_settings.hpp:55
static bool start_subsystem() noexcept
Get the global os_settings instance.
Definition os_settings.hpp:253
static std::chrono::milliseconds keyboard_repeat_interval() noexcept
Get the keyboard repeat interval.
Definition os_settings.hpp:141
static std::vector< language * > languages() noexcept
Get the configured languages.
Definition os_settings.hpp:42
static hi::subpixel_orientation subpixel_orientation() noexcept
Get the configured light/dark theme mode.
Definition os_settings.hpp:89
static std::chrono::milliseconds cursor_blink_delay() noexcept
Get the cursor blink delay.
Definition os_settings.hpp:151
static aarectanglei desktop_rectangle() noexcept
Get the rectangle describing the desktop.
Definition os_settings.hpp:231
static int minimum_window_width() noexcept
The minimum width a window is allowed to be.
Definition os_settings.hpp:172
static aarectanglei primary_monitor_rectangle() noexcept
Get the rectangle of the primary monitor.
Definition os_settings.hpp:212
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:121
static uintptr_t primary_monitor_id() noexcept
Get an opaque id of the primary monitor.
Definition os_settings.hpp:221
static int minimum_window_height() noexcept
The minimum height a window is allowed to be.
Definition os_settings.hpp:182
static bool left_to_right() noexcept
Check if the configured writing direction is left-to-right.
Definition os_settings.hpp:65
static int maximum_window_width() noexcept
The maximum width a window is allowed to be.
Definition os_settings.hpp:192
static std::chrono::milliseconds double_click_interval() noexcept
Get the mouse double click interval.
Definition os_settings.hpp:113
static bool uniform_HDR() noexcept
Whether SDR and HDR application can coexists on the same display.
Definition os_settings.hpp:105
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:81
static bool right_to_left() noexcept
Check if the configured writing direction is right-to-left.
Definition os_settings.hpp:74
static std::chrono::milliseconds cursor_blink_interval() noexcept
Get the cursor blink interval.
Definition os_settings.hpp:162
True if T is a forwarded type of Forward.
Definition concepts.hpp:130