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;
|
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
namespace Gala.Plugins.Notify {
|
|
|
|
public class Main : Gala.Plugin {
|
2020-01-15 00:59:01 +03:00
|
|
|
private GLib.Settings behavior_settings;
|
2020-01-09 22:26:30 +03:00
|
|
|
Gala.WindowManager? wm = null;
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
NotifyServer server;
|
|
|
|
NotificationStack stack;
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2020-01-15 00:59:01 +03:00
|
|
|
uint owner_id = 0U;
|
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
public override void initialize (Gala.WindowManager wm) {
|
2020-01-15 00:59:01 +03:00
|
|
|
behavior_settings = new GLib.Settings ("org.pantheon.desktop.gala.behavior");
|
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
this.wm = wm;
|
2019-11-01 00:22:38 +03:00
|
|
|
#if HAS_MUTTER330
|
2020-01-09 22:26:30 +03:00
|
|
|
unowned Meta.Display display = wm.get_display ();
|
2019-11-01 00:22:38 +03:00
|
|
|
#else
|
2020-01-09 22:26:30 +03:00
|
|
|
var screen = wm.get_screen ();
|
2019-11-01 00:22:38 +03:00
|
|
|
#endif
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2019-11-01 00:22:38 +03:00
|
|
|
#if HAS_MUTTER330
|
2020-01-09 22:26:30 +03:00
|
|
|
stack = new NotificationStack (display);
|
2019-11-01 00:22:38 +03:00
|
|
|
#else
|
2020-01-09 22:26:30 +03:00
|
|
|
stack = new NotificationStack (screen);
|
2019-11-01 00:22:38 +03:00
|
|
|
#endif
|
2020-01-09 22:26:30 +03:00
|
|
|
stack.animations_changed.connect ((running) => {
|
|
|
|
freeze_track = running;
|
|
|
|
});
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2020-01-15 00:59:01 +03:00
|
|
|
screen.monitors_changed.connect (update_position);
|
|
|
|
screen.workareas_changed.connect (update_position);
|
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
server = new NotifyServer (stack);
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2020-01-15 00:59:01 +03:00
|
|
|
if (!behavior_settings.get_boolean ("use-new-notifications")) {
|
|
|
|
enable ();
|
|
|
|
}
|
|
|
|
|
|
|
|
behavior_settings.changed["use-new-notifications"].connect (() => {
|
|
|
|
if (!behavior_settings.get_boolean ("use-new-notifications")) {
|
|
|
|
enable ();
|
|
|
|
} else {
|
|
|
|
disable ();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void enable ()
|
|
|
|
{
|
|
|
|
if (owner_id != 0U) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wm.ui_group.add_child (stack);
|
|
|
|
track_actor (stack);
|
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
update_position ();
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2020-01-15 00:59:01 +03:00
|
|
|
owner_id = Bus.own_name (BusType.SESSION, "org.freedesktop.Notifications", BusNameOwnerFlags.REPLACE,
|
2020-01-09 22:26:30 +03:00
|
|
|
(connection) => {
|
|
|
|
try {
|
|
|
|
connection.register_object ("/org/freedesktop/Notifications", server);
|
|
|
|
} catch (Error e) {
|
|
|
|
warning ("Registring notification server failed: %s", e.message);
|
|
|
|
destroy ();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
() => {},
|
|
|
|
(con, name) => {
|
|
|
|
warning ("Could not aquire bus %s", name);
|
|
|
|
destroy ();
|
|
|
|
});
|
|
|
|
}
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
void disable () {
|
2020-01-15 00:59:01 +03:00
|
|
|
if (owner_id == 0U) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bus.unown_name (owner_id);
|
|
|
|
|
|
|
|
untrack_actor (stack);
|
|
|
|
wm.ui_group.remove_child (stack);
|
|
|
|
|
|
|
|
owner_id = 0U;
|
|
|
|
}
|
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
void update_position () {
|
2019-11-01 00:22:38 +03:00
|
|
|
#if HAS_MUTTER330
|
2020-01-09 22:26:30 +03:00
|
|
|
unowned Meta.Display display = wm.get_display ();
|
|
|
|
var primary = display.get_primary_monitor ();
|
|
|
|
var area = display.get_workspace_manager ().get_active_workspace ().get_work_area_for_monitor (primary);
|
2019-11-01 00:22:38 +03:00
|
|
|
#else
|
2020-01-09 22:26:30 +03:00
|
|
|
var screen = wm.get_screen ();
|
|
|
|
var primary = screen.get_primary_monitor ();
|
|
|
|
var area = screen.get_active_workspace ().get_work_area_for_monitor (primary);
|
2019-11-01 00:22:38 +03:00
|
|
|
#endif
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
stack.x = area.x + area.width - stack.width;
|
|
|
|
stack.y = area.y;
|
|
|
|
}
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
public override void destroy () {
|
2020-01-09 22:26:30 +03:00
|
|
|
if (wm == null)
|
|
|
|
return;
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2020-01-09 22:26:30 +03:00
|
|
|
untrack_actor (stack);
|
|
|
|
stack.destroy ();
|
|
|
|
}
|
|
|
|
}
|
2014-06-23 19:41:54 +04:00
|
|
|
}
|
|
|
|
|
2020-01-15 03:44:21 +03:00
|
|
|
public Gala.PluginInfo register_plugin () {
|
2020-01-09 22:26:30 +03:00
|
|
|
return Gala.PluginInfo () {
|
|
|
|
name = "Notify",
|
|
|
|
author = "Gala Developers",
|
|
|
|
plugin_type = typeof (Gala.Plugins.Notify.Main),
|
|
|
|
provides = Gala.PluginFunction.ADDITION,
|
|
|
|
load_priority = Gala.LoadPriority.IMMEDIATE
|
|
|
|
};
|
2014-06-23 19:41:54 +04:00
|
|
|
}
|