File indexing completed on 2024-11-10 04:57:20
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "switcheritem.h" 0010 // KWin 0011 #include "compositor.h" 0012 #include "core/output.h" 0013 #include "tabboxhandler.h" 0014 #include "workspace.h" 0015 // Qt 0016 #include <QAbstractItemModel> 0017 0018 namespace KWin 0019 { 0020 namespace TabBox 0021 { 0022 0023 SwitcherItem::SwitcherItem(QObject *parent) 0024 : QObject(parent) 0025 , m_model(nullptr) 0026 , m_item(nullptr) 0027 , m_visible(false) 0028 , m_allDesktops(false) 0029 , m_currentIndex(0) 0030 { 0031 m_selectedIndexConnection = connect(tabBox, &TabBoxHandler::selectedIndexChanged, this, [this] { 0032 if (isVisible()) { 0033 setCurrentIndex(tabBox->currentIndex().row()); 0034 } 0035 }); 0036 connect(workspace(), &Workspace::outputsChanged, this, &SwitcherItem::screenGeometryChanged); 0037 connect(Compositor::self(), &Compositor::compositingToggled, this, &SwitcherItem::compositingChanged); 0038 } 0039 0040 SwitcherItem::~SwitcherItem() 0041 { 0042 disconnect(m_selectedIndexConnection); 0043 } 0044 0045 void SwitcherItem::setItem(QObject *item) 0046 { 0047 if (m_item == item) { 0048 return; 0049 } 0050 m_item = item; 0051 Q_EMIT itemChanged(); 0052 } 0053 0054 void SwitcherItem::setModel(QAbstractItemModel *model) 0055 { 0056 m_model = model; 0057 Q_EMIT modelChanged(); 0058 } 0059 0060 void SwitcherItem::setVisible(bool visible) 0061 { 0062 if (m_visible == visible) { 0063 return; 0064 } 0065 if (visible) { 0066 Q_EMIT screenGeometryChanged(); 0067 } 0068 m_visible = visible; 0069 Q_EMIT visibleChanged(); 0070 } 0071 0072 QRect SwitcherItem::screenGeometry() const 0073 { 0074 return workspace()->activeOutput()->geometry(); 0075 } 0076 0077 void SwitcherItem::setCurrentIndex(int index) 0078 { 0079 if (m_currentIndex == index) { 0080 return; 0081 } 0082 m_currentIndex = index; 0083 if (m_model) { 0084 tabBox->setCurrentIndex(m_model->index(index, 0)); 0085 } 0086 Q_EMIT currentIndexChanged(m_currentIndex); 0087 } 0088 0089 void SwitcherItem::setAllDesktops(bool all) 0090 { 0091 if (m_allDesktops == all) { 0092 return; 0093 } 0094 m_allDesktops = all; 0095 Q_EMIT allDesktopsChanged(); 0096 } 0097 0098 void SwitcherItem::setNoModifierGrab(bool set) 0099 { 0100 if (m_noModifierGrab == set) { 0101 return; 0102 } 0103 m_noModifierGrab = set; 0104 Q_EMIT noModifierGrabChanged(); 0105 } 0106 0107 bool SwitcherItem::automaticallyHide() const 0108 { 0109 return m_automaticallyHide; 0110 } 0111 0112 void SwitcherItem::setAutomaticallyHide(bool value) 0113 { 0114 if (m_automaticallyHide == value) { 0115 return; 0116 } 0117 m_automaticallyHide = value; 0118 Q_EMIT automaticallyHideChanged(); 0119 } 0120 0121 bool SwitcherItem::compositing() 0122 { 0123 return Compositor::compositing(); 0124 } 0125 0126 } 0127 } 0128 0129 #include "moc_switcheritem.cpp"