-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
251 lines (237 loc) · 6.93 KB
/
init.lua
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
-- Modules
local awful = require('awful')
---- Ratio that screen is split
local ratio = 0.733 -- 0.6465
-- Default resize amount
local resize_default_amount = 10
-- Table that holds all active fake screen variables
local screens = {}
-- Modkeys
local modkey = 'Mod4' -- Win/Super
local altkey = 'Mod1' -- Alt
local function screen_has_fake(s)
s = s or awful.screen.focused()
return s.has_fake or s.is_fake
end
local function create_fake(s)
-- If screen was not passed
s = s or awful.screen.focused()
-- If already is or has fake
if screen_has_fake(s) then return end
-- Create variables
local geo = s.geometry
local real_w = math.floor(geo.width * ratio)
local fake_w = geo.width - real_w
-- Index for cleaner code
local index = tostring(s.index)
-- Set initial sizes into memory
screens[index] = {}
screens[index].geo = geo
screens[index].real_w = real_w
screens[index].fake_w = fake_w
-- Create if doesn't exist
-- Resize screen
s:fake_resize(geo.x, geo.y, real_w, geo.height)
-- Create fake for screen
s.fake = _G.screen.fake_add(
geo.x + real_w,
geo.y,
fake_w,
geo.height
)
s.fake.parent = s
-- Mark screens
s.fake.is_fake = true
s.has_fake = true
-- Change status
s.fake.is_open = true
-- Because memory leak
collectgarbage('collect')
-- Emit signal
s:emit_signal('fake_created')
end
local function remove_fake(s)
-- Return if no screen presented
s = s or awful.screen.focused()
-- Ge real screen if fake was focused
if s.is_fake then s = s.parent end
-- If screen doesn't have fake
if not s.has_fake then return end
-- Index for cleaner code
local index = tostring(s.index)
s:fake_resize(
screens[index].geo.x,
screens[index].geo.y,
screens[index].geo.width,
screens[index].geo.height
)
-- Remove and handle variables
s.fake:fake_remove()
s.has_fake = false
s.fake = nil
screens[index] = {}
-- Because memory leaks
collectgarbage('collect')
-- Emit signal
s:emit_signal('fake_created')
end
-- Toggle fake screen
local function toggle_fake(s)
-- No screen given as parameter
s = s or awful.screen.focused()
-- If screen doesn't have fake or isn't fake
if not s.has_fake and not s.is_fake then return end
-- Ge real screen if fake was focused
if s.is_fake then s = s.parent end
-- Index for cleaner code
local index = tostring(s.index)
-- If fake was open
if s.fake.is_open then
-- Resize real screen to be initial size
s:fake_resize(
screens[index].geo.x,
screens[index].geo.y,
screens[index].geo.width,
screens[index].geo.height
)
-- Resize fake to 1px 'out of the view'
-- 0px will move clients out of the screen.
-- On multi monitor setups it will show up
-- on screen on right side of the screen we're handling
s.fake:fake_resize(
screens[index].geo.width,
screens[index].geo.y,
1,
screens[index].geo.height
)
-- Mark fake as hidden
s.fake.is_open = false
else -- Fake was selected
-- Resize screens
s:fake_resize(
screens[index].geo.x,
screens[index].geo.y,
screens[index].real_w,
screens[index].geo.height
)
s.fake:fake_resize(
screens[index].geo.x + screens[index].real_w,
screens[index].geo.y,
screens[index].fake_w,
screens[index].geo.height
)
-- Mark fake as open
s.fake.is_open = true
end
-- Because memory leaks
collectgarbage('collect')
-- Emit signal
s:emit_signal('fake_toggle')
end
-- Resize fake with given amount in pixels
local function resize_fake(amount, s)
-- No screen given
s = s or awful.screen.focused()
amount = amount or resize_default_amount
-- Ge real screen if fake was focused
if s.is_fake then s = s.parent end
-- Index for cleaner code
local index = tostring(s.index)
-- Resize only if fake is open
if s.fake.is_open then
-- Modify width variables
screens[index].real_w = screens[index].real_w + amount
screens[index].fake_w = screens[index].fake_w - amount
-- Resize screens
s:fake_resize(
screens[index].geo.x,
screens[index].geo.y,
screens[index].real_w,
screens[index].geo.height
)
s.fake:fake_resize(
screens[index].geo.x + screens[index].real_w,
screens[index].geo.y,
screens[index].fake_w,
screens[index].geo.height
)
end
-- Because memory leak
collectgarbage('collect')
-- Emit signal
s:emit_signal('fake_resize')
end
-- Reset screen widths to default value
local function reset_fake(s)
-- No sreen given
s = s or awful.screen.focused()
-- Get real screen if fake was focused
if s.is_fake then s = s.parent end
-- In case screen doesn't have fake
if not s.has_fake then return end
-- Index for cleaner code
local index = tostring(s.index)
if s.fake.is_open then
screens[index].real_w = math.floor(screens[index].geo.width * ratio)
screens[index].fake_w = screens[index].geo.width - screens[index].real_w
s:fake_resize(
screens[index].geo.x,
screens[index].geo.y,
screens[index].real_w,
screens[index].geo.height
)
s.fake:fake_resize(
screens[index].real_w,
screens[index].geo.y,
screens[index].geo.width - screens[index].real_w,
screens[index].geo.height
)
end
-- Because memory leak
collectgarbage('collect')
-- Emit signal
s:emit_signal('fake_reset')
end
-- Keybinds for git version
awful.keyboard.append_global_keybindings({
-- Toggle/hide fake screen
awful.key({ modkey }, '§',
function()
_G.screen.emit_signal('toggle_fake')
end,
{ description = 'show/hide fake screen', group = 'fake screen' }),
-- Create or remove
awful.key({ modkey, altkey }, '§',
function()
if screen_has_fake() then
_G.screen.emit_signal('remove_fake')
else
_G.screen.emit_signal('create_fake')
end
end,
{ description = 'create/remove fake screen', group = 'fake screen' }),
-- Increase fake screen size
awful.key({ modkey, altkey }, 'Left',
function()
_G.screen.emit_signal('resize_fake', -10)
end,
{ description = 'resize fake screen', group = 'fake screen' }),
-- Decrease fake screen size
awful.key({ modkey, altkey }, 'Right',
function()
_G.screen.emit_signal('resize_fake', 10)
end,
{ description = 'resize fake screen', group = 'fake screen' }),
-- Reset screen sizes to initial size
awful.key({ modkey, altkey }, 'r',
function()
_G.screen.emit_signal('reset_fake')
end,
{ description = 'reset fake screen size', group = 'fake screen' }),
})
-- Signals, maybe useful for keybinds. s = screen, a = amount
_G.screen.connect_signal('remove_fake', function(s) remove_fake(s) end)
_G.screen.connect_signal('toggle_fake', function(s) toggle_fake(s) end)
_G.screen.connect_signal('create_fake', function(s) create_fake(s) end)
_G.screen.connect_signal('resize_fake', function(a, s) resize_fake(a, s) end)
_G.screen.connect_signal('reset_fake', function(s) reset_fake(s) end)