Repository navigation
Expand file tree
/
Copy pathtag.lua
More file actions
1401 lines (1209 loc) · 40.7 KB
/
Copy pathtag.lua
File metadata and controls
1401 lines (1209 loc) · 40.7 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
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
---------------------------------------------------------------------------
--- Useful functions for tag manipulation.
--
-- @author Julien Danjou <julien@danjou.info>
-- @copyright 2008 Julien Danjou
-- @release @AWESOME_VERSION@
-- @module tag
---------------------------------------------------------------------------
-- Grab environment we need
local util = require("awful.util")
local ascreen = require("awful.screen")
local beautiful = require("beautiful")
local object = require("gears.object")
local timer = require("gears.timer")
local pairs = pairs
local ipairs = ipairs
local table = table
local setmetatable = setmetatable
local capi =
{
tag = tag,
screen = screen,
mouse = mouse,
client = client,
root = root
}
local function get_screen(s)
return s and capi.screen[s]
end
local tag = {object = {}, mt = {} }
-- Private data
local data = {}
data.history = {}
data.dynamic_cache = setmetatable({}, { __mode = 'k' })
data.tags = setmetatable({}, { __mode = 'k' })
-- History functions
tag.history = {}
tag.history.limit = 20
-- screen.tags depend on index, it cannot be used by awful.tag
local function raw_tags(scr)
local tmp_tags = {}
for _, t in ipairs(root.tags()) do
if get_screen(t.screen) == scr then
table.insert(tmp_tags, t)
end
end
return tmp_tags
end
--- The number of elements kept in the history.
-- @tfield integer awful.tag.history.limit
--- The tag index.
--
-- The index is the position as shown in the `awful.widget.taglist`.
--
-- **Signal:**
--
-- * *property::index*
--
-- @property index
-- @param integer
-- @treturn number The tag index.
function tag.object.set_index(self, idx)
local scr = get_screen(tag.getproperty(self, "screen"))
-- screen.tags cannot be used as it depend on index
local tmp_tags = raw_tags(scr)
-- sort the tags by index
table.sort(tmp_tags, function(a, b)
local ia, ib = tag.getproperty(a, "index"), tag.getproperty(b, "index")
return (ia or math.huge) < (ib or math.huge)
end)
if (not idx) or (idx < 1) or (idx > #tmp_tags) then
return
end
local rm_index = nil
for i, t in ipairs(tmp_tags) do
if t == self then
table.remove(tmp_tags, i)
rm_index = i
break
end
end
table.insert(tmp_tags, idx, self)
for i = idx < rm_index and idx or rm_index, #tmp_tags do
local tmp_tag = tmp_tags[i]
tag.object.set_screen(tmp_tag, scr)
tag.setproperty(tmp_tag, "index", i)
end
end
function tag.object.get_index(query_tag)
local idx = tag.getproperty(query_tag, "index")
if idx then return idx end
-- Get an unordered list of tags
local tags = raw_tags(query_tag.screen)
-- Too bad, lets compute it
for i, t in ipairs(tags) do
if t == query_tag then
tag.setproperty(t, "index", i)
return i
end
end
end
--- Move a tag to an absolute position in the screen[]:tags() table.
-- @deprecated awful.tag.move
-- @param new_index Integer absolute position in the table to insert.
-- @param target_tag The tag that should be moved. If null, the currently
-- selected tag is used.
-- @see index
function tag.move(new_index, target_tag)
util.deprecate("Use t.index = new_index instead of awful.tag.move")
target_tag = target_tag or ascreen.focused().selected_tag
tag.object.set_index(target_tag, new_index)
end
--- Swap 2 tags
-- @function tag.swap
-- @see tag.swap
-- @param tag2 The second tag
-- @see client.swap
function tag.object.swap(self, tag2)
local idx1, idx2 = tag.object.get_index(self), tag.object.get_index(tag2)
local scr2, scr1 = tag.getproperty(tag2, "screen"), tag.getproperty(self, "screen")
-- If they are on the same screen, avoid recomputing the whole table
-- for nothing.
if scr1 == scr2 then
tag.setproperty(self, "index", idx2)
tag.setproperty(tag2, "index", idx1)
else
tag.object.set_screen(tag2, scr1)
tag.object.set_index (tag2, idx1)
tag.object.set_screen(self, scr2)
tag.object.set_index (self, idx2)
end
end
--- Swap 2 tags
-- @deprecated awful.tag.swap
-- @see tag.swap
-- @param tag1 The first tag
-- @param tag2 The second tag
function tag.swap(tag1, tag2)
util.deprecate("Use t:swap(tag2) instead of awful.tag.swap")
tag.object.swap(tag1, tag2)
end
--- Add a tag.
--
-- This function allow to create tags from a set of properties:
--
-- local t = awful.tag.add("my new tag", {
-- screen = screen.primary,
-- layout = awful.layout.suit.max,
-- })
--
-- @function awful.tag.add
-- @param name The tag name, a string
-- @param props The tags inital properties, a table
-- @return The created tag
-- @see tag.delete
function tag.add(name, props)
local properties = props or {}
-- Be sure to set the screen before the tag is activated to avoid function
-- connected to property::activated to be called without a valid tag.
-- set properties cannot be used as this has to be set before the first
-- signal is sent
properties.screen = get_screen(properties.screen or ascreen.focused())
-- Index is also required
properties.index = #raw_tags(properties.screen)+1
local newtag = capi.tag{ name = name }
-- Start with a fresh property table to avoid collisions with unsupported data
data.tags[newtag] = {screen=properties.screen, index=properties.index}
newtag.activated = true
for k, v in pairs(properties) do
-- `rawget` doesn't work on userdata, `:clients()` is the only relevant
-- entry.
if k == "clients" or tag.object[k] then
newtag[k](newtag, v)
else
newtag[k] = v
end
end
return newtag
end
--- Create a set of tags and attach it to a screen.
-- @function awful.tag.new
-- @param names The tag name, in a table
-- @param screen The tag screen, or 1 if not set.
-- @param layout The layout or layout table to set for this tags by default.
-- @return A table with all created tags.
function tag.new(names, screen, layout)
screen = get_screen(screen or 1)
local tags = {}
for id, name in ipairs(names) do
table.insert(tags, id, tag.add(name, {screen = screen,
layout = (layout and layout[id]) or
layout}))
-- Select the first tag.
if id == 1 then
tags[id].selected = true
end
end
return tags
end
--- Find a suitable fallback tag.
-- @function awful.tag.find_fallback
-- @param screen The screen to look for a tag on. [awful.screen.focused()]
-- @param invalids A table of tags we consider unacceptable. [selectedlist(scr)]
function tag.find_fallback(screen, invalids)
local scr = screen or ascreen.focused()
local t = invalids or scr.selected_tags
for _, v in pairs(scr.tags) do
if not util.table.hasitem(t, v) then return v end
end
end
--- Delete a tag.
--
-- To delete the current tag:
--
-- mouse.screen.selected_tag:delete()
--
-- @function tag.delete
-- @see awful.tag.add
-- @see awful.tag.find_fallback
-- @tparam[opt=awful.tag.find_fallback()] tag fallback_tag Tag to assign
-- stickied tags to.
-- @tparam[opt=false] boolean force Move even non-sticky clients to the fallback
-- tag.
-- @return Returns true if the tag is successfully deleted.
-- If there are no clients exclusively on this tag then delete it. Any
-- stickied clients are assigned to the optional 'fallback_tag'.
-- If after deleting the tag there is no selected tag, try and restore from
-- history or select the first tag on the screen.
function tag.object.delete(self, fallback_tag, force)
-- abort if the taf isn't currently activated
if not self.activated then return false end
local target_scr = get_screen(tag.getproperty(self, "screen"))
local tags = target_scr.tags
local idx = tag.object.get_index(self)
local ntags = #tags
-- We can't use the target tag as a fallback.
if fallback_tag == self then return false end
-- No fallback_tag provided, try and get one.
if fallback_tag == nil then
fallback_tag = tag.find_fallback(target_scr, {self})
end
-- Abort if we would have un-tagged clients.
local clients = self:clients()
if #clients > 0 and fallback_tag == nil then return false end
-- Move the clients we can off of this tag.
for _, c in pairs(clients) do
local nb_tags = #c:tags()
-- If a client has only this tag, or stickied clients with
-- nowhere to go, abort.
if (not c.sticky and nb_tags == 1 and not force) then
return
-- If a client has multiple tags, then do not move it to fallback
elseif nb_tags < 2 then
c:tags({fallback_tag})
end
end
-- delete the tag
data.tags[self].screen = nil
self.activated = false
-- Update all indexes
for i=idx+1, #tags do
tag.setproperty(tags[i], "index", i-1)
end
-- If no tags are visible (and we did not delete the lasttag), try and
-- view one. The > 1 is because ntags is no longer synchronized with the
-- current count.
if target_scr.selected_tag == nil and ntags > 1 then
tag.history.restore(target_scr, 1)
if target_scr.selected_tag == nil then
local other_tag = tags[tags[1] == self and 2 or 1]
if other_tag then
other_tag.selected = true
end
end
end
return true
end
--- Delete a tag.
-- @deprecated awful.tag.delete
-- @see tag.delete
-- @param target_tag Optional tag object to delete. [selected()]
-- @param fallback_tag Tag to assign stickied tags to. [~selected()]
-- @return Returns true if the tag is successfully deleted, nil otherwise.
-- If there are no clients exclusively on this tag then delete it. Any
-- stickied clients are assigned to the optional 'fallback_tag'.
-- If after deleting the tag there is no selected tag, try and restore from
-- history or select the first tag on the screen.
function tag.delete(target_tag, fallback_tag)
util.deprecate("Use t:delete(fallback_tag) instead of awful.tag.delete")
return tag.object.delete(target_tag, fallback_tag)
end
--- Update the tag history.
-- @function awful.tag.history.update
-- @param obj Screen object.
function tag.history.update(obj)
local s = get_screen(obj)
local curtags = s.selected_tags
-- create history table
if not data.history[s] then
data.history[s] = {}
else
if data.history[s].current then
-- Check that the list is not identical
local identical = #data.history[s].current == #curtags
if identical then
for idx, _tag in ipairs(data.history[s].current) do
if curtags[idx] ~= _tag then
identical = false
break
end
end
end
-- Do not update history the table are identical
if identical then return end
end
-- Limit history
if #data.history[s] >= tag.history.limit then
for i = tag.history.limit, #data.history[s] do
data.history[s][i] = nil
end
end
end
-- store previously selected tags in the history table
table.insert(data.history[s], 1, data.history[s].current)
data.history[s].previous = data.history[s][1]
-- store currently selected tags
data.history[s].current = setmetatable(curtags, { __mode = 'v' })
end
--- Revert tag history.
-- @function awful.tag.history.restore
-- @param screen The screen.
-- @param idx Index in history. Defaults to "previous" which is a special index
-- toggling between last two selected sets of tags. Number (eg 1) will go back
-- to the given index in history.
function tag.history.restore(screen, idx)
local s = get_screen(screen or ascreen.focused())
local i = idx or "previous"
local sel = s.selected_tags
-- do nothing if history empty
if not data.history[s] or not data.history[s][i] then return end
-- if all tags been deleted, try next entry
if #data.history[s][i] == 0 then
if i == "previous" then i = 0 end
tag.history.restore(s, i + 1)
return
end
-- deselect all tags
tag.viewnone(s)
-- select tags from the history entry
for _, t in ipairs(data.history[s][i]) do
if t.activated and t.screen then
t.selected = true
end
end
-- update currently selected tags table
data.history[s].current = data.history[s][i]
-- store previously selected tags
data.history[s].previous = setmetatable(sel, { __mode = 'v' })
-- remove the reverted history entry
if i ~= "previous" then table.remove(data.history[s], i) end
s:emit_signal("tag::history::update")
end
--- Get a list of all tags on a screen
-- @deprecated awful.tag.gettags
-- @tparam screen s Screen
-- @return A table with all available tags
-- @see screen.tags
function tag.gettags(s)
util.deprecate("Use s.tags instead of awful.tag.gettags")
s = get_screen(s)
return s and s.tags or {}
end
--- Find a tag by name
-- @tparam[opt] screen s The screen of the tag
-- @tparam string name The name of the tag
-- @return The tag found, or `nil`
function tag.find_by_name(s, name)
local tags = s and s.tags or root.tags()
for _, t in ipairs(tags) do
if name == t.name then
return t
end
end
end
--- The tag screen.
--
-- **Signal:**
--
-- * *property::screen*
--
-- @property screen
-- @param screen
-- @see screen
function tag.object.set_screen(t, s)
s = get_screen(s or ascreen.focused())
local sel = tag.selected
local old_screen = get_screen(tag.getproperty(t, "screen"))
if s == old_screen then return end
-- Keeping the old index make very little sense when changing screen
tag.setproperty(t, "index", nil)
-- Change the screen
tag.setproperty(t, "screen", s)
tag.setproperty(t, "index", #s:get_tags(true))
-- Make sure the client's screen matches its tags
for _,c in ipairs(t:clients()) do
c.screen = s --Move all clients
c:tags({t})
end
-- Update all indexes
for i,t2 in ipairs(old_screen.tags) do
tag.setproperty(t2, "index", i)
end
-- Restore the old screen history if the tag was selected
if sel then
tag.history.restore(old_screen, 1)
end
end
--- Set a tag's screen
-- @deprecated awful.tag.setscreen
-- @see screen
-- @param s Screen
-- @param t tag object
function tag.setscreen(s, t)
-- For API consistency, the arguments have been swapped for Awesome 3.6
-- this method is already deprecated, so be silent and swap the args
if type(t) == "number" then
s, t = t, s
end
util.deprecate("Use t.screen = s instead of awful.tag.setscreen(t, s)")
tag.object.set_screen(t, s)
end
--- Get a tag's screen
-- @deprecated awful.tag.getscreen
-- @see screen
-- @param[opt] t tag object
-- @return Screen number
function tag.getscreen(t)
util.deprecate("Use t.screen instead of awful.tag.setscreen(t, s)")
-- A new getter is not required
t = t or ascreen.focused().selected_tag
local prop = tag.getproperty(t, "screen")
return prop and prop.index
end
--- Return a table with all visible tags
-- @deprecated awful.tag.selectedlist
-- @param s Screen.
-- @return A table with all selected tags.
-- @see screen.selected_tags
function tag.selectedlist(s)
util.deprecate("Use s.selected_tags instead of awful.tag.selectedlist")
s = get_screen(s or ascreen.focused())
return s.selected_tags
end
--- Return only the first visible tag.
-- @deprecated awful.tag.selected
-- @param s Screen.
-- @see screen.selected_tag
function tag.selected(s)
util.deprecate("Use s.selected_tag instead of awful.tag.selected")
s = get_screen(s or ascreen.focused())
return s.selected_tag
end
--- The tag master width factor.
--
-- The master width factor is one of the 5 main properties used to configure
-- the `layout`. Each layout interpret (or ignore) this property differenly.
--
-- See the layout suit documentation for information about how the master width
-- factor is used.
--
-- **Signal:**
--
-- * *property::mwfact* (deprecated)
-- * *property::master_width_factor*
--
-- @property master_width_factor
-- @param number Between 0 and 1
-- @see master_count
-- @see column_count
-- @see master_fill_policy
-- @see gap
function tag.object.set_master_width_factor(t, mwfact)
if mwfact >= 0 and mwfact <= 1 then
tag.setproperty(t, "mwfact", mwfact)
tag.setproperty(t, "master_width_factor", mwfact)
end
end
function tag.object.get_master_width_factor(t)
return tag.getproperty(t, "master_width_factor") or 0.5
end
--- Set master width factor.
-- @deprecated awful.tag.setmwfact
-- @see master_fill_policy
-- @see master_width_factor
-- @param mwfact Master width factor.
-- @param t The tag to modify, if null tag.selected() is used.
function tag.setmwfact(mwfact, t)
util.deprecate("Use t.master_width_factor = mwfact instead of awful.tag.setmwfact")
tag.object.get_master_width_factor(t or ascreen.focused().selected_tag, mwfact)
end
--- Increase master width factor.
-- @function awful.tag.incmwfact
-- @see master_width_factor
-- @param add Value to add to master width factor.
-- @param t The tag to modify, if null tag.selected() is used.
function tag.incmwfact(add, t)
t = t or t or ascreen.focused().selected_tag
tag.object.set_master_width_factor(t, tag.object.get_master_width_factor(t) + add)
end
--- Get master width factor.
-- @deprecated awful.tag.getmwfact
-- @see master_width_factor
-- @see master_fill_policy
-- @param[opt] t The tag.
function tag.getmwfact(t)
util.deprecate("Use t.master_width_factor instead of awful.tag.getmwfact")
return tag.object.get_master_width_factor(t or ascreen.focused().selected_tag)
end
--- An ordered list of layouts.
-- `awful.tag.layout` Is usually defined in `rc.lua`. It store the list of
-- layouts used when selecting the previous and next layouts. This is the
-- default:
--
-- -- Table of layouts to cover with awful.layout.inc, order matters.
-- awful.layout.layouts = {
-- awful.layout.suit.floating,
-- awful.layout.suit.tile,
-- awful.layout.suit.tile.left,
-- awful.layout.suit.tile.bottom,
-- awful.layout.suit.tile.top,
-- awful.layout.suit.fair,
-- awful.layout.suit.fair.horizontal,
-- awful.layout.suit.spiral,
-- awful.layout.suit.spiral.dwindle,
-- awful.layout.suit.max,
-- awful.layout.suit.max.fullscreen,
-- awful.layout.suit.magnifier,
-- awful.layout.suit.corner.nw,
-- -- awful.layout.suit.corner.ne,
-- -- awful.layout.suit.corner.sw,
-- -- awful.layout.suit.corner.se,
-- }
--
-- @field awful.tag.layouts
--- The tag client layout.
--
-- This property hold the layout. A layout can be either stateless or stateful.
-- Stateless layouts are used by default by Awesome. They tile clients without
-- any other overhead. They take an ordered list of clients and place them on
-- the screen. Stateful layouts create an object instance for each tags and
-- can store variables and metadata. Because of this, they are able to change
-- over time and be serialized (saved).
--
-- Both types of layouts have valid usage scenarios.
--
-- **Stateless layouts:**
--
-- These layouts are stored in `awful.layout.suit`. They expose a table with 2
-- fields:
--
-- * **name** (*string*): The layout name. This should be unique.
-- * **arrange** (*function*): The function called when the clients need to be
-- placed. The only parameter is a table or arguments returned by
-- `awful.layout.parameters`
--
-- **Stateful layouts:**
--
-- The stateful layouts API is the same as stateless, but they are a function
-- returining a layout instead of a layout itself. They also should have an
-- `is_dynamic = true` property. If they don't, `awful.tag` will create a new
-- instance everytime the layout is set. If they do, the instance will be
-- cached and re-used.
--
-- **Signal:**
--
-- * *property::layout*
--
-- @property layout
-- @see awful.tag.layouts
-- @tparam layout|function layout A layout table or a constructor function
-- @return The layout
function tag.object.set_layout(t, layout)
-- Check if the signature match a stateful layout
if type(layout) == "function" or (
type(layout) == "table"
and getmetatable(layout)
and getmetatable(layout).__call
) then
if not data.dynamic_cache[t] then
data.dynamic_cache[t] = {}
end
local instance = data.dynamic_cache[t][layout] or layout(t)
-- Always make sure the layout is notified it is enabled
if tag.getproperty(t, "screen").selected_tag == t and instance.wake_up then
instance:wake_up()
end
-- Avoid creating the same layout twice, use layout:reset() to reset
if instance.is_dynamic then
data.dynamic_cache[t][layout] = instance
end
layout = instance
end
tag.setproperty(t, "layout", layout)
return layout
end
--- Set layout.
-- @deprecated awful.tag.setlayout
-- @see layout
-- @param layout a layout table or a constructor function
-- @param t The tag to modify
-- @return The layout
function tag.setlayout(layout, t)
util.deprecate("Use t.layout = layout instead of awful.tag.setlayout")
return tag.object.set_layout(t, layout)
end
--- Define if the tag must be deleted when the last client is untagged.
--
-- This is useful to create "throw-away" tags for operation like 50/50
-- side-by-side views.
--
-- local t = awful.tag.add("Temporary", {
-- screen = client.focus.screen,
-- volatile = true,
-- clients = {
-- client.focus,
-- awful.client.focus.history.get(client.focus.screen, 1)
-- }
-- }
--
-- **Signal:**
--
-- * *property::volatile*
--
-- @property volatile
-- @param boolean
-- Volatile accessors are implicit
--- Set if the tag must be deleted when the last client is untagged
-- @deprecated awful.tag.setvolatile
-- @see volatile
-- @tparam boolean volatile If the tag must be deleted when the last client is untagged
-- @param t The tag to modify, if null tag.selected() is used.
function tag.setvolatile(volatile, t)
util.deprecate("Use t.volatile = volatile instead of awful.tag.setvolatile")
tag.setproperty(t, "volatile", volatile)
end
--- Get if the tag must be deleted when the last client closes
-- @deprecated awful.tag.getvolatile
-- @see volatile
-- @param t The tag to modify, if null tag.selected() is used.
-- @treturn boolean If the tag will be deleted when the last client is untagged
function tag.getvolatile(t)
util.deprecate("Use t.volatile instead of awful.tag.getvolatile")
return tag.getproperty(t, "volatile") or false
end
--- The default gap.
--
-- @beautiful beautiful.useless_gap
-- @param number (default: 0)
-- @see gap
--- The gap (spacing, also called `useless_gap`) between clients.
--
-- This property allow to waste space on the screen in the name of style,
-- unicorns and readability.
--
-- **Signal:**
--
-- * *property::useless_gap*
--
-- @property gap
-- @param number The value has to be greater than zero.
function tag.object.set_gap(t, useless_gap)
if useless_gap >= 0 then
tag.setproperty(t, "useless_gap", useless_gap)
end
end
function tag.object.get_gap(t)
return tag.getproperty(t, "useless_gap") or beautiful.useless_gap or 0
end
--- Set the spacing between clients
-- @deprecated awful.tag.setgap
-- @see gap
-- @param useless_gap The spacing between clients
-- @param t The tag to modify, if null tag.selected() is used.
function tag.setgap(useless_gap, t)
util.deprecate("Use t.gap = useless_gap instead of awful.tag.setgap")
tag.object.set_gap(t or ascreen.focused().selected_tag, useless_gap)
end
--- Increase the spacing between clients
-- @function awful.tag.incgap
-- @see gap
-- @param add Value to add to the spacing between clients
-- @param t The tag to modify, if null tag.selected() is used.
function tag.incgap(add, t)
t = t or t or ascreen.focused().selected_tag
tag.object.set_gap(t, tag.object.get_gap(t) + add)
end
--- Get the spacing between clients.
-- @deprecated awful.tag.getgap
-- @see gap
-- @tparam[opt=tag.selected()] tag t The tag.
-- @tparam[opt] int numclients Number of (tiled) clients. Passing this will
-- return 0 for a single client. You can override this function to change
-- this behavior.
function tag.getgap(t, numclients)
util.deprecate("Use t.gap instead of awful.tag.getgap")
if numclients == 1 then
return 0
end
return tag.object.get_gap(t or ascreen.focused().selected_tag)
end
--- Set size fill policy for the master client(s).
--
-- **Signal:**
--
-- * *property::master_fill_policy*
--
-- @property master_fill_policy
-- @param string "expand" or "master_width_factor"
function tag.object.get_master_fill_policy(t)
return tag.getproperty(t, "master_fill_policy") or "expand"
end
--- Set size fill policy for the master client(s)
-- @deprecated awful.tag.setmfpol
-- @see master_fill_policy
-- @tparam string policy Can be set to
-- "expand" (fill all the available workarea) or
-- "master_width_factor" (fill only an area inside the master width factor)
-- @tparam[opt=tag.selected()] tag t The tag to modify
function tag.setmfpol(policy, t)
util.deprecate("Use t.master_fill_policy = policy instead of awful.tag.setmfpol")
t = t or ascreen.focused().selected_tag
tag.setproperty(t, "master_fill_policy", policy)
end
--- Toggle size fill policy for the master client(s)
-- between "expand" and "master_width_factor".
-- @function awful.tag.togglemfpol
-- @see master_fill_policy
-- @tparam tag t The tag to modify, if null tag.selected() is used.
function tag.togglemfpol(t)
t = t or ascreen.focused().selected_tag
if tag.getmfpol(t) == "expand" then
tag.setproperty(t, "master_fill_policy", "master_width_factor")
else
tag.setproperty(t, "master_fill_policy", "expand")
end
end
--- Get size fill policy for the master client(s)
-- @deprecated awful.tag.getmfpol
-- @see master_fill_policy
-- @tparam[opt=tag.selected()] tag t The tag
-- @treturn string Possible values are
-- "expand" (fill all the available workarea, default one) or
-- "master_width_factor" (fill only an area inside the master width factor)
function tag.getmfpol(t)
util.deprecate("Use t.master_fill_policy instead of awful.tag.getmfpol")
t = t or ascreen.focused().selected_tag
return tag.getproperty(t, "master_fill_policy") or "expand"
end
--- Set the number of master windows.
--
-- **Signal:**
--
-- * *property::nmaster* (deprecated)
-- * *property::master_count* (deprecated)
--
-- @property master_count
-- @param integer nmaster Only positive values are accepted
function tag.object.set_master_count(t, nmaster)
if nmaster >= 0 then
tag.setproperty(t, "nmaster", nmaster)
tag.setproperty(t, "master_count", nmaster)
end
end
function tag.object.get_master_count(t)
return tag.getproperty(t, "master_count") or 1
end
---
-- @deprecated awful.tag.setnmaster
-- @see master_count
-- @param nmaster The number of master windows.
-- @param[opt] t The tag.
function tag.setnmaster(nmaster, t)
util.deprecate("Use t.master_count = nmaster instead of awful.tag.setnmaster")
tag.object.set_master_count(t or ascreen.focused().selected_tag, nmaster)
end
--- Get the number of master windows.
-- @deprecated awful.tag.getnmaster
-- @see master_count
-- @param[opt] t The tag.
function tag.getnmaster(t)
util.deprecate("Use t.master_count instead of awful.tag.setnmaster")
t = t or ascreen.focused().selected_tag
return tag.getproperty(t, "master_count") or 1
end
--- Increase the number of master windows.
-- @function awful.tag.incnmaster
-- @see master_count
-- @param add Value to add to number of master windows.
-- @param[opt] t The tag to modify, if null tag.selected() is used.
-- @tparam[opt=false] boolean sensible Limit nmaster based on the number of
-- visible tiled windows?
function tag.incnmaster(add, t, sensible)
t = t or ascreen.focused().selected_tag
if sensible then
local screen = get_screen(tag.getproperty(t, "screen"))
local ntiled = #screen.tiled_clients
local nmaster = tag.object.get_master_count(t)
if nmaster > ntiled then
nmaster = ntiled
end
local newnmaster = nmaster + add
if newnmaster > ntiled then
newnmaster = ntiled
end
tag.object.set_master_count(t, newnmaster)
else
tag.object.set_master_count(t, tag.object.get_master_count(t) + add)
end
end
--- Set the tag icon.
--
-- **Signal:**
--
-- * *property::icon*
--
-- @property icon
-- @tparam path|surface icon The icon
-- accessors are implicit.
--- Set the tag icon
-- @deprecated awful.tag.seticon
-- @see icon
-- @param icon the icon to set, either path or image object
-- @param _tag the tag
function tag.seticon(icon, _tag)
util.deprecate("Use t.icon = icon instead of awful.tag.seticon")
_tag = _tag or ascreen.focused().selected_tag
tag.setproperty(_tag, "icon", icon)
end
--- Get the tag icon
-- @deprecated awful.tag.geticon
-- @see icon
-- @param _tag the tag
function tag.geticon(_tag)
util.deprecate("Use t.icon instead of awful.tag.geticon")
_tag = _tag or ascreen.focused().selected_tag
return tag.getproperty(_tag, "icon")
end
--- Set the number of columns.
--
-- **Signal:**
--
-- * *property::ncol* (deprecated)
-- * *property::column_count*
--
-- @property column_count
-- @tparam integer ncol Has to be greater than 1