diff --git a/toonz/sources/CMakeLists.txt b/toonz/sources/CMakeLists.txt index fe4f74e..3e2316b 100644 --- a/toonz/sources/CMakeLists.txt +++ b/toonz/sources/CMakeLists.txt @@ -120,7 +120,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) if(APPLE) set(CMAKE_MACOSX_RPATH ON) set(CMAKE_SKIP_BUILD_RPATH FALSE) - set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) + set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_INSTALL_RPATH ${QT_LIB_PATH}) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${QT_LIB_PATH}" isSystemDir) @@ -451,6 +451,11 @@ add_subdirectory(tcleanupper) add_subdirectory(tcomposer) add_subdirectory(tconverter) add_subdirectory(toonzfarm) + +if(APPLE) + add_subdirectory(mousedragfilter) +endif() + if((PLATFORM EQUAL 32) AND (WIN32 OR APPLE)) add_subdirectory(t32bitsrv) endif() diff --git a/toonz/sources/mousedragfilter/CMakeLists.txt b/toonz/sources/mousedragfilter/CMakeLists.txt new file mode 100644 index 0000000..5158770 --- /dev/null +++ b/toonz/sources/mousedragfilter/CMakeLists.txt @@ -0,0 +1,10 @@ +if(APPLE) + cmake_minimum_required(VERSION 2.8.11) + project(MouseDragFilter) + + include_directories(.) + find_library(FOUNDATION_LIBRARY NAMES foundation) + find_library(CG_LIBRARY NAMES CoreGraphics) + add_library(mousedragfilter mousedragfilter.mm mousedragfilter.h) + target_link_libraries(mousedragfilter ${CG_LIBRARY} ${FOUNDATION_LIBRARY}) +endif() diff --git a/toonz/sources/mousedragfilter/mousedragfilter.h b/toonz/sources/mousedragfilter/mousedragfilter.h new file mode 100644 index 0000000..1f39281 --- /dev/null +++ b/toonz/sources/mousedragfilter/mousedragfilter.h @@ -0,0 +1,6 @@ +#pragma once +bool IsLeftMouseDragged(void *); +bool IsLeftMouseDown(void *); +bool IsLeftMouseUp(void *); +void MonitorNSMouseEvent(void *); +void SendLeftMousePressEvent(); diff --git a/toonz/sources/mousedragfilter/mousedragfilter.mm b/toonz/sources/mousedragfilter/mousedragfilter.mm new file mode 100644 index 0000000..a4a138f --- /dev/null +++ b/toonz/sources/mousedragfilter/mousedragfilter.mm @@ -0,0 +1,61 @@ +#include +#include "mousedragfilter.h" +#import +#import + + +bool IsLeftMouseDown(void *message){ + NSEvent * event = (NSEvent*)message; + if([event type] == NSLeftMouseDown){ + return true; + } + return false; +} + + +bool IsLeftMouseUp(void *message){ + NSEvent * event = (NSEvent*)message; + if([event type] == NSLeftMouseUp){ + return true; + } + return false; +} + + +bool IsLeftMouseDragged(void *message){ + NSEvent * event = (NSEvent*)message; + if([event type] == NSLeftMouseDragged){ + return true; + } + return false; +} + + +void MonitorNSMouseEvent(void *message){ + NSEvent * event = (NSEvent*)message; + switch ([event type]) { + case NSLeftMouseDown: + std::cout << "Lv" << std::endl; break; + case NSLeftMouseUp: + std::cout << "L^" << std::endl; break; + case NSRightMouseDown: + std::cout << "Rv" << std::endl; break; + case NSRightMouseUp: + std::cout << "R^" << std::endl; break; + case NSOtherMouseDown: + std::cout << [event buttonNumber] << "v" << std::endl; break; + case NSOtherMouseUp: + std::cout << [event buttonNumber] << "^" << std::endl; break; + default: + break; + } +} + + +void SendLeftMousePressEvent(){ + CGEventRef event = CGEventCreate(NULL); + CGPoint location = CGEventGetLocation(event); + CFRelease(event); + CGEventRef mouseDown = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, location, kCGMouseButtonLeft); + CGEventPost(kCGHIDEventTap, mouseDown); +} diff --git a/toonz/sources/toonz/CMakeLists.txt b/toonz/sources/toonz/CMakeLists.txt index 12c7927..c3d76c8 100644 --- a/toonz/sources/toonz/CMakeLists.txt +++ b/toonz/sources/toonz/CMakeLists.txt @@ -357,6 +357,12 @@ include_directories( ../../sources/toonzqt ) +if(APPLE) + include_directories(../../sources/mousedragfilter) +endif() + + + if(WIN32) if(PLATFORM EQUAL 32) include_directories( @@ -379,7 +385,9 @@ elseif(APPLE) # 変なところにライブラリ生成するカスども set(EXTRA_LIBS ${EXTRA_LIBS} "$" "$") - target_link_libraries(OpenToonz_${VERSION} Qt5::Core Qt5::Gui Qt5::Network Qt5::OpenGL Qt5::Svg Qt5::Xml Qt5::Script Qt5::Widgets Qt5::PrintSupport Qt5::Multimedia ${GL_LIB} ${GLUT_LIB} ${COCOA_LIB} ${EXTRA_LIBS}) + + target_link_libraries(OpenToonz_${VERSION} Qt5::Core Qt5::Gui Qt5::Network Qt5::OpenGL Qt5::Svg Qt5::Xml Qt5::Script Qt5::Widgets Qt5::PrintSupport Qt5::Multimedia ${GL_LIB} ${GLUT_LIB} ${COCOA_LIB} ${EXTRA_LIBS} mousedragfilter) + elseif(UNIX) _find_toonz_library(EXTRA_LIBS "tnzcore;tnzbase;toonzlib;colorfx;tnzext;image;sound;toonzqt;tnztools") @@ -509,4 +517,3 @@ exec \$OPENTOONZ_BASE/bin/OpenToonz_${VERSION} \"\$@\" ) endif() - diff --git a/toonz/sources/toonz/main.cpp b/toonz/sources/toonz/main.cpp index 586d4e6..00dd059 100644 --- a/toonz/sources/toonz/main.cpp +++ b/toonz/sources/toonz/main.cpp @@ -71,6 +71,8 @@ // Qt includes #include +#include +#include #include #include #include @@ -263,6 +265,42 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); +#ifdef MACOSX +// This workaround is to avoid missing left button problem on Qt5.6.0. +// To invalidate m_rightButtonClicked in Qt/qnsview.mm, sending NSLeftButtonDown +// event +// before NSLeftMouseDragged event propagated to QApplication. +// See more details in ../mousedragfilter/mousedragfilter.mm. + +#include "mousedragfilter.h" + + class OSXMouseDragFilter final : public QAbstractNativeEventFilter { + bool leftButtonPressed = false; + + public: + bool nativeEventFilter(const QByteArray &eventType, void *message, + long *) Q_DECL_OVERRIDE { + if (IsLeftMouseDown(message)) { + leftButtonPressed = true; + } + if (IsLeftMouseUp(message)) { + leftButtonPressed = false; + } + + if (eventType == "mac_generic_NSEvent") { + if (IsLeftMouseDragged(message) && !leftButtonPressed) { + std::cout << "force mouse press event" << std::endl; + SendLeftMousePressEvent(); + return true; + } + } + return false; + } + }; + + a.installNativeEventFilter(new OSXMouseDragFilter); +#endif + #ifdef Q_OS_WIN // Since currently OpenToonz does not work with OpenGL of software or // angle, @@ -483,7 +521,7 @@ int main(int argc, char *argv[]) { TApp::instance()->init(); // iwsw commented out temporarily -#if 0 +#if 0 QStringList monitorNames; /*-- 接続モニタがPVM-2541の場合のみLUTを読み込む --*/ if (Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled())