Expose XWarpPointer to lua as rootwin:warp_pointer, for region_do_warp_alt
[notion.git] / contrib / scripts / net_client_list.lua
blobda00154558addd9ce53b6a4f1da1895e74ed61b7
1 -- Authors: Etan Reisner <deryni@gmail.com>
2 -- License: MIT, see http://opensource.org/licenses/mit-license.php
3 -- Last Changed: 2007-07-22
4 --
5 --[[
6 Author: Etan Reisner
7 Email: deryni@unreliablesource.net
8 Summary: Maintains the _NET_CLIENT_LIST property (and the _NET_CLIENT_LIST_STACKING property incorrectly) on the root window.
9 Last Updated: 2007-07-22
11 Copyright (c) Etan Reisner 2007
13 This software is released under the terms of the MIT license. For more
14 information, see http://opensource.org/licenses/mit-license.php .
15 --]]
17 local atom_window = ioncore.x_intern_atom("WINDOW", false)
18 local atom_client_list = ioncore.x_intern_atom("_NET_CLIENT_LIST", false)
19 local atom_client_list_stacking = ioncore.x_intern_atom("_NET_CLIENT_LIST_STACKING", false)
21 local function add_client(cwin)
22 if not cwin then
23 return
24 end
26 local rootwin = cwin:rootwin_of()
27 local list = {n=0}
29 ioncore.clientwin_i(function (cwin)
30 list.n = list.n + 1
31 list[list.n] = cwin:xid()
32 return true
33 end)
34 list.n = nil
36 ioncore.x_change_property(rootwin:xid(), atom_client_list, atom_window,
37 32, "replace", list)
38 ioncore.x_change_property(rootwin:xid(), atom_client_list_stacking,
39 atom_window, 32, "replace", list)
40 end
42 local function remove_client(xid)
43 local rootwin = ioncore.current():rootwin_of()
44 local list = {n=0}
46 ioncore.clientwin_i(function (cwin)
47 list.n = list.n + 1
48 list[list.n] = cwin:xid()
49 return true
50 end)
51 list.n = nil
53 ioncore.x_change_property(rootwin:xid(), atom_client_list, atom_window,
54 32, "replace", list)
55 ioncore.x_change_property(rootwin:xid(), atom_client_list_stacking,
56 atom_window, 32, "replace", list)
57 end
59 local function net_mark_supported(atom)
60 if (ioncore.rootwin) then
61 local rootwin = ioncore.rootwin()
62 local atom_atom = ioncore.x_intern_atom("ATOM", false)
63 local atom_net_supported = ioncore.x_intern_atom("_NET_SUPPORTED", false)
64 ioncore.x_change_property(rootwin:xid(), atom_net_supported, atom_atom,
65 32, "append", {atom})
66 end
67 end
69 add_client(ioncore.current())
72 local hook
74 hook = ioncore.get_hook("clientwin_mapped_hook")
75 if hook then
76 hook:add(add_client)
77 end
78 hook = nil
79 hook = ioncore.get_hook("clientwin_unmapped_hook")
80 if hook then
81 hook:add(remove_client)
82 end
84 net_mark_supported(atom_client_list);
85 end