Merge lp:~donadigo/pantheon-greeter/fix-black-bars into lp:~elementary-pantheon/pantheon-greeter/trunk

Proposed by Adam Bieńkowski
Status: Merged
Approved by: Danielle Foré
Approved revision: 459
Merged at revision: 458
Proposed branch: lp:~donadigo/pantheon-greeter/fix-black-bars
Merge into: lp:~elementary-pantheon/pantheon-greeter/trunk
Diff against target: 83 lines (+18/-37)
1 file modified
src/Wallpaper.vala (+18/-37)
To merge this branch: bzr merge lp:~donadigo/pantheon-greeter/fix-black-bars
Reviewer Review Type Date Requested Status
Danielle Foré Approve
Review via email: mp+297404@code.launchpad.net

Commit message

* Fix black bars appearing to users on login screen.

Description of the change

Fixes black bars appearing to users on login screen.

This branch uses the Ubuntu's Unity Greeter algorithm that is easier to understand and also fixes the problem with black bars.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Looks good! Thanks :D

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Wallpaper.vala'
2--- src/Wallpaper.vala 2016-06-14 12:38:50 +0000
3+++ src/Wallpaper.vala 2016-06-14 21:40:30 +0000
4@@ -98,15 +98,17 @@
5 cache_path += path;
6 cache_pixbuf += buf;
7 background_pixbuf = buf;
8+ } else {
9+ buf = validate_pixbuf (buf);
10 }
11- //check if the currently loaded wallpaper is the one we loaded in this method
12+
13+ // check if the currently loaded wallpaper is the one we loaded in this method
14 if (last_loaded != path) {
15 return; //if not, abort
16 }
17
18 var new_wallpaper = make_image ();
19 new_wallpaper.pixbuf = buf;
20- resize (new_wallpaper);
21 stack.add (new_wallpaper);
22 stack.show_all ();
23 stack.visible_child = new_wallpaper;
24@@ -178,45 +180,24 @@
25 * screen size to save memory.
26 */
27 Gdk.Pixbuf validate_pixbuf (Gdk.Pixbuf pixbuf) {
28- var result = scale_to_rect (pixbuf, gpu_limit, gpu_limit);
29- result = scale_to_rect (pixbuf, screen_width, screen_height);
30- return result;
31+ return scale_to_rect (pixbuf, screen_width, screen_height);
32 }
33
34 Gdk.Pixbuf scale_to_rect (Gdk.Pixbuf pixbuf, int rect_width, int rect_height) {
35- int height = pixbuf.height;
36- int width = pixbuf.width;
37-
38- if (height > rect_height || width > rect_width) {
39- float hw = (float)height / width * rect_width;
40- float wh = (float)width / height * rect_height;
41- if (height < width) {
42- return pixbuf.scale_simple (rect_width, (int) (hw), Gdk.InterpType.BILINEAR);
43- } else {
44- return pixbuf.scale_simple ((int) (wh), rect_height, Gdk.InterpType.BILINEAR);
45- }
46- }
47- return pixbuf;
48- }
49-
50- void resize (Gtk.Image image) {
51- int w, h;
52-
53- w = image.width_request;
54- h = image.height_request;
55-
56-
57- if (width > (w * height) / h) {
58- image.width_request = (int) width;
59- image.height_request = (int) (h * width / w);
60-
61- if (height > image.height_request) {
62- image.height_request = (int) height;
63- image.width_request = (int) (w * height / h);
64- }
65+ double target_aspect = (double) rect_width / rect_height;
66+ double aspect = (double) pixbuf.width / pixbuf.height;
67+ double scale, offset_x = 0, offset_y = 0;
68+ if (aspect > target_aspect) {
69+ scale = (double) rect_height / pixbuf.height;
70+ offset_x = (pixbuf.width * scale - rect_width) / 2;
71 } else {
72- image.height_request = (int) height;
73- image.width_request = (int) (w * height / h);
74+ scale = (double) rect_width / pixbuf.width;
75+ offset_y = (pixbuf.height * scale - rect_height) / 2;
76 }
77+
78+ var scaled_pixbuf = new Gdk.Pixbuf (pixbuf.colorspace, pixbuf.has_alpha, pixbuf.bits_per_sample, rect_width, rect_height);
79+ pixbuf.scale (scaled_pixbuf, 0, 0, rect_width, rect_height, -offset_x, -offset_y, scale, scale, Gdk.InterpType.BILINEAR);
80+
81+ return scaled_pixbuf;
82 }
83 }

Subscribers

People subscribed via source and target branches