Skip to content

Commit

Permalink
Support only configure position or size for x11
Browse files Browse the repository at this point in the history
  • Loading branch information
wineee committed Nov 5, 2024
1 parent 6e88ca5 commit 0de69fb
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 6 deletions.
106 changes: 106 additions & 0 deletions src/server/protocols/wxwaylandsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Q_DECL_HIDDEN WXWaylandSurfacePrivate : public WToplevelSurfacePrivate
void updateChildren();
void updateParent();
void updateWindowTypes();
void doConfigureSize(uint16_t width, uint16_t height);
void doConfigurePosition(int16_t x, int16_t y);

W_DECLARE_PUBLIC(WXWaylandSurface)

Expand Down Expand Up @@ -241,6 +243,98 @@ void WXWaylandSurfacePrivate::updateWindowTypes()
Q_EMIT q_func()->windowTypesChanged();
}

void WXWaylandSurfacePrivate::doConfigureSize(uint16_t width, uint16_t height) {
// auto xsurface = nativeHandle();
// xsurface->width = width;
// xsurface->height = height;

// uint32_t mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
// uint32_t values[] = { width, height };
// qDebug() << Q_FUNC_INFO << " " << width << " " << height;
// xcb_configure_window(xwayland->xcbConnection(), xsurface->window_id, mask, values);

// xcb_flush(xwayland->xcbConnection());

auto xsurface = handle()->handle();
int old_w = xsurface->width;
int old_h = xsurface->height;

xsurface->x = 100;
xsurface->y = 100;
xsurface->width = width;
xsurface->height = height;

struct wlr_xwm *xwm = xsurface->xwm;
uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
XCB_CONFIG_WINDOW_BORDER_WIDTH;
uint32_t values[] = {100, 100, width, height, 0};
xcb_configure_window(xwayland->xcbConnection(), xsurface->window_id, mask, values);

// If the window size did not change, then we cannot rely on
// the X server to generate a ConfigureNotify event. Instead,
// we are supposed to send a synthetic event. See ICCCM part
// 4.1.5. But we ignore override-redirect windows as ICCCM does
// not apply to them.
if (width == old_w && height == old_h && !xsurface->override_redirect) {
xcb_configure_notify_event_t configure_notify = {
.response_type = XCB_CONFIGURE_NOTIFY,
.event = xsurface->window_id,
.window = xsurface->window_id,
.x = 100,
.y = 100,
.width = width,
.height = height,
};

xcb_send_event(xwayland->xcbConnection(), 0, xsurface->window_id,
XCB_EVENT_MASK_STRUCTURE_NOTIFY,
(const char *)&configure_notify);
}

xcb_flush(xwayland->xcbConnection());


//wlr_xwayland_surface_configure(q_func()->handle()->handle(),100,100,width,height);
}

void WXWaylandSurfacePrivate::doConfigurePosition(int16_t x, int16_t y)
{
return;
auto xsurface = nativeHandle();

xsurface->x = x;
xsurface->y = y;

uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y;
uint32_t values[] = { (uint32_t)x, (uint32_t)y };
xcb_configure_window(xwayland->xcbConnection(), xsurface->window_id, mask, values);

// If the window size did not change, then we cannot rely on
// the X server to generate a ConfigureNotify event. Instead,
// we are supposed to send a synthetic event. See ICCCM part
// 4.1.5. But we ignore override-redirect windows as ICCCM does
// not apply to them.
if (!xsurface->override_redirect) {
xcb_configure_notify_event_t configure_notify = {
.response_type = XCB_CONFIGURE_NOTIFY,
.event = xsurface->window_id,
.window = xsurface->window_id,
.x = x,
.y = y,
.width = xsurface->width,
.height = xsurface->height,
};

xcb_send_event(xwayland->xcbConnection(), 0, xsurface->window_id,
XCB_EVENT_MASK_STRUCTURE_NOTIFY,
(const char *)&configure_notify);
}

xcb_flush(xwayland->xcbConnection());
}


WXWaylandSurface::WXWaylandSurface(qw_xwayland_surface *handle, WXWayland *xwayland, QObject *parent)
: WToplevelSurface(*new WXWaylandSurfacePrivate(this, handle, xwayland), parent)
{
Expand Down Expand Up @@ -461,6 +555,18 @@ WXWaylandSurface::DecorationsType WXWaylandSurface::decorationsType() const
return static_cast<DecorationsType>(d->nativeHandle()->decorations);
}

void WXWaylandSurface::configureSize(uint16_t width, uint16_t height)
{
W_D(WXWaylandSurface);
d->doConfigureSize(width, height);
}

void WXWaylandSurface::configurePosition(int16_t x, int16_t y)
{
W_D(WXWaylandSurface);
d->doConfigurePosition(x, y);
}

bool WXWaylandSurface::checkNewSize(const QSize &size)
{
const QSize minSize = this->minSize();
Expand Down
3 changes: 3 additions & 0 deletions src/server/protocols/wxwaylandsurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class WAYLIB_SERVER_EXPORT WXWaylandSurface : public WToplevelSurface
WindowTypes windowTypes() const;
DecorationsType decorationsType() const;

void configureSize(uint16_t width, uint16_t height);
void configurePosition(int16_t x, int16_t y);

public Q_SLOTS:
bool checkNewSize(const QSize &size) override;
void resize(const QSize &size) override;
Expand Down
23 changes: 17 additions & 6 deletions src/server/qtquick/wxwaylandsurfaceitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Q_DECL_HIDDEN WXWaylandSurfaceItemPrivate : public WSurfaceItemPrivate
{
Q_DECLARE_PUBLIC(WXWaylandSurfaceItem)
public:
void configureSurface(const QRect &newGeometry);
void configureSurfaceSize(const QSize &newSize);
void configureSurfacePosition(const QPoint &newPosition);
QSize expectSurfaceSize() const;
QPoint explicitSurfacePosition() const;
static inline WXWaylandSurfaceItemPrivate *get(WXWaylandSurfaceItem *qq) {
Expand All @@ -27,15 +28,25 @@ class Q_DECL_HIDDEN WXWaylandSurfaceItemPrivate : public WSurfaceItemPrivate
QSize maximumSize;
};

void WXWaylandSurfaceItemPrivate::configureSurface(const QRect &newGeometry)
void WXWaylandSurfaceItemPrivate::configureSurfaceSize(const QSize &newSize)
{
Q_Q(WXWaylandSurfaceItem);
if (!q->isVisible())
return;
q->xwaylandSurface()->configure(newGeometry);
q->xwaylandSurface()->configureSize(newSize.width(), newSize.height());
q->updateSurfaceState();
}

void WXWaylandSurfaceItemPrivate::configureSurfacePosition(const QPoint &newPosition)
{
Q_Q(WXWaylandSurfaceItem);
if (!q->isVisible())
return;
q->xwaylandSurface()->configurePosition(newPosition.x(), newPosition.y());
q->updateSurfaceState();
}


QSize WXWaylandSurfaceItemPrivate::expectSurfaceSize() const
{
const Q_Q(WXWaylandSurfaceItem);
Expand Down Expand Up @@ -234,7 +245,8 @@ void WXWaylandSurfaceItem::initSurface()
bool WXWaylandSurfaceItem::doResizeSurface(const QSize &newSize)
{
Q_D(WXWaylandSurfaceItem);
d->configureSurface(QRect(d->surfacePosition.toPoint(), newSize));

d->configureSurfaceSize(newSize);
return true;
}

Expand All @@ -251,8 +263,7 @@ QSizeF WXWaylandSurfaceItem::getContentSize() const
void WXWaylandSurfaceItem::updatePosition()
{
Q_D(WXWaylandSurfaceItem);
d->configureSurface(QRect(d->explicitSurfacePosition(),
d->expectSurfaceSize()));
d->configureSurfacePosition(d->explicitSurfacePosition());
}

WAYLIB_SERVER_END_NAMESPACE

0 comments on commit 0de69fb

Please sign in to comment.