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 token_type = notifier_type::token_type;
26
31 [[nodiscard]] static std::vector<language_tag> language_tags() noexcept
32 {
33 start_subsystem();
34 hilet lock = std::scoped_lock(_mutex);
35 return _language_tags;
36 }
37
43 [[nodiscard]] static std::vector<language *> languages() noexcept
44 {
45 start_subsystem();
46 hilet lock = std::scoped_lock(_mutex);
47 return _languages;
48 }
49
52 [[nodiscard]] static hi::theme_mode theme_mode() noexcept
53 {
54 start_subsystem();
55 return _theme_mode.load(std::memory_order_relaxed);
56 }
57
60 [[nodiscard]] static hi::subpixel_orientation subpixel_orientation() noexcept
61 {
62 start_subsystem();
63 return _subpixel_orientation.load(std::memory_order_relaxed);
64 }
65
76 [[nodiscard]] static bool uniform_HDR() noexcept
77 {
78 start_subsystem();
79 return _uniform_HDR;
80 }
81
84 [[nodiscard]] static std::chrono::milliseconds double_click_interval() noexcept
85 {
86 start_subsystem();
87 return _double_click_interval.load(std::memory_order_relaxed);
88 }
89
92 [[nodiscard]] static float double_click_distance() noexcept
93 {
94 start_subsystem();
95 return _double_click_distance.load(std::memory_order_relaxed);
96 }
97
102 [[nodiscard]] static std::chrono::milliseconds keyboard_repeat_delay() noexcept
103 {
104 start_subsystem();
105 return _keyboard_repeat_delay.load(std::memory_order_relaxed);
106 }
107
113 {
114 start_subsystem();
115 return _keyboard_repeat_interval.load(std::memory_order_relaxed);
116 }
117
122 [[nodiscard]] static std::chrono::milliseconds cursor_blink_delay() noexcept
123 {
124 start_subsystem();
125 return _cursor_blink_delay.load(std::memory_order_relaxed);
126 }
127
133 [[nodiscard]] static std::chrono::milliseconds cursor_blink_interval() noexcept
134 {
135 start_subsystem();
136 return _cursor_blink_interval.load(std::memory_order_relaxed);
137 }
138
141 [[nodiscard]] static extent2 minimum_window_size() noexcept
142 {
143 start_subsystem();
144 hilet lock = std::scoped_lock(_mutex);
145 return _minimum_window_size;
146 }
147
150 [[nodiscard]] static extent2 maximum_window_size() noexcept
151 {
152 start_subsystem();
153 hilet lock = std::scoped_lock(_mutex);
154 return _maximum_window_size;
155 }
156
161 [[nodiscard]] static aarectangle primary_monitor_rectangle() noexcept
162 {
163 start_subsystem();
164 hilet lock = std::scoped_lock(_mutex);
165 return _primary_monitor_rectangle;
166 }
167
170 [[nodiscard]] static uintptr_t primary_monitor_id() noexcept
171 {
172 hi_axiom(_started);
173 return _primary_monitor_id.load(std::memory_order::relaxed);
174 }
175
180 [[nodiscard]] static aarectangle desktop_rectangle() noexcept
181 {
182 start_subsystem();
183 hilet lock = std::scoped_lock(_mutex);
184 return _desktop_rectangle;
185 }
186
189 static void gather() noexcept;
190
191 [[nodiscard]] static token_type subscribe(callback_flags flags, std::invocable<> auto&& callback) noexcept
192 {
193 start_subsystem();
194 hilet lock = std::scoped_lock(_mutex);
195 return _notifier.subscribe(flags, hi_forward(callback));
196 }
197
198 [[nodiscard]] static token_type subscribe(std::invocable<> auto&& callback) noexcept
199 {
200 return subscribe(callback_flags::synchronous, hi_forward(callback));
201 }
202
203private:
204 static constexpr std::chrono::duration gather_interval = std::chrono::seconds(5);
205 static constexpr std::chrono::duration gather_minimum_interval = std::chrono::seconds(1);
206
207 static inline std::atomic<bool> _started = false;
208 static inline unfair_mutex _mutex;
209 static inline loop::timer_token_type _gather_cbt;
210 static inline utc_nanoseconds _gather_last_time;
211
212 static inline notifier_type _notifier;
213
214 static inline std::vector<language_tag> _language_tags = {};
215 static inline std::vector<language *> _languages = {};
216 static inline std::atomic<hi::theme_mode> _theme_mode = theme_mode::dark;
217 static inline std::atomic<bool> _uniform_HDR = false;
218 static inline std::atomic<hi::subpixel_orientation> _subpixel_orientation = hi::subpixel_orientation::unknown;
219 static inline std::atomic<std::chrono::milliseconds> _double_click_interval = std::chrono::milliseconds(500);
220 static inline std::atomic<float> _double_click_distance = 4.0f;
221 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_delay = std::chrono::milliseconds(250);
222 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_interval = std::chrono::milliseconds(33);
223 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_interval = std::chrono::milliseconds(1000);
224 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_delay = std::chrono::milliseconds(1000);
225 static inline extent2 _minimum_window_size = extent2{40.0f, 25.0f};
226 static inline extent2 _maximum_window_size = extent2{1920.0f, 1080.0f};
227 static inline std::atomic<uintptr_t> _primary_monitor_id = 0;
228 static inline aarectangle _primary_monitor_rectangle = aarectangle{0.0, 0.0, 1920.0f, 1080.0f};
229 static inline aarectangle _desktop_rectangle = aarectangle{0.0, 0.0, 1920.0f, 1080.0f};
230
235 static bool start_subsystem() noexcept
236 {
237 return hi::start_subsystem(_started, false, subsystem_init, subsystem_deinit);
238 }
239
240 [[nodiscard]] static bool subsystem_init() noexcept;
241 static void subsystem_deinit() noexcept;
242
243 [[nodiscard]] static std::vector<language_tag> gather_languages();
244 [[nodiscard]] static hi::theme_mode gather_theme_mode();
245 [[nodiscard]] static hi::subpixel_orientation gather_subpixel_orientation();
246 [[nodiscard]] static bool gather_uniform_HDR();
247 [[nodiscard]] static std::chrono::milliseconds gather_double_click_interval();
248 [[nodiscard]] static float gather_double_click_distance();
249 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_delay();
250 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_interval();
251 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_interval();
252 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_delay();
253 [[nodiscard]] static extent2 gather_minimum_window_size();
254 [[nodiscard]] static extent2 gather_maximum_window_size();
255 [[nodiscard]] static uintptr_t gather_primary_monitor_id();
256 [[nodiscard]] static aarectangle gather_primary_monitor_rectangle();
257 [[nodiscard]] static aarectangle gather_desktop_rectangle();
258};
259
260} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition required.hpp:29
STL namespace.
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:102
static aarectangle primary_monitor_rectangle() noexcept
Get the rectangle of the primary monitor.
Definition os_settings.hpp:161
static std::chrono::milliseconds keyboard_repeat_interval() noexcept
Get the keyboard repeat interval.
Definition os_settings.hpp:112
static extent2 maximum_window_size() noexcept
Get the maximum window size supported by the operating system.
Definition os_settings.hpp:150
static extent2 minimum_window_size() noexcept
Get the minimum window size supported by the operating system.
Definition os_settings.hpp:141
static std::vector< language * > languages() noexcept
Get the configured languages.
Definition os_settings.hpp:43
static hi::subpixel_orientation subpixel_orientation() noexcept
Get the configured light/dark theme mode.
Definition os_settings.hpp:60
static std::chrono::milliseconds cursor_blink_delay() noexcept
Get the cursor blink delay.
Definition os_settings.hpp:122
static aarectangle desktop_rectangle() noexcept
Get the rectangle describing the desktop.
Definition os_settings.hpp:180
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:92
static uintptr_t primary_monitor_id() noexcept
Get an opaque id of the primary monitor.
Definition os_settings.hpp:170
static std::chrono::milliseconds double_click_interval() noexcept
Get the mouse double click interval.
Definition os_settings.hpp:84
static bool uniform_HDR() noexcept
Whether SDR and HDR application can coexists on the same display.
Definition os_settings.hpp:76
static std::vector< language_tag > language_tags() noexcept
Get the language tags for the configured languages.
Definition os_settings.hpp:31
static hi::theme_mode theme_mode() noexcept
Get the configured light/dark theme mode.
Definition os_settings.hpp:52
static std::chrono::milliseconds cursor_blink_interval() noexcept
Get the cursor blink interval.
Definition os_settings.hpp:133