Sélectionner une révision Git
module_qt_window.cc 3,90 Kio
#include "module_qt_window.hh"
#include <QApplication>
#include "common.h"
#include <sched.h>
#include "mainwindow.hh"
static module_qt_window_s *module = nullptr;
static void *
___create_mpv_widget(void *arg)
{
/* Unsafe reinterpret cast, but isok */
module_qt_window_s *qt_window = reinterpret_cast<module_qt_window_s *>(arg);
int argc = 0;
QApplication app(argc, nullptr);
setlocale(LC_NUMERIC, "C");
qt_window->main_window = new MainWindow(qt_window);
qt_window->main_window->show();
return std::bit_cast<void *>((static_cast<size_t>(app.exec())));
}
#if defined(LKT_OS_MINGW) && (LKT_OS_MINGW == 1)
void *__imp____lkt_abort;
void *__imp____lkt_log_rs;
void *__imp_lkt_toggle_play_state;
void *__imp_lkt_play_next;
void *__imp_lkt_play_prev;
#endif
extern "C" {
DLL_EXPORT int
mod_new(void UNUSED *func_ptrs)
{
#if defined(LKT_OS_MINGW) && (LKT_OS_MINGW == 1)
struct lkt_func_ptrs {
void *___lkt_log_rs;
void *___lkt_abort;
void *lkt_play_next;
void *lkt_play_prev;
void *lkt_toggle_play_state;
};
#define IMPORT_FUNCTION(name) \
{ \
struct lkt_func_ptrs *ptrs = (struct lkt_func_ptrs *)func_ptrs; \
__imp_##name = ptrs->name; \
LOG_INFO("DLL", #name " := %p", __imp_##name); \
}
IMPORT_FUNCTION(___lkt_log_rs);
IMPORT_FUNCTION(___lkt_abort);
IMPORT_FUNCTION(lkt_toggle_play_state);
IMPORT_FUNCTION(lkt_play_next);
IMPORT_FUNCTION(lkt_play_prev);
#undef IMPORT_FUNCTION
#endif
LOG_DEBUG("WINDOW", "initializing a new window");
if (module == nullptr) {
module = LKT_ALLOC_STRUCT(module_qt_window_s);
RETURN_UNLESS(module, "Out of memory", 1);
RETURN_IF(pthread_create(&module->thread, nullptr, ___create_mpv_widget, module),
"Failed to launch the Qt thread, leak the module structure", 1);
LOG_DEBUG("WINDOW", "waiting for the new window, active wait...");
timespec timeToWait = { 0, 10000000 };
while (!(module)->launched) {
nanosleep(&timeToWait, nullptr);
}
LOG_DEBUG("WINDOW", "new window OK!");