File indexing completed on 2024-11-10 04:57:52
0001 /* 0002 SPDX-FileCopyrightText: 2016 Martin Graesslin <mgraesslin@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 0006 */ 0007 #include "osd.h" 0008 #include "main.h" 0009 #include "onscreennotification.h" 0010 #include "scripting/scripting.h" 0011 #include "workspace.h" 0012 0013 #include <QQmlEngine> 0014 #include <QThread> 0015 0016 namespace KWin 0017 { 0018 namespace OSD 0019 { 0020 0021 static OnScreenNotification *create() 0022 { 0023 auto osd = new OnScreenNotification(workspace()); 0024 osd->setConfig(kwinApp()->config()); 0025 osd->setEngine(Scripting::self()->qmlEngine()); 0026 return osd; 0027 } 0028 0029 static OnScreenNotification *osd() 0030 { 0031 static OnScreenNotification *s_osd = create(); 0032 return s_osd; 0033 } 0034 0035 void show(const QString &message, const QString &iconName, int timeout) 0036 { 0037 if (!kwinApp()->shouldUseWaylandForCompositing()) { 0038 // FIXME: only supported on Wayland 0039 return; 0040 } 0041 0042 if (QThread::currentThread() != qGuiApp->thread()) { 0043 QTimer::singleShot(0, QCoreApplication::instance(), [message, iconName, timeout] { 0044 show(message, iconName, timeout); 0045 }); 0046 return; 0047 } 0048 0049 auto notification = osd(); 0050 notification->setIconName(iconName); 0051 notification->setMessage(message); 0052 notification->setTimeout(timeout); 0053 notification->setVisible(true); 0054 } 0055 0056 void show(const QString &message, int timeout) 0057 { 0058 show(message, QString(), timeout); 0059 } 0060 0061 void show(const QString &message, const QString &iconName) 0062 { 0063 show(message, iconName, 0); 0064 } 0065 0066 void hide(HideFlags flags) 0067 { 0068 if (!kwinApp()->shouldUseWaylandForCompositing()) { 0069 // FIXME: only supported on Wayland 0070 return; 0071 } 0072 osd()->setSkipCloseAnimation(flags.testFlag(HideFlag::SkipCloseAnimation)); 0073 osd()->setVisible(false); 0074 } 0075 0076 } 0077 }