项目作者: potamides

项目描述 :
Framework for modal, vi-like keybindings for the awesome window manager
高级语言: Lua
项目地址: git://github.com/potamides/modalawesome.git
创建时间: 2019-10-25T15:12:40Z
项目社区:https://github.com/potamides/modalawesome

开源协议:GNU General Public License v3.0

下载


modalawesome

Modalawesome makes it possible to create vi-like keybindings for the
awesome window manager. It introduces a modal
alternative to the standard
awful.key keybindings
and supports complex commands with motions and counts by making use of Lua
patterns. Check out the
demo to get an overall
impression of what this is capable of.

Installation

Clone the repository and put it in the Lua search path for awesome
(e.g. ~/.config/awesome).

  1. git clone https://github.com/potamides/modalawesome

After that include the module at the top of the rc.lua file.

  1. local modalawesome = require("modalawesome")

This project requires awesome 4.3+ and Lua 5.1+. Older versions may
also work but are untested.

Usage

The goal of modalawesome is to enable complete control over awesome with modal
commands. To make that possible modalawesome covers the same scope
as the keybindings set through the
client:keys
(normally applied with
awful.rules) and
root.keys tables
usually found in an rc.lua file. Thus after setting up modalawesome the
standard keybindings are redundant and can be safely removed, if desired.

Quickstart

Add modalawesome.init() to your rc.lua and restart awesome. Press r to
enter launcher mode and h to launch a help window with all keybindings.
However it is advisable to read this file beforehand.

Commands

Commands are realized as tables with three entries.

  • description: a description to show in the popup widget with hotkeys
    help
  • pattern: a table with Lua patterns, which the entered keys are matched
    against
  • handler: a function which is called when a entered sequence fully matches
    the patterns

This concept can be best explained with an example. A command to focus another
tag could look like this:

  1. local command = {
  2. description = "focus tag by direction",
  3. pattern = {'%d*', '[fb]'},
  4. handler = function(mode, index, direction)
  5. index = index == '' and 1 or tonumber(index)
  6. if direction == 'f' then
  7. awful.tag.viewidx(index)
  8. else
  9. awful.tag.viewidx(-index)
  10. end
  11. end
  12. }

Each item in the pattern table has its own argument in the handler
function. Here %d* matches the relative index of the new tag and [fb]
determines if a tag before or after the current tag should be focused. This
means that e.g. the sequence 1b would focus the previous tag and 3000f
would move the focus three thousand tags forward. The first argument of the
handler function (mode), which was not used in this example, can be used
to switch modes.

Modes

Like vi, modalawesome supports multiple modes. A mode is realized as a table of
commands. Each mode is associated with a name. Modes can be changed with the
mode argument of the handler function. It provides two functions for
that.

  • mode.start(name): start the mode named name and activate its commands
  • mode.stop(): stop the current mode and interact with the focused client,
    no commands are active

A basic configuration with multiple modes could look like this:

  1. local modes = {
  2. mode1 = {
  3. {
  4. description = "start mode2",
  5. pattern = {'v'},
  6. handler = function(mode)
  7. mode.start("mode2")
  8. end
  9. }
  10. },
  11. mode2 = {
  12. {
  13. description = "start mode1",
  14. pattern = {'v'},
  15. handler = function(mode)
  16. mode.start("mode1")
  17. end
  18. },
  19. {
  20. description = "start insert mode",
  21. pattern = {'i'},
  22. handler = function(mode)
  23. mode.stop()
  24. end
  25. }
  26. }
  27. }

Default Configuration

Modalawesome provides default modes and commands that are loosely based on the
default keybindings of awesome. The modalawesome default controls serve
as a good starting point for a customized configuration.

  1. local modes = require("modalawesome.modes")

The default configuration provides three modes to control awesome. The tag
mode is used to change tags and to interact with different clients on a tag.
From it the launcher mode and the layout mode can be started. The
purpose of the launcher mode is to launch various applications, processes
and utility functions and the layout mode can be used to change various
layout options of the current tag.

Indicators

Modalawesome provides two textboxes with information about the current mode
(modalawesome.active_mode) and the current entered key sequence
(modalawesome.sequence). These textboxes could be placed in the
wibar.

  1. s.mywibox:setup {
  2. layout = wibox.layout.align.horizontal,
  3. { -- Left widgets
  4. layout = wibox.layout.fixed.horizontal,
  5. -- ...
  6. modalawesome.active_mode
  7. },
  8. -- ...
  9. { -- Right widgets
  10. layout = wibox.layout.fixed.horizontal,
  11. modalawesome.sequence,
  12. -- ...
  13. },
  14. }

Initialization

For configuration purposes modalawesome provides the init function. This
function expects a table with settings. The following settings are available:

  • modkey: the key which can be used to go back to the default mode
    (comparable to Esc in vi)
  • default_mode: name of the base mode of modalawesome (comparable to
    Normal mode in vi)
  • modes: a table with modes, the index of a mode should be its name
  • stop_name: the text to show in the modalaweosme.active_mode textbox,
    when no mode is active
  • keybindings: a table of awful.key style keybindings which are active in
    all modes

The default settings are defined as follows:

  1. modalawesome.init{
  2. modkey = "Mod4",
  3. default_mode = "tag",
  4. modes = require("modalawesome.modes"),
  5. stop_name = "client",
  6. keybindings = {}
  7. }

The keybindings table makes it possible to easily integrate media keys into
modalawesome.

  1. local keybindings = {
  2. {{}, "XF86MonBrightnessDown", function () awful.spawn("xbacklight -dec 10") end},
  3. {{}, "XF86MonBrightnessUp", function () awful.spawn("xbacklight -inc 10") end},
  4. }

Advanced

Access Internal Keygrabber

The mode argument of the handler function also exposes the internal
keygrabber used
by modelawesome. This can be used to temporarily stop keygrabbing if another
keygrabber needs to be run.

  1. handler = function(mode, ...)
  2. mode.grabber:stop()
  3. -- ...
  4. mode.grabber:start()
  5. end

Explicit Modifier Keys

In many cases it’s not necessary to explicitly specify the modifiers to use in
a pattern, instead it’s sufficient to specify the corresponding symbol
directly.

  1. local pattern = {"S"} -- matches "Shift-s"

However this doesn’t work with special keys like Tab or modifiers like
Control. For these cases you can use a slightly extended pattern syntax. Each
item in the pattern table for which explicit modifier matching is desired
should be replaced with a table with the modifiers as first elements and the
corresponding item as the last. Supported modifiers are Shift, Control,
Mod1 and Mod4.

  1. local pattern = {{"Control", "w"}, "[hjkl]"} -- matches "Control-w [hjkl]"
  1. local pattern = {{"Control", "Shift", "Tab"}} -- matches "Control-Shift-Tab"

Common Keybindings

In some scenarios it might be desirable to add a lot of common keybindings to
multiple modes (e.g. to make some commands accessible everywhere through a
leader key). It might be tedious to add these bindings to all modes manually
and it would also potentially clutter the hotkeys widget. For this use case
modalawesome honors the merge key in mode tables:

  1. local modes = {
  2. tag = { --[[ ... ]] },
  3. launcher = { --[[ ... ]] },
  4. layout = { --[[ ... ]] },
  5. common = { merge=true, --[[ ... ]] }
  6. }

In this example all keybindings in common would be merged with the tag,
launcher and layout modes, however the hotkeys widget would still show
these bindings grouped under the common mode. For more fine-grained control
over merging the value of the merge key could also be a table with mode
names.