Changeset View
Changeset View
Standalone View
Standalone View
src/server/plasmawindowmanagement_interface.cpp
Show All 17 Lines | |||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "plasmawindowmanagement_interface.h" | 20 | #include "plasmawindowmanagement_interface.h" | ||
21 | #include "global_p.h" | 21 | #include "global_p.h" | ||
22 | #include "resource_p.h" | 22 | #include "resource_p.h" | ||
23 | #include "display.h" | 23 | #include "display.h" | ||
24 | #include "surface_interface.h" | 24 | #include "surface_interface.h" | ||
25 | 25 | | |||
26 | #include <QtConcurrentRun> | ||||
27 | #include <QFile> | ||||
28 | #include <QIcon> | ||||
26 | #include <QList> | 29 | #include <QList> | ||
27 | #include <QVector> | 30 | #include <QVector> | ||
28 | #include <QRect> | 31 | #include <QRect> | ||
29 | #include <QHash> | 32 | #include <QHash> | ||
30 | 33 | | |||
31 | #include <wayland-server.h> | 34 | #include <wayland-server.h> | ||
32 | #include <wayland-plasma-window-management-server-protocol.h> | 35 | #include <wayland-plasma-window-management-server-protocol.h> | ||
33 | 36 | | |||
Show All 31 Lines | |||||
65 | public: | 68 | public: | ||
66 | Private(PlasmaWindowManagementInterface *wm, PlasmaWindowInterface *q); | 69 | Private(PlasmaWindowManagementInterface *wm, PlasmaWindowInterface *q); | ||
67 | ~Private(); | 70 | ~Private(); | ||
68 | 71 | | |||
69 | void createResource(wl_resource *parent, uint32_t id); | 72 | void createResource(wl_resource *parent, uint32_t id); | ||
70 | void setTitle(const QString &title); | 73 | void setTitle(const QString &title); | ||
71 | void setAppId(const QString &appId); | 74 | void setAppId(const QString &appId); | ||
72 | void setThemedIconName(const QString &iconName); | 75 | void setThemedIconName(const QString &iconName); | ||
76 | void setIcon(const QIcon &icon); | ||||
73 | void setVirtualDesktop(quint32 desktop); | 77 | void setVirtualDesktop(quint32 desktop); | ||
74 | void unmap(); | 78 | void unmap(); | ||
75 | void setState(org_kde_plasma_window_management_state flag, bool set); | 79 | void setState(org_kde_plasma_window_management_state flag, bool set); | ||
76 | void setParentWindow(PlasmaWindowInterface *parent); | 80 | void setParentWindow(PlasmaWindowInterface *parent); | ||
77 | void setGeometry(const QRect &geometry); | 81 | void setGeometry(const QRect &geometry); | ||
78 | wl_resource *resourceForParent(PlasmaWindowInterface *parent, wl_resource *child) const; | 82 | wl_resource *resourceForParent(PlasmaWindowInterface *parent, wl_resource *child) const; | ||
79 | 83 | | |||
80 | QVector<wl_resource*> resources; | 84 | QVector<wl_resource*> resources; | ||
Show All 11 Lines | 94 | private: | |||
92 | static void setStateCallback(wl_client *client, wl_resource *resource, uint32_t flags, uint32_t state); | 96 | static void setStateCallback(wl_client *client, wl_resource *resource, uint32_t flags, uint32_t state); | ||
93 | static void setVirtualDesktopCallback(wl_client *client, wl_resource *resource, uint32_t number); | 97 | static void setVirtualDesktopCallback(wl_client *client, wl_resource *resource, uint32_t number); | ||
94 | static void closeCallback(wl_client *client, wl_resource *resource); | 98 | static void closeCallback(wl_client *client, wl_resource *resource); | ||
95 | static void requestMoveCallback(wl_client *client, wl_resource *resource); | 99 | static void requestMoveCallback(wl_client *client, wl_resource *resource); | ||
96 | static void requestResizeCallback(wl_client *client, wl_resource *resource); | 100 | static void requestResizeCallback(wl_client *client, wl_resource *resource); | ||
97 | static void setMinimizedGeometryCallback(wl_client *client, wl_resource *resource, wl_resource *panel, uint32_t x, uint32_t y, uint32_t width, uint32_t height); | 101 | static void setMinimizedGeometryCallback(wl_client *client, wl_resource *resource, wl_resource *panel, uint32_t x, uint32_t y, uint32_t width, uint32_t height); | ||
98 | static void unsetMinimizedGeometryCallback(wl_client *client, wl_resource *resource, wl_resource *panel); | 102 | static void unsetMinimizedGeometryCallback(wl_client *client, wl_resource *resource, wl_resource *panel); | ||
99 | static void destroyCallback(wl_client *client, wl_resource *resource); | 103 | static void destroyCallback(wl_client *client, wl_resource *resource); | ||
104 | static void getIconCallback(wl_client *client, wl_resource *resource, int32_t fd); | ||||
100 | static Private *cast(wl_resource *resource) { | 105 | static Private *cast(wl_resource *resource) { | ||
101 | return reinterpret_cast<Private*>(wl_resource_get_user_data(resource)); | 106 | return reinterpret_cast<Private*>(wl_resource_get_user_data(resource)); | ||
102 | } | 107 | } | ||
103 | 108 | | |||
104 | PlasmaWindowInterface *q; | 109 | PlasmaWindowInterface *q; | ||
105 | QString m_title; | 110 | QString m_title; | ||
106 | QString m_appId; | 111 | QString m_appId; | ||
107 | QString m_themedIconName; | 112 | QString m_themedIconName; | ||
113 | QIcon m_icon; | ||||
108 | quint32 m_virtualDesktop = 0; | 114 | quint32 m_virtualDesktop = 0; | ||
109 | quint32 m_state = 0; | 115 | quint32 m_state = 0; | ||
110 | wl_listener listener; | 116 | wl_listener listener; | ||
111 | static const struct org_kde_plasma_window_interface s_interface; | 117 | static const struct org_kde_plasma_window_interface s_interface; | ||
112 | }; | 118 | }; | ||
113 | 119 | | |||
114 | const quint32 PlasmaWindowManagementInterface::Private::s_version = 6; | 120 | const quint32 PlasmaWindowManagementInterface::Private::s_version = 7; | ||
115 | 121 | | |||
116 | PlasmaWindowManagementInterface::Private::Private(PlasmaWindowManagementInterface *q, Display *d) | 122 | PlasmaWindowManagementInterface::Private::Private(PlasmaWindowManagementInterface *q, Display *d) | ||
117 | : Global::Private(d, &org_kde_plasma_window_management_interface, s_version) | 123 | : Global::Private(d, &org_kde_plasma_window_management_interface, s_version) | ||
118 | , q(q) | 124 | , q(q) | ||
119 | { | 125 | { | ||
120 | } | 126 | } | ||
121 | 127 | | |||
122 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | 128 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | ||
▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Line(s) | |||||
262 | const struct org_kde_plasma_window_interface PlasmaWindowInterface::Private::s_interface = { | 268 | const struct org_kde_plasma_window_interface PlasmaWindowInterface::Private::s_interface = { | ||
263 | setStateCallback, | 269 | setStateCallback, | ||
264 | setVirtualDesktopCallback, | 270 | setVirtualDesktopCallback, | ||
265 | setMinimizedGeometryCallback, | 271 | setMinimizedGeometryCallback, | ||
266 | unsetMinimizedGeometryCallback, | 272 | unsetMinimizedGeometryCallback, | ||
267 | closeCallback, | 273 | closeCallback, | ||
268 | requestMoveCallback, | 274 | requestMoveCallback, | ||
269 | requestResizeCallback, | 275 | requestResizeCallback, | ||
270 | destroyCallback | 276 | destroyCallback, | ||
277 | getIconCallback | ||||
271 | }; | 278 | }; | ||
272 | #endif | 279 | #endif | ||
273 | 280 | | |||
274 | PlasmaWindowInterface::Private::Private(PlasmaWindowManagementInterface *wm, PlasmaWindowInterface *q) | 281 | PlasmaWindowInterface::Private::Private(PlasmaWindowManagementInterface *wm, PlasmaWindowInterface *q) | ||
275 | : wm(wm) | 282 | : wm(wm) | ||
276 | , q(q) | 283 | , q(q) | ||
277 | { | 284 | { | ||
278 | } | 285 | } | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 319 | { | |||
321 | org_kde_plasma_window_send_virtual_desktop_changed(resource, m_virtualDesktop); | 328 | org_kde_plasma_window_send_virtual_desktop_changed(resource, m_virtualDesktop); | ||
322 | if (!m_appId.isEmpty()) { | 329 | if (!m_appId.isEmpty()) { | ||
323 | org_kde_plasma_window_send_app_id_changed(resource, m_appId.toUtf8().constData()); | 330 | org_kde_plasma_window_send_app_id_changed(resource, m_appId.toUtf8().constData()); | ||
324 | } | 331 | } | ||
325 | if (!m_title.isEmpty()) { | 332 | if (!m_title.isEmpty()) { | ||
326 | org_kde_plasma_window_send_title_changed(resource, m_title.toUtf8().constData()); | 333 | org_kde_plasma_window_send_title_changed(resource, m_title.toUtf8().constData()); | ||
327 | } | 334 | } | ||
328 | org_kde_plasma_window_send_state_changed(resource, m_state); | 335 | org_kde_plasma_window_send_state_changed(resource, m_state); | ||
336 | if (!m_themedIconName.isEmpty()) { | ||||
329 | org_kde_plasma_window_send_themed_icon_name_changed(resource, m_themedIconName.toUtf8().constData()); | 337 | org_kde_plasma_window_send_themed_icon_name_changed(resource, m_themedIconName.toUtf8().constData()); | ||
338 | } else { | ||||
339 | if (wl_resource_get_version(resource) >= ORG_KDE_PLASMA_WINDOW_ICON_CHANGED_SINCE_VERSION) { | ||||
340 | org_kde_plasma_window_send_icon_changed(resource); | ||||
341 | } | ||||
342 | } | ||||
330 | 343 | | |||
331 | org_kde_plasma_window_send_parent_window(resource, resourceForParent(parentWindow, resource)); | 344 | org_kde_plasma_window_send_parent_window(resource, resourceForParent(parentWindow, resource)); | ||
332 | 345 | | |||
333 | if (unmapped) { | 346 | if (unmapped) { | ||
334 | org_kde_plasma_window_send_unmapped(resource); | 347 | org_kde_plasma_window_send_unmapped(resource); | ||
335 | } | 348 | } | ||
336 | 349 | | |||
337 | if (geometry.isValid() && wl_resource_get_version(resource) >= ORG_KDE_PLASMA_WINDOW_GEOMETRY_SINCE_VERSION) { | 350 | if (geometry.isValid() && wl_resource_get_version(resource) >= ORG_KDE_PLASMA_WINDOW_GEOMETRY_SINCE_VERSION) { | ||
Show All 25 Lines | 373 | { | |||
363 | } | 376 | } | ||
364 | m_themedIconName = iconName; | 377 | m_themedIconName = iconName; | ||
365 | const QByteArray utf8 = m_themedIconName.toUtf8(); | 378 | const QByteArray utf8 = m_themedIconName.toUtf8(); | ||
366 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | 379 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | ||
367 | org_kde_plasma_window_send_themed_icon_name_changed(*it, utf8.constData()); | 380 | org_kde_plasma_window_send_themed_icon_name_changed(*it, utf8.constData()); | ||
368 | } | 381 | } | ||
369 | } | 382 | } | ||
370 | 383 | | |||
384 | void PlasmaWindowInterface::Private::setIcon(const QIcon &icon) | ||||
385 | { | ||||
386 | m_icon = icon; | ||||
apol: maybe worth adding a `if (m_icon == icon) return;` | |||||
in theory yes, in practice: operator== doesn't exist for QIcon so all you get is a compile error :-( graesslin: in theory yes, in practice: operator== doesn't exist for QIcon so all you get is a compile… | |||||
romangg: What about comparing QIcon::cacheKey() values? | |||||
387 | setThemedIconName(m_icon.name()); | ||||
388 | if (m_icon.name().isEmpty()) { | ||||
389 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | ||||
390 | if (wl_resource_get_version(*it) >= ORG_KDE_PLASMA_WINDOW_ICON_CHANGED_SINCE_VERSION) { | ||||
391 | org_kde_plasma_window_send_icon_changed(*it); | ||||
392 | } | ||||
393 | } | ||||
394 | } | ||||
395 | } | ||||
396 | | ||||
397 | void PlasmaWindowInterface::Private::getIconCallback(wl_client *client, wl_resource *resource, int32_t fd) | ||||
398 | { | ||||
399 | Q_UNUSED(client) | ||||
400 | Private *p = cast(resource); | ||||
401 | QtConcurrent::run( | ||||
402 | [fd] (const QIcon &icon) { | ||||
403 | QFile file; | ||||
404 | file.open(fd, QIODevice::WriteOnly, QFileDevice::AutoCloseHandle); | ||||
405 | QDataStream ds(&file); | ||||
406 | ds << icon; | ||||
Is there anything protecting this from being unsynchronised parallel access to m_icon (and p)? Simplest solution might be passing the icon by value into the lambda. roberts: Is there anything protecting this from being unsynchronised parallel access to m_icon (and p)? | |||||
I assumed that reading from the icon is thread save. But you are right: better save than sorry. Especially accessing the p pointer could be dangerous as the PlasmaWindowInterface instance might get deleted. graesslin: I assumed that reading from the icon is thread save. But you are right: better save than sorry. | |||||
407 | file.close(); | ||||
408 | }, p->m_icon | ||||
409 | ); | ||||
410 | } | ||||
411 | | ||||
371 | void PlasmaWindowInterface::Private::setTitle(const QString &title) | 412 | void PlasmaWindowInterface::Private::setTitle(const QString &title) | ||
372 | { | 413 | { | ||
373 | if (m_title == title) { | 414 | if (m_title == title) { | ||
374 | return; | 415 | return; | ||
375 | } | 416 | } | ||
376 | m_title = title; | 417 | m_title = title; | ||
377 | const QByteArray utf8 = m_title.toUtf8(); | 418 | const QByteArray utf8 = m_title.toUtf8(); | ||
378 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | 419 | for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { | ||
▲ Show 20 Lines • Show All 315 Lines • ▼ Show 20 Line(s) | 734 | { | |||
694 | d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZABLE, set); | 735 | d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZABLE, set); | ||
695 | } | 736 | } | ||
696 | 737 | | |||
697 | void PlasmaWindowInterface::setSkipTaskbar(bool set) | 738 | void PlasmaWindowInterface::setSkipTaskbar(bool set) | ||
698 | { | 739 | { | ||
699 | d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPTASKBAR, set); | 740 | d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPTASKBAR, set); | ||
700 | } | 741 | } | ||
701 | 742 | | |||
743 | #ifndef KWAYLANDSERVER_NO_DEPRECATED | ||||
702 | void PlasmaWindowInterface::setThemedIconName(const QString &iconName) | 744 | void PlasmaWindowInterface::setThemedIconName(const QString &iconName) | ||
703 | { | 745 | { | ||
704 | d->setThemedIconName(iconName); | 746 | d->setThemedIconName(iconName); | ||
705 | } | 747 | } | ||
748 | #endif | ||||
749 | | ||||
750 | void PlasmaWindowInterface::setIcon(const QIcon &icon) | ||||
751 | { | ||||
752 | d->setIcon(icon); | ||||
753 | } | ||||
706 | 754 | | |||
707 | void PlasmaWindowInterface::setShadeable(bool set) | 755 | void PlasmaWindowInterface::setShadeable(bool set) | ||
708 | { | 756 | { | ||
709 | d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADEABLE, set); | 757 | d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADEABLE, set); | ||
710 | } | 758 | } | ||
711 | 759 | | |||
712 | void PlasmaWindowInterface::setShaded(bool set) | 760 | void PlasmaWindowInterface::setShaded(bool set) | ||
713 | { | 761 | { | ||
Show All 30 Lines |
maybe worth adding a if (m_icon == icon) return;