From 1dd1e82cf0f6d9fd69de4f759802c9d588252a36 Mon Sep 17 00:00:00 2001 From: Mikhail Zolotukhin Date: Sat, 26 Mar 2022 20:42:02 +0300 Subject: [PATCH] chore: arrange cxx skeleton --- src/core/engine/CMakeLists.txt | 3 ++- src/core/engine/engine.cpp | 41 +++++++++++++++++++++++++++++++- src/core/engine/engine.hpp | 7 +++++- src/core/engine/surface.cpp | 9 +++++++ src/core/engine/surface.hpp | 11 +++++++++ src/core/engine/window.cpp | 20 ++++++++++++++++ src/core/engine/window.hpp | 22 +++++++++++++++++ src/core/engine/windows_list.cpp | 9 +++++-- src/core/engine/windows_list.hpp | 1 + src/core/plasma-api/client.cpp | 6 +++++ src/core/plasma-api/client.hpp | 2 ++ src/core/plasma-api/toplevel.cpp | 21 ++++++++++++++++ src/core/plasma-api/toplevel.hpp | 5 +++- src/core/qml-plugin.cpp | 2 +- src/kwinscript/engine/index.ts | 8 ------- 15 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 src/core/engine/surface.cpp create mode 100644 src/core/engine/surface.hpp diff --git a/src/core/engine/CMakeLists.txt b/src/core/engine/CMakeLists.txt index b694cd81..23247102 100644 --- a/src/core/engine/CMakeLists.txt +++ b/src/core/engine/CMakeLists.txt @@ -1,4 +1,5 @@ # SPDX-FileCopyrightText: 2022 Mikhail Zolotukhin # SPDX-License-Identifier: MIT -target_sources(bismuth_core PRIVATE engine.cpp windows_list.cpp window.cpp) +target_sources(bismuth_core PRIVATE engine.cpp windows_list.cpp window.cpp + surface.cpp) diff --git a/src/core/engine/engine.cpp b/src/core/engine/engine.cpp index b7fe9414..889eb3c2 100644 --- a/src/core/engine/engine.cpp +++ b/src/core/engine/engine.cpp @@ -2,10 +2,13 @@ // SPDX-License-Identifier: MIT #include "engine.hpp" +#include "engine/surface.hpp" +#include "plasma-api/api.hpp" namespace Bismuth { -Engine::Engine() +Engine::Engine(PlasmaApi::Api &api) + : m_plasmaApi(api) { } @@ -17,9 +20,45 @@ void Engine::addWindow(PlasmaApi::Client client) void Engine::removeWindow(PlasmaApi::Client client) { + m_windows.remove(client); } void Engine::arrange() { + auto screenSurfaces = [this]() -> std::vector { + auto result = std::vector(1); + + for (auto screen = 0; screen < m_plasmaApi.workspace().numScreens(); screen++) { + result.push_back(Surface()); + } + + return result; + }; + + for (auto &surface : screenSurfaces()) { + arrangeWindowsOnSurface(surface); + } } + +void Engine::arrangeWindowsOnSurface(const Surface &surface) +{ + auto layout = "Layout"; + auto workingArea = QRect(); + auto tilingArea = QRect(); + + auto visibleWindows = std::vector(); + + auto windowsThatCanBeTiled = std::vector(); + + // Maximize sole tile if enabled or apply the current layout as expected + // ... + // Or + // Apply layout to windows + + // If enabled, limit the windows' width + + // Commit window assigned properties + // visibleWindows.forEach((win : EngineWindow) = > win.commit()); +} + } diff --git a/src/core/engine/engine.hpp b/src/core/engine/engine.hpp index f095cab7..df738d53 100644 --- a/src/core/engine/engine.hpp +++ b/src/core/engine/engine.hpp @@ -3,6 +3,8 @@ #pragma once +#include "engine/surface.hpp" +#include "plasma-api/api.hpp" #include "plasma-api/client.hpp" #include "windows_list.hpp" @@ -11,7 +13,7 @@ namespace Bismuth class Engine { public: - Engine(); + Engine(PlasmaApi::Api &); void addWindow(PlasmaApi::Client); void removeWindow(PlasmaApi::Client); @@ -22,6 +24,9 @@ public: void arrange(); private: + void arrangeWindowsOnSurface(const Surface &); + WindowsList m_windows{}; + PlasmaApi::Api &m_plasmaApi; }; } diff --git a/src/core/engine/surface.cpp b/src/core/engine/surface.cpp new file mode 100644 index 00000000..90454793 --- /dev/null +++ b/src/core/engine/surface.cpp @@ -0,0 +1,9 @@ +// SPDX-FileCopyrightText: 2022 Mikhail Zolotukhin +// SPDX-License-Identifier: MIT + +#include "surface.hpp" + +namespace Bismuth +{ + +} diff --git a/src/core/engine/surface.hpp b/src/core/engine/surface.hpp new file mode 100644 index 00000000..9cd0b06f --- /dev/null +++ b/src/core/engine/surface.hpp @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2022 Mikhail Zolotukhin +// SPDX-License-Identifier: MIT + +#pragma once + +namespace Bismuth +{ +class Surface +{ +}; +} diff --git a/src/core/engine/window.cpp b/src/core/engine/window.cpp index 57588209..83152dfb 100644 --- a/src/core/engine/window.cpp +++ b/src/core/engine/window.cpp @@ -6,4 +6,24 @@ namespace Bismuth { +Window::Window(PlasmaApi::Client client) + : m_client(client) +{ +} + +bool Window::operator<(const Window &rhs) const +{ + return m_client < m_client; +} + +void Window::setMode(Mode value) +{ + m_mode = value; +} + +Window::Mode Window::mode() const +{ + return m_mode; +} + } diff --git a/src/core/engine/window.hpp b/src/core/engine/window.hpp index 63e44655..251b70ce 100644 --- a/src/core/engine/window.hpp +++ b/src/core/engine/window.hpp @@ -3,9 +3,31 @@ #pragma once +#include "plasma-api/client.hpp" + namespace Bismuth { class Window { +public: + enum class Mode { + Ignored, + Floating, + Fullscreen, + Maximized, + Tiled, + }; + + Window(PlasmaApi::Client client); + + bool operator<(const Window &rhs) const; + + void setMode(Mode); + Mode mode() const; + +private: + PlasmaApi::Client m_client; + + Mode m_mode; }; } diff --git a/src/core/engine/windows_list.cpp b/src/core/engine/windows_list.cpp index 1d54112b..8b052318 100644 --- a/src/core/engine/windows_list.cpp +++ b/src/core/engine/windows_list.cpp @@ -7,8 +7,13 @@ namespace Bismuth { -void WindowsList::add(PlasmaApi::Client) +void WindowsList::add(PlasmaApi::Client client) { - qDebug(Bi) << "Adding window... (CXX)"; + m_windowMap.insert_or_assign(client, Window(client)); +} + +void WindowsList::remove(PlasmaApi::Client client) +{ + m_windowMap.erase(client); } } diff --git a/src/core/engine/windows_list.hpp b/src/core/engine/windows_list.hpp index ff6be7de..db65aa5e 100644 --- a/src/core/engine/windows_list.hpp +++ b/src/core/engine/windows_list.hpp @@ -12,6 +12,7 @@ class WindowsList { public: void add(PlasmaApi::Client); + void remove(PlasmaApi::Client); private: std::map m_windowMap{}; diff --git a/src/core/plasma-api/client.cpp b/src/core/plasma-api/client.cpp index c974c2ad..600244ee 100644 --- a/src/core/plasma-api/client.cpp +++ b/src/core/plasma-api/client.cpp @@ -12,4 +12,10 @@ Client::Client(QObject *kwinImpl) Client::Client(const Client &rhs) : TopLevel(rhs){}; + +bool Client::operator<(const Client &rhs) const +{ + return m_kwinImpl < rhs.m_kwinImpl; +} + } diff --git a/src/core/plasma-api/client.hpp b/src/core/plasma-api/client.hpp index 505fb52a..ba6ba7fa 100644 --- a/src/core/plasma-api/client.hpp +++ b/src/core/plasma-api/client.hpp @@ -22,6 +22,8 @@ public: Client(const Client &); virtual ~Client() = default; + bool operator<(const Client &rhs) const; + /** * The activities this client is on. If it's on all activities the property is empty. */ diff --git a/src/core/plasma-api/toplevel.cpp b/src/core/plasma-api/toplevel.cpp index 1c692353..b76a3e3a 100644 --- a/src/core/plasma-api/toplevel.cpp +++ b/src/core/plasma-api/toplevel.cpp @@ -11,4 +11,25 @@ TopLevel::TopLevel(QObject *kwinImpl) TopLevel::TopLevel(const TopLevel &rhs) : m_kwinImpl(rhs.m_kwinImpl){}; + +TopLevel::TopLevel(TopLevel &&rhs) + : m_kwinImpl(rhs.m_kwinImpl){}; + +TopLevel &TopLevel::operator=(const TopLevel &rhs) +{ + if (&rhs != this) { + m_kwinImpl = rhs.m_kwinImpl; + } + + return *this; +} + +TopLevel &TopLevel::operator=(TopLevel &&rhs) +{ + if (&rhs != this) { + m_kwinImpl = std::move(rhs.m_kwinImpl); + } + + return *this; +} } diff --git a/src/core/plasma-api/toplevel.hpp b/src/core/plasma-api/toplevel.hpp index 5feac1a3..4b4149ca 100644 --- a/src/core/plasma-api/toplevel.hpp +++ b/src/core/plasma-api/toplevel.hpp @@ -13,9 +13,12 @@ class TopLevel : public QObject Q_OBJECT public: TopLevel() = default; + virtual ~TopLevel() = default; explicit TopLevel(QObject *kwinImplPtr); TopLevel(const TopLevel &); - virtual ~TopLevel() = default; + TopLevel(TopLevel &&); + TopLevel &operator=(const TopLevel &); + TopLevel &operator=(TopLevel &&); /** * Whether the window is a dialog window. diff --git a/src/core/qml-plugin.cpp b/src/core/qml-plugin.cpp index c528565f..bde33630 100644 --- a/src/core/qml-plugin.cpp +++ b/src/core/qml-plugin.cpp @@ -44,7 +44,7 @@ void Core::init() m_config = std::make_unique(); m_qmlEngine = qmlEngine(this); m_plasmaApi = std::make_unique(m_qmlEngine); - m_engine = std::make_unique(); + m_engine = std::make_unique(*m_plasmaApi); m_controller = std::make_unique(*m_plasmaApi, *m_engine); m_tsProxy = std::make_unique(m_qmlEngine, *m_controller, *m_plasmaApi, *m_config); m_controller->setProxy(m_tsProxy.get()); diff --git a/src/kwinscript/engine/index.ts b/src/kwinscript/engine/index.ts index 69d6710b..149c972a 100644 --- a/src/kwinscript/engine/index.ts +++ b/src/kwinscript/engine/index.ts @@ -333,14 +333,6 @@ export class EngineImpl implements Engine { const tilingArea = this.getTilingArea(workingArea, layout); const visibleWindows = this.windows.visibleWindowsOn(screenSurface); - this.log.log([ - "arrangeScreen", - { - layout, - screenSurface, - visibles: visibleWindows.length, - }, - ]); // Set correct window state for new windows visibleWindows.forEach((win: EngineWindow) => {