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 mwfact = beautiful.master_width_factor or 0.5
94 g.width = math.sqrt(mwfact) * mg.width
95 g.height = math.sqrt(mwfact) * mg.height
96 g.x = mg.x + (mg.width - g.width) / 2
97 g.y = mg.y + (mg.height - g.height) / 2
99 if c then c:geometry(g) end -- if c is still a valid object
102 -- Non-empty tag browsing
103 -- direction in {-1, 1} <-> {previous, next} non-empty tag
104 function util.tag_view_nonempty(direction, sc)
105 local s = sc or awful.screen.focused()
107 for i = 1, #s.tags do
108 awful.tag.viewidx(direction, s)
109 if #s.clients > 0 then
115 -- {{{ Dynamic tagging
118 function util.add_tag()
120 prompt = "New tag name: ",
121 textbox = awful.screen.focused().mypromptbox.widget,
122 exe_callback = function(name)
123 if not name or #name == 0 then return end
124 awful.tag.add(name, { screen = awful.screen.focused() }):view_only()
129 -- Rename current tag
130 function util.rename_tag()
132 prompt = "Rename tag: ",
133 textbox = awful.screen.focused().mypromptbox.widget,
134 exe_callback = function(new_name)
135 if not new_name or #new_name == 0 then return end
136 local t = awful.screen.focused().selected_tag
145 -- pos in {-1, 1} <-> {previous, next} tag position
146 function util.move_tag(pos)
147 local tag = awful.screen.focused().selected_tag
148 local idx = awful.tag.getidx(tag)
149 if tonumber(pos) <= -1 then
150 awful.tag.move(idx - 1, tag)
152 awful.tag.move(idx + 1, tag)
156 -- Delete current tag
157 -- Any rule set on the tag shall be broken
158 function util.delete_tag()
159 local t = awful.screen.focused().selected_tag
160 if not t then return end
166 -- On the fly useless gaps change
167 function util.useless_gaps_resize(thatmuch)
168 beautiful.useless_gap = beautiful.useless_gap or 0
169 beautiful.useless_gap = tonumber(beautiful.useless_gap) + thatmuch
170 awful.layout.arrange(awful.screen.focused())
173 return setmetatable(util, { __index = wrequire })