-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
235 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
#include "X11RunLoop.h" | ||
#include "vstgui/lib/platform/linux/x11platform.h" | ||
#include "base/source/fobject.h" | ||
|
||
namespace VSTGUI { | ||
|
||
RunLoop::RunLoop(Steinberg::FUnknown* runLoop) | ||
: runLoop(runLoop) | ||
{ | ||
} | ||
|
||
RunLoop::~RunLoop() {} | ||
|
||
SharedPointer<RunLoop> RunLoop::get() | ||
{ | ||
return X11::RunLoop::get().cast<VSTGUI::RunLoop>(); | ||
} | ||
|
||
struct RunLoop::EventHandler final : Steinberg::Linux::IEventHandler, public Steinberg::FObject { | ||
X11::IEventHandler* handler { nullptr }; | ||
bool alive { false }; | ||
|
||
void PLUGIN_API onFDIsSet(Steinberg::Linux::FileDescriptor) override | ||
{ | ||
if (alive && handler) | ||
handler->onEvent(); | ||
} | ||
|
||
DELEGATE_REFCOUNT(Steinberg::FObject) | ||
DEFINE_INTERFACES | ||
DEF_INTERFACE(Steinberg::Linux::IEventHandler) | ||
END_DEFINE_INTERFACES(Steinberg::FObject) | ||
}; | ||
|
||
struct RunLoop::TimerHandler final : Steinberg::Linux::ITimerHandler, public Steinberg::FObject { | ||
X11::ITimerHandler* handler { nullptr }; | ||
bool alive { false }; | ||
|
||
void PLUGIN_API onTimer() override | ||
{ | ||
if (alive && handler) | ||
handler->onTimer(); | ||
} | ||
|
||
DELEGATE_REFCOUNT(Steinberg::FObject) | ||
DEFINE_INTERFACES | ||
DEF_INTERFACE(Steinberg::Linux::ITimerHandler) | ||
END_DEFINE_INTERFACES(Steinberg::FObject) | ||
}; | ||
|
||
|
||
void RunLoop::processSomeEvents() | ||
{ | ||
for (size_t i = 0; i < eventHandlers.size(); ++i) { | ||
const auto& eh = eventHandlers[i]; | ||
if (eh->alive && eh->handler) { | ||
eh->handler->onEvent(); | ||
} | ||
} | ||
} | ||
|
||
void RunLoop::cleanupDeadHandlers() | ||
{ | ||
for (size_t i = 0; i < eventHandlers.size(); ++i) { | ||
const auto& eh = eventHandlers[i]; | ||
if (!eh->alive) { | ||
runLoop->unregisterEventHandler(eh); | ||
eventHandlers.erase(eventHandlers.begin() + i--); | ||
} | ||
} | ||
for (size_t i = 0; i < timerHandlers.size(); ++i) { | ||
const auto& th = timerHandlers[i]; | ||
if (!th->alive) { | ||
runLoop->unregisterTimer(th); | ||
timerHandlers.erase(timerHandlers.begin() + i--); | ||
} | ||
} | ||
} | ||
|
||
bool RunLoop::registerEventHandler(int fd, X11::IEventHandler* handler) | ||
{ | ||
if (!runLoop) | ||
return false; | ||
|
||
auto smtgHandler = Steinberg::owned(new EventHandler()); | ||
smtgHandler->handler = handler; | ||
smtgHandler->alive = true; | ||
if (runLoop->registerEventHandler(smtgHandler, fd) == Steinberg::kResultTrue) { | ||
eventHandlers.push_back(smtgHandler); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool RunLoop::unregisterEventHandler(X11::IEventHandler* handler) | ||
{ | ||
if (!runLoop) | ||
return false; | ||
|
||
for (size_t i = 0; i < eventHandlers.size(); ++i) { | ||
const auto& eh = eventHandlers[i]; | ||
if (eh->alive && eh->handler == handler) { | ||
eh->alive = false; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
bool RunLoop::registerTimer(uint64_t interval, X11::ITimerHandler* handler) | ||
{ | ||
if (!runLoop) | ||
return false; | ||
|
||
auto smtgHandler = Steinberg::owned(new TimerHandler()); | ||
smtgHandler->handler = handler; | ||
smtgHandler->alive = true; | ||
if (runLoop->registerTimer(smtgHandler, interval) == Steinberg::kResultTrue) { | ||
timerHandlers.push_back(smtgHandler); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool RunLoop::unregisterTimer(X11::ITimerHandler* handler) | ||
{ | ||
if (!runLoop) | ||
return false; | ||
|
||
for (size_t i = 0; i < timerHandlers.size(); ++i) { | ||
const auto& th = timerHandlers[i]; | ||
if (th->alive && th->handler == handler) { | ||
th->alive = false; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} // namespace VSTGUI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
/* | ||
This is a modified version the X11 run loop from vst3editor.cpp. | ||
This version is edited to add more safeguards to protect against host bugs. | ||
It also permits to call event processing externally in case the host has a | ||
defective X11 event loop notifier. | ||
*/ | ||
|
||
#pragma once | ||
#include "vstgui/lib/platform/linux/x11frame.h" | ||
#include "pluginterfaces/gui/iplugview.h" | ||
|
||
namespace VSTGUI { | ||
|
||
class RunLoop final : public X11::IRunLoop, public AtomicReferenceCounted { | ||
public: | ||
explicit RunLoop(Steinberg::FUnknown* runLoop); | ||
~RunLoop(); | ||
|
||
static SharedPointer<RunLoop> get(); | ||
|
||
void processSomeEvents(); | ||
void cleanupDeadHandlers(); | ||
|
||
// X11::IRunLoop | ||
bool registerEventHandler(int fd, X11::IEventHandler* handler); | ||
bool unregisterEventHandler(X11::IEventHandler* handler); | ||
bool registerTimer(uint64_t interval, X11::ITimerHandler* handler); | ||
bool unregisterTimer(X11::ITimerHandler* handler); | ||
|
||
private: | ||
struct EventHandler; | ||
struct TimerHandler; | ||
|
||
private: | ||
using EventHandlers = std::vector<Steinberg::IPtr<EventHandler>>; | ||
using TimerHandlers = std::vector<Steinberg::IPtr<TimerHandler>>; | ||
EventHandlers eventHandlers; | ||
TimerHandlers timerHandlers; | ||
Steinberg::FUnknownPtr<Steinberg::Linux::IRunLoop> runLoop; | ||
}; | ||
|
||
} // namespace VSTGUI |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.