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

2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
  1. -- This file is part of Reno desktop.
  2. --
  3. -- 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.
  4. --
  5. -- 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.
  6. --
  7. -- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
  8. -- library for constructing bindable keys
  9. local asckey = {
  10. keymap = {}
  11. }
  12. local awful = require("awful")
  13. local gears = require("gears")
  14. asckey.set_keymap = function(keymap)
  15. for k,v in pairs(keymap) do
  16. asckey.keymap[v] = k
  17. end
  18. end
  19. asckey.get_keycomb = function(name)
  20. local modifiers = {}
  21. name = name:gsub("[^%s%+]+%+",function(v)
  22. if v == "modkey+" then v = global.modkey.."+" end
  23. table.insert(modifiers,v:sub(1,-2))
  24. return ""
  25. end)
  26. return modifiers,name
  27. end
  28. asckey.k = function(name,callback,description,release)
  29. if not asckey.keymap[name] then
  30. return {}
  31. end
  32. local modifiers,key = asckey.get_keycomb(asckey.keymap[name])
  33. if key:match("^Mouse(%d+)$") then
  34. -- After several experiments, the best solution to making the extra mouse buttons bindable
  35. -- was this. The drawback is that all bindings for these are global, and they do not return
  36. -- the button object itself. Crappy hack, but it will suffice for now.
  37. local callback_wrap = function(...)
  38. callback(...)
  39. -- For some ungodly reason binding to mouse drops all keybindings
  40. gears.timer.delayed_call(function()
  41. mousegrabber.run(function() return false end,"bogosity")
  42. mousegrabber.stop()
  43. end)
  44. end
  45. local new_button = awful.button(modifiers, tonumber(key:match("^Mouse(%d+)$")),
  46. callback_wrap,release)
  47. awful.rules.rules[1].properties.buttons = gears.table.join(
  48. awful.rules.rules[1].properties.buttons,
  49. new_button
  50. )
  51. root.buttons(gears.table.join(
  52. root.buttons(),
  53. new_button
  54. ))
  55. return {}
  56. else
  57. local callback_wrap = (description.release_pre and function(...)
  58. root.fake_input("key_release",key)
  59. callback(...)
  60. end) or callback
  61. if release then
  62. return awful.key(modifiers,key,
  63. callback_wrap,
  64. description)
  65. else
  66. return awful.key(modifiers,key,
  67. callback_wrap,
  68. release, description)
  69. end
  70. end
  71. end
  72. asckey.custom_binds = function()
  73. local custom_keys = {}
  74. for comm,_ in pairs(asckey.keymap) do
  75. if not comm:match("^:.*") then
  76. table.insert(custom_keys,asckey.k(comm,function()
  77. awful.spawn(comm)
  78. end,{description = comm, group = "custom"}))
  79. end
  80. end
  81. return custom_keys
  82. end
  83. asckey.context = function(keys)
  84. local context = {keys = keys, key_lookup = {},active = false}
  85. for _,v in pairs(keys) do
  86. context.key_lookup[v] = true
  87. end
  88. function context:activate()
  89. context.active = true
  90. root.keys(gears.table.join(
  91. root.keys(),
  92. self.keys
  93. ))
  94. end
  95. function context:deactivate()
  96. context.active = false
  97. local root_keys = root.keys()
  98. for i = #root_keys,1,-1 do
  99. if self.key_lookup[root_keys[i]] then
  100. table.remove(root_keys,i)
  101. end
  102. end
  103. root.keys(root_keys)
  104. end
  105. return context
  106. end
  107. return asckey