mac: implement clipboard (At the cost of making the pending function a crime against god)
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
This commit is contained in:
parent
9be36b0755
commit
9d7a75394c
2 changed files with 58 additions and 1 deletions
|
|
@ -80,6 +80,8 @@
|
||||||
MilskoCocoaView *view;
|
MilskoCocoaView *view;
|
||||||
MwLL parent;
|
MwLL parent;
|
||||||
MilskoFakePointer *handle;
|
MilskoFakePointer *handle;
|
||||||
|
NSUInteger strHash;
|
||||||
|
MwBool pendingTicker;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (MilskoCocoa *)newWithParent:(MwLL)parent
|
+ (MilskoCocoa *)newWithParent:(MwLL)parent
|
||||||
|
|
@ -118,6 +120,7 @@
|
||||||
- (void)getCursorCoord:(MwPoint *)point;
|
- (void)getCursorCoord:(MwPoint *)point;
|
||||||
- (void)getScreenSize:(MwRect *)rect;
|
- (void)getScreenSize:(MwRect *)rect;
|
||||||
- (void)destroy;
|
- (void)destroy;
|
||||||
|
- (void)sendClipboardEvent;
|
||||||
|
|
||||||
- (NSWindow *)parentWindow;
|
- (NSWindow *)parentWindow;
|
||||||
- (NSView *)getView;
|
- (NSView *)getView;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include "Mw/BaseTypes.h"
|
||||||
|
#include "Mw/LowLevel.h"
|
||||||
#include <Mw/Milsko.h>
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
#pragma clang push
|
#pragma clang push
|
||||||
|
|
@ -140,6 +142,7 @@ static CGPoint pointFlip(CGPoint point) {
|
||||||
c->parent = parent;
|
c->parent = parent;
|
||||||
|
|
||||||
c->_forceRender = MwTRUE;
|
c->_forceRender = MwTRUE;
|
||||||
|
c->strHash = 0;
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
@ -235,12 +238,23 @@ static CGPoint pointFlip(CGPoint point) {
|
||||||
_forceRender = MwFALSE;
|
_forceRender = MwFALSE;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
// Apple does not give you a reliable way to tell when events are coming. I
|
||||||
|
// found this out by accident by stumbling upon a comment wxWidget's code,
|
||||||
|
// thought I could figure out something better, and I ended up with the same
|
||||||
|
// solution they tried and can confirm it doesn't work.
|
||||||
|
// Thanks Tim Cook.
|
||||||
|
#if 0
|
||||||
self->lastEvent = [self->window nextEventMatchingMask:NSAnyEventMask
|
self->lastEvent = [self->window nextEventMatchingMask:NSAnyEventMask
|
||||||
untilDate:[NSDate distantPast]
|
untilDate:[NSDate distantPast]
|
||||||
inMode:NSDefaultRunLoopMode
|
inMode:NSDefaultRunLoopMode
|
||||||
dequeue:YES];
|
dequeue:YES];
|
||||||
|
|
||||||
|
|
||||||
return self->lastEvent != NULL;
|
return self->lastEvent != NULL;
|
||||||
|
#endif
|
||||||
|
// And unlike wxWidgets we can't just return 1, so instead we alternate
|
||||||
|
// between such.
|
||||||
|
return (self->pendingTicker = !self->pendingTicker);
|
||||||
};
|
};
|
||||||
|
|
||||||
- (void)getNextEvent {
|
- (void)getNextEvent {
|
||||||
|
|
@ -257,6 +271,8 @@ static CGPoint pointFlip(CGPoint point) {
|
||||||
dequeue:YES])) {
|
dequeue:YES])) {
|
||||||
[self eventProcess:ev];
|
[self eventProcess:ev];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[self sendClipboardEvent];
|
||||||
};
|
};
|
||||||
|
|
||||||
- (void)eventProcess:(NSEvent *)ev {
|
- (void)eventProcess:(NSEvent *)ev {
|
||||||
|
|
@ -816,6 +832,39 @@ static CGPoint pointFlip(CGPoint point) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)sendClipboardEvent {
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
|
||||||
|
NSArray *items = @[
|
||||||
|
@"public.utf8-plain-text",
|
||||||
|
@"public.utf16-external-plain-text",
|
||||||
|
@"com.apple.traditional-mac-plain-text",
|
||||||
|
];
|
||||||
|
MwLL this = self->handle.pointer;
|
||||||
|
|
||||||
|
if ([pasteboard canReadItemWithDataConformingToTypes:items]) {
|
||||||
|
char *data = NULL;
|
||||||
|
size_t size = 0;
|
||||||
|
for (NSPasteboardItem *item in [pasteboard pasteboardItems]) {
|
||||||
|
for (NSString *it in items) {
|
||||||
|
NSString *itemData = [item stringForType:(NSString *)it];
|
||||||
|
if (itemData != NULL) {
|
||||||
|
if (strHash != 0 && strHash != [itemData hash]) {
|
||||||
|
char *text = malloc([itemData length]);
|
||||||
|
strncpy(text, [itemData UTF8String], [itemData length]);
|
||||||
|
MwLLDispatch(this, clipboard, text);
|
||||||
|
printf("%s -> %p\n", text, this);
|
||||||
|
free(text);
|
||||||
|
}
|
||||||
|
strHash = [itemData hash];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[pool release];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setTitle:(const char *)title {
|
- (void)setTitle:(const char *)title {
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
[self->window
|
[self->window
|
||||||
|
|
@ -882,6 +931,11 @@ static CGPoint pointFlip(CGPoint point) {
|
||||||
* until 10.13.2 so I need to do this manually */
|
* until 10.13.2 so I need to do this manually */
|
||||||
};
|
};
|
||||||
- (void)setClipboard:(const char *)text {
|
- (void)setClipboard:(const char *)text {
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
|
||||||
|
[pasteboard declareTypes:@[ NSPasteboardTypeString ] owner:nil];
|
||||||
|
[pasteboard setString:@(text) forType:NSPasteboardTypeString];
|
||||||
|
[pool release];
|
||||||
};
|
};
|
||||||
- (void)getClipboard {
|
- (void)getClipboard {
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue