AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
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_ANDROID
36#elif AUI_PLATFORM_LINUX
37 Pipe mNotifyPipe;
38 std::atomic_bool mFastPathNotify = false;
39 std::string mXClipboardText;
40
41 void xProcessEvent(XEvent& ev);
42 void xClipboardCopyImpl(const AString& text);
43 AString xClipboardPasteImpl();
44#endif
45
46public:
48 ~AWindowManager() override;
49
50 AWatchdog& watchdog() noexcept {
51 return mWatchdog;
52 }
53
54 void removeAllWindows() {
55 auto windows = std::move(mWindows); // keeping it safe
56 windows.clear();
57 }
58
59 void closeAllWindows();
60 void notifyProcessMessages() override;
61 void loop() override;
62
63 const ADeque<_<AWindow>>& getWindows() const {
64 return mWindows;
65 }
66
67 void start() {
68 mLoopRunning = true;
69 }
70 void stop() {
71 mLoopRunning = false;
73 }
74
75 virtual void initNativeWindow(const IRenderingContext::Init& init);
76
77 template<typename T>
78 [[nodiscard]] ADeque<_<T>> getWindowsOfType() const {
79 ADeque<_<T>> result;
80 for (auto& w : mWindows) {
81 if (auto c = _cast<T>(w)) {
82 result << c;
83 }
84 }
85
86 return std::move(result);
87 }
88};
Definition: AClipboard.h:21
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
Definition: AWindowManager.h:23
Represents a window in the underlying windowing system.
Definition: AWindow.h:45
Definition: IEventLoop.h:33
Definition: IEventLoop.h:17
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:177
Definition: IRenderingContext.h:38
Definition: Text.h:21