aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Gysin <christoph.gysin@gmail.com>2015-11-25 22:26:21 +0200
committerChristoph Gysin <christoph.gysin@gmail.com>2015-11-25 22:32:02 +0200
commitbe3fae148bc2a48a1d828b72221c0fd69bea79f7 (patch)
treeeb872cf8e54e08d6ee6205564d8959a11430b9b3
parent8630bc37524434096165acff5493eff399387df2 (diff)
downloadsway-be3fae148bc2a48a1d828b72221c0fd69bea79f7.tar.xz
swaybg: implement scaling mode "fit"
-rw-r--r--sway.5.txt2
-rw-r--r--sway/commands.c1
-rw-r--r--swaybg/main.c23
3 files changed, 25 insertions, 1 deletions
diff --git a/sway.5.txt b/sway.5.txt
index 700de8b2..8a949465 100644
--- a/sway.5.txt
+++ b/sway.5.txt
@@ -127,7 +127,7 @@ Commands
**output** <name> <background|bg> <file> <mode>::
Sets the wallpaper for the given output to the specified file, using the given
- scaling mode (one of "stretch", "fill", "center", "tile").
+ scaling mode (one of "stretch", "fill", "fit", "center", "tile").
**output** <name> disable::
Disables the specified output.
diff --git a/sway/commands.c b/sway/commands.c
index 6a4af43c..c63aa320 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -85,6 +85,7 @@ static char *bg_options[] = {
"stretch",
"center",
"fill",
+ "fit",
"tile"
};
diff --git a/swaybg/main.c b/swaybg/main.c
index 7cfe1320..e4c699c1 100644
--- a/swaybg/main.c
+++ b/swaybg/main.c
@@ -15,6 +15,7 @@ struct registry *registry;
enum scaling_mode_t {
SCALING_MODE_STRETCH,
SCALING_MODE_FILL,
+ SCALING_MODE_FIT,
SCALING_MODE_CENTER,
SCALING_MODE_TILE,
};
@@ -66,6 +67,8 @@ int main(int argc, const char **argv) {
scaling_mode = SCALING_MODE_STRETCH;
} else if (strcmp(scaling_mode_str, "fill") == 0) {
scaling_mode = SCALING_MODE_FILL;
+ } else if (strcmp(scaling_mode_str, "fit") == 0) {
+ scaling_mode = SCALING_MODE_FIT;
} else if (strcmp(scaling_mode_str, "center") == 0) {
scaling_mode = SCALING_MODE_CENTER;
} else if (strcmp(scaling_mode_str, "tile") == 0) {
@@ -105,6 +108,26 @@ int main(int argc, const char **argv) {
}
}
break;
+ case SCALING_MODE_FIT:
+ {
+ double window_ratio = (double) window->width / window->height;
+ double bg_ratio = width / height;
+
+ if (window_ratio > bg_ratio) {
+ double scale = (double) window->height / height;
+ cairo_scale(window->cairo, scale, scale);
+ cairo_set_source_surface(window->cairo, image,
+ (double) window->width/2 / scale - width/2,
+ 0);
+ } else {
+ double scale = (double) window->width / width;
+ cairo_scale(window->cairo, scale, scale);
+ cairo_set_source_surface(window->cairo, image,
+ 0,
+ (double) window->height/2 / scale - height/2);
+ }
+ }
+ break;
case SCALING_MODE_CENTER:
cairo_set_source_surface(window->cairo, image,
(double) window->width/2 - width/2,