-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cocoa: Import from former external "gocoa" module. (#13)
Contrary to my former belief (as expressed in the README of my gocoa fork[1] and mojbro/gocoa#24), going forward I think that maintaining gocoa as a separate Go module is too much of a burden as I'm holding back lots of small things which would need Spot-specific code right now. Honestly, most of my existing changes should have been broader to make sense for a general purpose Cocoa binding. To make things a bit easier for me, I decided to import the binding completely into Spot as an internal package. I'll be removing anything that I don't seem necessary for Spot but I will keep the original history to correctly attribute the work done by @mojbro, @phaus, @StarHack, and @dim13 [1] https://github.com/roblillack/gocoa?tab=readme-ov-file#what-is-this
- Loading branch information
Showing
68 changed files
with
3,018 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
github.com/pwiecz/go-fltk v0.0.0-20240511142305-990b442ae1ed h1:7/j/4x3KAwuJB9sWdfhi+1UFbv42TyJ4LyUI/GHS+p8= | ||
github.com/pwiecz/go-fltk v0.0.0-20240511142305-990b442ae1ed/go.mod h1:uMK5daOr9p+ba2BPs5QadbfaqqrHR5TGj13yWGsAsmw= | ||
github.com/roblillack/gocoa v0.3.0 h1:ZvEulTbrJHgmeweJJrHZhoGvUzgD/Q54Pmc+cJ5sJyo= | ||
github.com/roblillack/gocoa v0.3.0/go.mod h1:zySUFzLK/KSb3KDT903dTRJ2WPmMBbF3a2u8/39UzMg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Philip Möjbro | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface AppDelegate : NSObject <NSApplicationDelegate> | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#import "appdelegate.h" | ||
#include "_cgo_export.h" | ||
|
||
@implementation AppDelegate | ||
|
||
- (void)dealloc | ||
{ | ||
[super dealloc]; | ||
} | ||
|
||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification | ||
{ | ||
NSLog(@"applicationDidFinishLaunching"); | ||
|
||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; | ||
[NSApp activateIgnoringOtherApps:YES]; | ||
|
||
callOnApplicationDidFinishLaunchingHandler(); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cocoa | ||
|
||
// #cgo CFLAGS: -x objective-c | ||
// #cgo LDFLAGS: -framework Cocoa | ||
// #include "application.h" | ||
import "C" | ||
import "runtime/cgo" | ||
|
||
var appDidFinishLaunchingFunc func() | ||
|
||
// InitApplication initializes the global application instance. Call this before using | ||
// the rest of the cocoa package. | ||
func InitApplication() { | ||
C.InitSharedApplication() | ||
} | ||
|
||
// RunApplication launches the main Cocoa runloop. | ||
func RunApplication() { | ||
C.RunApplication() | ||
} | ||
|
||
// OnApplicationDidFinishLaunching - will be triggered after Application Launch is finished | ||
func OnApplicationDidFinishLaunching(fn func()) { | ||
appDidFinishLaunchingFunc = fn | ||
} | ||
|
||
// TerminateApplication - will be triggered, when the Application terminates | ||
func TerminateApplication() { | ||
C.TerminateApplication() | ||
} | ||
|
||
//export callOnApplicationDidFinishLaunchingHandler | ||
func callOnApplicationDidFinishLaunchingHandler() { | ||
if appDidFinishLaunchingFunc != nil { | ||
appDidFinishLaunchingFunc() | ||
} | ||
} | ||
|
||
//export go_callback | ||
func go_callback(h C.uintptr_t) { | ||
hnd := cgo.Handle(h) | ||
fn := hnd.Value().(func()) | ||
fn() | ||
hnd.Delete() | ||
} | ||
|
||
func RunOnMainLoop(fn func()) { | ||
h := cgo.NewHandle(fn) | ||
C.RunOnMainLoop(C.uintptr_t(h)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <stdint.h> | ||
#import <Cocoa/Cocoa.h> | ||
|
||
void InitSharedApplication(); | ||
void RunApplication(); | ||
void TerminateApplication(); | ||
void RunOnMainLoop(uintptr_t h); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#import "application.h" | ||
#import "appdelegate.h" | ||
#include "_cgo_export.h" | ||
|
||
AppDelegate *gocoa_applicationDelegate = nil; | ||
|
||
// InitSharedApplication calls NSApplication.sharedApplication() which initializes the | ||
// global application instance NSApp. | ||
void InitSharedApplication() { | ||
static bool hasBeenInitialized = false; // false first time function is called | ||
if (hasBeenInitialized) | ||
return; | ||
[NSApplication sharedApplication]; | ||
gocoa_applicationDelegate = [[AppDelegate alloc] init]; | ||
[NSApp setDelegate:gocoa_applicationDelegate]; | ||
hasBeenInitialized = true; | ||
} | ||
|
||
void releaseSharedApplication() { | ||
if (gocoa_applicationDelegate != nil) { | ||
[gocoa_applicationDelegate release]; | ||
} | ||
} | ||
|
||
void RunApplication() { | ||
@autoreleasepool { | ||
[NSApp run]; | ||
releaseSharedApplication(); | ||
} | ||
} | ||
|
||
void TerminateApplication() { | ||
[NSApp terminate:nil]; | ||
} | ||
|
||
extern void go_callback(uintptr_t h); | ||
void RunOnMainLoop(uintptr_t h) { | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
go_callback(h); | ||
}); | ||
} |
Oops, something went wrong.