forked from alexflint/gallium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request alexflint#35 from alexflint/cgo_interfaces
Add interface for getting native window handle
- Loading branch information
Showing
6 changed files
with
127 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ out/ | |
# Vim | ||
/*.swp | ||
*.app | ||
|
||
/build/ |
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
Git LFS file not shown
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,43 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"runtime" | ||
|
||
"github.com/alexflint/gallium" | ||
) | ||
|
||
/* | ||
#cgo CFLAGS: -x objective-c | ||
#cgo CFLAGS: -framework Cocoa | ||
#cgo LDFLAGS: -framework Cocoa | ||
#include <Cocoa/Cocoa.h> | ||
#include <dispatch/dispatch.h> | ||
void SetAlpha(void* window, float alpha) { | ||
// Cocoa requires that all UI operations happen on the main thread. Since | ||
// gallium.Loop will have initiated the Cocoa event loop, we can can use | ||
// dispatch_async to run code on the main thread. | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
NSWindow* w = (NSWindow*)window; | ||
[w setAlphaValue:alpha]; | ||
}); | ||
} | ||
*/ | ||
import "C" | ||
|
||
func onReady(ui *gallium.App) { | ||
window, err := ui.OpenWindow("http://example.com/", gallium.FramedWindow) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
C.SetAlpha(window.NativeWindow(), 0.5) | ||
} | ||
|
||
func main() { | ||
runtime.LockOSThread() | ||
gallium.RedirectStdoutStderr(os.ExpandEnv("$HOME/Library/Logs/Gallium.log")) | ||
gallium.Loop(os.Args, onReady) | ||
} |