mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-03-30 11:11:21 -04:00
xwayland: add support for global scale factor
This does the necessary changes to support HiDPI in xwayland applications, with the following xwayland patch: https://gitlab.freedesktop.org/xorg/xserver/merge_requests/111
This commit is contained in:
parent
61d6408fdb
commit
9bd9089045
3 changed files with 41 additions and 11 deletions
|
|
@ -30,6 +30,8 @@ struct wlr_xwayland {
|
||||||
|
|
||||||
time_t server_start;
|
time_t server_start;
|
||||||
|
|
||||||
|
int32_t scale;
|
||||||
|
|
||||||
/* Anything above display is reset on Xwayland restart, rest is conserved */
|
/* Anything above display is reset on Xwayland restart, rest is conserved */
|
||||||
|
|
||||||
int display;
|
int display;
|
||||||
|
|
@ -205,6 +207,8 @@ struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display,
|
||||||
|
|
||||||
void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland);
|
void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland);
|
||||||
|
|
||||||
|
void wlr_xwayland_set_scale(struct wlr_xwayland *wlr_xwayland, int32_t scale);
|
||||||
|
|
||||||
void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland,
|
void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland,
|
||||||
uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height,
|
uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height,
|
||||||
int32_t hotspot_x, int32_t hotspot_y);
|
int32_t hotspot_x, int32_t hotspot_y);
|
||||||
|
|
|
||||||
|
|
@ -409,6 +409,8 @@ struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display,
|
||||||
wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1;
|
wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1;
|
||||||
wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1;
|
wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1;
|
||||||
|
|
||||||
|
wlr_xwayland->scale = 1;
|
||||||
|
|
||||||
wl_signal_init(&wlr_xwayland->events.new_surface);
|
wl_signal_init(&wlr_xwayland->events.new_surface);
|
||||||
wl_signal_init(&wlr_xwayland->events.ready);
|
wl_signal_init(&wlr_xwayland->events.ready);
|
||||||
|
|
||||||
|
|
@ -436,6 +438,10 @@ error_alloc:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wlr_xwayland_set_scale(struct wlr_xwayland *wlr_xwayland, int32_t scale) {
|
||||||
|
wlr_xwayland->scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland,
|
void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland,
|
||||||
uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height,
|
uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height,
|
||||||
int32_t hotspot_x, int32_t hotspot_y) {
|
int32_t hotspot_x, int32_t hotspot_y) {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,15 @@
|
||||||
#include "util/signal.h"
|
#include "util/signal.h"
|
||||||
#include "xwayland/xwm.h"
|
#include "xwayland/xwm.h"
|
||||||
|
|
||||||
|
|
||||||
|
static int32_t scale(struct wlr_xwm *xwm, int32_t val) {
|
||||||
|
return val * xwm->xwayland->scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t unscale(struct wlr_xwm *xwm, int32_t val) {
|
||||||
|
return (val + xwm->xwayland->scale/2) / xwm->xwayland->scale;
|
||||||
|
}
|
||||||
|
|
||||||
const char *atom_map[ATOM_LAST] = {
|
const char *atom_map[ATOM_LAST] = {
|
||||||
[WL_SURFACE_ID] = "WL_SURFACE_ID",
|
[WL_SURFACE_ID] = "WL_SURFACE_ID",
|
||||||
[WM_DELETE_WINDOW] = "WM_DELETE_WINDOW",
|
[WM_DELETE_WINDOW] = "WM_DELETE_WINDOW",
|
||||||
|
|
@ -834,8 +843,13 @@ static void xwm_handle_create_notify(struct wlr_xwm *xwm,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xwayland_surface_create(xwm, ev->window, ev->x, ev->y,
|
xwayland_surface_create(xwm, ev->window,
|
||||||
ev->width, ev->height, ev->override_redirect);
|
unscale(xwm, ev->x),
|
||||||
|
unscale(xwm, ev->y),
|
||||||
|
unscale(xwm, ev->width),
|
||||||
|
unscale(xwm, ev->height),
|
||||||
|
ev->override_redirect
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xwm_handle_destroy_notify(struct wlr_xwm *xwm,
|
static void xwm_handle_destroy_notify(struct wlr_xwm *xwm,
|
||||||
|
|
@ -866,10 +880,10 @@ static void xwm_handle_configure_request(struct wlr_xwm *xwm,
|
||||||
|
|
||||||
struct wlr_xwayland_surface_configure_event wlr_event = {
|
struct wlr_xwayland_surface_configure_event wlr_event = {
|
||||||
.surface = surface,
|
.surface = surface,
|
||||||
.x = mask & XCB_CONFIG_WINDOW_X ? ev->x : surface->x,
|
.x = unscale(xwm, mask & XCB_CONFIG_WINDOW_X ? ev->x : surface->x),
|
||||||
.y = mask & XCB_CONFIG_WINDOW_Y ? ev->y : surface->y,
|
.y = unscale(xwm, mask & XCB_CONFIG_WINDOW_Y ? ev->y : surface->y),
|
||||||
.width = mask & XCB_CONFIG_WINDOW_WIDTH ? ev->width : surface->width,
|
.width = unscale(xwm, mask & XCB_CONFIG_WINDOW_WIDTH ? ev->width : surface->width),
|
||||||
.height = mask & XCB_CONFIG_WINDOW_HEIGHT ? ev->height : surface->height,
|
.height = unscale(xwm, mask & XCB_CONFIG_WINDOW_HEIGHT ? ev->height : surface->height),
|
||||||
.mask = mask,
|
.mask = mask,
|
||||||
};
|
};
|
||||||
wlr_log(WLR_DEBUG, "XCB_CONFIGURE_REQUEST (%u) [%ux%u+%d,%d]", ev->window,
|
wlr_log(WLR_DEBUG, "XCB_CONFIGURE_REQUEST (%u) [%ux%u+%d,%d]", ev->window,
|
||||||
|
|
@ -885,10 +899,10 @@ static void xwm_handle_configure_notify(struct wlr_xwm *xwm,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xsurface->x = ev->x;
|
xsurface->x = unscale(xwm, ev->x);
|
||||||
xsurface->y = ev->y;
|
xsurface->y = unscale(xwm, ev->y);
|
||||||
xsurface->width = ev->width;
|
xsurface->width = unscale(xwm, ev->width);
|
||||||
xsurface->height = ev->height;
|
xsurface->height = unscale(xwm, ev->height);
|
||||||
|
|
||||||
if (xsurface->override_redirect != ev->override_redirect) {
|
if (xsurface->override_redirect != ev->override_redirect) {
|
||||||
xsurface->override_redirect = ev->override_redirect;
|
xsurface->override_redirect = ev->override_redirect;
|
||||||
|
|
@ -1431,7 +1445,13 @@ void wlr_xwayland_surface_configure(struct wlr_xwayland_surface *xsurface,
|
||||||
uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
|
uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
|
||||||
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
|
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
|
||||||
XCB_CONFIG_WINDOW_BORDER_WIDTH;
|
XCB_CONFIG_WINDOW_BORDER_WIDTH;
|
||||||
uint32_t values[] = {x, y, width, height, 0};
|
uint32_t values[] = {
|
||||||
|
scale(xsurface->xwm, x),
|
||||||
|
scale(xsurface->xwm, y),
|
||||||
|
scale(xsurface->xwm, width),
|
||||||
|
scale(xsurface->xwm, height),
|
||||||
|
0,
|
||||||
|
};
|
||||||
xcb_configure_window(xwm->xcb_conn, xsurface->window_id, mask, values);
|
xcb_configure_window(xwm->xcb_conn, xsurface->window_id, mask, values);
|
||||||
xcb_flush(xwm->xcb_conn);
|
xcb_flush(xwm->xcb_conn);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue