-
Notifications
You must be signed in to change notification settings - Fork 11
/
dockapplet.h
168 lines (135 loc) · 3.38 KB
/
dockapplet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef DOCKAPPLET_H
#define DOCKAPPLET_H
#include <QtCore/QVector>
#include <QtCore/QMap>
#include <QtGui/QIcon>
#include <QtGui/QGraphicsItem>
#include "applet.h"
class QGraphicsPixmapItem;
class TextGraphicsItem;
class DockApplet;
class Client;
// Represents a single item in a dock.
// There isn't one to one relationship between window (client) and dock item, that's why
// it's separate entity. One dock item can represent pinned launcher and one or more opened
// windows of that application.
class DockItem: public QObject, public QGraphicsItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
DockItem(DockApplet* dockApplet);
~DockItem();
void updateContent();
void addClient(Client* client);
void removeClient(Client* client);
void setTargetPosition(const QPoint& targetPosition);
void setTargetSize(const QSize& targetSize);
void moveInstantly();
void startAnimation();
const QVector<Client*>& clients() const
{
return m_clients;
}
QRectF boundingRect() const;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
public slots:
void animate();
void close();
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
void mousePressEvent(QGraphicsSceneMouseEvent* event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
private:
void updateClientsIconGeometry();
bool isUrgent();
QTimer* m_animationTimer;
DockApplet* m_dockApplet;
TextGraphicsItem* m_textItem;
QGraphicsPixmapItem* m_iconItem;
QVector<Client*> m_clients;
QPoint m_position;
QPoint m_targetPosition;
QSize m_size;
QSize m_targetSize;
qreal m_highlightIntensity;
qreal m_urgencyHighlightIntensity;
bool m_dragging;
QPointF m_mouseDownPosition;
QPoint m_dragStartPosition;
};
// Used for tracking connected windows (X11 clients).
// Client may have it's DockItem, but not necessary (for example, special windows are not shown in dock).
class Client
{
public:
Client(DockApplet* dockApplet, unsigned long handle);
~Client();
unsigned long handle() const
{
return m_handle;
}
bool isVisible()
{
return m_visible;
}
const QString& name() const
{
return m_name;
}
const QIcon& icon() const
{
return m_icon;
}
bool isUrgent() const
{
return m_isUrgent;
}
void windowPropertyChanged(unsigned long atom);
private:
void updateVisibility();
void updateName();
void updateIcon();
void updateUrgency();
DockApplet* m_dockApplet;
unsigned long m_handle;
QString m_name;
QIcon m_icon;
bool m_isUrgent;
bool m_visible;
DockItem* m_dockItem;
};
class DockApplet: public Applet
{
Q_OBJECT
public:
DockApplet(PanelWindow* panelWindow);
~DockApplet();
bool init();
QSize desiredSize();
void registerDockItem(DockItem* dockItem);
void unregisterDockItem(DockItem* dockItem);
DockItem* dockItemForClient(Client* client);
void updateLayout();
unsigned long activeWindow() const
{
return m_activeWindow;
}
void draggingStarted();
void draggingStopped();
void moveItem(DockItem* dockItem, bool right);
protected:
void layoutChanged();
private slots:
void windowPropertyChanged(unsigned long window, unsigned long atom);
private:
void updateClientList();
void updateActiveWindow();
QMap<unsigned long, Client*> m_clients;
QVector<DockItem*> m_dockItems;
unsigned long m_activeWindow;
bool m_dragging;
};
#endif