Expose XWarpPointer to lua as rootwin:warp_pointer, for region_do_warp_alt
[notion.git] / contrib / scripts / min_tabs.lua
blob8d2ddf3a786928714dcc0b5eb56f98b1ca81721b
1 -- Authors: David Tweed, Cas Cremers, David Roundy, John Schreiner
2 -- License: Unknown
3 -- Last Changed: 2007-02-22
4 --
5 --[[
6 min_tabs.lua
8 lua code to auto show/hide tabs as the number of windows in an ion frame
9 changes from/to 1
10 this affects windows on WIonWS and WPaneWS workspaces but leave
11 windows on WFloatWS's alone
13 Originally created by David Tweed
15 22 Feb 2007 John Schreiner: ignore transients to prevent empty frames
16 14 Dec 2006 David Roundy: modified to work with latest ion3
17 11 Feb 2005 David Tweed: modified to work with ion3 svn versions
18 15 Feb 2005 Cas Cremers: only frames with one window hide the tabbar
19 (as opposed to <= 2)
20 01 Sep 2005 Cas Cremers: single client windows that are tagged still
21 show the tabbar.
23 - Easier to work with using a style with slightly wider frame
24 borders and more vivid "active frame" colours.
25 - The keybinding META..T is defined at the end of the file: this
26 should override the normal binging, thus min_tabs should be
27 loaded *after* the normal definition of META..T. It is not
28 appropriate to have key bindings hard-coded in extensions, but I
29 don't currently know of a better way.
30 - Currently supports ion3 with old toggling as well as new
31 toggling function conventions; this can be removed later on.
33 one way to enable this is by adding
34 dopath("min_tabs")
35 to cfg_ion.lua
39 function show_only_necessary_tabs_in_frame(fp)
40 if WFrame.mode(fp) == 'floating' then
41 -- Escape: floatws thing should not be handled
42 return
43 end
46 -- First the logic, then the propagation back to ion
48 -- It should *not* be shown if there is only one app
49 -- However, this (single) app should not be tagged,
50 -- because then we would want to show it.
52 -- Assume the tabbar should be shown.
53 local show_bar = true
54 if WMPlex.mx_count(fp) == 1 then
55 local rg = fp:mx_nth(0)
56 if not rg:is_tagged() then
57 show_bar = false
58 end
59 end
61 -- Propagate choice
62 ioncore.defer(function()
63 -- don't touch transient frames
64 if fp:mode() ~= "transient" then
65 if show_bar then
66 fp:set_mode("tiled")
67 else
68 fp:set_mode("tiled-alt")
69 end
70 end
71 end)
72 end
76 function show_only_necessary_tabs_in_frame_wrapper(ftable)
77 show_only_necessary_tabs_in_frame(ftable.reg)
78 end
82 function min_tabs_setup_hook()
83 local hk=ioncore.get_hook("frame_managed_changed_hook")
84 hk:add(show_only_necessary_tabs_in_frame_wrapper)
85 end
89 function min_tabs_tag_wrapper(fr,reg)
91 -- Note the ugly code: this actually caters for two versions of ion3
92 -- I am only including this because I like Ubuntu [CC]
94 local oldversion = (reg["toggle_tag"] ~= nil)
95 if oldversion then
97 -- old version (for Ubuntu, can be removed later on)
98 reg:toggle_tag()
100 else
102 -- new version
103 reg:set_tagged("toggle")
107 -- recompute tabbar state
108 show_only_necessary_tabs_in_frame(fr)
112 --[[
113 Special keybinding override for this extension
116 defbindings("WMPlex.toplevel", {
117 bdoc("Tag current object within the frame."),
118 kpress(META.."T", "min_tabs_tag_wrapper(_,_sub)", "_sub:non-nil"),
123 min_tabs_setup_hook()