diff options
author | Drew DeVault <ddevault@linode.com> | 2016-09-05 11:36:48 -0400 |
---|---|---|
committer | Drew DeVault <ddevault@linode.com> | 2016-09-05 11:36:48 -0400 |
commit | b2226ac6551f18275fadbcb3bc16a06d2a3dd97f (patch) | |
tree | 65628cb83abaa546c5f0e2cd8949c55aacb40360 /wayland | |
parent | Initial testing on hidpi clients (diff) | |
download | sway-b2226ac6551f18275fadbcb3bc16a06d2a3dd97f.tar.gz sway-b2226ac6551f18275fadbcb3bc16a06d2a3dd97f.tar.zst sway-b2226ac6551f18275fadbcb3bc16a06d2a3dd97f.zip |
Add client support for HiDPI
This adds HiDPI support to swaybar, swaybg, and swaylock.
Diffstat (limited to 'wayland')
-rw-r--r-- | wayland/buffers.c | 15 | ||||
-rw-r--r-- | wayland/pango.c | 4 | ||||
-rw-r--r-- | wayland/registry.c | 3 | ||||
-rw-r--r-- | wayland/window.c | 14 |
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 = { | |||
50 | }; | 50 | }; |
51 | 51 | ||
52 | static struct buffer *create_buffer(struct window *window, struct buffer *buf, | 52 | static struct buffer *create_buffer(struct window *window, struct buffer *buf, |
53 | int32_t width, int32_t height, uint32_t format) { | 53 | int32_t width, int32_t height, int32_t scale, uint32_t format) { |
54 | 54 | ||
55 | width *= scale; | ||
56 | height *= scale; | ||
55 | uint32_t stride = width * 4; | 57 | uint32_t stride = width * 4; |
56 | uint32_t size = stride * height; | 58 | uint32_t size = stride * height; |
57 | 59 | ||
@@ -63,7 +65,8 @@ static struct buffer *create_buffer(struct window *window, struct buffer *buf, | |||
63 | } | 65 | } |
64 | void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | 66 | void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
65 | struct wl_shm_pool *pool = wl_shm_create_pool(window->registry->shm, fd, size); | 67 | struct wl_shm_pool *pool = wl_shm_create_pool(window->registry->shm, fd, size); |
66 | buf->buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, format); | 68 | buf->buffer = wl_shm_pool_create_buffer(pool, 0, |
69 | width, height, stride, format); | ||
67 | wl_shm_pool_destroy(pool); | 70 | wl_shm_pool_destroy(pool); |
68 | close(fd); | 71 | close(fd); |
69 | unlink(name); | 72 | unlink(name); |
@@ -72,10 +75,10 @@ static struct buffer *create_buffer(struct window *window, struct buffer *buf, | |||
72 | 75 | ||
73 | buf->width = width; | 76 | buf->width = width; |
74 | buf->height = height; | 77 | buf->height = height; |
75 | buf->surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride); | 78 | buf->surface = cairo_image_surface_create_for_data(data, |
79 | CAIRO_FORMAT_ARGB32, width, height, stride); | ||
76 | buf->cairo = cairo_create(buf->surface); | 80 | buf->cairo = cairo_create(buf->surface); |
77 | buf->pango = pango_cairo_create_context(buf->cairo); | 81 | buf->pango = pango_cairo_create_context(buf->cairo); |
78 | pango_cairo_context_set_resolution(buf->pango, 96 * 2); | ||
79 | 82 | ||
80 | wl_buffer_add_listener(buf->buffer, &buffer_listener, buf); | 83 | wl_buffer_add_listener(buf->buffer, &buffer_listener, buf); |
81 | return buf; | 84 | return buf; |
@@ -114,7 +117,9 @@ struct buffer *get_next_buffer(struct window *window) { | |||
114 | } | 117 | } |
115 | 118 | ||
116 | if (!buffer->buffer) { | 119 | if (!buffer->buffer) { |
117 | if (!create_buffer(window, buffer, window->width, window->height, WL_SHM_FORMAT_ARGB8888)) { | 120 | if (!create_buffer(window, buffer, |
121 | window->width, window->height, window->scale, | ||
122 | WL_SHM_FORMAT_ARGB8888)) { | ||
118 | return NULL; | 123 | return NULL; |
119 | } | 124 | } |
120 | } | 125 | } |
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 @@ | |||
9 | 9 | ||
10 | PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text, bool markup) { | 10 | PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text, bool markup) { |
11 | PangoLayout *layout = pango_cairo_create_layout(cairo); | 11 | PangoLayout *layout = pango_cairo_create_layout(cairo); |
12 | PangoAttrList *attrs = pango_attr_list_new(); | ||
13 | pango_attr_list_insert(attrs, pango_attr_scale_new(2)); | ||
12 | if (markup) { | 14 | if (markup) { |
13 | pango_layout_set_markup(layout, text, -1); | 15 | pango_layout_set_markup(layout, text, -1); |
14 | } else { | 16 | } else { |
@@ -17,6 +19,8 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text | |||
17 | PangoFontDescription *desc = pango_font_description_from_string(font); | 19 | PangoFontDescription *desc = pango_font_description_from_string(font); |
18 | pango_layout_set_font_description(layout, desc); | 20 | pango_layout_set_font_description(layout, desc); |
19 | pango_layout_set_single_paragraph_mode(layout, 1); | 21 | pango_layout_set_single_paragraph_mode(layout, 1); |
22 | pango_layout_set_attributes(layout, attrs); | ||
23 | pango_attr_list_unref(attrs); | ||
20 | pango_font_description_free(desc); | 24 | pango_font_description_free(desc); |
21 | return layout; | 25 | return layout; |
22 | } | 26 | } |
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, | |||
18 | state->flags = flags; | 18 | state->flags = flags; |
19 | state->width = width; | 19 | state->width = width; |
20 | state->height = height; | 20 | state->height = height; |
21 | sway_log(L_DEBUG, "Got mode %dx%x:0x%X for output %p", | ||
22 | width, height, flags, data); | ||
21 | } | 23 | } |
22 | } | 24 | } |
23 | 25 | ||
@@ -34,6 +36,7 @@ static void display_handle_done(void *data, struct wl_output *wl_output) { | |||
34 | static void display_handle_scale(void *data, struct wl_output *wl_output, int32_t factor) { | 36 | static void display_handle_scale(void *data, struct wl_output *wl_output, int32_t factor) { |
35 | struct output_state *state = data; | 37 | struct output_state *state = data; |
36 | state->scale = factor; | 38 | state->scale = factor; |
39 | sway_log(L_DEBUG, "Got scale factor %d for output %p", factor, data); | ||
37 | } | 40 | } |
38 | 41 | ||
39 | static const struct wl_output_listener output_listener = { | 42 | 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) { | |||
93 | wl_shell_surface_set_toplevel(window->shell_surface); | 93 | wl_shell_surface_set_toplevel(window->shell_surface); |
94 | } | 94 | } |
95 | 95 | ||
96 | struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height, bool shell_surface) { | 96 | struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height, |
97 | int32_t scale, bool shell_surface) { | ||
97 | struct window *window = malloc(sizeof(struct window)); | 98 | struct window *window = malloc(sizeof(struct window)); |
98 | memset(window, 0, sizeof(struct window)); | 99 | memset(window, 0, sizeof(struct window)); |
99 | window->width = width; | 100 | window->width = width; |
100 | window->height = height; | 101 | window->height = height; |
102 | window->scale = scale; | ||
101 | window->registry = registry; | 103 | window->registry = registry; |
102 | window->font = "monospace 10"; | 104 | window->font = "monospace 10"; |
103 | 105 | ||
@@ -121,15 +123,18 @@ struct window *window_setup(struct registry *registry, uint32_t width, uint32_t | |||
121 | cursor_size = "16"; | 123 | cursor_size = "16"; |
122 | } | 124 | } |
123 | 125 | ||
126 | sway_log(L_DEBUG, "Cursor scale: %d", scale); | ||
124 | window->cursor.cursor_theme = wl_cursor_theme_load(cursor_theme, | 127 | window->cursor.cursor_theme = wl_cursor_theme_load(cursor_theme, |
125 | atoi(cursor_size), registry->shm); | 128 | atoi(cursor_size) * scale, registry->shm); |
126 | window->cursor.cursor = wl_cursor_theme_get_cursor(window->cursor.cursor_theme, "left_ptr"); | 129 | window->cursor.cursor = wl_cursor_theme_get_cursor(window->cursor.cursor_theme, "left_ptr"); |
127 | window->cursor.surface = wl_compositor_create_surface(registry->compositor); | 130 | window->cursor.surface = wl_compositor_create_surface(registry->compositor); |
128 | 131 | ||
129 | struct wl_cursor_image *image = window->cursor.cursor->images[0]; | 132 | struct wl_cursor_image *image = window->cursor.cursor->images[0]; |
130 | struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image); | 133 | struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image); |
131 | wl_surface_attach(window->cursor.surface, cursor_buf, 0, 0); | 134 | wl_surface_attach(window->cursor.surface, cursor_buf, 0, 0); |
132 | wl_surface_damage(window->cursor.surface, 0, 0, image->width, image->height); | 135 | wl_surface_set_buffer_scale(window->cursor.surface, scale); |
136 | wl_surface_damage(window->cursor.surface, 0, 0, | ||
137 | image->width, image->height); | ||
133 | wl_surface_commit(window->cursor.surface); | 138 | wl_surface_commit(window->cursor.surface); |
134 | } | 139 | } |
135 | 140 | ||
@@ -159,8 +164,9 @@ int window_render(struct window *window) { | |||
159 | window->frame_cb = wl_surface_frame(window->surface); | 164 | window->frame_cb = wl_surface_frame(window->surface); |
160 | wl_callback_add_listener(window->frame_cb, &listener, window); | 165 | wl_callback_add_listener(window->frame_cb, &listener, window); |
161 | 166 | ||
162 | wl_surface_damage(window->surface, 0, 0, window->buffer->width, window->buffer->height); | ||
163 | wl_surface_attach(window->surface, window->buffer->buffer, 0, 0); | 167 | wl_surface_attach(window->surface, window->buffer->buffer, 0, 0); |
168 | wl_surface_set_buffer_scale(window->surface, window->scale); | ||
169 | wl_surface_damage(window->surface, 0, 0, window->width, window->height); | ||
164 | wl_surface_commit(window->surface); | 170 | wl_surface_commit(window->surface); |
165 | 171 | ||
166 | return 1; | 172 | return 1; |