diff --git a/korgac/alarmdialog.h b/korgac/alarmdialog.h --- a/korgac/alarmdialog.h +++ b/korgac/alarmdialog.h @@ -134,6 +134,7 @@ ReminderList selectedItems() const; void toggleDetails(QTreeWidgetItem *item); void showDetails(QTreeWidgetItem *item); + static bool grabFocus(); Akonadi::ETMCalendar::Ptr mCalendar; QTreeWidget *mIncidenceTree = nullptr; diff --git a/korgac/alarmdialog.cpp b/korgac/alarmdialog.cpp --- a/korgac/alarmdialog.cpp +++ b/korgac/alarmdialog.cpp @@ -626,7 +626,11 @@ KWindowSystem::unminimizeWindow(winId(), false); KWindowSystem::setState(winId(), NET::KeepAbove | NET::DemandsAttention); KWindowSystem::setOnAllDesktops(winId(), true); - KWindowSystem::activateWindow(winId()); + if (grabFocus()) { + KWindowSystem::activateWindow(winId()); + } else { + KWindowSystem::raiseWindow(winId()); + } // Audio, Procedure, and EMail alarms eventNotification(); @@ -1099,3 +1103,10 @@ } genGroup.sync(); } + +bool AlarmDialog::grabFocus() +{ + KSharedConfig::Ptr config = KSharedConfig::openConfig(); + KConfigGroup generalConfig(config, "General"); + return generalConfig.readEntry("GrabFocus", false); +} diff --git a/korgac/alarmdockwindow.h b/korgac/alarmdockwindow.h --- a/korgac/alarmdockwindow.h +++ b/korgac/alarmdockwindow.h @@ -42,6 +42,7 @@ public Q_SLOTS: void toggleAlarmsEnabled(bool checked); void toggleAutostart(bool checked); + void toggleGrabFocus(bool checked); void slotUpdate(int reminders); Q_SIGNALS: @@ -65,6 +66,11 @@ QAction *mAutostart = nullptr; QAction *mSuspendAll = nullptr; QAction *mDismissAll = nullptr; + // True/Enable if the notify daemon should grab focus (activate window) away + // from the current application. This makes it easy to dismiss, but if the + // user is typing AlarmDialog now gets those keys and space or return will + // dismiss all notifications before the user has a chance to read them. + QAction *mGrabFocus = nullptr; bool mAutostartSet = false; }; diff --git a/korgac/alarmdockwindow.cpp b/korgac/alarmdockwindow.cpp --- a/korgac/alarmdockwindow.cpp +++ b/korgac/alarmdockwindow.cpp @@ -44,6 +44,7 @@ KConfigGroup config(KSharedConfig::openConfig(), "General"); const bool autostartSet = config.hasKey("Autostart"); const bool autostart = config.readEntry("Autostart", true); + const bool grabFocus = config.readEntry("GrabFocus", false); const bool alarmsEnabled = config.readEntry("Enabled", true); mName = i18nc("@title:window", "KOrganizer Reminder Daemon"); @@ -92,6 +93,17 @@ mAlarmsEnabled->setChecked(alarmsEnabled); mAutostart->setChecked(autostart); + mGrabFocus = + contextMenu()->addAction(i18nc( "@action:inmenu", "Reminder Requests Focus")); + mGrabFocus->setToolTip(i18nc("@info:tooltip", + "When this option is enabled the reminder dialog will " + "automatically receive keyboard focus when it opens.")); + connect(mGrabFocus, &QAction::toggled, this, &AlarmDockWindow::toggleGrabFocus); + // ToolTips aren't enabled for menus by default. + contextMenu()->setToolTipsVisible(true); + mGrabFocus->setCheckable(true); + mGrabFocus->setChecked(grabFocus); + // Disable standard quit behaviour. We have to intercept the quit even, // if the main window is hidden. QAction *act = action(QStringLiteral("quit")); @@ -139,6 +151,12 @@ enableAutostart(checked); } +void AlarmDockWindow::toggleGrabFocus(bool checked) +{ + KConfigGroup config(KSharedConfig::openConfig(), "General"); + config.writeEntry("GrabFocus", checked); +} + void AlarmDockWindow::slotSuspendAll() { Q_EMIT suspendAllSignal();