Now THAT is an idea. As I mentioned I tried setting movable to false on MouseDown, but its too late. Using MouseMove to turn it off before the user even clicks is probably the simplest way to solve this problem.
[quote=494272:@Kevin Gale]Here’s some very rough code i’ve just hacked up that should work on macOS 10.11 and later.
NOTE. You will need to tidy up the events listed during the initialisation and in the event handler.
Class Window1
Inherits Window
Window1.Open:
Sub Open()
'prevent window dragging by default
Declare Sub setMovable Lib "AppKit" Selector "setMovable:" (windowHandle As Integer, enabled As Boolean)
setMovable(Self.Handle, False)
'attach our event monitor listener so that we can enable window dragging in specific areas
Self.mCocoaEventMonitorObj_ = New cCocoaWindowEventMonitor
Call Self.mCocoaEventMonitorObj_.addLocalMonitorForEventsMatchingMask(Bitwise.BitOr(NSEventMBS.NSLeftMouseDown Mask, NSEventMBS.NSLeftMouseDraggedMask, NSEventMBS.NSLeftMouseUp, NSEventMBS.NSRightMouseDownMask, NSEventMBS.NSRightMouseDraggedMask, NSEventMBS.NSRightMouseUp, NSEventMBS.NSOtherMouseDownMask, NSEventMBS.NSOtherMouseDraggedMask, NSEventMBS.NSOtherMouseUp))
End Sub
Private mCocoaEventMonitorObj_ As cCocoaWindowEventMonitor
End Class
Class cCocoaWindowEventMonitor
Inherits NSEventMonitorMBS
[code]
cCocoaWindowEventMonitor.LocalEvent:
Function LocalEvent(e as NSEventMBS) As NSEventMBS
Declare sub performWindowDragWithEvent Lib “AppKit” Selector “performWindowDragWithEvent:” (windowHandle As Integer, eventHandle As Integer)
Dim userWindowClicked As Window
Dim count As Int32
Dim i As Int32
Dim clickY As Int32
'determine if we have clicked in a user window (ie: not an alert)
userWindowClicked = Nil
count = WindowCount - 1
For i = 0 To count
If Window(i).NSWindowMBS = e.window Then
userWindowClicked = Window(i)
Exit For
End If
Next
'continue if we have clicked in a user window
If userWindowClicked <> Nil Then
If (e.type = NSEventMBS.NSLeftMouseDown) Or (e.type = NSEventMBS.NSRightMouseDown) Or (e.type = NSEventMB S.NSOtherMouseDown) Then
clickY = userWindowClicked.Bounds.Height - e.locationInWindow.Y
If clickY <= (userWindowClicked.Top - userWindowClicked.Bounds.Top) Then
'clicked in the title bar
If e.locationInWindow.x > 200 Then
'clicked in an area we allow dragging so start the drag
performWindowDragWithEvent(e.window.Handle, e.Handle)
End If
End If
End If
End If
'return the event unmodified
Return e
End Function
End Class[/code][/quote]
This is also a clever idea. I was approaching the problem backwards, trying to stop the click when necessary. My concern with this code is it assumes dragging is the only thing possible from the titlebar. Things like a double click to minimize based on system settings would end up being blocked. So I was going to take the idea and set Movable to false in the mouse down from NSEventMonitor, but I have a feeling using Xojos MouseMove will work and be simpler. Thank you though, it gives me another possibility if the mouse move idea doesnt work.