Skip to content

Commit dc76e19

Browse files
committed
Window start drag bugfix for windows that moved outside drag events
1 parent c8031e9 commit dc76e19

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

WobblyWindows/Warp.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ extension NSScreen {
148148
}
149149

150150
@objc public func startDrag(at point: CGPoint) {
151+
self.alreadySetFrame = false
151152
let distances = particles
152153
.map { $0.position.distanceTo(point: point) }
153154

@@ -183,7 +184,9 @@ extension NSScreen {
183184
}
184185
}
185186

187+
var alreadySetFrame = false
186188
@objc public func endDrag() {
189+
if alreadySetFrame { return }
187190
let idx = GRID_WIDTH * (GRID_HEIGHT - 1) + GRID_HEIGHT * (GRID_WIDTH - 1)
188191
springs.removeLast(springs.count - idx)
189192
if particles.indices.contains(GRID_WIDTH * GRID_HEIGHT) { particles.remove(at: GRID_WIDTH * GRID_HEIGHT) }
@@ -208,6 +211,7 @@ extension NSScreen {
208211
)
209212

210213
self.window.setFrameDirty(frame)
214+
self.alreadySetFrame = true
211215

212216
self.window.styleMask.insert(NSWindow.StyleMask.resizable)
213217
} else {

WobblyWindows/WindowAdditions.mm

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ + (void) willMove:(id) notification {
6262
// NSLog(@"willMove");
6363
NSWindow* window = (NSWindow*)[(NSNotification*)notification object];
6464

65-
// Fallback for whatsapp and IDEA
66-
if (window.warp == NULL) {
67-
window.warp = [[Warp alloc] initWithWindow:window];
68-
}
65+
//Reinit window since it may have moved in different method
66+
window.warp = [[Warp alloc] initWithWindow:window];
6967

7068
[window.warp startDragAt: NSEvent.mouseLocation];
7169
[window windowMoves: notification];
@@ -78,9 +76,9 @@ - (void) windowMoves:(id) notification {
7876
NSWindow* window = (NSWindow*)[(NSNotification*)notification object];
7977
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0f / 60.0f) target:self selector:@selector(windowMoved:) userInfo:window repeats:YES];
8078

81-
// if (monitor != NULL) { // only disable mouseup monitor when we move a window again, because sometimes the first event does not fully trigger.
82-
// [NSEvent removeMonitor:monitor];
83-
// }
79+
if (monitor != NULL) { // only disable mouseup monitor when we move a window again, because sometimes the first event does not fully trigger.
80+
[NSEvent removeMonitor:monitor];
81+
}
8482
monitor = [NSEvent addGlobalMonitorForEventsMatchingMask:NSEventMaskLeftMouseUp | NSEventMaskRightMouseUp handler:^(NSEvent *event) {
8583
[window moveStopped];
8684
}];

0 commit comments

Comments
 (0)