Merge lp:~tombeckmann/audience/aspect-ration-second-try into lp:~audience-members/audience/trunk

Proposed by Tom Beckmann
Status: Merged
Approved by: Viko Adi Rahmawan
Approved revision: 467
Merged at revision: 499
Proposed branch: lp:~tombeckmann/audience/aspect-ration-second-try
Merge into: lp:~audience-members/audience/trunk
Diff against target: 153 lines (+66/-12)
2 files modified
src/Audience.vala (+61/-7)
src/Widgets/VideoPlayer.vala (+5/-5)
To merge this branch: bzr merge lp:~tombeckmann/audience/aspect-ration-second-try
Reviewer Review Type Date Requested Status
Viko Adi Rahmawan (community) Approve
Artem Anufrij (community) ratio Needs Fixing
Review via email: mp+242789@code.launchpad.net

Commit message

fix ratio constrain in CSD

Description of the change

I think it's working now, so I'm proposing it for being merged. I'm not 100% sure it will work seamlessly in all cases though, so I haven't removed the debug prints yet.

The system works by locking the window's aspect ratio after a resize has finished or while it pauses. This is required, as outlined before, because of the CSD, which adds a constant padding around the video, so in turn the entire window's aspect ratio is no longer constant when resized.

To post a comment you must log in.
467. By Tom Beckmann

try to work around minimal black bars occuring because of the resize operation

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

Hey Tom,
"audience" crashes on add a new video into playlist.

It doesn't happening on currently version.

review: Needs Fixing
Revision history for this message
Tom Beckmann (tombeckmann) wrote :

After some investigations we found out that this crash is not related to this branch.

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :
review: Needs Fixing (ratio)
Revision history for this message
PerfectCarl (name-is-carl) wrote :

What is the status of this work?

How can we test it in a reproducible way?
(we can't just get our hands on random movies and see what happens).

Revision history for this message
Viko Adi Rahmawan (vikoadi) wrote :

It works!
btw, there is a bug where i can't resize window twice, not until i fullscreen-unfullscreen the window (trunk affected too)
so maybe just remove debugging code, merge from trunk than merge it to trunk

Revision history for this message
Tom Beckmann (tombeckmann) wrote :

I'll be focusing on gala the next couple of days (and then probably some other project will have to take immediate priority). If you like, I can change the branch ownership to ~elementary-apps (if you're part of that team, or your account directly) so you can take over from here.

Revision history for this message
Viko Adi Rahmawan (vikoadi) wrote :

i think unresizable bug is different problem, so my proposal we should just merge this branch into trunk.

Revision history for this message
Tom Beckmann (tombeckmann) wrote :

I'll leave that decision completely to you, feel free to do any adjustments you like while merging :)

Revision history for this message
Viko Adi Rahmawan (vikoadi) wrote :

fix ratio constrain in CSD

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Audience.vala'
2--- src/Audience.vala 2014-11-02 19:13:36 +0000
3+++ src/Audience.vala 2014-11-25 18:33:34 +0000
4@@ -89,6 +89,7 @@
5 private static App app; // global App instance
6 private Audience.Widgets.VideoPlayer video_player;
7 private Audience.Widgets.BottomBar bottom_bar;
8+ private Gtk.HeaderBar header;
9 private Clutter.Stage stage;
10 private Gtk.Revealer unfullscreen_bar;
11 private GtkClutter.Actor bottom_actor;
12@@ -167,7 +168,7 @@
13 mainbox.pack_start (clutter);
14 mainbox.pack_start (welcome);
15
16- var header = new Gtk.HeaderBar ();
17+ header = new Gtk.HeaderBar ();
18 header.set_show_close_button (true);
19 header.get_style_context ().remove_class ("header-bar");
20
21@@ -275,7 +276,7 @@
22 return false;
23 });
24
25- mainwindow.size_allocate.connect ((alloc) => {on_size_allocate (alloc);});
26+ mainwindow.size_allocate.connect (on_size_allocate);
27 mainwindow.motion_notify_event.connect ((event) => {
28 if (event.window == null)
29 return false;
30@@ -551,12 +552,62 @@
31 mainwindow.get_window ().move_resize (monitor.width / 2 - width / 2 + monitor.x,
32 monitor.height / 2 - height / 2 + monitor.y,
33 width, height);
34-
35- if (settings.keep_aspect) {
36+ }
37+
38+ uint update_aspect_ratio_timeout = 0;
39+ bool update_aspect_ratio_locked = false;
40+ int prev_width = 0;
41+ int prev_height = 0;
42+ /**
43+ * Updates the window's aspect ratio locking if enabled.
44+ * Return type is just there to make it compatible with Idle.add()
45+ */
46+ private bool update_aspect_ratio ()
47+ {
48+ if (!settings.keep_aspect || video_player.video_width < 1 || video_player.height < 1
49+ || !clutter.visible)
50+ return false;
51+
52+ if (update_aspect_ratio_timeout != 0)
53+ Source.remove (update_aspect_ratio_timeout);
54+
55+ update_aspect_ratio_timeout = Timeout.add (200, () => {
56+ Gtk.Allocation a;
57+ clutter.get_allocation (out a);
58+ print ("%i %i %i,%i\n", a.x, a.y, (mainwindow.get_allocated_width () - clutter.get_allocated_width ()) / 2, (mainwindow.get_allocated_height () - clutter.get_allocated_height ()) / 2);
59+ double width = clutter.get_allocated_width ();
60+ double height = width * video_player.video_height / (double) video_player.video_width;
61+ double width_offset = mainwindow.get_allocated_width () - width;
62+ double height_offset = mainwindow.get_allocated_height () - clutter.get_allocated_height ();
63+
64+ print ("Width: %f, Height: %f, Offset: %f (%f, %f)\n", width, height, height_offset, video_player.video_width, video_player.video_height);
65+
66 var geom = Gdk.Geometry ();
67- geom.min_aspect = geom.max_aspect = video_w / (double)video_h;
68+ geom.min_aspect = geom.max_aspect = (width + width_offset) / (height + height_offset);
69+
70+ var w = mainwindow.get_allocated_width ();
71+ var h = (int) (w * geom.max_aspect);
72+ int b, c;
73+
74 mainwindow.get_window ().set_geometry_hints (geom, Gdk.WindowHints.ASPECT);
75- }
76+
77+ mainwindow.get_window ().constrain_size (geom, Gdk.WindowHints.ASPECT, w, h, out b, out c);
78+ print ("Result: %i %i == %i %i\n", w, h, b, c);
79+ mainwindow.get_window ().resize (b, c);
80+
81+ update_aspect_ratio_timeout = 0;
82+
83+ Idle.add (() => {
84+ prev_width = mainwindow.get_allocated_width ();
85+ prev_height = mainwindow.get_allocated_height ();
86+
87+ return false;
88+ });
89+
90+ return false;
91+ });
92+
93+ return false;
94 }
95
96 private void on_window_state_changed (Gdk.WindowState window_state) {
97@@ -603,6 +654,9 @@
98 old_h = alloc.height;
99 }
100 }
101+
102+ if (prev_width != mainwindow.get_allocated_width () && prev_height != mainwindow.get_allocated_height ())
103+ Idle.add (update_aspect_ratio);
104 }
105
106 private bool update_pointer_position (double y, int window_height) {
107@@ -854,4 +908,4 @@
108 var app = Audience.App.get_instance ();
109
110 app.run (args);
111-}
112\ No newline at end of file
113+}
114
115=== modified file 'src/Widgets/VideoPlayer.vala'
116--- src/Widgets/VideoPlayer.vala 2014-10-05 06:13:09 +0000
117+++ src/Widgets/VideoPlayer.vala 2014-11-25 18:33:34 +0000
118@@ -102,7 +102,7 @@
119 if (video != null && video.data != null) {
120 var video_info = (Gst.PbUtils.DiscovererVideoInfo)video.data;
121 video_height = video_info.get_height ();
122- video_width = get_video_width (video_info);
123+ video_width = query_video_width (video_info);
124 }
125 } catch (Error e) {
126 error ();
127@@ -161,8 +161,8 @@
128 public dynamic Gst.Element playbin;
129 Clutter.Texture video;
130
131- uint video_width;
132- uint video_height;
133+ public uint video_width { get; private set; }
134+ public uint video_height { get; private set; }
135
136 public GnomeSessionManager session_manager;
137 uint32 inhibit_cookie;
138@@ -459,7 +459,7 @@
139 playbin.seek_simple (Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, new_position);
140 }
141
142- uint get_video_width (Gst.PbUtils.DiscovererVideoInfo video_info) {
143+ uint query_video_width (Gst.PbUtils.DiscovererVideoInfo video_info) {
144 var par = get_video_par (video_info);
145 if (par == -1) {
146 return video_info.get_width ();
147@@ -477,4 +477,4 @@
148 return num / (double)denom;
149 }
150 }
151-}
152\ No newline at end of file
153+}

Subscribers

People subscribed via source and target branches

to all changes: