Merge lp:~ricotz/gala/rework-shadow-effect into lp:gala

Proposed by Rico Tzschichholz
Status: Merged
Merged at revision: 509
Proposed branch: lp:~ricotz/gala/rework-shadow-effect
Merge into: lp:gala
Diff against target: 272 lines (+68/-75)
3 files modified
src/ShadowEffect.vala (+33/-23)
src/Widgets/WindowClone.vala (+34/-51)
src/Widgets/WorkspaceClone.vala (+1/-1)
To merge this branch: bzr merge lp:~ricotz/gala/rework-shadow-effect
Reviewer Review Type Date Requested Status
Cody Garver (community) testing Approve
Diego Rocha (community) Approve
Review via email: mp+286060@code.launchpad.net
To post a comment you must log in.
lp:~ricotz/gala/rework-shadow-effect updated
508. By Diego Rocha

windowclone: Fix animation when dragging window from neighboor workspace

Revision history for this message
Diego Rocha (diego-rocha-comp) wrote :

Rico, you have removed 'toggle_shadow' from WindowClone and all code associated to it. This makes the clone's shadow of a window that is not maximized get darker/lighter with no fade when entering/leaving multitasking view.

Here's a video of this happening:

https://drive.google.com/file/d/0B4eLCXdUQUZtOC1kb0pQclNmZnc/view?usp=sharing

review: Needs Fixing
lp:~ricotz/gala/rework-shadow-effect updated
509. By Rico Tzschichholz

Reimplement "shadow-effect" used by Window- and WorkspaceClone

Based on patch by "Diego Rocha (diego-rocha-comp)"

Revision history for this message
Diego Rocha (diego-rocha-comp) wrote :

Looks good

review: Approve
Revision history for this message
Cody Garver (codygarver) wrote :

Non-GTK3 window shadows are still funky, but I guess that's outside the scope of this branch.

review: Approve (testing)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ShadowEffect.vala'
2--- src/ShadowEffect.vala 2014-07-18 05:37:33 +0000
3+++ src/ShadowEffect.vala 2016-02-16 18:06:07 +0000
4@@ -50,13 +50,14 @@
5 Cogl.Material material;
6 string? current_key = null;
7
8- public ShadowEffect (int actor_width, int actor_height, int shadow_size, int shadow_spread)
9+ public ShadowEffect (int shadow_size, int shadow_spread)
10 {
11 Object (shadow_size: shadow_size, shadow_spread: shadow_spread);
12+ }
13
14+ construct
15+ {
16 material = new Cogl.Material ();
17-
18- update_size (actor_width, actor_height);
19 }
20
21 ~ShadowEffect ()
22@@ -65,24 +66,18 @@
23 decrement_shadow_users (current_key);
24 }
25
26- public void update_size (int actor_width, int actor_height)
27- {
28- var shadow = get_shadow (actor_width, actor_height, shadow_size, shadow_spread);
29- material.set_layer (0, shadow);
30- }
31-
32- Cogl.Texture get_shadow (int actor_width, int actor_height, int shadow_size, int shadow_spread)
33- {
34- if (current_key != null) {
35- decrement_shadow_users (current_key);
36- }
37+ Cogl.Texture? get_shadow (int width, int height, int shadow_size, int shadow_spread)
38+ {
39+ var old_key = current_key;
40+
41+ current_key = "%ix%i:%i:%i".printf (width, height, shadow_size, shadow_spread);
42+ if (old_key == current_key)
43+ return null;
44+
45+ if (old_key != null)
46+ decrement_shadow_users (old_key);
47
48 Shadow? shadow = null;
49-
50- var width = actor_width + shadow_size * 2;
51- var height = actor_height + shadow_size * 2;
52-
53- current_key = "%ix%i:%i:%i".printf (width, height, shadow_size, shadow_spread);
54 if ((shadow = shadow_cache.@get (current_key)) != null) {
55 shadow.users++;
56 return shadow.texture;
57@@ -91,7 +86,7 @@
58 // fill a new texture for this size
59 var buffer = new Granite.Drawing.BufferSurface (width, height);
60 buffer.context.rectangle (shadow_size - shadow_spread, shadow_size - shadow_spread,
61- actor_width + shadow_spread * 2, actor_height + shadow_spread * 2);
62+ width - shadow_size * 2 + shadow_spread * 2, height - shadow_size * 2 + shadow_spread * 2);
63 buffer.context.set_source_rgba (0, 0, 0, 0.7);
64 buffer.context.fill ();
65
66@@ -124,7 +119,12 @@
67
68 public override void paint (EffectPaintFlags flags)
69 {
70- var size = shadow_size * scale_factor;
71+ var bounding_box = get_bounding_box ();
72+ var shadow = get_shadow ((int) (bounding_box.x2 - bounding_box.x1), (int) (bounding_box.y2 - bounding_box.y1),
73+ shadow_size, shadow_spread);
74+
75+ if (shadow != null)
76+ material.set_layer (0, shadow);
77
78 var opacity = actor.get_paint_opacity () * shadow_opacity / 255;
79 var alpha = Cogl.Color.from_4ub (255, 255, 255, opacity);
80@@ -133,10 +133,20 @@
81 material.set_color (alpha);
82
83 Cogl.set_source (material);
84- Cogl.rectangle (-size, -size, actor.width + size, actor.height + size);
85+ Cogl.rectangle (bounding_box.x1, bounding_box.y1, bounding_box.x2, bounding_box.y2);
86
87 actor.continue_paint ();
88 }
89+
90+ public virtual ActorBox get_bounding_box ()
91+ {
92+ var size = shadow_size * scale_factor;
93+ var bounding_box = ActorBox ();
94+
95+ bounding_box.set_origin (-size, -size);
96+ bounding_box.set_size (actor.width + size * 2, actor.height + size * 2);
97+
98+ return bounding_box;
99+ }
100 }
101 }
102-
103
104=== modified file 'src/Widgets/WindowClone.vala'
105--- src/Widgets/WindowClone.vala 2016-02-15 15:40:55 +0000
106+++ src/Widgets/WindowClone.vala 2016-02-16 18:06:07 +0000
107@@ -20,6 +20,31 @@
108
109 namespace Gala
110 {
111+ class WindowShadowEffect : ShadowEffect
112+ {
113+ public Meta.Window window { get; construct; }
114+
115+ public WindowShadowEffect (Meta.Window window, int shadow_size, int shadow_spread)
116+ {
117+ Object (window: window, shadow_size: shadow_size, shadow_spread: shadow_spread, shadow_opacity: 255);
118+ }
119+
120+ public override ActorBox get_bounding_box ()
121+ {
122+ var size = shadow_size * scale_factor;
123+
124+ var input_rect = window.get_buffer_rect ();
125+ var outer_rect = window.get_frame_rect ();
126+
127+ // Occupy only window frame area plus shadow size
128+ var bounding_box = ActorBox ();
129+ bounding_box.set_origin (-(input_rect.x - outer_rect.x) - size, -(input_rect.y - outer_rect.y) - size);
130+ bounding_box.set_size (outer_rect.width + size * 2, outer_rect.height + size * 2);
131+
132+ return bounding_box;
133+ }
134+ }
135+
136 /**
137 * A container for a clone of the texture of a MetaWindow, a WindowIcon,
138 * a close button and a shadow. Used together with the WindowCloneContainer.
139@@ -159,8 +184,6 @@
140
141 if (shadow_update_timeout != 0)
142 Source.remove (shadow_update_timeout);
143-
144- window.size_changed.disconnect (update_shadow_size);
145 }
146
147 /**
148@@ -198,10 +221,8 @@
149
150 transition_to_original_state (false);
151
152- var outer_rect = window.get_frame_rect ();
153- shadow_effect = new ShadowEffect (outer_rect.width, outer_rect.height, 40, 5);
154- add_effect_with_name ("shadow", shadow_effect);
155- window.size_changed.connect (update_shadow_size);
156+ shadow_effect = new WindowShadowEffect (window, 40, 5);
157+ clone.add_effect_with_name ("shadow", shadow_effect);
158
159 if (should_fade ())
160 opacity = 0;
161@@ -229,30 +250,6 @@
162 && window.get_workspace () != window.get_screen ().get_active_workspace ();
163 }
164
165- /**
166- * Sets a timeout of 500ms after which, if no new resize action reset it,
167- * the shadow will be resized and a request_reposition() will be emitted to
168- * make the WindowCloneContainer calculate a new layout to honor the new size.
169- */
170- void update_shadow_size ()
171- {
172- if (shadow_update_timeout != 0)
173- Source.remove (shadow_update_timeout);
174-
175- shadow_update_timeout = Timeout.add (500, () => {
176- var rect = window.get_frame_rect ();
177- var effect = get_effect ("shadow") as ShadowEffect;
178- effect.update_size (rect.width, rect.height);
179-
180- shadow_update_timeout = 0;
181-
182- // if there was a size change it makes sense to recalculate the positions
183- request_reposition ();
184-
185- return false;
186- });
187- }
188-
189 void on_all_workspaces_changed ()
190 {
191 // we don't display windows that are on all workspaces
192@@ -344,18 +341,15 @@
193 };
194 active_shape.allocate (shape_alloc, flags);
195
196- if (clone == null)
197+ if (clone == null || dragging)
198 return;
199
200- var actor = window.get_compositor_private () as WindowActor;
201+ var actor = (WindowActor) window.get_compositor_private ();
202 var input_rect = window.get_buffer_rect ();
203 var outer_rect = window.get_frame_rect ();
204 var scale_factor = (float)width / outer_rect.width;
205
206- var shadow_effect = get_effect ("shadow") as ShadowEffect;
207- shadow_effect.scale_factor = scale_factor;
208-
209- var alloc = ActorBox ();
210+ ActorBox alloc = {};
211 alloc.set_origin ((input_rect.x - outer_rect.x) * scale_factor,
212 (input_rect.y - outer_rect.y) * scale_factor);
213 alloc.set_size (actor.width * scale_factor, actor.height * scale_factor);
214@@ -427,9 +421,9 @@
215 shadow_transition.progress_mode = MultitaskingView.ANIMATION_MODE;
216
217 if (show)
218- shadow_transition.interval = new Clutter.Interval (typeof (uint8), 0, 255);
219+ shadow_transition.interval = new Clutter.Interval (typeof (uint8), shadow_effect.shadow_opacity, 255);
220 else
221- shadow_transition.interval = new Clutter.Interval (typeof (uint8), 255, 0);
222+ shadow_transition.interval = new Clutter.Interval (typeof (uint8), shadow_effect.shadow_opacity, 0);
223
224 add_transition ("shadow-opacity", shadow_transition);
225 }
226@@ -518,8 +512,6 @@
227
228 var scale = window_icon.width / clone.width;
229
230- ((ShadowEffect) get_effect ("shadow")).shadow_opacity = 0;
231-
232 clone.get_transformed_position (out abs_x, out abs_y);
233 clone.save_easing_state ();
234 clone.set_easing_duration (200);
235@@ -674,22 +666,13 @@
236 get_parent ().remove_child (this);
237 prev_parent.insert_child_at_index (this, prev_index);
238
239+ clone.set_pivot_point (0, 0);
240+
241 clone.save_easing_state ();
242 clone.set_easing_duration (250);
243 clone.set_easing_mode (AnimationMode.EASE_OUT_QUAD);
244 clone.set_scale (1, 1);
245 clone.opacity = 255;
246-
247- Clutter.Callback finished = () => {
248- ((ShadowEffect) get_effect ("shadow")).shadow_opacity = 255;
249- };
250-
251- var transition = clone.get_transition ("scale-x");
252- if (transition != null)
253- transition.completed.connect (() => finished (this));
254- else
255- finished (this);
256-
257 clone.restore_easing_state ();
258
259 request_reposition ();
260
261=== modified file 'src/Widgets/WorkspaceClone.vala'
262--- src/Widgets/WorkspaceClone.vala 2015-11-11 19:56:40 +0000
263+++ src/Widgets/WorkspaceClone.vala 2016-02-16 18:06:07 +0000
264@@ -35,7 +35,7 @@
265 var primary = screen.get_primary_monitor ();
266 var monitor_geom = screen.get_monitor_geometry (primary);
267
268- add_effect (new ShadowEffect (monitor_geom.width, monitor_geom.height, 40, 5));
269+ add_effect (new ShadowEffect (40, 5));
270 }
271
272 public override void paint ()

Subscribers

People subscribed via source and target branches