From 53e8b2d41988be69deb800e1ef3cbcfc699a3076 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 13 Jan 2018 07:42:29 +0100 Subject: cmake, main: work toward introducing alternative UI We're going to base opentrack derivatives on the same branch. Previously merges were a living hell. Modularizing the UI code and having continuously-built executables will do a lot. First opentrack variant in progress is a TrackHat device for mouse and scrolling control for people with spine and hand/arm disabilities. --- CMakeLists.txt | 38 +++--- cmake/msvc.cmake | 4 +- cmake/opentrack-boilerplate.cmake | 39 +++--- cmake/opentrack-qt.cmake | 2 +- cmake/opentrack-variant.cmake | 50 ++++++++ gui/init.cpp | 222 +++++++++++++++++++++++++++++++++ gui/init.hpp | 14 +++ gui/main-window.cpp | 142 +++++++++++---------- gui/main-window.hpp | 22 ++-- main/CMakeLists.txt | 9 -- main/facetracknoir.ico | Bin 67134 -> 0 bytes main/facetracknoir.rc | 2 - main/lang/nl_NL.ts | 4 - main/lang/ru_RU.ts | 4 - main/lang/stub.ts | 4 - main/main.cpp | 255 -------------------------------------- options/defs.hpp | 1 - variant/default/CMakeLists.txt | 9 ++ variant/default/facetracknoir.ico | Bin 0 -> 67134 bytes variant/default/facetracknoir.rc | 2 + variant/default/lang/nl_NL.ts | 4 + variant/default/lang/ru_RU.ts | 4 + variant/default/lang/stub.ts | 4 + variant/default/main.cpp | 20 +++ variant/trackmouse/CMakeLists.txt | 1 + 25 files changed, 463 insertions(+), 393 deletions(-) create mode 100644 cmake/opentrack-variant.cmake create mode 100644 gui/init.cpp create mode 100644 gui/init.hpp delete mode 100644 main/CMakeLists.txt delete mode 100644 main/facetracknoir.ico delete mode 100644 main/facetracknoir.rc delete mode 100644 main/lang/nl_NL.ts delete mode 100644 main/lang/ru_RU.ts delete mode 100644 main/lang/stub.ts delete mode 100644 main/main.cpp create mode 100644 variant/default/CMakeLists.txt create mode 100644 variant/default/facetracknoir.ico create mode 100644 variant/default/facetracknoir.rc create mode 100644 variant/default/lang/nl_NL.ts create mode 100644 variant/default/lang/ru_RU.ts create mode 100644 variant/default/lang/stub.ts create mode 100644 variant/default/main.cpp create mode 100644 variant/trackmouse/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index f47bdd03..aa1a63dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ include(opentrack-boilerplate) include(opentrack-qt) include(opentrack-version) include(opentrack-install) +include(opentrack-variant) if(WIN32) enable_language(RC) @@ -57,31 +58,20 @@ add_custom_target(mrproper COMMAND "${CMAKE_SOURCE_DIR}/cmake/opentrack-clean-build-directory.cmake" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}") -otr_add_target_dirs(opentrack-subprojects - "tracker-*" - "proto-*" - "filter-*" - "ext-*" - "options" - "api" - "compat" - "logic" - "dinput" - "gui" - "main" - "x-plane-plugin" - "csv" - "pose-widget" - "spline" - "qxt-mini" - "macosx" - "cv" - "migration") +function(otr_add_subdirs) + otr_dist_select_variant() + get_property(_globs GLOBAL PROPERTY opentrack-subprojects) + otr_add_target_dirs(_globbed ${_globs}) -foreach(k ${opentrack-subprojects}) - get_filename_component(k "${k}" DIRECTORY) - add_subdirectory("${k}") -endforeach() + get_property(_variant GLOBAL PROPERTY opentrack-variant) + add_subdirectory("variant/${_variant}") + foreach(k ${_globbed}) + get_filename_component(k "${k}" DIRECTORY) + add_subdirectory("${k}") + endforeach() +endfunction() + +otr_add_subdirs() otr_merge_translations() install_sources() diff --git a/cmake/msvc.cmake b/cmake/msvc.cmake index 45791d4e..8d125ffa 100644 --- a/cmake/msvc.cmake +++ b/cmake/msvc.cmake @@ -65,8 +65,8 @@ set(_CXXFLAGS_DEBUG "${_CFLAGS_DEBUG}") set(_LDFLAGS "-machine:X86 -DEBUG") -set(_ltcg "-LTCG") -#set(_ltcg "-LTCG:INCREMENTAL") +#set(_ltcg "-LTCG") +set(_ltcg "-LTCG:INCREMENTAL") set(_LDFLAGS_RELEASE "-OPT:REF,ICF -cgthreads:1 ${_ltcg}") set(_LDFLAGS_DEBUG "") diff --git a/cmake/opentrack-boilerplate.cmake b/cmake/opentrack-boilerplate.cmake index a4d197be..019efb05 100644 --- a/cmake/opentrack-boilerplate.cmake +++ b/cmake/opentrack-boilerplate.cmake @@ -27,19 +27,22 @@ if(NOT (orig-hier-path STREQUAL new-hier-path)) endif() function(otr_glob_sources var) - set(dir "${CMAKE_CURRENT_SOURCE_DIR}") - file(GLOB ${var}-cxx ${dir}/*.cpp) - file(GLOB ${var}-cc ${dir}/*.c) - file(GLOB ${var}-hh ${dir}/*.h ${dir}/*.hpp) - file(GLOB ${var}-res ${dir}/*.rc) - foreach(f ${var}-res) - set_source_files_properties(${f} PROPERTIES LANGUAGE RC) - endforeach() - file(GLOB ${var}-ui ${dir}/*.ui) - file(GLOB ${var}-rc ${dir}/*.qrc) - set(${var}-all ${${var}-cc} ${${var}-cxx} ${${var}-hh} ${${var}-rc} ${${var}-res}) - foreach(i ui rc res cc cxx hh all) - set(${var}-${i} "${${var}-${i}}" PARENT_SCOPE) + set(basedir "${CMAKE_CURRENT_SOURCE_DIR}") + foreach(dir . ${ARGN}) + set(dir "${basedir}/${dir}") + file(GLOB ${var}-cxx ${dir}/*.cpp) + file(GLOB ${var}-cc ${dir}/*.c) + file(GLOB ${var}-hh ${dir}/*.h ${dir}/*.hpp) + file(GLOB ${var}-res ${dir}/*.rc) + foreach(f ${var}-res) + set_source_files_properties(${f} PROPERTIES LANGUAGE RC) + endforeach() + file(GLOB ${var}-ui ${dir}/*.ui) + file(GLOB ${var}-rc ${dir}/*.qrc) + set(${var}-all ${${var}-cc} ${${var}-cxx} ${${var}-hh} ${${var}-rc} ${${var}-res}) + foreach(i ui rc res cc cxx hh all) + set(${var}-${i} "${${var}-${i}}" PARENT_SCOPE) + endforeach() endforeach() endfunction() @@ -124,7 +127,7 @@ function(otr_module n_) cmake_parse_arguments(arg "STATIC;NO-COMPAT;BIN;EXECUTABLE;NO-QT;WIN32-CONSOLE;NO-INSTALL;RELINK" "LINK;COMPILE" - "SOURCES" + "SOURCES;SUBDIRS" ${ARGN} ) @@ -134,7 +137,7 @@ function(otr_module n_) set(n "opentrack-${n_}") - otr_glob_sources(${n}) + otr_glob_sources(${n} ${arg_SUBDIRS}) list(APPEND ${n}-all ${arg_SOURCES}) if(NOT arg_NO-QT) @@ -183,6 +186,12 @@ function(otr_module n_) string(TOUPPER "${build-n}" build-n) set_property(TARGET ${n} PROPERTY DEFINE_SYMBOL "BUILD_${build-n}") + get_property(ident GLOBAL PROPERTY opentrack-ident) + if (".${ident}" STREQUAL ".") + message(FATAL_ERROR "must set global property `opentrack-ident' in `opentrack-variant.cmake'") + endif() + set_property(TARGET ${n} APPEND PROPERTY COMPILE_DEFINITIONS "OPENTRACK_ORG=\"${ident}\"") + if(arg_STATIC) set(arg_NO-INSTALL TRUE) endif() diff --git a/cmake/opentrack-qt.cmake b/cmake/opentrack-qt.cmake index 665ed053..911eec5b 100644 --- a/cmake/opentrack-qt.cmake +++ b/cmake/opentrack-qt.cmake @@ -2,7 +2,7 @@ find_package(Qt5 REQUIRED COMPONENTS Core Network Widgets LinguistTools Gui QUIE if(WIN32) find_package(Qt5Gui REQUIRED COMPONENTS QWindowsIntegrationPlugin) endif() -find_package(Qt5 COMPONENTS SerialPort Gamepad QUIET) +find_package(Qt5 COMPONENTS SerialPort QUIET) include_directories(SYSTEM ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}) add_definitions(${Qt5Core_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Network_DEFINITIONS}) diff --git a/cmake/opentrack-variant.cmake b/cmake/opentrack-variant.cmake new file mode 100644 index 00000000..7418f882 --- /dev/null +++ b/cmake/opentrack-variant.cmake @@ -0,0 +1,50 @@ +# set these as cache variables manually + +set(opentrack_variant "default" CACHE STRING "") +set_property(CACHE opentrack_variant PROPERTY STRINGS "default;trackmouse") + +function(otr_dist_select_variant) + if(opentrack_variant STREQUAL "trackmouse") + set_property(GLOBAL PROPERTY opentrack-variant "trackmouse") + set_property(GLOBAL PROPERTY opentrack-ident "trackmouse-prototype") + set(subprojects + "tracker-pt" + "proto-mouse" + "filter-accela" + "options" + "api" + "compat" + "logic" + "dinput" + "gui" + "spline" + "cv" + "migration") + set_property(GLOBAL PROPERTY opentrack-subprojects "${subprojects}") + else() + set_property(GLOBAL PROPERTY opentrack-variant "default") + set_property(GLOBAL PROPERTY opentrack-ident "opentrack-2.3") + set(subprojects + "tracker-*" + "proto-*" + "filter-*" + "ext-*" + "options" + "api" + "compat" + "logic" + "dinput" + "gui" + "main" + "x-plane-plugin" + "csv" + "pose-widget" + "spline" + "qxt-mini" + "macosx" + "cv" + "migration") + set_property(GLOBAL PROPERTY opentrack-subprojects "${subprojects}") + endif() +endfunction() + diff --git a/gui/init.cpp b/gui/init.cpp new file mode 100644 index 00000000..7ccc67fe --- /dev/null +++ b/gui/init.cpp @@ -0,0 +1,222 @@ +#include "init.hpp" + +#if defined(Q_CREATOR_RUN) +# pragma clang diagnostic ignored "-Wmain" +#endif + +#include "migration/migration.hpp" +#include "gui/main-window.hpp" +#include "options/options.hpp" +using namespace options; +#include "opentrack-library-path.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#if /* denormal control */ \ + /* GNU */ defined __x86_64__ || defined __SSE2__ || \ + /* MSVC */ defined _M_AMD64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) +# include +# include +# include + +#define OTR_HAS_DENORM_CONTROL +void set_fp_mask() +{ + _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); + _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); + _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST); + _MM_SET_EXCEPTION_MASK(_MM_MASK_MASK); +} +#endif + +void set_qt_style() +{ +#if defined _WIN32 + if (QSysInfo::WindowsVersion == QSysInfo::WV_XP) + return; +#endif + +#if defined _WIN32 || defined __APPLE__ + // our layouts on OSX make some control wrongly sized -sh 20160908 + { + const char* preferred[] { "fusion", "windowsvista", "macintosh" }; + for (const char* style_name : preferred) + { + QStyle* s = QStyleFactory::create(style_name); + if (s) + { + QApplication::setStyle(s); + break; + } + } + } +#endif +} + +#ifdef _WIN32 + +void qdebug_to_console(QtMsgType, const QMessageLogContext& ctx, const QString &msg) +{ + const unsigned short* const str_ = msg.utf16(); + auto str = reinterpret_cast(str_); + static_assert(sizeof(*str_) == sizeof(*str), ""); + + std::fflush(stderr); + if (ctx.function) + std::fprintf(stderr, "[%s:%d%s]: %ls\n", ctx.file, ctx.line, ctx.function, str); + else if (ctx.file) + std::fprintf(stderr, "[%s:%d]: %ls\n", ctx.file, ctx.line, str); + else + std::fprintf(stderr, "%ls\n", str); + std::fflush(stderr); +} + +void attach_parent_console() +{ + if (AttachConsole(ATTACH_PARENT_PROCESS)) + { + // XXX c++ iostreams aren't reopened + + _wfreopen(L"CON", L"w", stdout); + _wfreopen(L"CON", L"w", stderr); + _wfreopen(L"CON", L"r", stdin); + } + (void)qInstallMessageHandler(qdebug_to_console); +} + +void add_win32_path() +{ + // see https://software.intel.com/en-us/articles/limitation-to-the-length-of-the-system-path-variable + static char env_path[4096] { '\0', }; + { + QString lib_path = OPENTRACK_BASE_PATH; + lib_path.replace("/", "\\"); + const QByteArray lib_path_ = QFile::encodeName(lib_path); + + QString mod_path = OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH; + mod_path.replace("/", "\\"); + const QByteArray mod_path_ = QFile::encodeName(mod_path); + + const char* contents[] { + "PATH=", + lib_path_.constData(), + ";", + mod_path_.constData(), + ";", + getenv("PATH"), + }; + + bool ok = true; + + for (const char* ptr : contents) + { + if (ptr) + strcat_s(env_path, sizeof(env_path), ptr); + + if (!ptr || ptr[0] == '\0' || env_path[0] == '\0') + { + qDebug() << "bad path element" + << (ptr == nullptr ? "" : ptr); + ok = false; + break; + } + } + + if (ok) + { + const int error = _putenv(env_path); + + if (error) + qDebug() << "can't _putenv win32 path"; + } + else + qDebug() << "can't set win32 path"; + } +} + +#endif + +int run_window(QApplication& app, std::unique_ptr main_window) +{ + if (!main_window->isEnabled()) + { + qDebug() << "exit before window created"; + return 2; + } + + app.setQuitOnLastWindowClosed(false); + + int ret = app.exec(); + qDebug() << "exit" << ret; + + return ret; +} + +int otr_main(int argc, char** argv, std::function make_main_window) +{ +#ifdef _WIN32 + attach_parent_console(); +#endif + +#if defined OTR_HAS_DENORM_CONTROL + set_fp_mask(); +#endif + + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_X11InitThreads, true); + + QApplication app(argc, argv); + +#ifdef _WIN32 + add_win32_path(); +#endif + + QDir::setCurrent(OPENTRACK_BASE_PATH); + +#if 0 +#if !defined(__linux) && !defined _WIN32 + // workaround QTBUG-38598 + QCoreApplication::addLibraryPath("."); +#endif +#endif + + set_qt_style(); + QTranslator t; + + // QLocale::setDefault(QLocale("ru_RU")); // force i18n for testing + + if (group::with_global_settings_object([&](QSettings& s) { + return !s.value("disable-translation", false).toBool(); + })) + { + (void) t.load(QLocale(), "", "", OPENTRACK_BASE_PATH + "/" OPENTRACK_I18N_PATH, ".qm"); + (void) QCoreApplication::installTranslator(&t); + } + + int ret = run_window(app, std::unique_ptr(make_main_window())); + + // msvc crashes in Qt plugin system's dtor + // Note: QLibrary::PreventUnloadHint seems to workaround it +#if defined(_MSC_VER) && 0 + qDebug() << "exit: terminating"; + TerminateProcess(GetCurrentProcess(), 0); +#endif + + return ret; +} diff --git a/gui/init.hpp b/gui/init.hpp new file mode 100644 index 00000000..d437b084 --- /dev/null +++ b/gui/init.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "export.hpp" + +#include +#include + +int OTR_GUI_EXPORT otr_main(int argc, char** argv, std::function make_main_window); + +template +auto run_application(int argc, char** argv, F&& fun) +{ + return otr_main(argc, argv, fun); +} diff --git a/gui/main-window.cpp b/gui/main-window.cpp index 1f84ea71..bc20cf59 100644 --- a/gui/main-window.cpp +++ b/gui/main-window.cpp @@ -15,73 +15,71 @@ #include "compat/check-visible.hpp" #include "compat/sleep.hpp" -#include -#include +#include #include -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -# include -#endif +#include extern "C" const char* const opentrack_version; +#if !defined EXIT_SUCCESS +# define EXIT_SUCCESS 0 +#endif + +#if !defined EXIT_FAILURE +# define EXIT_FAILURE 1 +#endif + +// + +/* FreeBSD sysexits(3) + * + * The input data was incorrect in some way. This + * should only be used for user's data and not system + * files. + */ + +#if !defined EX_DATAERR +# define EX_DATAERR 65 +#endif + #if !defined _WIN32 && !defined __APPLE__ # include void MainWindow::annoy_if_root() { if (geteuid() == 0) { - for (unsigned k = 0; k < 2; k++) - { - portable::sleep(1 * 1000); - QMessageBox::critical(this, - tr("Running as root is bad"), - tr("Do not run as root. Set correct device node permissions."), - QMessageBox::Ok); - portable::sleep(1 * 1000); - QMessageBox::critical(this, - tr("Running as root is bad, seriously"), - tr("Do not run as root. I'll keep whining at every startup."), - QMessageBox::Ok); - portable::sleep(3 * 1000); - QMessageBox::critical(this, - tr("Running as root is really seriously bad"), - tr("Do not run as root. Be annoyed, comprehensively."), - QMessageBox::Ok); - } + portable::sleep(4000); + QMessageBox::critical(this, + tr("Running as root is bad"), + tr("Do not run as root. Set correct device node permissions."), + QMessageBox::Ok); + portable::sleep(4000); + QMessageBox::critical(this, + tr("Running as root is bad, seriously"), + tr("Do not run as root. I'll keep whining at every startup."), + QMessageBox::Ok); + portable::sleep(4000); + QMessageBox::critical(this, + tr("Running as root is really seriously bad"), + tr("Do not run as root. Be annoyed, comprehensively."), + QMessageBox::Ok); } } #endif main_window::main_window() : - State(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH), - pose_update_timer(this), - kbd_quit(QKeySequence("Ctrl+Q"), this), - menu_action_header(&tray_menu), - menu_action_show(&tray_menu), - menu_action_exit(&tray_menu), - menu_action_tracker(&tray_menu), - menu_action_filter(&tray_menu), - menu_action_proto(&tray_menu), - menu_action_options(&tray_menu), - menu_action_mappings(&tray_menu) + State(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH) { ui.setupUi(this); + setAttribute(Qt::WA_QuitOnClose, true); + #if !defined _WIN32 && !defined __APPLE__ annoy_if_root(); #endif - { - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | windowFlags()); - } + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | windowFlags()); update_button_state(false, false); @@ -92,7 +90,10 @@ main_window::main_window() : } if (!refresh_config_list()) + { + exit(EX_DATAERR); return; + } connect(ui.btnEditCurves, SIGNAL(clicked()), this, SLOT(show_mapping_window())); connect(ui.btnShortcuts, SIGNAL(clicked()), this, SLOT(show_options_dialog())); @@ -133,14 +134,15 @@ main_window::main_window() : ui.profile_button->setMenu(&profile_menu); } - if (!progn( + { const QString cur = group::ini_filename(); - if (is_config_listed(cur)) - return set_profile(cur); - else - return set_profile(OPENTRACK_DEFAULT_CONFIG); - )) - return; + bool ok = is_config_listed(cur) ? set_profile(cur) : set_profile(OPENTRACK_DEFAULT_CONFIG); + if (!ok) + { + exit(EX_DATAERR); + return; + } + } // only tie and connect main screen options after migrations are done // below is fine, set_profile() is called already @@ -162,9 +164,9 @@ main_window::main_window() : this, [&](const QString&) { if (pFilterDialog) pFilterDialog = nullptr; }); - connect(&m.tracker_dll, base_value::value_changed(), this, &main_window::save_modules, Qt::QueuedConnection); - connect(&m.protocol_dll, base_value::value_changed(), this, &main_window::save_modules, Qt::QueuedConnection); - connect(&m.filter_dll, base_value::value_changed(), this, &main_window::save_modules, Qt::QueuedConnection); + connect(&m.tracker_dll, base_value::value_changed(), this, &main_window::save_modules, Qt::DirectConnection); + connect(&m.protocol_dll, base_value::value_changed(), this, &main_window::save_modules, Qt::DirectConnection); + connect(&m.filter_dll, base_value::value_changed(), this, &main_window::save_modules, Qt::DirectConnection); tie_setting(m.tracker_dll, ui.iconcomboTrackerSource); tie_setting(m.protocol_dll, ui.iconcomboProtocol); @@ -202,6 +204,17 @@ main_window::main_window() : det_timer.start(1000); config_list_timer.start(1000 * 5); kbd_quit.setEnabled(true); + + adjustSize(); + setFixedSize(size()); + + if (!start_in_tray()) + { + setVisible(true); + show(); + } + else + setVisible(false); } void main_window::init_tray_menu() @@ -301,15 +314,15 @@ void main_window::die_on_config_not_writable() QMessageBox::Close, QMessageBox::NoButton); // signals main() to short-circuit - if (!isVisible()) - setEnabled(false); + //if (!isVisible()) + // setEnabled(false); - setVisible(false); + //setVisible(false); // tray related - qApp->setQuitOnLastWindowClosed(true); + //qApp->setQuitOnLastWindowClosed(true); - close(); + exit(EX_DATAERR); } bool main_window::maybe_die_on_config_not_writable(const QString& current, QStringList* ini_list_) @@ -701,9 +714,11 @@ void main_window::show_mapping_window() mk_window(mapping_widget, pose); } -void main_window::exit() +void main_window::exit(int status) { - QCoreApplication::exit(0); + setEnabled(false); + close(); + QCoreApplication::exit(status); } bool main_window::set_profile(const QString& new_name_) @@ -885,8 +900,9 @@ void main_window::changeEvent(QEvent* e) } } -void main_window::closeEvent(QCloseEvent*) +void main_window::closeEvent(QCloseEvent* ev) { + ev->accept(); exit(); } diff --git a/gui/main-window.hpp b/gui/main-window.hpp index 253c1194..402202d6 100644 --- a/gui/main-window.hpp +++ b/gui/main-window.hpp @@ -21,8 +21,7 @@ #include "logic/state.hpp" #include "options/options.hpp" -#include -#include +#include #include #include #include @@ -53,12 +52,12 @@ class OTR_GUI_EXPORT main_window : public QMainWindow, private State module_settings m; std::unique_ptr tray; QMenu tray_menu; - QTimer pose_update_timer; + QTimer pose_update_timer { this }; QTimer det_timer; QTimer config_list_timer; std::unique_ptr options_widget; std::unique_ptr mapping_widget; - QShortcut kbd_quit; + QShortcut kbd_quit { QKeySequence("Ctrl+Q"), this }; std::unique_ptr pFilterDialog; std::unique_ptr pProtocolDialog; std::unique_ptr pTrackerDialog; @@ -66,9 +65,14 @@ class OTR_GUI_EXPORT main_window : public QMainWindow, private State process_detector_worker det; QMenu profile_menu; - QAction menu_action_header, menu_action_show, menu_action_exit, - menu_action_tracker, menu_action_filter, menu_action_proto, - menu_action_options, menu_action_mappings; + QAction menu_action_header { &tray_menu }, + menu_action_show { &tray_menu }, + menu_action_exit { &tray_menu }, + menu_action_tracker { &tray_menu }, + menu_action_filter { &tray_menu }, + menu_action_proto { &tray_menu }, + menu_action_options { &tray_menu }, + menu_action_mappings { &tray_menu }; std::shared_ptr current_tracker() { @@ -96,7 +100,7 @@ class OTR_GUI_EXPORT main_window : public QMainWindow, private State void init_tray_menu(); void changeEvent(QEvent* e) override; - void closeEvent(QCloseEvent*) override; + void closeEvent(QCloseEvent* ev) override; bool event(QEvent *event) override; bool maybe_hide_to_tray(QEvent* e); #if !defined _WIN32 && !defined __APPLE__ @@ -117,7 +121,7 @@ class OTR_GUI_EXPORT main_window : public QMainWindow, private State private slots: void save_modules(); - void exit(); + void exit(int status = 0); bool set_profile(const QString& new_name); void show_tracker_settings(); diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt deleted file mode 100644 index a9e3c754..00000000 --- a/main/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -otr_module(executable EXECUTABLE BIN) - -set_target_properties(opentrack-executable PROPERTIES - SUFFIX "${opentrack-binary-suffix}" - OUTPUT_NAME "opentrack" - PREFIX "" -) - -target_link_libraries(opentrack-executable opentrack-user-interface) diff --git a/main/facetracknoir.ico b/main/facetracknoir.ico deleted file mode 100644 index 5cac8da1..00000000 Binary files a/main/facetracknoir.ico and /dev/null differ diff --git a/main/facetracknoir.rc b/main/facetracknoir.rc deleted file mode 100644 index 020ffe97..00000000 --- a/main/facetracknoir.rc +++ /dev/null @@ -1,2 +0,0 @@ -#include -IDI_ICON1 ICON "facetracknoir.ico" diff --git a/main/lang/nl_NL.ts b/main/lang/nl_NL.ts deleted file mode 100644 index 9e739505..00000000 --- a/main/lang/nl_NL.ts +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/main/lang/ru_RU.ts b/main/lang/ru_RU.ts deleted file mode 100644 index f62cf2e1..00000000 --- a/main/lang/ru_RU.ts +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/main/lang/stub.ts b/main/lang/stub.ts deleted file mode 100644 index 6401616d..00000000 --- a/main/lang/stub.ts +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/main/main.cpp b/main/main.cpp deleted file mode 100644 index 03c12a8b..00000000 --- a/main/main.cpp +++ /dev/null @@ -1,255 +0,0 @@ -#ifdef _WIN32 -# include -# include -# include -# include -# include -# include -# include -# include -#endif - -#include "migration/migration.hpp" -#include "gui/main-window.hpp" -#include "options/options.hpp" -using namespace options; -#include "opentrack-library-path.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if /* denormal control */ \ - /* GNU */ defined __x86_64__ || defined __SSE2__ || \ - /* MSVC */ defined _M_AMD64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) -# include -# include -# include - -#define OTR_HAS_DENORM_CONTROL -void set_fp_mask() -{ - unsigned old_mask = _mm_getcsr(); - (void) old_mask; - - _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); - _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); - _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST); - _MM_SET_EXCEPTION_MASK(_MM_MASK_MASK); - -#if 0 - unsigned new_mask = _mm_getcsr(); - - qDebug() << "old" << (void*) old_mask << "new" << (void*) new_mask; -#endif -} -#endif - -void set_qt_style() -{ -#if defined _WIN32 - if (QSysInfo::WindowsVersion == QSysInfo::WV_XP) - return; -#endif - -#if defined(_WIN32) || defined(__APPLE__) - // our layouts on OSX make some control wrongly sized -sh 20160908 - { - const QStringList preferred { "fusion", "windowsvista", "macintosh" }; - for (const auto& style_name : preferred) - { - QStyle* s = QStyleFactory::create(style_name); - if (s) - { - QApplication::setStyle(s); - break; - } - } - } -#endif -} - -#ifdef _WIN32 - -void qdebug_to_console(QtMsgType, const QMessageLogContext& ctx, const QString &msg) -{ - const unsigned short* const str_ = msg.utf16(); - auto str = reinterpret_cast(str_); - static_assert(sizeof(*str_) == sizeof(*str), ""); - - std::fflush(stderr); - if (ctx.function) - std::fprintf(stderr, "[%s]: %ls\n", ctx.function, str); - else if (ctx.file) - std::fprintf(stderr, "[%s:%d]: %ls\n", ctx.file, ctx.line, str); - else - std::fprintf(stderr, "%ls\n", str); - std::fflush(stderr); -} - -void attach_parent_console() -{ - if (AttachConsole(ATTACH_PARENT_PROCESS)) - { - // XXX c++ iostreams aren't reopened - - _wfreopen(L"CON", L"w", stdout); - _wfreopen(L"CON", L"w", stderr); - _wfreopen(L"CON", L"r", stdin); - qInstallMessageHandler(qdebug_to_console); - } -} - -void add_win32_path() -{ - // see https://software.intel.com/en-us/articles/limitation-to-the-length-of-the-system-path-variable - static char env_path[4096] { '\0', }; - { - QString lib_path = OPENTRACK_BASE_PATH; - lib_path.replace("/", "\\"); - const QByteArray lib_path_ = QFile::encodeName(lib_path); - - QString mod_path = OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH; - mod_path.replace("/", "\\"); - const QByteArray mod_path_ = QFile::encodeName(mod_path); - - std::vector contents - { - "PATH=", - lib_path_.constData(), - ";", - mod_path_.constData(), - ";", - getenv("PATH"), - }; - - bool ok = true; - - for (const char* ptr : contents) - { - if (ptr) - strcat_s(env_path, sizeof(env_path), ptr); - - if (!ptr || ptr[0] == '\0' || env_path[0] == '\0') - { - qDebug() << "bad path element" - << (ptr == nullptr ? "" : ptr); - ok = false; - break; - } - } - - if (ok) - { - const int error = _putenv(env_path); - - if (error) - qDebug() << "can't _putenv win32 path"; - } - else - qDebug() << "can't set win32 path"; - } -} - -#endif - -int -#ifdef _MSC_VER -WINAPI -#endif -main(int argc, char** argv) -{ -#ifdef _WIN32 - attach_parent_console(); -#endif - -#if defined OTR_HAS_DENORM_CONTROL - set_fp_mask(); -#endif - -#if QT_VERSION >= 0x050600 // flag introduced in QT 5.6. It is non-essential so might as well allow compilation on older systems. - QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); -#endif - QApplication::setAttribute(Qt::AA_X11InitThreads, true); - - QApplication app(argc, argv); - -#ifdef _WIN32 - add_win32_path(); -#endif - - main_window::set_working_directory(); - -#if !defined(__linux) && !defined _WIN32 - // workaround QTBUG-38598 - QCoreApplication::addLibraryPath("."); -#endif - - set_qt_style(); - QTranslator t; - - // QLocale::setDefault(QLocale("ru_RU")); // force i18n for testing - - if (group::with_global_settings_object([&](QSettings& s) { - return !s.value("disable-translation", false).toBool(); - })) - { - (void) t.load(QLocale(), "", "", OPENTRACK_BASE_PATH + "/" OPENTRACK_I18N_PATH, ".qm"); - (void) QCoreApplication::installTranslator(&t); - } - - do - { - std::shared_ptr w = std::make_shared(); - - if (!w->isEnabled()) - break; - - if (!w->start_in_tray()) - { - w->setVisible(true); - w->show(); - w->adjustSize(); - w->setFixedSize(w->size()); - } - else - w->setVisible(false); - - app.setQuitOnLastWindowClosed(false); - app.exec(); - - app.exit(0); - - qDebug() << "exit: window"; - } - while (false); - - // msvc crashes in Qt plugin system's dtor - // Note: QLibrary::PreventUnloadHint seems to workaround it -#if defined(_MSC_VER) && 0 - qDebug() << "exit: terminating"; - TerminateProcess(GetCurrentProcess(), 0); -#endif - - qDebug() << "exit: main()"; - - return 0; -} - -#if defined(Q_CREATOR_RUN) -# pragma clang diagnostic ignored "-Wmain" -#endif - -#ifdef _MSC_VER -int WINAPI -WinMain (struct HINSTANCE__*, struct HINSTANCE__*, char*, int) -{ - return main (__argc, __argv); -} - -#endif diff --git a/options/defs.hpp b/options/defs.hpp index 6f368848..f093a22a 100644 --- a/options/defs.hpp +++ b/options/defs.hpp @@ -5,4 +5,3 @@ #define OPENTRACK_CONFIG_FILENAME_KEY "settings-filename" #define OPENTRACK_DEFAULT_CONFIG "default.ini" #define OPENTRACK_DEFAULT_CONFIG_Q QStringLiteral("default.ini") -#define OPENTRACK_ORG "opentrack-2.3" diff --git a/variant/default/CMakeLists.txt b/variant/default/CMakeLists.txt new file mode 100644 index 00000000..a9e3c754 --- /dev/null +++ b/variant/default/CMakeLists.txt @@ -0,0 +1,9 @@ +otr_module(executable EXECUTABLE BIN) + +set_target_properties(opentrack-executable PROPERTIES + SUFFIX "${opentrack-binary-suffix}" + OUTPUT_NAME "opentrack" + PREFIX "" +) + +target_link_libraries(opentrack-executable opentrack-user-interface) diff --git a/variant/default/facetracknoir.ico b/variant/default/facetracknoir.ico new file mode 100644 index 00000000..5cac8da1 Binary files /dev/null and b/variant/default/facetracknoir.ico differ diff --git a/variant/default/facetracknoir.rc b/variant/default/facetracknoir.rc new file mode 100644 index 00000000..020ffe97 --- /dev/null +++ b/variant/default/facetracknoir.rc @@ -0,0 +1,2 @@ +#include +IDI_ICON1 ICON "facetracknoir.ico" diff --git a/variant/default/lang/nl_NL.ts b/variant/default/lang/nl_NL.ts new file mode 100644 index 00000000..9e739505 --- /dev/null +++ b/variant/default/lang/nl_NL.ts @@ -0,0 +1,4 @@ + + + + diff --git a/variant/default/lang/ru_RU.ts b/variant/default/lang/ru_RU.ts new file mode 100644 index 00000000..f62cf2e1 --- /dev/null +++ b/variant/default/lang/ru_RU.ts @@ -0,0 +1,4 @@ + + + + diff --git a/variant/default/lang/stub.ts b/variant/default/lang/stub.ts new file mode 100644 index 00000000..6401616d --- /dev/null +++ b/variant/default/lang/stub.ts @@ -0,0 +1,4 @@ + + + + diff --git a/variant/default/main.cpp b/variant/default/main.cpp new file mode 100644 index 00000000..80f7e495 --- /dev/null +++ b/variant/default/main.cpp @@ -0,0 +1,20 @@ +#include "gui/init.hpp" +#include "gui/main-window.hpp" + +#if defined _WIN32 +# include +#endif + +int main(int argc, char** argv) +{ + return run_application(argc, argv, []() { return new main_window; }); +} + +#if defined _MSC_VER +int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int /* nCmdShow */) +{ + return main(__argc, __argv); +} +#endif + + diff --git a/variant/trackmouse/CMakeLists.txt b/variant/trackmouse/CMakeLists.txt new file mode 100644 index 00000000..bda9c39b --- /dev/null +++ b/variant/trackmouse/CMakeLists.txt @@ -0,0 +1 @@ +message("FATAL_ERROR" "") -- cgit v1.2.3