82
82
cr.set_source_surface (bottom_buffer.surface, 0.0, 0.0);
85
85
// Crossfade upper buffer
86
86
cr.set_source_surface (top_buffer.surface, 0.0, 0.0);
87
87
cr.paint_with_alpha (opacity);
90
void draw_color_background (BufferSurface surface) {
93
Gdk.Color.parse (Wallpaper.settings.background_color, out bg);
94
surface.context.set_source_rgb (bg.red / 255.0, bg.blue / 255.0, bg.green / 255.0);
90
void draw_color_background (BufferSurface surface, Gdk.Color color) {
92
surface.context.set_source_rgb (color.red / 255.0, color.blue / 255.0, color.green / 255.0);
95
93
surface.context.paint ();
98
void draw_picture (BufferSurface surface, Gdk.Rectangle dim) {
96
void draw_picture (BufferSurface surface, Pixbuf picture, PictureMode mode) {
100
98
var context = surface.context;
101
var path = Wallpaper.settings.picture_path;
105
switch (Wallpaper.settings.picture_mode) {
107
case PictureMode.TILED:
108
var wallpaper = new Pixbuf.from_file (path);
109
cairo_set_source_pixbuf (context, wallpaper, dim.x, dim.y);
110
var pattern = context.get_source ();
111
pattern.set_extend (Extend.REPEAT);
113
case PictureMode.CENTERED:
114
var wallpaper = new Pixbuf.from_file (path);
115
cairo_set_source_pixbuf (context, wallpaper, dim.x + ((wallpaper.width - dim.width) / -2.0), dim.y + (wallpaper.height - dim.height) / -2.0);
117
case PictureMode.SCALED:
118
var wallpaper = new Pixbuf.from_file_at_scale (path, -1, dim.height, true);
119
cairo_set_source_pixbuf (context, wallpaper, dim.x + ((wallpaper.width - dim.width) / -2.0), dim.y);
121
case PictureMode.STRETCHED:
122
var wallpaper = new Pixbuf.from_file_at_scale (path, dim.width, dim.height, false);
123
cairo_set_source_pixbuf (context, wallpaper, dim.x, dim.y);
125
case PictureMode.ZOOMED:
126
var wallpaper = new Pixbuf.from_file_at_scale (path, dim.width, -1, true);
127
cairo_set_source_pixbuf (context, wallpaper, dim.x, dim.y + (wallpaper.height - dim.height) / -2.0);
130
var wallpaper = new Pixbuf.from_file (path);
131
cairo_set_source_pixbuf (context, wallpaper, dim.x, dim.y);
136
warning ("Could not set '%s' as wallpaper. Ensure the file exists.", path);
99
bool span_screen = (picture.width >= window.screen_width && picture.height >= window.screen_height);
101
bool stretch_x = false;
102
bool stretch_y = false;
104
bool center_x = false;
105
bool center_y = false;
109
case PictureMode.TILED:
112
case PictureMode.CENTERED:
116
case PictureMode.SCALED:
120
case PictureMode.STRETCHED:
125
case PictureMode.ZOOMED:
131
Gdk.Pixbuf wallpaper;
132
int width = picture.width, height = picture.height;
133
double offset_x, offset_y;
134
foreach (var mon in window.monitors) {
136
// Scale picture accordingly
137
if (stretch_x && stretch_y) {
138
width = span_screen ? window.screen_width : mon.width;
139
height = span_screen ? window.screen_height : mon.height;
140
} else if (stretch_x && !stretch_y) {
141
width = span_screen ? window.screen_width : mon.width;
142
height = picture.height * width / picture.width;
143
} else if (stretch_y && !stretch_x) {
144
height = span_screen ? window.screen_height : mon.height;
145
width = picture.width * height / picture.height;
147
wallpaper = picture.scale_simple (width, height, InterpType.BILINEAR);
150
offset_x = center_x ? ((span_screen ? window.screen_width : mon.width) - width) / 2.0 : 0.0;
151
offset_y = center_y ? ((span_screen ? window.screen_height : mon.height) - height) / 2.0 : 0.0;
152
cairo_set_source_pixbuf (context, wallpaper, offset_x, offset_y);
154
if (mode == PictureMode.TILED)
155
context.get_source ().set_extend (Extend.REPEAT);
142
163
private void update_buffers () {
144
165
if (needs_flip) {
145
166
var temp = top_buffer;
146
top_buffer = bottom_buffer;
147
bottom_buffer = temp;
150
draw_color_background (top_buffer);
152
foreach (var monitor in window.monitors)
153
draw_picture (top_buffer, monitor);
155
var now = new DateTime.now_utc ();
167
top_buffer = bottom_buffer;
168
bottom_buffer = temp;
172
Gdk.Color.parse (Wallpaper.settings.background_color, out bg);
173
draw_color_background (top_buffer, bg);
175
draw_picture (top_buffer, new Pixbuf.from_file (Wallpaper.settings.picture_path), Wallpaper.settings.picture_mode);
177
warning ("Could not set '%s' as wallpaper. Ensure the file exists.", Wallpaper.settings.picture_path);
180
var now = new DateTime.now_utc ();
156
181
var diff = now.difference (last_fade);
158
183
if (diff < fade_duration * 1000) // we're in the middle of an animation, so finish it
159
184
last_fade = now.add_seconds ((diff - fade_duration * 1000) / 1000000.0);
161
186
last_fade = new DateTime.now_utc ();
166
191
protected override bool animation_needed (DateTime render_time) {