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
|
#ifndef SRDWM_WINDOW_MANAGER_H
#define SRDWM_WINDOW_MANAGER_H
#include <vector>
#include <algorithm> // Required for std::remove_if
#include <memory> // Required for std::unique_ptr
#include <map>
#include <string>
#include <functional>
#include <set> // Required for std::set
#include "../input/input_handler.h"
#include "../layouts/layout_engine.h"
#include "../platform/platform.h" // For Event type
#include "../layouts/layout.h" // For Monitor type
class SRDWindow; // Forward declaration
class InputHandler; // Forward declaration
class LuaManager; // Forward declaration
// Workspace structure
struct Workspace {
int id;
std::string name;
std::vector<SRDWindow*> windows;
std::string layout;
bool visible;
Workspace(int id, const std::string& name = "")
: id(id), name(name), layout("tiling"), visible(false) {}
};
class SRDWindowManager {
public:
SRDWindowManager();
~SRDWindowManager();
void run(); // Main loop
// SRDWindow management
void add_window(std::unique_ptr<SRDWindow> window);
void remove_window(SRDWindow* window);
void focus_window(SRDWindow* window);
SRDWindow* get_focused_window() const;
std::vector<SRDWindow*> get_windows() const;
void manage_windows(); // Added missing method
void focus_next_window();
void focus_previous_window();
// SRDWindow operations
void close_window(SRDWindow* window);
void minimize_window(SRDWindow* window);
void maximize_window(SRDWindow* window);
void move_window(SRDWindow* window, int x, int y);
void resize_window(SRDWindow* window, int width, int height);
void toggle_window_floating(SRDWindow* window);
bool is_window_floating(SRDWindow* window) const;
// Window dragging and resizing
void start_window_drag(SRDWindow* window, int start_x, int start_y);
void start_window_resize(SRDWindow* window, int start_x, int start_y, int edge);
void update_window_drag(int x, int y);
void update_window_resize(int x, int y);
void end_window_drag();
void end_window_resize();
bool is_dragging() const { return dragging_window_ != nullptr; }
bool is_resizing() const { return resizing_window_ != nullptr; }
// Workspace management
void add_workspace(const std::string& name = "");
void remove_workspace(int workspace_id);
void switch_to_workspace(int workspace_id);
void move_window_to_workspace(SRDWindow* window, int workspace_id);
int get_current_workspace() const;
std::vector<Workspace> get_workspaces() const;
Workspace* get_workspace(int workspace_id);
// Layout management
void set_layout(int monitor_id, const std::string& layout_name);
std::string get_layout(int monitor_id) const;
void arrange_windows();
void tile_windows();
void arrange_windows_dynamic();
// Key binding system
void bind_key(const std::string& key_combination, std::function<void()> action);
void unbind_key(const std::string& key_combination);
void handle_key_press(int key_code, int modifiers);
void handle_key_release(int key_code, int modifiers);
// Input event handling (called by InputHandler)
void handle_key_press(int key_code);
void handle_key_release(int key_code);
void handle_mouse_button_press(int button, int x, int y);
void handle_mouse_button_release(int button, int x, int y);
void handle_mouse_motion(int x, int y);
void handle_event(const Event& event); // Added missing method
// Integration
void set_layout_engine(LayoutEngine* engine);
void set_lua_manager(LuaManager* manager);
void set_platform(Platform* platform);
private:
// Window tracking
std::vector<SRDWindow*> windows_; // Added missing member variable
SRDWindow* focused_window_ = nullptr;
std::set<SRDWindow*> floating_windows_; // Track floating windows
InputHandler* input_handler_ = nullptr;
LayoutEngine* layout_engine_ = nullptr;
LuaManager* lua_manager_ = nullptr;
Platform* platform_ = nullptr;
// Workspace management
std::vector<Workspace> workspaces_;
int current_workspace_ = 0;
int next_workspace_id_ = 1;
// Window dragging and resizing state
SRDWindow* dragging_window_ = nullptr;
SRDWindow* resizing_window_ = nullptr;
int drag_start_x_ = 0;
int drag_start_y_ = 0;
int drag_start_window_x_ = 0;
int drag_start_window_y_ = 0;
int resize_start_x_ = 0;
int resize_start_y_ = 0;
int resize_start_width_ = 0;
int resize_start_height_ = 0;
int resize_edge_ = 0; // 0=none, 1=left, 2=right, 3=top, 4=bottom, 5=corner
// Key binding system
std::map<std::string, std::function<void()>> key_bindings_;
std::map<int, int> pressed_keys_; // key_code -> modifiers
// Platform-specific data (placeholder)
void* platform_data_ = nullptr;
// Monitor information
std::vector<Monitor> monitors_;
// Helper methods
std::string key_code_to_string(int key_code, int modifiers) const;
void execute_key_binding(const std::string& key_combination);
void update_layout_for_window(SRDWindow* window);
void arrange_workspace_windows(int workspace_id);
void update_workspace_visibility();
// Window interaction helpers
SRDWindow* find_window_at_position(int x, int y) const;
bool is_in_titlebar_area(SRDWindow* window, int x, int y) const;
bool is_in_resize_area(SRDWindow* window, int x, int y) const;
int get_resize_edge(SRDWindow* window, int x, int y) const;
};
#endif // SRDWM_WINDOW_MANAGER_H
|