Changeset View
Changeset View
Standalone View
Standalone View
wayland_server.cpp
Show All 17 Lines | |||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "wayland_server.h" | 20 | #include "wayland_server.h" | ||
21 | #include "client.h" | 21 | #include "client.h" | ||
22 | #include "platform.h" | 22 | #include "platform.h" | ||
23 | #include "composite.h" | 23 | #include "composite.h" | ||
24 | #include "idle_inhibition.h" | 24 | #include "idle_inhibition.h" | ||
25 | #include "screens.h" | 25 | #include "screens.h" | ||
26 | #include "shell_client.h" | 26 | #include "xdgshellclient.h" | ||
27 | #include "workspace.h" | 27 | #include "workspace.h" | ||
28 | 28 | | |||
29 | // Client | 29 | // Client | ||
30 | #include <KWayland/Client/connection_thread.h> | 30 | #include <KWayland/Client/connection_thread.h> | ||
31 | #include <KWayland/Client/event_queue.h> | 31 | #include <KWayland/Client/event_queue.h> | ||
32 | #include <KWayland/Client/registry.h> | 32 | #include <KWayland/Client/registry.h> | ||
33 | #include <KWayland/Client/compositor.h> | 33 | #include <KWayland/Client/compositor.h> | ||
34 | #include <KWayland/Client/seat.h> | 34 | #include <KWayland/Client/seat.h> | ||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | 148 | { | |||
152 | } | 152 | } | ||
153 | if (surface->client() == m_xwayland.client) { | 153 | if (surface->client() == m_xwayland.client) { | ||
154 | // skip Xwayland clients, those are created using standard X11 way | 154 | // skip Xwayland clients, those are created using standard X11 way | ||
155 | return; | 155 | return; | ||
156 | } | 156 | } | ||
157 | if (surface->client() == m_screenLockerClientConnection) { | 157 | if (surface->client() == m_screenLockerClientConnection) { | ||
158 | ScreenLocker::KSldApp::self()->lockScreenShown(); | 158 | ScreenLocker::KSldApp::self()->lockScreenShown(); | ||
159 | } | 159 | } | ||
160 | ShellClient *client = new ShellClient(surface); | 160 | XdgShellClient *client = new XdgShellClient(surface); | ||
161 | if (ServerSideDecorationInterface *deco = ServerSideDecorationInterface::get(surface->surface())) { | 161 | if (ServerSideDecorationInterface *deco = ServerSideDecorationInterface::get(surface->surface())) { | ||
162 | client->installServerSideDecoration(deco); | 162 | client->installServerSideDecoration(deco); | ||
163 | } | 163 | } | ||
164 | auto it = std::find_if(m_plasmaShellSurfaces.begin(), m_plasmaShellSurfaces.end(), | 164 | auto it = std::find_if(m_plasmaShellSurfaces.begin(), m_plasmaShellSurfaces.end(), | ||
165 | [client] (PlasmaShellSurfaceInterface *surface) { | 165 | [client] (PlasmaShellSurfaceInterface *surface) { | ||
166 | return client->surface() == surface->surface(); | 166 | return client->surface() == surface->surface(); | ||
167 | } | 167 | } | ||
168 | ); | 168 | ); | ||
169 | if (it != m_plasmaShellSurfaces.end()) { | 169 | if (it != m_plasmaShellSurfaces.end()) { | ||
170 | client->installPlasmaShellSurface(*it); | 170 | client->installPlasmaShellSurface(*it); | ||
171 | m_plasmaShellSurfaces.erase(it); | 171 | m_plasmaShellSurfaces.erase(it); | ||
172 | } | 172 | } | ||
173 | if (auto menu = m_appMenuManager->appMenuForSurface(surface->surface())) { | 173 | if (auto menu = m_appMenuManager->appMenuForSurface(surface->surface())) { | ||
174 | client->installAppMenu(menu); | 174 | client->installAppMenu(menu); | ||
175 | } | 175 | } | ||
176 | if (auto palette = m_paletteManager->paletteForSurface(surface->surface())) { | 176 | if (auto palette = m_paletteManager->paletteForSurface(surface->surface())) { | ||
177 | client->installPalette(palette); | 177 | client->installPalette(palette); | ||
178 | } | 178 | } | ||
179 | m_clients << client; | 179 | m_clients << client; | ||
180 | if (client->readyForPainting()) { | 180 | if (client->readyForPainting()) { | ||
181 | emit shellClientAdded(client); | 181 | emit shellClientAdded(client); | ||
182 | } else { | 182 | } else { | ||
183 | connect(client, &ShellClient::windowShown, this, &WaylandServer::shellClientShown); | 183 | connect(client, &XdgShellClient::windowShown, this, &WaylandServer::shellClientShown); | ||
184 | } | 184 | } | ||
185 | 185 | | |||
186 | //not directly connected as the connection is tied to client instead of this | 186 | //not directly connected as the connection is tied to client instead of this | ||
187 | connect(m_XdgForeign, &KWayland::Server::XdgForeignInterface::transientChanged, client, [this](KWayland::Server::SurfaceInterface *child) { | 187 | connect(m_XdgForeign, &KWayland::Server::XdgForeignInterface::transientChanged, client, [this](KWayland::Server::SurfaceInterface *child) { | ||
188 | emit foreignTransientChanged(child); | 188 | emit foreignTransientChanged(child); | ||
189 | }); | 189 | }); | ||
190 | } | 190 | } | ||
191 | 191 | | |||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 280 | { | |||
320 | m_xdgShell = m_display->createXdgShell(XdgShellInterfaceVersion::Stable, m_display); | 320 | m_xdgShell = m_display->createXdgShell(XdgShellInterfaceVersion::Stable, m_display); | ||
321 | m_xdgShell->create(); | 321 | m_xdgShell->create(); | ||
322 | connect(m_xdgShell, &XdgShellInterface::surfaceCreated, this, &WaylandServer::createSurface<XdgShellSurfaceInterface>); | 322 | connect(m_xdgShell, &XdgShellInterface::surfaceCreated, this, &WaylandServer::createSurface<XdgShellSurfaceInterface>); | ||
323 | connect(m_xdgShell, &XdgShellInterface::xdgPopupCreated, this, &WaylandServer::createSurface<XdgShellPopupInterface>); | 323 | connect(m_xdgShell, &XdgShellInterface::xdgPopupCreated, this, &WaylandServer::createSurface<XdgShellPopupInterface>); | ||
324 | 324 | | |||
325 | m_xdgDecorationManager = m_display->createXdgDecorationManager(m_xdgShell, m_display); | 325 | m_xdgDecorationManager = m_display->createXdgDecorationManager(m_xdgShell, m_display); | ||
326 | m_xdgDecorationManager->create(); | 326 | m_xdgDecorationManager->create(); | ||
327 | connect(m_xdgDecorationManager, &XdgDecorationManagerInterface::xdgDecorationInterfaceCreated, this, [this] (XdgDecorationInterface *deco) { | 327 | connect(m_xdgDecorationManager, &XdgDecorationManagerInterface::xdgDecorationInterfaceCreated, this, [this] (XdgDecorationInterface *deco) { | ||
328 | if (ShellClient *client = findClient(deco->surface()->surface())) { | 328 | if (XdgShellClient *client = findClient(deco->surface()->surface())) { | ||
329 | client->installXdgDecoration(deco); | 329 | client->installXdgDecoration(deco); | ||
330 | } | 330 | } | ||
331 | }); | 331 | }); | ||
332 | 332 | | |||
333 | m_display->createShm(); | 333 | m_display->createShm(); | ||
334 | m_seat = m_display->createSeat(m_display); | 334 | m_seat = m_display->createSeat(m_display); | ||
335 | m_seat->create(); | 335 | m_seat->create(); | ||
336 | m_display->createPointerGestures(PointerGesturesInterfaceVersion::UnstableV1, m_display)->create(); | 336 | m_display->createPointerGestures(PointerGesturesInterfaceVersion::UnstableV1, m_display)->create(); | ||
337 | m_display->createPointerConstraints(PointerConstraintsInterfaceVersion::UnstableV1, m_display)->create(); | 337 | m_display->createPointerConstraints(PointerConstraintsInterfaceVersion::UnstableV1, m_display)->create(); | ||
338 | m_dataDeviceManager = m_display->createDataDeviceManager(m_display); | 338 | m_dataDeviceManager = m_display->createDataDeviceManager(m_display); | ||
339 | m_dataDeviceManager->create(); | 339 | m_dataDeviceManager->create(); | ||
340 | m_idle = m_display->createIdle(m_display); | 340 | m_idle = m_display->createIdle(m_display); | ||
341 | m_idle->create(); | 341 | m_idle->create(); | ||
342 | auto idleInhibition = new IdleInhibition(m_idle); | 342 | auto idleInhibition = new IdleInhibition(m_idle); | ||
343 | connect(this, &WaylandServer::shellClientAdded, idleInhibition, &IdleInhibition::registerShellClient); | 343 | connect(this, &WaylandServer::shellClientAdded, idleInhibition, &IdleInhibition::registerXdgShellClient); | ||
344 | m_display->createIdleInhibitManager(IdleInhibitManagerInterfaceVersion::UnstableV1, m_display)->create(); | 344 | m_display->createIdleInhibitManager(IdleInhibitManagerInterfaceVersion::UnstableV1, m_display)->create(); | ||
345 | m_plasmaShell = m_display->createPlasmaShell(m_display); | 345 | m_plasmaShell = m_display->createPlasmaShell(m_display); | ||
346 | m_plasmaShell->create(); | 346 | m_plasmaShell->create(); | ||
347 | connect(m_plasmaShell, &PlasmaShellInterface::surfaceCreated, | 347 | connect(m_plasmaShell, &PlasmaShellInterface::surfaceCreated, | ||
348 | [this] (PlasmaShellSurfaceInterface *surface) { | 348 | [this] (PlasmaShellSurfaceInterface *surface) { | ||
349 | if (ShellClient *client = findClient(surface->surface())) { | 349 | if (XdgShellClient *client = findClient(surface->surface())) { | ||
350 | client->installPlasmaShellSurface(surface); | 350 | client->installPlasmaShellSurface(surface); | ||
351 | } else { | 351 | } else { | ||
352 | m_plasmaShellSurfaces << surface; | 352 | m_plasmaShellSurfaces << surface; | ||
353 | connect(surface, &QObject::destroyed, this, | 353 | connect(surface, &QObject::destroyed, this, | ||
354 | [this, surface] { | 354 | [this, surface] { | ||
355 | m_plasmaShellSurfaces.removeOne(surface); | 355 | m_plasmaShellSurfaces.removeOne(surface); | ||
356 | } | 356 | } | ||
357 | ); | 357 | ); | ||
358 | } | 358 | } | ||
359 | } | 359 | } | ||
360 | ); | 360 | ); | ||
361 | m_appMenuManager = m_display->createAppMenuManagerInterface(m_display); | 361 | m_appMenuManager = m_display->createAppMenuManagerInterface(m_display); | ||
362 | m_appMenuManager->create(); | 362 | m_appMenuManager->create(); | ||
363 | connect(m_appMenuManager, &AppMenuManagerInterface::appMenuCreated, | 363 | connect(m_appMenuManager, &AppMenuManagerInterface::appMenuCreated, | ||
364 | [this] (AppMenuInterface *appMenu) { | 364 | [this] (AppMenuInterface *appMenu) { | ||
365 | if (ShellClient *client = findClient(appMenu->surface())) { | 365 | if (XdgShellClient *client = findClient(appMenu->surface())) { | ||
366 | client->installAppMenu(appMenu); | 366 | client->installAppMenu(appMenu); | ||
367 | } | 367 | } | ||
368 | } | 368 | } | ||
369 | ); | 369 | ); | ||
370 | m_paletteManager = m_display->createServerSideDecorationPaletteManager(m_display); | 370 | m_paletteManager = m_display->createServerSideDecorationPaletteManager(m_display); | ||
371 | m_paletteManager->create(); | 371 | m_paletteManager->create(); | ||
372 | connect(m_paletteManager, &ServerSideDecorationPaletteManagerInterface::paletteCreated, | 372 | connect(m_paletteManager, &ServerSideDecorationPaletteManagerInterface::paletteCreated, | ||
373 | [this] (ServerSideDecorationPaletteInterface *palette) { | 373 | [this] (ServerSideDecorationPaletteInterface *palette) { | ||
374 | if (ShellClient *client = findClient(palette->surface())) { | 374 | if (XdgShellClient *client = findClient(palette->surface())) { | ||
375 | client->installPalette(palette); | 375 | client->installPalette(palette); | ||
376 | } | 376 | } | ||
377 | } | 377 | } | ||
378 | ); | 378 | ); | ||
379 | 379 | | |||
380 | m_windowManagement = m_display->createPlasmaWindowManagement(m_display); | 380 | m_windowManagement = m_display->createPlasmaWindowManagement(m_display); | ||
381 | m_windowManagement->create(); | 381 | m_windowManagement->create(); | ||
382 | m_windowManagement->setShowingDesktopState(PlasmaWindowManagementInterface::ShowingDesktopState::Disabled); | 382 | m_windowManagement->setShowingDesktopState(PlasmaWindowManagementInterface::ShowingDesktopState::Disabled); | ||
Show All 29 Lines | |||||
412 | auto shadowManager = m_display->createShadowManager(m_display); | 412 | auto shadowManager = m_display->createShadowManager(m_display); | ||
413 | shadowManager->create(); | 413 | shadowManager->create(); | ||
414 | 414 | | |||
415 | m_display->createDpmsManager(m_display)->create(); | 415 | m_display->createDpmsManager(m_display)->create(); | ||
416 | 416 | | |||
417 | m_decorationManager = m_display->createServerSideDecorationManager(m_display); | 417 | m_decorationManager = m_display->createServerSideDecorationManager(m_display); | ||
418 | connect(m_decorationManager, &ServerSideDecorationManagerInterface::decorationCreated, this, | 418 | connect(m_decorationManager, &ServerSideDecorationManagerInterface::decorationCreated, this, | ||
419 | [this] (ServerSideDecorationInterface *deco) { | 419 | [this] (ServerSideDecorationInterface *deco) { | ||
420 | if (ShellClient *c = findClient(deco->surface())) { | 420 | if (XdgShellClient *c = findClient(deco->surface())) { | ||
421 | c->installServerSideDecoration(deco); | 421 | c->installServerSideDecoration(deco); | ||
422 | } | 422 | } | ||
423 | connect(deco, &ServerSideDecorationInterface::modeRequested, this, | 423 | connect(deco, &ServerSideDecorationInterface::modeRequested, this, | ||
424 | [this, deco] (ServerSideDecorationManagerInterface::Mode mode) { | 424 | [this, deco] (ServerSideDecorationManagerInterface::Mode mode) { | ||
425 | // always acknowledge the requested mode | 425 | // always acknowledge the requested mode | ||
426 | deco->setMode(mode); | 426 | deco->setMode(mode); | ||
427 | } | 427 | } | ||
428 | ); | 428 | ); | ||
Show All 24 Lines | |||||
453 | 453 | | |||
454 | SurfaceInterface *WaylandServer::findForeignTransientForSurface(SurfaceInterface *surface) | 454 | SurfaceInterface *WaylandServer::findForeignTransientForSurface(SurfaceInterface *surface) | ||
455 | { | 455 | { | ||
456 | return m_XdgForeign->transientFor(surface); | 456 | return m_XdgForeign->transientFor(surface); | ||
457 | } | 457 | } | ||
458 | 458 | | |||
459 | void WaylandServer::shellClientShown(Toplevel *t) | 459 | void WaylandServer::shellClientShown(Toplevel *t) | ||
460 | { | 460 | { | ||
461 | ShellClient *c = dynamic_cast<ShellClient*>(t); | 461 | XdgShellClient *c = dynamic_cast<XdgShellClient *>(t); | ||
462 | if (!c) { | 462 | if (!c) { | ||
463 | qCWarning(KWIN_CORE) << "Failed to cast a Toplevel which is supposed to be a ShellClient to ShellClient"; | 463 | qCWarning(KWIN_CORE) << "Failed to cast a Toplevel which is supposed to be a XdgShellClient to XdgShellClient"; | ||
464 | return; | 464 | return; | ||
465 | } | 465 | } | ||
466 | disconnect(c, &ShellClient::windowShown, this, &WaylandServer::shellClientShown); | 466 | disconnect(c, &XdgShellClient::windowShown, this, &WaylandServer::shellClientShown); | ||
467 | emit shellClientAdded(c); | 467 | emit shellClientAdded(c); | ||
468 | } | 468 | } | ||
469 | 469 | | |||
470 | void WaylandServer::initWorkspace() | 470 | void WaylandServer::initWorkspace() | ||
471 | { | 471 | { | ||
472 | VirtualDesktopManager::self()->setVirtualDesktopManagement(m_virtualDesktopManagement); | 472 | VirtualDesktopManager::self()->setVirtualDesktopManagement(m_virtualDesktopManagement); | ||
473 | 473 | | |||
474 | if (m_windowManagement) { | 474 | if (m_windowManagement) { | ||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Line(s) | 606 | connect(registry, &Registry::interfacesAnnounced, this, | |||
622 | } | 622 | } | ||
623 | ); | 623 | ); | ||
624 | registry->setup(); | 624 | registry->setup(); | ||
625 | } | 625 | } | ||
626 | ); | 626 | ); | ||
627 | m_internalConnection.client->initConnection(); | 627 | m_internalConnection.client->initConnection(); | ||
628 | } | 628 | } | ||
629 | 629 | | |||
630 | void WaylandServer::removeClient(ShellClient *c) | 630 | void WaylandServer::removeClient(XdgShellClient *c) | ||
631 | { | 631 | { | ||
632 | m_clients.removeAll(c); | 632 | m_clients.removeAll(c); | ||
633 | emit shellClientRemoved(c); | 633 | emit shellClientRemoved(c); | ||
634 | } | 634 | } | ||
635 | 635 | | |||
636 | void WaylandServer::dispatch() | 636 | void WaylandServer::dispatch() | ||
637 | { | 637 | { | ||
638 | if (!m_display) { | 638 | if (!m_display) { | ||
639 | return; | 639 | return; | ||
640 | } | 640 | } | ||
641 | if (m_internalConnection.server) { | 641 | if (m_internalConnection.server) { | ||
642 | m_internalConnection.server->flush(); | 642 | m_internalConnection.server->flush(); | ||
643 | } | 643 | } | ||
644 | m_display->dispatchEvents(0); | 644 | m_display->dispatchEvents(0); | ||
645 | } | 645 | } | ||
646 | 646 | | |||
647 | static ShellClient *findClientInList(const QList<ShellClient*> &clients, quint32 id) | 647 | static XdgShellClient *findClientInList(const QList<XdgShellClient *> &clients, quint32 id) | ||
648 | { | 648 | { | ||
649 | auto it = std::find_if(clients.begin(), clients.end(), | 649 | auto it = std::find_if(clients.begin(), clients.end(), | ||
650 | [id] (ShellClient *c) { | 650 | [id] (XdgShellClient *c) { | ||
651 | return c->windowId() == id; | 651 | return c->windowId() == id; | ||
652 | } | 652 | } | ||
653 | ); | 653 | ); | ||
654 | if (it == clients.end()) { | 654 | if (it == clients.end()) { | ||
655 | return nullptr; | 655 | return nullptr; | ||
656 | } | 656 | } | ||
657 | return *it; | 657 | return *it; | ||
658 | } | 658 | } | ||
659 | 659 | | |||
660 | static ShellClient *findClientInList(const QList<ShellClient*> &clients, KWayland::Server::SurfaceInterface *surface) | 660 | static XdgShellClient *findClientInList(const QList<XdgShellClient *> &clients, KWayland::Server::SurfaceInterface *surface) | ||
661 | { | 661 | { | ||
662 | auto it = std::find_if(clients.begin(), clients.end(), | 662 | auto it = std::find_if(clients.begin(), clients.end(), | ||
663 | [surface] (ShellClient *c) { | 663 | [surface] (XdgShellClient *c) { | ||
664 | return c->surface() == surface; | 664 | return c->surface() == surface; | ||
665 | } | 665 | } | ||
666 | ); | 666 | ); | ||
667 | if (it == clients.end()) { | 667 | if (it == clients.end()) { | ||
668 | return nullptr; | 668 | return nullptr; | ||
669 | } | 669 | } | ||
670 | return *it; | 670 | return *it; | ||
671 | } | 671 | } | ||
672 | 672 | | |||
673 | ShellClient *WaylandServer::findClient(quint32 id) const | 673 | XdgShellClient *WaylandServer::findClient(quint32 id) const | ||
674 | { | 674 | { | ||
675 | if (id == 0) { | 675 | if (id == 0) { | ||
676 | return nullptr; | 676 | return nullptr; | ||
677 | } | 677 | } | ||
678 | if (ShellClient *c = findClientInList(m_clients, id)) { | 678 | if (XdgShellClient *c = findClientInList(m_clients, id)) { | ||
679 | return c; | 679 | return c; | ||
680 | } | 680 | } | ||
681 | return nullptr; | 681 | return nullptr; | ||
682 | } | 682 | } | ||
683 | 683 | | |||
684 | ShellClient *WaylandServer::findClient(SurfaceInterface *surface) const | 684 | XdgShellClient *WaylandServer::findClient(SurfaceInterface *surface) const | ||
685 | { | 685 | { | ||
686 | if (!surface) { | 686 | if (!surface) { | ||
687 | return nullptr; | 687 | return nullptr; | ||
688 | } | 688 | } | ||
689 | if (ShellClient *c = findClientInList(m_clients, surface)) { | 689 | if (XdgShellClient *c = findClientInList(m_clients, surface)) { | ||
690 | return c; | 690 | return c; | ||
691 | } | 691 | } | ||
692 | return nullptr; | 692 | return nullptr; | ||
693 | } | 693 | } | ||
694 | 694 | | |||
695 | AbstractClient *WaylandServer::findAbstractClient(SurfaceInterface *surface) const | 695 | AbstractClient *WaylandServer::findAbstractClient(SurfaceInterface *surface) const | ||
696 | { | 696 | { | ||
697 | return findClient(surface); | 697 | return findClient(surface); | ||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |