aboutsummaryrefslogtreecommitdiff
path: root/swaybg/main.c
diff options
context:
space:
mode:
authorDrew DeVault <ddevault@linode.com>2016-09-05 11:36:48 -0400
committerDrew DeVault <ddevault@linode.com>2016-09-05 11:36:48 -0400
commitb2226ac6551f18275fadbcb3bc16a06d2a3dd97f (patch)
tree65628cb83abaa546c5f0e2cd8949c55aacb40360 /swaybg/main.c
parent61184e3208c28b24a84aae5f5f0005311283826d (diff)
Add client support for HiDPI
This adds HiDPI support to swaybar, swaybg, and swaylock.
Diffstat (limited to 'swaybg/main.c')
-rw-r--r--swaybg/main.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/swaybg/main.c b/swaybg/main.c
index b23b8027..9dba0c8f 100644
--- a/swaybg/main.c
+++ b/swaybg/main.c
@@ -69,7 +69,8 @@ int main(int argc, const char **argv) {
sway_log(L_INFO, "Using output %d of %d", desired_output, registry->outputs->length);
int i;
struct output_state *output = registry->outputs->items[desired_output];
- struct window *window = window_setup(registry, output->width, output->height, false);
+ struct window *window = window_setup(registry,
+ output->width, output->height, output->scale, false);
if (!window) {
sway_abort("Failed to create surfaces.");
}
@@ -115,60 +116,63 @@ int main(int argc, const char **argv) {
sway_abort("Unsupported scaling mode: %s", scaling_mode_str);
}
+ int wwidth = window->width * window->scale;
+ int wheight = window->height * window->scale;
+
for (i = 0; i < surfaces->length; ++i) {
struct window *window = surfaces->items[i];
if (window_prerender(window) && window->cairo) {
switch (scaling_mode) {
case SCALING_MODE_STRETCH:
cairo_scale(window->cairo,
- (double) window->width / width,
- (double) window->height / height);
+ (double) wwidth / width,
+ (double) wheight / height);
cairo_set_source_surface(window->cairo, image, 0, 0);
break;
case SCALING_MODE_FILL:
{
- double window_ratio = (double) window->width / window->height;
+ double window_ratio = (double) wwidth / wheight;
double bg_ratio = width / height;
if (window_ratio > bg_ratio) {
- double scale = (double) window->width / width;
+ double scale = (double) wwidth / width;
cairo_scale(window->cairo, scale, scale);
cairo_set_source_surface(window->cairo, image,
0,
- (double) window->height/2 / scale - height/2);
+ (double) wheight/2 / scale - height/2);
} else {
- double scale = (double) window->height / height;
+ double scale = (double) wheight / height;
cairo_scale(window->cairo, scale, scale);
cairo_set_source_surface(window->cairo, image,
- (double) window->width/2 / scale - width/2,
+ (double) wwidth/2 / scale - width/2,
0);
}
break;
}
case SCALING_MODE_FIT:
{
- double window_ratio = (double) window->width / window->height;
+ double window_ratio = (double) wwidth / wheight;
double bg_ratio = width / height;
if (window_ratio > bg_ratio) {
- double scale = (double) window->height / height;
+ double scale = (double) wheight / height;
cairo_scale(window->cairo, scale, scale);
cairo_set_source_surface(window->cairo, image,
- (double) window->width/2 / scale - width/2,
+ (double) wwidth/2 / scale - width/2,
0);
} else {
- double scale = (double) window->width / width;
+ double scale = (double) wwidth / width;
cairo_scale(window->cairo, scale, scale);
cairo_set_source_surface(window->cairo, image,
0,
- (double) window->height/2 / scale - height/2);
+ (double) wheight/2 / scale - height/2);
}
break;
}
case SCALING_MODE_CENTER:
cairo_set_source_surface(window->cairo, image,
- (double) window->width/2 - width/2,
- (double) window->height/2 - height/2);
+ (double) wwidth/2 - width/2,
+ (double) wheight/2 - height/2);
break;
case SCALING_MODE_TILE:
{