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 sqrt = math.sqrt
19 local tonumber = tonumber
20 local wrequire = require("lain.helpers").wrequire
21 local setmetatable = setmetatable
23 -- Lain utilities submodule
25 local util = { _NAME = "lain.util" }
27 -- Like awful.menu.clients, but only show clients of currently selected tags
28 function util.menu_clients_current_tags(menu, args)
29 -- List of currently selected tags.
30 local cls_tags = awful.screen.focused().selected_tags
32 if cls_tags == nil then return nil end
34 -- Final list of menu items.
37 -- For each selected tag get all clients of that tag and add them to
38 -- the menu. A click on a menu item will raise that client.
39 for i = 1,#cls_tags do
41 local cls = t:clients()
43 for k, c in pairs(cls) do
44 cls_t[#cls_t + 1] = { awful.util.escape(c.name) or "",
54 -- No clients? Then quit.
55 if #cls_t <= 0 then return nil end
57 -- menu may contain some predefined values, otherwise start with a
59 if not menu then menu = {} end
61 -- Set the list of items and show the menu.
63 local m = awful.menu(menu)
69 -- Magnify a client: set it to "float" and resize it.
70 function util.magnify_client(c, width_f, height_f)
71 if c and not c.floating then
72 util.magnified_client = c
73 util.mc(c, width_f, height_f)
75 util.magnified_client = nil
80 -- https://github.com/copycat-killer/lain/issues/195
81 function util.mc(c, width_f, height_f)
82 c = c or util.magnified_client
83 if not c then return end
86 local s = awful.screen.focused()
89 local mwfact = width_f or s.selected_tag.master_width_factor or 0.5
90 g.width = sqrt(mwfact) * mg.width
91 g.height = sqrt(height_f or mwfact) * mg.height
92 g.x = mg.x + (mg.width - g.width) / 2
93 g.y = mg.y + (mg.height - g.height) / 2
95 if c then c:geometry(g) end -- if c is still a valid object
98 -- Non-empty tag browsing
99 -- direction in {-1, 1} <-> {previous, next} non-empty tag
100 function util.tag_view_nonempty(direction, sc)
101 local s = sc or awful.screen.focused()
103 for i = 1, #s.tags do
104 awful.tag.viewidx(direction, s)
105 if #s.clients > 0 then
111 -- {{{ Dynamic tagging
114 function util.add_tag(layout)
116 prompt = "New tag name: ",
117 textbox = awful.screen.focused().mypromptbox.widget,
118 exe_callback = function(name)
119 if not name or #name == 0 then return end
120 awful.tag.add(name, { screen = awful.screen.focused(), layout = layout or awful.layout.layouts[0] }):view_only()
125 -- Rename current tag
126 function util.rename_tag()
128 prompt = "Rename tag: ",
129 textbox = awful.screen.focused().mypromptbox.widget,
130 exe_callback = function(new_name)
131 if not new_name or #new_name == 0 then return end
132 local t = awful.screen.focused().selected_tag
141 -- pos in {-1, 1} <-> {previous, next} tag position
142 function util.move_tag(pos)
143 local tag = awful.screen.focused().selected_tag
144 if tonumber(pos) <= -1 then
145 awful.tag.move(tag.index - 1, tag)
147 awful.tag.move(tag.index + 1, tag)
151 -- Delete current tag
152 -- Any rule set on the tag shall be broken
153 function util.delete_tag()
154 local t = awful.screen.focused().selected_tag
155 if not t then return end
161 -- On the fly useless gaps change
162 function util.useless_gaps_resize(thatmuch)
163 local scr = awful.screen.focused()
164 scr.selected_tag.gap = scr.selected_tag.gap + tonumber(thatmuch)
165 awful.layout.arrange(scr)
168 return setmetatable(util, { __index = wrequire })