@@ -252,7 +252,7 @@ class DigitalButton
252
252
}
253
253
}
254
254
// 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." );
256
256
}
257
257
return _keyToRelease.get ();
258
258
}
@@ -505,11 +505,15 @@ void Mapping::ProcessEvent(BtnEvent evt, DigitalButton &button, in_string displa
505
505
}
506
506
}
507
507
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
+ }
513
517
}
514
518
515
519
bool Mapping::AddMapping (KeyCode key, EventModifier evtMod, ActionModifier actMod)
@@ -581,7 +585,7 @@ bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMo
581
585
case ActionModifier::Instant:
582
586
{
583
587
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);
585
589
releaseEvt = BtnEvent::OnInstantRelease;
586
590
} break ;
587
591
case ActionModifier::INVALID:
@@ -595,18 +599,13 @@ bool Mapping::AddMapping(KeyCode key, EventModifier evtMod, ActionModifier actMo
595
599
return true ;
596
600
}
597
601
598
- void Mapping::RunAllActions (DigitalButton *btn, int numEventActions, ...)
602
+
603
+ void Mapping::RunBothActions (DigitalButton *btn, OnEventAction action1, OnEventAction action2)
599
604
{
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);
610
609
}
611
610
612
611
// 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[]) {
2758
2757
newButton.SetFilter (&filterMapping);
2759
2758
mappings.push_back (newButton);
2760
2759
}
2761
- tray.reset (new TrayIcon (trayIconData, &beforeShowTrayMenu ));
2762
2760
// console
2763
2761
initConsole (&CleanUp);
2764
2762
printf (" Welcome to JoyShockMapper version %s!\n " , version);
2765
2763
// if (whitelister) printf("JoyShockMapper was successfully whitelisted!\n");
2766
2764
// prepare for input
2767
2765
connectDevices ();
2768
2766
JslSetCallback (&joyShockPollCallback);
2769
- tray->Show ();
2767
+ tray.reset (new TrayIcon (trayIconData, &beforeShowTrayMenu ));
2768
+ tray->Show ();
2770
2769
2771
2770
left_stick_mode.SetFilter (&filterInvalidValue<StickMode, StickMode::INVALID>)->
2772
2771
AddOnChangeListener (bind (&UpdateRingModeFromStickMode, &left_ring_mode, ::placeholders::_1));
@@ -2833,7 +2832,11 @@ int main(int argc, char *argv[]) {
2833
2832
currentWorkingDir.SetFilter ( [] (PathString current, PathString next) { return SetCWD (string (next)) ? next : current; });
2834
2833
autoloadSwitch.SetFilter (&filterInvalidValue<Switch, Switch::INVALID>)->AddOnChangeListener (&UpdateAutoload);
2835
2834
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
2837
2840
CmdRegistry commandRegistry;
2838
2841
2839
2842
autoLoadThread.reset (new PollingThread (&AutoLoadPoll, &commandRegistry, 1000 , true )); // Start by default
0 commit comments