Skip to content

Commit ab33ff9

Browse files
committed
1 parent 897ee27 commit ab33ff9

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

src/xwayland/XSurface.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ void CXWaylandSurface::configure(const CBox& box) {
166166
geometry = box;
167167

168168
uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_BORDER_WIDTH;
169-
uint32_t values[] = {box.x, box.y, box.width, box.height, 0};
169+
uint32_t values[] = {g_pXWayland->pWM->applyScale(box.x), g_pXWayland->pWM->applyScale(box.y), g_pXWayland->pWM->applyScale(box.width),
170+
g_pXWayland->pWM->applyScale(box.height), 0};
170171
xcb_configure_window(g_pXWayland->pWM->connection, xID, mask, values);
171172

172173
if (geometry.width == box.width && geometry.height == box.height) {
@@ -175,10 +176,10 @@ void CXWaylandSurface::configure(const CBox& box) {
175176
e.response_type = XCB_CONFIGURE_NOTIFY;
176177
e.event = xID;
177178
e.window = xID;
178-
e.x = box.x;
179-
e.y = box.y;
180-
e.width = box.width;
181-
e.height = box.height;
179+
e.x = g_pXWayland->pWM->applyScale(box.x);
180+
e.y = g_pXWayland->pWM->applyScale(box.y);
181+
e.width = g_pXWayland->pWM->applyScale(box.width);
182+
e.height = g_pXWayland->pWM->applyScale(box.height);
182183
e.border_width = 0;
183184
e.above_sibling = XCB_NONE;
184185
e.override_redirect = overrideRedirect;

src/xwayland/XWM.cpp

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ void CXWM::handleCreate(xcb_create_notify_event_t* e) {
3939
if (isWMWindow(e->window))
4040
return;
4141

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

4647
const auto WINDOW = CWindow::create(XSURF);
@@ -70,9 +71,9 @@ void CXWM::handleConfigureRequest(xcb_configure_request_event_t* e) {
7071
if (!(MASK & GEOMETRY))
7172
return;
7273

73-
XSURF->events.configureRequest.emit(CBox{MASK & XCB_CONFIG_WINDOW_X ? e->x : XSURF->geometry.x, MASK & XCB_CONFIG_WINDOW_Y ? e->y : XSURF->geometry.y,
74-
MASK & XCB_CONFIG_WINDOW_WIDTH ? e->width : XSURF->geometry.width,
75-
MASK & XCB_CONFIG_WINDOW_HEIGHT ? e->height : XSURF->geometry.height});
74+
XSURF->events.configureRequest.emit(
75+
CBox{MASK & XCB_CONFIG_WINDOW_X ? applyUnScale(e->x) : XSURF->geometry.x, MASK & XCB_CONFIG_WINDOW_Y ? applyUnScale(e->y) : XSURF->geometry.y,
76+
MASK & XCB_CONFIG_WINDOW_WIDTH ? applyUnScale(e->width) : XSURF->geometry.width, MASK & XCB_CONFIG_WINDOW_HEIGHT ? applyUnScale(e->height) : XSURF->geometry.height});
7677
}
7778

7879
void CXWM::handleConfigureNotify(xcb_configure_notify_event_t* e) {
@@ -81,10 +82,11 @@ void CXWM::handleConfigureNotify(xcb_configure_notify_event_t* e) {
8182
if (!XSURF)
8283
return;
8384

84-
if (XSURF->geometry == CBox{e->x, e->y, e->width, e->height})
85+
const CBox geom = {applyUnScale(e->x), applyUnScale(e->y), applyUnScale(e->width), applyUnScale(e->height)};
86+
if (XSURF->geometry == geom)
8587
return;
8688

87-
XSURF->geometry = {e->x, e->y, e->width, e->height};
89+
XSURF->geometry = geom;
8890
updateOverrideRedirect(XSURF, e->override_redirect);
8991
XSURF->events.setGeometry.emit();
9092
}
@@ -261,6 +263,17 @@ void CXWM::readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_
261263

262264
xcb_icccm_get_wm_size_hints_from_reply(XSURF->sizeHints.get(), reply);
263265

266+
XSURF->sizeHints->x = applyUnScale(XSURF->sizeHints->x);
267+
XSURF->sizeHints->y = applyUnScale(XSURF->sizeHints->y);
268+
XSURF->sizeHints->width = applyUnScale(XSURF->sizeHints->width);
269+
XSURF->sizeHints->height = applyUnScale(XSURF->sizeHints->height);
270+
XSURF->sizeHints->min_width = applyUnScale(XSURF->sizeHints->min_width);
271+
XSURF->sizeHints->min_height = applyUnScale(XSURF->sizeHints->min_height);
272+
XSURF->sizeHints->max_width = applyUnScale(XSURF->sizeHints->max_width);
273+
XSURF->sizeHints->max_height = applyUnScale(XSURF->sizeHints->max_height);
274+
XSURF->sizeHints->base_width = applyUnScale(XSURF->sizeHints->base_width);
275+
XSURF->sizeHints->base_height = applyUnScale(XSURF->sizeHints->base_height);
276+
264277
const int32_t FLAGS = XSURF->sizeHints->flags;
265278
const bool HASMIN = (FLAGS & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE);
266279
const bool HASBASE = (FLAGS & XCB_ICCCM_SIZE_HINT_BASE_SIZE);
@@ -294,8 +307,20 @@ void CXWM::readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_
294307
void CXWM::handlePropertyNotify(xcb_property_notify_event_t* e) {
295308
const auto XSURF = windowForXID(e->window);
296309

297-
if (!XSURF)
310+
if (!XSURF) {
311+
if (e->atom == HYPRATOMS["_XWAYLAND_GLOBAL_OUTPUT_SCALE"]) {
312+
xcb_get_property_cookie_t cookie = xcb_get_property(connection, 0, e->window, e->atom, XCB_ATOM_ANY, 0, 2048);
313+
xcb_get_property_reply_t* reply = xcb_get_property_reply(connection, cookie, nullptr);
314+
if (!reply) {
315+
return;
316+
}
317+
if (reply->type == XCB_ATOM_CARDINAL) {
318+
scale = *(uint32_t*)xcb_get_property_value(reply);
319+
}
320+
free(reply);
321+
}
298322
return;
323+
}
299324

300325
xcb_get_property_cookie_t cookie = xcb_get_property(connection, 0, XSURF->xID, e->atom, XCB_ATOM_ANY, 0, 2048);
301326
xcb_get_property_reply_t* reply = xcb_get_property_reply(connection, cookie, nullptr);
@@ -1304,6 +1329,14 @@ SP<IDataOffer> CXWM::createX11DataOffer(SP<CWLSurfaceResource> surf, SP<IDataSou
13041329
return offer;
13051330
}
13061331

1332+
double CXWM::applyScale(double val) {
1333+
return std::floor(val * scale);
1334+
}
1335+
1336+
double CXWM::applyUnScale(double val) {
1337+
return std::ceil(val / scale);
1338+
}
1339+
13071340
void SXSelection::onSelection() {
13081341
if (g_pSeatManager->selection.currentSelection && g_pSeatManager->selection.currentSelection->type() == DATA_SOURCE_TYPE_X11)
13091342
return;

src/xwayland/XWM.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,16 @@ class CXWM {
175175

176176
SXSelection* getSelection(xcb_atom_t atom);
177177

178+
double applyScale(double val);
179+
double applyUnScale(double val);
180+
178181
//
179182
CXCBConnection connection;
180183
xcb_errors_context_t* errors = nullptr;
181184
xcb_screen_t* screen = nullptr;
182185

183186
xcb_window_t wmWindow;
187+
double scale = 1.0;
184188

185189
wl_event_source* eventSource = nullptr;
186190

src/xwayland/XWayland.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,6 @@ inline std::unordered_map<std::string, uint32_t> HYPRATOMS = {
130130
HYPRATOM("DELETE"),
131131
HYPRATOM("TEXT"),
132132
HYPRATOM("INCR"),
133+
HYPRATOM("_XWAYLAND_GLOBAL_OUTPUT_SCALE"),
133134
#endif
134135
};

0 commit comments

Comments
 (0)