fix(mac): run event queue events in autoreleasepool

This commit is contained in:
Luiz Sardinha 2026-09-06 17:10:54 +02:00 committed by Chris Rizzitello
parent 71929a3418
commit ce2f948c29
4 changed files with 66 additions and 11 deletions

View file

@ -1,9 +1,17 @@
# SPDX-FileCopyrightText: (C) 2026 Deskflow Developers
# SPDX-FileCopyrightText: (C) 2024 Chris Rizzitello <sithlord48@gmail.com> # SPDX-FileCopyrightText: (C) 2024 Chris Rizzitello <sithlord48@gmail.com>
# SPDX-FileCopyrightText: (C) 2012 - 2024 Symless Ltd # SPDX-FileCopyrightText: (C) 2012 - 2024 Symless Ltd
# SPDX-FileCopyrightText: (C) 2009 - 2012 Nick Bolton # SPDX-FileCopyrightText: (C) 2009 - 2012 Nick Bolton
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
add_library(base STATIC if(APPLE)
set(PLATFORM_CODE
OSXAutoReleasePool.h
OSXAutoReleasePool.mm
)
endif()
add_library(base STATIC ${PLATFORM_CODE}
BaseException.cpp BaseException.cpp
BaseException.h BaseException.h
DirectionTypes.h DirectionTypes.h

View file

@ -18,6 +18,10 @@
#include <stdexcept> #include <stdexcept>
#if defined(__APPLE__)
#include "base/OSXAutoReleasePool.h"
#endif
// interrupt handler. this just adds a quit event to the queue. // interrupt handler. this just adds a quit event to the queue.
static void interrupt(Arch::ThreadSignal, void *data) static void interrupt(Arch::ThreadSignal, void *data)
{ {
@ -166,16 +170,23 @@ bool EventQueue::getEvent(Event &event, double timeout)
bool EventQueue::dispatchEvent(const Event &event) bool EventQueue::dispatchEvent(const Event &event)
{ {
void *target = event.getTarget(); #if defined(__APPLE__)
if (auto typeHandler = getHandler(event.getType(), target); typeHandler.has_value()) { auto dispatch = [&] {
(*typeHandler)(event); #endif
return true; void *target = event.getTarget();
} if (auto typeHandler = getHandler(event.getType(), target); typeHandler.has_value()) {
if (auto anyHandler = getHandler(EventTypes::Unknown, target); anyHandler.has_value()) { (*typeHandler)(event);
(*anyHandler)(event); return true;
return true; }
} if (auto anyHandler = getHandler(EventTypes::Unknown, target); anyHandler.has_value()) {
return false; (*anyHandler)(event);
return true;
}
return false;
#if defined(__APPLE__)
};
return deskflow::runInAutoReleasePool(dispatch);
#endif
} }
void EventQueue::addEvent(Event &&event) void EventQueue::addEvent(Event &&event)

View file

@ -0,0 +1,16 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2026 Deskflow Developers
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#pragma once
#include <functional>
namespace deskflow {
//! Run \p fn inside an Objective-C \c \@autoreleasepool block.
bool runInAutoReleasePool(const std::function<bool()> &fn);
} // namespace deskflow

View file

@ -0,0 +1,20 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2026 Deskflow Developers
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
#import "base/OSXAutoReleasePool.h"
#import <Foundation/Foundation.h>
namespace deskflow {
bool runInAutoReleasePool(const std::function<bool()> &fn)
{
@autoreleasepool {
return fn();
}
}
} // namespace deskflow