summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
127 127
128**output** <name> <background|bg> <file> <mode>:: 128**output** <name> <background|bg> <file> <mode>::
129 Sets the wallpaper for the given output to the specified file, using the given 129 Sets the wallpaper for the given output to the specified file, using the given
130 scaling mode (one of "stretch", "fill", "center", "tile"). 130 scaling mode (one of "stretch", "fill", "fit", "center", "tile").
131 131
132**output** <name> disable:: 132**output** <name> disable::
133 Disables the specified output. 133 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[] = {
85 "stretch", 85 "stretch",
86 "center", 86 "center",
87 "fill", 87 "fill",
88 "fit",
88 "tile" 89 "tile"
89}; 90};
90 91
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;
15enum scaling_mode_t { 15enum scaling_mode_t {
16 SCALING_MODE_STRETCH, 16 SCALING_MODE_STRETCH,
17 SCALING_MODE_FILL, 17 SCALING_MODE_FILL,
18 SCALING_MODE_FIT,
18 SCALING_MODE_CENTER, 19 SCALING_MODE_CENTER,
19 SCALING_MODE_TILE, 20 SCALING_MODE_TILE,
20}; 21};
@@ -66,6 +67,8 @@ int main(int argc, const char **argv) {
66 scaling_mode = SCALING_MODE_STRETCH; 67 scaling_mode = SCALING_MODE_STRETCH;
67 } else if (strcmp(scaling_mode_str, "fill") == 0) { 68 } else if (strcmp(scaling_mode_str, "fill") == 0) {
68 scaling_mode = SCALING_MODE_FILL; 69 scaling_mode = SCALING_MODE_FILL;
70 } else if (strcmp(scaling_mode_str, "fit") == 0) {
71 scaling_mode = SCALING_MODE_FIT;
69 } else if (strcmp(scaling_mode_str, "center") == 0) { 72 } else if (strcmp(scaling_mode_str, "center") == 0) {
70 scaling_mode = SCALING_MODE_CENTER; 73 scaling_mode = SCALING_MODE_CENTER;
71 } else if (strcmp(scaling_mode_str, "tile") == 0) { 74 } else if (strcmp(scaling_mode_str, "tile") == 0) {
@@ -105,6 +108,26 @@ int main(int argc, const char **argv) {
105 } 108 }
106 } 109 }
107 break; 110 break;
111 case SCALING_MODE_FIT:
112 {
113 double window_ratio = (double) window->width / window->height;
114 double bg_ratio = width / height;
115
116 if (window_ratio > bg_ratio) {
117 double scale = (double) window->height / height;
118 cairo_scale(window->cairo, scale, scale);
119 cairo_set_source_surface(window->cairo, image,
120 (double) window->width/2 / scale - width/2,
121 0);
122 } else {
123 double scale = (double) window->width / width;
124 cairo_scale(window->cairo, scale, scale);
125 cairo_set_source_surface(window->cairo, image,
126 0,
127 (double) window->height/2 / scale - height/2);
128 }
129 }
130 break;
108 case SCALING_MODE_CENTER: 131 case SCALING_MODE_CENTER:
109 cairo_set_source_surface(window->cairo, image, 132 cairo_set_source_surface(window->cairo, image,
110 (double) window->width/2 - width/2, 133 (double) window->width/2 - width/2,