From 3cdb7fb3a522eeb450444875c3a34f554fb8966a Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 4 Oct 2026 22:45:25 +0800 Subject: [PATCH] =?UTF-8?q?gui:=20a=20Command-click=20on=20the=20Mac's=20m?= =?UTF-8?q?enu=20bar=20icon=20is=20left=20to=20the=20system,=20which=20dra?= =?UTF-8?q?gs=20the=20icon=20with=20it=20(#792,=20BennettChina)=20?= =?UTF-8?q?=E2=80=94=20Hidden=20Bar's=20users=20move=20icons=20with=20Comm?= =?UTF-8?q?and-drag,=20and=20magpie's=20icon=20opened=20its=20panel=20inst?= =?UTF-8?q?ead.=20The=20tray's=20click=20handler=20now=20reads=20the=20hel?= =?UTF-8?q?d=20modifiers=20([NSEvent=20modifierFlags])=20and=20does=20noth?= =?UTF-8?q?ing=20when=20Command=20is=20down;=20other=20systems=20are=20unc?= =?UTF-8?q?hanged.=20go=20vet,=20builds=20(darwin=20with=20the=20GUI,=20GO?= =?UTF-8?q?OS=3Dlinux=20nogui,=20GOOS=3Dwindows)=20and=20go=20test=20-tags?= =?UTF-8?q?=20nogui=20./internal/gui/=20under=20a=20temp=20HOME=20pass;=20?= =?UTF-8?q?the=20drag=20itself=20wasn't=20exercised=20here=20(it=20would?= =?UTF-8?q?=20move=20icons=20in=20the=20owner's=20live=20menu=20bar).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/app.go | 3 +++ internal/gui/cmdheld_darwin.go | 19 +++++++++++++++++++ internal/gui/cmdheld_other.go | 6 ++++++ 3 files changed, 28 insertions(+) create mode 100644 internal/gui/cmdheld_darwin.go create mode 100644 internal/gui/cmdheld_other.go diff --git a/internal/gui/app.go b/internal/gui/app.go index 53870fee..886feb1f 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -438,6 +438,9 @@ func Run(version string, showMain bool, link string) error { // the quick panel by the icon, or the main window if the user would // rather (Settings → Tray icon) h.tray.OnClick(func() { + if cmdClick() { + return // Command-drag moves the icon; the system handles it + } if runtime.GOOS == "darwin" { go h.flap() } diff --git a/internal/gui/cmdheld_darwin.go b/internal/gui/cmdheld_darwin.go new file mode 100644 index 00000000..f628d014 --- /dev/null +++ b/internal/gui/cmdheld_darwin.go @@ -0,0 +1,19 @@ +//go:build !nogui + +package gui + +/* +#cgo CFLAGS: -x objective-c +#cgo LDFLAGS: -framework Cocoa +#import + +static int commandHeld(void) { + return ([NSEvent modifierFlags] & NSEventModifierFlagCommand) != 0; +} +*/ +import "C" + +// cmdClick says whether Command was held as the icon was clicked: the Mac +// drags a menu bar icon with Command, so the click is the system's, not +// magpie's (BennettChina, #792: Hidden Bar's users move icons so). +func cmdClick() bool { return C.commandHeld() != 0 } diff --git a/internal/gui/cmdheld_other.go b/internal/gui/cmdheld_other.go new file mode 100644 index 00000000..d5ca3b80 --- /dev/null +++ b/internal/gui/cmdheld_other.go @@ -0,0 +1,6 @@ +//go:build !darwin && !nogui + +package gui + +// cmdClick: only the Mac drags its tray icons with a modifier. +func cmdClick() bool { return false }