Skip to content

Commit

Permalink
Added keymapperctl --input and --output. 2nd
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed Sep 1, 2024
1 parent b2e8e51 commit 971e163
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/config/get_key_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Key get_key_by_name(std::string_view name) {
return Key::Shift;
if (name == "Control")
return Key::Control;
if (name == "Meta")
if (name == "Meta")
return Key::Meta;

// allow some aliases
Expand Down
40 changes: 27 additions & 13 deletions src/runtime/Stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ namespace {
return false;
}

bool has_device_filter(const Stage::Context& context) {
return (context.device_filter ||
context.device_id_filter);
}

bool has_device_filter(const std::vector<Stage::Context>& contexts) {
for (const auto& context : contexts)
if (context.device_filter ||
context.device_id_filter)
if (has_device_filter(context))
return true;
return false;
}
Expand Down Expand Up @@ -160,21 +164,31 @@ std::vector<Key> Stage::get_output_keys_down() const {
}

void Stage::evaluate_device_filters(const std::vector<DeviceDesc>& device_descs) {
for (auto& context : m_contexts) {
context.matching_device_bits = { };
auto bit = decltype(context.matching_device_bits){ 1 };
for (const auto& device_desc : device_descs) {
if (context.device_filter.matches(device_desc.name, false) &&
context.device_id_filter.matches(device_desc.id, false))
context.matching_device_bits |= bit;
bit <<= 1;
for (auto& context : m_contexts)
if (has_device_filter(context)) {
context.matching_device_bits = { };
auto bit = decltype(context.matching_device_bits){ 1 };
for (const auto& device_desc : device_descs) {
if (context.device_filter.matches(device_desc.name, false) &&
context.device_id_filter.matches(device_desc.id, false))
context.matching_device_bits |= bit;
bit <<= 1;
}
}
else {
context.matching_device_bits = all_device_bits;
}
}
}

bool Stage::device_matches_filter(const Context& context, int device_index) const {
return (device_index == any_device_index ||
((context.matching_device_bits >> device_index) & 1));
if (device_index == any_device_index)
return true;

// no-device only matches contexts with default device
if (device_index == no_device_index)
return (context.matching_device_bits == all_device_bits);

return ((context.matching_device_bits >> device_index) & 1);
}

KeySequence Stage::set_active_client_contexts(const std::vector<int> &indices) {
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/Stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Stage {
public:
static const int no_device_index = -1;
static const int any_device_index = -2;
static const uint64_t all_device_bits = ~uint64_t{ };

struct Input {
KeySequence input;
Expand All @@ -31,7 +32,7 @@ class Stage {
Filter device_filter;
Filter device_id_filter;
KeySequence modifier_filter;
uint64_t matching_device_bits = ~uint64_t{ };
uint64_t matching_device_bits = all_device_bits;
bool invert_modifier_filter{ };
bool fallthrough{ };
};
Expand Down

0 comments on commit 971e163

Please sign in to comment.