├── .gitignore ├── gogoa.go ├── g_application.h ├── support └── images │ └── gogoa_run.png ├── g_window.h ├── g_application.m ├── application.go ├── window.go ├── g_window.m ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | _obj 3 | 4 | -------------------------------------------------------------------------------- /gogoa.go: -------------------------------------------------------------------------------- 1 | package gogoa 2 | 3 | // #cgo CFLAGS: -x objective-c 4 | // #cgo LDFLAGS: -framework Cocoa 5 | -------------------------------------------------------------------------------- /g_application.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | void* SharedApplication(void); 4 | 5 | void Run(void *app); 6 | -------------------------------------------------------------------------------- /support/images/gogoa_run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alediaferia/gogoa/HEAD/support/images/gogoa_run.png -------------------------------------------------------------------------------- /g_window.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void *NewWindow(int x, int y, int width, int height); 4 | void MakeKeyAndOrderFront(void *); 5 | void SetTitle(void *, char* title); 6 | -------------------------------------------------------------------------------- /g_application.m: -------------------------------------------------------------------------------- 1 | #import "g_application.h" 2 | 3 | void* 4 | SharedApplication(void) { 5 | return [NSApplication sharedApplication]; 6 | } 7 | 8 | void 9 | Run(void *app) { 10 | @autoreleasepool { 11 | NSApplication* a = (NSApplication*)app; 12 | [a setActivationPolicy:NSApplicationActivationPolicyRegular]; 13 | [a run]; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /application.go: -------------------------------------------------------------------------------- 1 | package gogoa 2 | 3 | // #cgo CFLAGS: -x objective-c 4 | // #cgo LDFLAGS: -framework Cocoa 5 | //#include "g_application.h" 6 | import "C" 7 | import "unsafe" 8 | 9 | 10 | type Application struct { 11 | ptr unsafe.Pointer 12 | } 13 | 14 | func SharedApplication() (*Application) { 15 | app := new(Application) 16 | app.ptr = C.SharedApplication() 17 | 18 | return app 19 | } 20 | 21 | func (this *Application) Run() { 22 | C.Run(this.ptr) 23 | } 24 | -------------------------------------------------------------------------------- /window.go: -------------------------------------------------------------------------------- 1 | package gogoa 2 | 3 | // #cgo CFLAGS: -x objective-c 4 | // #cgo LDFLAGS: -framework Cocoa 5 | //#include "g_window.h" 6 | import "C" 7 | import "unsafe" 8 | 9 | type Window struct { 10 | ptr unsafe.Pointer 11 | } 12 | 13 | func NewWindow(x, y, width, height int) (*Window) { 14 | w := new(Window) 15 | w.ptr = C.NewWindow(C.int(x), C.int(y), C.int(width), C.int(height)) 16 | 17 | return w 18 | } 19 | 20 | func (self *Window) MakeKeyAndOrderFront() { 21 | C.MakeKeyAndOrderFront(self.ptr) 22 | } 23 | 24 | func (self *Window) SetTitle(title string) { 25 | C.SetTitle(self.ptr, C.CString(title)) 26 | } 27 | -------------------------------------------------------------------------------- /g_window.m: -------------------------------------------------------------------------------- 1 | #include "g_window.h" 2 | 3 | #include 4 | 5 | void *NewWindow(int x, int y, int width, int height) 6 | { 7 | NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(x, y, width, height) 8 | styleMask:NSTitledWindowMask 9 | backing:NSBackingStoreBuffered defer:NO]; 10 | 11 | return window; 12 | } 13 | 14 | void MakeKeyAndOrderFront(void *self) { 15 | NSWindow *window = self; 16 | [window makeKeyAndOrderFront:nil]; 17 | } 18 | 19 | void SetTitle(void *self, char *title) { 20 | NSWindow *window = self; 21 | NSString *nsTitle = [NSString stringWithUTF8String:title]; 22 | 23 | [window setTitle:nsTitle]; 24 | free(title); 25 | } 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Alessandro Diaferia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gogoa 2 | Cocoa bindings for Go 3 | 4 | Why? 5 | --- 6 | Just for fun and curiosity. I was wondering how would it take to show a Cocoa Window through Go and here you Go :smile: 7 | 8 | I don't know if this project will ever be useful and I'm rather sure this won't be useful anytime if it's just me coding it so I welcome contributions. They would make me feel I'm not alone :p 9 | 10 | Getting started 11 | --------------- 12 | 13 | The fastest way to try this project is running a Cocoa window. Actually this is the only thing you can do with it currently. 14 | 15 | ```go 16 | package main 17 | 18 | import ( 19 | "github.com/alediaferia/gogoa" 20 | ) 21 | 22 | func main() { 23 | app := gogoa.SharedApplication() 24 | window := gogoa.NewWindow(0, 0, 200, 200) 25 | window.SetTitle("Gogoga!") 26 | window.MakeKeyAndOrderFront() 27 | 28 | app.Run() 29 | } 30 | ``` 31 | 32 | Screenshots 33 | ----------- 34 | ![Gogoa runs](/support/images/gogoa_run.png?raw=true "Gogoa runs!") 35 | 36 | Contribute 37 | ---------- 38 | I would really love other people interested in this to help me build something useful. 39 | Please, feel free to push whatever pull request comes to your mind. Also, I'd be happy to discuss the next steps with you. 40 | 41 | License 42 | ------- 43 | This codebase is currently licensed under MIT License you can find [here](LICENSE) 44 | 45 | Copyright (c) Alessandro Diaferia 46 | --------------------------------------------------------------------------------