[Scummvm-git-logs] scummvm master -> a155061ee46b61c27d591b4135499785977ad43e

bgK bastien.bouclet at gmail.com
Wed Mar 11 05:17:21 UTC 2020


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
dbb2c73a6b KEYMAPPER: Update the logic for multiple global / game keymaps
a155061ee4 KEYMAPPER: Set the default virtual mouse settings


Commit: dbb2c73a6bb16e2c65b3ba2d0e815d314be9785d
    https://github.com/scummvm/scummvm/commit/dbb2c73a6bb16e2c65b3ba2d0e815d314be9785d
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2020-03-11T05:07:06+01:00

Commit Message:
KEYMAPPER: Update the logic for multiple global / game keymaps

It is valid for actions from different keymaps of the same type to be
triggered by a single event.

Changed paths:
    backends/keymapper/keymapper.cpp
    backends/keymapper/keymapper.h


diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp
index 72cdb9d281..37f1776689 100644
--- a/backends/keymapper/keymapper.cpp
+++ b/backends/keymapper/keymapper.cpp
@@ -40,7 +40,7 @@ Keymapper::Keymapper(EventManager *eventMan) :
 		_backendDefaultBindings(nullptr),
 		_delayedEventSource(new DelayedEventSource()),
 		_enabled(true),
-		_enabledKeymapType(Keymap::kKeymapTypeGlobal) {
+		_enabledKeymapType(Keymap::kKeymapTypeGame) {
 	_eventMan->getEventDispatcher()->registerSource(_delayedEventSource, true);
 	resetInputState();
 }
@@ -90,9 +90,7 @@ void Keymapper::addGlobalKeymap(Keymap *keymap) {
 
 	ConfigManager::Domain *keymapperDomain = ConfMan.getDomain(ConfigManager::kKeymapperDomain);
 	initKeymap(keymap, keymapperDomain);
-
-	// Global keymaps have the lowest priority, they need to be first in the array
-	_keymaps.insert_at(0, keymap);
+	_keymaps.push_back(keymap);
 }
 
 void Keymapper::addGameKeymap(Keymap *keymap) {
@@ -150,10 +148,10 @@ void Keymapper::reloadAllMappings() {
 }
 
 void Keymapper::setEnabledKeymapType(Keymap::KeymapType type) {
+	assert(type == Keymap::kKeymapTypeGui || type == Keymap::kKeymapTypeGame);
 	_enabledKeymapType = type;
 }
 
-
 List<Event> Keymapper::mapEvent(const Event &ev) {
 	if (!_enabled) {
 		List<Event> originalEvent;
@@ -164,19 +162,49 @@ List<Event> Keymapper::mapEvent(const Event &ev) {
 	hardcodedEventMapping(ev);
 
 	List<Event> mappedEvents;
-	for (int i = _keymaps.size() - 1; i >= 0; --i) {
-		if (!_keymaps[i]->isEnabled()) {
-			continue;
+	if (!mapEvent(ev, _enabledKeymapType, mappedEvents)) {
+		// If we found actions matching this input in the game / gui keymaps,
+		// no need to look at the global keymaps. An input resulting in actions
+		// from system and game keymaps would lead to unexpected user experience.
+		mapEvent(ev, Keymap::kKeymapTypeGlobal, mappedEvents);
+	}
+
+	if (ev.type == EVENT_JOYAXIS_MOTION && ev.joystick.axis < ARRAYSIZE(_joystickAxisPreviouslyPressed)) {
+		if (ABS<int32>(ev.joystick.position) >= kJoyAxisPressedTreshold) {
+			_joystickAxisPreviouslyPressed[ev.joystick.axis] = true;
+		} else if (ABS<int32>(ev.joystick.position) < kJoyAxisUnpressedTreshold) {
+			_joystickAxisPreviouslyPressed[ev.joystick.axis] = false;
 		}
+	}
+
+	// Ignore keyboard repeat events. Repeat event are meant for text input,
+	// the keymapper / keymaps are supposed to be disabled during text input.
+	// TODO: Add a way to keep repeat events if needed.
+	if (!mappedEvents.empty() && ev.type == EVENT_KEYDOWN && ev.kbdRepeat) {
+		return List<Event>();
+	}
+
+	if (mappedEvents.empty()) {
+		// if it didn't get mapped, just pass it through
+		mappedEvents.push_back(ev);
+	}
+
+	return mappedEvents;
+}
+
+bool Keymapper::mapEvent(const Event &ev, Keymap::KeymapType keymapType, List<Event> &mappedEvents) {
+	bool matchedAction = false;
 
-		Keymap::KeymapType keymapType = _keymaps[i]->getType();
-		if (keymapType != _enabledKeymapType && keymapType != Keymap::kKeymapTypeGlobal) {
-			continue; // Ignore GUI keymaps while in game and vice versa
+	for (uint i = 0; i < _keymaps.size(); i++) {
+		if (!_keymaps[i]->isEnabled() || _keymaps[i]->getType() != keymapType) {
+			continue;
 		}
 
-		//debug(9, "Keymapper::mapKey keymap: %s", _keymaps[i]->getId().c_str());
+		Keymap::ActionArray actions = _keymaps[i]->getMappedActions(ev);
+		if (!actions.empty()) {
+			matchedAction = true;
+		}
 
-		const Keymap::ActionArray &actions = _keymaps[i]->getMappedActions(ev);
 		for (Keymap::ActionArray::const_iterator it = actions.begin(); it != actions.end(); it++) {
 			Event mappedEvent = executeAction(*it, ev);
 			if (mappedEvent.type == EVENT_INVALID) {
@@ -197,34 +225,9 @@ List<Event> Keymapper::mapEvent(const Event &ev) {
 
 			mappedEvents.push_back(mappedEvent);
 		}
-		if (!actions.empty()) {
-			// If we found actions matching this input in a keymap, no need to look at the other keymaps.
-			// An input resulting in actions from system and game keymaps would lead to unexpected user experience.
-			break;
-		}
-	}
-
-	if (ev.type == EVENT_JOYAXIS_MOTION && ev.joystick.axis < ARRAYSIZE(_joystickAxisPreviouslyPressed)) {
-		if (ABS<int32>(ev.joystick.position) >= kJoyAxisPressedTreshold) {
-			_joystickAxisPreviouslyPressed[ev.joystick.axis] = true;
-		} else if (ABS<int32>(ev.joystick.position) < kJoyAxisUnpressedTreshold) {
-			_joystickAxisPreviouslyPressed[ev.joystick.axis] = false;
-		}
 	}
 
-	// Ignore keyboard repeat events. Repeat event are meant for text input,
-	// the keymapper / keymaps are supposed to be disabled during text input.
-	// TODO: Add a way to keep repeat events if needed.
-	if (!mappedEvents.empty() && ev.type == EVENT_KEYDOWN && ev.kbdRepeat) {
-		return List<Event>();
-	}
-
-	if (mappedEvents.empty()) {
-		// if it didn't get mapped, just pass it through
-		mappedEvents.push_back(ev);
-	}
-
-	return mappedEvents;
+	return matchedAction;
 }
 
 Keymapper::IncomingEventType Keymapper::convertToIncomingEventType(const Event &ev) const {
diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h
index 6f1cf1cb88..9e524ec33a 100644
--- a/backends/keymapper/keymapper.h
+++ b/backends/keymapper/keymapper.h
@@ -157,6 +157,7 @@ private:
 
 	bool _joystickAxisPreviouslyPressed[6];
 
+	bool mapEvent(const Event &ev, Keymap::KeymapType keymapType, List<Event> &mappedEvents);
 	Event executeAction(const Action *act, const Event &incomingEvent);
 	EventType convertStartToEnd(EventType eventType);
 	IncomingEventType convertToIncomingEventType(const Event &ev) const;


Commit: a155061ee46b61c27d591b4135499785977ad43e
    https://github.com/scummvm/scummvm/commit/a155061ee46b61c27d591b4135499785977ad43e
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2020-03-11T06:15:46+01:00

Commit Message:
KEYMAPPER: Set the default virtual mouse settings

Fixes the 3DS mouse cursor drifting.

Changed paths:
    backends/events/sdl/legacy-sdl-events.cpp
    backends/keymapper/virtual-mouse.cpp
    backends/platform/sdl/sdl.cpp


diff --git a/backends/events/sdl/legacy-sdl-events.cpp b/backends/events/sdl/legacy-sdl-events.cpp
index b02dbd2532..5dfa87673c 100644
--- a/backends/events/sdl/legacy-sdl-events.cpp
+++ b/backends/events/sdl/legacy-sdl-events.cpp
@@ -33,6 +33,9 @@
 LegacySdlEventSource::LegacySdlEventSource() {
 	// Reset mouse state
 	memset(&_km, 0, sizeof(_km));
+
+	ConfMan.registerDefault("kbdmouse_speed", 3);
+	ConfMan.registerDefault("joystick_deadzone", 3);
 }
 
 void LegacySdlEventSource::updateKbdMouse() {
diff --git a/backends/keymapper/virtual-mouse.cpp b/backends/keymapper/virtual-mouse.cpp
index 0adf3a2a92..09f528700d 100644
--- a/backends/keymapper/virtual-mouse.cpp
+++ b/backends/keymapper/virtual-mouse.cpp
@@ -43,6 +43,9 @@ VirtualMouse::VirtualMouse(EventDispatcher *eventDispatcher) :
 		_subPixelRemainderX(0.f),
 		_subPixelRemainderY(0.f),
 		_lastUpdateMillis(0) {
+	ConfMan.registerDefault("kbdmouse_speed", 3);
+	ConfMan.registerDefault("joystick_deadzone", 3);
+
 	_eventDispatcher->registerSource(this, false);
 	_eventDispatcher->registerObserver(this, 10, false);
 }
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index ba10c5d066..f4cb7a0678 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -86,9 +86,6 @@ OSystem_SDL::OSystem_SDL()
 	_mixerManager(0),
 	_eventSource(0),
 	_window(0) {
-
-	ConfMan.registerDefault("kbdmouse_speed", 3);
-	ConfMan.registerDefault("joystick_deadzone", 3);
 }
 
 OSystem_SDL::~OSystem_SDL() {




More information about the Scummvm-git-logs mailing list