Skip to content

Commit ae81dd6

Browse files
committed
1 parent b03f41e commit ae81dd6

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

src/xwayland/XSurface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ void CXWaylandSurface::configure(const CBox& box) {
168168
geometry = box;
169169

170170
uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_BORDER_WIDTH;
171-
uint32_t values[] = {box.x, box.y, box.width, box.height, 0};
171+
uint32_t values[] = {g_pXWayland->pWM->applyScale(box.x), g_pXWayland->pWM->applyScale(box.y), g_pXWayland->pWM->applyScale(box.width),
172+
g_pXWayland->pWM->applyScale(box.height), 0};
172173
xcb_configure_window(g_pXWayland->pWM->connection, xID, mask, values);
173174

174175
g_pXWayland->pWM->updateClientList();

src/xwayland/XWM.cpp

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ void CXWM::handleCreate(xcb_create_notify_event_t* e) {
3636
if (isWMWindow(e->window))
3737
return;
3838

39-
const auto XSURF = surfaces.emplace_back(SP<CXWaylandSurface>(new CXWaylandSurface(e->window, CBox{e->x, e->y, e->width, e->height}, e->override_redirect)));
40-
XSURF->self = XSURF;
39+
const auto XSURF = surfaces.emplace_back(
40+
SP<CXWaylandSurface>(new CXWaylandSurface(e->window, CBox{applyUnScale(e->x), applyUnScale(e->y), applyUnScale(e->width), applyUnScale(e->height)}, e->override_redirect)));
41+
XSURF->self = XSURF;
4142
Debug::log(LOG, "[xwm] New XSurface at {:x} with xid of {}", (uintptr_t)XSURF.get(), e->window);
4243

4344
const auto WINDOW = CWindow::create(XSURF);
@@ -67,8 +68,9 @@ void CXWM::handleConfigure(xcb_configure_request_event_t* e) {
6768
if (!(MASK & GEOMETRY))
6869
return;
6970

70-
XSURF->events.configure.emit(CBox{MASK & XCB_CONFIG_WINDOW_X ? e->x : XSURF->geometry.x, MASK & XCB_CONFIG_WINDOW_Y ? e->y : XSURF->geometry.y,
71-
MASK & XCB_CONFIG_WINDOW_WIDTH ? e->width : XSURF->geometry.width, MASK & XCB_CONFIG_WINDOW_HEIGHT ? e->height : XSURF->geometry.height});
71+
XSURF->events.configure.emit(CBox{MASK & XCB_CONFIG_WINDOW_X ? applyUnScale(e->x) : XSURF->geometry.x, MASK & XCB_CONFIG_WINDOW_Y ? applyUnScale(e->y) : XSURF->geometry.y,
72+
MASK & XCB_CONFIG_WINDOW_WIDTH ? applyUnScale(e->width) : XSURF->geometry.width,
73+
MASK & XCB_CONFIG_WINDOW_HEIGHT ? applyUnScale(e->height) : XSURF->geometry.height});
7274
}
7375

7476
void CXWM::handleConfigureNotify(xcb_configure_notify_event_t* e) {
@@ -77,10 +79,11 @@ void CXWM::handleConfigureNotify(xcb_configure_notify_event_t* e) {
7779
if (!XSURF)
7880
return;
7981

80-
if (XSURF->geometry == CBox{e->x, e->y, e->width, e->height})
82+
const CBox geom = {applyUnScale(e->x), applyUnScale(e->y), applyUnScale(e->width), applyUnScale(e->height)};
83+
if (XSURF->geometry == geom)
8184
return;
8285

83-
XSURF->geometry = {e->x, e->y, e->width, e->height};
86+
XSURF->geometry = geom;
8487
XSURF->events.setGeometry.emit();
8588
}
8689

@@ -227,6 +230,17 @@ void CXWM::readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_
227230

228231
xcb_icccm_get_wm_size_hints_from_reply(XSURF->sizeHints.get(), reply);
229232

233+
XSURF->sizeHints->x = applyUnScale(XSURF->sizeHints->x);
234+
XSURF->sizeHints->y = applyUnScale(XSURF->sizeHints->y);
235+
XSURF->sizeHints->width = applyUnScale(XSURF->sizeHints->width);
236+
XSURF->sizeHints->height = applyUnScale(XSURF->sizeHints->height);
237+
XSURF->sizeHints->min_width = applyUnScale(XSURF->sizeHints->min_width);
238+
XSURF->sizeHints->min_height = applyUnScale(XSURF->sizeHints->min_height);
239+
XSURF->sizeHints->max_width = applyUnScale(XSURF->sizeHints->max_width);
240+
XSURF->sizeHints->max_height = applyUnScale(XSURF->sizeHints->max_height);
241+
XSURF->sizeHints->base_width = applyUnScale(XSURF->sizeHints->base_width);
242+
XSURF->sizeHints->base_height = applyUnScale(XSURF->sizeHints->base_height);
243+
230244
const int32_t FLAGS = XSURF->sizeHints->flags;
231245
const bool HASMIN = (FLAGS & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE);
232246
const bool HASBASE = (FLAGS & XCB_ICCCM_SIZE_HINT_BASE_SIZE);
@@ -260,8 +274,20 @@ void CXWM::readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_
260274
void CXWM::handlePropertyNotify(xcb_property_notify_event_t* e) {
261275
const auto XSURF = windowForXID(e->window);
262276

263-
if (!XSURF)
277+
if (!XSURF) {
278+
if (e->atom == HYPRATOMS["_XWAYLAND_GLOBAL_OUTPUT_SCALE"]) {
279+
xcb_get_property_cookie_t cookie = xcb_get_property(connection, 0, e->window, e->atom, XCB_ATOM_ANY, 0, 2048);
280+
xcb_get_property_reply_t* reply = xcb_get_property_reply(connection, cookie, nullptr);
281+
if (!reply) {
282+
return;
283+
}
284+
if (reply->type == XCB_ATOM_CARDINAL) {
285+
scale = *(uint32_t*)xcb_get_property_value(reply);
286+
}
287+
free(reply);
288+
}
264289
return;
290+
}
265291

266292
xcb_get_property_cookie_t cookie = xcb_get_property(connection, 0, XSURF->xID, e->atom, XCB_ATOM_ANY, 0, 2048);
267293
xcb_get_property_reply_t* reply = xcb_get_property_reply(connection, cookie, nullptr);
@@ -1115,6 +1141,14 @@ void CXWM::setCursor(unsigned char* pixData, uint32_t stride, const Vector2D& si
11151141
xcb_flush(connection);
11161142
}
11171143

1144+
double CXWM::applyScale(double val) {
1145+
return std::floor(val * scale);
1146+
}
1147+
1148+
double CXWM::applyUnScale(double val) {
1149+
return std::ceil(val / scale);
1150+
}
1151+
11181152
void SXSelection::onSelection() {
11191153
if (g_pSeatManager->selection.currentSelection && g_pSeatManager->selection.currentSelection->type() == DATA_SOURCE_TYPE_X11)
11201154
return;

src/xwayland/XWM.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,16 @@ class CXWM {
119119
void getTransferData(SXSelection& sel);
120120
void readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_reply_t* reply);
121121

122+
double applyScale(double val);
123+
double applyUnScale(double val);
124+
122125
//
123126
xcb_connection_t* connection = nullptr;
124127
xcb_errors_context_t* errors = nullptr;
125128
xcb_screen_t* screen = nullptr;
126129

127130
xcb_window_t wmWindow;
131+
double scale = 1.0;
128132

129133
wl_event_source* eventSource = nullptr;
130134

src/xwayland/XWayland.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,5 @@ inline std::unordered_map<std::string, uint32_t> HYPRATOMS = {
125125
HYPRATOM("DELETE"),
126126
HYPRATOM("TEXT"),
127127
HYPRATOM("INCR"),
128-
};
128+
HYPRATOM("_XWAYLAND_GLOBAL_OUTPUT_SCALE"),
129+
};

0 commit comments

Comments
 (0)