Drop WaylandServer initialization flags

These flags affect kwin in general so WaylandServer is not the best place
for them to live in. For such things, we typically add properties in the
Application object, which is what this change does.
This commit is contained in:
Vlad Zahorodnii 2024-06-03 18:54:08 +03:00
parent c6ac6d3caa
commit 944be3d55a
10 changed files with 63 additions and 61 deletions

View file

@ -80,7 +80,8 @@ void NoGlobalShortcutsTest::initTestCase()
{
qRegisterMetaType<KWin::ElectricBorder>("ElectricBorder");
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
QVERIFY(waylandServer()->init(s_socketName, KWin::WaylandServer::InitializationFlag::NoGlobalShortcuts));
kwinApp()->setSupportsGlobalShortcuts(false);
QVERIFY(waylandServer()->init(s_socketName));
Test::setOutputConfig({
QRect(0, 0, 1280, 1024),
QRect(1280, 0, 1280, 1024),

View file

@ -2916,7 +2916,6 @@ private:
void InputRedirection::setupInputFilters()
{
const bool hasGlobalShortcutSupport = waylandServer()->hasGlobalShortcutSupport();
if (kwinApp()->session()->capabilities() & Session::Capability::SwitchTerminal) {
m_virtualTerminalFilter = std::make_unique<VirtualTerminalFilter>();
installInputEventFilter(m_virtualTerminalFilter.get());
@ -2934,7 +2933,7 @@ void InputRedirection::setupInputFilters()
m_lockscreenFilter = std::make_unique<LockScreenFilter>();
installInputEventFilter(m_lockscreenFilter.get());
if (hasGlobalShortcutSupport) {
if (kwinApp()->supportsGlobalShortcuts()) {
m_screenEdgeFilter = std::make_unique<ScreenEdgeInputFilter>();
installInputEventFilter(m_screenEdgeFilter.get());
}
@ -2950,7 +2949,7 @@ void InputRedirection::setupInputFilters()
installInputEventFilter(m_tabboxFilter.get());
#endif
#if KWIN_BUILD_GLOBALSHORTCUTS
if (hasGlobalShortcutSupport) {
if (kwinApp()->supportsGlobalShortcuts()) {
m_globalShortcutFilter = std::make_unique<GlobalShortcutFilter>();
installInputEventFilter(m_globalShortcutFilter.get());
}

View file

@ -154,7 +154,7 @@ void KeyboardInputRedirection::init()
update();
});
#if KWIN_BUILD_SCREENLOCKER
if (waylandServer()->hasScreenLockerIntegration()) {
if (kwinApp()->supportsLockScreen()) {
connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this, &KeyboardInputRedirection::update);
}
#endif

View file

@ -272,6 +272,15 @@ public:
return m_terminating;
}
bool initiallyLocked() const;
void setInitiallyLocked(bool locked);
bool supportsLockScreen() const;
void setSupportsLockScreen(bool set);
bool supportsGlobalShortcuts() const;
void setSupportsGlobalShortcuts(bool set);
void installNativeX11EventFilter();
void removeNativeX11EventFilter();
@ -386,6 +395,9 @@ private:
#endif
bool m_followLocale1 = false;
bool m_configLock;
bool m_initiallyLocked = false;
bool m_supportsLockScreen = true;
bool m_supportsGlobalShortcuts = true;
KSharedConfigPtr m_config;
KSharedConfigPtr m_kxkbConfig;
KSharedConfigPtr m_inputConfig;
@ -414,6 +426,36 @@ private:
std::unique_ptr<Cursor> m_platformCursor;
};
inline bool Application::initiallyLocked() const
{
return m_initiallyLocked;
}
inline void Application::setInitiallyLocked(bool locked)
{
m_initiallyLocked = locked;
}
inline bool Application::supportsLockScreen() const
{
return m_supportsLockScreen;
}
inline void Application::setSupportsLockScreen(bool set)
{
m_supportsLockScreen = set;
}
inline bool Application::supportsGlobalShortcuts() const
{
return m_supportsGlobalShortcuts;
}
inline void Application::setSupportsGlobalShortcuts(bool set)
{
m_supportsGlobalShortcuts = set;
}
inline static Application *kwinApp()
{
Q_ASSERT(qobject_cast<Application *>(QCoreApplication::instance()));

View file

@ -555,16 +555,15 @@ int main(int argc, char *argv[])
}
KWin::WaylandServer *server = KWin::WaylandServer::create();
KWin::WaylandServer::InitializationFlags flags;
#if KWIN_BUILD_SCREENLOCKER
if (parser.isSet(screenLockerOption)) {
flags = KWin::WaylandServer::InitializationFlag::LockScreen;
a.setInitiallyLocked(true);
} else if (parser.isSet(noScreenLockerOption)) {
flags = KWin::WaylandServer::InitializationFlag::NoLockScreenIntegration;
a.setSupportsLockScreen(false);
}
#endif
if (parser.isSet(noGlobalShortcutsOption)) {
flags |= KWin::WaylandServer::InitializationFlag::NoGlobalShortcuts;
a.setSupportsGlobalShortcuts(false);
}
const QString socketName = parser.value(waylandSocketOption);
@ -588,7 +587,7 @@ int main(int argc, char *argv[])
qInfo() << "Accepting client connections on sockets:" << server->display()->socketNames();
}
if (!server->init(flags)) {
if (!server->init()) {
std::cerr << "FATAL ERROR: could not create Wayland server" << std::endl;
return 1;
}

View file

@ -110,7 +110,7 @@ void PointerInputRedirection::init()
connect(workspace(), &Workspace::outputsChanged, this, &PointerInputRedirection::updateAfterScreenChange);
#if KWIN_BUILD_SCREENLOCKER
if (waylandServer()->hasScreenLockerIntegration()) {
if (kwinApp()->supportsLockScreen()) {
connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this, [this]() {
if (waylandServer()->seat()->hasPointer()) {
waylandServer()->seat()->cancelPointerPinchGesture();
@ -963,7 +963,7 @@ CursorImage::CursorImage(PointerInputRedirection *parent)
m_serverCursor.shape = std::make_unique<ShapeCursorSource>();
#if KWIN_BUILD_SCREENLOCKER
if (waylandServer()->hasScreenLockerIntegration()) {
if (kwinApp()->supportsLockScreen()) {
connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this, &CursorImage::reevaluteSource);
}
#endif

View file

@ -7,7 +7,6 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "screenlockerwatcher.h"
#include "wayland_server.h"
// dbus generated
#include "kscreenlocker_interface.h"
@ -22,11 +21,7 @@ ScreenLockerWatcher::ScreenLockerWatcher()
: m_serviceWatcher(new QDBusServiceWatcher(this))
, m_locked(false)
{
if (waylandServer() && waylandServer()->hasScreenLockerIntegration()) {
connect(waylandServer(), &WaylandServer::initialized, this, &ScreenLockerWatcher::initialize);
} else {
initialize();
}
initialize();
}
void ScreenLockerWatcher::initialize()

View file

@ -49,7 +49,7 @@ void TouchInputRedirection::init()
InputDeviceHandler::init();
#if KWIN_BUILD_SCREENLOCKER
if (waylandServer()->hasScreenLockerIntegration()) {
if (kwinApp()->supportsLockScreen()) {
connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this, [this]() {
cancel();
// position doesn't matter

View file

@ -305,17 +305,16 @@ bool WaylandServer::start()
return m_display->start();
}
bool WaylandServer::init(const QString &socketName, InitializationFlags flags)
bool WaylandServer::init(const QString &socketName)
{
if (!m_display->addSocketName(socketName)) {
return false;
}
return init(flags);
return init();
}
bool WaylandServer::init(InitializationFlags flags)
bool WaylandServer::init()
{
m_initFlags = flags;
m_compositor = new CompositorInterface(m_display, m_display);
#if KWIN_BUILD_X11
connect(m_compositor, &CompositorInterface::surfaceCreated, this, [this](SurfaceInterface *surface) {
@ -600,7 +599,7 @@ void WaylandServer::initWorkspace()
connect(workspace(), &Workspace::outputAdded, this, &WaylandServer::handleOutputEnabled);
connect(workspace(), &Workspace::outputRemoved, this, &WaylandServer::handleOutputDisabled);
if (hasScreenLockerIntegration()) {
if (kwinApp()->supportsLockScreen()) {
initScreenLocker();
}
@ -666,7 +665,7 @@ void WaylandServer::initScreenLocker()
ScreenLocker::KSldApp::self()->initialize();
if (m_initFlags.testFlag(InitializationFlag::LockScreen)) {
if (kwinApp()->initiallyLocked()) {
ScreenLocker::KSldApp::self()->lock(ScreenLocker::EstablishLock::Immediate);
}
#endif
@ -787,7 +786,7 @@ XdgSurfaceWindow *WaylandServer::findXdgSurfaceWindow(SurfaceInterface *surface)
bool WaylandServer::isScreenLocked() const
{
#if KWIN_BUILD_SCREENLOCKER
if (!hasScreenLockerIntegration()) {
if (!kwinApp()->supportsLockScreen()) {
return false;
}
return ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::Locked || ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::AcquiringLock;
@ -796,20 +795,6 @@ bool WaylandServer::isScreenLocked() const
#endif
}
bool WaylandServer::hasScreenLockerIntegration() const
{
#if KWIN_BUILD_SCREENLOCKER
return !m_initFlags.testFlag(InitializationFlag::NoLockScreenIntegration);
#else
return false;
#endif
}
bool WaylandServer::hasGlobalShortcutSupport() const
{
return !m_initFlags.testFlag(InitializationFlag::NoGlobalShortcuts);
}
bool WaylandServer::isKeyboardShortcutsInhibited() const
{
auto surface = seat()->focusedKeyboardSurface();

View file

@ -68,18 +68,9 @@ class KWIN_EXPORT WaylandServer : public QObject
Q_OBJECT
public:
enum class InitializationFlag {
NoOptions = 0x0,
LockScreen = 0x1,
NoLockScreenIntegration = 0x2,
NoGlobalShortcuts = 0x4
};
Q_DECLARE_FLAGS(InitializationFlags, InitializationFlag)
~WaylandServer() override;
bool init(const QString &socketName, InitializationFlags flags = InitializationFlag::NoOptions);
bool init(InitializationFlags flags = InitializationFlag::NoOptions);
bool init(const QString &socketName);
bool init();
bool start();
@ -184,15 +175,6 @@ public:
* @returns true if screen is locked.
*/
bool isScreenLocked() const;
/**
* @returns whether integration with KScreenLocker is available.
*/
bool hasScreenLockerIntegration() const;
/**
* @returns whether any kind of global shortcuts are supported.
*/
bool hasGlobalShortcutSupport() const;
void initWorkspace();
@ -300,7 +282,6 @@ private:
PresentationTime *m_presentationTime = nullptr;
LinuxDrmSyncObjV1Interface *m_linuxDrmSyncObj = nullptr;
QList<Window *> m_windows;
InitializationFlags m_initFlags;
QHash<Output *, OutputInterface *> m_waylandOutputs;
QHash<Output *, OutputDeviceV2Interface *> m_waylandOutputDevices;
DrmLeaseManagerV1 *m_leaseManager = nullptr;