13 -- intern useful atoms
14 for _
,v
in pairs
{ "_NET_SUPPORTED", "_NET_WM_NAME", "WM_STATE" } do if not atom
[v
] then atom
[v
] = x
.intern_atom(v
) end end
16 -- utility window calls
17 local rt
= getmetatable(cwm
.root
)
18 rt
.getwmstate
= function(win
)
19 local res
= win
:get_property(atom
.WM_STATE
)
20 if res
then return res
[0] end
22 rt
.setwmstate
= function(win
,data
)
24 win
:set_property(atom
.WM_STATE
,nil, data
, 0)
28 -------------------------------------------------------
30 -------------------------------------------------------
32 for k
,v
in pairs(t
) do
37 function cwm
.add_window(win
,attr
)
40 if (cwm
.windows
[win
]) then return end
42 cwm
.windows
[win
] = attr
43 cwm
.windows
[win
].old_bw
= attr
.border_width
44 -- win:configure{border_width=5}
45 win
:set_attributes
{border_pixel
=x
.color('#ff0000')}
49 cwm
.root
:set_attributes
{
50 override_redirect
=true,
51 background_pixmap
=x
.ParentRelative
,
53 x
.SubstructureRedirectMask|
54 x
.SubstructureNotifyMask|
63 local wins
= x
.query_tree()
64 for _
,win
in ipairs(wins
) do
65 local a
=win
:get_attributes()
67 -- ignore overriden windows
68 if a
.override_redirect
then
71 if a
.map_state
== x
.IsViewable
or win
:getwmstate() == atom
.IconicState
then
77 function cwm
.grabkeys(win
,map
)
78 for k
,func
in pairs(map
) do
81 for e
in string.gmatch(k
, "[^+-]*") do
82 if e
== "" then continue
end
86 modmask
= $ | x
[mt
[i
].."Mask"]
88 local key
= x
.keysym2keycode(x
.string2keysym(mt
[#mt
]))
91 win
:grab_key(key
, modmask
)
93 -- and register handler
94 cwm
.winkeys
[win
] = $
or {}
95 cwm
.winkeys
[win
][modmask
] = $
or {}
96 cwm
.winkeys
[win
][modmask
][key
] = func
101 cwm
.grabkeys(cwm
.root
,keymap
)
106 -- prepare input event mask
108 print("waiting for next event")
109 local ev
=x
.get_events()
111 print("GOT EVENT", ev
.type)