Deskflow 1.26.0.207
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
App.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2026 Deskflow Developers
4 * SPDX-FileCopyrightText: (C) 2012 - 2026 Symless Ltd.
5 * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
6 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
7 */
8
9#pragma once
10
11#include "base/EventQueue.h"
12#include "base/Log.h"
13#include "common/ExitCodes.h"
14#include "deskflow/IApp.h"
16
17#if defined(Q_OS_WIN)
19#else
21#endif
22
23#include <QObject>
24#include <QThread>
25
26#include <memory>
27#include <stdexcept>
28
29namespace deskflow {
30class Screen;
31}
32
34class IEventQueue;
36
37class App : public QObject, private IApp
38{
39public:
40 class XNoEiSupport : public std::runtime_error
41 {
42 public:
43 XNoEiSupport() : std::runtime_error("libei is not supported")
44 {
45 // do nothing
46 }
47 };
48
49 explicit App(IEventQueue *events, const QString &processName);
50 App(App const &) = delete;
51 App(App &&) = delete;
52 ~App() override;
53
54 App &operator=(App const &) = delete;
55 App &operator=(App &&) = delete;
56
57 virtual void parseArgs() = 0;
58 virtual void loadConfig() = 0;
59 virtual bool loadConfig(const QString &filename) = 0;
60
61 void setByeFunc(void (*bye)(int)) override
62 {
63 m_bye = bye;
64 }
65 void bye(int error) override
66 {
67 m_bye(error);
68 }
69 IEventQueue *getEvents() const override
70 {
71 return m_events;
72 }
73
75 {
76 return m_appUtil;
77 }
78
79 void run(QThread &coreThread);
80 void quit() const;
81 void setupFileLogging();
82 void loggingFilterWarning() const;
83 void initApp() override;
84
85 void setEvents(EventQueue &events)
86 {
87 m_events = &events;
88 }
89 void setSocketMultiplexer(std::unique_ptr<SocketMultiplexer> &&sm)
90 {
91 m_socketMultiplexer = std::move(sm);
92 }
93
95 {
96 return m_socketMultiplexer.get();
97 }
98
99 static App &instance()
100 {
101 assert(s_instance != nullptr);
102 return *s_instance;
103 }
104
105 QString processName() const
106 {
107 return m_pname;
108 }
109
110 void handleScreenError() const;
111
112 void updateExitCode(int errorCode)
113 {
114 m_exitCode = errorCode;
115 }
116
117 int getExitCode() const
118 {
119 return m_exitCode;
120 }
121
122protected:
123 void runEventsLoop(const void *);
124
126 {
128 explicit LoopErrorCode(int errorCode) : m_errorCode(errorCode)
129 {
130 }
131 };
132
133private:
134 void (*m_bye)(int);
135 IEventQueue *m_events = nullptr;
136 static App *s_instance;
137 FileLogOutputter *m_fileLog = nullptr;
138 ARCH_APP_UTIL m_appUtil;
139 std::unique_ptr<SocketMultiplexer> m_socketMultiplexer;
140 QString m_pname;
141 int m_exitCode = s_exitSuccess;
142};
143
144#if !defined(WINAPI_LIBEI) && WINAPI_XWINDOWS
145constexpr static auto s_helpNoWayland = //
146 "\nYour Linux distribution does not support Wayland EI (emulated input)\n"
147 "which is required for Wayland support. Please use a Linux distribution\n"
148 "that supports Wayland EI.\n";
149
150#else
151constexpr static auto s_helpNoWayland = "";
152#endif
#define ARCH_APP_UTIL
Definition AppUtilUnix.h:12
static constexpr auto s_helpNoWayland
Definition App.h:151
static int(PASCAL FAR *bind_winsock)(SOCKET s
static const int s_exitSuccess
App successfully completed.
Definition ExitCodes.h:11
XNoEiSupport()
Definition App.h:43
Definition App.h:38
void updateExitCode(int errorCode)
Definition App.h:112
IEventQueue * getEvents() const override
Definition App.h:69
virtual void loadConfig()=0
static App & instance()
Definition App.h:99
virtual bool loadConfig(const QString &filename)=0
App(App const &)=delete
SocketMultiplexer * getSocketMultiplexer() const
Definition App.h:94
App & operator=(App &&)=delete
void loggingFilterWarning() const
Definition App.cpp:134
App(IEventQueue *events, const QString &processName)
Definition App.cpp:41
void setupFileLogging()
Definition App.cpp:124
void setByeFunc(void(*bye)(int)) override
Definition App.h:61
void initApp() override
Definition App.cpp:144
int getExitCode() const
Definition App.h:117
void quit() const
Definition App.cpp:171
void run(QThread &coreThread)
Definition App.cpp:59
QString processName() const
Definition App.h:105
App(App &&)=delete
ARCH_APP_UTIL & appUtil()
Definition App.h:74
void runEventsLoop(const void *)
Definition App.cpp:177
virtual void parseArgs()=0
void bye(int error) override
Definition App.h:65
App & operator=(App const &)=delete
void setEvents(EventQueue &events)
Definition App.h:85
~App() override
Definition App.cpp:54
void setSocketMultiplexer(std::unique_ptr< SocketMultiplexer > &&sm)
Definition App.h:89
void handleScreenError() const
Definition App.cpp:165
Event queue.
Definition EventQueue.h:28
Write log to file.
Definition LogOutputters.h:57
Definition IApp.h:20
Event queue interface.
Definition IEventQueue.h:29
Socket multiplexer.
Definition SocketMultiplexer.h:24
Platform independent screen.
Definition Screen.h:30
Definition DaemonApp.h:18
Definition Config.h:29
int m_errorCode
Definition App.h:127
LoopErrorCode(int errorCode)
Definition App.h:128