From f2b0f9708f7c6d92bb27b5416b1f251a1f1601f2 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Thu, 2 Dec 2021 19:55:58 +0100 Subject: [PATCH] chore(bindings) module + use argument constructors --- configuration/bindings/client_keybindings.lua | 113 +++++++++++++ .../bindings/client_mousebindings.lua | 39 +++++ .../{ => bindings}/global_keybindings.lua | 159 +++++++++++------- .../bindings/global_mousebindings.lua | 28 +++ configuration/bindings/init.lua | 13 ++ configuration/bindings/utils.lua | 16 ++ configuration/client_keybindings.lua | 50 ------ configuration/client_mousebindings.lua | 25 --- configuration/global_mousebindings.lua | 14 -- configuration/init.lua | 15 +- init.lua | 8 +- 11 files changed, 313 insertions(+), 167 deletions(-) create mode 100644 configuration/bindings/client_keybindings.lua create mode 100644 configuration/bindings/client_mousebindings.lua rename configuration/{ => bindings}/global_keybindings.lua (56%) create mode 100644 configuration/bindings/global_mousebindings.lua create mode 100644 configuration/bindings/init.lua create mode 100644 configuration/bindings/utils.lua delete mode 100644 configuration/client_keybindings.lua delete mode 100644 configuration/client_mousebindings.lua delete mode 100644 configuration/global_mousebindings.lua diff --git a/configuration/bindings/client_keybindings.lua b/configuration/bindings/client_keybindings.lua new file mode 100644 index 0000000..1b25a43 --- /dev/null +++ b/configuration/bindings/client_keybindings.lua @@ -0,0 +1,113 @@ +local akey = require "awful.key" +local aclient = require "awful.client" + +local utils = require "rc.configuration.bindings.utils" + +local client_keybindings = { + + akey { + modifiers = { utils.mods.modkey }, + key = "f", + description = "toggle fullscreen", + group = utils.groups.client, + on_press = function(client) + client.fullscreen = not client.fullscreen + client:raise() + end, + }, + + akey { + modifiers = { utils.mods.modkey }, + key = "c", + description = "close", + group = utils.groups.client, + on_press = function(client) + client:kill() + end, + }, + + akey { + modifiers = { utils.mods.modkey, utils.mods.control }, + key = "space", + description = "toggle floating", + group = utils.groups.client, + on_press = aclient.floating.toggle, + }, + + akey { + modifiers = { utils.mods.modkey, utils.mods.control }, + key = "Return", + description = "move to master", + group = utils.groups.client, + on_press = function(client) + client:swap(aclient.getmaster()) + end, + }, + + akey { + modifiers = { utils.mods.modkey }, + key = "o", + description = "move to screen", + group = utils.groups.client, + on_press = function(client) + client:move_to_screen() + end, + }, + + akey { + modifiers = { utils.mods.modkey }, + key = "t", + description = "toggle keep on top", + group = utils.groups.client, + on_press = function(client) + client.ontop = not client.ontop + end, + }, + + akey { + modifiers = { utils.mods.modkey }, + key = "n", + description = "minimize", + group = utils.groups.client, + on_press = function(client) + -- The client currently has the input focus, so it cannot be + -- minimized, since minimized clients can't have the focus. + client.minimized = true + end, + }, + + akey { + modifiers = { utils.mods.modkey }, + key = "m", + description = "(un)maximize", + group = utils.groups.client, + on_press = function(client) + client.maximized = not client.maximized + client:raise() + end, + }, + + akey { + modifiers = { utils.mods.modkey, utils.mods.control }, + key = "m", + description = "(un)maximize vertically", + group = utils.groups.client, + on_press = function(client) + client.maximized_vertical = not client.maximized_vertical + client:raise() + end, + }, + + akey { + modifiers = { utils.mods.modkey, utils.mods.shift }, + key = "m", + description = "(un)maximize horizontally", + group = utils.groups.client, + on_press = function(client) + client.maximized_horizontal = not client.maximized_horizontal + client:raise() + end, + }, +} + +return client_keybindings diff --git a/configuration/bindings/client_mousebindings.lua b/configuration/bindings/client_mousebindings.lua new file mode 100644 index 0000000..8817c86 --- /dev/null +++ b/configuration/bindings/client_mousebindings.lua @@ -0,0 +1,39 @@ +local abutton = require "awful.button" + +local utils = require "rc.configuration.bindings.utils" + +local mousebindings = { + abutton { + modifiers = {}, + button = abutton.names.LEFT, + on_press = function(client) + client:activate { + context = "mouse_click", + } + end, + }, + + abutton { + modifiers = { utils.mods.modkey }, + button = abutton.names.LEFT, + on_press = function(client) + client:activate { + context = "mouse_click", + action = "mouse_move", + } + end, + }, + + abutton { + modifiers = { utils.mods.modkey }, + button = abutton.names.RIGHT, + on_press = function(client) + client:activate { + context = "mouse_click", + action = "mouse_resize", + } + end, + }, +} + +return mousebindings diff --git a/configuration/global_keybindings.lua b/configuration/bindings/global_keybindings.lua similarity index 56% rename from configuration/global_keybindings.lua rename to configuration/bindings/global_keybindings.lua index b053782..f66e589 100644 --- a/configuration/global_keybindings.lua +++ b/configuration/bindings/global_keybindings.lua @@ -13,73 +13,104 @@ local desktop_bar = require "rc.ui.desktop_decoration.bar" local hotkeys_popup = require "rc.ui.hotkeys_popup" local mymainmenu = require "rc.ui.menu.mymainmenu" +local utils = require "rc.configuration.bindings.utils" + local capi = { awesome = _G.awesome, client = _G.client, } -local control = "Control" -local modkey = "Mod4" -local shift = "Shift" - local global_keybindings = { - akey({ modkey }, "s", function() - hotkeys_popup.show_help() - end, { + + -- Awesome + + akey { + modifiers = { utils.mods.modkey }, + key = "s", description = "show help", - group = "awesome", - }), - akey({ modkey }, "w", function() - mymainmenu():show() - end, { + group = utils.groups.awesome, + on_press = function() + hotkeys_popup.show_help() + end, + }, + + akey { + modifiers = { utils.mods.modkey }, + key = "w", description = "show main menu", - group = "awesome", - }), - akey( - { modkey, control }, - "r", - capi.awesome.restart, - { description = "reload awesome", group = "awesome" } - ), - akey( - { modkey, shift }, - "q", - capi.awesome.quit, - { description = "quit awesome", group = "awesome" } - ), - akey({ modkey }, "x", function() - aprompt.run { - prompt = "Run Lua code: ", - textbox = desktop_bar(ascreen.focused()).promptbox.widget, - exe_callback = autil.eval, - history_path = autil.get_cache_dir() .. "/history_eval", - } - end, { + group = utils.groups.awesome, + on_press = function() + mymainmenu():show() + end, + }, + + akey { + modifiers = { utils.mods.modkey, utils.mods.control }, + key = "r", + description = "reload awesome", + group = utils.groups.awesome, + on_press = capi.awesome.restart, + }, + + akey { + modifiers = { utils.mods.modkey, utils.mods.shift }, + key = "q", + description = "quit awesome", + group = utils.groups.awesome, + on_press = capi.awesome.quit, + }, + + akey { + modifiers = { utils.mods.modkey }, + key = "x", description = "lua execute prompt", - group = "awesome", - }), - akey({ modkey }, "Return", function() - aspawn(applications.open_terminal()) - end, { + group = utils.groups.awesome, + on_press = function() + aprompt.run { + prompt = "Run Lua code: ", + textbox = desktop_bar(ascreen.focused()).promptbox.widget, + exe_callback = autil.eval, + history_path = autil.get_cache_dir() .. "/history_eval", + } + end, + }, + + -- Launcher + + akey { + modifiers = { utils.mods.modkey }, + key = "Return", description = "open a terminal", - group = "launcher", - }), - akey({ modkey }, "r", function() - desktop_bar(ascreen.focused()).promptbox:run() - end, { + group = utils.groups.launcher, + on_press = function() + aspawn(applications.open_terminal()) + end, + }, + + akey { + modifiers = { utils.mods.modkey }, + key = "r", description = "run prompt", - group = "launcher", - }), - akey({ modkey }, "p", function() - menubar.show() - end, { + group = utils.groups.launcher, + on_press = function() + desktop_bar(ascreen.focused()).promptbox:run() + end, + }, + + akey { + modifiers = { utils.mods.modkey }, + key = "p", description = "show the menubar", - group = "launcher", - }), + group = utils.groups.launcher, + on_press = function() + menubar.show() + end, + }, -- Client focus + akey { - modifiers = { modkey }, + modifiers = { utils.mods.modkey }, key = "j", group = "client", description = "Focus next client by index", @@ -87,8 +118,9 @@ local global_keybindings = { aclient.focus.byidx(1) end, }, + akey { - modifiers = { modkey }, + modifiers = { utils.mods.modkey }, key = "k", group = "client", description = "Focus previous by index", @@ -98,8 +130,9 @@ local global_keybindings = { }, -- Layout manipulation + akey { - modifiers = { modkey, shift }, + modifiers = { utils.mods.modkey, utils.mods.shift }, key = "j", group = "client", description = "Swap with next client", @@ -107,8 +140,9 @@ local global_keybindings = { aclient.swap.byidx(1) end, }, + akey { - modifiers = { modkey, shift }, + modifiers = { utils.mods.modkey, utils.mods.shift }, key = "k", group = "client", description = "Swap with previous client", @@ -116,8 +150,9 @@ local global_keybindings = { aclient.swap.byidx(-1) end, }, + akey { - modifiers = { modkey, shift }, + modifiers = { utils.mods.modkey, utils.mods.shift }, key = "Right", description = "Increase master width factor", group = "client", @@ -125,8 +160,9 @@ local global_keybindings = { atag.incmwfact(0.01) end, }, + akey { - modifiers = { modkey, shift }, + modifiers = { utils.mods.modkey, utils.mods.shift }, key = "Left", description = "Decrease master width factor", group = "client", @@ -136,8 +172,9 @@ local global_keybindings = { }, -- Tags manipulation + akey { - modifiers = { modkey }, + modifiers = { utils.mods.modkey }, keygroup = akey.keygroup.NUMROW, description = "only view tag", group = "tag", @@ -150,8 +187,9 @@ local global_keybindings = { end end, }, + akey { - modifiers = { modkey, control }, + modifiers = { utils.mods.modkey, utils.mods.control }, keygroup = akey.keygroup.NUMROW, description = "toggle tag", group = "tag", @@ -164,8 +202,9 @@ local global_keybindings = { end end, }, + akey { - modifiers = { modkey, shift }, + modifiers = { utils.mods.modkey, utils.mods.shift }, keygroup = akey.keygroup.NUMROW, description = "move focused client to tag", group = "tag", diff --git a/configuration/bindings/global_mousebindings.lua b/configuration/bindings/global_mousebindings.lua new file mode 100644 index 0000000..eac992f --- /dev/null +++ b/configuration/bindings/global_mousebindings.lua @@ -0,0 +1,28 @@ +local abutton = require "awful.button" +local atag = require "awful.tag" + +local mymainmenu = require "rc.ui.menu.mymainmenu" + +local global_mousebindings = { + abutton { + modifiers = {}, + button = abutton.names.RIGHT, + on_press = function() + mymainmenu():toggle() + end, + }, + + abutton { + modifiers = {}, + button = abutton.names.SCROLL_UP, + on_press = tag.viewprev, + }, + + abutton { + modifiers = {}, + button = abutton.names.SCROLL_DOWN, + on_press = atag.viewnext, + }, +} + +return global_mousebindings diff --git a/configuration/bindings/init.lua b/configuration/bindings/init.lua new file mode 100644 index 0000000..9ce68b2 --- /dev/null +++ b/configuration/bindings/init.lua @@ -0,0 +1,13 @@ +local bindings = {} + +bindings.client_keybindings = + require "rc.configuration.bindings.client_keybindings" +bindings.client_mousebindings = + require "rc.configuration.bindings.client_mousebindings" +bindings.global_keybindings = + require "rc.configuration.bindings.global_keybindings" +bindings.global_mousebindings = + require "rc.configuration.bindings.global_mousebindings" +bindings.utils = require "rc.configuration.bindings.utils" + +return bindings diff --git a/configuration/bindings/utils.lua b/configuration/bindings/utils.lua new file mode 100644 index 0000000..584e52a --- /dev/null +++ b/configuration/bindings/utils.lua @@ -0,0 +1,16 @@ +local mods = { + control = "Control", + modkey = "Mod4", + shift = "Shift", +} + +local groups = { + client = "client", + awesome = "awesome", + launcher = "launcher", +} + +return { + mods = mods, + groups = groups, +} diff --git a/configuration/client_keybindings.lua b/configuration/client_keybindings.lua deleted file mode 100644 index 4d6761b..0000000 --- a/configuration/client_keybindings.lua +++ /dev/null @@ -1,50 +0,0 @@ -local akey = require "awful.key" -local aclient = require "awful.client" - -local control = "Control" -local modkey = "Mod4" -local shift = "Shift" - -local client_keybindings = { - akey({ modkey }, "f", function(client) - client.fullscreen = not client.fullscreen - client:raise() - end, { description = "toggle fullscreen", group = "client" }), - akey({ modkey, shift }, "c", function(client) - client:kill() - end, { description = "close", group = "client" }), - akey( - { modkey, control }, - "space", - aclient.floating.toggle, - { description = "toggle floating", group = "client" } - ), - akey({ modkey, control }, "Return", function(client) - client:swap(aclient.getmaster()) - end, { description = "move to master", group = "client" }), - akey({ modkey }, "o", function(client) - client:move_to_screen() - end, { description = "move to screen", group = "client" }), - akey({ modkey }, "t", function(client) - client.ontop = not client.ontop - end, { description = "toggle keep on top", group = "client" }), - akey({ modkey }, "n", function(client) - -- The client currently has the input focus, so it cannot be - -- minimized, since minimized clients can't have the focus. - client.minimized = true - end, { description = "minimize", group = "client" }), - akey({ modkey }, "m", function(client) - client.maximized = not client.maximized - client:raise() - end, { description = "(un)maximize", group = "client" }), - akey({ modkey, control }, "m", function(client) - client.maximized_vertical = not client.maximized_vertical - client:raise() - end, { description = "(un)maximize vertically", group = "client" }), - akey({ modkey, shift }, "m", function(client) - client.maximized_horizontal = not client.maximized_horizontal - client:raise() - end, { description = "(un)maximize horizontally", group = "client" }), -} - -return client_keybindings diff --git a/configuration/client_mousebindings.lua b/configuration/client_mousebindings.lua deleted file mode 100644 index 6373bbe..0000000 --- a/configuration/client_mousebindings.lua +++ /dev/null @@ -1,25 +0,0 @@ -local abutton = require "awful.button" - -local modkey = "Mod4" - -local mousebindings = { - abutton({}, 1, function(client) - client:activate { - context = "mouse_click", - } - end), - abutton({ modkey }, 1, function(client) - client:activate { - context = "mouse_click", - action = "mouse_move", - } - end), - abutton({ modkey }, 3, function(client) - client:activate { - context = "mouse_click", - action = "mouse_resize", - } - end), -} - -return mousebindings diff --git a/configuration/global_mousebindings.lua b/configuration/global_mousebindings.lua deleted file mode 100644 index 952eccc..0000000 --- a/configuration/global_mousebindings.lua +++ /dev/null @@ -1,14 +0,0 @@ -local abutton = require "awful.button" -local atag = require "awful.tag" - -local mymainmenu = require "rc.ui.menu.mymainmenu" - -local global_mousebindings = { - abutton({}, 3, function() - mymainmenu():toggle() - end), - abutton({}, 4, atag.viewprev), - abutton({}, 5, atag.viewnext), -} - -return global_mousebindings diff --git a/configuration/init.lua b/configuration/init.lua index 6406563..6c84ac8 100644 --- a/configuration/init.lua +++ b/configuration/init.lua @@ -1,23 +1,10 @@ local rc_configuration = {} rc_configuration.applications = require "rc.configuration.applications" - -rc_configuration.client_keybindings = - require "rc.configuration.client_keybindings" -rc_configuration.client_mousebindings = - require "rc.configuration.client_mousebindings" - -rc_configuration.global_keybindings = - require "rc.configuration.global_keybindings" -rc_configuration.global_mousebindings = - require "rc.configuration.global_mousebindings" - +rc_configuration.bindings = require "rc.configuration.bindings" rc_configuration.menu = require "rc.configuration.menu" - rc_configuration.rules = require "rc.configuration.rules" - rc_configuration.prompt_commands = require "rc.configuration.prompt_commands" - rc_configuration.tag_layouts = require "rc.configuration.tag_layouts" return rc_configuration diff --git a/init.lua b/init.lua index 4dd7187..00fba18 100644 --- a/init.lua +++ b/init.lua @@ -38,8 +38,8 @@ local my_slots = require "rc.slots" -- This needs to be run after awesome has completed C API initialization and -- the `root` object is available. gtimer.delayed_call(function() - legacy.global_mouse_bindings(configuration.global_mousebindings) - legacy.global_keybindings(configuration.global_keybindings) + legacy.global_mouse_bindings(configuration.bindings.global_mousebindings) + legacy.global_keybindings(configuration.bindings.global_keybindings) end) -- luacheck: ignore unused variable load_wallpaper @@ -89,7 +89,7 @@ local client_mousebinding = slot { signal = "request::default_mousebindings", slot = slot.slots.client.append_mousebindings, slot_params = { - mousebindings = configuration.client_mousebindings, + mousebindings = configuration.bindings.client_mousebindings, }, } @@ -101,7 +101,7 @@ local client_keybinding = slot { signal = "request::default_keybindings", slot = slot.slots.client.append_keybindings, slot_params = { - keybindings = configuration.client_keybindings, + keybindings = configuration.bindings.client_keybindings, }, }