Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
171 lines (130 loc) · 4.24 KB
/
Copy pathinit.lua
File metadata and controls
171 lines (130 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
-- functions to share tags on multiple screens
--{{{ Grab environment we need
local capi = { screen = screen,
client = client
}
local pairs = pairs
local ipairs = ipairs
local tag = require("awful.tag")
local awful = require("awful")
--local naughty = require("naughty")
--local inspect = require("inspect")
--}}}
module("sharetags")
--[[
function dump(data)
naughty.notify({ text = inspect(data) })
end
]]
--{{{ Private structures
--}}}
--{{{ Functions
--{{{ create_tags: create a table of tags and bind them to screens
-- @param names : list to label the tags
-- @param layouts : list of layouts for the tags
-- @return table of tag objects
function create_tags(names, layouts)
local tags = {}
local count = #names
if capi.screen.count() >= #names then
count = capi.screen.count() + 1
end
for tagnumber = 1, count do
tags[tagnumber] = tag.add(names[tagnumber], {})
tag.setproperty(tags[tagnumber], "number", tagnumber)
-- Add tags to screen one by one
tag.setscreen(tags[tagnumber], 1)
awful.layout.set(layouts[tagnumber], tags[tagnumber])
end
return tags
end
--}}}
--{{{ tag_move: move a tag to a screen
-- @param t : the tag object to move
-- @param screen_target : the screen object to move to
function tag_move(t, screen_target)
local ts = t or tag.selected()
if not screen_target then return end
local current_screen = tag.getscreen(ts)
if current_screen and screen_target ~= current_screen then
-- switch for tag
local mynumber = tag.getproperty(ts, "number")
-- sort tags
local index = #tag.gettags(screen_target)+1
for i, screen_tag in pairs(tag.gettags(screen_target)) do
local number = tag.getproperty(screen_tag, "number")
if (mynumber < number) then
index = i
break
end
end
-- save curren_screen tags
local selected_tags = tag.selectedlist(current_screen)
tag.setscreen(ts, screen_target)
tag.move(index, ts)
-- restore curren_screen tag
tag.viewmore(selected_tags, current_screen)
-- switch for all clients on tag
if #ts:clients() > 0 then
for _ , c in ipairs(ts:clients()) do
if not c.sticky then
c.screen = screen_target
c:tags( {ts} )
-- Fix maximized client if display sizes not equal
local is_maximized = c.maximized
if is_maximized then
c.maximized = false
c.maximized = true
end
else
awful.client.toggletag(ts,c)
end
end
end
end
end
--}}}
-- Open tag on screen
function select_tag(t, target_screen)
local prev_focus = capi.client.focus;
local tag_screen = tag.getscreen(t)
local is_tag_select = t.selected;
local is_tag_moved = (target_screen ~= tag_screen)
--if t.selected and target_screen ~= tag_screen and #tag.selectedlist(tag_screen) == 1 then
-- swap_screen(tag_screen, target_screen)
--else
tag_move(t, target_screen)
tag.viewonly(t)
--end
-- Если было перемещение тега то фокус на окне теряется.
-- Проверка на что это тот-же самый тег, восстанавливаем фокус на окне
if is_tag_moved and is_tag_select then
if #t:clients() > 0 and prev_focus then
capi.client.focus = prev_focus
end
end
end
-- Toggle tag on screen
function toggle_tag(t, screen)
if (tag.getscreen(t) ~= screen) then
tag_move(t, screen)
if not t.selected then
tag.viewtoggle(t)
end
else
tag.viewtoggle(t)
end
end
-- Swap all tags between two screens
function swap_screen(screen1, screen2)
local tags1 = tag.selectedlist(screen1)
local tags2 = tag.selectedlist(screen2)
tag. viewnone(screen1);
tag. viewnone(screen2);
for i, t in ipairs(tags1) do
toggle_tag(t, screen2)
end
for i, t in ipairs(tags2) do
toggle_tag(t, screen1)
end
end