Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy and paste backend for Cocoa. #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion cocoa/cocoa_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ func init() {
}
wde.BackendRun = Run
wde.BackendStop = Stop
wde.BackendGetClipboardText = GetClipboardText
wde.BackendSetClipboardText = SetClipboardText

runtime.LockOSThread()
C.initMacDraw()
SetAppName("go")


// I'll uncomment these once the 'super' key glitch is fixed
// wde.PasteChord = "super+v"
// wde.CopyChord = "super+c"
// wde.CutChord = "super+x"
}

func SetAppName(name string) {
Expand Down Expand Up @@ -161,6 +168,14 @@ func (w *Window) Close() (err error) {
return
}

func GetClipboardText() string {
return C.GoString(C.getClipboardText())
}

func SetClipboardText(text string) {
C.setClipboardText(C.CString(text))
}

func Run() {
C.NSAppRun()
}
Expand Down
5 changes: 4 additions & 1 deletion cocoa/framework/gomacdraw/gmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ void flushWindowScreen(GMDWindow gmdw);
void setScreenPixel(GMDImage screen, int x, int y, int r, int g, int b, int a);
void getScreenSize(GMDImage screen, int* width, int* height);

void setScreenData(GMDImage screen, void* data);
void setScreenData(GMDImage screen, void* data);

const char* getClipboardText();
void setClipboardText(const char* text);
14 changes: 14 additions & 0 deletions cocoa/framework/gomacdraw/gmd.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,17 @@ void getScreenSize(GMDImage screen, int* width, int* height) {
*height = size.height;
[pool release];
}

const char* getClipboardText() {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[pool release];
return [[[NSPasteboard generalPasteboard] stringForType:NSPasteboardTypeString] UTF8String];
}

void setClipboardText(const char* text) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
[pasteBoard clearContents];
[pasteBoard setString:[[NSString alloc] initWithUTF8String:text] forType:NSPasteboardTypeString];
[pool release];
}
4 changes: 4 additions & 0 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ const (
KeyCapsLock = "caps"
)

var PasteChord = "control+v"
var CopyChord = "control+c"
var CutChord = "control+x"

var chordPrecedence = []string{
"super",
"shift",
Expand Down
16 changes: 16 additions & 0 deletions wde.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,19 @@ func NewWindow(width, height int) (Window, error) {
var BackendNewWindow = func(width, height int) (Window, error) {
panic("no wde backend imported")
}

func GetClipboardText() string {
return BackendGetClipboardText()
}

var BackendGetClipboardText = func() string {
panic("no wde backend imported")
}

func SetClipboardText(text string) {
BackendSetClipboardText(text)
}

var BackendSetClipboardText = func(text string) {
panic("no wde backend imported")
}