File indexing completed on 2024-06-09 05:31:00
0001 /* 0002 SPDX-FileCopyrightText: 2014 Eike Hein <hein@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "windowsystem.h" 0008 0009 #include <QQuickItem> 0010 0011 #include <KWindowSystem> 0012 #include <KX11Extras> 0013 0014 WindowSystem::WindowSystem(QObject *parent) 0015 : QObject(parent) 0016 { 0017 } 0018 0019 WindowSystem::~WindowSystem() 0020 { 0021 } 0022 0023 bool WindowSystem::eventFilter(QObject *watched, QEvent *event) 0024 { 0025 if (event->type() == QEvent::FocusIn) { 0026 removeEventFilter(watched); 0027 Q_EMIT focusIn(qobject_cast<QQuickWindow *>(watched)); 0028 } 0029 0030 return false; 0031 } 0032 0033 void WindowSystem::forceActive(QQuickItem *item) 0034 { 0035 if (!item || !item->window()) { 0036 return; 0037 } 0038 0039 KX11Extras::forceActiveWindow(item->window()->winId()); 0040 } 0041 0042 bool WindowSystem::isActive(QQuickItem *item) 0043 { 0044 if (!item || !item->window()) { 0045 return false; 0046 } 0047 0048 return item->window()->isActive(); 0049 } 0050 0051 void WindowSystem::monitorWindowFocus(QQuickItem *item) 0052 { 0053 if (!item || !item->window()) { 0054 return; 0055 } 0056 0057 item->window()->installEventFilter(this); 0058 } 0059 0060 void WindowSystem::monitorWindowVisibility(QQuickItem *item) 0061 { 0062 if (!item || !item->window()) { 0063 return; 0064 } 0065 0066 connect(item->window(), &QQuickWindow::visibilityChanged, this, &WindowSystem::monitoredWindowVisibilityChanged, Qt::UniqueConnection); 0067 } 0068 0069 void WindowSystem::monitoredWindowVisibilityChanged(QWindow::Visibility visibility) const 0070 { 0071 bool visible = (visibility != QWindow::Hidden); 0072 QQuickWindow *w = static_cast<QQuickWindow *>(QObject::sender()); 0073 0074 if (!visible) { 0075 Q_EMIT hidden(w); 0076 } 0077 }