core: begin using CFileDescriptor from hyprutils (#9122)

* config: make fd use CFileDescriptor

make use of the new hyprutils CFileDescriptor instead of manual FD
handling.

* hyprctl: make fd use CFileDescriptor

make use of the new hyprutils CFileDescriptor instead of manual FD
handling.

* ikeyboard: make fd use CFileDescriptor

make use of the new CFileDescriptor instead of manual FD handling, also
in sendKeymap remove dead code, it already early returns if keyboard
isnt valid, and dont try to close the FD that ikeyboard owns.

* core: make SHMFile functions use CFileDescriptor

make SHMFile misc functions use CFileDescriptor and its associated usage
in dmabuf and keyboard.

* core: make explicit sync use CFileDescriptor

begin using CFileDescriptor in explicit sync and its timelines and
eglsync usage in opengl, there is still a bit left with manual handling
that requires future aquamarine change aswell.

* eventmgr: make fd and sockets use CFileDescriptor

make use of the hyprutils CFileDescriptor instead of manual FD and
socket handling and closing.

* eventloopmgr: make timerfd use CFileDescriptor

make the timerfd use CFileDescriptor instead of manual fd handling

* opengl: make gbm fd use CFileDescriptor

make the gbm rendernode fd use CFileDescriptor instead of manual fd
handling

* core: make selection source/offer use CFileDescriptor

make data selection source and offers use CFileDescriptor and its
associated use in xwm and protocols

* protocols: convert protocols fd to CFileDescriptor

make most fd handling use CFileDescriptor in protocols

* shm: make SHMPool use CfileDescriptor

make SHMPool use CFileDescriptor instead of manual fd handling.

* opengl: duplicate fd with CFileDescriptor

duplicate fenceFD with CFileDescriptor duplicate instead.

* xwayland: make sockets and fds use CFileDescriptor

instead of manual opening/closing make sockets and fds use
CFileDescriptor

* keybindmgr: make sockets and fds use CFileDescriptor

make sockets and fds use CFileDescriptor instead of manual handling.
This commit is contained in:
Tom Englund 2025-01-30 12:30:12 +01:00 committed by GitHub
parent 7d1c78f4a3
commit 32c0fa2f2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
50 changed files with 422 additions and 526 deletions

View file

@ -7,6 +7,8 @@
#include "../managers/XWaylandManager.hpp"
#include "../desktop/WLSurface.hpp"
using namespace Hyprutils::OS;
#ifndef NO_XWAYLAND
static xcb_atom_t dndActionToAtom(uint32_t actions) {
if (actions & WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY)
@ -172,7 +174,7 @@ std::vector<std::string> CX11DataSource::mimes() {
return mimeTypes;
}
void CX11DataSource::send(const std::string& mime, uint32_t fd) {
void CX11DataSource::send(const std::string& mime, CFileDescriptor fd) {
;
}

View file

@ -2,6 +2,7 @@
#include "../protocols/types/DataDevice.hpp"
#include <wayland-server-protocol.h>
#include <hyprutils/os/FileDescriptor.hpp>
#define XDND_VERSION 5
@ -35,7 +36,7 @@ class CX11DataSource : public IDataSource {
~CX11DataSource() = default;
virtual std::vector<std::string> mimes();
virtual void send(const std::string& mime, uint32_t fd);
virtual void send(const std::string& mime, Hyprutils::OS::CFileDescriptor fd);
virtual void accepted(const std::string& mime);
virtual void cancelled();
virtual bool hasDnd();

View file

@ -24,70 +24,41 @@
#include "../defines.hpp"
#include "../Compositor.hpp"
#include "../managers/CursorManager.hpp"
using namespace Hyprutils::OS;
// Constants
constexpr int SOCKET_DIR_PERMISSIONS = 0755;
constexpr int SOCKET_BACKLOG = 1;
constexpr int MAX_SOCKET_RETRIES = 32;
constexpr int LOCK_FILE_MODE = 0444;
constexpr int SOCKET_DIR_PERMISSIONS = 0755;
constexpr int SOCKET_BACKLOG = 1;
constexpr int MAX_SOCKET_RETRIES = 32;
constexpr int LOCK_FILE_MODE = 0444;
static bool setCloseOnExec(int fd, bool cloexec) {
int flags = fcntl(fd, F_GETFD);
if (flags == -1) {
Debug::log(ERR, "fcntl failed");
return false;
}
if (cloexec)
flags = flags | FD_CLOEXEC;
else
flags = flags & ~FD_CLOEXEC;
if (fcntl(fd, F_SETFD, flags) == -1) {
Debug::log(ERR, "fcntl failed");
return false;
}
return true;
}
static void cleanUpSocket(int fd, const char* path) {
close(fd);
if (path[0])
unlink(path);
}
static inline void closeSocketSafely(int& fd) {
if (fd >= 0)
close(fd);
}
static int createSocket(struct sockaddr_un* addr, size_t path_size) {
socklen_t size = offsetof(struct sockaddr_un, sun_path) + path_size + 1;
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
static CFileDescriptor createSocket(struct sockaddr_un* addr, size_t path_size) {
socklen_t size = offsetof(struct sockaddr_un, sun_path) + path_size + 1;
CFileDescriptor fd{socket(AF_UNIX, SOCK_STREAM, 0)};
if (!fd.isValid()) {
Debug::log(ERR, "Failed to create socket {}{}", addr->sun_path[0] ? addr->sun_path[0] : '@', addr->sun_path + 1);
return -1;
return {};
}
if (!setCloseOnExec(fd, true)) {
close(fd);
return -1;
if (!fd.setFlags(fd.getFlags() | FD_CLOEXEC)) {
return {};
}
if (addr->sun_path[0])
unlink(addr->sun_path);
if (bind(fd, (struct sockaddr*)addr, size) < 0) {
if (bind(fd.get(), (struct sockaddr*)addr, size) < 0) {
Debug::log(ERR, "Failed to bind socket {}{}", addr->sun_path[0] ? addr->sun_path[0] : '@', addr->sun_path + 1);
cleanUpSocket(fd, addr->sun_path);
return -1;
if (addr->sun_path[0])
unlink(addr->sun_path);
return {};
}
if (listen(fd, SOCKET_BACKLOG) < 0) {
if (listen(fd.get(), SOCKET_BACKLOG) < 0) {
Debug::log(ERR, "Failed to listen to socket {}{}", addr->sun_path[0] ? addr->sun_path[0] : '@', addr->sun_path + 1);
cleanUpSocket(fd, addr->sun_path);
return -1;
if (addr->sun_path[0])
unlink(addr->sun_path);
return {};
}
return fd;
@ -141,7 +112,7 @@ static std::string getSocketPath(int display, bool isLinux) {
return std::format("/tmp/.X11-unix/X{}_", display);
}
static bool openSockets(std::array<int, 2>& sockets, int display) {
static bool openSockets(std::array<CFileDescriptor, 2>& sockets, int display) {
if (!ensureSocketDirExists())
return false;
@ -151,17 +122,16 @@ static bool openSockets(std::array<int, 2>& sockets, int display) {
path = getSocketPath(display, false);
strncpy(addr.sun_path, path.c_str(), path.length() + 1);
sockets[0] = createSocket(&addr, path.length());
if (sockets[0] < 0)
sockets[0] = CFileDescriptor{createSocket(&addr, path.length())};
if (!sockets[0].isValid())
return false;
path = getSocketPath(display, true);
strncpy(addr.sun_path, path.c_str(), path.length() + 1);
sockets[1] = createSocket(&addr, path.length());
if (sockets[1] < 0) {
close(sockets[0]);
sockets[0] = -1;
sockets[1] = CFileDescriptor{createSocket(&addr, path.length())};
if (!sockets[1].isValid()) {
sockets[0].reset();
return false;
}
@ -174,7 +144,8 @@ static void startServer(void* data) {
}
static int xwaylandReady(int fd, uint32_t mask, void* data) {
return g_pXWayland->pServer->ready(fd, mask);
CFileDescriptor xwlFd{fd};
return g_pXWayland->pServer->ready(std::move(xwlFd), mask);
}
static bool safeRemove(const std::string& path) {
@ -186,38 +157,34 @@ static bool safeRemove(const std::string& path) {
bool CXWaylandServer::tryOpenSockets() {
for (size_t i = 0; i <= MAX_SOCKET_RETRIES; ++i) {
std::string lockPath = std::format("/tmp/.X{}-lock", i);
std::string lockPath = std::format("/tmp/.X{}-lock", i);
int fd = open(lockPath.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, LOCK_FILE_MODE);
if (fd >= 0) {
CFileDescriptor fd{open(lockPath.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, LOCK_FILE_MODE)};
if (fd.isValid()) {
// we managed to open the lock
if (!openSockets(xFDs, i)) {
safeRemove(lockPath);
close(fd);
continue;
}
const std::string pidStr = std::to_string(getpid());
if (write(fd, pidStr.c_str(), pidStr.length()) != (long)pidStr.length()) {
if (write(fd.get(), pidStr.c_str(), pidStr.length()) != (long)pidStr.length()) {
safeRemove(lockPath);
close(fd);
continue;
}
close(fd);
display = i;
displayName = std::format(":{}", display);
break;
}
fd = open(lockPath.c_str(), O_RDONLY | O_CLOEXEC);
fd = CFileDescriptor{open(lockPath.c_str(), O_RDONLY | O_CLOEXEC)};
if (fd < 0)
if (!fd.isValid())
continue;
char pidstr[12] = {0};
read(fd, pidstr, sizeof(pidstr) - 1);
close(fd);
read(fd.get(), pidstr, sizeof(pidstr) - 1);
int32_t pid = 0;
try {
@ -249,9 +216,6 @@ CXWaylandServer::~CXWaylandServer() {
if (display < 0)
return;
closeSocketSafely(xFDs[0]);
closeSocketSafely(xFDs[1]);
std::string lockPath = std::format("/tmp/.X{}-lock", display);
safeRemove(lockPath);
@ -277,21 +241,11 @@ void CXWaylandServer::die() {
if (pipeSource)
wl_event_source_remove(pipeSource);
if (pipeFd >= 0)
close(pipeFd);
closeSocketSafely(waylandFDs[0]);
closeSocketSafely(waylandFDs[1]);
closeSocketSafely(xwmFDs[0]);
closeSocketSafely(xwmFDs[1]);
// possible crash. Better to leak a bit.
//if (xwaylandClient)
// wl_client_destroy(xwaylandClient);
xwaylandClient = nullptr;
waylandFDs = {-1, -1};
xwmFDs = {-1, -1};
}
bool CXWaylandServer::create() {
@ -307,15 +261,17 @@ bool CXWaylandServer::create() {
return true;
}
void CXWaylandServer::runXWayland(int notifyFD) {
if (!setCloseOnExec(xFDs[0], false) || !setCloseOnExec(xFDs[1], false) || !setCloseOnExec(waylandFDs[1], false) || !setCloseOnExec(xwmFDs[1], false)) {
void CXWaylandServer::runXWayland(CFileDescriptor& notifyFD) {
if (!xFDs[0].setFlags(xFDs[0].getFlags() & ~FD_CLOEXEC) || !xFDs[1].setFlags(xFDs[1].getFlags() & ~FD_CLOEXEC) ||
!waylandFDs[1].setFlags(waylandFDs[1].getFlags() & ~FD_CLOEXEC) || !xwmFDs[1].setFlags(xwmFDs[1].getFlags() & ~FD_CLOEXEC)) {
Debug::log(ERR, "Failed to unset cloexec on fds");
_exit(EXIT_FAILURE);
}
auto cmd = std::format("Xwayland {} -rootless -core -listenfd {} -listenfd {} -displayfd {} -wm {}", displayName, xFDs[0], xFDs[1], notifyFD, xwmFDs[1]);
auto cmd =
std::format("Xwayland {} -rootless -core -listenfd {} -listenfd {} -displayfd {} -wm {}", displayName, xFDs[0].get(), xFDs[1].get(), notifyFD.get(), xwmFDs[1].get());
auto waylandSocket = std::format("{}", waylandFDs[1]);
auto waylandSocket = std::format("{}", waylandFDs[1].get());
setenv("WAYLAND_SOCKET", waylandSocket.c_str(), true);
Debug::log(LOG, "Starting XWayland with \"{}\", bon voyage!", cmd);
@ -327,40 +283,46 @@ void CXWaylandServer::runXWayland(int notifyFD) {
}
bool CXWaylandServer::start() {
idleSource = nullptr;
if (socketpair(AF_UNIX, SOCK_STREAM, 0, waylandFDs.data()) != 0) {
idleSource = nullptr;
int wlPair[2] = {-1, -1};
if (socketpair(AF_UNIX, SOCK_STREAM, 0, wlPair) != 0) {
Debug::log(ERR, "socketpair failed (1)");
die();
return false;
}
waylandFDs[0] = CFileDescriptor{wlPair[0]};
waylandFDs[1] = CFileDescriptor{wlPair[1]};
if (!setCloseOnExec(waylandFDs[0], true) || !setCloseOnExec(waylandFDs[1], true)) {
if (!waylandFDs[0].setFlags(waylandFDs[0].getFlags() | FD_CLOEXEC) || !waylandFDs[1].setFlags(waylandFDs[1].getFlags() | FD_CLOEXEC)) {
Debug::log(ERR, "set_cloexec failed (1)");
die();
return false;
}
if (socketpair(AF_UNIX, SOCK_STREAM, 0, xwmFDs.data()) != 0) {
int xwmPair[2] = {-1, -1};
if (socketpair(AF_UNIX, SOCK_STREAM, 0, xwmPair) != 0) {
Debug::log(ERR, "socketpair failed (2)");
die();
return false;
}
if (!setCloseOnExec(xwmFDs[0], true) || !setCloseOnExec(xwmFDs[1], true)) {
xwmFDs[0] = CFileDescriptor{xwmPair[0]};
xwmFDs[1] = CFileDescriptor{xwmPair[1]};
if (!xwmFDs[0].setFlags(xwmFDs[0].getFlags() | FD_CLOEXEC) || !xwmFDs[1].setFlags(xwmFDs[1].getFlags() | FD_CLOEXEC)) {
Debug::log(ERR, "set_cloexec failed (2)");
die();
return false;
}
xwaylandClient = wl_client_create(g_pCompositor->m_sWLDisplay, waylandFDs[0]);
xwaylandClient = wl_client_create(g_pCompositor->m_sWLDisplay, waylandFDs[0].get());
if (!xwaylandClient) {
Debug::log(ERR, "wl_client_create failed");
die();
return false;
}
waylandFDs[0] = -1;
waylandFDs[0].take(); // does this leak?
int notify[2] = {-1, -1};
if (pipe(notify) < 0) {
@ -369,22 +331,20 @@ bool CXWaylandServer::start() {
return false;
}
if (!setCloseOnExec(notify[0], true)) {
CFileDescriptor notifyFds[2] = {CFileDescriptor{notify[0]}, CFileDescriptor{notify[1]}};
if (!notifyFds[0].setFlags(notifyFds[0].getFlags() | FD_CLOEXEC)) {
Debug::log(ERR, "set_cloexec failed (3)");
close(notify[0]);
close(notify[1]);
die();
return false;
}
pipeSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, notify[0], WL_EVENT_READABLE, ::xwaylandReady, nullptr);
pipeFd = notify[0];
pipeSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, notifyFds[0].get(), WL_EVENT_READABLE, ::xwaylandReady, nullptr);
pipeFd = std::move(notifyFds[0]);
serverPID = fork();
if (serverPID < 0) {
Debug::log(ERR, "fork failed");
close(notify[0]);
close(notify[1]);
die();
return false;
} else if (serverPID == 0) {
@ -393,25 +353,19 @@ bool CXWaylandServer::start() {
Debug::log(ERR, "second fork failed");
_exit(1);
} else if (pid == 0)
runXWayland(notify[1]);
runXWayland(notifyFds[1]);
_exit(0);
}
close(notify[1]);
close(waylandFDs[1]);
closeSocketSafely(xwmFDs[1]);
waylandFDs[1] = -1;
xwmFDs[1] = -1;
return true;
}
int CXWaylandServer::ready(int fd, uint32_t mask) {
int CXWaylandServer::ready(CFileDescriptor fd, uint32_t mask) {
if (mask & WL_EVENT_READABLE) {
// xwayland writes twice
char buf[64];
ssize_t n = read(fd, buf, sizeof(buf));
ssize_t n = read(fd.get(), buf, sizeof(buf));
if (n < 0 && errno != EINTR) {
Debug::log(ERR, "Xwayland: read from displayFd failed");
mask = 0;
@ -436,7 +390,6 @@ int CXWaylandServer::ready(int fd, uint32_t mask) {
Debug::log(LOG, "XWayland is ready");
close(fd);
wl_event_source_remove(pipeSource);
pipeSource = nullptr;

View file

@ -1,6 +1,7 @@
#pragma once
#include <array>
#include <hyprutils/os/FileDescriptor.hpp>
#include "../helpers/signal/Signal.hpp"
struct wl_event_source;
@ -19,7 +20,7 @@ class CXWaylandServer {
bool start();
// called on ready
int ready(int fd, uint32_t mask);
int ready(Hyprutils::OS::CFileDescriptor fd, uint32_t mask);
void die();
@ -30,20 +31,20 @@ class CXWaylandServer {
wl_client* xwaylandClient = nullptr;
private:
bool tryOpenSockets();
void runXWayland(int notifyFD);
bool tryOpenSockets();
void runXWayland(Hyprutils::OS::CFileDescriptor& notifyFD);
pid_t serverPID = 0;
pid_t serverPID = 0;
std::string displayName;
int display = -1;
std::array<int, 2> xFDs = {-1, -1};
std::array<wl_event_source*, 2> xFDReadEvents = {nullptr, nullptr};
wl_event_source* idleSource = nullptr;
wl_event_source* pipeSource = nullptr;
int pipeFd = -1;
std::array<int, 2> xwmFDs = {-1, -1};
std::array<int, 2> waylandFDs = {-1, -1};
std::string displayName;
int display = -1;
std::array<Hyprutils::OS::CFileDescriptor, 2> xFDs;
std::array<wl_event_source*, 2> xFDReadEvents = {nullptr, nullptr};
wl_event_source* idleSource = nullptr;
wl_event_source* pipeSource = nullptr;
Hyprutils::OS::CFileDescriptor pipeFd;
std::array<Hyprutils::OS::CFileDescriptor, 2> xwmFDs;
std::array<Hyprutils::OS::CFileDescriptor, 2> waylandFDs;
friend class CXWM;
};

View file

@ -5,6 +5,7 @@
#include "XDataSource.hpp"
#include <fcntl.h>
using namespace Hyprutils::OS;
CXDataSource::CXDataSource(SXSelection& sel_) : selection(sel_) {
xcb_get_property_cookie_t cookie = xcb_get_property(g_pXWayland->pWM->connection,
@ -47,7 +48,7 @@ std::vector<std::string> CXDataSource::mimes() {
return mimeTypes;
}
void CXDataSource::send(const std::string& mime, uint32_t fd) {
void CXDataSource::send(const std::string& mime, CFileDescriptor fd) {
xcb_atom_t mimeAtom = 0;
if (mime == "text/plain")
@ -65,11 +66,10 @@ void CXDataSource::send(const std::string& mime, uint32_t fd) {
if (!mimeAtom) {
Debug::log(ERR, "[XDataSource] mime atom not found");
close(fd);
return;
}
Debug::log(LOG, "[XDataSource] send with mime {} to fd {}", mime, fd);
Debug::log(LOG, "[XDataSource] send with mime {} to fd {}", mime, fd.get());
selection.transfer = makeUnique<SXTransfer>(selection);
selection.transfer->incomingWindow = xcb_generate_id(g_pXWayland->pWM->connection);
@ -81,8 +81,9 @@ void CXDataSource::send(const std::string& mime, uint32_t fd) {
xcb_flush(g_pXWayland->pWM->connection);
fcntl(fd, F_SETFL, O_WRONLY | O_NONBLOCK);
selection.transfer->wlFD = fd;
//TODO: make CFileDescriptor setflags take SETFL aswell
fcntl(fd.get(), F_SETFL, O_WRONLY | O_NONBLOCK);
selection.transfer->wlFD = std::move(fd);
}
void CXDataSource::accepted(const std::string& mime) {
@ -101,4 +102,4 @@ eDataSourceType CXDataSource::type() {
return DATA_SOURCE_TYPE_X11;
}
#endif
#endif

View file

@ -1,6 +1,7 @@
#pragma once
#include "../protocols/types/DataDevice.hpp"
#include <hyprutils/os/FileDescriptor.hpp>
struct SXSelection;
@ -9,7 +10,7 @@ class CXDataSource : public IDataSource {
CXDataSource(SXSelection&);
virtual std::vector<std::string> mimes();
virtual void send(const std::string& mime, uint32_t fd);
virtual void send(const std::string& mime, Hyprutils::OS::CFileDescriptor fd);
virtual void accepted(const std::string& mime);
virtual void cancelled();
virtual void error(uint32_t code, const std::string& msg);
@ -19,4 +20,4 @@ class CXDataSource : public IDataSource {
SXSelection& selection;
std::vector<std::string> mimeTypes; // these two have shared idx
std::vector<uint32_t> mimeAtoms; //
};
};

View file

@ -17,6 +17,7 @@
#include "../managers/SeatManager.hpp"
#include "../protocols/XWaylandShell.hpp"
#include "../protocols/core/Compositor.hpp"
using namespace Hyprutils::OS;
#define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f
#define INCR_CHUNK_SIZE (64 * 1024)
@ -883,7 +884,7 @@ void CXWM::getRenderFormat() {
free(reply);
}
CXWM::CXWM() : connection(g_pXWayland->pServer->xwmFDs[0]) {
CXWM::CXWM() : connection(g_pXWayland->pServer->xwmFDs[0].get()) {
if (connection.hasError()) {
Debug::log(ERR, "[xwm] Couldn't start, error {}", connection.hasError());
@ -901,7 +902,7 @@ CXWM::CXWM() : connection(g_pXWayland->pServer->xwmFDs[0]) {
xcb_screen_iterator_t screen_iterator = xcb_setup_roots_iterator(xcb_get_setup(connection));
screen = screen_iterator.data;
eventSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, g_pXWayland->pServer->xwmFDs[0], WL_EVENT_READABLE, ::onX11Event, nullptr);
eventSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, g_pXWayland->pServer->xwmFDs[0].get(), WL_EVENT_READABLE, ::onX11Event, nullptr);
wl_event_source_check(eventSource);
gatherResources();
@ -1180,13 +1181,12 @@ void CXWM::getTransferData(SXSelection& sel) {
if (sel.transfer->propertyReply->type == HYPRATOMS["INCR"]) {
Debug::log(ERR, "[xwm] Transfer is INCR, which we don't support :(");
close(sel.transfer->wlFD);
sel.transfer.reset();
return;
} else {
sel.onWrite();
if (sel.transfer)
sel.transfer->eventSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, sel.transfer->wlFD, WL_EVENT_WRITABLE, ::writeDataSource, &sel);
sel.transfer->eventSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, sel.transfer->wlFD.get(), WL_EVENT_WRITABLE, ::writeDataSource, &sel);
}
}
@ -1361,13 +1361,13 @@ bool SXSelection::sendData(xcb_selection_request_event_t* e, std::string mime) {
// the wayland client might not expect a non-blocking fd
// fcntl(p[1], F_SETFL, O_NONBLOCK);
transfer->wlFD = p[0];
transfer->wlFD = CFileDescriptor{p[0]};
Debug::log(LOG, "[xwm] sending wayland selection to xwayland with mime {}, target {}, fds {} {}", mime, e->target, p[0], p[1]);
selection->send(mime, p[1]);
selection->send(mime, CFileDescriptor{p[1]});
transfer->eventSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, transfer->wlFD, WL_EVENT_READABLE, ::readDataSource, this);
transfer->eventSource = wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, transfer->wlFD.get(), WL_EVENT_READABLE, ::readDataSource, this);
return true;
}
@ -1376,10 +1376,9 @@ int SXSelection::onWrite() {
char* property = (char*)xcb_get_property_value(transfer->propertyReply);
int remainder = xcb_get_property_value_length(transfer->propertyReply) - transfer->propertyStart;
ssize_t len = write(transfer->wlFD, property + transfer->propertyStart, remainder);
ssize_t len = write(transfer->wlFD.get(), property + transfer->propertyStart, remainder);
if (len == -1) {
Debug::log(ERR, "[xwm] write died in transfer get");
close(transfer->wlFD);
transfer.reset();
return 0;
}
@ -1389,7 +1388,6 @@ int SXSelection::onWrite() {
Debug::log(LOG, "[xwm] wl client read partially: len {}", len);
} else {
Debug::log(LOG, "[xwm] cb transfer to wl client complete, read {} bytes", len);
close(transfer->wlFD);
transfer.reset();
}
@ -1397,8 +1395,6 @@ int SXSelection::onWrite() {
}
SXTransfer::~SXTransfer() {
if (wlFD)
close(wlFD);
if (eventSource)
wl_event_source_remove(eventSource);
if (incomingWindow)

View file

@ -10,6 +10,7 @@
#include <xcb/xfixes.h>
#include <xcb/composite.h>
#include <xcb/xcb_errors.h>
#include <hyprutils/os/FileDescriptor.hpp>
struct wl_event_source;
class CXWaylandSurfaceResource;
@ -18,25 +19,25 @@ struct SXSelection;
struct SXTransfer {
~SXTransfer();
SXSelection& selection;
bool out = true;
SXSelection& selection;
bool out = true;
bool incremental = false;
bool flushOnDelete = false;
bool propertySet = false;
bool incremental = false;
bool flushOnDelete = false;
bool propertySet = false;
int wlFD = -1;
wl_event_source* eventSource = nullptr;
Hyprutils::OS::CFileDescriptor wlFD;
wl_event_source* eventSource = nullptr;
std::vector<uint8_t> data;
std::vector<uint8_t> data;
xcb_selection_request_event_t request;
xcb_selection_request_event_t request;
int propertyStart;
xcb_get_property_reply_t* propertyReply;
xcb_window_t incomingWindow;
int propertyStart;
xcb_get_property_reply_t* propertyReply;
xcb_window_t incomingWindow;
bool getIncomingSelectionProp(bool erase);
bool getIncomingSelectionProp(bool erase);
};
struct SXSelection {