-
Notifications
You must be signed in to change notification settings - Fork 2
/
methods.lua
1533 lines (1208 loc) · 44.5 KB
/
methods.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--------------------------------------------------------- dependencies -- ;
local naughty = require('naughty')
local gears = require("gears")
local awful = require("awful")
local beautiful = require('beautiful')
local grect = gears.geometry.rectangle
local tabs = require("machina.tabs")
local geoms = require("machina.geoms")
local helpers = require("machina.helpers")
local get_client_ix = helpers.get_client_ix
local getlowest = helpers.getlowest
local compare = helpers.compare
local tablelength = helpers.tablelength
local set_contains = helpers.set_contains
local clear_tabbar = helpers.clear_tabbar
---------------------------------------------------------------- locals -- ;
local global_client_table = {}
local global_widget_table = {}
function double_click_event_handler(double_click_event)
if double_click_timer then
double_click_timer:stop()
double_click_timer = nil
double_click_event()
return
end
beautiful.layout_machi = machi.get_icon()
double_click_timer = gears.timer.start_new(0.20, function()
double_click_timer = nil
return false
end)
end
function get_global_clients()
return global_client_table
end
function update_global_clients(c)
global_client_table[c.window] = c
end
----------------------------------------------------- reset_client_meta -- ;
local function reset_client_meta(c)
c.maximized = false
c.maximized_horizontal = false
c.maximized_vertical = false
c.direction = nil
return c
end
--------------------------------------------------- reset_all_clients() -- ;
local function reset_all_clients(s)
local s = s or awful.screen.focused()
for i,c in pairs(s.clients) do
reset_client_meta(c)
end
end
---------------------------------------------------------- set_region() -- ;
local function set_region(region, c)
local c = c or client.focus or nil
if c then
c.region = region end
end
------------------------------------------ get_visible_floating_clients -- ;
local function get_all_floating_clients(s)
local s = s or awful.screen.focused(s)
local les_visibles = {}
for i,p in pairs(s.all_clients) do
if p.floating then
les_visibles[#les_visibles+1] = p
end
end
return les_visibles
end
local function get_visible_floating_clients(s)
local s = s or awful.screen.focused(s)
local les_visibles = {}
for i,p in pairs(s.all_clients) do
if p.floating and (p.always_on or p.bypass) and p:isvisible() then
les_visibles[#les_visibles+1] = p
end
end
return les_visibles
end
---------------------------------------------------- get_space_around() -- ;
local function get_space_around(c)
if not c then return nil end
local c = c or nil
local s = awful.screen.focused()
local space_around = {
left=c.x,
right=s.workarea.width - (c.x + c.width),
top=s.workarea.height - (c.y),
bottom=s.workarea.height - (c.y + c.height),
}
return space_around
end
-------------------------------------------------------- align_floats() -- ;
local function align_floats(direction)
return function (c)
local s = s or awful.screen.focused()
local c = client.focus or nil
local direction = direction or "right"
local space_around = get_space_around(c)
local cs = get_all_floating_clients(s)
if not c then return end
--|flow control
if space_around.right < 300
and space_around.left < 300 then
return
end --|flow control
for i,p in pairs(cs) do
if p.window == c.window then goto next end
--|if c itself if it is actually floating
if space_around.right < 300 and direction == "right" then
direction = "left"
end
if space_around.left < 300 and direction == "left" then
direction = "right"
end --|flow control, nothing to do
if direction == "right" then
if (p.width) > space_around.right then
p.width = space_around.right
end
--|resize if necessary
p:geometry({x=c.x+c.width, y=c.y})
--|place x on the right
end
if direction == "left" then
if p.width > space_around.left then
p.width = space_around.left
end
--|resize if necessary
p:geometry({x=space_around.left - p.width, y=c.y})
--|place x on the left
end
if direction == "left" then direction = "right" end
if direction == "right" then direction = "left" end
p.hidden = false
p:raise()
-- p:emit_signal("request::activate")
--|bring float up
awful.placement.no_offscreen(p)
--|ensure everything is visible
::next::
end
client.focus = c
--|keep focus at the originating client
end
end
--|this will spread out floating clients to the left or
--|right of the focused client, can refactor most of this later.
--|perhaps it is better to limit this to visible floats only.
--|perhaps it would be better to keep the position and geometry
--|of the floats prior to aligning them, so that they can appear
--|where they used to be later.
------------------------------------------------------------- go_edge() -- ;
local function go_edge(direction, regions, current_box)
test_box = true
edge_pos = nil
while test_box do
test_box = grect.get_in_direction(direction, regions, current_box)
if test_box then
current_box = regions[test_box]
edge_pos = test_box
end
end
return edge_pos
end --|
--|figures out the beginning of each row on the layout.
----------------------------------------------------------- always_on() -- ;
local function toggle_always_on()
always_on = nil or client.focus.always_on
client.focus.always_on = not always_on
end
--------------------------------------------------------- screen_info() -- ;
local function screen_info(s)
local s = s or awful.screen.focused()
local focused_screen = s or nil
local workarea = s.workarea or nil
local selected_tag = s.selected_tag or nil
local layout = awful.layout.get(s) or nil
local focused_client = client.focus or nil
return focused_screen,
workarea,
selected_tag,
layout,
focused_client
end
---------------------------------------------------------- get_region() -- ;
local function get_region(region_ix, s)
local s = s or awful.screen.focused()
local focused_screen,
workarea,
selected_tag,
layout,
focused_client = screen_info(s)
local machi_fn = nil
local machi_data = nil
local machi_regions = nil
if layout.machi_get_regions then
machi_fn = layout.machi_get_regions
machi_data = machi_fn(workarea, selected_tag)
machi_regions = machi_data
end --|version 1
if layout.machi_get_instance_data then
machi_fn = layout.machi_get_instance_data
machi_geom = layout.machi_set_geometry
machi_data = {machi_fn(screen[focused_screen], selected_tag)}
machi_regions = machi_data[3]
for i=#machi_regions,1,-1 do
if machi_regions[i].habitable == false then
table.remove(machi_regions, i)
end
end --|remove unhabitable regions
table.sort(
machi_regions,
function (a1, a2)
return a1.id > a2.id
end
) --|v2 returns unordered region list and needs sorting.
end --|version 2/NG
return machi_regions[region_ix]
end
--------------------------------------------------------- get_regions() -- ;
local function get_regions(s)
local s = s or awful.screen.focused()
local focused_screen,
workarea,
selected_tag,
layout,
focused_client = screen_info(s)
local machi_fn = nil
local machi_data = nil
local machi_regions = nil
if layout.machi_get_regions then
machi_fn = layout.machi_get_regions
machi_data = machi_fn(workarea, selected_tag)
machi_regions = machi_data
end --|version 1
if layout.machi_get_instance_data then
machi_fn = layout.machi_get_instance_data
machi_geom = layout.machi_set_geometry
machi_data = {machi_fn(screen[focused_screen], selected_tag)}
machi_regions = machi_data[3]
for i=#machi_regions,1,-1 do
if machi_regions[i].habitable == false then
table.remove(machi_regions, i)
end
end --|remove unhabitable regions
table.sort(
machi_regions,
function (a1, a2)
return a1.id > a2.id
end
) --|v2 returns unordered region list and needs sorting.
end --|version 2/NG
return machi_regions, machi_fn
end
------------------------------------------------------- get_client_info -- ;
local function get_client_info(c)
local c = c or client.focus or nil
local s = s or c.screen or nil
local source_client = c
local active_region = nil
local outofboundary = nil
local proximity = {}
if not source_client then return {} end
--|flow control
if source_client.x < 0 or source_client.y < 0
then outofboundary = true
end --| negative coordinates always mean out of boundary
local regions = get_regions(s)
--|get regions on the screen
if not regions then return {} end
--|flow control
for i, a in ipairs(regions) do
local px = a.x - source_client.x
local py = a.y - source_client.y
if px == 0 then px = 1 end
if py == 0 then py = 1 end
proximity[i] = {
index = i,
v = math.abs(px * py)
} --│keep track of proximity in case nothing matches in
--│this block.
end --│figures out focused client's region under normal
--│circumstances.
if not active_region then
table.sort(proximity, compare) --| sort to get the smallest area
active_region = proximity[1].index --| first item should be the right choice
if source_client.floating then
if regions[active_region].width - source_client.width ~= 0
or regions[active_region].height - source_client.height ~= 0
then
outofboundary = true
end
end --|when client is not the same size as the located
--|region, we should still consider this as out of
--|boundary
end --|user is probably executing get_active_regions on a
--|floating window.
if not active_region then
active_region = 1
end --|at this point, we are out of options, set the index
--|to one and hope for the best.
-- refactor
if active_region and source_client.width > regions[active_region].width then
outofboundary = true
end --|machi sometimes could auto expand the client, consider
--|that as out of boundary.
if active_region and source_client.height > regions[active_region].height then
outofboundary = true
end --|machi sometimes could auto expand the client, consider
--|that as out of boundary.
-- refactor
active_region_geom = {
width=regions[active_region].width-regions[active_region].width/2,
height=regions[active_region].height-regions[active_region].height/2
}
return {
active_region = active_region,
active_region_geom = active_region_geom,
regions = regions,
outofboundary = outofboundary,
tags = c:tags()
}
end
------------------------------------------------------------- move_to() -- ;
local function move_to(location)
return function()
local c = client.focus or nil
if not c then return end
--▨ flow control
local c = reset_client_meta(client.focus)
local ci = get_client_info(c)
local useless_gap = nil
local regions = get_regions()
local edges = {x={},y={}}
local is = {
region=ci.active_region,
region_geom=ci.active_region_geom
}
for i,region in ipairs(regions) do
edges.x[region.x] = region.x + region.width
edges.y[region.y] = region.y + region.height
end
useless_gap = getlowest(edges.x)
if client.focus.floating then
client.focus:geometry(geoms[location](useless_gap))
end
if not client.focus.floating then
-- todo: set actual destination region geometry
-- this is not okay and buggy
-- or at least set it up to use directional shifting
-- to match left, right, center
local tobe_geom = geoms[location](useless_gap)
tobe_geom.width = 300
tobe_geom.height = 600
local tobe = {
region=get_client_info(client.focus).active_region,
}
client.focus:geometry(tobe_geom)
resize_region_to_index(is.region, is.region_geom, true)
draw_tabbar(is.region)
gears.timer.delayed_call(function ()
client.focus.region = tobe.region
draw_tabbar(tobe.region)
end)
end --| redraw tabs and update meta
return
end
end
----------------------------------------- focus_by_direction(direction) -- ;
local function focus_by_direction(direction)
return function()
if not client.focus then return false end
awful.client.focus.global_bydirection(direction, nil,true)
client.focus:raise()
end
end
----------------------------------------------- get_clients_in_region() -- ;
local function get_punched_clients(region_ix, s)
local s = s or awful.screen.focused()
local active_region = region_ix or nil
local region = get_region(region_ix, s)
local region_clients = {}
if #region_clients == 0 then
for i, w in ipairs(s.clients) do
if not w.floating then
if w.region == region_ix then
region_clients[#region_clients + 1] = w
end
end
end --|try to get clients based on simple coordinates
end
return region_clients
end --|try to get clients in a region using three different
--|algorithms.
local function get_clients_in_region(region_ix, c, s)
local c = c or client.focus or nil
local s = s or c.screen or awful.screen.focused()
local source_client = c or client.focus or nil
local source_screen = s or (source_client and source_client.screen)
local active_region = region_ix or nil
local regions = get_regions(s)
local region_clients = {}
if not active_region then
for i, a in ipairs(regions) do
if a.x <= source_client.x and source_client.x < a.x + a.width and
a.y <= source_client.y and source_client.y < a.y + a.height
then
active_region = i
end
end
end --|if no region index was provided, find the
--|region of the focused_client.
if not active_region then
return
end
if #region_clients == 0 then
for i, w in ipairs(s.clients) do
if not (w.floating) then
if (
math.abs(regions[active_region].x - w.x) <= 5 and
math.abs(regions[active_region].y - w.y) <= 5
)
-- or
-- (
-- regions[active_region].x ~= w.x and
-- w.region == region_ix
-- ) --|handle resizing left expanded regions
then
region_clients[#region_clients + 1] = w
w.region = region_ix
--|this basically will fix any inconsistency
--|along the way.
end
end
end --|try to get clients based on simple coordinates
end
-- if #region_clients == 0 then
-- for i, cc in pairs(s.clients) do
-- if cc.region == active_region
-- and regions[active_region].x == cc.x
-- and regions[active_region].y == cc.y
-- then
-- region_clients[#region_clients + 1] = cc
-- end
-- end
-- end --| this logic compares c.region to global client index.
-- --| if we somehow fail to update c.region somewhere
-- --| shuffle shortcuts won't work with this one.
-- if #region_clients == 0 then
-- for _, cc in ipairs(s.clients) do
-- if not (cc.floating) then
-- if regions[active_region].x <= cc.x + cc.width + cc.border_width * 2
-- and cc.x <= (regions[active_region].x + regions[active_region].width)
-- and regions[active_region].y <= (cc.y + cc.height + cc.border_width * 2)
-- and cc.y <= (regions[active_region].y + regions[active_region].height)
-- then
-- region_clients[#region_clients + 1] = cc
-- end
-- end
-- end
-- end --|this logic works with coordinates more throughly but
-- --|it also causes issues with overflowing
-- --|(expanded) clients.
return region_clients
end --|try to get clients in a region using three different
--|algorithms.
----------------------------------------------------- expand_horizontal -- ;
local function expand_horizontal(direction)
return function ()
local c = client.focus
local geom = nil
if c.maximized_horizontal then
c.maximized_horizontal = false
end --|reset toggle maximized state
if c.direction == direction then
c.direction = nil
c.maximized_horizontal = false
c.maximized_vertical = false
if not c.floating then
resize_region_to_index(c.region, true, true)
draw_tabbar(c.region)
gears.timer.weak_start_new(0.1,function ()
client_under_mouse = mouse.current_client
if client_under_mouse then
client.focus = mouse.current_client
end
end) --|when toggling leave the focus
--|to the client under the pointer
end
return
end --|reset toggle when sending the same
--|shortcut consequitively.
local stuff = get_client_info()
local target = grect.get_in_direction(direction, stuff.regions, client.focus:geometry())
if not target and direction ~= "center" then return end -- flow control
--▨▨▨
if direction == "right" then
tobe = {
x=c.x,
width=math.abs(stuff.regions[target].x + stuff.regions[target].width - c.x - 4),
height=c.height,
y=c.y
}
c.direction = direction
c.maximized_horizontal = true
c.maximixed_vertical = false
gears.timer.delayed_call(function (c)
c:geometry(tobe)
resize_region_to_client(c, {horizontal=true,vertical=false,direction=direction})
end,c)
return
end
--▨▨▨
if direction == "left" then
tobe = {
x=stuff.regions[target].x,
width=c.x + c.width - stuff.regions[target].x,
height=c.height,
y=c.y
}
c.direction = direction
c.maximized_horizontal = true
c.maximixed_vertical = false
gears.timer.delayed_call(function (c)
c:geometry(tobe)
resize_region_to_client(c, {horizontal=true,vertical=false,direction=direction})
end,c)
return
end
--▨▨▨
if direction == "center" then
c.maximized = false
c.maximixed_vertical = false
fixedchoice = geoms.clients[c.class] or nil
if c.floating then
c.maximized_horizontal = false
geom = geoms.crt43()
end
if not c.floating then
c.direction = "center"
c.maximized_horizontal = true
geom = geoms.p1080()
end
if fixedchoice and not c.floating then
c.direction = "center"
c.maximized_horizontal = true
geom = fixedchoice()
end
c:geometry(geom)
awful.placement.centered(c)
client.focus = nil
--|allow micky to move the mouse
gears.timer.delayed_call(function (c)
client.focus = c
--|allow micky to move the mouse
c:raise()
client.emit_signal("tabbar_draw", c.region)
clear_tabbar(c)
end,c) --|give it time in case maximize_horizontal is
--|adjusted before centering
return
end
end
end
--|c.direction is used to create a fake toggling effect.
--|tiled clients require an internal maximized property to
--|be set, otherwise they won't budge.
----------------------------------------------------- expand_vertical() -- ;
local function expand_vertical()
local c = client.focus
local going = "down"
if c.maximized_vertical then
if not c.floating then
-- draw_tabbar(c.region)
resize_region_to_index(c.region, true, true)
end
return
end --|reset toggle when sending same shortcut
--|consequitively
local stuff = get_client_info()
local target = grect.get_in_direction("down", stuff.regions, client.focus:geometry())
if target and stuff.regions[target].x ~= c.x then
return
end --|flow control
--|ensure we are operating in the same X axis,
--|vertical directions jump around
if not target then
going = "up"
target = grect.get_in_direction("up", stuff.regions, client.focus:geometry())
end --|flow control
--|try reverse direction
if not target then return end
--|flow control
if going == "down" then
tobe = {
y=c.y,
x=c.x,
width=c.width,
height=stuff.regions[target].y + stuff.regions[target].height - c.y
}
end
if going == "up" then
tobe = {
x=c.x,
width=c.width,
y=stuff.regions[target].y,
height= c.height + c.y - stuff.regions[target].y
}
end
c.maximized_vertical = true
gears.timer.delayed_call(function ()
client.focus:raise()
client.focus:geometry(tobe)
resize_region_to_client(c, {horizontal=false,vertical=true,direction=direction})
end)
return
end
------------------------------------------------------------- shuffle() -- ;
local function shuffle(direction)
return function()
if not client.focus then return end
--▨ flow control
local tablist = get_piled_clients(client.focus.region)
--|this is the ordered list
if not #tablist then return end
--▨ flow control
focused_client_ix = get_client_ix(client.focus.window, tablist)
--|find the index position of the focused client
if not focused_client_ix then return end
--▨ flow control
prev_ix = focused_client_ix - 1
next_ix = focused_client_ix + 1
--|calculate target indexes
if next_ix > #tablist then next_ix = 1 end
if prev_ix < 1 then prev_ix = #tablist end
--|check for validity of the index
if direction == "backward" then
tablist[prev_ix]:emit_signal("request::activate", "mouse_enter",{raise = true})
return
end
if direction == "forward" then
tablist[next_ix]:emit_signal("request::activate", "mouse_enter",{raise = true})
return
end
end
end
---------------------------------------------------------- get_swapee() -- ;
local function get_swapee(target_region_ix)
local regions = get_regions()
--| all regions
local cltbl = awful.client.visible(client.focus.screen, true)
--| all visible clients on all regions
--| but we don't know which regions they are at
local swap_map = {}
for a,region in ipairs(regions) do
for i,c in ipairs(cltbl) do
if c.x == region.x and c.y == region.y then
swap_map[a] = i
break --|avoid stacked regions
end
end
end --|iterate over regions, and match the client objects in
--|each region.
local swapee = cltbl[swap_map[target_region_ix]]
return swapee
end
--[[
returns the client object at a specific region. we can
also use signals to keep track of this but we are trying
to avoid exessive use of signals.
--]]
---------------------------------------------------------- my_shifter() -- ;
local function focus_by_number(region_ix,s)
return function()
local s = s or awful.screen.focused()
local regions = get_regions(s)
local target_region_ix
local target_region
local swapee = get_swapee(region_ix)
--|visible client at the target region
swapee:emit_signal("request::activate", "mouse_enter",{raise = true})
end
end
local function focus_by_index(direction)
return function()
if direction == "left" then direction = "backward" end
if direction == "right" then direction = "forward" end
local c = client.focus
local stuff = get_client_info()
local client_region_ix = stuff.active_region
local source_region
local target_region_ix
local target_region
c = reset_client_meta(c)
--|clean artifacts in case client was expanded.
if direction == "backward" then
if (client_region_ix + 1) > #stuff.regions then
target_region_ix = 1
else
target_region_ix = client_region_ix+1
end
end --|go next region by index,
--|if not reset to first
if direction == "forward" then
if (client_region_ix - 1) < 1 then
target_region_ix = #stuff.regions
else
target_region_ix = client_region_ix - 1
end
end --|go previous region by index,
--|if not reset to last
local swapee = get_swapee(target_region_ix)
--|visible client at the target region
swapee:emit_signal("request::activate", "mouse_enter",{raise = true})
end
end
local function my_shifter(direction, swap)
return function()
if direction == "left" then direction = "backward" end
if direction == "right" then direction = "forward" end
local c = client.focus
local stuff = get_client_info()
local client_region_ix = stuff.active_region
local source_region
local target_region_ix
local target_region
c = reset_client_meta(c)
--|clean artifacts in case client was expanded.
if direction == "backward" then
if (client_region_ix + 1) > #stuff.regions then
target_region_ix = 1
else
target_region_ix = client_region_ix+1
end
end --|go next region by index,
--|if not reset to first
if direction == "forward" then
if (client_region_ix - 1) < 1 then
target_region_ix = #stuff.regions
else
target_region_ix = client_region_ix - 1
end
end --|go previous region by index,
--|if not reset to last
if stuff.outofboundary then
target_region_ix = client_region_ix
end --|ignore previous when out of boundary
--|probably floating or expanded client
--|push inside the boundary instead
source_region = stuff.regions[client_region_ix]
target_region = stuff.regions[target_region_ix]
--|target regions geometry
local swapee = get_swapee(target_region_ix)
--|visible client at the target region
c:geometry(target_region)
--|relocate client
c.region = target_region_ix
--|update client property
if not swap then c:raise() end
--|raise
if swap and swapee then
swapee:geometry(source_region)
swapee:emit_signal("request::activate", "mouse_enter",{raise = true})
end --|perform swap
draw_tabbar(target_region_ix)
resize_region_to_index(target_region_ix, target_region, true)
--|update tabs in target region
draw_tabbar(client_region_ix)
resize_region_to_index(client_region_ix, source_region, true)
--|update tabs in source region
end
end
---------------------------------------------------- shift_by_direction -- ;
local function shift_by_direction(direction, swap)
return function ()
local c = client.focus
local stuff = get_client_info()
local target_region_ix = nil
local client_region_ix = stuff.active_region
if stuff.outofboundary == true then
return my_shifter(direction)()
end --|my_shifter handles this situation better.
local candidate = {
up = grect.get_in_direction("up", stuff.regions, client.focus:geometry()),
down = grect.get_in_direction("down", stuff.regions, client.focus:geometry()),
left = grect.get_in_direction("left", stuff.regions, client.focus:geometry()),