Skip to content

Commit a3e526e

Browse files
feat: little refactor of Desktop Inits
1 parent 4fb9b8d commit a3e526e

12 files changed

Lines changed: 182 additions & 16 deletions

File tree

desktop/ui/CFDesktop.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <QWidget>
1818
namespace cf::desktop {
1919
class PanelManager;
20-
class WidgetShellLayer;
20+
class IShellLayer;
2121
class CFDesktopEntity;
2222

2323
/**
@@ -77,11 +77,11 @@ class CF_DESKTOP_EXPORT CFDesktop final : public QWidget {
7777
/* Managed by Resources */
7878
struct InitResources {
7979
PanelManager* panel_manager_{nullptr};
80-
WidgetShellLayer* shell_layer_{nullptr};
80+
IShellLayer* shell_layer_{nullptr};
8181
};
8282

8383
PanelManager* panel_manager_{nullptr};
84-
WidgetShellLayer* shell_layer_{nullptr};
84+
IShellLayer* shell_layer_{nullptr};
8585

8686
private:
8787
CFDesktop(CFDesktopEntity* entity_object); /* pass the entity objects */

desktop/ui/CFDesktopEntity.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
#include "components/DisplayServerBackendFactory.h"
99
#include "components/IDisplayServerBackend.h"
1010
#include "components/PanelManager.h"
11-
#include "components/shell_layer_impl/WallpaperShellLayerStrategy.h"
12-
#include "components/shell_layer_impl/WidgetShellLayer.h"
13-
#include "components/wallpaper/ImageWallPaperLayer.h"
1411
#include "platform/DesktopPropertyStrategyFactory.h"
1512
#include "platform/display_backend_helper.h"
13+
#include "platform/shell_layer_helper.h"
1614
#include "qt_format.h"
1715
#include <memory>
1816

@@ -86,23 +84,21 @@ CFDesktopEntity::RunsSetupResult CFDesktopEntity::run_init(RunsSetupMethod m) {
8684

8785
// ── Create PanelManager and ShellLayer ──
8886
auto* panel_mgr = new PanelManager(desktop_entity_, desktop_entity_);
89-
auto* shell = new WidgetShellLayer(desktop_entity_);
87+
88+
auto shell_api = platform::native_shell_layer();
89+
auto* shell = shell_api.shell_creator(desktop_entity_);
90+
auto strategy = shell_api.strategy_creator();
91+
shell->setStrategy(std::move(strategy));
9092

9193
// Inject into CFDesktop
9294
CFDesktop::InitResources res;
9395
res.panel_manager_ = panel_mgr;
9496
res.shell_layer_ = shell;
9597
desktop_entity_->register_desktop_resources(res);
9698

97-
// Set shell strategy with wallpaper support
98-
auto wallpaper_layer = std::make_unique<wallpaper::ImageWallPaperLayer>();
99-
auto wallpaper_strategy =
100-
std::make_unique<WallpaperShellLayerStrategy>(std::move(wallpaper_layer));
101-
shell->setStrategy(std::move(wallpaper_strategy));
102-
10399
// Connect PanelManager geometry changes to ShellLayer
104-
QObject::connect(panel_mgr, &PanelManager::availableGeometryChanged, shell,
105-
&WidgetShellLayer::onAvailableGeometryChanged);
100+
QObject::connect(panel_mgr, &PanelManager::availableGeometryChanged, desktop_entity_,
101+
[shell](const QRect& r) { shell->onAvailableGeometryChanged(r); });
106102

107103
// Show the desktop full-screen
108104
desktop_entity_->showFullScreen();

desktop/ui/components/IShellLayer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ class IShellLayer {
6060
* Wayland compositor layers commit the surface.
6161
*/
6262
virtual void requestRepaint() = 0;
63+
64+
/**
65+
* @brief Handles changes to the available screen geometry.
66+
*
67+
* Called when the available geometry changes (e.g., after panel layout).
68+
* Implementations should update their geometry and notify the active strategy.
69+
*
70+
* @param[in] available The new available geometry rectangle.
71+
*/
72+
virtual void onAvailableGeometryChanged(const QRect& available) = 0;
6373
};
6474

6575
} // namespace cf::desktop

desktop/ui/components/shell_layer_impl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_library(cfdesktop_shell_layer_impl STATIC
33
WidgetShellLayer.cpp
44
DefaultShellLayerStrategy.cpp
55
WallpaperShellLayerStrategy.cpp
6+
../wallpaper/wallpaper_setup.cpp
67
)
78

89
target_include_directories(cfdesktop_shell_layer_impl PUBLIC

desktop/ui/components/shell_layer_impl/WidgetShellLayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class WidgetShellLayer : public QWidget, public IShellLayer {
8484
*
8585
* @param[in] rect The new available geometry rectangle.
8686
*/
87-
void onAvailableGeometryChanged(const QRect& rect);
87+
void onAvailableGeometryChanged(const QRect& rect) override;
8888

8989
protected:
9090
/**
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "wallpaper/wallpaper_setup.h"
2+
#include "shell_layer_impl/WallpaperShellLayerStrategy.h"
3+
#include "wallpaper/ImageWallPaperLayer.h"
4+
5+
namespace cf::desktop::wallpaper {
6+
7+
namespace {
8+
9+
std::unique_ptr<WallPaperLayer> make_layer() {
10+
return std::make_unique<ImageWallPaperLayer>();
11+
}
12+
13+
} // namespace
14+
15+
std::unique_ptr<IShellLayerStrategy> create_wallpaper_strategy() {
16+
return std::make_unique<WallpaperShellLayerStrategy>(make_layer());
17+
}
18+
19+
} // namespace cf::desktop::wallpaper
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @file desktop/ui/components/wallpaper/wallpaper_setup.h
3+
* @brief Factory for creating a wallpaper shell-layer strategy.
4+
*
5+
* @author N/A
6+
* @date N/A
7+
* @version N/A
8+
* @since N/A
9+
* @ingroup none
10+
*/
11+
12+
#pragma once
13+
#include <memory>
14+
15+
namespace cf::desktop {
16+
class IShellLayerStrategy;
17+
}
18+
19+
namespace cf::desktop::wallpaper {
20+
21+
/**
22+
* @brief Create a wallpaper shell layer strategy with the default wallpaper layer.
23+
*
24+
* @return std::unique_ptr<IShellLayerStrategy>
25+
*/
26+
std::unique_ptr<IShellLayerStrategy> create_wallpaper_strategy();
27+
28+
} // namespace cf::desktop::wallpaper

desktop/ui/platform/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ set(PLATFORM_SOURCES
88
IDesktopPropertyStrategy.cpp
99
IDesktopDisplaySizeStrategy.cpp
1010
display_backend_helper.cpp
11+
shell_layer_helper.cpp
1112
)
1213

1314
set(PLATFORM_HEADERS
1415
platform_helper.h
1516
DesktopPropertyStrategyFactory.h
1617
IDesktopPropertyStrategy.h
1718
display_backend_helper.h
19+
shell_layer_helper.h
1820
)
1921

2022
# Add platform-specific subdirectories

desktop/ui/platform/linux_wsl/linux_wsl_platform.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#include "linux_wsl_platform.h"
22
#include "IDesktopPropertyStrategy.h"
3+
#include "components/IShellLayerStrategy.h"
4+
#include "components/shell_layer_impl/WidgetShellLayer.h"
5+
#include "components/wallpaper/wallpaper_setup.h"
36
#include "display_backend_helper.h"
47
#include "linux_wsl_factory.h"
58
#include "platform_helper.h"
9+
#include "shell_layer_helper.h"
610
#include "wsl_x11_display_server_backend.h"
711

812
namespace cf::desktop::platform_strategy {
@@ -31,4 +35,16 @@ DisplayBackendFactoryAPI native_display_impl() {
3135
return api;
3236
}
3337

38+
ShellLayerFactoryAPI native_shell_layer_impl() {
39+
ShellLayerFactoryAPI api;
40+
api.shell_creator = [](QWidget* parent) -> IShellLayer* {
41+
return new WidgetShellLayer(parent);
42+
};
43+
api.shell_releaser = [](IShellLayer* p) { delete p; };
44+
api.strategy_creator = []() -> std::unique_ptr<IShellLayerStrategy> {
45+
return wallpaper::create_wallpaper_strategy();
46+
};
47+
return api;
48+
}
49+
3450
} // namespace cf::desktop::platform
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "shell_layer_helper.h"
2+
3+
namespace cf::desktop::platform {
4+
5+
/* Forward declaration -- each platform provides this */
6+
ShellLayerFactoryAPI native_shell_layer_impl();
7+
8+
ShellLayerFactoryAPI native_shell_layer() noexcept {
9+
return native_shell_layer_impl();
10+
}
11+
12+
} // namespace cf::desktop::platform

0 commit comments

Comments
 (0)