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"
12#include "geometry/axis_aligned_rectangle.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 start_subsystem();
35 hilet lock = std::scoped_lock(_mutex);
36 return _language_tags;
37 }
38
44 [[nodiscard]] static std::vector<language *> languages() noexcept
45 {
46 start_subsystem();
47 hilet lock = std::scoped_lock(_mutex);
48 return _languages;
49 }
50
53 [[nodiscard]] static hi::theme_mode theme_mode() noexcept
54 {
55 start_subsystem();
56 return _theme_mode.load(std::memory_order_relaxed);
57 }
58
61 [[nodiscard]] static hi::subpixel_orientation subpixel_orientation() noexcept
62 {
63 start_subsystem();
64 return _subpixel_orientation.load(std::memory_order_relaxed);
65 }
66
77 [[nodiscard]] static bool uniform_HDR() noexcept
78 {
79 start_subsystem();
80 return _uniform_HDR;
81 }
82
85 [[nodiscard]] static std::chrono::milliseconds double_click_interval() noexcept
86 {
87 start_subsystem();
88 return _double_click_interval.load(std::memory_order_relaxed);
89 }
90
93 [[nodiscard]] static float double_click_distance() noexcept
94 {
95 start_subsystem();
96 return _double_click_distance.load(std::memory_order_relaxed);
97 }
98
103 [[nodiscard]] static std::chrono::milliseconds keyboard_repeat_delay() noexcept
104 {
105 start_subsystem();
106 return _keyboard_repeat_delay.load(std::memory_order_relaxed);
107 }
108
114 {
115 start_subsystem();
116 return _keyboard_repeat_interval.load(std::memory_order_relaxed);
117 }
118
123 [[nodiscard]] static std::chrono::milliseconds cursor_blink_delay() noexcept
124 {
125 start_subsystem();
126 return _cursor_blink_delay.load(std::memory_order_relaxed);
127 }
128
134 [[nodiscard]] static std::chrono::milliseconds cursor_blink_interval() noexcept
135 {
136 start_subsystem();
137 return _cursor_blink_interval.load(std::memory_order_relaxed);
138 }
139
142 [[nodiscard]] static extent2 minimum_window_size() noexcept
143 {
144 start_subsystem();
145 hilet lock = std::scoped_lock(_mutex);
146 return _minimum_window_size;
147 }
148
151 [[nodiscard]] static extent2 maximum_window_size() noexcept
152 {
153 start_subsystem();
154 hilet lock = std::scoped_lock(_mutex);
155 return _maximum_window_size;
156 }
157
162 [[nodiscard]] static aarectangle primary_monitor_rectangle() noexcept
163 {
164 start_subsystem();
165 hilet lock = std::scoped_lock(_mutex);
166 return _primary_monitor_rectangle;
167 }
168
171 [[nodiscard]] static uintptr_t primary_monitor_id() noexcept
172 {
173 hi_axiom(_started);
174 return _primary_monitor_id.load(std::memory_order::relaxed);
175 }
176
181 [[nodiscard]] static aarectangle desktop_rectangle() noexcept
182 {
183 start_subsystem();
184 hilet lock = std::scoped_lock(_mutex);
185 return _desktop_rectangle;
186 }
187
190 static void gather() noexcept;
191
192 [[nodiscard]] static callback_token subscribe(forward_of<callback_proto> auto&& callback, callback_flags flags = callback_flags::synchronous) noexcept
193 {
194 start_subsystem();
195 hilet lock = std::scoped_lock(_mutex);
196 return _notifier.subscribe(hi_forward(callback), flags);
197 }
198
199private:
200 static constexpr std::chrono::duration gather_interval = std::chrono::seconds(5);
201 static constexpr std::chrono::duration gather_minimum_interval = std::chrono::seconds(1);
202
203 static inline std::atomic<bool> _started = false;
204 static inline unfair_mutex _mutex;
205 static inline loop::timer_callback_token _gather_cbt;
206 static inline utc_nanoseconds _gather_last_time;
207
208 static inline notifier_type _notifier;
209
210 static inline std::vector<language_tag> _language_tags = {};
211 static inline std::vector<language *> _languages = {};
212 static inline std::atomic<hi::theme_mode> _theme_mode = theme_mode::dark;
213 static inline std::atomic<bool> _uniform_HDR = false;
214 static inline std::atomic<hi::subpixel_orientation> _subpixel_orientation = hi::subpixel_orientation::unknown;
215 static inline std::atomic<std::chrono::milliseconds> _double_click_interval = std::chrono::milliseconds(500);
216 static inline std::atomic<float> _double_click_distance = 4.0f;
217 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_delay = std::chrono::milliseconds(250);
218 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_interval = std::chrono::milliseconds(33);
219 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_interval = std::chrono::milliseconds(1000);
220 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_delay = std::chrono::milliseconds(1000);
221 static inline extent2 _minimum_window_size = extent2{40.0f, 25.0f};
222 static inline extent2 _maximum_window_size = extent2{1920.0f, 1080.0f};
223 static inline std::atomic<uintptr_t> _primary_monitor_id = 0;
224 static inline aarectangle _primary_monitor_rectangle = aarectangle{0.0, 0.0, 1920.0f, 1080.0f};
225 static inline aarectangle _desktop_rectangle = aarectangle{0.0, 0.0, 1920.0f, 1080.0f};
226
231 static bool start_subsystem() noexcept
232 {
233 return hi::start_subsystem(_started, false, subsystem_init, subsystem_deinit);
234 }
235
236 [[nodiscard]] static bool subsystem_init() noexcept;
237 static void subsystem_deinit() noexcept;
238
239 [[nodiscard]] static std::vector<language_tag> gather_languages();
240 [[nodiscard]] static hi::theme_mode gather_theme_mode();
241 [[nodiscard]] static hi::subpixel_orientation gather_subpixel_orientation();
242 [[nodiscard]] static bool gather_uniform_HDR();
243 [[nodiscard]] static std::chrono::milliseconds gather_double_click_interval();
244 [[nodiscard]] static float gather_double_click_distance();
245 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_delay();
246 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_interval();
247 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_interval();
248 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_delay();
249 [[nodiscard]] static extent2 gather_minimum_window_size();
250 [[nodiscard]] static extent2 gather_maximum_window_size();
251 [[nodiscard]] static uintptr_t gather_primary_monitor_id();
252 [[nodiscard]] static aarectangle gather_primary_monitor_rectangle();
253 [[nodiscard]] static aarectangle gather_desktop_rectangle();
254};
255
256} // namespace hi::inline v1
#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
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
callback_flags
Definition callback_flags.hpp:12
The HikoGUI namespace.
Definition ascii.hpp:19
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
A notifier which can be used to call a set of registered callbacks.
Definition notifier.hpp:24
Definition os_settings.hpp:22
static std::chrono::milliseconds keyboard_repeat_delay() noexcept
Get the delay before the keyboard starts repeating.
Definition os_settings.hpp:103
static aarectangle primary_monitor_rectangle() noexcept
Get the rectangle of the primary monitor.
Definition os_settings.hpp:162
static std::chrono::milliseconds keyboard_repeat_interval() noexcept
Get the keyboard repeat interval.
Definition os_settings.hpp:113
static extent2 maximum_window_size() noexcept
Get the maximum window size supported by the operating system.
Definition os_settings.hpp:151
static extent2 minimum_window_size() noexcept
Get the minimum window size supported by the operating system.
Definition os_settings.hpp:142
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:61
static std::chrono::milliseconds cursor_blink_delay() noexcept
Get the cursor blink delay.
Definition os_settings.hpp:123
static aarectangle desktop_rectangle() noexcept
Get the rectangle describing the desktop.
Definition os_settings.hpp:181
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:93
static uintptr_t primary_monitor_id() noexcept
Get an opaque id of the primary monitor.
Definition os_settings.hpp:171
static std::chrono::milliseconds double_click_interval() noexcept
Get the mouse double click interval.
Definition os_settings.hpp:85
static bool uniform_HDR() noexcept
Whether SDR and HDR application can coexists on the same display.
Definition os_settings.hpp:77
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:53
static std::chrono::milliseconds cursor_blink_interval() noexcept
Get the cursor blink interval.
Definition os_settings.hpp:134
True if T is a forwarded type of Forward.
Definition concepts.hpp:130