Skip to content

Commit

Permalink
Remove dependency on libuv
Browse files Browse the repository at this point in the history
  • Loading branch information
barche committed Apr 11, 2021
1 parent a36226c commit 4bc5d39
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 35 deletions.
32 changes: 5 additions & 27 deletions application_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "application_manager.hpp"
#include "julia_api.hpp"
#include "jlcxx/functions.hpp"

namespace qmlwrap
{
Expand Down Expand Up @@ -110,18 +111,6 @@ void ApplicationManager::exec()
cleanup();
}

// Non-blocking exec, polling for Qt events in the uv event loop using a uv_timer_t
void ApplicationManager::exec_async()
{
if(jl_global_event_loop() == nullptr)
{
return;
}
m_timer = new uv_timer_t();
uv_timer_init(jl_global_event_loop(), m_timer);
uv_timer_start(m_timer, ApplicationManager::process_events, 15, 15);
}

ApplicationManager::ApplicationManager()
{
qInstallMessageHandler(julia_message_output);
Expand Down Expand Up @@ -164,29 +153,18 @@ void ApplicationManager::set_engine(QQmlEngine* e)
QObject::connect(m_engine, &QQmlEngine::quit, [this]()
{
m_quit_called = true;
if(m_timer != nullptr)
{
uv_timer_stop(m_timer);
uv_close((uv_handle_t*)m_timer, ApplicationManager::handle_quit);
}
static jlcxx::JuliaFunction stoptimer(jl_get_function(m_qml_mod, "_stoptimer"));
stoptimer();
m_app->quit();
});
}

void ApplicationManager::process_events(uv_timer_t* timer)
void ApplicationManager::process_events()
{
QApplication::sendPostedEvents();
QApplication::processEvents(QEventLoop::AllEvents, 15);
}

void ApplicationManager::handle_quit(uv_handle_t* handle)
{
if(instance().m_timer == nullptr)
return;

uv_unref(handle);
delete instance().m_timer;
instance().m_timer = nullptr;
}
jl_module_t* ApplicationManager::m_qml_mod = nullptr;

}
11 changes: 4 additions & 7 deletions application_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ class ApplicationManager
// Blocking call to exec, running the Qt event loop
void exec();

// Non-blocking exec, polling for Qt events in the uv event loop using a uv_timer_t
void exec_async();
static void process_events();

static jl_module_t* m_qml_mod;

private:

ApplicationManager();
Expand All @@ -51,14 +53,9 @@ class ApplicationManager

void set_engine(QQmlEngine* e);

static void process_events(uv_timer_t* timer);

static void handle_quit(uv_handle_t* handle);

QApplication* m_app = nullptr;
QQmlEngine* m_engine = nullptr;
QQmlContext* m_root_ctx = nullptr;
uv_timer_t* m_timer = nullptr;
bool m_quit_called = false;
};

Expand Down
3 changes: 2 additions & 1 deletion wrap_qml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
qmlRegisterType<qmlwrap::OpenGLViewport>("org.julialang", 1, 0, "OpenGLViewport");
qmlRegisterType<qmlwrap::MakieViewport>("org.julialang", 1, 0, "MakieViewport");

qmlwrap::ApplicationManager::m_qml_mod = qml_module.julia_module();
qmlwrap::MakieViewport::m_qml_mod = qml_module.julia_module();

qml_module.add_type<QObject>("QObject");
Expand Down Expand Up @@ -412,7 +413,7 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& qml_module)
qml_module.method("init_qquickview", []() { return qmlwrap::ApplicationManager::instance().init_qquickview(); });
qml_module.method("qmlcontext", []() { return qmlwrap::ApplicationManager::instance().root_context(); });
qml_module.method("exec", []() { qmlwrap::ApplicationManager::instance().exec(); });
qml_module.method("exec_async", []() { qmlwrap::ApplicationManager::instance().exec_async(); });
qml_module.method("process_events", qmlwrap::ApplicationManager::process_events);

qml_module.add_type<QTimer>("QTimer", julia_base_type<QObject>())
.method("start", [] (QTimer& t) { t.start(); } )
Expand Down

0 comments on commit 4bc5d39

Please sign in to comment.