Skip to content

Commit

Permalink
Merge pull request #142 from TauAkiou/master
Browse files Browse the repository at this point in the history
Linux Build Fixes
  • Loading branch information
JibbSmart authored Feb 8, 2021
2 parents 580e0f5 + 306f4dc commit 8e6e3c2
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 30 deletions.
2 changes: 1 addition & 1 deletion JoyShockMapper/include/JoyShockMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class Mapping
map<BtnEvent, OnEventAction> eventMapping;
float tapDurationMs = MAGIC_TAP_DURATION;
void InsertEventMapping(BtnEvent evt, OnEventAction action);
static void RunAllActions(DigitalButton *btn, int numEventActions, ...);
static void RunBothActions(DigitalButton *btn, OnEventAction action1, OnEventAction action2);

public:
Mapping() = default;
Expand Down
2 changes: 2 additions & 0 deletions JoyShockMapper/include/win32/WindowsTrayIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>
#include <map>
#include <string>
#include <atomic>

struct MenuItem;

Expand All @@ -17,6 +18,7 @@ class WindowsTrayIcon {
std::map<UINT_PTR, std::function<void()>> _clickMap;
HANDLE _thread;
std::function<void()> _beforeShow;
std::atomic_bool _init;

public:
WindowsTrayIcon(HINSTANCE hInstance, std::function<void()> beforeShow);
Expand Down
4 changes: 4 additions & 0 deletions JoyShockMapper/src/linux/InputHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,10 @@ std::string GetCWD()
return pathBuffer.get();
}

bool SetCWD(in_string newCWD) {
return chdir(newCWD.c_str()) != 0;
}

DWORD ShowOnlineHelp()
{
::system("xdg-open https://github.com/JibbSmart/JoyShockMapper/blob/master/README.md");
Expand Down
14 changes: 7 additions & 7 deletions JoyShockMapper/src/linux/PlatformDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "JoyShockMapper.h"
#include "PlatformDefinitions.h"

const char *AUTOLOAD_FOLDER = [] {
const char *AUTOLOAD_FOLDER() {
std::string directory;

const auto XDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME");
Expand All @@ -25,9 +25,9 @@ const char *AUTOLOAD_FOLDER = [] {

directory = directory + "/JoyShockMapper/AutoLoad/";
return strdup(directory.c_str());
}();
};

const char *GYRO_CONFIGS_FOLDER = [] {
const char *GYRO_CONFIGS_FOLDER() {
std::string directory;

const auto XDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME");
Expand All @@ -42,9 +42,9 @@ const char *GYRO_CONFIGS_FOLDER = [] {

directory = directory + "/JoyShockMapper/GyroConfigs/";
return strdup(directory.c_str());
}();
};

const char *BASE_JSM_CONFIG_FOLDER = [] {
const char *BASE_JSM_CONFIG_FOLDER() {
std::string directory;

const auto XDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME");
Expand All @@ -59,7 +59,7 @@ const char *BASE_JSM_CONFIG_FOLDER = [] {

directory = directory + "/JoyShockMapper/";
return strdup(directory.c_str());
}();
};

unsigned long GetCurrentProcessId()
{
Expand All @@ -73,7 +73,7 @@ unsigned long GetCurrentProcessId()
/// NONE
/// And characters: ; ' , . / \ [ ] + - `
/// Yes, this looks slow. But it's only there to help set up faster mappings
WORD KeyCode::nameToKey(const std::string &name)
WORD nameToKey(const std::string &name)
{
// https://msdn.microsoft.com/en-us/library/dd375731%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
auto length = name.length();
Expand Down
45 changes: 24 additions & 21 deletions JoyShockMapper/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class DigitalButton
}
}
// Chord stack should always include NONE which will provide a value in the loop above
throw exception("ChordStack should always include ButtonID::NONE, for the chorded variable to return the base value.");
throw runtime_error("ChordStack should always include ButtonID::NONE, for the chorded variable to return the base value.");
}
return _keyToRelease.get();
}
Expand Down Expand Up @@ -505,11 +505,15 @@ void Mapping::ProcessEvent(BtnEvent evt, DigitalButton &button, in_string displa
}
}

void Mapping::InsertEventMapping(BtnEvent evt, OnEventAction action)
{
auto existingActions = eventMapping.find(evt);
eventMapping[evt] = existingActions == eventMapping.end() ? action :
bind(&RunAllActions, placeholders::_1, 2, existingActions->second, action); // Chain with already existing mapping, if any
void Mapping::InsertEventMapping(BtnEvent evt, OnEventAction action) {
auto existingActions = eventMapping.find(evt);

if (existingActions == eventMapping.end()) {
eventMapping[evt] = action;
} else {
// Chain with already existing mapping, if any
eventMapping[evt] = bind(&RunBothActions, placeholders::_1, existingActions->second, action);
}
}

bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMod)
Expand Down Expand Up @@ -581,7 +585,7 @@ bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMo
case ActionModifier::Instant:
{
OnEventAction action2 = bind(&DigitalButton::RegisterInstant, placeholders::_1, applyEvt);
apply = bind(&Mapping::RunAllActions, placeholders::_1, 2, apply, action2);
apply = bind(&Mapping::RunBothActions, placeholders::_1, apply, action2);
releaseEvt = BtnEvent::OnInstantRelease;
} break;
case ActionModifier::INVALID:
Expand All @@ -595,18 +599,13 @@ bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMo
return true;
}

void Mapping::RunAllActions(DigitalButton *btn, int numEventActions, ...)

void Mapping::RunBothActions(DigitalButton *btn, OnEventAction action1, OnEventAction action2)
{
va_list arguments;
va_start(arguments, numEventActions);
for (int x = 0; x < numEventActions; x++)
{
auto action = va_arg(arguments, OnEventAction);
if(action)
action(btn);
}
va_end(arguments);
return;
if (action1)
action1(btn);
if (action2)
action2(btn);
}

// An instance of this class represents a single controller device that JSM is listening to.
Expand Down Expand Up @@ -2758,15 +2757,15 @@ int main(int argc, char *argv[]) {
newButton.SetFilter(&filterMapping);
mappings.push_back(newButton);
}
tray.reset(new TrayIcon(trayIconData, &beforeShowTrayMenu ));
// console
initConsole(&CleanUp);
printf("Welcome to JoyShockMapper version %s!\n", version);
//if (whitelister) printf("JoyShockMapper was successfully whitelisted!\n");
// prepare for input
connectDevices();
JslSetCallback(&joyShockPollCallback);
tray->Show();
tray.reset(new TrayIcon(trayIconData, &beforeShowTrayMenu ));
tray->Show();

left_stick_mode.SetFilter(&filterInvalidValue<StickMode, StickMode::INVALID>)->
AddOnChangeListener(bind(&UpdateRingModeFromStickMode, &left_ring_mode, ::placeholders::_1));
Expand Down Expand Up @@ -2833,7 +2832,11 @@ int main(int argc, char *argv[]) {
currentWorkingDir.SetFilter( [] (PathString current, PathString next) { return SetCWD(string(next)) ? next : current; });
autoloadSwitch.SetFilter(&filterInvalidValue<Switch, Switch::INVALID>)->AddOnChangeListener(&UpdateAutoload);

currentWorkingDir = string(&cmdLine[0], &cmdLine[wcslen(cmdLine)]);
#if _WIN32
currentWorkingDir = string(&cmdLine[0], &cmdLine[wcslen(cmdLine)]);
#else
currentWorkingDir = string(argv[0]);
#endif
CmdRegistry commandRegistry;

autoLoadThread.reset(new PollingThread(&AutoLoadPoll, &commandRegistry, 1000, true)); // Start by default
Expand Down
8 changes: 7 additions & 1 deletion JoyShockMapper/src/win32/WindowsTrayIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <memory.h>
#include <tchar.h>
#include <algorithm>
#include <chrono>

#include "win32/resource.h"
//#include "wintoastlib.h"
Expand Down Expand Up @@ -84,6 +85,7 @@ WindowsTrayIcon::WindowsTrayIcon(HINSTANCE hInstance, std::function<void()> befo
, _menuMap()
, _thread (0)
, _beforeShow(beforeShow)
,_init(false)
{
registry.push_back(this);

Expand All @@ -104,7 +106,9 @@ WindowsTrayIcon::WindowsTrayIcon(HINSTANCE hInstance, std::function<void()> befo
MessageHandlerLoop, // thread function name
this, // argument to thread function
0, // use default creation flags
nullptr); // returns the thread identifier
nullptr); // returns the thread identifier

Sleep(100); // Longest measured time was 33ms, but performance depends on CPU speed. 100ms should be plenty.
}

WindowsTrayIcon::~WindowsTrayIcon()
Expand Down Expand Up @@ -260,6 +264,8 @@ BOOL WindowsTrayIcon::InitInstance()

// call ShowWindow here to make the dialog initially visible

_init = true;

return TRUE;
}

Expand Down

0 comments on commit 8e6e3c2

Please sign in to comment.