Skip to content

Commit 8e6e3c2

Browse files
authored
Merge pull request #142 from TauAkiou/master
Linux Build Fixes
2 parents 580e0f5 + 306f4dc commit 8e6e3c2

File tree

6 files changed

+45
-30
lines changed

6 files changed

+45
-30
lines changed

JoyShockMapper/include/JoyShockMapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class Mapping
292292
map<BtnEvent, OnEventAction> eventMapping;
293293
float tapDurationMs = MAGIC_TAP_DURATION;
294294
void InsertEventMapping(BtnEvent evt, OnEventAction action);
295-
static void RunAllActions(DigitalButton *btn, int numEventActions, ...);
295+
static void RunBothActions(DigitalButton *btn, OnEventAction action1, OnEventAction action2);
296296

297297
public:
298298
Mapping() = default;

JoyShockMapper/include/win32/WindowsTrayIcon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <vector>
88
#include <map>
99
#include <string>
10+
#include <atomic>
1011

1112
struct MenuItem;
1213

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

2123
public:
2224
WindowsTrayIcon(HINSTANCE hInstance, std::function<void()> beforeShow);

JoyShockMapper/src/linux/InputHelpers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,10 @@ std::string GetCWD()
696696
return pathBuffer.get();
697697
}
698698

699+
bool SetCWD(in_string newCWD) {
700+
return chdir(newCWD.c_str()) != 0;
701+
}
702+
699703
DWORD ShowOnlineHelp()
700704
{
701705
::system("xdg-open https://github.com/JibbSmart/JoyShockMapper/blob/master/README.md");

JoyShockMapper/src/linux/PlatformDefinitions.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "JoyShockMapper.h"
1111
#include "PlatformDefinitions.h"
1212

13-
const char *AUTOLOAD_FOLDER = [] {
13+
const char *AUTOLOAD_FOLDER() {
1414
std::string directory;
1515

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

2626
directory = directory + "/JoyShockMapper/AutoLoad/";
2727
return strdup(directory.c_str());
28-
}();
28+
};
2929

30-
const char *GYRO_CONFIGS_FOLDER = [] {
30+
const char *GYRO_CONFIGS_FOLDER() {
3131
std::string directory;
3232

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

4343
directory = directory + "/JoyShockMapper/GyroConfigs/";
4444
return strdup(directory.c_str());
45-
}();
45+
};
4646

47-
const char *BASE_JSM_CONFIG_FOLDER = [] {
47+
const char *BASE_JSM_CONFIG_FOLDER() {
4848
std::string directory;
4949

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

6060
directory = directory + "/JoyShockMapper/";
6161
return strdup(directory.c_str());
62-
}();
62+
};
6363

6464
unsigned long GetCurrentProcessId()
6565
{
@@ -73,7 +73,7 @@ unsigned long GetCurrentProcessId()
7373
/// NONE
7474
/// And characters: ; ' , . / \ [ ] + - `
7575
/// Yes, this looks slow. But it's only there to help set up faster mappings
76-
WORD KeyCode::nameToKey(const std::string &name)
76+
WORD nameToKey(const std::string &name)
7777
{
7878
// https://msdn.microsoft.com/en-us/library/dd375731%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
7979
auto length = name.length();

JoyShockMapper/src/main.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class DigitalButton
252252
}
253253
}
254254
// Chord stack should always include NONE which will provide a value in the loop above
255-
throw exception("ChordStack should always include ButtonID::NONE, for the chorded variable to return the base value.");
255+
throw runtime_error("ChordStack should always include ButtonID::NONE, for the chorded variable to return the base value.");
256256
}
257257
return _keyToRelease.get();
258258
}
@@ -505,11 +505,15 @@ void Mapping::ProcessEvent(BtnEvent evt, DigitalButton &button, in_string displa
505505
}
506506
}
507507

508-
void Mapping::InsertEventMapping(BtnEvent evt, OnEventAction action)
509-
{
510-
auto existingActions = eventMapping.find(evt);
511-
eventMapping[evt] = existingActions == eventMapping.end() ? action :
512-
bind(&RunAllActions, placeholders::_1, 2, existingActions->second, action); // Chain with already existing mapping, if any
508+
void Mapping::InsertEventMapping(BtnEvent evt, OnEventAction action) {
509+
auto existingActions = eventMapping.find(evt);
510+
511+
if (existingActions == eventMapping.end()) {
512+
eventMapping[evt] = action;
513+
} else {
514+
// Chain with already existing mapping, if any
515+
eventMapping[evt] = bind(&RunBothActions, placeholders::_1, existingActions->second, action);
516+
}
513517
}
514518

515519
bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMod)
@@ -581,7 +585,7 @@ bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMo
581585
case ActionModifier::Instant:
582586
{
583587
OnEventAction action2 = bind(&DigitalButton::RegisterInstant, placeholders::_1, applyEvt);
584-
apply = bind(&Mapping::RunAllActions, placeholders::_1, 2, apply, action2);
588+
apply = bind(&Mapping::RunBothActions, placeholders::_1, apply, action2);
585589
releaseEvt = BtnEvent::OnInstantRelease;
586590
} break;
587591
case ActionModifier::INVALID:
@@ -595,18 +599,13 @@ bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMo
595599
return true;
596600
}
597601

598-
void Mapping::RunAllActions(DigitalButton *btn, int numEventActions, ...)
602+
603+
void Mapping::RunBothActions(DigitalButton *btn, OnEventAction action1, OnEventAction action2)
599604
{
600-
va_list arguments;
601-
va_start(arguments, numEventActions);
602-
for (int x = 0; x < numEventActions; x++)
603-
{
604-
auto action = va_arg(arguments, OnEventAction);
605-
if(action)
606-
action(btn);
607-
}
608-
va_end(arguments);
609-
return;
605+
if (action1)
606+
action1(btn);
607+
if (action2)
608+
action2(btn);
610609
}
611610

612611
// An instance of this class represents a single controller device that JSM is listening to.
@@ -2758,15 +2757,15 @@ int main(int argc, char *argv[]) {
27582757
newButton.SetFilter(&filterMapping);
27592758
mappings.push_back(newButton);
27602759
}
2761-
tray.reset(new TrayIcon(trayIconData, &beforeShowTrayMenu ));
27622760
// console
27632761
initConsole(&CleanUp);
27642762
printf("Welcome to JoyShockMapper version %s!\n", version);
27652763
//if (whitelister) printf("JoyShockMapper was successfully whitelisted!\n");
27662764
// prepare for input
27672765
connectDevices();
27682766
JslSetCallback(&joyShockPollCallback);
2769-
tray->Show();
2767+
tray.reset(new TrayIcon(trayIconData, &beforeShowTrayMenu ));
2768+
tray->Show();
27702769

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

2836-
currentWorkingDir = string(&cmdLine[0], &cmdLine[wcslen(cmdLine)]);
2835+
#if _WIN32
2836+
currentWorkingDir = string(&cmdLine[0], &cmdLine[wcslen(cmdLine)]);
2837+
#else
2838+
currentWorkingDir = string(argv[0]);
2839+
#endif
28372840
CmdRegistry commandRegistry;
28382841

28392842
autoLoadThread.reset(new PollingThread(&AutoLoadPoll, &commandRegistry, 1000, true)); // Start by default

JoyShockMapper/src/win32/WindowsTrayIcon.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <memory.h>
1818
#include <tchar.h>
1919
#include <algorithm>
20+
#include <chrono>
2021

2122
#include "win32/resource.h"
2223
//#include "wintoastlib.h"
@@ -84,6 +85,7 @@ WindowsTrayIcon::WindowsTrayIcon(HINSTANCE hInstance, std::function<void()> befo
8485
, _menuMap()
8586
, _thread (0)
8687
, _beforeShow(beforeShow)
88+
,_init(false)
8789
{
8890
registry.push_back(this);
8991

@@ -104,7 +106,9 @@ WindowsTrayIcon::WindowsTrayIcon(HINSTANCE hInstance, std::function<void()> befo
104106
MessageHandlerLoop, // thread function name
105107
this, // argument to thread function
106108
0, // use default creation flags
107-
nullptr); // returns the thread identifier
109+
nullptr); // returns the thread identifier
110+
111+
Sleep(100); // Longest measured time was 33ms, but performance depends on CPU speed. 100ms should be plenty.
108112
}
109113

110114
WindowsTrayIcon::~WindowsTrayIcon()
@@ -260,6 +264,8 @@ BOOL WindowsTrayIcon::InitInstance()
260264

261265
// call ShowWindow here to make the dialog initially visible
262266

267+
_init = true;
268+
263269
return TRUE;
264270
}
265271

0 commit comments

Comments
 (0)