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.
4 Layouts, widgets and utilities for Awesome WM
8 Licensed under GNU General Public License v2
9 * (c) 2013, Luke Bonham
10 * (c) 2010-2012, Peter Hofmann
14 local awful = require("awful")
15 local sqrt = math.sqrt
18 local tonumber = tonumber
19 local wrequire = require("lain.helpers").wrequire
20 local setmetatable = setmetatable
22 -- Lain utilities submodule
24 local util = { _NAME = "lain.util" }
26 -- Like awful.menu.clients, but only show clients of currently selected tags
27 function util.menu_clients_current_tags(menu, args)
28 -- List of currently selected tags.
29 local cls_tags = awful.screen.focused().selected_tags
31 if cls_tags == nil then return nil end
33 -- Final list of menu items.
36 -- For each selected tag get all clients of that tag and add them to
37 -- the menu. A click on a menu item will raise that client.
38 for i = 1,#cls_tags do
40 local cls = t:clients()
42 for k, c in pairs(cls) do
43 cls_t[#cls_t + 1] = { awful.util.escape(c.name) or "",
53 -- No clients? Then quit.
54 if #cls_t <= 0 then return nil end
56 -- menu may contain some predefined values, otherwise start with a
58 if not menu then menu = {} end
60 -- Set the list of items and show the menu.
62 local m = awful.menu(menu)
68 -- Magnify a client: set it to "float" and resize it.
69 function util.magnify_client(c, width_f, height_f)
70 if c and not c.floating then
71 util.magnified_client = c
72 util.mc(c, width_f, height_f)
74 util.magnified_client = nil
79 -- https://github.com/lcpz/lain/issues/195
80 function util.mc(c, width_f, height_f)
81 c = c or util.magnified_client
82 if not c then return end
85 local s = awful.screen.focused()
88 local mwfact = width_f or s.selected_tag.master_width_factor or 0.5
89 g.width = sqrt(mwfact) * mg.width
90 g.height = sqrt(height_f or mwfact) * mg.height
91 g.x = mg.x + (mg.width - g.width) / 2
92 g.y = mg.y + (mg.height - g.height) / 2
94 if c then c:geometry(g) end -- if c is still a valid object
97 -- Non-empty tag browsing
98 -- direction in {-1, 1} <-> {previous, next} non-empty tag
99 function util.tag_view_nonempty(direction, sc)
100 local s = sc or awful.screen.focused()
102 for i = 1, #s.tags do
103 awful.tag.viewidx(direction, s)
104 if #s.clients > 0 then
110 -- {{{ Dynamic tagging
113 function util.add_tag(layout)
115 prompt = "New tag name: ",
116 textbox = awful.screen.focused().mypromptbox.widget,
117 exe_callback = function(name)
118 if not name or #name == 0 then return end
119 awful.tag.add(name, { screen = awful.screen.focused(), layout = layout or awful.layout.suit.tile }):view_only()
124 -- Rename current tag
125 function util.rename_tag()
127 prompt = "Rename tag: ",
128 textbox = awful.screen.focused().mypromptbox.widget,
129 exe_callback = function(new_name)
130 if not new_name or #new_name == 0 then return end
131 local t = awful.screen.focused().selected_tag
140 -- pos in {-1, 1} <-> {previous, next} tag position
141 function util.move_tag(pos)
142 local tag = awful.screen.focused().selected_tag
143 if tonumber(pos) <= -1 then
144 awful.tag.move(tag.index - 1, tag)
146 awful.tag.move(tag.index + 1, tag)
150 -- Delete current tag
151 -- Any rule set on the tag shall be broken
152 function util.delete_tag()
153 local t = awful.screen.focused().selected_tag
154 if not t then return end
160 -- On the fly useless gaps change
161 function util.useless_gaps_resize(thatmuch)
162 local scr = awful.screen.focused()
163 scr.selected_tag.gap = scr.selected_tag.gap + tonumber(thatmuch)
164 awful.layout.arrange(scr)
167 return setmetatable(util, { __index = wrequire })