Skip to content

Commit

Permalink
Adding an option for notification screen selection
Browse files Browse the repository at this point in the history
Resolves #9891, resolves #10510, resolves #11684
  • Loading branch information
rcalixte committed Nov 15, 2023
1 parent 430422d commit 7beabf3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import gi
gi.require_version('Notify', '0.7')
from gi.repository import Notify
from gi.repository import Gio, Notify

from SettingsWidgets import SidePage
from xapp.GSettingsWidgets import *
Expand All @@ -29,6 +29,12 @@
("large", _("Large"))
]

NOTIFICATION_DISPLAY_SCREENS = [
("primary-screen", _("Primary screen")),
("active-screen", _("Active screen")),
("fixed-screen", _("Fixed screen"))
]


class Module:
name = "notifications"
Expand Down Expand Up @@ -62,6 +68,14 @@ def on_module_selected(self):
switch = GSettingsSwitch(_("Show notifications on the bottom side of the screen"), "org.cinnamon.desktop.notifications", "bottom-notifications")
settings.add_reveal_row(switch, "org.cinnamon.desktop.notifications", "display-notifications")

combo = GSettingsComboBox(_("Screen to use for displaying notifications"), "org.cinnamon.desktop.notifications", "notification-screen-display", NOTIFICATION_DISPLAY_SCREENS)
settings.add_reveal_row(combo, "org.cinnamon.desktop.notifications", "display-notifications")

spin = GSettingsSpinButton(_("Fixed screen number"), "org.cinnamon.desktop.notifications", "notification-fixed-screen", None, 1, 13, 1)
settings.add_reveal_row(spin, "org.cinnamon.desktop.notifications", "notification-fixed-screen")
spin.revealer.settings = Gio.Settings("org.cinnamon.desktop.notifications")
spin.revealer.settings.bind_with_mapping("notification-screen-display", spin.revealer, "reveal-child", Gio.SettingsBindFlags.GET, lambda option: option == "fixed-screen", None)

spin = GSettingsSpinButton(_("Notification duration"), "org.cinnamon.desktop.notifications", "notification-duration", _("seconds"), 1, 60, 1, 1)
settings.add_reveal_row(spin, "org.cinnamon.desktop.notifications", "display-notifications")

Expand Down
42 changes: 27 additions & 15 deletions js/ui/messageTray.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,14 @@ var Notification = class Notification {
/* FIXME: vscroll should be enabled
* -vfade covers too much for this size of scrollable
* -scrollview min-height is broken inside tray with a scrollview
*
*
* TODO: when scrollable:
*
*
* applet connects to this signal to enable captured-event passthru so you can grab the scrollbar:
* let vscroll = this._scrollArea.get_vscroll_bar();
* vscroll.connect('scroll-start', () => { this.emit('scrolling-changed', true) });
* vscroll.connect('scroll-stop', () => { this.emit('scrolling-changed', false) });
*
*
* `enable_mouse_scrolling` makes it difficult to scroll when there are many notifications
* in the tray because most of the area is these smaller scrollviews which capture the event.
* ideally, this should only be disabled when the notification is in the tray and there are
Expand Down Expand Up @@ -438,7 +438,7 @@ var Notification = class Notification {
/**
* scrollTo:
* @side (St.Side): St.Side.TOP or St.Side.BOTTOM
*
*
* Scrolls the content area (if scrollable) to the indicated edge
*/
scrollTo(side) {
Expand Down Expand Up @@ -501,11 +501,11 @@ var Notification = class Notification {
* addButton:
* @id (number): the action ID
* @label (string): the label for the action's button
*
*
* Adds a button with the given @label to the notification. All
* action buttons will appear in a single row at the bottom of
* the notification.
*
*
* If the button is clicked, the notification will emit the
* %action-invoked signal with @id as a parameter.
*/
Expand Down Expand Up @@ -545,7 +545,7 @@ var Notification = class Notification {

/**
* clearButtons:
*
*
* Removes all buttons.
*/
clearButtons() {
Expand Down Expand Up @@ -938,10 +938,21 @@ MessageTray.prototype = {
this._notificationBin.child = this._notification.actor;
this._notificationBin.opacity = 0;

let monitor = Main.layoutManager.primaryMonitor;
let topPanel = Main.panelManager.getPanel(monitor.index, 0);
let bottomPanel = Main.panelManager.getPanel(monitor.index, 1);
let rightPanel = Main.panelManager.getPanel(monitor.index, 3);
this._monitor = Main.layoutManager.primaryMonitor;
this._notificationScreenDisplay = this.settings.get_string("notification-screen-display");
let monitors = Main.layoutManager.monitors;
switch (this._notificationScreenDisplay) {
case "active-screen":
this._monitor = Main.layoutManager.currentMonitor;
break;
case "fixed-screen":
this._fixedScreenNum = this.settings.get_int("notification-fixed-screen");
if (this._fixedScreenNum <= monitors.length)
this._monitor = monitors[this._fixedScreenNum - 1];
}
let topPanel = Main.panelManager.getPanel(this._monitor.index, 0);
let bottomPanel = Main.panelManager.getPanel(this._monitor.index, 1);
let rightPanel = Main.panelManager.getPanel(this._monitor.index, 3);
let topGap = 10;
let bottomGap = 10;
let rightGap = 0;
Expand All @@ -954,11 +965,11 @@ MessageTray.prototype = {
if (topPanel) {
topGap += topPanel.actor.get_height();
}
this._notificationBin.y = monitor.y + topGap; // Notifications appear from here (for the animation)
this._notificationBin.y = this._monitor.y + topGap; // Notifications appear from here (for the animation)
}

let margin = this._notification._table.get_theme_node().get_length('margin-from-right-edge-of-screen');
this._notificationBin.x = monitor.x + monitor.width - this._notification._table.width - margin - rightGap;
this._notificationBin.x = this._monitor.x + this._monitor.width - this._notification._table.width - margin - rightGap;
if (!this._notification.silent || this._notification.urgency >= Urgency.HIGH) {
Main.soundManager.play('notification');
}
Expand All @@ -974,7 +985,7 @@ MessageTray.prototype = {
bottomGap += bottomPanel.actor.get_height();
}
let getBottomPositionY = () => {
return monitor.y + monitor.height - this._notificationBin.height - bottomGap;
return this._monitor.y + this._monitor.height - this._notificationBin.height - bottomGap;
};
let shouldReturn = false;
let initialY = getBottomPositionY();
Expand Down Expand Up @@ -1037,7 +1048,7 @@ MessageTray.prototype = {
_notificationTimeout: function() {
let [x, y, mods] = global.get_pointer();
let distance = Math.abs(this._notificationBin.y - y);
if (distance < this._lastSeenMouseDistance - 50 || this._notification.actor.hover) {
if (distance < this._lastSeenMouseDistance - 50 || this._notification && this._notification.actor.hover) {
// The mouse is moving towards the notification, so don't
// hide it yet. (We just create a new timeout (and destroy
// the old one) each time because the bookkeeping is simpler.)
Expand All @@ -1054,6 +1065,7 @@ MessageTray.prototype = {

_hideNotification: function() {
let y = Main.layoutManager.primaryMonitor.y;

if (this.bottomPosition) {
if (this.bottomPositionSignal) {
this._notificationBin.disconnect(this.bottomPositionSignal);
Expand Down

0 comments on commit 7beabf3

Please sign in to comment.