-
Notifications
You must be signed in to change notification settings - Fork 2
/
linuxcsd.cpp
48 lines (38 loc) · 1.59 KB
/
linuxcsd.cpp
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
#include "linuxcsd.h"
#include <QEvent>
#include <QWidget>
namespace CSD::Internal {
LinuxClientSideDecorationFilter::WidgetCallbacks::WidgetCallbacks(
Callback onActivationChanged, Callback onWindowStateChanged)
: onActivationChanged(std::move(onActivationChanged)),
onWindowStateChanged(std::move(onWindowStateChanged)) {}
LinuxClientSideDecorationFilter::LinuxClientSideDecorationFilter(
QObject *parent)
: QObject(parent) {}
LinuxClientSideDecorationFilter::~LinuxClientSideDecorationFilter() {
for (const auto &pair : this->m_callbacks) {
pair.first->removeEventFilter(this);
}
}
bool LinuxClientSideDecorationFilter::eventFilter(QObject *watched,
QEvent *event) {
QWidget *widget = static_cast<QWidget *>(watched);
auto resultIterator = this->m_callbacks.find(widget);
if (event->type() == QEvent::ActivationChange) {
resultIterator->second.onActivationChanged();
} else if (event->type() == QEvent::WindowStateChange) {
resultIterator->second.onWindowStateChanged();
}
return false;
}
void LinuxClientSideDecorationFilter::apply(QWidget *widget,
Callback onActivationChanged,
Callback onWindowStateChanged) {
this->m_callbacks.emplace(
widget,
WidgetCallbacks(std::move(onActivationChanged),
std::move(onWindowStateChanged)));
widget->installEventFilter(this);
widget->setWindowFlag(Qt::FramelessWindowHint);
}
} // namespace CSD::Internal