~gala-dev/gala/windowswitcher-fade-opacity

« back to all changes in this revision

Viewing changes to src/Widgets/WindowThumb.vala

  • Committer: Rico Tzschichholz
  • Date: 2014-04-08 12:51:06 UTC
  • Revision ID: ricotz@ubuntu.com-20140408125106-6ahv3pbbwilck1pi
codestyle: Drop trailing spaces/tabs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  
 
1
//
2
2
//  Copyright (C) 2012 Tom Beckmann
3
 
// 
 
3
//
4
4
//  This program is free software: you can redistribute it and/or modify
5
5
//  it under the terms of the GNU General Public License as published by
6
6
//  the Free Software Foundation, either version 3 of the License, or
7
7
//  (at your option) any later version.
8
 
// 
 
8
//
9
9
//  This program is distributed in the hope that it will be useful,
10
10
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
12
//  GNU General Public License for more details.
13
 
// 
 
13
//
14
14
//  You should have received a copy of the GNU General Public License
15
15
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
// 
 
16
//
17
17
 
18
18
using Meta;
19
19
using Clutter;
28
28
                public GtkClutter.Texture close_button;
29
29
 
30
30
                const int WAIT_FOR_CONFIRMATION_DIALOG = 100;
31
 
                
 
31
 
32
32
                public signal void selected (Window window);
33
33
                public signal void closed ();
34
 
                
 
34
 
35
35
                public WindowThumb (Window _window)
36
36
                {
37
37
                        window = _window;
38
 
                        
 
38
 
39
39
                        reactive = true;
40
 
                        
 
40
 
41
41
                        var actor = window.get_compositor_private () as WindowActor;
42
42
                        clone = new Clone (actor);
43
 
                        
 
43
 
44
44
                        icon = new GtkClutter.Texture ();
45
45
                        icon.scale_x = 0.0f;
46
46
                        icon.scale_y = 0.0f;
47
47
                        icon.scale_gravity = Gravity.CENTER;
48
 
                        
 
48
 
49
49
                        try {
50
50
                                icon.set_from_pixbuf (Utils.get_icon_for_window (window, 64));
51
51
                        } catch (Error e) { warning (e.message); }
52
 
                        
 
52
 
53
53
                        close_button = new GtkClutter.Texture ();
54
54
                        close_button.reactive = true;
55
55
                        close_button.visible = false;
58
58
                        close_button.scale_gravity = Gravity.CENTER;
59
59
                        close_button.button_release_event.connect (close_button_clicked);
60
60
                        close_button.leave_event.connect ((e) => leave_event (e));
61
 
                        
 
61
 
62
62
                        try {
63
63
                                close_button.set_from_pixbuf (Granite.Widgets.Utils.get_close_pixbuf ());
64
64
                        } catch (Error e) { warning (e.message); }
65
 
                        
 
65
 
66
66
                        add_child (clone);
67
 
                        
 
67
 
68
68
                        var stage = Compositor.get_stage_for_screen (window.get_screen ());
69
69
                        stage.add_child (icon);
70
70
                        stage.add_child (close_button);
71
71
                }
72
 
                
 
72
 
73
73
                bool close_button_clicked (ButtonEvent event)
74
74
                {
75
75
                        if (event.button != 1)
76
76
                                return false;
77
 
                        
 
77
 
78
78
                        close_window ();
79
 
                        
 
79
 
80
80
                        return true;
81
81
                }
82
 
                
 
82
 
83
83
                public void close_window ()
84
84
                {
85
85
                        get_parent ().set_child_below_sibling (this, null);
102
102
                        clone.destroy ();
103
103
                        close_button.destroy ();
104
104
                        icon.destroy ();
105
 
                        
 
105
 
106
106
                        base.destroy ();
107
107
                }
108
 
                
 
108
 
109
109
                public override bool enter_event (CrossingEvent event)
110
110
                {
111
111
                        //if we're still animating don't show the close button
112
112
                        if (get_animation () != null)
113
113
                                return false;
114
 
                        
 
114
 
115
115
                        close_button.visible = true;
116
116
                        close_button.animate (AnimationMode.EASE_OUT_ELASTIC, 400, scale_x : 1.0f, scale_y : 1.0f);
117
 
                        
 
117
 
118
118
                        return true;
119
119
                }
120
 
                
 
120
 
121
121
                public override bool motion_event (MotionEvent event)
122
122
                {
123
123
                        if (get_animation () != null)
124
124
                                return false;
125
 
                        
 
125
 
126
126
                        close_button.visible = true;
127
127
                        close_button.animate (AnimationMode.EASE_OUT_ELASTIC, 400, scale_x : 1.0f, scale_y : 1.0f);
128
 
                        
 
128
 
129
129
                        return true;
130
130
                }
131
 
                
 
131
 
132
132
                public override bool leave_event (CrossingEvent event)
133
133
                {
134
134
                        if (event.related == close_button)
135
135
                                return false;
136
 
                        
 
136
 
137
137
                        close_button.animate (AnimationMode.EASE_IN_QUAD, 200, scale_x : 0.0f, scale_y : 0.0f)
138
138
                                .completed.connect (() => close_button.visible = false );
139
 
                        
 
139
 
140
140
                        return true;
141
141
                }
142
 
                
 
142
 
143
143
                public override bool button_release_event (ButtonEvent event)
144
144
                {
145
145
                        switch (event.button) {
151
151
                                        close_window ();
152
152
                                        break;
153
153
                        }
154
 
                        
 
154
 
155
155
                        return true;
156
156
                }
157
 
                
 
157
 
158
158
                public void close (bool do_animate = true)
159
159
                {
160
160
                        unowned Meta.Rectangle rect = window.get_outer_rect ();
161
 
                        
 
161
 
162
162
                        //FIXME need to subtract 10 here to remove jump for most windows, but adds jump for maximized ones
163
163
                        float delta = window.maximized_horizontally || window.maximized_vertically ? 0 : 10;
164
 
                        
 
164
 
165
165
                        float dest_x = rect.x - delta;
166
166
                        float dest_y = rect.y - delta;
167
 
                        
 
167
 
168
168
                        //stop all running animations
169
169
                        detach_animation ();
170
170
                        icon.detach_animation ();
171
171
                        close_button.detach_animation ();
172
 
                        
 
172
 
173
173
                        bool dont_show = window.minimized || window.get_workspace () != window.get_screen ().get_active_workspace ();
174
174
                        do_animate = do_animate && !dont_show;
175
 
                        
 
175
 
176
176
                        if (do_animate) {
177
177
                                icon.animate (AnimationMode.EASE_IN_CUBIC, 100, scale_x:0.0f, scale_y:0.0f);
178
178
                                close_button.animate (AnimationMode.EASE_IN_QUAD, 200, scale_x : 0.0f, scale_y : 0.0f);
179
 
                                
 
179
 
180
180
                                animate (AnimationMode.EASE_IN_OUT_CUBIC, 300, scale_x:1.0f, scale_y:1.0f, x:dest_x, y:dest_y).completed.connect (() => {
181
181
                                        clone.source.show ();
182
182
                                        destroy ();