3 Email: deryni@unreliablesource.net
4 Summary: Displays an WInfoWin on XkbBell events, also sets xkbbell grattr:s on the frame containing the window that triggered the event.
6 Last Updated: 2011-05-05
8 Copyright (c) Etan Reisner 2011
11 local bell_hook
= ioncore
.get_hook("xkb_bell_event")
13 pcall(dopath
, "mod_xkbevents")
14 bell_hook
= ioncore
.get_hook("xkb_bell_event")
16 warn("Could not load mod_xkbevents.")
21 xkbbell
= xkbbell
or {}
22 if not xkbbell
.timeout
then
23 xkbbell
.timeout
= 10000
25 if not xkbbell
.low_threshold
then
26 xkbbell
.low_threshold
= 50
28 if not xkbbell
.medium_threshold
then
29 xkbbell
.medium_threshold
= 75
31 if not xkbbell
.high_threshold
then
32 xkbbell
.high_threshold
= 100
35 local timer
= ioncore
.create_timer()
36 local screen_iws
= setmetatable({}, {__mode
="kv"})
37 local iw_hide_funs
= setmetatable({}, {__mode
="kv"})
38 local active_frames
= setmetatable({}, {__mode
="kv"})
40 local function set_hidden(iw
, scr
, state
)
41 scr
= scr
or ioncore
.find_manager(iw
, "WScreen")
42 scr
:set_hidden(iw
, state
or "set")
45 local function unset_grattrs(frame
)
46 frame
:set_grattr("xkbbell", "unset")
47 frame
:set_grattr("xkbbell-low", "unset")
48 frame
:set_grattr("xkbbell-medium", "unset")
49 frame
:set_grattr("xkbbell-high", "unset")
52 local function hide_fun(iw
, scr
)
58 local function region_notify(reg
, how
)
59 if how
~= "activated" then
63 local frame
= ioncore
.find_manager(reg
, "WFrame")
64 if frame
and active_frames
[frame
] then
65 active_frames
[frame
] = nil
70 local function bell_info(tab
)
71 local style
= "xkbbell"
72 if tab
.percent
<= xkbbell
.low_threshold
then
74 elseif tab
.percent
<= xkbbell
.medium_threshold
then
75 style
= "xkbbell-medium"
76 elseif tab
.percent
<= xkbbell
.high_threshold
then
77 style
= "xkbbell-high"
81 local frame
= ioncore
.find_manager(tab
.window
, "WFrame")
83 local cframe
= ioncore
.find_manager(ioncore
.current(), "WFrame")
84 if frame
~= cframe
then
85 active_frames
[frame
] = true
87 frame
:set_grattr(style
, "set")
91 -- Fall through to setting a screen iw for this bell.
94 local scr
= ioncore
.current():screen_of()
95 local iw
= screen_iws
[scr
]
96 ioncore
.defer(function()
99 name
="xkbbell"..scr
:id(),
106 geom
={x
=0,y
=0,w
=1,h
=1},
109 iw
:set_text("Bell!", -1)
111 iw_hide_funs
[scr
] = hide_fun(iw
, scr
)
114 set_hidden(iw
, scr
, "unset")
115 timer
:set(xkbbell
.timeout
, iw_hide_funs
[scr
])
119 bell_hook
:add(bell_info
)
121 local hook
= ioncore
.get_hook("region_notify")