Skip to content

Commit 48d3a49

Browse files
committed
1 parent 16c62a6 commit 48d3a49

File tree

5 files changed

+59
-14
lines changed

5 files changed

+59
-14
lines changed

src/protocols/PointerConstraints.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../managers/input/InputManager.hpp"
88
#include "../render/Renderer.hpp"
99
#include "../helpers/Monitor.hpp"
10+
#include "../xwayland/XWayland.hpp"
1011

1112
CPointerConstraint::CPointerConstraint(SP<CZwpLockedPointerV1> resource_, SP<CWLSurfaceResource> surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime_) :
1213
m_resourceLocked(resource_), m_locked(true), m_lifetime(lifetime_) {
@@ -37,7 +38,7 @@ CPointerConstraint::CPointerConstraint(SP<CZwpLockedPointerV1> resource_, SP<CWL
3738
const auto PWINDOW = m_hlSurface->getWindow();
3839
if (PWINDOW) {
3940
const auto ISXWL = PWINDOW->m_isX11;
40-
scale = ISXWL && *PXWLFORCESCALEZERO ? PWINDOW->m_X11SurfaceScaledBy : 1.f;
41+
scale = ISXWL ? (*PXWLFORCESCALEZERO ? PWINDOW->m_X11SurfaceScaledBy : g_pXWayland->m_wm->getScale()) : 1.f;
4142
}
4243

4344
m_positionHint = {wl_fixed_to_double(x) / scale, wl_fixed_to_double(y) / scale};

src/xwayland/XSurface.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ void CXWaylandSurface::configure(const CBox& box) {
168168
m_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->m_wm->applyScale(box.x), g_pXWayland->m_wm->applyScale(box.y), g_pXWayland->m_wm->applyScale(box.width),
172+
g_pXWayland->m_wm->applyScale(box.height), 0};
172173
xcb_configure_window(g_pXWayland->m_wm->m_connection, m_xID, mask, values);
173174

174175
if (m_geometry.width == box.width && m_geometry.height == box.height) {
@@ -177,10 +178,10 @@ void CXWaylandSurface::configure(const CBox& box) {
177178
e.response_type = XCB_CONFIGURE_NOTIFY;
178179
e.event = m_xID;
179180
e.window = m_xID;
180-
e.x = box.x;
181-
e.y = box.y;
182-
e.width = box.width;
183-
e.height = box.height;
181+
e.x = g_pXWayland->m_wm->applyScale(box.x);
182+
e.y = g_pXWayland->m_wm->applyScale(box.y);
183+
e.width = g_pXWayland->m_wm->applyScale(box.width);
184+
e.height = g_pXWayland->m_wm->applyScale(box.height);
184185
e.border_width = 0;
185186
e.above_sibling = XCB_NONE;
186187
e.override_redirect = m_overrideRedirect;

src/xwayland/XWM.cpp

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

44-
const auto XSURF = m_surfaces.emplace_back(SP<CXWaylandSurface>(new CXWaylandSurface(e->window, CBox{e->x, e->y, e->width, e->height}, e->override_redirect)));
45-
XSURF->m_self = XSURF;
44+
const auto XSURF = m_surfaces.emplace_back(
45+
SP<CXWaylandSurface>(new CXWaylandSurface(e->window, CBox{applyUnScale(e->x), applyUnScale(e->y), applyUnScale(e->width), applyUnScale(e->height)}, e->override_redirect)));
46+
XSURF->m_self = XSURF;
4647
Debug::log(LOG, "[xwm] New XSurface at {:x} with xid of {}", (uintptr_t)XSURF.get(), e->window);
4748

4849
const auto WINDOW = CWindow::create(XSURF);
@@ -72,9 +73,9 @@ void CXWM::handleConfigureRequest(xcb_configure_request_event_t* e) {
7273
if (!(MASK & GEOMETRY))
7374
return;
7475

75-
XSURF->m_events.configureRequest.emit(CBox{MASK & XCB_CONFIG_WINDOW_X ? e->x : XSURF->m_geometry.x, MASK & XCB_CONFIG_WINDOW_Y ? e->y : XSURF->m_geometry.y,
76-
MASK & XCB_CONFIG_WINDOW_WIDTH ? e->width : XSURF->m_geometry.width,
77-
MASK & XCB_CONFIG_WINDOW_HEIGHT ? e->height : XSURF->m_geometry.height});
76+
XSURF->m_events.configureRequest.emit(CBox{
77+
MASK & XCB_CONFIG_WINDOW_X ? applyUnScale(e->x) : XSURF->m_geometry.x, MASK & XCB_CONFIG_WINDOW_Y ? applyUnScale(e->y) : XSURF->m_geometry.y,
78+
MASK & XCB_CONFIG_WINDOW_WIDTH ? applyUnScale(e->width) : XSURF->m_geometry.width, MASK & XCB_CONFIG_WINDOW_HEIGHT ? applyUnScale(e->height) : XSURF->m_geometry.height});
7879
}
7980

8081
void CXWM::handleConfigureNotify(xcb_configure_notify_event_t* e) {
@@ -83,10 +84,11 @@ void CXWM::handleConfigureNotify(xcb_configure_notify_event_t* e) {
8384
if (!XSURF)
8485
return;
8586

86-
if (XSURF->m_geometry == CBox{e->x, e->y, e->width, e->height})
87+
const auto GEOM = CBox{applyUnScale(e->x), applyUnScale(e->y), applyUnScale(e->width), applyUnScale(e->height)};
88+
if (XSURF->m_geometry == GEOM)
8789
return;
8890

89-
XSURF->m_geometry = {e->x, e->y, e->width, e->height};
91+
XSURF->m_geometry = GEOM;
9092
updateOverrideRedirect(XSURF, e->override_redirect);
9193
XSURF->m_events.setGeometry.emit();
9294
}
@@ -273,6 +275,17 @@ void CXWM::readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_
273275
std::memset(XSURF->m_sizeHints.get(), 0, sizeof(xcb_size_hints_t));
274276
xcb_icccm_get_wm_size_hints_from_reply(XSURF->m_sizeHints.get(), reply);
275277

278+
XSURF->m_sizeHints->x = applyUnScale(XSURF->m_sizeHints->x);
279+
XSURF->m_sizeHints->y = applyUnScale(XSURF->m_sizeHints->y);
280+
XSURF->m_sizeHints->width = applyUnScale(XSURF->m_sizeHints->width);
281+
XSURF->m_sizeHints->height = applyUnScale(XSURF->m_sizeHints->height);
282+
XSURF->m_sizeHints->min_width = applyUnScale(XSURF->m_sizeHints->min_width);
283+
XSURF->m_sizeHints->min_height = applyUnScale(XSURF->m_sizeHints->min_height);
284+
XSURF->m_sizeHints->max_width = applyUnScale(XSURF->m_sizeHints->max_width);
285+
XSURF->m_sizeHints->max_height = applyUnScale(XSURF->m_sizeHints->max_height);
286+
XSURF->m_sizeHints->base_width = applyUnScale(XSURF->m_sizeHints->base_width);
287+
XSURF->m_sizeHints->base_height = applyUnScale(XSURF->m_sizeHints->base_height);
288+
276289
const int32_t FLAGS = XSURF->m_sizeHints->flags;
277290
const bool HASMIN = FLAGS & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE;
278291
const bool HASBASE = FLAGS & XCB_ICCCM_SIZE_HINT_BASE_SIZE;
@@ -328,8 +341,20 @@ void CXWM::readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_
328341
void CXWM::handlePropertyNotify(xcb_property_notify_event_t* e) {
329342
const auto XSURF = windowForXID(e->window);
330343

331-
if (!XSURF)
344+
if (!XSURF) {
345+
if (e->atom == HYPRATOMS["_XWAYLAND_GLOBAL_OUTPUT_SCALE"]) {
346+
xcb_get_property_cookie_t cookie = xcb_get_property(m_connection, 0, e->window, e->atom, XCB_ATOM_ANY, 0, 2048);
347+
xcb_get_property_reply_t* reply = xcb_get_property_reply(m_connection, cookie, nullptr);
348+
if (!reply) {
349+
return;
350+
}
351+
if (reply->type == XCB_ATOM_CARDINAL) {
352+
m_scale = *(uint32_t*)xcb_get_property_value(reply);
353+
}
354+
free(reply);
355+
}
332356
return;
357+
}
333358

334359
xcb_get_property_cookie_t cookie = xcb_get_property(m_connection, 0, XSURF->m_xID, e->atom, XCB_ATOM_ANY, 0, 2048);
335360
xcb_get_property_reply_t* reply = xcb_get_property_reply(m_connection, cookie, nullptr);
@@ -1355,6 +1380,18 @@ SP<IDataOffer> CXWM::createX11DataOffer(SP<CWLSurfaceResource> surf, SP<IDataSou
13551380
return offer;
13561381
}
13571382

1383+
double CXWM::getScale() {
1384+
return m_scale;
1385+
}
1386+
1387+
double CXWM::applyScale(double val) {
1388+
return std::floor(val * m_scale);
1389+
}
1390+
1391+
double CXWM::applyUnScale(double val) {
1392+
return std::ceil(val / m_scale);
1393+
}
1394+
13581395
void SXSelection::onSelection() {
13591396
const bool isClipboard = this == &g_pXWayland->m_wm->m_clipboard;
13601397
const bool isPrimary = this == &g_pXWayland->m_wm->m_primarySelection;

src/xwayland/XWM.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class CXWM {
112112
int onEvent(int fd, uint32_t mask);
113113
SP<CX11DataDevice> getDataDevice();
114114
SP<IDataOffer> createX11DataOffer(SP<CWLSurfaceResource> surf, SP<IDataSource> source);
115+
double getScale();
115116

116117
private:
117118
void setCursor(unsigned char* pixData, uint32_t stride, const Vector2D& size, const Vector2D& hotspot);
@@ -173,12 +174,16 @@ class CXWM {
173174

174175
SXSelection* getSelection(xcb_atom_t atom);
175176

177+
double applyScale(double val);
178+
double applyUnScale(double val);
179+
176180
//
177181
CXCBConnection m_connection;
178182
xcb_errors_context_t* m_errors = nullptr;
179183
xcb_screen_t* m_screen = nullptr;
180184

181185
xcb_window_t m_wmWindow;
186+
double m_scale = 1.0;
182187

183188
wl_event_source* m_eventSource = nullptr;
184189

src/xwayland/XWayland.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,6 @@ inline std::unordered_map<std::string, uint32_t> HYPRATOMS = {
127127
HYPRATOM("DELETE"),
128128
HYPRATOM("TEXT"),
129129
HYPRATOM("INCR"),
130+
HYPRATOM("_XWAYLAND_GLOBAL_OUTPUT_SCALE"),
130131
#endif
131132
};

0 commit comments

Comments
 (0)