quake.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. --[[
  2. Copyright 2018 Stefano Mazzucco <stefano AT curso DOT re>
  3. This program is free software: you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation, either version 3 of the License, or (at your option) any later
  6. version.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
  13. ]]
  14. -- Supported Awesome Version: 4.x
  15. local awful = require("awful")
  16. local client = client -- luacheck: ignore
  17. local DEFAULT_CLIENT_PROPS = {
  18. size_hints_honor = false,
  19. hidden = true,
  20. maximized = true,
  21. skip_taskbar = true,
  22. ontop = true,
  23. sticky = true,
  24. focusable = true,
  25. floating = true,
  26. }
  27. local function _update_props(quake, exclude)
  28. exclude = exclude or {}
  29. for k, v in pairs(quake.client_props) do
  30. if exclude[k] == nil then
  31. quake.client[k] = v
  32. end
  33. end
  34. end
  35. local function init(quake)
  36. if quake.client and quake.client.valid then
  37. _update_props(quake)
  38. if quake.geometry then
  39. quake.client:geometry(quake.geometry)
  40. end
  41. awful.ewmh.add_activate_filter(
  42. -- Prevent focus stealing when the
  43. -- client is visible.
  44. function()
  45. if quake.client.valid and quake.client:isvisible() then
  46. return false
  47. end
  48. return true
  49. end
  50. )
  51. quake.client:connect_signal(
  52. "focus",
  53. function ()
  54. _update_props(quake, {hidden=true})
  55. end)
  56. end
  57. end
  58. local Quake = {}
  59. function Quake:new(o)
  60. o.client_props = o.client_props or {}
  61. for k, v in pairs(DEFAULT_CLIENT_PROPS) do
  62. if o.client_props[k] == nil then
  63. o.client_props[k] = v
  64. end
  65. end
  66. setmetatable(o, self)
  67. self.__index = self
  68. client.connect_signal(
  69. "manage",
  70. function (c)
  71. if c and c.instance == o.name then
  72. o.client = c
  73. init(o)
  74. end
  75. end)
  76. return o
  77. end
  78. function Quake:toggle()
  79. if self.client and self.client.valid then
  80. client.focus = self.client
  81. self.client.hidden = not self.client.hidden
  82. end
  83. end
  84. function Quake:spawn()
  85. awful.client.run_or_raise(
  86. self.cmd,
  87. function(c)
  88. return c.instance == self.name
  89. end,
  90. function (c)
  91. c.first_tag = awful.screen.focused().selected_tag
  92. end
  93. )
  94. self:toggle()
  95. end
  96. return Quake