All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
5 Layouts, widgets and utilities for Awesome WM
9 Licensed under GNU General Public License v2
10 * (c) 2013, Luke Bonham
11 * (c) 2010-2012, Peter Hofmann
15 local awful = require("awful")
16 local beautiful = require("beautiful")
17 local math = { sqrt = math.sqrt }
19 local string = { gsub = string.gsub }
22 local tonumber = tonumber
24 local wrequire = require("lain.helpers").wrequire
25 local setmetatable = setmetatable
27 -- Lain utilities submodule
29 local util = { _NAME = "lain.util" }
31 -- Like awful.menu.clients, but only show clients of currently selected tags
32 function util.menu_clients_current_tags(menu, args)
33 -- List of currently selected tags.
34 local cls_tags = awful.screen.focused().selected_tags
36 if cls_tags == nil then return nil end
38 -- Final list of menu items.
41 -- For each selected tag get all clients of that tag and add them to
42 -- the menu. A click on a menu item will raise that client.
43 for i = 1,#cls_tags do
45 local cls = t:clients()
47 for k, c in pairs(cls) do
48 cls_t[#cls_t + 1] = { awful.util.escape(c.name) or "",
58 -- No clients? Then quit.
59 if #cls_t <= 0 then return nil end
61 -- menu may contain some predefined values, otherwise start with a
63 if not menu then menu = {} end
65 -- Set the list of items and show the menu.
67 local m = awful.menu(menu)
73 -- Magnify a client: set it to "float" and resize it.
74 function util.magnify_client(c)
75 if c and not c.floating then
77 util.magnified_client = c
80 util.magnified_client = nil
84 -- https://github.com/copycat-killer/lain/issues/195
86 c = c or util.magnified_client
87 if not c then return end
90 local s = awful.screen.focused()
92 local tag = s.selected_tag
93 local mwfact = beautiful.master_width_factor or 0.5
95 g.width = math.sqrt(mwfact) * mg.width
96 g.height = math.sqrt(mwfact) * mg.height
97 g.x = mg.x + (mg.width - g.width) / 2
98 g.y = mg.y + (mg.height - g.height) / 2
100 if c then c:geometry(g) end -- if c is still a valid object
103 -- Non-empty tag browsing
104 -- direction in {-1, 1} <-> {previous, next} non-empty tag
105 function util.tag_view_nonempty(direction, sc)
106 local s = sc or awful.screen.focused()
108 for i = 1, #s.tags do
109 awful.tag.viewidx(direction, s)
110 if #s.clients > 0 then
116 -- {{{ Dynamic tagging
119 function util.add_tag()
121 prompt = "New tag name: ",
122 textbox = awful.screen.focused().mypromptbox.widget,
123 exe_callback = function(name)
124 if not name or #name == 0 then return end
125 awful.tag.add(name, { screen = awful.screen.focused() }):view_only()
130 -- Rename current tag
131 function util.rename_tag()
133 prompt = "Rename tag: ",
134 textbox = awful.screen.focused().mypromptbox.widget,
135 exe_callback = function(new_name)
136 if not new_name or #new_name == 0 then return end
137 local t = awful.screen.focused().selected_tag
146 -- pos in {-1, 1} <-> {previous, next} tag position
147 function util.move_tag(pos)
148 local tag = awful.screen.focused().selected_tag
149 local idx = awful.tag.getidx(tag)
150 if tonumber(pos) <= -1 then
151 awful.tag.move(idx - 1, tag)
153 awful.tag.move(idx + 1, tag)
157 -- Delete current tag
158 -- Any rule set on the tag shall be broken
159 function util.delete_tag()
160 local t = awful.screen.focused().selected_tag
161 if not t then return end
167 -- On the fly useless gaps change
168 function util.useless_gaps_resize(thatmuch)
169 beautiful.useless_gap = beautiful.useless_gap or 0
170 beautiful.useless_gap = tonumber(beautiful.useless_gap) + thatmuch
171 awful.layout.arrange(awful.screen.focused())
174 return setmetatable(util, { __index = wrequire })