@@ -19,7 +19,7 @@ public interface Gala.Background.Background : Object, Gdk.Paintable {
1919 return new SolidColor (color);
2020 }
2121
22- public static Background ? get_for_file (File file ) {
22+ public static Background ? get_for_file (File file , GDesktop . BackgroundStyle style ) {
2323 Gdk . Texture texture;
2424 try {
2525 texture = Gdk . Texture . from_file (file);
@@ -28,7 +28,7 @@ public interface Gala.Background.Background : Object, Gdk.Paintable {
2828 return null ;
2929 }
3030
31- return new ImageBackground (texture);
31+ return new ImageBackground (texture, style );
3232 }
3333
3434 public static Background get_dimmed (Background other ) {
@@ -120,9 +120,10 @@ public interface Gala.Background.Background : Object, Gdk.Paintable {
120120
121121 private class ImageBackground : Object , Gdk .Paintable , Background {
122122 public Gdk . Texture texture { get ; construct; }
123+ public GDesktop . BackgroundStyle style { get ; construct; }
123124
124- public ImageBackground (Gdk .Texture texture ) {
125- Object (texture: texture);
125+ public ImageBackground (Gdk .Texture texture , GDesktop . BackgroundStyle style ) {
126+ Object (texture: texture, style : style );
126127 }
127128
128129 public ColorInformation ? get_color_information (int height ) {
@@ -134,7 +135,26 @@ public interface Gala.Background.Background : Object, Gdk.Paintable {
134135 }
135136
136137 public void snapshot (Gdk .Snapshot gdk_snapshot , double width , double height ) {
137- texture. snapshot (gdk_snapshot, width, height);
138+ var snapshot = (Gtk . Snapshot ) gdk_snapshot;
139+
140+ switch (style) {
141+ case ZOOM :
142+ var x_scale = (float ) width / texture. get_width ();
143+ var y_scale = (float ) height / texture. get_height ();
144+ if (x_scale > y_scale) {
145+ snapshot. scale (x_scale, x_scale);
146+ snapshot. translate ({0 , (float ) (height - texture. get_height () * y_scale) / 2 });
147+ } else {
148+ snapshot. scale (y_scale, y_scale);
149+ snapshot. translate ({(float ) (width - texture. get_width () * x_scale) / 2 , 0 });
150+ }
151+ texture. snapshot (snapshot, texture. get_width (), texture. get_height ());
152+ break ;
153+
154+ default:
155+ texture. snapshot (gdk_snapshot, width, height);
156+ break ;
157+ }
138158 }
139159 }
140160}
0 commit comments