mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 16:01:27 +00:00
swaybg: implement scaling mode "stretch"
This commit is contained in:
parent
504ac84cbc
commit
904983c375
|
@ -12,6 +12,10 @@ list_t *surfaces;
|
|||
|
||||
struct registry *registry;
|
||||
|
||||
enum scaling_mode_t {
|
||||
SCALING_MODE_STRETCH,
|
||||
};
|
||||
|
||||
void sway_terminate(void) {
|
||||
int i;
|
||||
for (i = 0; i < surfaces->length; ++i) {
|
||||
|
@ -49,16 +53,33 @@ int main(int argc, const char **argv) {
|
|||
desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
|
||||
list_add(surfaces, window);
|
||||
|
||||
const char *scaling_mode = argv[3];
|
||||
cairo_surface_t *image = cairo_image_surface_create_from_png(argv[2]);
|
||||
double width = cairo_image_surface_get_width(image);
|
||||
double height = cairo_image_surface_get_height(image);
|
||||
|
||||
const char *scaling_mode_str = argv[3];
|
||||
enum scaling_mode_t scaling_mode;
|
||||
if (strcmp(scaling_mode_str, "stretch") == 0) {
|
||||
scaling_mode = SCALING_MODE_STRETCH;
|
||||
} else {
|
||||
sway_abort("Unsupported scaling mode: %s", scaling_mode_str);
|
||||
}
|
||||
|
||||
for (i = 0; i < surfaces->length; ++i) {
|
||||
struct window *window = surfaces->items[i];
|
||||
if (window_prerender(window) && window->cairo) {
|
||||
cairo_scale(window->cairo, window->width / width, window->height / height);
|
||||
cairo_set_source_surface(window->cairo, image, 0, 0);
|
||||
|
||||
switch (scaling_mode) {
|
||||
case SCALING_MODE_STRETCH:
|
||||
cairo_scale(window->cairo,
|
||||
(double) window->width / width,
|
||||
(double) window->height / height);
|
||||
cairo_set_source_surface(window->cairo, image, 0, 0);
|
||||
break;
|
||||
default:
|
||||
sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str);
|
||||
}
|
||||
|
||||
cairo_paint(window->cairo);
|
||||
|
||||
window_render(window);
|
||||
|
|
Loading…
Reference in a new issue