KWin
Loading...
Searching...
No Matches
switcheritem.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "switcheritem.h"
10// KWin
11#include "compositor.h"
12#include "core/output.h"
13#include "tabboxhandler.h"
14#include "workspace.h"
15// Qt
16#include <QAbstractItemModel>
17
18namespace KWin
19{
20namespace TabBox
21{
22
23SwitcherItem::SwitcherItem(QObject *parent)
24 : QObject(parent)
25 , m_model(nullptr)
26 , m_item(nullptr)
27 , m_visible(false)
28 , m_allDesktops(false)
29 , m_currentIndex(0)
30{
31 m_selectedIndexConnection = connect(tabBox, &TabBoxHandler::selectedIndexChanged, this, [this] {
32 if (isVisible()) {
33 setCurrentIndex(tabBox->currentIndex().row());
34 }
35 });
36 connect(workspace(), &Workspace::outputsChanged, this, &SwitcherItem::screenGeometryChanged);
37 connect(Compositor::self(), &Compositor::compositingToggled, this, &SwitcherItem::compositingChanged);
38}
39
40SwitcherItem::~SwitcherItem()
41{
42 disconnect(m_selectedIndexConnection);
43}
44
45void SwitcherItem::setItem(QObject *item)
46{
47 if (m_item == item) {
48 return;
49 }
50 m_item = item;
51 Q_EMIT itemChanged();
52}
53
54void SwitcherItem::setModel(QAbstractItemModel *model)
55{
56 m_model = model;
57 Q_EMIT modelChanged();
58}
59
60void SwitcherItem::setVisible(bool visible)
61{
62 if (m_visible == visible) {
63 return;
64 }
65 if (visible) {
66 Q_EMIT screenGeometryChanged();
67 }
68 m_visible = visible;
69 Q_EMIT visibleChanged();
70}
71
72QRect SwitcherItem::screenGeometry() const
73{
74 return workspace()->activeOutput()->geometry();
75}
76
77void SwitcherItem::setCurrentIndex(int index)
78{
79 if (m_currentIndex == index) {
80 return;
81 }
82 m_currentIndex = index;
83 if (m_model) {
84 tabBox->setCurrentIndex(m_model->index(index, 0));
85 }
86 Q_EMIT currentIndexChanged(m_currentIndex);
87}
88
89void SwitcherItem::setAllDesktops(bool all)
90{
91 if (m_allDesktops == all) {
92 return;
93 }
94 m_allDesktops = all;
95 Q_EMIT allDesktopsChanged();
96}
97
98void SwitcherItem::setNoModifierGrab(bool set)
99{
100 if (m_noModifierGrab == set) {
101 return;
102 }
103 m_noModifierGrab = set;
104 Q_EMIT noModifierGrabChanged();
105}
106
107bool SwitcherItem::automaticallyHide() const
108{
109 return m_automaticallyHide;
110}
111
112void SwitcherItem::setAutomaticallyHide(bool value)
113{
114 if (m_automaticallyHide == value) {
115 return;
116 }
117 m_automaticallyHide = value;
118 Q_EMIT automaticallyHideChanged();
119}
120
121bool SwitcherItem::compositing()
122{
123 return Compositor::compositing();
124}
125
126}
127}
128
129#include "moc_switcheritem.cpp"
QRect geometry
Definition output.h:134
SwitcherItem(QObject *parent=nullptr)
const QModelIndex & currentIndex() const
void setCurrentIndex(const QModelIndex &index)
Output * activeOutput() const
TabBoxHandler * tabBox
Workspace * workspace()
Definition workspace.h:830