Debian Codegraph @

tyrannical/shortcut.lua

raw symbols SCIP
1 local capi = {root=root,client=client,tag=tag,mouse=mouse}
2 local ipairs = ipairs
3 local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
4 local aw_util = require( "awful.util" )
5 local aw_spawn = require( "awful.spawn" )
6 local aw_tag = require( "awful.tag" )
7 local aw_client = require( "awful.client" )
8 local aw_layout = require( "awful.layout" )
9 local aw_key = require( "awful.key" )
10 local aw_prompt = require( "awful.prompt" )
11 local glib = require( "lgi" ).GLib
12
13 local function get_current_screen()
14 if capi.client.focus and capi.client.focus.screen == capi.mouse.screen then
15 return capi.mouse.screen
16 elseif (capi.mouse.screen.selected_tag and #capi.mouse.screen.selected_tag:clients() == 0) or (not capi.client.focus) then
17 return capi.mouse.screen
18 end
19 return capi.client.focus.screen
20 end
21
22 -- Delete a tag as of 3.5.5, this have a few issue. Patches are on their way
23 local function delete_tag()
24 local t = get_current_screen().selected_tag
25 if not t then return end
26 t:delete()
27 end
28
29 -- Create a new tag at the end of the list
30 local function new_tag()
31 aw_tag.add("NewTag", {
32 screen= get_current_screen()
33 }):view_only()
34 end
35
36 local function new_tag_with_focussed()
37 local c = capi.client.focus
38 if not c then return end
39
40 local t = aw_tag.add(c.class, {
41 screen = get_current_screen(),
42 layout = aw_layout.suit.tile,
43 volatile = true
44 })
45
46 c:tags(aw_util.table.join(c:tags(), {t}))
47
48 t:view_only()
49 end
50
51 local function move_to_new_tag()
52 local c = capi.client.focus
53 if not c then return end
54
55 local t = aw_tag.add(c.class, {
56 screen = get_current_screen()
57 })
58
59 c:tags({t})
60 t:view_only()
61 end
62
63 local function rename_tag_to_focussed()
64 if not capi.client.focus then return end
65
66 local t = capi.client.focus.screen.selected_tag
67 if not t then return end
68
69 t.name = capi.client.focus.class
70 end
71
72 local function rename_tag()
73 aw_prompt.run {
74 prompt = "New tag name: ",
75 textbox = mypromptbox[capi.mouse.screen].widget,
76 exe_callback = function(new_name)
77 if not new_name or #new_name == 0 then
78 return
79 else
80 local t = capi.mouse.screen.selected_tag
81 if t then
82 t.name = new_name
83 end
84 end
85 end
86 }
87 end
88
89 local function term_in_current_tag()
90 aw_spawn(terminal, {
91 tag = get_current_screen().selected_tag,
92 slave = true,
93 screen = get_current_screen()
94 })
95 end
96
97 local function new_tag_with_term()
98 aw_spawn(terminal, {
99 new_tag = {
100 volatile = true,
101 screen = get_current_screen()
102 }
103 })
104 end
105
106 local function fork_tag()
107 local t = get_current_screen().selected_tag
108 if not t then return end
109
110 local clients = t:clients()
111 local t2 = aw_tag.add(t.name,aw_tag.getdata(t))
112
113 t2:clients(clients)
114 t2:view_only()
115 end
116
117 local function aero_tag()
118 local c = capi.client.focus
119 if not c then return end
120
121 local c2 = aw_client.focus.history.list[2]
122 if (not c2) or c2 == c then return end
123
124 local t = aw_tag.add("Aero", {
125 screen = c.screen,
126 layout = aw_layout.suit.tile,
127 master_width_factor = 0.5
128 })
129
130 t:clients({c,c2})
131
132 t:view_only()
133 end
134
135 local function register_keys()
136 local keys = {}
137 -- Comment the lines of the shortcut you don't want
138 for _,data in ipairs {
139 {{ modkey }, "d" , delete_tag },
140 {{ modkey }, "n" , new_tag },
141 {{ modkey, "Shift" }, "n" , new_tag_with_focussed },
142 {{ modkey, "Mod1" }, "n" , move_to_new_tag },
143 {{ modkey, "Mod1" }, "r" , rename_tag_to_focussed},
144 {{ modkey, "Shift" }, "r" , rename_tag },
145 {{ modkey, "Mod1" }, "Return", term_in_current_tag },
146 {{ modkey, "Control" }, "Return", new_tag_with_term },
147 {{ modkey, "Control" }, "f" , fork_tag },
148 {{ modkey }, "a" , aero_tag },
149 } do
150 keys[#keys+1] = aw_key(data[1], data[2], data[3])
151 end
152 capi.root.keys(aw_util.table.join(capi.root.keys(),unpack(keys)))
153 end
154 glib.idle_add(glib.PRIORITY_DEFAULT_IDLE, register_keys)