swaybg: implement scaling mode "center"

This commit is contained in:
Christoph Gysin 2015-11-25 20:53:13 +02:00
parent 81a87ec7a7
commit 621062f18d

View file

@ -15,6 +15,7 @@ struct registry *registry;
enum scaling_mode_t {
SCALING_MODE_STRETCH,
SCALING_MODE_FILL,
SCALING_MODE_CENTER,
};
void sway_terminate(void) {
@ -64,6 +65,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, "center") == 0) {
scaling_mode = SCALING_MODE_CENTER;
} else {
sway_abort("Unsupported scaling mode: %s", scaling_mode_str);
}
@ -99,6 +102,11 @@ int main(int argc, const char **argv) {
}
}
break;
case SCALING_MODE_CENTER:
cairo_set_source_surface(window->cairo, image,
(double) window->width/2 - width/2,
(double) window->height/2 - height/2);
break;
default:
sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str);
}