2014-06-23 19:41:54 +04:00
|
|
|
//
|
|
|
|
// Copyright (C) 2014 Tom Beckmann
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
using Clutter;
|
|
|
|
using Meta;
|
|
|
|
|
|
|
|
namespace Gala.Plugins.Notify
|
|
|
|
{
|
|
|
|
public class NotificationStack : Actor
|
|
|
|
{
|
2014-07-20 00:41:50 +04:00
|
|
|
const int ADDITIONAL_MARGIN = 12;
|
|
|
|
|
2014-06-23 19:41:54 +04:00
|
|
|
public signal void animations_changed (bool running);
|
|
|
|
|
2014-06-24 03:27:33 +04:00
|
|
|
public Screen screen { get; construct; }
|
|
|
|
|
2014-06-23 19:41:54 +04:00
|
|
|
int animation_counter = 0;
|
|
|
|
|
2014-06-24 03:27:33 +04:00
|
|
|
public NotificationStack (Screen screen)
|
2014-06-23 19:41:54 +04:00
|
|
|
{
|
2014-06-24 03:27:33 +04:00
|
|
|
Object (screen: screen);
|
2014-07-19 13:37:14 +04:00
|
|
|
}
|
2014-06-24 03:27:33 +04:00
|
|
|
|
2014-07-19 13:37:14 +04:00
|
|
|
construct
|
|
|
|
{
|
2014-07-20 00:41:50 +04:00
|
|
|
width = Notification.WIDTH + 2 * Notification.MARGIN + ADDITIONAL_MARGIN;
|
|
|
|
clip_to_allocation = true;
|
2014-06-23 19:41:54 +04:00
|
|
|
}
|
|
|
|
|
2014-07-18 15:12:31 +04:00
|
|
|
public void show_notification (Notification notification)
|
2014-06-23 19:41:54 +04:00
|
|
|
{
|
|
|
|
if (animation_counter == 0)
|
|
|
|
animations_changed (true);
|
|
|
|
|
2014-07-21 19:48:34 +04:00
|
|
|
// raise ourselves when we got something to show
|
|
|
|
get_parent ().set_child_above_sibling (this, null);
|
|
|
|
|
2014-07-20 00:41:50 +04:00
|
|
|
// we have a shoot-over on the start of the close animation, which gets clipped
|
|
|
|
// unless we make our container a bit wider and move the notifications over
|
|
|
|
notification.margin_left = ADDITIONAL_MARGIN;
|
|
|
|
|
2014-07-18 15:12:31 +04:00
|
|
|
notification.destroy.connect (() => {
|
|
|
|
update_positions ();
|
|
|
|
});
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2014-06-28 03:47:13 +04:00
|
|
|
float height;
|
|
|
|
notification.get_preferred_height (Notification.WIDTH, out height, null);
|
2014-07-18 15:12:31 +04:00
|
|
|
update_positions (height);
|
2014-06-28 03:47:13 +04:00
|
|
|
|
|
|
|
insert_child_at_index (notification, 0);
|
2014-06-23 19:41:54 +04:00
|
|
|
|
|
|
|
animation_counter++;
|
|
|
|
|
|
|
|
notification.get_transition ("entry").completed.connect (() => {
|
|
|
|
if (--animation_counter == 0)
|
|
|
|
animations_changed (false);
|
|
|
|
});
|
|
|
|
}
|
2014-06-28 03:47:13 +04:00
|
|
|
|
|
|
|
void update_positions (float add_y = 0.0f)
|
|
|
|
{
|
|
|
|
var y = add_y;
|
|
|
|
var i = get_n_children ();
|
|
|
|
var delay_step = i > 0 ? 150 / i : 0;
|
|
|
|
foreach (var child in get_children ()) {
|
|
|
|
if (((Notification) child).being_destroyed)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
child.save_easing_state ();
|
|
|
|
child.set_easing_mode (AnimationMode.EASE_OUT_BACK);
|
|
|
|
child.set_easing_duration (200);
|
|
|
|
child.set_easing_delay ((i--) * delay_step);
|
|
|
|
|
|
|
|
child.y = y;
|
|
|
|
child.restore_easing_state ();
|
|
|
|
|
|
|
|
y += child.height;
|
|
|
|
}
|
|
|
|
}
|
2014-06-23 19:41:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|