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

Apple silicon support #3

Merged
merged 4 commits into from
Jan 1, 2022
Merged
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
43 changes: 4 additions & 39 deletions app_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,18 @@
package unison

import (
"strings"
"time"

"github.com/progrium/macdriver/objc"
"github.com/richardwilkes/unison/internal/ns"
)

func platformEarlyInit() {
if openURLsCallback != nil {
appDelegate := ns.App().GetDelegate()
cls := objc.NewClass("UnisonAppDelegate", "NSObject")
cls.AddMethod("applicationShouldTerminate:", func(_, p1 objc.Object) uint {
return uint(appDelegate.Send("applicationShouldTerminte:", p1).Uint())
})
cls.AddMethod("applicationDidChangeScreenParameters:", func(_, p1 objc.Object) {
appDelegate.Send("applicationDidChangeScreenParameters:", p1)
})
cls.AddMethod("applicationWillFinishLaunching:", func(_, p1 objc.Object) {
appDelegate.Send("applicationWillFinishLaunching:", p1)
})
cls.AddMethod("applicationDidFinishLaunching:", func(_, p1 objc.Object) {
appDelegate.Send("applicationDidFinishLaunching:", p1)
})
cls.AddMethod("applicationDidHide:", func(_, p1 objc.Object) {
appDelegate.Send("applicationDidHide:", p1)
})
// All of the methods above this point are just pass-throughs to glfw. If glfw adds more methods, corresponding
// additions should be made here.
cls.AddMethod("application:openURLs:", func(_, app, urls objc.Object) {
if data := ns.URLArrayToStringSlice(ns.Array{Object: urls}); len(data) != 0 {
openURLsCallback(data)
}
})
ns.App().SetDelegate(cls.Alloc().Init())
}
ns.InstallAppDelegate(openURLsCallback)
}

func platformLateInit() {
cls := objc.NewClass("ThemeDelegate", "NSObject")
cls.AddMethod("themeChanged:", func(objc.Object) { themeChanged() })
delegate := cls.Alloc().Init()
def := ns.DefaultCenter()
selector := objc.Sel("themeChanged:")
def.AddObserver(delegate, selector, "AppleInterfaceThemeChangedNotification")
def.AddObserver(delegate, selector, "AppleColorPreferencesChangedNotification")

ns.App().SetActivationPolicy(ns.ActivationPolicyRegular)
ns.InstallSystemThemeChangedCallback(themeChanged)
ns.SetActivationPolicy(ns.ActivationPolicyRegular)
}

func platformBeep() {
Expand All @@ -68,7 +33,7 @@ func platformIsDarkModeTrackingPossible() bool {
}

func platformIsDarkModeEnabled() bool {
return strings.Contains(strings.ToLower(ns.StandardUserDefaults().StringForKey("AppleInterfaceStyle")), "dark")
return ns.IsDarkModeEnabled()
}

func platformDoubleClickInterval() time.Duration {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.17
require (
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211213063430-748e38ca8aec
github.com/progrium/macdriver v0.2.0
github.com/richardwilkes/toolbox v1.54.0
github.com/stretchr/testify v1.7.0
golang.org/x/image v0.0.0-20211028202545-6944b10bf410
Expand Down
286 changes: 0 additions & 286 deletions go.sum

Large diffs are not rendered by default.

81 changes: 0 additions & 81 deletions internal/ns/application_darwin.go

This file was deleted.

32 changes: 0 additions & 32 deletions internal/ns/array_darwin.go

This file was deleted.

21 changes: 0 additions & 21 deletions internal/ns/beep_darwin.go

This file was deleted.

67 changes: 67 additions & 0 deletions internal/ns/callbacks_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright ©2022 by Richard A. Wilkes. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.

package ns

/*
#import <Cocoa/Cocoa.h>

typedef CFTypeRef NSMenuRef;
typedef CFTypeRef NSMenuItemRef;
*/
import "C"

var (
menuUpdaters = make(map[Menu]func(Menu))
menuItemValidators = make(map[MenuItem]func(item MenuItem) bool)
menuItemHandlers = make(map[MenuItem]func(item MenuItem))
openURLsCallback func([]string)
systemThemeChangedCallback func()
)

//export updateMenuCallback
func updateMenuCallback(m C.NSMenuRef) {
menu := Menu(m)
if updater, ok := menuUpdaters[menu]; ok && updater != nil {
updater(menu)
}
}

//export menuItemValidateCallback
func menuItemValidateCallback(mi C.NSMenuItemRef) bool {
item := MenuItem(mi)
if validator, ok := menuItemValidators[item]; ok && validator != nil {
return validator(item)
}
return true
}

//export menuItemHandleCallback
func menuItemHandleCallback(mi C.NSMenuItemRef) {
item := MenuItem(mi)
if handler, ok := menuItemHandlers[item]; ok && handler != nil {
handler(item)
}
}

//export appOpenURLsCallback
func appOpenURLsCallback(a C.CFArrayRef) {
if openURLsCallback != nil {
if urls := Array(a).ArrayOfURLToStringSlice(); len(urls) > 0 {
openURLsCallback(urls)
}
}
}

//export themeChangedCallback
func themeChangedCallback() {
if systemThemeChangedCallback != nil {
systemThemeChangedCallback()
}
}
31 changes: 0 additions & 31 deletions internal/ns/distributed_notification_center_darwin.go

This file was deleted.

23 changes: 0 additions & 23 deletions internal/ns/event_darwin.go

This file was deleted.

59 changes: 0 additions & 59 deletions internal/ns/menu_darwin.go

This file was deleted.

Loading