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 /swaylock | |
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 'swaylock')
-rw-r--r-- | swaylock/main.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index 0637453c..075e44e7 100644 --- a/swaylock/main.c +++ b/swaylock/main.c | |||
@@ -223,58 +223,60 @@ void render_color(struct window *window, uint32_t color) { | |||
223 | void render_image(struct window *window, cairo_surface_t *image, enum scaling_mode scaling_mode) { | 223 | void render_image(struct window *window, cairo_surface_t *image, enum scaling_mode scaling_mode) { |
224 | double width = cairo_image_surface_get_width(image); | 224 | double width = cairo_image_surface_get_width(image); |
225 | double height = cairo_image_surface_get_height(image); | 225 | double height = cairo_image_surface_get_height(image); |
226 | int wwidth = window->width * window->scale; | ||
227 | int wheight = window->height * window->scale; | ||
226 | 228 | ||
227 | switch (scaling_mode) { | 229 | switch (scaling_mode) { |
228 | case SCALING_MODE_STRETCH: | 230 | case SCALING_MODE_STRETCH: |
229 | cairo_scale(window->cairo, | 231 | cairo_scale(window->cairo, |
230 | (double) window->width / width, | 232 | (double) wwidth / width, |
231 | (double) window->height / height); | 233 | (double) wheight / height); |
232 | cairo_set_source_surface(window->cairo, image, 0, 0); | 234 | cairo_set_source_surface(window->cairo, image, 0, 0); |
233 | break; | 235 | break; |
234 | case SCALING_MODE_FILL: | 236 | case SCALING_MODE_FILL: |
235 | { | 237 | { |
236 | double window_ratio = (double) window->width / window->height; | 238 | double window_ratio = (double) wwidth / wheight; |
237 | double bg_ratio = width / height; | 239 | double bg_ratio = wheight; |
238 | 240 | ||
239 | if (window_ratio > bg_ratio) { | 241 | if (window_ratio > bg_ratio) { |
240 | double scale = (double) window->width / width; | 242 | double scale = (double) wwidth / width; |
241 | cairo_scale(window->cairo, scale, scale); | 243 | cairo_scale(window->cairo, scale, scale); |
242 | cairo_set_source_surface(window->cairo, image, | 244 | cairo_set_source_surface(window->cairo, image, |
243 | 0, | 245 | 0, |
244 | (double) window->height/2 / scale - height/2); | 246 | (double) wheight/2 / scale - height/2); |
245 | } else { | 247 | } else { |
246 | double scale = (double) window->height / height; | 248 | double scale = (double) wheight / height; |
247 | cairo_scale(window->cairo, scale, scale); | 249 | cairo_scale(window->cairo, scale, scale); |
248 | cairo_set_source_surface(window->cairo, image, | 250 | cairo_set_source_surface(window->cairo, image, |
249 | (double) window->width/2 / scale - width/2, | 251 | (double) wwidth/2 / scale - width/2, |
250 | 0); | 252 | 0); |
251 | } | 253 | } |
252 | break; | 254 | break; |
253 | } | 255 | } |
254 | case SCALING_MODE_FIT: | 256 | case SCALING_MODE_FIT: |
255 | { | 257 | { |
256 | double window_ratio = (double) window->width / window->height; | 258 | double window_ratio = (double) wwidth / wheight; |
257 | double bg_ratio = width / height; | 259 | double bg_ratio = width / height; |
258 | 260 | ||
259 | if (window_ratio > bg_ratio) { | 261 | if (window_ratio > bg_ratio) { |
260 | double scale = (double) window->height / height; | 262 | double scale = (double) wheight / height; |
261 | cairo_scale(window->cairo, scale, scale); | 263 | cairo_scale(window->cairo, scale, scale); |
262 | cairo_set_source_surface(window->cairo, image, | 264 | cairo_set_source_surface(window->cairo, image, |
263 | (double) window->width/2 / scale - width/2, | 265 | (double) wwidth/2 / scale - width/2, |
264 | 0); | 266 | 0); |
265 | } else { | 267 | } else { |
266 | double scale = (double) window->width / width; | 268 | double scale = (double) wwidth / width; |
267 | cairo_scale(window->cairo, scale, scale); | 269 | cairo_scale(window->cairo, scale, scale); |
268 | cairo_set_source_surface(window->cairo, image, | 270 | cairo_set_source_surface(window->cairo, image, |
269 | 0, | 271 | 0, |
270 | (double) window->height/2 / scale - height/2); | 272 | (double) wheight/2 / scale - height/2); |
271 | } | 273 | } |
272 | break; | 274 | break; |
273 | } | 275 | } |
274 | case SCALING_MODE_CENTER: | 276 | case SCALING_MODE_CENTER: |
275 | cairo_set_source_surface(window->cairo, image, | 277 | cairo_set_source_surface(window->cairo, image, |
276 | (double) window->width/2 - width/2, | 278 | (double) wwidth/2 - width/2, |
277 | (double) window->height/2 - height/2); | 279 | (double) wheight/2 - height/2); |
278 | break; | 280 | break; |
279 | case SCALING_MODE_TILE: | 281 | case SCALING_MODE_TILE: |
280 | { | 282 | { |
@@ -477,7 +479,8 @@ int main(int argc, char **argv) { | |||
477 | 479 | ||
478 | for (i = 0; i < registry->outputs->length; ++i) { | 480 | for (i = 0; i < registry->outputs->length; ++i) { |
479 | struct output_state *output = registry->outputs->items[i]; | 481 | struct output_state *output = registry->outputs->items[i]; |
480 | struct window *window = window_setup(registry, output->width, output->height, true); | 482 | struct window *window = window_setup(registry, |
483 | output->width, output->height, output->scale, true); | ||
481 | if (!window) { | 484 | if (!window) { |
482 | sway_abort("Failed to create surfaces."); | 485 | sway_abort("Failed to create surfaces."); |
483 | } | 486 | } |
@@ -564,6 +567,8 @@ void render(struct render_data *render_data) { | |||
564 | if (!window_prerender(window) || !window->cairo) { | 567 | if (!window_prerender(window) || !window->cairo) { |
565 | continue; | 568 | continue; |
566 | } | 569 | } |
570 | int wwidth = window->width * window->scale; | ||
571 | int wheight = window->height * window->scale; | ||
567 | 572 | ||
568 | // Reset the transformation matrix | 573 | // Reset the transformation matrix |
569 | cairo_identity_matrix(window->cairo); | 574 | cairo_identity_matrix(window->cairo); |
@@ -595,7 +600,7 @@ void render(struct render_data *render_data) { | |||
595 | if (show_indicator && render_data->auth_state != AUTH_STATE_IDLE) { | 600 | if (show_indicator && render_data->auth_state != AUTH_STATE_IDLE) { |
596 | // Draw circle | 601 | // Draw circle |
597 | cairo_set_line_width(window->cairo, ARC_THICKNESS); | 602 | cairo_set_line_width(window->cairo, ARC_THICKNESS); |
598 | cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS, 0, 2 * M_PI); | 603 | cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, 0, 2 * M_PI); |
599 | switch (render_data->auth_state) { | 604 | switch (render_data->auth_state) { |
600 | case AUTH_STATE_INPUT: | 605 | case AUTH_STATE_INPUT: |
601 | case AUTH_STATE_BACKSPACE: { | 606 | case AUTH_STATE_BACKSPACE: { |
@@ -638,8 +643,8 @@ void render(struct render_data *render_data) { | |||
638 | double x, y; | 643 | double x, y; |
639 | 644 | ||
640 | cairo_text_extents(window->cairo, text, &extents); | 645 | cairo_text_extents(window->cairo, text, &extents); |
641 | x = window->width/2 - ((extents.width/2) + extents.x_bearing); | 646 | x = wwidth/2 - ((extents.width/2) + extents.x_bearing); |
642 | y = window->height/2 - ((extents.height/2) + extents.y_bearing); | 647 | y = wheight/2 - ((extents.height/2) + extents.y_bearing); |
643 | 648 | ||
644 | cairo_move_to(window->cairo, x, y); | 649 | cairo_move_to(window->cairo, x, y); |
645 | cairo_show_text(window->cairo, text); | 650 | cairo_show_text(window->cairo, text); |
@@ -651,7 +656,7 @@ void render(struct render_data *render_data) { | |||
651 | if (render_data->auth_state == AUTH_STATE_INPUT || render_data->auth_state == AUTH_STATE_BACKSPACE) { | 656 | if (render_data->auth_state == AUTH_STATE_INPUT || render_data->auth_state == AUTH_STATE_BACKSPACE) { |
652 | static double highlight_start = 0; | 657 | static double highlight_start = 0; |
653 | highlight_start += (rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5; | 658 | highlight_start += (rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5; |
654 | cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS, highlight_start, highlight_start + TYPE_INDICATOR_RANGE); | 659 | cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, highlight_start, highlight_start + TYPE_INDICATOR_RANGE); |
655 | if (render_data->auth_state == AUTH_STATE_INPUT) { | 660 | if (render_data->auth_state == AUTH_STATE_INPUT) { |
656 | cairo_set_source_rgb(window->cairo, 51.0 / 255, 219.0 / 255, 0); | 661 | cairo_set_source_rgb(window->cairo, 51.0 / 255, 219.0 / 255, 0); |
657 | } else { | 662 | } else { |
@@ -661,19 +666,19 @@ void render(struct render_data *render_data) { | |||
661 | 666 | ||
662 | // Draw borders | 667 | // Draw borders |
663 | cairo_set_source_rgb(window->cairo, 0, 0, 0); | 668 | cairo_set_source_rgb(window->cairo, 0, 0, 0); |
664 | cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS, highlight_start, highlight_start + TYPE_INDICATOR_BORDER_THICKNESS); | 669 | cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, highlight_start, highlight_start + TYPE_INDICATOR_BORDER_THICKNESS); |
665 | cairo_stroke(window->cairo); | 670 | cairo_stroke(window->cairo); |
666 | 671 | ||
667 | cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS, highlight_start + TYPE_INDICATOR_RANGE, (highlight_start + TYPE_INDICATOR_RANGE) + TYPE_INDICATOR_BORDER_THICKNESS); | 672 | cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, highlight_start + TYPE_INDICATOR_RANGE, (highlight_start + TYPE_INDICATOR_RANGE) + TYPE_INDICATOR_BORDER_THICKNESS); |
668 | cairo_stroke(window->cairo); | 673 | cairo_stroke(window->cairo); |
669 | } | 674 | } |
670 | 675 | ||
671 | // Draw inner + outer border of the circle | 676 | // Draw inner + outer border of the circle |
672 | cairo_set_source_rgb(window->cairo, 0, 0, 0); | 677 | cairo_set_source_rgb(window->cairo, 0, 0, 0); |
673 | cairo_set_line_width(window->cairo, 2.0); | 678 | cairo_set_line_width(window->cairo, 2.0); |
674 | cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS - ARC_THICKNESS/2, 0, 2*M_PI); | 679 | cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS - ARC_THICKNESS/2, 0, 2*M_PI); |
675 | cairo_stroke(window->cairo); | 680 | cairo_stroke(window->cairo); |
676 | cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS + ARC_THICKNESS/2, 0, 2*M_PI); | 681 | cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS + ARC_THICKNESS/2, 0, 2*M_PI); |
677 | cairo_stroke(window->cairo); | 682 | cairo_stroke(window->cairo); |
678 | } | 683 | } |
679 | window_render(window); | 684 | window_render(window); |