summaryrefslogtreecommitdiffstats
path: root/swaybg
diff options
context:
space:
mode:
authorLibravatar Christoph Gysin <christoph.gysin@gmail.com>2015-11-25 20:52:34 +0200
committerLibravatar Christoph Gysin <christoph.gysin@gmail.com>2015-11-25 22:29:49 +0200
commit81a87ec7a721b2f14c129f86b8403cce8c434435 (patch)
treee94a68c9de78c0474081a75fa79c341e98e371e8 /swaybg
parentswaybg: implement scaling mode "stretch" (diff)
downloadsway-81a87ec7a721b2f14c129f86b8403cce8c434435.tar.gz
sway-81a87ec7a721b2f14c129f86b8403cce8c434435.tar.zst
sway-81a87ec7a721b2f14c129f86b8403cce8c434435.zip
swaybg: implement scaling mode "fill"
Diffstat (limited to 'swaybg')
-rw-r--r--swaybg/main.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/swaybg/main.c b/swaybg/main.c
index 5510f2ef..a85c56bd 100644
--- a/swaybg/main.c
+++ b/swaybg/main.c
@@ -14,6 +14,7 @@ struct registry *registry;
14 14
15enum scaling_mode_t { 15enum scaling_mode_t {
16 SCALING_MODE_STRETCH, 16 SCALING_MODE_STRETCH,
17 SCALING_MODE_FILL,
17}; 18};
18 19
19void sway_terminate(void) { 20void sway_terminate(void) {
@@ -61,6 +62,8 @@ int main(int argc, const char **argv) {
61 enum scaling_mode_t scaling_mode; 62 enum scaling_mode_t scaling_mode;
62 if (strcmp(scaling_mode_str, "stretch") == 0) { 63 if (strcmp(scaling_mode_str, "stretch") == 0) {
63 scaling_mode = SCALING_MODE_STRETCH; 64 scaling_mode = SCALING_MODE_STRETCH;
65 } else if (strcmp(scaling_mode_str, "fill") == 0) {
66 scaling_mode = SCALING_MODE_FILL;
64 } else { 67 } else {
65 sway_abort("Unsupported scaling mode: %s", scaling_mode_str); 68 sway_abort("Unsupported scaling mode: %s", scaling_mode_str);
66 } 69 }
@@ -76,6 +79,26 @@ int main(int argc, const char **argv) {
76 (double) window->height / height); 79 (double) window->height / height);
77 cairo_set_source_surface(window->cairo, image, 0, 0); 80 cairo_set_source_surface(window->cairo, image, 0, 0);
78 break; 81 break;
82 case SCALING_MODE_FILL:
83 {
84 double window_ratio = (double) window->width / window->height;
85 double bg_ratio = width / height;
86
87 if (window_ratio > bg_ratio) {
88 double scale = (double) window->width / width;
89 cairo_scale(window->cairo, scale, scale);
90 cairo_set_source_surface(window->cairo, image,
91 0,
92 (double) window->height/2 / scale - height/2);
93 } else {
94 double scale = (double) window->height / height;
95 cairo_scale(window->cairo, scale, scale);
96 cairo_set_source_surface(window->cairo, image,
97 (double) window->width/2 / scale - width/2,
98 0);
99 }
100 }
101 break;
79 default: 102 default:
80 sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str); 103 sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str);
81 } 104 }