parent
1a2867c8ec
commit
6750868060
5 changed files with 117 additions and 60 deletions
@ -0,0 +1,63 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2006-2008 Robert Knight <robertknight@gmail.com> |
||||
SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de> |
||||
SPDX-FileCopyrightText: 2021 Jonah Brüchert <jbb@kaidan.im> |
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later |
||||
*/ |
||||
|
||||
#include "TerminalBell.h" |
||||
|
||||
#include <QTimer> |
||||
|
||||
#include <KNotification> |
||||
|
||||
#include <chrono> |
||||
|
||||
using namespace std::literals::chrono_literals; |
||||
|
||||
namespace Konsole { |
||||
|
||||
constexpr auto MASK_TIMEOUT = 500ms; |
||||
|
||||
TerminalBell::TerminalBell(Enum::BellModeEnum bellMode) |
||||
: _bellMode(bellMode) |
||||
{ |
||||
} |
||||
|
||||
void TerminalBell::bell(const QString &message, bool terminalHasFocus) |
||||
{ |
||||
switch (_bellMode) { |
||||
case Enum::SystemBeepBell: |
||||
KNotification::beep(); |
||||
break; |
||||
case Enum::NotifyBell: |
||||
// STABLE API:
|
||||
// Please note that these event names, "BellVisible" and "BellInvisible",
|
||||
// should not change and should be kept stable, because other applications
|
||||
// that use this code via KPart rely on these names for notifications.
|
||||
KNotification::event(terminalHasFocus ? QStringLiteral("BellVisible") : QStringLiteral("BellInvisible"), |
||||
message, QPixmap()); |
||||
break; |
||||
case Enum::VisualBell: |
||||
Q_EMIT visualBell(); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
|
||||
// limit the rate at which bells can occur.
|
||||
// ...mainly for sound effects where rapid bells in sequence
|
||||
// produce a horrible noise.
|
||||
_bellMasked = true; |
||||
QTimer::singleShot(MASK_TIMEOUT, this, [this]() { |
||||
_bellMasked = false; |
||||
}); |
||||
} |
||||
|
||||
void TerminalBell::setBellMode(Enum::BellModeEnum mode) |
||||
{ |
||||
_bellMode = mode; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,43 @@ |
||||
/*
|
||||
SPDX-FileCopyrightText: 2006-2008 Robert Knight <robertknight@gmail.com> |
||||
SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de> |
||||
SPDX-FileCopyrightText: 2021 Jonah Brüchert <jbb@kaidan.im> |
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
|
||||
#include <QObject> |
||||
|
||||
#include <Enumeration.h> |
||||
|
||||
namespace Konsole |
||||
{ |
||||
|
||||
class TerminalBell : public QObject { |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
TerminalBell(Enum::BellModeEnum bellMode); |
||||
void bell(const QString &message, bool terminalHasFocus); |
||||
|
||||
/**
|
||||
* Sets the type of effect used to alert the user when a 'bell' occurs in the |
||||
* terminal session. |
||||
* |
||||
* The terminal session can trigger the bell effect by calling bell() with |
||||
* the alert message. |
||||
*/ |
||||
void setBellMode(Enum::BellModeEnum mode); |
||||
|
||||
Q_SIGNALS: |
||||
void visualBell(); |
||||
|
||||
private: |
||||
Enum::BellModeEnum _bellMode; |
||||
bool _bellMasked = false; |
||||
}; |
||||
|
||||
} |
||||
Loading…
Reference in new issue