From 7592e8947fde4842a8fe966ec6b9e3fb2c8ccd3b Mon Sep 17 00:00:00 2001 From: "Martin T. H. Sandsmark" Date: Sat, 18 Jun 2016 20:42:46 +0200 Subject: [PATCH] Don't show activity/silence notifications when the terminal is active REVIEW: 128239 BUG: 257752 --- desktop/konsole.notifyrc | 9 +++++++++ src/Session.cpp | 34 +++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/desktop/konsole.notifyrc b/desktop/konsole.notifyrc index a2721cf5..19cf8217 100644 --- a/desktop/konsole.notifyrc +++ b/desktop/konsole.notifyrc @@ -426,6 +426,11 @@ Comment[zh_TW]=非可見工作階段中的響鈴行為 Sound=Oxygen-Sys-App-Message.ogg Action=Popup +[Event/ActivityHidden] +Name=Activity in Hidden Monitored Session +Comment=Activity detected in a hidden monitored session +Action=Popup + [Event/Activity] Name=Activity in Monitored Session Name[af]=Aktiwiteit in gemonitorde sessie @@ -591,6 +596,10 @@ Comment[zh_CN]=被监视会话中检测到的活动 Comment[zh_TW]=監控工作階段中偵測到的活動 Action=Popup +[Event/SilenceHidden] +Name=Silence in Hidden Monitored Session +Comment=Silence detected in a hidden monitored session +Action=Popup [Event/Silence] Name=Silence in Monitored Session diff --git a/src/Session.cpp b/src/Session.cpp index 3eb3f70e..768dc06a 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -598,14 +598,24 @@ void Session::silenceTimerDone() //when any of the views of the session becomes active //FIXME: Make message text for this notification and the activity notification more descriptive. - if (_monitorSilence) { - KNotification::event("Silence", i18n("Silence in session '%1'", _nameTitle), QPixmap(), - QApplication::activeWindow(), - KNotification::CloseWhenWidgetActivated); - emit stateChanged(NOTIFYSILENCE); - } else { + if (!_monitorSilence) { emit stateChanged(NOTIFYNORMAL); + return; } + + bool hasFocus = false; + for (TerminalDisplay *display : _views) { + if (display->hasFocus()) { + hasFocus = true; + break; + } + } + + KNotification::event(hasFocus ? "Silence" : "SilenceHidden", + i18n("Silence in session '%1'", _nameTitle), QPixmap(), + QApplication::activeWindow(), + KNotification::CloseWhenWidgetActivated); + emit stateChanged(NOTIFYSILENCE); } void Session::activityTimerDone() @@ -652,8 +662,18 @@ void Session::activityStateSet(int state) if (state == NOTIFYBELL) { emit bellRequest(i18n("Bell in session '%1'", _nameTitle)); } else if (state == NOTIFYACTIVITY) { + // Don't notify if the terminal is active + bool hasFocus = false; + for (TerminalDisplay *display : _views) { + if (display->hasFocus()) { + hasFocus = true; + break; + } + } + if (_monitorActivity && !_notifiedActivity) { - KNotification::event("Activity", i18n("Activity in session '%1'", _nameTitle), QPixmap(), + KNotification::event(hasFocus ? "Activity" : "ActivityHidden", + i18n("Activity in session '%1'", _nameTitle), QPixmap(), QApplication::activeWindow(), KNotification::CloseWhenWidgetActivated);