From b9000dd5a9e6024bfbd4bab7d39f3a2eeb1e4d8e Mon Sep 17 00:00:00 2001 From: June Tate-Gans Date: Wed, 28 Apr 2021 23:31:29 -0500 Subject: [PATCH] g13d: Add in the ability to unbind keys This allows us to unbind keys and leave them natural in the GUI. --- g13d/action.h | 4 ++++ g13d/device.cc | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/g13d/action.h b/g13d/action.h index 23f696f..424ecea 100644 --- a/g13d/action.h +++ b/g13d/action.h @@ -118,6 +118,10 @@ class Actionable { return _parent_ptr->manager(); } + virtual void clear_action() { + _action.reset(); + } + virtual void set_action(const ActionPtr &action) { _action = action; } diff --git a/g13d/device.cc b/g13d/device.cc index 536375c..7e6b2b4 100644 --- a/g13d/device.cc +++ b/g13d/device.cc @@ -434,6 +434,23 @@ void Device::_init_commands() { } } + G13_DEVICE_COMMAND(unbind) { + std::string keyname = remainder; + try { + if (auto key = _current_profile->find_key(keyname)) { + key->clear_action(); + } else if (auto stick_key = _stick.zone(keyname)) { + stick_key->clear_action(); + } else { + RETURN_FAIL("unbind key " << keyname << " unknown"); + } + G13_LOG(trace, "unbind " << keyname); + } catch (const std::exception &ex) { + RETURN_FAIL("unbind " << keyname + << " failed : " << ex.what()) + } + } + G13_DEVICE_COMMAND(profile) { switch_to_profile(remainder); }