diff options
author | 2023-11-23 07:54:23 -0500 | |
---|---|---|
committer | 2023-11-23 20:42:04 +0100 | |
commit | 39b9c0d6baeda0609dfe248fc5b86fb65ff69c2c (patch) | |
tree | 9e6347ac7c9b74a39ce07a6644221556d6fc1a97 /common/background-image.c | |
parent | xdg-shell: chase events update (diff) | |
download | sway-39b9c0d6baeda0609dfe248fc5b86fb65ff69c2c.tar.gz sway-39b9c0d6baeda0609dfe248fc5b86fb65ff69c2c.tar.zst sway-39b9c0d6baeda0609dfe248fc5b86fb65ff69c2c.zip |
common: Drop unused render_background_image
And the associated background_mode enum.
Diffstat (limited to 'common/background-image.c')
-rw-r--r-- | common/background-image.c | 88 |
1 files changed, 2 insertions, 86 deletions
diff --git a/common/background-image.c b/common/background-image.c index 994a0805..d94346c8 100644 --- a/common/background-image.c +++ b/common/background-image.c | |||
@@ -1,29 +1,12 @@ | |||
1 | #include <assert.h> | 1 | #include <assert.h> |
2 | #include "background-image.h" | 2 | #include "background-image.h" |
3 | #include "cairo_util.h" | 3 | #include "config.h" |
4 | #include "log.h" | 4 | #include "log.h" |
5 | |||
5 | #if HAVE_GDK_PIXBUF | 6 | #if HAVE_GDK_PIXBUF |
6 | #include <gdk-pixbuf/gdk-pixbuf.h> | 7 | #include <gdk-pixbuf/gdk-pixbuf.h> |
7 | #endif | 8 | #endif |
8 | 9 | ||
9 | enum background_mode parse_background_mode(const char *mode) { | ||
10 | if (strcmp(mode, "stretch") == 0) { | ||
11 | return BACKGROUND_MODE_STRETCH; | ||
12 | } else if (strcmp(mode, "fill") == 0) { | ||
13 | return BACKGROUND_MODE_FILL; | ||
14 | } else if (strcmp(mode, "fit") == 0) { | ||
15 | return BACKGROUND_MODE_FIT; | ||
16 | } else if (strcmp(mode, "center") == 0) { | ||
17 | return BACKGROUND_MODE_CENTER; | ||
18 | } else if (strcmp(mode, "tile") == 0) { | ||
19 | return BACKGROUND_MODE_TILE; | ||
20 | } else if (strcmp(mode, "solid_color") == 0) { | ||
21 | return BACKGROUND_MODE_SOLID_COLOR; | ||
22 | } | ||
23 | sway_log(SWAY_ERROR, "Unsupported background mode: %s", mode); | ||
24 | return BACKGROUND_MODE_INVALID; | ||
25 | } | ||
26 | |||
27 | #if HAVE_GDK_PIXBUF | 10 | #if HAVE_GDK_PIXBUF |
28 | static cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf( | 11 | static cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf( |
29 | const GdkPixbuf *gdkbuf) { | 12 | const GdkPixbuf *gdkbuf) { |
@@ -151,70 +134,3 @@ cairo_surface_t *load_background_image(const char *path) { | |||
151 | } | 134 | } |
152 | return image; | 135 | return image; |
153 | } | 136 | } |
154 | |||
155 | void render_background_image(cairo_t *cairo, cairo_surface_t *image, | ||
156 | enum background_mode mode, int buffer_width, int buffer_height) { | ||
157 | double width = cairo_image_surface_get_width(image); | ||
158 | double height = cairo_image_surface_get_height(image); | ||
159 | |||
160 | cairo_save(cairo); | ||
161 | switch (mode) { | ||
162 | case BACKGROUND_MODE_STRETCH: | ||
163 | cairo_scale(cairo, | ||
164 | (double)buffer_width / width, | ||
165 | (double)buffer_height / height); | ||
166 | cairo_set_source_surface(cairo, image, 0, 0); | ||
167 | break; | ||
168 | case BACKGROUND_MODE_FILL: { | ||
169 | double window_ratio = (double)buffer_width / buffer_height; | ||
170 | double bg_ratio = width / height; | ||
171 | |||
172 | if (window_ratio > bg_ratio) { | ||
173 | double scale = (double)buffer_width / width; | ||
174 | cairo_scale(cairo, scale, scale); | ||
175 | cairo_set_source_surface(cairo, image, | ||
176 | 0, (double)buffer_height / 2 / scale - height / 2); | ||
177 | } else { | ||
178 | double scale = (double)buffer_height / height; | ||
179 | cairo_scale(cairo, scale, scale); | ||
180 | cairo_set_source_surface(cairo, image, | ||
181 | (double)buffer_width / 2 / scale - width / 2, 0); | ||
182 | } | ||
183 | break; | ||
184 | } | ||
185 | case BACKGROUND_MODE_FIT: { | ||
186 | double window_ratio = (double)buffer_width / buffer_height; | ||
187 | double bg_ratio = width / height; | ||
188 | |||
189 | if (window_ratio > bg_ratio) { | ||
190 | double scale = (double)buffer_height / height; | ||
191 | cairo_scale(cairo, scale, scale); | ||
192 | cairo_set_source_surface(cairo, image, | ||
193 | (double)buffer_width / 2 / scale - width / 2, 0); | ||
194 | } else { | ||
195 | double scale = (double)buffer_width / width; | ||
196 | cairo_scale(cairo, scale, scale); | ||
197 | cairo_set_source_surface(cairo, image, | ||
198 | 0, (double)buffer_height / 2 / scale - height / 2); | ||
199 | } | ||
200 | break; | ||
201 | } | ||
202 | case BACKGROUND_MODE_CENTER: | ||
203 | cairo_set_source_surface(cairo, image, | ||
204 | (double)buffer_width / 2 - width / 2, | ||
205 | (double)buffer_height / 2 - height / 2); | ||
206 | break; | ||
207 | case BACKGROUND_MODE_TILE: { | ||
208 | cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image); | ||
209 | cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); | ||
210 | cairo_set_source(cairo, pattern); | ||
211 | break; | ||
212 | } | ||
213 | case BACKGROUND_MODE_SOLID_COLOR: | ||
214 | case BACKGROUND_MODE_INVALID: | ||
215 | assert(0); | ||
216 | break; | ||
217 | } | ||
218 | cairo_paint(cairo); | ||
219 | cairo_restore(cairo); | ||
220 | } | ||