Skip to content

Commit

Permalink
Merge pull request fyne-io#4348 from gcottom/browser-shortcut-fix-macos
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz authored Dec 25, 2023
2 parents 7f1274f + 6b611d7 commit d0b6d2d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/fredbi/uri v1.0.0
github.com/fsnotify/fsnotify v1.7.0
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504
github.com/fyne-io/glfw-js v0.0.0-20220517201726-bebc2019cd33
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20231223183121-56fa3ac82ce7
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe h1:A/wiwvQ0CAjPkuJyt
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe/go.mod h1:d4clgH0/GrRwWjRzJJQXxT/h1TyuNSfF/X64zb/3Ggg=
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 h1:+31CdF/okdokeFNoy9L/2PccG3JFidQT3ev64/r4pYU=
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504/go.mod h1:gLRWYfYnMA9TONeppRSikMdXlHQ97xVsPojddUv3b/E=
github.com/fyne-io/glfw-js v0.0.0-20220517201726-bebc2019cd33 h1:0Ayg0/do/sqX2R7NonoLZvWxGrd9utTVf3A0QvCbC88=
github.com/fyne-io/glfw-js v0.0.0-20220517201726-bebc2019cd33/go.mod h1:gLRWYfYnMA9TONeppRSikMdXlHQ97xVsPojddUv3b/E=
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 h1:hnLq+55b7Zh7/2IRzWCpiTcAvjv/P8ERF+N7+xXbZhk=
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2/go.mod h1:eO7W361vmlPOrykIg+Rsh1SZ3tQBaOsfzZhsIOb/Lm0=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down
15 changes: 15 additions & 0 deletions internal/driver/glfw/shortcuts_js.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build js && !wasm
// +build js,!wasm

package glfw

import (
"strings"

"github.com/gopherjs/gopherjs/js"
)

// Checks if running on Mac OSX
func isMacOSRuntime() bool {
return strings.Contains(strings.ToLower(js.Global.Get("window").Get("navigator").Get("platform").String()), "mac")
}
11 changes: 11 additions & 0 deletions internal/driver/glfw/shortcuts_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !js && !wasm
// +build !js,!wasm

package glfw

import "runtime"

// Checks if running on Mac OSX
func isMacOSRuntime() bool {
return runtime.GOOS == "darwin"
}
15 changes: 15 additions & 0 deletions internal/driver/glfw/shortcuts_wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build js && wasm
// +build js,wasm

package glfw

import (
"strings"

"syscall/js"
)

// Checks if running on Mac OSX
func isMacOSRuntime() bool {
return strings.Contains(strings.ToLower(js.Global().Get("window").Get("navigator").Get("platform").String()), "mac")
}
2 changes: 1 addition & 1 deletion internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ func (w *window) processFocused(focus bool) {
func (w *window) triggersShortcut(localizedKeyName fyne.KeyName, key fyne.KeyName, modifier fyne.KeyModifier) bool {
var shortcut fyne.Shortcut
ctrlMod := fyne.KeyModifierControl
if runtime.GOOS == "darwin" {
if isMacOSRuntime() {
ctrlMod = fyne.KeyModifierSuper
}
// User pressing physical keys Ctrl+V while using a Russian (or any non-ASCII) keyboard layout
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/glfw/window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@ func TestWindow_ClipboardCopy_DisabledEntry(t *testing.T) {
assert.Equal(t, "Testing", e.SelectedText())

ctrlMod := glfw.ModControl
if runtime.GOOS == "darwin" {
if isMacOSRuntime() {
ctrlMod = glfw.ModSuper
}
w.keyPressed(nil, glfw.KeyC, 0, glfw.Repeat, ctrlMod)
Expand Down

0 comments on commit d0b6d2d

Please sign in to comment.