]> git.madduck.net Git - etc/awesome.git/blob - .config/awesome/taghelpers.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

autorandr shortcut
[etc/awesome.git] / .config / awesome / taghelpers.lua
1 local awful = require('awful')
2
3 module = {}
4
5 function module.delete_tag()
6     local t = awful.screen.focused().selected_tag
7     if not t then return end
8     t:delete()
9 end
10
11 local tmpcounter = 0
12 function module.add_tag(name, properties, switchto, force)
13     local p = (type(properties) == "table" and properties) or {}
14     if not name then
15         name = name or string.format("t%d", tmpcounter)
16         tmpcounter = tmpcounter + 1
17     end
18     if not awful.tag.find_by_name(p.screen, name) or force then
19         p.screen = (p.screen
20             or (client.focus and client.focus.screen)
21             or awful.screen.focused())
22         local t = awful.tag.add(name, p)
23         if switchto then
24             t:view_only()
25         end
26         return t
27     else
28         local text = "A tag with name \"" .. name .. "\" already exists"
29         if p.screen then
30             text = text .. " (on screen " .. p.screen.name .. ")"
31         end
32         naughty.notify({
33             preset = naughty.config.presets.low,
34             title = "Add a new tag",
35             text = text
36         })
37     end
38 end
39
40 function module.rename_tag()
41     awful.prompt.run {
42         prompt       = "New tag name: ",
43         textbox      = awful.screen.focused().mypromptbox.widget,
44         exe_callback = function(new_name)
45             if not new_name or #new_name == 0 then return end
46
47             local t = awful.screen.focused().selected_tag
48             if t then
49                 t.name = new_name
50             end
51         end
52     }
53 end
54
55 function module.move_to_new_tag(clnt, properties, volatile, switchto, force)
56     local c = clnt or client.focus
57     if not c then return end
58
59     local p = (type(properties) == "table" and properties) or {}
60     local s = p.screen or c.screen
61     local t = module.add_tag(c.class, {
62         screen = s,
63         volatile = volatile,
64     }, switchto, force)
65     c:move_to_tag(t)
66 end
67
68 function module.copy_tag()
69     local t = awful.screen.focused().selected_tag
70     if not t then return end
71
72     local clients = t:clients()
73     local t2 = awful.tag.add(t.name, awful.tag.getdata(t))
74     t2:clients(clients)
75     t2:view_only()
76 end
77
78 function module.collect_orphan_clients_to_tag(name)
79     local orphans = {}
80     for _,c in ipairs(client.get()) do
81         if #c:tags() == 0 then
82             orphans[#orphans+1] = c
83         end
84     end
85     if #orphans == 0 then
86         naughty.notify({text="No orphan clients found."})
87         return
88     end
89     local t = awful.tag.find_by_name(nil, name)
90     if not t then
91         t = module.add_tag("orphans", {
92                 volatile = true,
93                 screen = awful.screen.focused(),
94             }, true)
95     end
96     for _,c in ipairs(orphans) do
97         c:move_to_tag(t)
98     end
99 end
100
101 return module