Deskflow 1.26.0.134
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 "deskflow/IApp.h"
15
16#if defined(Q_OS_WIN)
18#else
20#endif
21
22#include <QObject>
23#include <QThread>
24
25#include <memory>
26#include <stdexcept>
27
28namespace deskflow {
29class Screen;
30}
31
33class IEventQueue;
35
36class App : public QObject, private IApp
37{
38public:
39 class XNoEiSupport : public std::runtime_error
40 {
41 public:
42 XNoEiSupport() : std::runtime_error("libei is not supported")
43 {
44 // do nothing
45 }
46 };
47
48 App(IEventQueue *events, const QString &processName);
49 App(App const &) = delete;
50 App(App &&) = delete;
51 ~App() override;
52
53 App &operator=(App const &) = delete;
54 App &operator=(App &&) = delete;
55
56 virtual void parseArgs() = 0;
57 virtual void loadConfig() = 0;
58 virtual bool loadConfig(const QString &filename) = 0;
59
60 void setByeFunc(void (*bye)(int)) override
61 {
62 m_bye = bye;
63 }
64 void bye(int error) override
65 {
66 m_bye(error);
67 }
68 IEventQueue *getEvents() const override
69 {
70 return m_events;
71 }
72
74 {
75 return m_appUtil;
76 }
77
78 void run(QThread &coreThread);
79 void setupFileLogging();
80 void loggingFilterWarning() const;
81 void initApp() override;
82
83 void setEvents(EventQueue &events)
84 {
85 m_events = &events;
86 }
87 void setSocketMultiplexer(std::unique_ptr<SocketMultiplexer> &&sm)
88 {
89 m_socketMultiplexer = std::move(sm);
90 }
91
93 {
94 return m_socketMultiplexer.get();
95 }
96
97 static App &instance()
98 {
99 assert(s_instance != nullptr);
100 return *s_instance;
101 }
102
103 QString processName() const
104 {
105 return m_pname;
106 }
107
108 void handleScreenError() const;
109
110protected:
111 void runEventsLoop(const void *);
112
113private:
114 void (*m_bye)(int);
115 IEventQueue *m_events = nullptr;
116 static App *s_instance;
117 FileLogOutputter *m_fileLog = nullptr;
118 ARCH_APP_UTIL m_appUtil;
119 std::unique_ptr<SocketMultiplexer> m_socketMultiplexer;
120 QString m_pname;
121};
122
123#if !defined(WINAPI_LIBEI) && WINAPI_XWINDOWS
124constexpr static auto s_helpNoWayland = //
125 "\nYour Linux distribution does not support Wayland EI (emulated input)\n"
126 "which is required for Wayland support. Please use a Linux distribution\n"
127 "that supports Wayland EI.\n";
128
129#else
130constexpr static auto s_helpNoWayland = "";
131#endif
#define ARCH_APP_UTIL
Definition AppUtilUnix.h:12
static constexpr auto s_helpNoWayland
Definition App.h:130
static int(PASCAL FAR *bind_winsock)(SOCKET s
XNoEiSupport()
Definition App.h:42
Definition App.h:37
IEventQueue * getEvents() const override
Definition App.h:68
virtual void loadConfig()=0
static App & instance()
Definition App.h:97
virtual bool loadConfig(const QString &filename)=0
App(App const &)=delete
SocketMultiplexer * getSocketMultiplexer() const
Definition App.h:92
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:60
void initApp() override
Definition App.cpp:144
void run(QThread &coreThread)
Definition App.cpp:59
QString processName() const
Definition App.h:103
App(App &&)=delete
ARCH_APP_UTIL & appUtil()
Definition App.h:73
void runEventsLoop(const void *)
Definition App.cpp:171
virtual void parseArgs()=0
void bye(int error) override
Definition App.h:64
App & operator=(App const &)=delete
void setEvents(EventQueue &events)
Definition App.h:83
~App() override
Definition App.cpp:54
void setSocketMultiplexer(std::unique_ptr< SocketMultiplexer > &&sm)
Definition App.h:87
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:20
Definition Config.h:28