Skip to content

Commit

Permalink
feature: configure the gap size in the configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Jan 30, 2024
1 parent bef0916 commit 4d0bd40
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
6 changes: 3 additions & 3 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Features:
Features:
- [ ] Fix major bugs
- [ ] Configuration File
- [ ] Gap size
- [ ] Action key
- [ ] Keybindings
- [x] Gap size
- [x] Action key
- [x] Keybindings
- [ ] Workspaces
- [ ] Moving windows between workspaces
- [ ] Stacking windows
Expand Down
5 changes: 4 additions & 1 deletion USERGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ With those types defined, the following table defines the allowed key/value pair
|--------------------------|---------|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| action_key | `meta` | `Modifier` | The default key that is used to initate any action. |
| default_action_overrides | `[]` | `DefaultActionOverride[]` | A list overrides to apply to built-in actions. Actions may be overridden more than once and will respond to multiple key combinations as a result. Defining at least one override disables the default action defined in [Default Key Commands](#default-key-commands) |

| gap_size_x | 10 | int | Size of the gaps in pixels horizontally between windows | |
| gap_size_y | 10 | int | Size of the gaps in pixels vertically between windows | |

## Example Configuration
```yaml
Expand All @@ -98,4 +99,6 @@ default_action_overrides:
- ctrl
- shift
key: KEY_ENTER
gap_size_x: 20
gap_size_y: 20
```
26 changes: 23 additions & 3 deletions src/miracle_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ MiracleConfig::MiracleConfig()
continue;
}

std::string name = sub_node["name"].as<std::string>();
auto name = sub_node["name"].as<std::string>();
DefaultKeyCommand key_command;
if (name == "terminal")
key_command = DefaultKeyCommand::Terminal;
Expand Down Expand Up @@ -104,7 +104,7 @@ MiracleConfig::MiracleConfig()
continue;
}

std::string action = sub_node["action"].as<std::string>();
auto action = sub_node["action"].as<std::string>();
MirKeyboardAction keyboard_action;
if (action == "up")
keyboard_action = MirKeyboardAction::mir_keyboard_action_up;
Expand All @@ -119,7 +119,7 @@ MiracleConfig::MiracleConfig()
continue;
}

std::string key = sub_node["key"].as<std::string>();
auto 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
if (code < 0)
{
Expand Down Expand Up @@ -229,6 +229,16 @@ MiracleConfig::MiracleConfig()
if (key_commands[i].empty())
key_commands[i].push_back(default_key_commands[i]);
}

// Gap sizes
if (config["gap_size_x"])
{
gap_size_x = config["gap_size_x"].as<int>();
}
if (config["gap_size_y"])
{
gap_size_y = config["gap_size_y"].as<int>();
}
}

uint MiracleConfig::parse_modifier(std::string const& stringified_action_key)
Expand Down Expand Up @@ -301,4 +311,14 @@ DefaultKeyCommand MiracleConfig::matches_key_command(MirKeyboardAction action, i
}

return DefaultKeyCommand::MAX;
}

int MiracleConfig::get_gap_size_x() const
{
return gap_size_x;
}

int MiracleConfig::get_gap_size_y() const
{
return gap_size_y;
}
5 changes: 5 additions & 0 deletions src/miracle_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ class MiracleConfig
MiracleConfig();
[[nodiscard]] MirInputEventModifier get_input_event_modifier() const;
[[nodiscard]] DefaultKeyCommand matches_key_command(MirKeyboardAction action, int scan_code, unsigned int modifiers) const;
int get_gap_size_x() const;
int get_gap_size_y() const;

private:
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];

int gap_size_x = 10;
int gap_size_y = 10;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/miracle_window_management_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void MiracleWindowManagementPolicy::advise_move_to(miral::WindowInfo const& wind

void MiracleWindowManagementPolicy::advise_output_create(miral::Output const& output)
{
WindowTreeOptions options = { 10, 10 };
WindowTreeOptions options = { config.get_gap_size_x(), config.get_gap_size_y() };
auto new_tree = std::make_shared<OutputTreePair>(
output,
WindowTree(output.extents(), window_manager_tools, options));
Expand Down

0 comments on commit 4d0bd40

Please sign in to comment.