@@ -36,8 +36,9 @@ void CXWM::handleCreate(xcb_create_notify_event_t* e) {
36
36
if (isWMWindow (e->window ))
37
37
return ;
38
38
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;
41
42
Debug::log (LOG, " [xwm] New XSurface at {:x} with xid of {}" , (uintptr_t )XSURF.get (), e->window );
42
43
43
44
const auto WINDOW = CWindow::create (XSURF);
@@ -67,8 +68,9 @@ void CXWM::handleConfigure(xcb_configure_request_event_t* e) {
67
68
if (!(MASK & GEOMETRY))
68
69
return ;
69
70
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 });
72
74
}
73
75
74
76
void CXWM::handleConfigureNotify (xcb_configure_notify_event_t * e) {
@@ -77,10 +79,11 @@ void CXWM::handleConfigureNotify(xcb_configure_notify_event_t* e) {
77
79
if (!XSURF)
78
80
return ;
79
81
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)
81
84
return ;
82
85
83
- XSURF->geometry = {e-> x , e-> y , e-> width , e-> height } ;
86
+ XSURF->geometry = geom ;
84
87
XSURF->events .setGeometry .emit ();
85
88
}
86
89
@@ -227,6 +230,17 @@ void CXWM::readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_
227
230
228
231
xcb_icccm_get_wm_size_hints_from_reply (XSURF->sizeHints .get (), reply);
229
232
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
+
230
244
const int32_t FLAGS = XSURF->sizeHints ->flags ;
231
245
const bool HASMIN = (FLAGS & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE);
232
246
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_
260
274
void CXWM::handlePropertyNotify (xcb_property_notify_event_t * e) {
261
275
const auto XSURF = windowForXID (e->window );
262
276
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
+ }
264
289
return ;
290
+ }
265
291
266
292
xcb_get_property_cookie_t cookie = xcb_get_property (connection, 0 , XSURF->xID , e->atom , XCB_ATOM_ANY, 0 , 2048 );
267
293
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
1115
1141
xcb_flush (connection);
1116
1142
}
1117
1143
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
+
1118
1152
void SXSelection::onSelection () {
1119
1153
if (g_pSeatManager->selection .currentSelection && g_pSeatManager->selection .currentSelection ->type () == DATA_SOURCE_TYPE_X11)
1120
1154
return ;
0 commit comments