My configuration files for Debian/Ubuntu applications
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.
 
 
 
 
 
 

191 lines
5.1 KiB

  1. --[[
  2. Lain
  3. Layouts, widgets and utilities for Awesome WM
  4. Utilities section
  5. Licensed under GNU General Public License v2
  6. * (c) 2013, Luca CPZ
  7. * (c) 2010-2012, Peter Hofmann
  8. --]]
  9. local awful = require("awful")
  10. local sqrt = math.sqrt
  11. local pairs = pairs
  12. local client = client
  13. local tonumber = tonumber
  14. local wrequire = require("lain.helpers").wrequire
  15. local setmetatable = setmetatable
  16. -- Lain utilities submodule
  17. -- lain.util
  18. local util = { _NAME = "lain.util" }
  19. -- Like awful.menu.clients, but only show clients of currently selected tags
  20. function util.menu_clients_current_tags(menu, args)
  21. -- List of currently selected tags.
  22. local cls_tags = awful.screen.focused().selected_tags
  23. if cls_tags == nil then return nil end
  24. -- Final list of menu items.
  25. local cls_t = {}
  26. -- For each selected tag get all clients of that tag and add them to
  27. -- the menu. A click on a menu item will raise that client.
  28. for i = 1,#cls_tags do
  29. local t = cls_tags[i]
  30. local cls = t:clients()
  31. for _, c in pairs(cls) do
  32. cls_t[#cls_t + 1] = { awful.util.escape(c.name) or "",
  33. function ()
  34. c.minimized = false
  35. client.focus = c
  36. c:raise()
  37. end,
  38. c.icon }
  39. end
  40. end
  41. -- No clients? Then quit.
  42. if #cls_t <= 0 then return nil end
  43. -- menu may contain some predefined values, otherwise start with a
  44. -- fresh menu.
  45. if not menu then menu = {} end
  46. -- Set the list of items and show the menu.
  47. menu.items = cls_t
  48. local m = awful.menu(menu)
  49. m:show(args)
  50. return m
  51. end
  52. -- Magnify a client: set it to "float" and resize it.
  53. function util.magnify_client(c, width_f, height_f)
  54. if c and not c.floating then
  55. util.magnified_client = c
  56. util.mc(c, width_f, height_f)
  57. else
  58. util.magnified_client = nil
  59. c.floating = false
  60. end
  61. end
  62. -- https://github.com/lcpz/lain/issues/195
  63. function util.mc(c, width_f, height_f)
  64. c = c or util.magnified_client
  65. if not c then return end
  66. c.floating = true
  67. local s = awful.screen.focused()
  68. local mg = s.workarea
  69. local g = {}
  70. local mwfact = width_f or s.selected_tag.master_width_factor or 0.5
  71. g.width = sqrt(mwfact) * mg.width
  72. g.height = sqrt(height_f or mwfact) * mg.height
  73. g.x = mg.x + (mg.width - g.width) / 2
  74. g.y = mg.y + (mg.height - g.height) / 2
  75. if c then c:geometry(g) end -- if c is still a valid object
  76. end
  77. -- Non-empty tag browsing
  78. -- direction in {-1, 1} <-> {previous, next} non-empty tag
  79. function util.tag_view_nonempty(direction,sc)
  80. direction = direction or 1
  81. local s = sc or awful.screen.focused()
  82. local tags = s.tags
  83. local sel = s.selected_tag
  84. local i = sel.index
  85. repeat
  86. i = i + direction
  87. -- Wrap around when we reach one of the bounds
  88. if i > #tags then
  89. i = i - #tags
  90. end
  91. if i < 1 then
  92. i = i + #tags
  93. end
  94. local t = tags[i]
  95. -- Stop when we get back to where we started
  96. if t == sel then
  97. break
  98. end
  99. -- If it's The One, view it.
  100. if #t:clients() > 0 then
  101. t:view_only()
  102. return
  103. end
  104. until false
  105. end
  106. -- {{{ Dynamic tagging
  107. -- Add a new tag
  108. function util.add_tag(layout)
  109. awful.prompt.run {
  110. prompt = "New tag name: ",
  111. textbox = awful.screen.focused().mypromptbox.widget,
  112. exe_callback = function(name)
  113. if not name or #name == 0 then return end
  114. awful.tag.add(name, { screen = awful.screen.focused(), layout = layout or awful.layout.suit.tile }):view_only()
  115. end
  116. }
  117. end
  118. -- Rename current tag
  119. function util.rename_tag()
  120. awful.prompt.run {
  121. prompt = "Rename tag: ",
  122. textbox = awful.screen.focused().mypromptbox.widget,
  123. exe_callback = function(new_name)
  124. if not new_name or #new_name == 0 then return end
  125. local t = awful.screen.focused().selected_tag
  126. if t then
  127. t.name = new_name
  128. end
  129. end
  130. }
  131. end
  132. -- Move current tag
  133. -- pos in {-1, 1} <-> {previous, next} tag position
  134. function util.move_tag(pos)
  135. local tag = awful.screen.focused().selected_tag
  136. if tonumber(pos) <= -1 then
  137. awful.tag.move(tag.index - 1, tag)
  138. else
  139. awful.tag.move(tag.index + 1, tag)
  140. end
  141. end
  142. -- Delete current tag
  143. -- Any rule set on the tag shall be broken
  144. function util.delete_tag()
  145. local t = awful.screen.focused().selected_tag
  146. if not t then return end
  147. t:delete()
  148. end
  149. -- }}}
  150. -- On the fly useless gaps change
  151. function util.useless_gaps_resize(thatmuch, s, t)
  152. local scr = s or awful.screen.focused()
  153. local tag = t or scr.selected_tag
  154. tag.gap = tag.gap + tonumber(thatmuch)
  155. awful.layout.arrange(scr)
  156. end
  157. return setmetatable(util, { __index = wrequire })