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:
28 [[nodiscard]] static std::vector<language_tag> language_tags() noexcept
29 {
30 start_subsystem();
31 hilet lock = std::scoped_lock(_mutex);
32 return _language_tags;
33 }
34
40 [[nodiscard]] static std::vector<language *> languages() noexcept
41 {
42 start_subsystem();
43 hilet lock = std::scoped_lock(_mutex);
44 return _languages;
45 }
46
49 [[nodiscard]] static hi::theme_mode theme_mode() noexcept
50 {
51 start_subsystem();
52 return _theme_mode.load(std::memory_order_relaxed);
53 }
54
57 [[nodiscard]] static hi::subpixel_orientation subpixel_orientation() noexcept
58 {
59 start_subsystem();
60 return _subpixel_orientation.load(std::memory_order_relaxed);
61 }
62
65 [[nodiscard]] static std::chrono::milliseconds double_click_interval() noexcept
66 {
67 start_subsystem();
68 return _double_click_interval.load(std::memory_order_relaxed);
69 }
70
73 [[nodiscard]] static float double_click_distance() noexcept
74 {
75 start_subsystem();
76 return _double_click_distance.load(std::memory_order_relaxed);
77 }
78
83 [[nodiscard]] static std::chrono::milliseconds keyboard_repeat_delay() noexcept
84 {
85 start_subsystem();
86 return _keyboard_repeat_delay.load(std::memory_order_relaxed);
87 }
88
94 {
95 start_subsystem();
96 return _keyboard_repeat_interval.load(std::memory_order_relaxed);
97 }
98
103 [[nodiscard]] static std::chrono::milliseconds cursor_blink_delay() noexcept
104 {
105 start_subsystem();
106 return _cursor_blink_delay.load(std::memory_order_relaxed);
107 }
108
114 [[nodiscard]] static std::chrono::milliseconds cursor_blink_interval() noexcept
115 {
116 start_subsystem();
117 return _cursor_blink_interval.load(std::memory_order_relaxed);
118 }
119
122 [[nodiscard]] static extent2 minimum_window_size() noexcept
123 {
124 start_subsystem();
125 hilet lock = std::scoped_lock(_mutex);
126 return _minimum_window_size;
127 }
128
131 [[nodiscard]] static extent2 maximum_window_size() noexcept
132 {
133 start_subsystem();
134 hilet lock = std::scoped_lock(_mutex);
135 return _maximum_window_size;
136 }
137
142 [[nodiscard]] static aarectangle primary_monitor_rectangle() noexcept
143 {
144 start_subsystem();
145 hilet lock = std::scoped_lock(_mutex);
146 return _primary_monitor_rectangle;
147 }
148
151 [[nodiscard]] static uintptr_t primary_monitor_id() noexcept
152 {
153 hi_axiom(_started);
154 return _primary_monitor_id.load(std::memory_order::relaxed);
155 }
156
161 [[nodiscard]] static aarectangle desktop_rectangle() noexcept
162 {
163 start_subsystem();
164 hilet lock = std::scoped_lock(_mutex);
165 return _desktop_rectangle;
166 }
167
170 static void gather() noexcept;
171
172 [[nodiscard]] static auto subscribe(std::invocable<> auto &&callback) noexcept
173 {
174 start_subsystem();
175 hilet lock = std::scoped_lock(_mutex);
176 return _notifier.subscribe(hi_forward(callback));
177 }
178
179private:
180 static constexpr std::chrono::duration gather_interval = std::chrono::seconds(5);
181 static constexpr std::chrono::duration gather_minimum_interval = std::chrono::seconds(1);
182
183 static inline std::atomic<bool> _started = false;
184 static inline unfair_mutex _mutex;
185 static inline loop::timer_token_type _gather_cbt;
186 static inline utc_nanoseconds _gather_last_time;
187
188 static inline notifier<void()> _notifier;
189
190 static inline std::vector<language_tag> _language_tags = {};
191 static inline std::vector<language *> _languages = {};
192 static inline std::atomic<hi::theme_mode> _theme_mode = theme_mode::dark;
193 static inline std::atomic<hi::subpixel_orientation> _subpixel_orientation = hi::subpixel_orientation::unknown;
194 static inline std::atomic<std::chrono::milliseconds> _double_click_interval = std::chrono::milliseconds(500);
195 static inline std::atomic<float> _double_click_distance = 4.0f;
196 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_delay = std::chrono::milliseconds(250);
197 static inline std::atomic<std::chrono::milliseconds> _keyboard_repeat_interval = std::chrono::milliseconds(33);
198 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_interval = std::chrono::milliseconds(1000);
199 static inline std::atomic<std::chrono::milliseconds> _cursor_blink_delay = std::chrono::milliseconds(1000);
200 static inline extent2 _minimum_window_size = extent2{40.0f, 25.0f};
201 static inline extent2 _maximum_window_size = extent2{1920.0f, 1080.0f};
202 static inline std::atomic<uintptr_t> _primary_monitor_id = 0;
203 static inline aarectangle _primary_monitor_rectangle = aarectangle{0.0, 0.0, 1920.0f, 1080.0f};
204 static inline aarectangle _desktop_rectangle = aarectangle{0.0, 0.0, 1920.0f, 1080.0f};
205
210 static bool start_subsystem() noexcept
211 {
212 return hi::start_subsystem(_started, false, subsystem_init, subsystem_deinit);
213 }
214
215 [[nodiscard]] static bool subsystem_init() noexcept;
216 static void subsystem_deinit() noexcept;
217
218 [[nodiscard]] static std::vector<language_tag> gather_languages();
219 [[nodiscard]] static hi::theme_mode gather_theme_mode();
220 [[nodiscard]] static hi::subpixel_orientation gather_subpixel_orientation();
221 [[nodiscard]] static std::chrono::milliseconds gather_double_click_interval();
222 [[nodiscard]] static float gather_double_click_distance();
223 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_delay();
224 [[nodiscard]] static std::chrono::milliseconds gather_keyboard_repeat_interval();
225 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_interval();
226 [[nodiscard]] static std::chrono::milliseconds gather_cursor_blink_delay();
227 [[nodiscard]] static extent2 gather_minimum_window_size();
228 [[nodiscard]] static extent2 gather_maximum_window_size();
229 [[nodiscard]] static uintptr_t gather_primary_monitor_id();
230 [[nodiscard]] static aarectangle gather_primary_monitor_rectangle();
231 [[nodiscard]] static aarectangle gather_desktop_rectangle();
232};
233
234} // 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:23
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:83
static aarectangle primary_monitor_rectangle() noexcept
Get the rectangle of the primary monitor.
Definition os_settings.hpp:142
static std::chrono::milliseconds keyboard_repeat_interval() noexcept
Get the keyboard repeat interval.
Definition os_settings.hpp:93
static extent2 maximum_window_size() noexcept
Get the maximum window size supported by the operating system.
Definition os_settings.hpp:131
static extent2 minimum_window_size() noexcept
Get the minimum window size supported by the operating system.
Definition os_settings.hpp:122
static std::vector< language * > languages() noexcept
Get the configured languages.
Definition os_settings.hpp:40
static hi::subpixel_orientation subpixel_orientation() noexcept
Get the configured light/dark theme mode.
Definition os_settings.hpp:57
static std::chrono::milliseconds cursor_blink_delay() noexcept
Get the cursor blink delay.
Definition os_settings.hpp:103
static aarectangle desktop_rectangle() noexcept
Get the rectangle describing the desktop.
Definition os_settings.hpp:161
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:73
static uintptr_t primary_monitor_id() noexcept
Get an opaque id of the primary monitor.
Definition os_settings.hpp:151
static std::chrono::milliseconds double_click_interval() noexcept
Get the mouse double click interval.
Definition os_settings.hpp:65
static std::vector< language_tag > language_tags() noexcept
Get the language tags for the configured languages.
Definition os_settings.hpp:28
static hi::theme_mode theme_mode() noexcept
Get the configured light/dark theme mode.
Definition os_settings.hpp:49
static std::chrono::milliseconds cursor_blink_interval() noexcept
Get the cursor blink interval.
Definition os_settings.hpp:114