mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-17 06:45:58 +01:00
xwm: Minor cleanup, add wrappers for basic types (#7856)
This commit is contained in:
parent
9e98fb0167
commit
4414cd07e2
4 changed files with 74 additions and 40 deletions
|
@ -1,8 +1,8 @@
|
||||||
#ifndef NO_XWAYLAND
|
#ifndef NO_XWAYLAND
|
||||||
|
|
||||||
#include "XDataSource.hpp"
|
|
||||||
#include "XWayland.hpp"
|
#include "XWayland.hpp"
|
||||||
#include "../defines.hpp"
|
#include "../defines.hpp"
|
||||||
|
#include "XDataSource.hpp"
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
#ifndef NO_XWAYLAND
|
#ifndef NO_XWAYLAND
|
||||||
|
|
||||||
#include "../Compositor.hpp"
|
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
|
#include "../Compositor.hpp"
|
||||||
|
|
||||||
CXWaylandSurface::CXWaylandSurface(uint32_t xID_, CBox geometry_, bool OR) : xID(xID_), geometry(geometry_), overrideRedirect(OR) {
|
CXWaylandSurface::CXWaylandSurface(uint32_t xID_, CBox geometry_, bool OR) : xID(xID_), geometry(geometry_), overrideRedirect(OR) {
|
||||||
xcb_res_query_client_ids_cookie_t client_id_cookie = {0};
|
xcb_res_query_client_ids_cookie_t client_id_cookie = {0};
|
||||||
|
@ -196,12 +196,11 @@ void CXWaylandSurface::restackToTop() {
|
||||||
|
|
||||||
xcb_configure_window(g_pXWayland->pWM->connection, xID, XCB_CONFIG_WINDOW_STACK_MODE, values);
|
xcb_configure_window(g_pXWayland->pWM->connection, xID, XCB_CONFIG_WINDOW_STACK_MODE, values);
|
||||||
|
|
||||||
for (auto it = g_pXWayland->pWM->mappedSurfacesStacking.begin(); it != g_pXWayland->pWM->mappedSurfacesStacking.end(); ++it) {
|
auto& stack = g_pXWayland->pWM->mappedSurfacesStacking;
|
||||||
if (*it == self) {
|
auto it = std::find(stack.begin(), stack.end(), self);
|
||||||
std::rotate(it, it + 1, g_pXWayland->pWM->mappedSurfacesStacking.end());
|
|
||||||
break;
|
if (it != stack.end())
|
||||||
}
|
std::rotate(it, it + 1, stack.end());
|
||||||
}
|
|
||||||
|
|
||||||
g_pXWayland->pWM->updateClientList();
|
g_pXWayland->pWM->updateClientList();
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
#include "helpers/math/Math.hpp"
|
#include "helpers/math/Math.hpp"
|
||||||
|
#include <cstdint>
|
||||||
#ifndef NO_XWAYLAND
|
#ifndef NO_XWAYLAND
|
||||||
|
|
||||||
|
#include <ranges>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <xcb/xcb_icccm.h>
|
||||||
|
|
||||||
#include "XWayland.hpp"
|
#include "XWayland.hpp"
|
||||||
#include "../defines.hpp"
|
#include "../defines.hpp"
|
||||||
#include <unordered_map>
|
|
||||||
#include "../Compositor.hpp"
|
#include "../Compositor.hpp"
|
||||||
|
#include "../protocols/core/Seat.hpp"
|
||||||
|
#include "../managers/SeatManager.hpp"
|
||||||
#include "../protocols/XWaylandShell.hpp"
|
#include "../protocols/XWaylandShell.hpp"
|
||||||
#include "../protocols/core/Compositor.hpp"
|
#include "../protocols/core/Compositor.hpp"
|
||||||
#include "../managers/SeatManager.hpp"
|
|
||||||
#include "../protocols/core/Seat.hpp"
|
|
||||||
#include <ranges>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#include <xcb/xcb_icccm.h>
|
|
||||||
|
|
||||||
#define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f
|
#define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f
|
||||||
#define INCR_CHUNK_SIZE (64 * 1024)
|
#define INCR_CHUNK_SIZE (64 * 1024)
|
||||||
|
@ -830,15 +831,15 @@ void CXWM::getRenderFormat() {
|
||||||
free(reply);
|
free(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
CXWM::CXWM() {
|
CXWM::CXWM() : connection(g_pXWayland->pServer->xwmFDs[0]) {
|
||||||
connection = xcb_connect_to_fd(g_pXWayland->pServer->xwmFDs[0], nullptr);
|
|
||||||
|
|
||||||
if (int ret = xcb_connection_has_error(connection); ret) {
|
if (connection.hasError()) {
|
||||||
Debug::log(ERR, "[xwm] Couldn't start, error {}", ret);
|
Debug::log(ERR, "[xwm] Couldn't start, error {}", connection.hasError());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xcb_errors_context_new(connection, &errors)) {
|
CXCBErrorContext xcbErrCtx(connection);
|
||||||
|
if (!xcbErrCtx.isValid()) {
|
||||||
Debug::log(ERR, "[xwm] Couldn't allocate errors context");
|
Debug::log(ERR, "[xwm] Couldn't allocate errors context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -867,10 +868,7 @@ CXWM::CXWM() {
|
||||||
};
|
};
|
||||||
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, screen->root, HYPRATOMS["_NET_SUPPORTED"], XCB_ATOM_ATOM, 32, sizeof(supported) / sizeof(*supported), supported);
|
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, screen->root, HYPRATOMS["_NET_SUPPORTED"], XCB_ATOM_ATOM, 32, sizeof(supported) / sizeof(*supported), supported);
|
||||||
|
|
||||||
xcb_flush(connection);
|
|
||||||
|
|
||||||
setActiveWindow(XCB_WINDOW_NONE);
|
setActiveWindow(XCB_WINDOW_NONE);
|
||||||
|
|
||||||
initSelection();
|
initSelection();
|
||||||
|
|
||||||
listeners.newWLSurface = PROTO::compositor->events.newSurface.registerListener([this](std::any d) { onNewSurface(std::any_cast<SP<CWLSurfaceResource>>(d)); });
|
listeners.newWLSurface = PROTO::compositor->events.newSurface.registerListener([this](std::any d) { onNewSurface(std::any_cast<SP<CWLSurfaceResource>>(d)); });
|
||||||
|
@ -882,11 +880,6 @@ CXWM::CXWM() {
|
||||||
}
|
}
|
||||||
|
|
||||||
CXWM::~CXWM() {
|
CXWM::~CXWM() {
|
||||||
if (errors)
|
|
||||||
xcb_errors_context_free(errors);
|
|
||||||
|
|
||||||
if (connection)
|
|
||||||
xcb_disconnect(connection);
|
|
||||||
|
|
||||||
if (eventSource)
|
if (eventSource)
|
||||||
wl_event_source_remove(eventSource);
|
wl_event_source_remove(eventSource);
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../helpers/signal/Signal.hpp"
|
|
||||||
#include "../helpers/memory/Memory.hpp"
|
|
||||||
#include "../helpers/WLListener.hpp"
|
|
||||||
#include "../macros.hpp"
|
#include "../macros.hpp"
|
||||||
|
|
||||||
#include "XDataSource.hpp"
|
#include "XDataSource.hpp"
|
||||||
|
#include "../helpers/WLListener.hpp"
|
||||||
|
#include "../helpers/memory/Memory.hpp"
|
||||||
|
#include "../helpers/signal/Signal.hpp"
|
||||||
|
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <xcb/xcb_errors.h>
|
|
||||||
#include <xcb/composite.h>
|
|
||||||
#include <xcb/xfixes.h>
|
|
||||||
#include <xcb/res.h>
|
#include <xcb/res.h>
|
||||||
|
#include <xcb/xfixes.h>
|
||||||
|
#include <xcb/composite.h>
|
||||||
|
#include <xcb/xcb_errors.h>
|
||||||
|
|
||||||
struct wl_event_source;
|
struct wl_event_source;
|
||||||
class CXWaylandSurfaceResource;
|
class CXWaylandSurfaceResource;
|
||||||
|
@ -58,6 +57,49 @@ struct SXSelection {
|
||||||
std::unique_ptr<SXTransfer> transfer;
|
std::unique_ptr<SXTransfer> transfer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CXCBConnection {
|
||||||
|
public:
|
||||||
|
CXCBConnection(int fd) {
|
||||||
|
connection = xcb_connect_to_fd(fd, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
~CXCBConnection() {
|
||||||
|
if (connection)
|
||||||
|
xcb_disconnect(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasError() const {
|
||||||
|
return xcb_connection_has_error(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
operator xcb_connection_t*() const {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
xcb_connection_t* connection = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CXCBErrorContext {
|
||||||
|
public:
|
||||||
|
explicit CXCBErrorContext(xcb_connection_t* connection) {
|
||||||
|
if (xcb_errors_context_new(connection, &errors) != 0)
|
||||||
|
errors = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
~CXCBErrorContext() {
|
||||||
|
if (errors)
|
||||||
|
xcb_errors_context_free(errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isValid() const {
|
||||||
|
return errors != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
xcb_errors_context_t* errors = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
class CXWM {
|
class CXWM {
|
||||||
public:
|
public:
|
||||||
CXWM();
|
CXWM();
|
||||||
|
@ -123,7 +165,7 @@ class CXWM {
|
||||||
void readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_reply_t* reply);
|
void readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_reply_t* reply);
|
||||||
|
|
||||||
//
|
//
|
||||||
xcb_connection_t* connection = nullptr;
|
CXCBConnection connection;
|
||||||
xcb_errors_context_t* errors = nullptr;
|
xcb_errors_context_t* errors = nullptr;
|
||||||
xcb_screen_t* screen = nullptr;
|
xcb_screen_t* screen = nullptr;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue