1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
#include <iostream>
#include <memory>
#include <string>
// Include Lua manager
#include "config/lua_manager.h"
// Include layout engine
#include "layouts/layout_engine.h"
// Include window manager
#include "core/window_manager.h"
// Include platform factory
#include "platform/platform_factory.h"
int main(int argc, char* argv[]) {
std::cout << "SRDWM starting up..." << std::endl;
// Print platform information
PlatformFactory::print_platform_info();
// Initialize layout engine
auto layout_engine = std::make_unique<LayoutEngine>();
std::cout << "Layout engine created" << std::endl;
// Add a default monitor
Monitor default_monitor{0, 0, 0, 1920, 1080, "Default", 60};
layout_engine->add_monitor(default_monitor);
std::cout << "Default monitor added to layout engine" << std::endl;
// Initialize Lua manager
g_lua_manager = std::make_unique<LuaManager>();
if (!g_lua_manager->initialize()) {
std::cerr << "Failed to initialize Lua manager" << std::endl;
return 1;
}
// Connect layout engine to Lua manager
g_lua_manager->set_layout_engine(layout_engine.get());
std::cout << "Layout engine connected to Lua manager" << std::endl;
// Initialize window manager
auto window_manager = std::make_unique<SRDWindowManager>();
std::cout << "SRDWindow manager created" << std::endl;
// Connect components
window_manager->set_layout_engine(layout_engine.get());
window_manager->set_lua_manager(g_lua_manager.get());
std::cout << "Components connected to window manager" << std::endl;
// Initialize default workspaces
window_manager->add_workspace("Main");
window_manager->add_workspace("Web");
window_manager->add_workspace("Code");
window_manager->add_workspace("Media");
std::cout << "Default workspaces created" << std::endl;
// Load configuration
std::string config_path = "./config/srdwm.lua";
if (!g_lua_manager->load_config_file(config_path)) {
std::cout << "Failed to load configuration, using defaults" << std::endl;
// Set default configuration
g_lua_manager->set_string("general.default_layout", "tiling");
g_lua_manager->set_bool("general.smart_placement", true);
g_lua_manager->set_int("general.window_gap", 8);
g_lua_manager->set_int("general.border_width", 2);
g_lua_manager->set_bool("general.animations", true);
g_lua_manager->set_int("general.animation_duration", 200);
}
// Display current configuration
std::cout << "\nCurrent Configuration:" << std::endl;
std::cout << "Default Layout: " << g_lua_manager->get_string("general.default_layout", "tiling") << std::endl;
std::cout << "Smart Placement: " << (g_lua_manager->get_bool("general.smart_placement", true) ? "enabled" : "disabled") << std::endl;
std::cout << "Window Gap: " << g_lua_manager->get_int("general.window_gap", 8) << " pixels" << std::endl;
std::cout << "Border Width: " << g_lua_manager->get_int("general.border_width", 2) << " pixels" << std::endl;
std::cout << "Animations: " << (g_lua_manager->get_bool("general.animations", true) ? "enabled" : "disabled") << std::endl;
std::cout << "Animation Duration: " << g_lua_manager->get_int("general.animation_duration", 200) << " ms" << std::endl;
// Platform initialization
std::cout << "\nInitializing platform..." << std::endl;
// Create platform with automatic detection
auto platform = PlatformFactory::create_platform();
if (!platform) {
std::cerr << "Failed to create platform" << std::endl;
return 1;
}
std::cout << "Platform created: " << platform->get_platform_name() << std::endl;
// Initialize platform
if (!platform->initialize()) {
std::cerr << "Failed to initialize platform" << std::endl;
return 1;
}
std::cout << "Platform initialized successfully" << std::endl;
// Connect platform to window manager
window_manager->set_platform(platform.get());
// Set up key bindings
std::cout << "\nSetting up key bindings..." << std::endl;
// Workspace switching
window_manager->bind_key("Mod4+1", [&]() { window_manager->switch_to_workspace(0); });
window_manager->bind_key("Mod4+2", [&]() { window_manager->switch_to_workspace(1); });
window_manager->bind_key("Mod4+3", [&]() { window_manager->switch_to_workspace(2); });
window_manager->bind_key("Mod4+4", [&]() { window_manager->switch_to_workspace(3); });
// Workspace management
window_manager->bind_key("Mod4+Shift+1", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) window_manager->move_window_to_workspace(focused, 0);
});
window_manager->bind_key("Mod4+Shift+2", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) window_manager->move_window_to_workspace(focused, 1);
});
window_manager->bind_key("Mod4+Shift+3", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) window_manager->move_window_to_workspace(focused, 2);
});
window_manager->bind_key("Mod4+Shift+4", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) window_manager->move_window_to_workspace(focused, 3);
});
// Window focus cycling
window_manager->bind_key("Mod4+Tab", [&]() {
window_manager->focus_next_window();
});
window_manager->bind_key("Mod4+Shift+Tab", [&]() {
window_manager->focus_previous_window();
});
// Layout switching
window_manager->bind_key("Mod4+t", [&]() {
layout_engine->set_layout(0, "tiling");
window_manager->arrange_windows();
});
window_manager->bind_key("Mod4+d", [&]() {
layout_engine->set_layout(0, "dynamic");
window_manager->arrange_windows();
});
window_manager->bind_key("Mod4+s", [&]() {
layout_engine->set_layout(0, "smart_placement");
window_manager->arrange_windows();
});
// Window management
window_manager->bind_key("Mod4+q", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) window_manager->close_window(focused);
});
window_manager->bind_key("Mod4+m", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) window_manager->maximize_window(focused);
});
// Window floating and tiling
window_manager->bind_key("Mod4+f", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) {
window_manager->toggle_window_floating(focused);
}
});
// Window movement with arrow keys
window_manager->bind_key("Mod4+Shift+Left", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) {
int new_x = focused->getX() - 50;
window_manager->move_window(focused, new_x, focused->getY());
}
});
window_manager->bind_key("Mod4+Shift+Right", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) {
int new_x = focused->getX() + 50;
window_manager->move_window(focused, new_x, focused->getY());
}
});
window_manager->bind_key("Mod4+Shift+Up", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) {
int new_y = focused->getY() - 50;
window_manager->move_window(focused, focused->getX(), new_y);
}
});
window_manager->bind_key("Mod4+Shift+Down", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) {
int new_y = focused->getY() + 50;
window_manager->move_window(focused, focused->getX(), new_y);
}
});
// Window resizing with arrow keys
window_manager->bind_key("Mod4+Ctrl+Left", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) {
int new_width = focused->getWidth() - 50;
if (new_width >= 100) {
window_manager->resize_window(focused, new_width, focused->getHeight());
}
}
});
window_manager->bind_key("Mod4+Ctrl+Right", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) {
int new_width = focused->getWidth() + 50;
window_manager->resize_window(focused, new_width, focused->getHeight());
}
});
window_manager->bind_key("Mod4+Ctrl+Up", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) {
int new_height = focused->getHeight() - 50;
if (new_height >= 100) {
window_manager->resize_window(focused, focused->getWidth(), new_height);
}
}
});
window_manager->bind_key("Mod4+Ctrl+Down", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) {
int new_height = focused->getHeight() + 50;
window_manager->resize_window(focused, focused->getWidth(), new_height);
}
});
// Additional window operations
window_manager->bind_key("Mod4+space", [&]() {
auto* focused = window_manager->get_focused_window();
if (focused) window_manager->minimize_window(focused);
});
window_manager->bind_key("Mod4+Return", [&]() {
// TODO: Launch terminal
std::cout << "Launch terminal" << std::endl;
});
window_manager->bind_key("Mod4+d", [&]() {
// TODO: Launch application launcher
std::cout << "Launch application launcher" << std::endl;
});
// Quick layout presets
window_manager->bind_key("Mod4+Shift+t", [&]() {
layout_engine->set_layout(0, "tiling");
window_manager->arrange_windows();
});
window_manager->bind_key("Mod4+Shift+d", [&]() {
layout_engine->set_layout(0, "dynamic");
window_manager->arrange_windows();
});
window_manager->bind_key("Mod4+Shift+s", [&]() {
layout_engine->set_layout(0, "smart_placement");
window_manager->arrange_windows();
});
// Exit
window_manager->bind_key("Mod4+Shift+q", [&]() {
std::cout << "Exit key combination pressed" << std::endl;
// TODO: Implement proper cleanup and exit
});
std::cout << "Key bindings configured" << std::endl;
// Set initial layout
std::string default_layout = g_lua_manager->get_string("general.default_layout", "tiling");
layout_engine->set_layout(0, default_layout);
// Arrange initial windows
window_manager->arrange_windows();
std::cout << "\nSRDWM initialization complete!" << std::endl;
std::cout << "\nAvailable Key Bindings:" << std::endl;
std::cout << " Mod4+1-4 - Switch to workspace 1-4" << std::endl;
std::cout << " Mod4+Shift+1-4 - Move focused window to workspace 1-4" << std::endl;
std::cout << " Mod4+t/d/s - Switch to tiling/dynamic/smart placement layout" << std::endl;
std::cout << " Mod4+Shift+t/d/s - Quick layout presets" << std::endl;
std::cout << " Mod4+Tab - Focus next window" << std::endl;
std::cout << " Mod4+Shift+Tab - Focus previous window" << std::endl;
std::cout << " Mod4+f - Toggle window floating" << std::endl;
std::cout << " Mod4+q - Close focused window" << std::endl;
std::cout << " Mod4+m - Maximize focused window" << std::endl;
std::cout << " Mod4+space - Minimize focused window" << std::endl;
std::cout << " Mod4+Shift+Arrows - Move focused window" << std::endl;
std::cout << " Mod4+Ctrl+Arrows - Resize focused window" << std::endl;
std::cout << " Mod4+Return - Launch terminal" << std::endl;
std::cout << " Mod4+d - Launch application launcher" << std::endl;
std::cout << " Mod4+Shift+q - Exit SRDWM" << std::endl;
std::cout << "\nMouse Controls:" << std::endl;
std::cout << " Left click + drag on titlebar - Move window" << std::endl;
std::cout << " Left click + drag on edges - Resize window" << std::endl;
// Main event loop
try {
window_manager->run();
} catch (const std::exception& e) {
std::cerr << "Error in main loop: " << e.what() << std::endl;
}
std::cout << "SRDWM shutting down." << std::endl;
// Clean up platform
platform->shutdown();
platform.reset();
// Clean up Lua manager
g_lua_manager->shutdown();
g_lua_manager.reset();
std::cout << "Cleanup completed." << std::endl;
return 0;
}
|