mirror of
https://github.com/swaywm/sway.git
synced 2024-11-12 21:43:59 +01:00
Style fixes in swaybg
CONTRIBUTING.md's code example is sourced from this file, so I updated it as well.
This commit is contained in:
parent
392bfcbfb7
commit
9b62a98f3e
@ -106,57 +106,57 @@ int main(int argc, const char **argv) {
|
|||||||
cairo_set_source_surface(window->cairo, image, 0, 0);
|
cairo_set_source_surface(window->cairo, image, 0, 0);
|
||||||
break;
|
break;
|
||||||
case SCALING_MODE_FILL:
|
case SCALING_MODE_FILL:
|
||||||
{
|
{
|
||||||
double window_ratio = (double) window->width / window->height;
|
double window_ratio = (double) window->width / window->height;
|
||||||
double bg_ratio = width / height;
|
double bg_ratio = width / height;
|
||||||
|
|
||||||
if (window_ratio > bg_ratio) {
|
if (window_ratio > bg_ratio) {
|
||||||
double scale = (double) window->width / width;
|
double scale = (double) window->width / width;
|
||||||
cairo_scale(window->cairo, scale, scale);
|
cairo_scale(window->cairo, scale, scale);
|
||||||
cairo_set_source_surface(window->cairo, image,
|
cairo_set_source_surface(window->cairo, image,
|
||||||
0,
|
0,
|
||||||
(double) window->height/2 / scale - height/2);
|
(double) window->height/2 / scale - height/2);
|
||||||
} else {
|
} else {
|
||||||
double scale = (double) window->height / height;
|
double scale = (double) window->height / height;
|
||||||
cairo_scale(window->cairo, scale, scale);
|
cairo_scale(window->cairo, scale, scale);
|
||||||
cairo_set_source_surface(window->cairo, image,
|
cairo_set_source_surface(window->cairo, image,
|
||||||
(double) window->width/2 / scale - width/2,
|
(double) window->width/2 / scale - width/2,
|
||||||
0);
|
0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case SCALING_MODE_FIT:
|
case SCALING_MODE_FIT:
|
||||||
{
|
{
|
||||||
double window_ratio = (double) window->width / window->height;
|
double window_ratio = (double) window->width / window->height;
|
||||||
double bg_ratio = width / height;
|
double bg_ratio = width / height;
|
||||||
|
|
||||||
if (window_ratio > bg_ratio) {
|
if (window_ratio > bg_ratio) {
|
||||||
double scale = (double) window->height / height;
|
double scale = (double) window->height / height;
|
||||||
cairo_scale(window->cairo, scale, scale);
|
cairo_scale(window->cairo, scale, scale);
|
||||||
cairo_set_source_surface(window->cairo, image,
|
cairo_set_source_surface(window->cairo, image,
|
||||||
(double) window->width/2 / scale - width/2,
|
(double) window->width/2 / scale - width/2,
|
||||||
0);
|
0);
|
||||||
} else {
|
} else {
|
||||||
double scale = (double) window->width / width;
|
double scale = (double) window->width / width;
|
||||||
cairo_scale(window->cairo, scale, scale);
|
cairo_scale(window->cairo, scale, scale);
|
||||||
cairo_set_source_surface(window->cairo, image,
|
cairo_set_source_surface(window->cairo, image,
|
||||||
0,
|
0,
|
||||||
(double) window->height/2 / scale - height/2);
|
(double) window->height/2 / scale - height/2);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case SCALING_MODE_CENTER:
|
case SCALING_MODE_CENTER:
|
||||||
cairo_set_source_surface(window->cairo, image,
|
cairo_set_source_surface(window->cairo, image,
|
||||||
(double) window->width/2 - width/2,
|
(double) window->width/2 - width/2,
|
||||||
(double) window->height/2 - height/2);
|
(double) window->height/2 - height/2);
|
||||||
break;
|
break;
|
||||||
case SCALING_MODE_TILE:
|
case SCALING_MODE_TILE:
|
||||||
{
|
{
|
||||||
cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image);
|
cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image);
|
||||||
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
|
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
|
||||||
cairo_set_source(window->cairo, pattern);
|
cairo_set_source(window->cairo, pattern);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str);
|
sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str);
|
||||||
}
|
}
|
||||||
|
@ -88,57 +88,57 @@ int main(int argc, const char **argv) {
|
|||||||
cairo_set_source_surface(window->cairo, image, 0, 0);
|
cairo_set_source_surface(window->cairo, image, 0, 0);
|
||||||
break;
|
break;
|
||||||
case SCALING_MODE_FILL:
|
case SCALING_MODE_FILL:
|
||||||
{
|
{
|
||||||
double window_ratio = (double) window->width / window->height;
|
double window_ratio = (double) window->width / window->height;
|
||||||
double bg_ratio = width / height;
|
double bg_ratio = width / height;
|
||||||
|
|
||||||
if (window_ratio > bg_ratio) {
|
if (window_ratio > bg_ratio) {
|
||||||
double scale = (double) window->width / width;
|
double scale = (double) window->width / width;
|
||||||
cairo_scale(window->cairo, scale, scale);
|
cairo_scale(window->cairo, scale, scale);
|
||||||
cairo_set_source_surface(window->cairo, image,
|
cairo_set_source_surface(window->cairo, image,
|
||||||
0,
|
0,
|
||||||
(double) window->height/2 / scale - height/2);
|
(double) window->height/2 / scale - height/2);
|
||||||
} else {
|
} else {
|
||||||
double scale = (double) window->height / height;
|
double scale = (double) window->height / height;
|
||||||
cairo_scale(window->cairo, scale, scale);
|
cairo_scale(window->cairo, scale, scale);
|
||||||
cairo_set_source_surface(window->cairo, image,
|
cairo_set_source_surface(window->cairo, image,
|
||||||
(double) window->width/2 / scale - width/2,
|
(double) window->width/2 / scale - width/2,
|
||||||
0);
|
0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case SCALING_MODE_FIT:
|
case SCALING_MODE_FIT:
|
||||||
{
|
{
|
||||||
double window_ratio = (double) window->width / window->height;
|
double window_ratio = (double) window->width / window->height;
|
||||||
double bg_ratio = width / height;
|
double bg_ratio = width / height;
|
||||||
|
|
||||||
if (window_ratio > bg_ratio) {
|
if (window_ratio > bg_ratio) {
|
||||||
double scale = (double) window->height / height;
|
double scale = (double) window->height / height;
|
||||||
cairo_scale(window->cairo, scale, scale);
|
cairo_scale(window->cairo, scale, scale);
|
||||||
cairo_set_source_surface(window->cairo, image,
|
cairo_set_source_surface(window->cairo, image,
|
||||||
(double) window->width/2 / scale - width/2,
|
(double) window->width/2 / scale - width/2,
|
||||||
0);
|
0);
|
||||||
} else {
|
} else {
|
||||||
double scale = (double) window->width / width;
|
double scale = (double) window->width / width;
|
||||||
cairo_scale(window->cairo, scale, scale);
|
cairo_scale(window->cairo, scale, scale);
|
||||||
cairo_set_source_surface(window->cairo, image,
|
cairo_set_source_surface(window->cairo, image,
|
||||||
0,
|
0,
|
||||||
(double) window->height/2 / scale - height/2);
|
(double) window->height/2 / scale - height/2);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case SCALING_MODE_CENTER:
|
case SCALING_MODE_CENTER:
|
||||||
cairo_set_source_surface(window->cairo, image,
|
cairo_set_source_surface(window->cairo, image,
|
||||||
(double) window->width/2 - width/2,
|
(double) window->width/2 - width/2,
|
||||||
(double) window->height/2 - height/2);
|
(double) window->height/2 - height/2);
|
||||||
break;
|
break;
|
||||||
case SCALING_MODE_TILE:
|
case SCALING_MODE_TILE:
|
||||||
{
|
{
|
||||||
cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image);
|
cairo_pattern_t *pattern = cairo_pattern_create_for_surface(image);
|
||||||
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
|
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
|
||||||
cairo_set_source(window->cairo, pattern);
|
cairo_set_source(window->cairo, pattern);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str);
|
sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user