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-08-11 22:47:41 +04:00
|
|
|
// we need to keep a small offset to the top, because we clip the container to
|
|
|
|
// its allocations and the close button would be off for the first notification
|
|
|
|
const int TOP_OFFSET = 2;
|
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; }
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2019-05-14 12:20:50 +03:00
|
|
|
var scale = Utils.get_ui_scaling_factor ();
|
2017-09-26 01:59:55 +03:00
|
|
|
width = (Notification.WIDTH + 2 * Notification.MARGIN + ADDITIONAL_MARGIN) * scale;
|
2014-07-20 00:41:50 +04:00
|
|
|
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
|
|
|
{
|
2016-07-29 01:19:16 +03:00
|
|
|
animations_changed (true);
|
2019-05-14 12:20:50 +03:00
|
|
|
var scale = Utils.get_ui_scaling_factor ();
|
2014-06-23 19:41:54 +04:00
|
|
|
|
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
|
2017-09-26 01:59:55 +03:00
|
|
|
notification.margin_left = ADDITIONAL_MARGIN * scale;
|
2014-07-20 00:41:50 +04:00
|
|
|
|
2016-07-29 01:19:16 +03:00
|
|
|
notification.notify["being-destroyed"].connect (() => {
|
|
|
|
animations_changed (true);
|
|
|
|
});
|
|
|
|
|
2014-07-18 15:12:31 +04:00
|
|
|
notification.destroy.connect (() => {
|
2016-07-29 01:19:16 +03:00
|
|
|
animations_changed (false);
|
2014-07-18 15:12:31 +04:00
|
|
|
update_positions ();
|
|
|
|
});
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2016-07-29 01:19:16 +03:00
|
|
|
notification.get_transition ("entry").completed.connect (() => {
|
|
|
|
animations_changed (false);
|
|
|
|
});
|
|
|
|
|
2014-06-28 03:47:13 +04:00
|
|
|
float height;
|
2017-09-26 01:59:55 +03:00
|
|
|
notification.get_preferred_height (Notification.WIDTH * scale, out height, null);
|
2014-07-18 15:12:31 +04:00
|
|
|
update_positions (height);
|
2014-06-28 03:47:13 +04:00
|
|
|
|
2017-09-26 01:59:55 +03:00
|
|
|
notification.y = TOP_OFFSET * scale;
|
2014-06-28 03:47:13 +04:00
|
|
|
insert_child_at_index (notification, 0);
|
2014-06-23 19:41:54 +04:00
|
|
|
}
|
2014-06-28 03:47:13 +04:00
|
|
|
|
|
|
|
void update_positions (float add_y = 0.0f)
|
|
|
|
{
|
2019-05-14 12:20:50 +03:00
|
|
|
var scale = Utils.get_ui_scaling_factor ();
|
2017-09-26 01:59:55 +03:00
|
|
|
var y = add_y + TOP_OFFSET * scale;
|
2014-06-28 03:47:13 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|