workaround for missing left button on osx (#561)

* workaround for missing left button on osx

* change Qt path

* change CMake

* transfer filter's pointer to application directly

* rebase

* add final, delete virtual, and beautificate
This commit is contained in:
tomosu 2016-07-14 19:09:44 +09:00 committed by Shinya Kitaoka
parent a107c1293f
commit 9cb984e84d
6 changed files with 131 additions and 4 deletions

View file

@ -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()

View file

@ -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()

View file

@ -0,0 +1,6 @@
#pragma once
bool IsLeftMouseDragged(void *);
bool IsLeftMouseDown(void *);
bool IsLeftMouseUp(void *);
void MonitorNSMouseEvent(void *);
void SendLeftMousePressEvent();

View file

@ -0,0 +1,61 @@
#include <iostream>
#include "mousedragfilter.h"
#import <AppKit/AppKit.h>
#import <CoreGraphics/CoreGraphics.h>
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);
}

View file

@ -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_FILE:tnzstdfx>" "$<TARGET_FILE:tfarm>")
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()

View file

@ -71,6 +71,8 @@
// Qt includes
#include <QApplication>
#include <QAbstractEventDispatcher>
#include <QAbstractNativeEventFilter>
#include <QSplashScreen>
#include <QGLPixelBuffer>
#include <QTranslator>
@ -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())