summaryrefslogtreecommitdiff
path: root/wayland
diff options
context:
space:
mode:
authorDrew DeVault <[email protected]>2016-09-05 11:36:48 -0400
committerDrew DeVault <[email protected]>2016-09-05 11:36:48 -0400
commitb2226ac6551f18275fadbcb3bc16a06d2a3dd97f (patch)
tree65628cb83abaa546c5f0e2cd8949c55aacb40360 /wayland
parent61184e3208c28b24a84aae5f5f0005311283826d (diff)
Add client support for HiDPI
This adds HiDPI support to swaybar, swaybg, and swaylock.
Diffstat (limited to 'wayland')
-rw-r--r--wayland/buffers.c15
-rw-r--r--wayland/pango.c4
-rw-r--r--wayland/registry.c3
-rw-r--r--wayland/window.c14
4 files changed, 27 insertions, 9 deletions
diff --git a/wayland/buffers.c b/wayland/buffers.c
index ff1e5ecf..227d6d2c 100644
--- a/wayland/buffers.c
+++ b/wayland/buffers.c
@@ -50,8 +50,10 @@ static const struct wl_buffer_listener buffer_listener = {
};
static struct buffer *create_buffer(struct window *window, struct buffer *buf,
- int32_t width, int32_t height, uint32_t format) {
+ int32_t width, int32_t height, int32_t scale, uint32_t format) {
+ width *= scale;
+ height *= scale;
uint32_t stride = width * 4;
uint32_t size = stride * height;
@@ -63,7 +65,8 @@ static struct buffer *create_buffer(struct window *window, struct buffer *buf,
}
void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
struct wl_shm_pool *pool = wl_shm_create_pool(window->registry->shm, fd, size);
- buf->buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, format);
+ buf->buffer = wl_shm_pool_create_buffer(pool, 0,
+ width, height, stride, format);
wl_shm_pool_destroy(pool);
close(fd);
unlink(name);
@@ -72,10 +75,10 @@ static struct buffer *create_buffer(struct window *window, struct buffer *buf,
buf->width = width;
buf->height = height;
- buf->surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride);
+ buf->surface = cairo_image_surface_create_for_data(data,
+ CAIRO_FORMAT_ARGB32, width, height, stride);
buf->cairo = cairo_create(buf->surface);
buf->pango = pango_cairo_create_context(buf->cairo);
- pango_cairo_context_set_resolution(buf->pango, 96 * 2);
wl_buffer_add_listener(buf->buffer, &buffer_listener, buf);
return buf;
@@ -114,7 +117,9 @@ struct buffer *get_next_buffer(struct window *window) {
}
if (!buffer->buffer) {
- if (!create_buffer(window, buffer, window->width, window->height, WL_SHM_FORMAT_ARGB8888)) {
+ if (!create_buffer(window, buffer,
+ window->width, window->height, window->scale,
+ WL_SHM_FORMAT_ARGB8888)) {
return NULL;
}
}
diff --git a/wayland/pango.c b/wayland/pango.c
index f143aa6c..d601021f 100644
--- a/wayland/pango.c
+++ b/wayland/pango.c
@@ -9,6 +9,8 @@
PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text, bool markup) {
PangoLayout *layout = pango_cairo_create_layout(cairo);
+ PangoAttrList *attrs = pango_attr_list_new();
+ pango_attr_list_insert(attrs, pango_attr_scale_new(2));
if (markup) {
pango_layout_set_markup(layout, text, -1);
} else {
@@ -17,6 +19,8 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text
PangoFontDescription *desc = pango_font_description_from_string(font);
pango_layout_set_font_description(layout, desc);
pango_layout_set_single_paragraph_mode(layout, 1);
+ pango_layout_set_attributes(layout, attrs);
+ pango_attr_list_unref(attrs);
pango_font_description_free(desc);
return layout;
}
diff --git a/wayland/registry.c b/wayland/registry.c
index 2d66b7eb..44afb146 100644
--- a/wayland/registry.c
+++ b/wayland/registry.c
@@ -18,6 +18,8 @@ static void display_handle_mode(void *data, struct wl_output *wl_output,
state->flags = flags;
state->width = width;
state->height = height;
+ sway_log(L_DEBUG, "Got mode %dx%x:0x%X for output %p",
+ width, height, flags, data);
}
}
@@ -34,6 +36,7 @@ static void display_handle_done(void *data, struct wl_output *wl_output) {
static void display_handle_scale(void *data, struct wl_output *wl_output, int32_t factor) {
struct output_state *state = data;
state->scale = factor;
+ sway_log(L_DEBUG, "Got scale factor %d for output %p", factor, data);
}
static const struct wl_output_listener output_listener = {
diff --git a/wayland/window.c b/wayland/window.c
index 3f48d39f..8a506656 100644
--- a/wayland/window.c
+++ b/wayland/window.c
@@ -93,11 +93,13 @@ void window_make_shell(struct window *window) {
wl_shell_surface_set_toplevel(window->shell_surface);
}
-struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height, bool shell_surface) {
+struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height,
+ int32_t scale, bool shell_surface) {
struct window *window = malloc(sizeof(struct window));
memset(window, 0, sizeof(struct window));
window->width = width;
window->height = height;
+ window->scale = scale;
window->registry = registry;
window->font = "monospace 10";
@@ -121,15 +123,18 @@ struct window *window_setup(struct registry *registry, uint32_t width, uint32_t
cursor_size = "16";
}
+ sway_log(L_DEBUG, "Cursor scale: %d", scale);
window->cursor.cursor_theme = wl_cursor_theme_load(cursor_theme,
- atoi(cursor_size), registry->shm);
+ atoi(cursor_size) * scale, registry->shm);
window->cursor.cursor = wl_cursor_theme_get_cursor(window->cursor.cursor_theme, "left_ptr");
window->cursor.surface = wl_compositor_create_surface(registry->compositor);
struct wl_cursor_image *image = window->cursor.cursor->images[0];
struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image);
wl_surface_attach(window->cursor.surface, cursor_buf, 0, 0);
- wl_surface_damage(window->cursor.surface, 0, 0, image->width, image->height);
+ wl_surface_set_buffer_scale(window->cursor.surface, scale);
+ wl_surface_damage(window->cursor.surface, 0, 0,
+ image->width, image->height);
wl_surface_commit(window->cursor.surface);
}
@@ -159,8 +164,9 @@ int window_render(struct window *window) {
window->frame_cb = wl_surface_frame(window->surface);
wl_callback_add_listener(window->frame_cb, &listener, window);
- wl_surface_damage(window->surface, 0, 0, window->buffer->width, window->buffer->height);
wl_surface_attach(window->surface, window->buffer->buffer, 0, 0);
+ wl_surface_set_buffer_scale(window->surface, window->scale);
+ wl_surface_damage(window->surface, 0, 0, window->width, window->height);
wl_surface_commit(window->surface);
return 1;