AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AWindowManager.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13#include <AUI/Thread/IEventLoop.h>
14#include "AUI/Common/ATimer.h"
15#include "AUI/Platform/Pipe.h"
16#include "AUI/Util/AWatchdog.h"
17#include "IRenderingContext.h"
18
19class AWindow;
20typedef union _XEvent XEvent;
21
22
23class API_AUI_VIEWS AWindowManager: public IEventLoop {
24 friend class AWindow;
25 friend class AClipboard;
26private:
27 AWatchdog mWatchdog;
28 _<ATimer> mHangTimer;
29
30protected:
31 IEventLoop::Handle mHandle;
32 ADeque<_<AWindow>> mWindows;
33 bool mLoopRunning = false;
34
35#if AUI_PLATFORM_LINUX
36 Pipe mNotifyPipe;
37 std::atomic_bool mFastPathNotify = false;
38 std::string mXClipboardText;
39
40 void xProcessEvent(XEvent& ev);
41 void xClipboardCopyImpl(const AString& text);
42 AString xClipboardPasteImpl();
43#endif
44
45public:
46 AWindowManager();
47 ~AWindowManager() override;
48
49 AWatchdog& watchdog() noexcept {
50 return mWatchdog;
51 }
52
53 void removeAllWindows() {
54 auto windows = std::move(mWindows); // keeping it safe
55 windows.clear();
56 }
57
58 void closeAllWindows();
59 void notifyProcessMessages() override;
60 void loop() override;
61
62 const ADeque<_<AWindow>>& getWindows() const {
63 return mWindows;
64 }
65
66 void start() {
67 mLoopRunning = true;
68 }
69 void stop() {
70 mLoopRunning = false;
72 }
73
74 virtual void initNativeWindow(const IRenderingContext::Init& init);
75
76 template<typename T>
77 [[nodiscard]] ADeque<_<T>> getWindowsOfType() const {
78 ADeque<_<T>> result;
79 for (auto& w : mWindows) {
80 if (auto c = _cast<T>(w)) {
81 result << c;
82 }
83 }
84
85 return std::move(result);
86 }
87};
A std::deque with AUI extensions.
Definition ADeque.h:27
Represents a Unicode character string.
Definition AString.h:37
Watchdog helper class.
Definition AWatchdog.h:38
Represents a window in the underlying windowing system.
Definition AWindow.h:45
Definition IEventLoop.h:33
virtual void loop()=0
Do message processing loop.
virtual void notifyProcessMessages()=0
Notifies this IEventLoop that its thread got a new message to process.
Unix pipe RAII wrapper.
Definition Pipe.h:30
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
Definition IRenderingContext.h:38