mirror of
https://github.com/miracle-wm-org/miracle-wm.git
synced 2024-11-22 19:58:51 +03:00
feature: support for default key command overrides in the configuration
This commit is contained in:
parent
e45492c602
commit
b13beb2740
2
.github/workflows/cmake.yml
vendored
2
.github/workflows/cmake.yml
vendored
@ -24,7 +24,7 @@ jobs:
|
||||
run: sudo apt-add-repository ppa:mir-team/release
|
||||
|
||||
- name: Install dependencies
|
||||
run: sudo apt-get install libmiral-dev libgtest-dev libyaml-cpp-dev libglib2.0-dev
|
||||
run: sudo apt-get install libmiral-dev libgtest-dev libyaml-cpp-dev libglib2.0-dev libevdev-dev
|
||||
|
||||
- name: Configure CMake
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
|
||||
|
@ -18,6 +18,7 @@ find_package(PkgConfig)
|
||||
pkg_check_modules(MIRAL miral REQUIRED)
|
||||
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
|
||||
pkg_check_modules(YAML REQUIRED IMPORTED_TARGET yaml-cpp)
|
||||
pkg_check_modules(LIBEVDEV REQUIRED IMPORTED_TARGET libevdev)
|
||||
|
||||
add_executable(miracle-wm
|
||||
src/main.cpp
|
||||
@ -31,7 +32,7 @@ add_executable(miracle-wm
|
||||
)
|
||||
|
||||
target_include_directories(miracle-wm PUBLIC SYSTEM ${MIRAL_INCLUDE_DIRS})
|
||||
target_link_libraries( miracle-wm ${MIRAL_LDFLAGS} PkgConfig::YAML PkgConfig::GLIB)
|
||||
target_link_libraries( miracle-wm ${MIRAL_LDFLAGS} PkgConfig::YAML PkgConfig::GLIB PkgConfig::LIBEVDEV)
|
||||
|
||||
install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/miracle-wm
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
|
||||
|
@ -59,6 +59,8 @@ parts:
|
||||
- libyaml-cpp0.7
|
||||
- libglib2.0-dev
|
||||
- libglib2.0-0
|
||||
- libevdev-dev
|
||||
- libevdev2
|
||||
stage-packages:
|
||||
- libmiral6
|
||||
- mir-graphics-drivers-desktop
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <glib-2.0/glib.h>
|
||||
#include <fstream>
|
||||
#include <mir/log.h>
|
||||
#include <libevdev-1.0/libevdev/libevdev.h>
|
||||
|
||||
using namespace miracle;
|
||||
|
||||
@ -22,48 +23,230 @@ MiracleConfig::MiracleConfig()
|
||||
if (config["action_key"])
|
||||
{
|
||||
auto const stringified_action_key = config["action_key"].as<std::string>();
|
||||
if (stringified_action_key == "alt")
|
||||
primary_modifier = mir_input_event_modifier_alt;
|
||||
else if (stringified_action_key == "alt_left")
|
||||
primary_modifier = mir_input_event_modifier_alt_left;
|
||||
else if (stringified_action_key == "alt_right")
|
||||
primary_modifier = mir_input_event_modifier_alt_right;
|
||||
else if (stringified_action_key == "shift")
|
||||
primary_modifier = mir_input_event_modifier_shift;
|
||||
else if (stringified_action_key == "shift_left")
|
||||
primary_modifier = mir_input_event_modifier_shift_left;
|
||||
else if (stringified_action_key == "shift_right")
|
||||
primary_modifier = mir_input_event_modifier_shift_right;
|
||||
else if (stringified_action_key == "sym")
|
||||
primary_modifier = mir_input_event_modifier_sym;
|
||||
else if (stringified_action_key == "function")
|
||||
primary_modifier = mir_input_event_modifier_function;
|
||||
else if (stringified_action_key == "ctrl")
|
||||
primary_modifier = mir_input_event_modifier_ctrl;
|
||||
else if (stringified_action_key == "ctrl_left")
|
||||
primary_modifier = mir_input_event_modifier_ctrl_left;
|
||||
else if (stringified_action_key == "ctrl_right")
|
||||
primary_modifier = mir_input_event_modifier_ctrl_right;
|
||||
else if (stringified_action_key == "meta")
|
||||
primary_modifier = mir_input_event_modifier_meta;
|
||||
else if (stringified_action_key == "meta_left")
|
||||
primary_modifier = mir_input_event_modifier_meta_left;
|
||||
else if (stringified_action_key == "meta_right")
|
||||
primary_modifier = mir_input_event_modifier_meta_right;
|
||||
else if (stringified_action_key == "caps_lock")
|
||||
primary_modifier = mir_input_event_modifier_caps_lock;
|
||||
else if (stringified_action_key == "num_lock")
|
||||
primary_modifier = mir_input_event_modifier_num_lock;
|
||||
else if (stringified_action_key == "scroll_lock")
|
||||
primary_modifier = mir_input_event_modifier_num_lock;
|
||||
else
|
||||
mir::log_error("Unable to process action_key: %s", stringified_action_key.c_str());
|
||||
primary_modifier = parse_modifier(stringified_action_key);
|
||||
}
|
||||
|
||||
if (config["default_action_overrides"])
|
||||
{
|
||||
auto const default_action_overrides = config["default_action_overrides"];
|
||||
if (!default_action_overrides.IsSequence())
|
||||
{
|
||||
// TODO: Error
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto i = 0; i < default_action_overrides.size(); i++)
|
||||
{
|
||||
auto sub_node = default_action_overrides[i];
|
||||
if (!sub_node["name"] || !sub_node["action"] || !sub_node["modifiers"] || !sub_node["key"])
|
||||
{
|
||||
// TODO: Error
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string name = sub_node["name"].as<std::string>();
|
||||
DefaultKeyCommand key_command = DefaultKeyCommand::MAX;
|
||||
if (name == "terminal")
|
||||
key_command = DefaultKeyCommand::Terminal;
|
||||
else if (name == "request_vertical")
|
||||
key_command = DefaultKeyCommand::RequestVertical;
|
||||
else if (name == "request_horizontal")
|
||||
key_command = DefaultKeyCommand::RequestHorizontal;
|
||||
else if (name == "toggle_resize")
|
||||
key_command = DefaultKeyCommand::ToggleResize;
|
||||
else if (name == "move_up")
|
||||
key_command = DefaultKeyCommand::MoveUp;
|
||||
else if (name == "move_down")
|
||||
key_command = DefaultKeyCommand::MoveDown;
|
||||
else if (name == "move_left")
|
||||
key_command = DefaultKeyCommand::MoveLeft;
|
||||
else if (name == "move_right")
|
||||
key_command = DefaultKeyCommand::MoveRight;
|
||||
else if (name == "select_up")
|
||||
key_command = DefaultKeyCommand::SelectUp;
|
||||
else if (name == "select_down")
|
||||
key_command = DefaultKeyCommand::SelectDown;
|
||||
else if (name == "select_left")
|
||||
key_command = DefaultKeyCommand::SelectLeft;
|
||||
else if (name == "select_right")
|
||||
key_command = DefaultKeyCommand::SelectRight;
|
||||
else if (name == "quit_active_window")
|
||||
key_command = DefaultKeyCommand::QuitActiveWindow;
|
||||
else if (name == "quit_compositor")
|
||||
key_command = DefaultKeyCommand::QuitCompositor;
|
||||
else {
|
||||
// TODO: Error
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
std::string action = sub_node["action"].as<std::string>();
|
||||
MirKeyboardAction keyboard_action;
|
||||
if (action == "up")
|
||||
keyboard_action = MirKeyboardAction::mir_keyboard_action_up;
|
||||
else if (action == "down")
|
||||
keyboard_action = MirKeyboardAction::mir_keyboard_action_down;
|
||||
else if (action == "repeat")
|
||||
keyboard_action = MirKeyboardAction::mir_keyboard_action_repeat;
|
||||
else if (action == "modifiers")
|
||||
keyboard_action = MirKeyboardAction::mir_keyboard_action_modifiers;
|
||||
else {
|
||||
// TODO: Error
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string key = sub_node["key"].as<std::string>();
|
||||
auto code = libevdev_event_code_from_name(EV_KEY, key.c_str()); //https://stackoverflow.com/questions/32059363/is-there-a-way-to-get-the-evdev-keycode-from-a-string
|
||||
auto modifiers_node = sub_node["modifiers"];
|
||||
|
||||
if (!modifiers_node.IsSequence())
|
||||
{
|
||||
// TODO: Error
|
||||
continue;
|
||||
}
|
||||
|
||||
uint modifiers = 0;
|
||||
for (auto j = 0; j < modifiers_node.size(); j++)
|
||||
{
|
||||
auto modifier = modifiers_node[j].as<std::string>();
|
||||
modifiers = modifiers | parse_modifier(modifier);
|
||||
}
|
||||
|
||||
key_commands[key_command].push_back({
|
||||
keyboard_action,
|
||||
modifiers,
|
||||
code
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Fill in default actions if the list is zero for any one of them
|
||||
const KeyCommand default_key_commands[DefaultKeyCommand::MAX] =
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_ENTER
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_V
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_H
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_R
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_UP
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_DOWN
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_LEFT
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_RIGHT
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_UP
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_DOWN
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_LEFT
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_RIGHT
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_Q
|
||||
},
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_E
|
||||
}
|
||||
};
|
||||
for (int i = 0; i < DefaultKeyCommand::MAX; i++)
|
||||
{
|
||||
if (key_commands[i].empty())
|
||||
key_commands[i].push_back(default_key_commands[i]);
|
||||
}
|
||||
}
|
||||
|
||||
uint MiracleConfig::parse_modifier(std::string const& stringified_action_key)
|
||||
{
|
||||
if (stringified_action_key == "alt")
|
||||
return mir_input_event_modifier_alt;
|
||||
else if (stringified_action_key == "alt_left")
|
||||
return mir_input_event_modifier_alt_left;
|
||||
else if (stringified_action_key == "alt_right")
|
||||
return mir_input_event_modifier_alt_right;
|
||||
else if (stringified_action_key == "shift")
|
||||
return mir_input_event_modifier_shift;
|
||||
else if (stringified_action_key == "shift_left")
|
||||
return mir_input_event_modifier_shift_left;
|
||||
else if (stringified_action_key == "shift_right")
|
||||
return mir_input_event_modifier_shift_right;
|
||||
else if (stringified_action_key == "sym")
|
||||
return mir_input_event_modifier_sym;
|
||||
else if (stringified_action_key == "function")
|
||||
return mir_input_event_modifier_function;
|
||||
else if (stringified_action_key == "ctrl")
|
||||
return mir_input_event_modifier_ctrl;
|
||||
else if (stringified_action_key == "ctrl_left")
|
||||
return mir_input_event_modifier_ctrl_left;
|
||||
else if (stringified_action_key == "ctrl_right")
|
||||
return mir_input_event_modifier_ctrl_right;
|
||||
else if (stringified_action_key == "meta")
|
||||
return mir_input_event_modifier_meta;
|
||||
else if (stringified_action_key == "meta_left")
|
||||
return mir_input_event_modifier_meta_left;
|
||||
else if (stringified_action_key == "meta_right")
|
||||
return mir_input_event_modifier_meta_right;
|
||||
else if (stringified_action_key == "caps_lock")
|
||||
return mir_input_event_modifier_caps_lock;
|
||||
else if (stringified_action_key == "num_lock")
|
||||
return mir_input_event_modifier_num_lock;
|
||||
else if (stringified_action_key == "scroll_lock")
|
||||
return mir_input_event_modifier_num_lock;
|
||||
else if (stringified_action_key == "primary")
|
||||
return miracle_input_event_modifier_default;
|
||||
else
|
||||
mir::log_error("Unable to process action_key: %s", stringified_action_key.c_str());
|
||||
return mir_input_event_modifier_none;
|
||||
}
|
||||
|
||||
MirInputEventModifier MiracleConfig::get_input_event_modifier() const
|
||||
{
|
||||
return primary_modifier;
|
||||
return (MirInputEventModifier)primary_modifier;
|
||||
}
|
||||
|
||||
DefaultKeyCommand MiracleConfig::matches_key_command(MirKeyboardAction action, int scan_code, unsigned int modifiers) const
|
||||
|
@ -46,108 +46,11 @@ public:
|
||||
[[nodiscard]] DefaultKeyCommand matches_key_command(MirKeyboardAction action, int scan_code, unsigned int modifiers) const;
|
||||
|
||||
private:
|
||||
static const int miracle_input_event_modifier_default = 1 << 18;
|
||||
MirInputEventModifier primary_modifier = mir_input_event_modifier_meta;
|
||||
KeyCommandList key_commands[DefaultKeyCommand::MAX] = {
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_ENTER
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_V
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_H
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_R
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_UP
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_DOWN
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_LEFT
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_RIGHT
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_UP
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_DOWN
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_LEFT
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default,
|
||||
KEY_RIGHT
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_Q
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
MirKeyboardAction::mir_keyboard_action_down,
|
||||
miracle_input_event_modifier_default | mir_input_event_modifier_shift,
|
||||
KEY_E
|
||||
}
|
||||
},
|
||||
};
|
||||
static uint parse_modifier(std::string const& stringified_action_key);
|
||||
|
||||
static const uint miracle_input_event_modifier_default = 1 << 18;
|
||||
uint primary_modifier = mir_input_event_modifier_meta;
|
||||
KeyCommandList key_commands[DefaultKeyCommand::MAX];
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user