Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions como/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ add_library(base-wl SHARED)
target_link_libraries(base-wl
PUBLIC
KF6::Service
PW::KScreenLocker
WraplandServer
base
)
Expand All @@ -149,8 +148,8 @@ target_sources(base-wl
wayland/output_transform.h
wayland/platform.h
wayland/platform_helpers.h
wayland/screen_lock.h
wayland/server.h
wayland/server_helpers.h
wayland/xwl_platform.h
PRIVATE
wayland/filtered_display.cpp
Expand Down
20 changes: 0 additions & 20 deletions como/base/wayland/screen_lock.h

This file was deleted.

132 changes: 3 additions & 129 deletions como/base/wayland/server.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
SPDX-FileCopyrightText: 2015 Martin Gräßlin <[email protected]>
SPDX-FileCopyrightText: 2021 Roman Gilg <[email protected]>

SPDX-FileCopyrightText: 2024 Roman Gilg <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
Expand All @@ -12,8 +11,8 @@
#include "como_export.h"
#include <como/base/logging.h>
#include <como/base/wayland/platform_helpers.h>
#include <como/base/wayland/server_helpers.h>

#include <KScreenLocker/KsldApp>
#include <QObject>
#include <QThread>
#include <Wrapland/Server/client.h>
Expand Down Expand Up @@ -42,9 +41,6 @@ namespace como::base::wayland

class COMO_EXPORT server_qobject : public QObject
{
Q_OBJECT
Q_SIGNALS:
void screenlocker_initialized();
};

template<typename Base>
Expand Down Expand Up @@ -79,7 +75,7 @@ class server
*/
int create_xwayland_connection()
{
const auto socket = create_connection();
auto const socket = server_create_connection(*display);
if (!socket.connection) {
return -1;
}
Expand All @@ -101,23 +97,6 @@ class server
m_xwayland.client = nullptr;
}

bool is_screen_locked() const
{
if (!has_screen_locker_integration()) {
return false;
}
return ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::Locked
|| ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::AcquiringLock;
}

/**
* @returns whether integration with KScreenLocker is available.
*/
bool has_screen_locker_integration() const
{
return flags(m_initFlags & start_options::lock_screen_integration);
}

/**
* @returns whether any kind of global shortcuts are supported.
*/
Expand All @@ -131,95 +110,6 @@ class server
return m_xwayland.client;
}

/**
* Struct containing information for a created Wayland connection through a
* socketpair.
*/
struct socket_pair_connection {
/**
* ServerSide Connection
*/
Wrapland::Server::Client* connection = nullptr;
/**
* client-side file descriptor for the socket
*/
int fd = -1;
};
/**
* Creates a Wayland connection using a socket pair.
*/
socket_pair_connection create_connection()
{
socket_pair_connection ret;
int sx[2];
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sx) < 0) {
qCWarning(KWIN_CORE) << "Could not create socket";
return ret;
}
ret.connection = display->createClient(sx[0]);
ret.fd = sx[1];
return ret;
}

void init_screen_locker()
{
if (!has_screen_locker_integration()) {
return;
}

auto* screenLockerApp = ScreenLocker::KSldApp::self();

ScreenLocker::KSldApp::self()->setGreeterEnvironment(base.process_environment);
ScreenLocker::KSldApp::self()->initialize();

QObject::connect(ScreenLocker::KSldApp::self(),
&ScreenLocker::KSldApp::aboutToLock,
qobject.get(),
[this, screenLockerApp]() {
if (screen_locker_client_connection) {
// Already sent data to KScreenLocker.
return;
}
int clientFd = create_screen_locker_connection();
if (clientFd < 0) {
return;
}
ScreenLocker::KSldApp::self()->setWaylandFd(clientFd);

for (auto& seat : seats) {
QObject::connect(seat.get(),
&Wrapland::Server::Seat::timestampChanged,
screenLockerApp,
&ScreenLocker::KSldApp::userActivity);
}
});

QObject::connect(ScreenLocker::KSldApp::self(),
&ScreenLocker::KSldApp::unlocked,
qobject.get(),
[this, screenLockerApp]() {
if (screen_locker_client_connection) {
screen_locker_client_connection->destroy();
delete screen_locker_client_connection;
screen_locker_client_connection = nullptr;
}

for (auto& seat : seats) {
QObject::disconnect(seat.get(),
&Wrapland::Server::Seat::timestampChanged,
screenLockerApp,
&ScreenLocker::KSldApp::userActivity);
}
ScreenLocker::KSldApp::self()->setWaylandFd(-1);
});

if (flags(m_initFlags & start_options::lock_screen)) {
ScreenLocker::KSldApp::self()->lock(ScreenLocker::EstablishLock::Immediate);
}

Q_EMIT qobject->screenlocker_initialized();
}

std::unique_ptr<server_qobject> qobject;
std::unique_ptr<Wrapland::Server::Display> display;
std::unique_ptr<Wrapland::Server::output_manager> output_manager;
Expand All @@ -239,8 +129,6 @@ class server
std::unique_ptr<Wrapland::Server::RelativePointerManagerV1> relative_pointer_manager_v1;
std::unique_ptr<Wrapland::Server::security_context_manager_v1> security_context_manager_v1;

Wrapland::Server::Client* screen_locker_client_connection{nullptr};

private:
explicit server(Base& base, start_options flags)
: qobject{std::make_unique<server_qobject>()}
Expand Down Expand Up @@ -312,20 +200,6 @@ class server
= std::make_unique<Wrapland::Server::RelativePointerManagerV1>(display.get());
}

int create_screen_locker_connection()
{
const auto socket = create_connection();
if (!socket.connection) {
return -1;
}
screen_locker_client_connection = socket.connection;
QObject::connect(screen_locker_client_connection,
&Wrapland::Server::Client::disconnected,
qobject.get(),
[this] { screen_locker_client_connection = nullptr; });
return socket.fd;
}

struct {
Wrapland::Server::Client* client = nullptr;
QMetaObject::Connection destroyConnection;
Expand Down
36 changes: 36 additions & 0 deletions como/base/wayland/server_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
SPDX-FileCopyrightText: 2024 Roman Gilg <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once

#include <como/base/logging.h>

#include <Wrapland/Server/client.h>
#include <Wrapland/Server/display.h>
#include <sys/socket.h>

namespace como::base::wayland
{

struct socket_pair_connection {
Wrapland::Server::Client* connection{nullptr};
int fd = -1;
};

inline socket_pair_connection server_create_connection(Wrapland::Server::Display& display)
{
socket_pair_connection ret;
int sx[2];

if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sx) < 0) {
qCWarning(KWIN_CORE) << "Could not create socket";
return ret;
}

ret.connection = display.createClient(sx[0]);
ret.fd = sx[1];
return ret;
}

}
23 changes: 21 additions & 2 deletions como/desktop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ target_sources(desktop
FILE_SET HEADERS
FILES
platform.h
screen_locker.h
screen_locker_watcher.h
PRIVATE
screen_locker_watcher.cpp
Expand Down Expand Up @@ -60,7 +61,25 @@ target_sources(desktop-kde
${desktop_kde_dbus_src}
)

set_target_properties(desktop desktop-kde PROPERTIES
add_library(desktop-kde-wl SHARED)

target_link_libraries(desktop-kde-wl
PUBLIC
desktop-kde
PW::KScreenLocker
WraplandServer
)

target_sources(desktop-kde-wl
PUBLIC
FILE_SET HEADERS
FILES
kde/screen_locker.h
PRIVATE
kde/screen_locker.cpp
)

set_target_properties(desktop desktop-kde desktop-kde-wl PROPERTIES
VERSION ${CMAKE_PROJECT_VERSION}
SOVERSION ${CMAKE_PROJECT_VERSION_MAJOR}
PREFIX libcomo-
Expand Down Expand Up @@ -102,7 +121,7 @@ ecm_install_configured_files(
@ONLY DESTINATION ${KDE_INSTALL_SYSTEMDUSERUNITDIR}
)

install(TARGETS desktop desktop-kde
install(TARGETS desktop desktop-kde desktop-kde-wl
EXPORT como-export
LIBRARY NAMELINK_SKIP
FILE_SET HEADERS DESTINATION ${KDE_INSTALL_INCLUDEDIR}/como/desktop
Expand Down
37 changes: 37 additions & 0 deletions como/desktop/kde/screen_locker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
SPDX-FileCopyrightText: 2024 Roman Gilg <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "screen_locker.h"

#include <como/base/wayland/server_helpers.h>

namespace como::desktop::kde
{

bool screen_locker::is_locked() const
{
return ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::Locked
|| ScreenLocker::KSldApp::self()->lockState() == ScreenLocker::KSldApp::AcquiringLock;
}

Wrapland::Server::Client* screen_locker::get_client() const
{
return client;
}

int screen_locker::create_client(Wrapland::Server::Display& display)
{
auto const socket = base::wayland::server_create_connection(display);
if (!socket.connection) {
return -1;
}

client = socket.connection;
QObject::connect(
client, &Wrapland::Server::Client::disconnected, this, [this] { client = nullptr; });

return socket.fd;
}

}
Loading