fixes window dragging when window was not focused

This commit is contained in:
Gellert Hegyi 2025-01-17 13:23:37 +01:00
parent 5d6878e308
commit 8695aaa477
2 changed files with 15 additions and 1 deletions

View file

@ -27,15 +27,22 @@ NSView* viewUnderneathPoint(NSView* self, NSPoint point) {
}
NSView* swizzledHitTest(id obj, SEL sel, NSPoint point) {
NSView* view = obj;
NSView* originalReturn =
((NSView*(*) (id, SEL, NSPoint))g_originalHitTest)(obj, sel, point);
// Do the original implementation when window is not focused, so window can be
// dragged immediately even, when not focused.
if (!view.window.isKeyWindow) {
return originalReturn;
}
objc_setAssociatedObject(obj,
&kIsDraggableKey,
@(originalReturn == nil),
OBJC_ASSOCIATION_COPY_NONATOMIC);
NSView* viewUnderPoint = viewUnderneathPoint(obj, point);
NSView* viewUnderPoint = viewUnderneathPoint(view, point);
return [viewUnderPoint hitTest:point];
}

View file

@ -31,11 +31,14 @@
<input type="text" placeholder="type..." />
<button id="foo">cannot be clicked</button>
<button id="dbl2">can be doubleclicked</button>
</div>
<input type="text" placeholder="type..." />
<button id="bar">can be clicked</button>
<button id="dbl">can be doubleclicked</button>
<script>
window.onload = () => {
@ -43,6 +46,8 @@
const foo = document.getElementById('foo');
const bar = document.getElementById('bar');
const dbl = document.getElementById('dbl');
const dbl2 = document.getElementById('dbl2');
const span = document.querySelector('span');
const inc = () => {
@ -51,6 +56,8 @@
foo.addEventListener('click', inc);
bar.addEventListener('click', inc);
dbl.addEventListener('dblclick', inc);
dbl2.addEventListener('dblclick', inc);
}
</script>
</body>