mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
internal/ui: bug fix: initialMonitorByOS could return nil on macOS
initialMonitorByOS could return nil when a cursor was at an extreme position like the bottom of the display. Apparently, a cursor position could take an inclusive range of the monitor size. This change fixes this issue by fixing the comparison. Even if initialMonitorByOS returns nil, a fallback primary monitor should be used, so this is not a critical issue. Updates #2794
This commit is contained in:
parent
14a2c703df
commit
03d6811a65
@ -99,13 +99,15 @@ func (m *monitors) monitorFromID(id int) *Monitor {
|
||||
|
||||
// monitorFromPosition returns a monitor for the given position (x, y),
|
||||
// or returns nil if monitor is not found.
|
||||
// The position is in GLFW pixels.
|
||||
func (m *monitors) monitorFromPosition(x, y int) *Monitor {
|
||||
m.m.Lock()
|
||||
defer m.m.Unlock()
|
||||
|
||||
for _, m := range m.monitors {
|
||||
// Use an inclusive range. On macOS, the cursor position can take this range (#2794).
|
||||
// TODO: Fix incorrectness in the cases of https://github.com/glfw/glfw/issues/1961.
|
||||
if m.x <= x && x < m.x+m.videoMode.Width && m.y <= y && y < m.y+m.videoMode.Height {
|
||||
if m.x <= x && x <= m.x+m.videoMode.Width && m.y <= y && y <= m.y+m.videoMode.Height {
|
||||
return m
|
||||
}
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ var (
|
||||
sel_windowWillExitFullScreen = objc.RegisterName("windowWillExitFullScreen:")
|
||||
)
|
||||
|
||||
func currentMouseLocationInDIP() (x, y int) {
|
||||
func currentMouseLocation() (x, y int) {
|
||||
sig := cocoa.NSMethodSignature_signatureWithObjCTypes("{NSPoint=dd}@:")
|
||||
inv := cocoa.NSInvocation_invocationWithMethodSignature(sig)
|
||||
inv.SetTarget(objc.ID(class_NSEvent))
|
||||
@ -248,8 +248,6 @@ func currentMouseLocationInDIP() (x, y int) {
|
||||
var point cocoa.NSPoint
|
||||
inv.GetReturnValue(unsafe.Pointer(&point))
|
||||
|
||||
// On macOS, the unit of GLFW (OS-native) pixels' scale and device-independent pixels's scale are the same.
|
||||
// The monitor sizes' scales are also the same.
|
||||
x, y = int(point.X), int(point.Y)
|
||||
|
||||
// On macOS, the Y axis is upward. Adjust the Y position (#807, #2794).
|
||||
@ -260,17 +258,10 @@ func currentMouseLocationInDIP() (x, y int) {
|
||||
}
|
||||
|
||||
func initialMonitorByOS() (*Monitor, error) {
|
||||
x, y := currentMouseLocationInDIP()
|
||||
x, y := currentMouseLocation()
|
||||
|
||||
// Find the monitor including the cursor.
|
||||
for _, m := range theMonitors.append(nil) {
|
||||
w, h := m.videoMode.Width, m.videoMode.Height
|
||||
if x >= m.x && x < m.x+w && y >= m.y && y < m.y+h {
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
return theMonitors.monitorFromPosition(x, y), nil
|
||||
}
|
||||
|
||||
func monitorFromWindowByOS(w *glfw.Window) *Monitor {
|
||||
|
@ -145,14 +145,7 @@ func initialMonitorByOS() (*Monitor, error) {
|
||||
x, y := int(rep.RootX), int(rep.RootY)
|
||||
|
||||
// Find the monitor including the cursor.
|
||||
for _, m := range theMonitors.append(nil) {
|
||||
w, h := m.videoMode.Width, m.videoMode.Height
|
||||
if x >= m.x && x < m.x+w && y >= m.y && y < m.y+h {
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
return theMonitors.monitorFromPosition(x, y), nil
|
||||
}
|
||||
|
||||
func monitorFromWindowByOS(_ *glfw.Window) *Monitor {
|
||||
|
@ -136,14 +136,7 @@ func initialMonitorByOS() (*Monitor, error) {
|
||||
x, y := int(px), int(py)
|
||||
|
||||
// Find the monitor including the cursor.
|
||||
for _, m := range theMonitors.append(nil) {
|
||||
w, h := m.videoMode.Width, m.videoMode.Height
|
||||
if x >= m.x && x < m.x+w && y >= m.y && y < m.y+h {
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
return theMonitors.monitorFromPosition(x, y), nil
|
||||
}
|
||||
|
||||
func monitorFromWindowByOS(w *glfw.Window) *Monitor {
|
||||
|
Loading…
Reference in New Issue
Block a user