Skip to content

Commit e3b5339

Browse files
committed
Implement active window on Wayland
1 parent 8e2c726 commit e3b5339

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

dist/libtdesktopenvironment-blueprint.spec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name: libtdesktopenvironment-blueprint
22
Version: beta5
3-
Release: 1%{?dist}
3+
Release: 2%{?dist}
44
Summary: Common libraries for desktop integration for the- apps
55

66
License: GPLv3+

lib/Wm/wayland/waylandbackend.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ QList<DesktopWmWindowPtr> WaylandBackend::openWindows() {
129129

130130
DesktopWmWindowPtr WaylandBackend::activeWindow() {
131131
//TODO: Implement
132+
for (WaylandWindow* window : d->windows.values()) {
133+
if (window->isActive()) return window;
134+
}
132135
return nullptr;
133136
}
134137

lib/Wm/wayland/waylandwindow.cpp

+37-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ struct WaylandWindowPrivate {
3131

3232
QString title;
3333
ApplicationPointer application;
34+
35+
enum WindowState {
36+
NoState = 0,
37+
Activated = 1,
38+
Maximised = 2,
39+
Minimised = 4
40+
};
41+
typedef QFlags<WindowState> WindowStateFlags;
42+
43+
WindowStateFlags state = NoState;
3444
};
3545

3646
struct WaylandWindowEventListener {
@@ -57,6 +67,25 @@ struct WaylandWindowEventListener {
5767
emit this->parent->iconChanged();
5868
}
5969

70+
void stateChanged(wl_array* state) {
71+
WaylandWindowPrivate::WindowStateFlags windowState = WaylandWindowPrivate::NoState;
72+
for (quint32* flag = static_cast<quint32*>(state->data); reinterpret_cast<char*>(flag) < (static_cast<char*>(state->data) + state->size); flag++) {
73+
if (*flag == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED) {
74+
windowState |= WaylandWindowPrivate::Activated;
75+
}
76+
if (*flag == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MAXIMIZED) {
77+
windowState |= WaylandWindowPrivate::Maximised;
78+
}
79+
if (*flag == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MINIMIZED) {
80+
windowState |= WaylandWindowPrivate::Minimised;
81+
}
82+
}
83+
84+
this->parent->d->state = windowState;
85+
emit this->parent->windowStateChanged();
86+
emit this->parent->d->backend->activeWindowChanged();
87+
}
88+
6089
void closed() {
6190
this->parent->d->backend->signalToplevelClosed(this->parent->d->handle);
6291
}
@@ -85,7 +114,8 @@ WaylandWindow::WaylandWindow(zwlr_foreign_toplevel_handle_v1* handle, WaylandBac
85114

86115
};
87116
listener->state = [](void* data, struct zwlr_foreign_toplevel_handle_v1 * zwlr_foreign_toplevel_handle_v1, struct wl_array * state) {
88-
117+
Q_UNUSED(zwlr_foreign_toplevel_handle_v1)
118+
static_cast<WaylandWindowEventListener*>(data)->stateChanged(state);
89119
};
90120
listener->done = [](void* data, struct zwlr_foreign_toplevel_handle_v1 * zwlr_foreign_toplevel_handle_v1) {
91121

@@ -106,6 +136,10 @@ WaylandWindow::~WaylandWindow() {
106136
delete d;
107137
}
108138

139+
bool WaylandWindow::isActive() {
140+
return d->state & WaylandWindowPrivate::Activated;
141+
}
142+
109143
QString WaylandWindow::title() {
110144
return d->title;
111145
}
@@ -120,11 +154,11 @@ QIcon WaylandWindow::icon() {
120154
}
121155

122156
bool WaylandWindow::isMinimized() {
123-
return false;
157+
return d->state & WaylandWindowPrivate::Minimised;
124158
}
125159

126160
bool WaylandWindow::isMaximised() {
127-
return false;
161+
return d->state & WaylandWindowPrivate::Maximised;
128162
}
129163

130164
bool WaylandWindow::isFullScreen() {

lib/Wm/wayland/waylandwindow.h

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class WaylandWindow : public DesktopWmWindow {
3333
explicit WaylandWindow(zwlr_foreign_toplevel_handle_v1* handle, WaylandBackend* backend);
3434
~WaylandWindow();
3535

36+
bool isActive();
37+
3638
signals:
3739

3840
private:

0 commit comments

Comments
 (0)