Skip to content

Commit 3c2f70c

Browse files
committed
Change windows key
1 parent de75eda commit 3c2f70c

File tree

6 files changed

+51
-49
lines changed

6 files changed

+51
-49
lines changed

src/module.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,50 @@ WindowInt *window;
3030

3131
void createWindowJS(const v8::FunctionCallbackInfo<v8::Value>& args)
3232
{
33+
v8::String::Utf8Value str(v8::Isolate::GetCurrent(), args[0]);
34+
std::string name(*str);
35+
3336
v8::Local<v8::Object> bufferObj = args[0].As<v8::Object>();
3437
unsigned char* handle = (unsigned char*)node::Buffer::Data(bufferObj);
3538

36-
window->createWindow(handle);
39+
window->createWindow(name, handle);
3740
}
3841

3942
void destroyWindowJS(const v8::FunctionCallbackInfo<v8::Value>& args)
4043
{
41-
v8::Local<v8::Object> bufferObj = args[0].As<v8::Object>();
42-
unsigned char* handle = (unsigned char*)node::Buffer::Data(bufferObj);
44+
v8::String::Utf8Value str(v8::Isolate::GetCurrent(), args[0]);
45+
std::string name(*str);
4346

44-
window->destroyWindow(handle);
47+
window->destroyWindow(name);
4548
}
4649

4750
void connectIOSurfaceJS(const v8::FunctionCallbackInfo<v8::Value>& args)
4851
{
49-
v8::Local<v8::Object> bufferObj = args[0].As<v8::Object>();
50-
unsigned char* handle = (unsigned char*)node::Buffer::Data(bufferObj);
52+
v8::String::Utf8Value str(v8::Isolate::GetCurrent(), args[0]);
53+
std::string name(*str);
5154

5255
v8::Local<v8::Uint32> surfaceID = v8::Local<v8::Uint32>::Cast(args[1]);
5356

54-
window->connectIOSurfaceJS(handle, surfaceID->Uint32Value());
57+
window->connectIOSurfaceJS(name, surfaceID->Uint32Value());
5558
}
5659

5760
void destroyIOSurfaceJS(const v8::FunctionCallbackInfo<v8::Value>& args)
5861
{
59-
v8::Local<v8::Object> bufferObj = args[0].As<v8::Object>();
60-
unsigned char* handle = (unsigned char*)node::Buffer::Data(bufferObj);
62+
v8::String::Utf8Value str(v8::Isolate::GetCurrent(), args[0]);
63+
std::string name(*str);
6164

62-
window->destroyIOSurface(handle);
65+
window->destroyIOSurface(name);
6366
}
6467

6568
void moveWindowJS(const v8::FunctionCallbackInfo<v8::Value>& args)
6669
{
67-
v8::Local<v8::Object> bufferObj = args[0].As<v8::Object>();
68-
unsigned char* handle = (unsigned char*)node::Buffer::Data(bufferObj);
70+
v8::String::Utf8Value str(v8::Isolate::GetCurrent(), args[0]);
71+
std::string name(*str);
6972

7073
v8::Local<v8::Uint32> cx = v8::Local<v8::Uint32>::Cast(args[1]);
7174
v8::Local<v8::Uint32> cy = v8::Local<v8::Uint32>::Cast(args[2]);
7275

73-
window->moveWindow(handle, cx->Uint32Value(), cy->Uint32Value());
76+
window->moveWindow(name, cx->Uint32Value(), cy->Uint32Value());
7477
}
7578

7679
void init(v8::Local<v8::Object> exports) {

src/window-osx-int.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,27 @@ WindowInt::~WindowInt(void)
3333
if (_impl) { delete _impl; _impl = nullptr; }
3434
}
3535

36-
void WindowInt::createWindow(unsigned char* handle)
36+
void WindowInt::createWindow(std::string name, unsigned char* handle)
3737
{
38-
_impl->createWindow(handle);
38+
_impl->createWindow(name, handle);
3939
}
4040

41-
void WindowInt::destroyWindow(unsigned char* handle)
41+
void WindowInt::destroyWindow(std::string name)
4242
{
43-
_impl->destroyWindow(handle);
43+
_impl->destroyWindow(name);
4444
}
4545

46-
void WindowInt::connectIOSurfaceJS(unsigned char* handle, uint32_t surfaceID)
46+
void WindowInt::connectIOSurfaceJS(std::string name, uint32_t surfaceID)
4747
{
48-
_impl->connectIOSurfaceJS(handle, surfaceID);
48+
_impl->connectIOSurfaceJS(name, surfaceID);
4949
}
5050

51-
void WindowInt::destroyIOSurface(unsigned char* handle)
51+
void WindowInt::destroyIOSurface(std::string name)
5252
{
53-
_impl->destroyIOSurface(handle);
53+
_impl->destroyIOSurface(name);
5454
}
5555

56-
void WindowInt::moveWindow(unsigned char* handle, uint32_t cx, uint32_t cy)
56+
void WindowInt::moveWindow(std::string name, uint32_t cx, uint32_t cy)
5757
{
58-
_impl->moveWindow(handle, cx, cy);
58+
_impl->moveWindow(name, cx, cy);
5959
}

src/window-osx-int.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define __WINDOW_CLASS_H__
2121

2222
#include <stdint.h>
23+
#include <string>
2324

2425
class WindowObjCInt;
2526

@@ -30,11 +31,11 @@ class WindowInt
3031
~WindowInt(void);
3132

3233
void init(void);
33-
void createWindow(unsigned char* handle);
34-
void destroyWindow(unsigned char* handle);
35-
void connectIOSurfaceJS(unsigned char* handle, uint32_t surfaceID);
36-
void destroyIOSurface(unsigned char* handle);
37-
void moveWindow(unsigned char* handle, uint32_t cx, uint32_t cy);
34+
void createWindow(std::string name, unsigned char* handle);
35+
void destroyWindow(std::string name);
36+
void connectIOSurfaceJS(std::string name, uint32_t surfaceID);
37+
void destroyIOSurface(std::string name);
38+
void moveWindow(std::string name, uint32_t cx, uint32_t cy);
3839

3940
private:
4041
WindowObjCInt * _impl;

src/window-osx-obj-c-int.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222

2323
#include <stdint.h>
24+
#include <string>
2425

2526
class WindowObjCInt
2627
{
@@ -29,11 +30,11 @@ class WindowObjCInt
2930
~WindowObjCInt(void);
3031

3132
void init(void);
32-
void createWindow(unsigned char* handle);
33-
void destroyWindow(unsigned char* handle);
34-
void connectIOSurfaceJS(unsigned char* handle, uint32_t surfaceID);
35-
void destroyIOSurface(unsigned char* handle);
36-
void moveWindow(unsigned char* handle, uint32_t cx, uint32_t cy);
33+
void createWindow(std::string name, unsigned char* handle);
34+
void destroyWindow(std::string name);
35+
void connectIOSurfaceJS(std::string name, uint32_t surfaceID);
36+
void destroyIOSurface(std::string name);
37+
void moveWindow(std::string name, uint32_t cx, uint32_t cy);
3738

3839
private:
3940
void * self;

src/window-osx.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <iostream>
3232
#include <thread>
3333
#include <mutex>
34+
#include <string>
3435

3536
@interface WindowImplObj : NSObject
3637
@end
@@ -57,4 +58,4 @@ struct WindowInfo {
5758
bool destroyed = false;
5859
};
5960

60-
std::map<void*, void*> windows; // <NSView* parent, WindowInfo* wi>
61+
std::map<std::string, void*> windows; // <std::string name, WindowInfo* wi>

src/window-osx.mm

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ @implementation WindowImplObj
378378
self = [[WindowImplObj alloc] init];
379379
}
380380

381-
void WindowObjCInt::createWindow(unsigned char* handle)
381+
void WindowObjCInt::createWindow(std::string name, unsigned char* handle)
382382
{
383383
WindowInfo* wi = new WindowInfo();
384384

@@ -388,13 +388,12 @@ @implementation WindowImplObj
388388
wi->view = [[OpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
389389
[winParent.contentView addSubview:wi->view];
390390

391-
windows.emplace(viewParent, wi);
391+
windows.emplace(name, wi);
392392
}
393393

394-
void WindowObjCInt::destroyWindow(unsigned char* handle)
394+
void WindowObjCInt::destroyWindow(std::string name)
395395
{
396-
NSView *viewParent = *reinterpret_cast<NSView**>(handle);
397-
auto it = windows.find(viewParent);
396+
auto it = windows.find(name);
398397
if (it == windows.end())
399398
return;
400399

@@ -414,13 +413,12 @@ @implementation WindowImplObj
414413
[wi->view removeFromSuperview];
415414
CFRelease(wi->view);
416415

417-
windows.erase(viewParent);
416+
windows.erase(name);
418417
}
419418

420-
void WindowObjCInt::connectIOSurfaceJS(unsigned char* handle, uint32_t surfaceID)
419+
void WindowObjCInt::connectIOSurfaceJS(std::string name, uint32_t surfaceID)
421420
{
422-
NSView* viewParent = *reinterpret_cast<NSView**>(handle);
423-
auto it = windows.find(viewParent);
421+
auto it = windows.find(name);
424422
if (it == windows.end())
425423
return;
426424

@@ -437,10 +435,9 @@ @implementation WindowImplObj
437435
IOSurfaceGetHeight(wi->view.glData->surface))];
438436
}
439437

440-
void WindowObjCInt::destroyIOSurface(unsigned char* handle)
438+
void WindowObjCInt::destroyIOSurface(std::string name)
441439
{
442-
NSView *viewParent = *reinterpret_cast<NSView**>(handle);
443-
auto it = windows.find(viewParent);
440+
auto it = windows.find(name);
444441
if (it == windows.end())
445442
return;
446443

@@ -451,10 +448,9 @@ @implementation WindowImplObj
451448
}
452449
}
453450

454-
void WindowObjCInt::moveWindow(unsigned char* handle, uint32_t cx, uint32_t cy)
451+
void WindowObjCInt::moveWindow(std::string name, uint32_t cx, uint32_t cy)
455452
{
456-
NSView *viewParent = *reinterpret_cast<NSView**>(handle);
457-
auto it = windows.find(viewParent);
453+
auto it = windows.find(name);
458454
if (it == windows.end())
459455
return;
460456

0 commit comments

Comments
 (0)