]> 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:

Sound and music player handling
[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, name, properties, volatile, switchto, force)
56     local c = clnt or client.focus
57     if not c then return end
58
59     local n = name or c.class
60     local p = (type(properties) == "table" and properties) or {}
61     local s = p.screen or c.screen
62     local t = module.add_tag(n, gears.table.join(p, {
63         screen = s,
64         volatile = volatile,
65     }), switchto, force)
66     c:move_to_tag(t)
67 end
68
69 function module.copy_tag()
70     local t = awful.screen.focused().selected_tag
71     if not t then return end
72
73     local clients = t:clients()
74     local t2 = awful.tag.add(t.name, awful.tag.getdata(t))
75     t2:clients(clients)
76     t2:view_only()
77 end
78
79 function module.collect_orphan_clients_to_tag(name)
80     local orphans = {}
81     for _,c in ipairs(client.get()) do
82         if #c:tags() == 0 then
83             orphans[#orphans+1] = c
84         end
85     end
86     if #orphans == 0 then
87         naughty.notify({text="No orphan clients found."})
88         return
89     end
90     local t = awful.tag.find_by_name(nil, name)
91     if not t then
92         t = module.add_tag("orphans", {
93                 volatile = true,
94                 screen = awful.screen.focused(),
95             }, true)
96     end
97     for _,c in ipairs(orphans) do
98         c:move_to_tag(t)
99     end
100 end
101
102 return module