mirror of
https://github.com/debauchee/barrier.git
synced 2026-02-10 05:36:22 +08:00
moving 1.4 to trunk
This commit is contained in:
18
src/plugin/CMakeLists.txt
Normal file
18
src/plugin/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
# synergy -- mouse and keyboard sharing utility
|
||||
# Copyright (C) 2012 Nick Bolton
|
||||
#
|
||||
# This package is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# found in the file COPYING that should have accompanied this file.
|
||||
#
|
||||
# This package 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/>.
|
||||
|
||||
if (WIN32)
|
||||
add_subdirectory(winmmjoy)
|
||||
endif()
|
||||
33
src/plugin/winmmjoy/CMakeLists.txt
Normal file
33
src/plugin/winmmjoy/CMakeLists.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
# synergy -- mouse and keyboard sharing utility
|
||||
# Copyright (C) 2012 Nick Bolton
|
||||
#
|
||||
# This package is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# found in the file COPYING that should have accompanied this file.
|
||||
#
|
||||
# This package 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/>.
|
||||
|
||||
set(inc
|
||||
winmmjoy.h
|
||||
)
|
||||
|
||||
set(src
|
||||
winmmjoy.cpp
|
||||
${inc}
|
||||
)
|
||||
|
||||
add_library(winmmjoy SHARED ${inc} ${src})
|
||||
|
||||
add_custom_command(
|
||||
TARGET winmmjoy
|
||||
POST_BUILD
|
||||
COMMAND xcopy /Y /Q
|
||||
..\\..\\..\\..\\lib\\${CMAKE_CFG_INTDIR}\\winmmjoy.*
|
||||
..\\..\\..\\..\\bin\\${CMAKE_CFG_INTDIR}\\plugins\\
|
||||
)
|
||||
103
src/plugin/winmmjoy/winmmjoy.cpp
Normal file
103
src/plugin/winmmjoy/winmmjoy.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2012 Nick Bolton
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file COPYING that should have accompanied this file.
|
||||
*
|
||||
* This package 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/>.
|
||||
*/
|
||||
|
||||
#include "winmmjoy.h"
|
||||
|
||||
#include <MMSystem.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#pragma comment(lib, "winmm.lib")
|
||||
|
||||
std::stringstream _logStream;
|
||||
#define LOG(s) \
|
||||
_logStream.str(""); \
|
||||
_logStream << "winmmjoy: " << s << std::endl; \
|
||||
s_log( _logStream.str().c_str())
|
||||
|
||||
static bool s_running = true;
|
||||
static void (*s_sendEvent)(const char*, void*) = NULL;
|
||||
static void (*s_log)(const char*) = NULL;
|
||||
|
||||
extern "C" {
|
||||
|
||||
int
|
||||
init(void (*sendEvent)(const char*, void*), void (*log)(const char*))
|
||||
{
|
||||
s_sendEvent = sendEvent;
|
||||
s_log = log;
|
||||
LOG("init");
|
||||
CreateThread(NULL, 0, mainLoop, NULL, 0, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cleanup()
|
||||
{
|
||||
LOG("cleanup");
|
||||
s_running = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DWORD WINAPI
|
||||
mainLoop(void* data)
|
||||
{
|
||||
const char* buttonsEvent = "IPrimaryScreen::getGameDeviceButtonsEvent";
|
||||
const char* sticksEvent = "IPrimaryScreen::getGameDeviceSticksEvent";
|
||||
const char* triggersEvent = "IPrimaryScreen::getGameDeviceTriggersEvent";
|
||||
|
||||
JOYINFOEX joyInfo;
|
||||
ZeroMemory(&joyInfo, sizeof(joyInfo));
|
||||
joyInfo.dwSize = sizeof(joyInfo);
|
||||
joyInfo.dwFlags = JOY_RETURNALL;
|
||||
|
||||
// note: synergy data is often 16-bit, where winmm is 32-bit.
|
||||
UINT index = JOYSTICKID1;
|
||||
DWORD buttons, buttonsLast = 0;
|
||||
DWORD xPos, xPosLast = 0;
|
||||
DWORD yPos, yPosLast = 0;
|
||||
|
||||
while (s_running) {
|
||||
|
||||
if (joyGetPosEx(index, &joyInfo) != JOYERR_NOERROR) {
|
||||
Sleep(1000);
|
||||
continue;
|
||||
}
|
||||
|
||||
buttons = joyInfo.dwButtons;
|
||||
xPos = joyInfo.dwXpos;
|
||||
yPos = joyInfo.dwYpos;
|
||||
|
||||
if (buttons != buttonsLast) {
|
||||
s_sendEvent(buttonsEvent,
|
||||
new CGameDeviceButtonInfo(index, (GameDeviceButton)joyInfo.dwButtons));
|
||||
}
|
||||
|
||||
if (xPos != xPosLast || yPos != yPosLast) {
|
||||
s_sendEvent(sticksEvent,
|
||||
new CGameDeviceStickInfo(index, (short)xPos, (short)yPos, 0, 0));
|
||||
}
|
||||
|
||||
buttonsLast = buttons;
|
||||
xPosLast = xPos;
|
||||
yPosLast = yPos;
|
||||
Sleep(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
70
src/plugin/winmmjoy/winmmjoy.h
Normal file
70
src/plugin/winmmjoy/winmmjoy.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2012 Nick Bolton
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file COPYING that should have accompanied this file.
|
||||
*
|
||||
* This package 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
#if defined(winmmjoy_EXPORTS)
|
||||
#define WINMMJOY_API __declspec(dllexport)
|
||||
#else
|
||||
#define WINMMJOY_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
|
||||
WINMMJOY_API int init(void (*sendEvent)(const char*, void*), void (*log)(const char*));
|
||||
WINMMJOY_API int cleanup();
|
||||
|
||||
}
|
||||
|
||||
DWORD WINAPI mainLoop(void* data);
|
||||
|
||||
typedef unsigned char GameDeviceID;
|
||||
typedef unsigned short GameDeviceButton;
|
||||
|
||||
class CGameDeviceButtonInfo {
|
||||
public:
|
||||
CGameDeviceButtonInfo(GameDeviceID id, GameDeviceButton buttons) :
|
||||
m_id(id), m_buttons(buttons) { }
|
||||
public:
|
||||
GameDeviceID m_id;
|
||||
GameDeviceButton m_buttons;
|
||||
};
|
||||
|
||||
class CGameDeviceStickInfo {
|
||||
public:
|
||||
CGameDeviceStickInfo(GameDeviceID id, short x1, short y1, short x2, short y2) :
|
||||
m_id(id), m_x1(x1), m_x2(x2), m_y1(y1), m_y2(y2) { }
|
||||
public:
|
||||
GameDeviceID m_id;
|
||||
short m_x1;
|
||||
short m_x2;
|
||||
short m_y1;
|
||||
short m_y2;
|
||||
};
|
||||
|
||||
class CGameDeviceTriggerInfo {
|
||||
public:
|
||||
CGameDeviceTriggerInfo(GameDeviceID id, unsigned char t1, unsigned char t2) :
|
||||
m_id(id), m_t1(t1), m_t2(t2) { }
|
||||
public:
|
||||
GameDeviceID m_id;
|
||||
unsigned char m_t1;
|
||||
unsigned char m_t2;
|
||||
};
|
||||
Reference in New Issue
Block a user