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/extent.hpp"
13#include "unfair_mutex.hpp"
14#include "subsystem.hpp"
15#include "loop.hpp"
16#include "notifier.hpp"
17#include <vector>
18#include <mutex>
19
20namespace hi::inline v1 {
21
23public:
25 using callback_token = notifier_type::callback_token;
26 using callback_proto = notifier_type::callback_proto;
27
32 [[nodiscard]] static std::vector<language_tag> language_tags() noexcept
33 {
34 hi_axiom(_populated.load(std::memory_order::acquire));
35 hilet lock = std::scoped_lock(_mutex);
36 return _language_tags;
37 }
38
44 [[nodiscard]] static std::vector<language *> languages() noexcept
45 {
46 hi_axiom(_populated.load(std::memory_order::acquire));
47 hilet lock = std::scoped_lock(_mutex);
48 return _languages;
49 }
50
57 [[nodiscard]] static unicode_bidi_class writing_direction() noexcept
58 {
59 hi_axiom(_populated.load(std::memory_order::acquire));
60 return _writing_direction.load(std::memory_order::relaxed);
61 }
62
67 [[nodiscard]] static bool left_to_right() noexcept
68 {
69 return writing_direction() == unicode_bidi_class::L;
70 }
71
76 [[nodiscard]] static bool right_to_left() noexcept
77 {
78 return not left_to_right();
79 }
80
83 [[nodiscard]] static hi::theme_mode theme_mode() noexcept
84 {
85 hi_axiom(_populated.load(std::memory_order::acquire));
86 return _theme_mode.load(std::memory_order::relaxed);
87 }
88
91 [[nodiscard]] static hi::subpixel_orientation subpixel_orientation() noexcept
92 {
93 hi_axiom(_populated.load(std::memory_order::acquire));
94 return _subpixel_orientation.load(std::memory_order::relaxed);
95 }
96
107 [[nodiscard]] static bool uniform_HDR() noexcept
108 {
109 hi_axiom(_populated.load(std::memory_order::acquire));
110 return _uniform_HDR.load(std::memory_order::relaxed);
111 }
112
115 [[nodiscard]] static std::chrono::milliseconds double_click_interval() noexcept
116 {
117 hi_axiom(_populated.load(std::memory_order::acquire));
118 return _double_click_interval.load(std::memory_order::relaxed);
119 }
120
123 [[nodiscard]] static float double_click_distance() noexcept
124 {
125 hi_axiom(_populated.load(std::memory_order::acquire));
126 return _double_click_distance.load(std::memory_order::relaxed);
127 }
128
133 [[nodiscard]] static std::chrono::milliseconds keyboard_repeat_delay() noexcept
134 {
135 hi_axiom(_populated.load(std::memory_order::acquire));
136 return _keyboard_repeat_delay.load(std::memory_order::relaxed);
137 }
138
144 {
145 hi_axiom(_populated.load(std::memory_order::acquire));
146 return _keyboard_repeat_interval.load(std::memory_order::relaxed);
147 }
148
153 [[nodiscard]] static std::chrono::milliseconds cursor_blink_delay() noexcept
154 {
155 hi_axiom(_populated.load(std::memory_order::acquire));
156 return _cursor_blink_delay.load(std::memory_order::relaxed);
157 }
158
164 [[nodiscard]] static std::chrono::milliseconds cursor_blink_interval() noexcept
165 {
166 hi_axiom(_populated.load(std::memory_order::acquire));
167 return _cursor_blink_interval.load(std::memory_order::relaxed);
168 }
169
174 [[nodiscard]] static int minimum_window_width() noexcept
175 {
176 hi_axiom(_populated.load(std::memory_order::acquire));
177 return _minimum_window_width.load(std::memory_order::relaxed);
178 }
179
184 [[nodiscard]] static int minimum_window_height() noexcept
185 {
186 hi_axiom(_populated.load(std::memory_order::acquire));
187 return _minimum_window_height.load(std::memory_order::relaxed);
188 }
189
194 [[nodiscard]] static int maximum_window_width() noexcept
195 {
196 hi_axiom(_populated.load(std::memory_order::acquire));
197 return _maximum_window_width.load(std::memory_order::relaxed);
198 }
199
204 [[nodiscard]] static int maximum_window_height() noexcept
205 {
206 hi_axiom(_populated.load(std::memory_order::acquire));
207 return _maximum_window_height.load(std::memory_order::relaxed);
208 }
209
214 [[nodiscard]] static aarectanglei primary_monitor_rectangle() noexcept
215 {
216 hi_axiom(_populated.load(std::memory_order::acquire));
217 hilet lock = std::scoped_lock(_mutex);
218 return _primary_monitor_rectangle;
219 }
220
223 [[nodiscard]] static uintptr_t primary_monitor_id() noexcept
224 {
225 hi_axiom(_populated.load(std::memory_order::acquire));
226 return _primary_monitor_id.load(std::memory_order::relaxed);
227 }
228
233 [[nodiscard]] static aarectanglei desktop_rectangle() noexcept
234 {
235 hi_axiom(_populated.load(std::memory_order::acquire));
236 hilet lock = std::scoped_lock(_mutex);
237 return _desktop_rectangle;
238 }
239
242 static void gather() noexcept;
243
244 [[nodiscard]] static callback_token
245 subscribe(forward_of<callback_proto> auto&& callback, callback_flags flags = callback_flags::synchronous) noexcept
246 {
247 hilet lock = std::scoped_lock(_mutex);
248 return _notifier.subscribe(hi_forward(callback), flags);
249 }
250
255 static bool start_subsystem() noexcept
256 {
257 return hi::start_subsystem(_started, false, subsystem_init, subsystem_deinit);
258 }
259
260private:
261 static constexpr std::chrono::duration gather_interval = std::chrono::seconds(5);
262 static constexpr std::chrono::duration gather_minimum_interval = std::chrono::seconds(1);
263
264 static inline std::atomic<bool> _started = false;
265 static inline std::atomic<bool> _populated = false;
266 static inline unfair_mutex _mutex;
267 static inline loop::timer_callback_token _gather_cbt;
268 static inline utc_nanoseconds _gather_last_time;
269
270 static inline notifier_type _notifier;
271
272 static inline std::vector<language_tag> _language_tags = {};
273 static inline std::vector<language *> _languages = {};
274 static inline std::atomic<hi::unicode_bidi_class> _writing_direction = hi::unicode_bidi_class::L;
275 static inline std::atomic<hi::theme_mode> _theme_mode = theme_mode::dark;
276 static inline std::atomic<bool> _uniform_HDR = false;
277 static inline std::atomic<hi::subpixel_orientation> _subpixel_orientation = hi::subpixel_orientation::unknown;
278 static inline std::atomic<std::chrono::milliseconds> _double_click_interval = std::chrono::milliseconds(500);
279 static inline std::atomic<float> _double_click_distance = 4.0f;
280 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_delay = std::chrono::milliseconds(250);
281 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_interval = std::chrono::milliseconds(33);
282 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_interval = std::chrono::milliseconds(1000);
283 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_delay = std::chrono::milliseconds(1000);
284 static inline std::atomic<int> _minimum_window_width = 40;
285 static inline std::atomic<int> _minimum_window_height = 25;
286 static inline std::atomic<int> _maximum_window_width = 1920;
287 static inline std::atomic<int> _maximum_window_height = 1080;
288 static inline std::atomic<uintptr_t> _primary_monitor_id = 0;
289 static inline aarectanglei _primary_monitor_rectangle = aarectanglei{0, 0, 1920, 1080};
290 static inline aarectanglei _desktop_rectangle = aarectanglei{0, 0, 1920, 1080};
291
292 [[nodiscard]] static bool subsystem_init() noexcept;
293 static void subsystem_deinit() noexcept;
294
295 [[nodiscard]] static std::vector<language_tag> gather_languages();
296 [[nodiscard]] static hi::theme_mode gather_theme_mode();
297 [[nodiscard]] static hi::subpixel_orientation gather_subpixel_orientation();
298 [[nodiscard]] static bool gather_uniform_HDR();
299 [[nodiscard]] static std::chrono::milliseconds gather_double_click_interval();
300 [[nodiscard]] static float gather_double_click_distance();
301 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_delay();
302 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_interval();
303 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_interval();
304 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_delay();
305 [[nodiscard]] static int gather_minimum_window_width();
306 [[nodiscard]] static int gather_minimum_window_height();
307 [[nodiscard]] static int gather_maximum_window_width();
308 [[nodiscard]] static int gather_maximum_window_height();
309 [[nodiscard]] static uintptr_t gather_primary_monitor_id();
310 [[nodiscard]] static aarectanglei gather_primary_monitor_rectangle();
311 [[nodiscard]] static aarectanglei gather_desktop_rectangle();
312};
313
314} // namespace hi::inline v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
#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
Defined the geo::extent, extent2 and extent3 types.
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
callback_flags
Definition callback_flags.hpp:12
unicode_bidi_class
Bidirectional class Unicode Standard Annex #9: https://unicode.org/reports/tr9/.
Definition unicode_bidi_class.hpp:17
geometry/margins.hpp
Definition assert.hpp:18
A notifier which can be used to call a set of registered callbacks.
Definition notifier.hpp:26
Definition os_settings.hpp:22
static int maximum_window_height() noexcept
The maximum height a window is allowed to be.
Definition os_settings.hpp:204
static std::chrono::milliseconds keyboard_repeat_delay() noexcept
Get the delay before the keyboard starts repeating.
Definition os_settings.hpp:133
static unicode_bidi_class writing_direction() noexcept
Get the configured writing direction.
Definition os_settings.hpp:57
static bool start_subsystem() noexcept
Get the global os_settings instance.
Definition os_settings.hpp:255
static std::chrono::milliseconds keyboard_repeat_interval() noexcept
Get the keyboard repeat interval.
Definition os_settings.hpp:143
static std::vector< language * > languages() noexcept
Get the configured languages.
Definition os_settings.hpp:44
static hi::subpixel_orientation subpixel_orientation() noexcept
Get the configured light/dark theme mode.
Definition os_settings.hpp:91
static std::chrono::milliseconds cursor_blink_delay() noexcept
Get the cursor blink delay.
Definition os_settings.hpp:153
static aarectanglei desktop_rectangle() noexcept
Get the rectangle describing the desktop.
Definition os_settings.hpp:233
static int minimum_window_width() noexcept
The minimum width a window is allowed to be.
Definition os_settings.hpp:174
static aarectanglei primary_monitor_rectangle() noexcept
Get the rectangle of the primary monitor.
Definition os_settings.hpp:214
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:123
static uintptr_t primary_monitor_id() noexcept
Get an opaque id of the primary monitor.
Definition os_settings.hpp:223
static int minimum_window_height() noexcept
The minimum height a window is allowed to be.
Definition os_settings.hpp:184
static bool left_to_right() noexcept
Check if the configured writing direction is left-to-right.
Definition os_settings.hpp:67
static int maximum_window_width() noexcept
The maximum width a window is allowed to be.
Definition os_settings.hpp:194
static std::chrono::milliseconds double_click_interval() noexcept
Get the mouse double click interval.
Definition os_settings.hpp:115
static bool uniform_HDR() noexcept
Whether SDR and HDR application can coexists on the same display.
Definition os_settings.hpp:107
static std::vector< language_tag > language_tags() noexcept
Get the language tags for the configured languages.
Definition os_settings.hpp:32
static hi::theme_mode theme_mode() noexcept
Get the configured light/dark theme mode.
Definition os_settings.hpp:83
static bool right_to_left() noexcept
Check if the configured writing direction is right-to-left.
Definition os_settings.hpp:76
static std::chrono::milliseconds cursor_blink_interval() noexcept
Get the cursor blink interval.
Definition os_settings.hpp:164
True if T is a forwarded type of Forward.
Definition concepts.hpp:130