Commit c3d5c3db authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

x11: Add a helper to get the default screen

Since the screen number is well-known, we can look up the default
screen on demand. Note that xcb_get_setup() is pretty cheap as it
simply returns a const pointer to pre-allocated data.
parent 94ee33e9
Pipeline #210310 failed with stage
in 14 minutes and 58 seconds
......@@ -114,7 +114,7 @@ void X11DesktopWindowTest::testDesktopWindow()
auto cmCookie = xcb_create_colormap_checked(c.data(), XCB_COLORMAP_ALLOC_NONE, colormapId, rootWindow(), visualId);
QVERIFY(!xcb_request_check(c.data(), cmCookie));
const uint32_t values[] = {XCB_PIXMAP_NONE, kwinApp()->x11DefaultScreen()->black_pixel, colormapId};
const uint32_t values[] = {XCB_PIXMAP_NONE, Xcb::defaultScreen()->black_pixel, colormapId};
auto cookie = xcb_create_window_checked(c.data(), 32, windowId, rootWindow(),
windowGeometry.x(),
windowGeometry.y(),
......
......@@ -337,7 +337,7 @@ void SceneQPainterTest::testX11Window()
QVERIFY(!xcb_connection_has_error(c.data()));
const QRect windowGeometry(0, 0, 100, 200);
xcb_window_t windowId = xcb_generate_id(c.data());
uint32_t value = kwinApp()->x11DefaultScreen()->white_pixel;
uint32_t value = Xcb::defaultScreen()->white_pixel;
xcb_create_window(c.data(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
windowGeometry.x(),
windowGeometry.y(),
......
......@@ -127,7 +127,6 @@ void XwaylandServerCrashTest::testCrash()
QTRY_VERIFY(!window);
QTRY_VERIFY(!unmanaged);
QCOMPARE(kwinApp()->x11Connection(), nullptr);
QCOMPARE(kwinApp()->x11DefaultScreen(), nullptr);
QCOMPARE(kwinApp()->x11RootWindow(), XCB_WINDOW_NONE);
// Render a frame to ensure that the compositor doesn't crash.
......
......@@ -6,6 +6,7 @@
#include "x11_standalone_placeholderoutput.h"
#include "x11_standalone_platform.h"
#include "utils/xcbutils.h"
namespace KWin
{
......@@ -15,7 +16,7 @@ X11PlaceholderOutput::X11PlaceholderOutput(X11StandalonePlatform *backend, QObje
, m_backend(backend)
{
QSize pixelSize;
xcb_screen_t *screen = kwinApp()->x11DefaultScreen();
xcb_screen_t *screen = Xcb::defaultScreen();
if (screen) {
pixelSize = QSize(screen->width_in_pixels, screen->height_in_pixels);
}
......
......@@ -82,7 +82,7 @@ bool XrandrEventFilter::event(xcb_generic_event_t *event)
// update default screen
auto *xrrEvent = reinterpret_cast<xcb_randr_screen_change_notify_event_t *>(event);
xcb_screen_t *screen = kwinApp()->x11DefaultScreen();
xcb_screen_t *screen = Xcb::defaultScreen();
if (xrrEvent->rotation & (XCB_RANDR_ROTATION_ROTATE_90 | XCB_RANDR_ROTATION_ROTATE_270)) {
screen->width_in_pixels = xrrEvent->height;
screen->height_in_pixels = xrrEvent->width;
......
......@@ -248,7 +248,7 @@ xcb_cursor_t Cursor::x11Cursor(const QByteArray &name)
}
xcb_cursor_context_t *ctx;
if (xcb_cursor_context_new(kwinApp()->x11Connection(), kwinApp()->x11DefaultScreen(), &ctx) < 0) {
if (xcb_cursor_context_new(kwinApp()->x11Connection(), Xcb::defaultScreen(), &ctx) < 0) {
return XCB_CURSOR_NONE;
}
......
......@@ -169,14 +169,6 @@ public:
return m_connection;
}
/**
* @returns the X11 default screen
*/
xcb_screen_t *x11DefaultScreen() const
{
return m_defaultScreen;
}
/**
* Inheriting classes should use this method to set the X11 root window
* before accessing any X11 specific code pathes.
......@@ -193,14 +185,6 @@ public:
{
m_connection = c;
}
/**
* Inheriting classes should use this method to set the default screen
* before accessing any X11 specific code pathes.
*/
void setX11DefaultScreen(xcb_screen_t *screen)
{
m_defaultScreen = screen;
}
qreal xwaylandScale() const
{
......@@ -300,7 +284,6 @@ private:
xcb_timestamp_t m_x11Time = XCB_TIME_CURRENT_TIME;
xcb_window_t m_rootWindow = XCB_WINDOW_NONE;
xcb_connection_t *m_connection = nullptr;
xcb_screen_t *m_defaultScreen = nullptr;
#if KWIN_BUILD_ACTIVITIES
bool m_useKActivities = true;
#endif
......
......@@ -212,10 +212,6 @@ void ApplicationX11::performStartup()
{
crashChecking();
xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(x11Connection())).data;
Q_ASSERT(screen);
setX11DefaultScreen(screen);
owner.reset(new KWinSelectionOwner());
connect(owner.data(), &KSelectionOwner::failedToClaimOwnership, [] {
fputs(i18n("kwin: unable to claim manager selection, another wm running? (try using --replace)\n").toLocal8Bit().constData(), stderr);
......
......@@ -1971,16 +1971,14 @@ static inline void restackWindowsWithRaise(const QVector<xcb_window_t> &windows)
restackWindows(windows);
}
static xcb_screen_t *defaultScreen()
{
return xcb_setup_roots_iterator(xcb_get_setup(connection())).data;
}
static inline int defaultDepth()
{
static int depth = 0;
if (depth != 0) {
return depth;
}
xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(connection())).data;
Q_ASSERT(screen);
depth = screen->root_depth;
return depth;
return defaultScreen()->root_depth;
}
static inline xcb_rectangle_t fromQt(const QRect &rect)
......
......@@ -78,9 +78,10 @@ X11EventFilter *X11EventFilterContainer::filter() const
ColorMapper::ColorMapper(QObject *parent)
: QObject(parent)
, m_default(kwinApp()->x11DefaultScreen()->default_colormap)
, m_installed(kwinApp()->x11DefaultScreen()->default_colormap)
{
const xcb_screen_t *screen = Xcb::defaultScreen();
m_default = screen->default_colormap;
m_installed = screen->default_colormap;
}
ColorMapper::~ColorMapper()
......
......@@ -260,7 +260,6 @@ bool Xwayland::createX11Connection()
Q_ASSERT(screen);
m_app->setX11Connection(connection);
m_app->setX11DefaultScreen(screen);
m_app->setX11RootWindow(screen->root);
m_app->createAtoms();
......@@ -290,7 +289,6 @@ void Xwayland::destroyX11Connection()
xcb_disconnect(m_app->x11Connection());
m_app->setX11Connection(nullptr);
m_app->setX11DefaultScreen(nullptr);
m_app->setX11RootWindow(XCB_WINDOW_NONE);
Q_EMIT m_app->x11ConnectionChanged();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment