Skip to content

Commit 563c727

Browse files
committed
Rename WindowID to WindowId across codebase
Replaces all instances of the WindowID typedef and related usage with WindowId for consistency and clarity. Updates function signatures, class members, event constructors, and documentation comments in all window-related source and header files for Linux, macOS, and Windows platforms.
1 parent 9ca5cae commit 563c727

File tree

13 files changed

+273
-272
lines changed

13 files changed

+273
-272
lines changed

.cursor/rules/global-registry.mdc

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,24 @@ class Registry {
4747
public:
4848
using Key = void*;
4949
using Ptr = std::shared_ptr<T>;
50-
50+
5151
static Registry& GetInstance();
52-
52+
5353
// Register an object with a key
5454
bool Register(Key key, Ptr object);
55-
55+
5656
// Unregister an object by key
5757
bool Unregister(Key key);
58-
58+
5959
// Retrieve an object by key
6060
Ptr Get(Key key) const;
61-
61+
6262
// Check if key exists
6363
bool Contains(Key key) const;
64-
64+
6565
// Clear all entries
6666
void Clear();
67-
67+
6868
// Get snapshot of all entries
6969
std::unordered_map<Key, Ptr> GetSnapshot() const;
7070

@@ -97,13 +97,13 @@ public:
9797
// Create native window
9898
HWND hwnd = CreateWindowEx(...);
9999
if (!hwnd) return nullptr;
100-
100+
101101
// Create wrapper
102102
auto window = std::make_shared<Window>(static_cast<void*>(hwnd));
103-
103+
104104
// Register in global registry
105105
GlobalRegistry<Window>().Register(static_cast<void*>(hwnd), window);
106-
106+
107107
return window;
108108
}
109109
};
@@ -117,13 +117,13 @@ public:
117117
// Create native window
118118
NSWindow* nswindow = [[NSWindow alloc] init...];
119119
if (!nswindow) return nullptr;
120-
120+
121121
// Create wrapper
122122
auto window = std::make_shared<Window>(static_cast<void*>(nswindow));
123-
123+
124124
// Register in global registry
125125
GlobalRegistry<Window>().Register(static_cast<void*>(nswindow), window);
126-
126+
127127
return window;
128128
}
129129
};
@@ -140,11 +140,11 @@ When platform code calls back with native handles, look up the wrapper:
140140
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
141141
// Look up Window wrapper from native handle
142142
auto window = GlobalRegistry<Window>().Get(static_cast<void*>(hwnd));
143-
143+
144144
if (!window) {
145145
return DefWindowProc(hwnd, msg, wp, lp);
146146
}
147-
147+
148148
// Handle message using wrapper
149149
switch (msg) {
150150
case WM_SIZE:
@@ -154,7 +154,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
154154
// Emit WindowMovedEvent
155155
break;
156156
}
157-
157+
158158
return DefWindowProc(hwnd, msg, wp, lp);
159159
}
160160
```
@@ -166,11 +166,11 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
166166

167167
- (void)windowDidMove:(NSNotification*)notification {
168168
NSWindow* nswindow = [notification object];
169-
169+
170170
// Look up Window wrapper from native handle
171171
auto window = nativeapi::GlobalRegistry<nativeapi::Window>()
172172
.Get(static_cast<void*>(nswindow));
173-
173+
174174
if (window) {
175175
// Emit WindowMovedEvent using wrapper
176176
NSRect frame = [nswindow frame];
@@ -185,12 +185,12 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
185185

186186
```cpp
187187
// GTK signal callback
188-
static void OnWindowStateChanged(GtkWidget* widget,
188+
static void OnWindowStateChanged(GtkWidget* widget,
189189
GdkEventWindowState* event,
190190
gpointer user_data) {
191191
// Look up Window wrapper from native handle
192192
auto window = GlobalRegistry<Window>().Get(static_cast<void*>(widget));
193-
193+
194194
if (window) {
195195
// Emit appropriate event using wrapper
196196
if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) {
@@ -210,12 +210,12 @@ public:
210210
~Window() {
211211
// Get native handle before pimpl_ is destroyed
212212
void* native = GetNativeObject();
213-
213+
214214
if (native) {
215215
// Unregister from global registry
216216
GlobalRegistry<Window>().Unregister(native);
217217
}
218-
218+
219219
// pimpl_ destructor will clean up native object
220220
}
221221

@@ -228,26 +228,26 @@ private:
228228
Or unregister when manager destroys object:
229229

230230
```cpp
231-
bool WindowManager::Destroy(WindowID id) {
231+
bool WindowManager::Destroy(WindowId id) {
232232
auto it = windows_.find(id);
233233
if (it == windows_.end()) {
234234
return false;
235235
}
236-
236+
237237
auto window = it->second;
238-
238+
239239
// Unregister from global registry
240240
void* native = window->GetNativeObject();
241241
if (native) {
242242
GlobalRegistry<Window>().Unregister(native);
243243
}
244-
244+
245245
// Remove from local registry
246246
windows_.erase(it);
247-
247+
248248
// Emit event
249249
Emit<WindowClosedEvent>(id);
250-
250+
251251
return true;
252252
}
253253
```
@@ -286,10 +286,10 @@ void OnMenuCommand(HMENU hmenu, UINT item_id) {
286286
// macOS
287287
- (void)menuItemClicked:(id)sender {
288288
NSMenuItem* nsitem = (NSMenuItem*)sender;
289-
289+
290290
auto item = nativeapi::GlobalRegistry<nativeapi::MenuItem>()
291291
.Get(static_cast<void*>(nsitem));
292-
292+
293293
if (item) {
294294
item->Trigger();
295295
}
@@ -299,7 +299,7 @@ void OnMenuCommand(HMENU hmenu, UINT item_id) {
299299
static void OnMenuItemActivated(GtkMenuItem* menu_item, gpointer user_data) {
300300
auto item = nativeapi::GlobalRegistry<nativeapi::MenuItem>()
301301
.Get(static_cast<void*>(menu_item));
302-
302+
303303
if (item) {
304304
item->Trigger();
305305
}
@@ -497,7 +497,7 @@ auto snapshot = GlobalRegistry<Window>().GetSnapshot();
497497
std::cout << "Registered windows: " << snapshot.size() << std::endl;
498498

499499
for (const auto& [native, window] : snapshot) {
500-
std::cout << " - " << window->GetTitle()
500+
std::cout << " - " << window->GetTitle()
501501
<< " (native: " << native << ")" << std::endl;
502502
}
503503
```

.cursor/rules/pimpl-pattern.mdc

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public:
3838
private:
3939
// Forward declaration only - no definition
4040
class Impl;
41-
41+
4242
// Pointer to implementation
4343
std::unique_ptr<Impl> pimpl_;
4444
};
@@ -68,14 +68,14 @@ namespace nativeapi {
6868
class Window::Impl {
6969
public:
7070
Impl(HWND hwnd) : hwnd_(hwnd) {}
71-
71+
7272
HWND hwnd_; // Windows-specific handle
7373
// Other Windows-specific state...
7474
};
7575

7676
Window::Window() : pimpl_(std::make_unique<Impl>(nullptr)) {}
7777

78-
Window::Window(void* window)
78+
Window::Window(void* window)
7979
: pimpl_(std::make_unique<Impl>(static_cast<HWND>(window))) {}
8080

8181
Window::~Window() = default; // unique_ptr handles cleanup
@@ -101,14 +101,14 @@ namespace nativeapi {
101101
class Window::Impl {
102102
public:
103103
Impl(NSWindow* window) : window_(window) {}
104-
104+
105105
NSWindow* window_; // macOS-specific handle
106106
// Other macOS-specific state...
107107
};
108108

109109
Window::Window() : pimpl_(std::make_unique<Impl>(nil)) {}
110110

111-
Window::Window(void* window)
111+
Window::Window(void* window)
112112
: pimpl_(std::make_unique<Impl>(static_cast<NSWindow*>(window))) {}
113113

114114
Window::~Window() = default;
@@ -134,14 +134,14 @@ namespace nativeapi {
134134
class Window::Impl {
135135
public:
136136
Impl(GtkWidget* window) : window_(window) {}
137-
137+
138138
GtkWidget* window_; // GTK-specific handle
139139
// Other GTK-specific state...
140140
};
141141

142142
Window::Window() : pimpl_(std::make_unique<Impl>(nullptr)) {}
143143

144-
Window::Window(void* window)
144+
Window::Window(void* window)
145145
: pimpl_(std::make_unique<Impl>(static_cast<GtkWidget*>(window))) {}
146146

147147
Window::~Window() = default;
@@ -172,7 +172,7 @@ class MyClass {
172172
public:
173173
MyClass();
174174
virtual ~MyClass();
175-
175+
176176
void DoSomething();
177177

178178
private:
@@ -218,7 +218,7 @@ class MyClass {
218218
public:
219219
MyClass();
220220
virtual ~MyClass(); // Virtual if used as base class
221-
221+
222222
// Copy/move operations - handle appropriately
223223
MyClass(const MyClass&) = delete;
224224
MyClass& operator=(const MyClass&) = delete;
@@ -256,7 +256,7 @@ TrayIcon::TrayIcon() : TrayIcon(nullptr) {} // Delegate to parameterized constr
256256
TrayIcon::TrayIcon(void* tray) {
257257
// Handle both cases in one place
258258
NSStatusItem* status_item = nullptr;
259-
259+
260260
if (tray == nullptr) {
261261
// Create new platform object
262262
NSStatusBar* status_bar = [NSStatusBar systemStatusBar];
@@ -265,10 +265,10 @@ TrayIcon::TrayIcon(void* tray) {
265265
// Wrap existing platform object
266266
status_item = (__bridge NSStatusItem*)tray;
267267
}
268-
268+
269269
// All initialization logic in one place
270270
pimpl_ = std::make_unique<Impl>(status_item);
271-
271+
272272
// Additional setup that applies to both cases
273273
if (pimpl_->status_item_) {
274274
// Configure the status item...
@@ -291,7 +291,7 @@ TrayIcon::TrayIcon() : pimpl_(std::make_unique<Impl>()) {
291291
NSStatusBar* status_bar = [NSStatusBar systemStatusBar];
292292
NSStatusItem* status_item = [status_bar statusItemWithLength:NSVariableStatusItemLength];
293293
pimpl_->status_item_ = status_item;
294-
294+
295295
// Setup code duplicated...
296296
if (pimpl_->status_item_) {
297297
// Configure...
@@ -301,7 +301,7 @@ TrayIcon::TrayIcon() : pimpl_(std::make_unique<Impl>()) {
301301
TrayIcon::TrayIcon(void* tray) : pimpl_(std::make_unique<Impl>()) {
302302
NSStatusItem* status_item = (__bridge NSStatusItem*)tray;
303303
pimpl_->status_item_ = status_item;
304-
304+
305305
// Same setup code duplicated again!
306306
if (pimpl_->status_item_) {
307307
// Configure...
@@ -318,17 +318,17 @@ class WindowManager : public EventEmitter<WindowEvent> {
318318
public:
319319
static WindowManager& GetInstance();
320320
virtual ~WindowManager();
321-
321+
322322
std::shared_ptr<Window> Create(const WindowOptions& options);
323323

324324
private:
325325
WindowManager(); // Private constructor
326-
326+
327327
class Impl;
328328
std::unique_ptr<Impl> pimpl_;
329-
329+
330330
// Public data that doesn't vary by platform
331-
std::unordered_map<WindowID, std::shared_ptr<Window>> windows_;
331+
std::unordered_map<WindowId, std::shared_ptr<Window>> windows_;
332332
};
333333
```
334334

@@ -365,11 +365,11 @@ public:
365365
};
366366

367367
// Windows implementation
368-
Window::Window(void* window)
368+
Window::Window(void* window)
369369
: pimpl_(std::make_unique<Impl>(static_cast<HWND>(window))) {}
370370

371371
// macOS implementation
372-
Window::Window(void* window)
372+
Window::Window(void* window)
373373
: pimpl_(std::make_unique<Impl>(static_cast<NSWindow*>(window))) {}
374374
```
375375

@@ -380,7 +380,7 @@ Always validate before using platform handles:
380380
```cpp
381381
void Window::Show() {
382382
if (!pimpl_->hwnd_) return; // Or pimpl_->window_, pimpl_->gtk_window_
383-
383+
384384
// Safe to use handle
385385
ShowWindow(pimpl_->hwnd_, SW_SHOW);
386386
}

0 commit comments

Comments
 (0)