Skip to content

Commit 9606794

Browse files
committed
Some cleanup and support ZOOM BackgroundStyle
1 parent 62768c8 commit 9606794

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

background/Application.vala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ public class Gala.Background.Application : Gtk.Application {
2525
Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = scheme == DARK;
2626
});
2727

28-
/*
29-
* We have to be careful not to init Granite because Granite gets Settings sync but it takes a while
30-
* until the portal launches so it blocks.
31-
*/
32-
3328
background_manager = new BackgroundManager ();
3429

3530
try {

background/Background.vala

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

background/BackgroundManager.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class Gala.Background.BackgroundManager : Object {
5959
if (style != GDesktop.BackgroundStyle.NONE) {
6060
var uri = gnome_settings.get_string ("picture-uri");
6161
var file = File.new_for_uri (uri);
62-
current_background = Background.get_for_file (file);
62+
current_background = Background.get_for_file (file, style);
6363
} else {
6464
Gdk.RGBA color = {};
6565
color.parse (gnome_settings.get_string ("primary-color"));

0 commit comments

Comments
 (0)