Skip to content
This repository was archived by the owner on Jan 4, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.o
.*.swp
.directory
.vscode
*.qm
*.diff
*.mo
Expand Down
62 changes: 54 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ if(UNIX)
option(WITH_X11 "Compile with support for X11." ON)
option(WITH_UINPUT "Compile with support for uinput. uinput will be usable to simulate events." OFF)
option(WITH_XTEST "Compile with support for XTest. XTest will be usable to simulate events." ON)
if(APPLE)
message("Using cocoa.")
option(WITH_COCOA "Compile with support for Cocoa." ON)
endif(APPLE)
option(APPDATA "Build project with AppData file support." OFF)
endif(UNIX)

Expand Down Expand Up @@ -115,9 +119,9 @@ if(UNIX)
message("uinput support allowed for simulating events.")
endif(WITH_UINPUT)

if(NOT WITH_XTEST AND NOT WITH_UINPUT)
if(NOT WITH_XTEST AND NOT WITH_UINPUT AND NOT WITH_COCOA)
message(FATAL_ERROR "No system is defined for simulating events.")
endif(NOT WITH_XTEST AND NOT WITH_UINPUT)
endif(NOT WITH_XTEST AND NOT WITH_UINPUT AND NOT WITH_COCOA)
endif(UNIX)

set(antimicro_SOURCES src/main.cpp
Expand Down Expand Up @@ -375,6 +379,21 @@ if(UNIX)
endif(WITH_XTEST)
endif(WITH_X11)

if(WITH_COCOA)
LIST(APPEND antimicro_SOURCES src/qtcocoakeymapper.cpp
src/cocoahelper.cpp
src/eventhandlers/cocoaeventhandler.mm
src/cocoaappdelegateadapter.mm
src/cocoaappdelegate.m
src/capturedwindowinfodialog.cpp
)
LIST(APPEND antimicro_HEADERS src/qtcocoakeymapper.h
src/cocoahelper.h
src/eventhandlers/cocoaeventhandler.h
src/capturedwindowinfodialog.h
)
endif(WITH_COCOA)

if(WITH_UINPUT)
LIST(APPEND antimicro_SOURCES src/qtuinputkeymapper.cpp
src/uinputhelper.cpp
Expand Down Expand Up @@ -484,6 +503,10 @@ if(UNIX)
if(WITH_UINPUT)
add_definitions(-DWITH_UINPUT)
endif(WITH_UINPUT)

if(WITH_COCOA)
add_definitions(-DWITH_COCOA)
endif(WITH_COCOA)
endif(UNIX)

if (UNIX)
Expand Down Expand Up @@ -577,6 +600,11 @@ elseif(WIN32)
endif(UNIX)

if(UNIX)
if(WITH_COCOA)
FIND_LIBRARY(COCOA_LIBRARY Cocoa)
LIST(APPEND LIBS ${COCOA_LIBRARY})
endif(WITH_COCOA)

if(WITH_X11)
LIST(APPEND LIBS ${X11_X11_LIB})
LIST(APPEND LIBS ${X11_Xi_LIB})
Expand All @@ -588,6 +616,7 @@ if(UNIX)

if(USE_SDL_2)
list(APPEND LIBS ${SDL2_LIBRARIES})
link_directories(${SDL2_LIBRARY_DIRS})
else()
list(APPEND LIBS ${SDL_LIBRARIES})
endif(USE_SDL_2)
Expand Down Expand Up @@ -668,10 +697,25 @@ endif(UNIX)

if(USE_QT5)
if(UNIX)
add_executable(antimicro ${antimicro_SOURCES}
${antimicro_FORMS_HEADERS}
${antimicro_RESOURCES_RCC}
)
if(APPLE)

set (ICON_NAME antimicro.icns)
set (ICON_PATH ${PROJECT_SOURCE_DIR}/src/images/${ICON_NAME})
set (BUILD_FLAGS MACOSX_BUNDLE)
set (MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
set_source_files_properties (${ICON_PATH} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
add_executable(antimicro ${BUILD_FLAGS}
${antimicro_SOURCES}
${antimicro_FORMS_HEADERS}
${antimicro_RESOURCES_RCC}
${ICON_PATH}
)
else()
add_executable(antimicro ${antimicro_SOURCES}
${antimicro_FORMS_HEADERS}
${antimicro_RESOURCES_RCC}
)
endif(APPLE)
elseif(WIN32)
# The WIN32 is required to specify a GUI application.
add_executable(antimicro WIN32 ${antimicro_SOURCES}
Expand All @@ -696,9 +740,11 @@ target_link_libraries(antimicro ${LIBS})

# Specify out directory for final executable.
if(UNIX)
install(TARGETS antimicro RUNTIME DESTINATION "bin")
if(NOT APPLE)
install(TARGETS antimicro RUNTIME DESTINATION "bin")
endif(NOT APPLE)
elseif(WIN32)
install(TARGETS antimicro RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
install(TARGETS antimicro RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
endif(UNIX)

if(UNIX)
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,20 @@ Notes about the WXS file and the building process :

* built MSI package will be placed in /windows

## Building under macOS

* Install Qt 5 and SDL2 using [Homebrew](https://brew.sh): `brew install qt sdl2`

* Create a build directory and invoke CMake:

```bash
cd antimicro
mkdir build && cd build
CMAKE_PREFIX_PATH=/usr/local/Cellar/qt/YOUR_QT_VERSION cmake .. -DWITH_XTEST=OFF -DWITH_X11=OFF -DWITH_COCOA=ON
make
```


## Testing under Linux

If you are having problems with antimicro detecting a controller or
Expand Down
4 changes: 4 additions & 0 deletions src/addeditautoprofiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#include <QApplication>
#endif

#ifdef WITH_COCOA
#include "capturedwindowinfodialog.h"
#endif

#elif defined(Q_OS_WIN)
#include "winappprofiletimerdialog.h"
#include "capturedwindowinfodialog.h"
Expand Down
6 changes: 6 additions & 0 deletions src/advancebuttondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ AdvanceButtonDialog::AdvanceButtonDialog(JoyButton *button, QWidget *parent) :
connect(ui->turboModeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setButtonTurboMode(int)));
connect(ui->loadProfilePushButton, SIGNAL(clicked()), this, SLOT(showSelectProfileWindow()));
connect(ui->execToolButton, SIGNAL(clicked(bool)), this, SLOT(showFindExecutableWindow(bool)));

#ifdef WITH_COCOA
// Not inplemented
ui->slotTypeComboBox->removeItem(TextEntry);
#endif

}

AdvanceButtonDialog::~AdvanceButtonDialog()
Expand Down
11 changes: 11 additions & 0 deletions src/antkeymapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ static QStringList buildEventGeneratorList()
#ifdef WITH_UINPUT
temp.append("uinput");
#endif
#ifdef WITH_COCOA
temp.append("cocoa");
#endif

#endif
return temp;
Expand Down Expand Up @@ -75,6 +78,14 @@ AntKeyMapper::AntKeyMapper(QString handler, QObject *parent) :
}
#endif

#ifdef WITH_COCOA
if (handler == "cocoa")
{
internalMapper = &cocoaMapper;
nativeKeyMapper = 0;
}
#endif

#ifdef WITH_UINPUT
if (handler == "uinput")
{
Expand Down
8 changes: 8 additions & 0 deletions src/antkeymapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#if defined(WITH_UINPUT)
#include "qtuinputkeymapper.h"
#endif

#if defined(WITH_COCOA)
#include "qtcocoakeymapper.h"
#endif
#endif

class AntKeyMapper : public QObject
Expand Down Expand Up @@ -74,6 +78,10 @@ class AntKeyMapper : public QObject
QtUInputKeyMapper uinputMapper;
#endif

#if defined(WITH_COCOA)
QtCocoaKeyMapper cocoaMapper;
#endif

#endif

signals:
Expand Down
4 changes: 4 additions & 0 deletions src/buttoneditdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ void ButtonEditDialog::keyReleaseEvent(QKeyEvent *event)
checkalias = AntKeyMapper::getInstance()->returnQtKey(finalvirtual, controlcode);
}

#elif defined(WITH_COCOA)
int finalvirtual = 0;
int checkalias = 0;
virtualactual = event->key();
#else

#if defined(WITH_X11)
Expand Down
8 changes: 4 additions & 4 deletions src/capturedwindowinfodialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#ifdef Q_OS_WIN
#include "winextras.h"
#else
#elif defined(WITH_X11)
#include "x11extras.h"
#endif

Expand All @@ -39,7 +39,7 @@ CapturedWindowInfoDialog::CapturedWindowInfoDialog(unsigned long window, QWidget

selectedMatch = WindowNone;

#ifdef Q_OS_UNIX
#if defined(Q_OS_UNIX) && defined(WITH_X11)
X11Extras *info = X11Extras::getInstance();
ui->winPathChoiceComboBox->setVisible(false);
#endif
Expand All @@ -51,7 +51,7 @@ CapturedWindowInfoDialog::CapturedWindowInfoDialog(unsigned long window, QWidget
ui->winClassCheckBox->setVisible(false);
ui->winClassLabel->setVisible(false);
ui->winClassHeadLabel->setVisible(false);
#else
#elif defined(Q_OS_UNIX) && defined(WITH_X11)
winClass = info->getWindowClass(window);
ui->winClassLabel->setText(winClass);
if (winClass.isEmpty())
Expand All @@ -71,7 +71,7 @@ CapturedWindowInfoDialog::CapturedWindowInfoDialog(unsigned long window, QWidget

#ifdef Q_OS_WIN
winName = WinExtras::getCurrentWindowText();
#else
#elif defined(Q_OS_UNIX) && defined(WITH_X11)
winName = info->getWindowTitle(window);
#endif

Expand Down
22 changes: 22 additions & 0 deletions src/cocoaappdelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* antimicro Gamepad to KB+M event mapper
* Copyright (C) 2015 Travis Nickles <nickles.travis@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#import <Cocoa/Cocoa.h>

@interface CocoaAppDelegate : NSObject <NSApplicationDelegate>

@end
59 changes: 59 additions & 0 deletions src/cocoaappdelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* antimicro Gamepad to KB+M event mapper
* Copyright (C) 2015 Travis Nickles <nickles.travis@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#import "cocoaappdelegate.h"

@interface CocoaAppDelegate ()

@property(nonatomic) id <NSObject> activityToken;

- (void)disableAppNap;

@end

@implementation CocoaAppDelegate

- (void)dealloc
{
[super dealloc];
}

- (void)disableAppNap
{
NSActivityOptions options = NSActivityUserInitiatedAllowingIdleSystemSleep;
id <NSObject> activity = [[NSProcessInfo processInfo] beginActivityWithOptions:options reason:@"Disabled AppNap"];
[self setActivityToken:activity];
[[self activityToken] retain];
NSLog(@"Disabled AppNap");
}

- (void)applicationDidFinishLaunching:(NSNotification*)notification
{
[self disableAppNap];
}

- (void)applicationWillTerminate:(NSNotification*)notification
{
[[NSProcessInfo processInfo] endActivity:[self activityToken]];
if ([self activityToken] != nil) {
[[self activityToken] release];
[self setActivityToken:nil];
}
NSLog(@"Terminating application!");
}

@end
35 changes: 35 additions & 0 deletions src/cocoaappdelegateadapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* antimicro Gamepad to KB+M event mapper
* Copyright (C) 2015 Travis Nickles <nickles.travis@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef COCOAAPPDELEGATEINTERFACE_H
#define COCOAAPPDELEGATEINTERFACE_H

#import <QObject>

class CocoaAppDelegateAdapter : public QObject
{
Q_OBJECT
public:
explicit CocoaAppDelegateAdapter(QObject *parent = 0);
virtual ~CocoaAppDelegateAdapter();

void registerDelegate();
private:
void *delegate;
};

#endif // COCOAAPPDELEGATEINTERFACE_H
Loading