@@ -13,7 +13,7 @@ public class Gala.CloseButton : Clutter.Actor {
1313
1414 // used to avoid changing hitbox of the button
1515 private Clutter . Actor pixbuf_actor;
16- private bool is_pressed = false ;
16+ private Clutter . ClickAction click_action ;
1717
1818 static construct {
1919 close_pixbufs = new Gee .HashMap<int, Gdk . Pixbuf ?> ();
@@ -31,10 +31,30 @@ public class Gala.CloseButton : Clutter.Actor {
3131 };
3232 add_child (pixbuf_actor);
3333
34+ click_action = new Clutter .ClickAction ();
35+ add_action (click_action);
36+ click_action. clicked. connect (on_clicked);
37+ click_action. notify[" pressed" ]. connect (on_pressed_changed);
38+
3439 load_pixbuf ();
3540 notify[" monitor-scale" ]. connect (load_pixbuf);
3641 }
3742
43+ private void on_clicked () {
44+ triggered (Meta . CURRENT_TIME );
45+ }
46+
47+ private void on_pressed_changed () {
48+ var estimated_duration = Utils . get_animation_duration ((uint ) (ANIMATION_DURATION * (scale_x - 0.8 ) / 0.2 ));
49+ var scale = click_action. pressed ? 0.8 : 1.0 ;
50+
51+ pixbuf_actor. save_easing_state ();
52+ pixbuf_actor. set_easing_duration (estimated_duration);
53+ pixbuf_actor. set_easing_mode (Clutter . AnimationMode . EASE_IN_OUT );
54+ pixbuf_actor. set_scale (scale, scale);
55+ pixbuf_actor. restore_easing_state ();
56+ }
57+
3858 private void load_pixbuf () {
3959 var pixbuf = get_close_button_pixbuf (monitor_scale);
4060 if (pixbuf != null ) {
@@ -77,46 +97,4 @@ public class Gala.CloseButton : Clutter.Actor {
7797 pixbuf_actor. set_size (size, size);
7898 pixbuf_actor. background_color = { 255 , 0 , 0 , 255 };
7999 }
80-
81- public override bool button_press_event (Clutter . Event e) {
82- var estimated_duration = Utils . get_animation_duration ((uint ) (ANIMATION_DURATION * (scale_x - 0.8 ) / 0.2 ));
83-
84- pixbuf_actor. save_easing_state ();
85- pixbuf_actor. set_easing_duration (estimated_duration);
86- pixbuf_actor. set_easing_mode (Clutter . AnimationMode . EASE_IN_OUT );
87- pixbuf_actor. set_scale (0.8 , 0.8 );
88- pixbuf_actor. restore_easing_state ();
89-
90- is_pressed = true ;
91-
92- return Clutter . EVENT_STOP ;
93- }
94-
95- public override bool button_release_event (Clutter . Event e) {
96- reset_scale ();
97-
98- if (is_pressed) {
99- triggered (e. get_time ());
100- is_pressed = false ;
101- }
102-
103- return Clutter . EVENT_STOP ;
104- }
105-
106- public override bool leave_event (Clutter . Event event) {
107- reset_scale ();
108- is_pressed = false ;
109-
110- return Clutter . EVENT_PROPAGATE ;
111- }
112-
113- private void reset_scale () {
114- var estimated_duration = Utils . get_animation_duration ((uint ) (ANIMATION_DURATION * (1.0 - scale_x) / 0.2 ));
115-
116- pixbuf_actor. save_easing_state ();
117- pixbuf_actor. set_easing_duration (estimated_duration);
118- pixbuf_actor. set_easing_mode (Clutter . AnimationMode . EASE_IN_OUT );
119- pixbuf_actor. set_scale (1.0 , 1.0 );
120- pixbuf_actor. restore_easing_state ();
121- }
122100}
0 commit comments