Reno is the second iteration of the AWMTK-powered AwesomeWM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

113 lines
3.8 KiB

-- This file is part of Reno desktop.
--
-- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
--
-- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
-- library for constructing bindable keys
local asckey = {
keymap = {}
}
local awful = require("awful")
local gears = require("gears")
asckey.set_keymap = function(keymap)
for k,v in pairs(keymap) do
asckey.keymap[v] = k
end
end
asckey.get_keycomb = function(name)
local modifiers = {}
name = name:gsub("[^%s%+]+%+",function(v)
if v == "modkey+" then v = global.modkey.."+" end
table.insert(modifiers,v:sub(1,-2))
return ""
end)
return modifiers,name
end
asckey.k = function(name,callback,description,release)
if not asckey.keymap[name] then
return {}
end
local modifiers,key = asckey.get_keycomb(asckey.keymap[name])
if key:match("^Mouse(%d+)$") then
-- After several experiments, the best solution to making the extra mouse buttons bindable
-- was this. The drawback is that all bindings for these are global, and they do not return
-- the button object itself. Crappy hack, but it will suffice for now.
local callback_wrap = function(...)
callback(...)
-- For some ungodly reason binding to mouse drops all keybindings
gears.timer.delayed_call(function()
mousegrabber.run(function() return false end,"bogosity")
mousegrabber.stop()
end)
end
local new_button = awful.button(modifiers, tonumber(key:match("^Mouse(%d+)$")),
callback_wrap,release)
awful.rules.rules[1].properties.buttons = gears.table.join(
awful.rules.rules[1].properties.buttons,
new_button
)
root.buttons(gears.table.join(
root.buttons(),
new_button
))
return {}
else
local callback_wrap = (description.release_pre and function(...)
root.fake_input("key_release",key)
callback(...)
end) or callback
if release then
return awful.key(modifiers,key,
callback_wrap,
description)
else
return awful.key(modifiers,key,
callback_wrap,
release, description)
end
end
end
asckey.custom_binds = function()
local custom_keys = {}
for comm,_ in pairs(asckey.keymap) do
if not comm:match("^:.*") then
table.insert(custom_keys,asckey.k(comm,function()
awful.spawn(comm)
end,{description = comm, group = "custom"}))
end
end
return custom_keys
end
asckey.context = function(keys)
local context = {keys = keys, key_lookup = {},active = false}
for _,v in pairs(keys) do
context.key_lookup[v] = true
end
function context:activate()
context.active = true
root.keys(gears.table.join(
root.keys(),
self.keys
))
end
function context:deactivate()
context.active = false
local root_keys = root.keys()
for i = #root_keys,1,-1 do
if self.key_lookup[root_keys[i]] then
table.remove(root_keys,i)
end
end
root.keys(root_keys)
end
return context
end
return asckey