fix(mac): run event queue events in autoreleasepool
This commit is contained in:
parent
71929a3418
commit
ce2f948c29
4 changed files with 66 additions and 11 deletions
|
|
@ -1,9 +1,17 @@
|
|||
# SPDX-FileCopyrightText: (C) 2026 Deskflow Developers
|
||||
# SPDX-FileCopyrightText: (C) 2024 Chris Rizzitello <sithlord48@gmail.com>
|
||||
# SPDX-FileCopyrightText: (C) 2012 - 2024 Symless Ltd
|
||||
# SPDX-FileCopyrightText: (C) 2009 - 2012 Nick Bolton
|
||||
# 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.h
|
||||
DirectionTypes.h
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
#include <stdexcept>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include "base/OSXAutoReleasePool.h"
|
||||
#endif
|
||||
|
||||
// interrupt handler. this just adds a quit event to the queue.
|
||||
static void interrupt(Arch::ThreadSignal, void *data)
|
||||
{
|
||||
|
|
@ -166,6 +170,9 @@ bool EventQueue::getEvent(Event &event, double timeout)
|
|||
|
||||
bool EventQueue::dispatchEvent(const Event &event)
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
auto dispatch = [&] {
|
||||
#endif
|
||||
void *target = event.getTarget();
|
||||
if (auto typeHandler = getHandler(event.getType(), target); typeHandler.has_value()) {
|
||||
(*typeHandler)(event);
|
||||
|
|
@ -176,6 +183,10 @@ bool EventQueue::dispatchEvent(const Event &event)
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
#if defined(__APPLE__)
|
||||
};
|
||||
return deskflow::runInAutoReleasePool(dispatch);
|
||||
#endif
|
||||
}
|
||||
|
||||
void EventQueue::addEvent(Event &&event)
|
||||
|
|
|
|||
16
src/lib/base/OSXAutoReleasePool.h
Normal file
16
src/lib/base/OSXAutoReleasePool.h
Normal 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
|
||||
20
src/lib/base/OSXAutoReleasePool.mm
Normal file
20
src/lib/base/OSXAutoReleasePool.mm
Normal 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
|
||||
Loading…
Reference in a new issue