File: closeorkill.lua

package info (click to toggle)
ion3-scripts 20050418-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 300 kB
  • ctags: 153
  • sloc: makefile: 18
file content (36 lines) | stat: -rw-r--r-- 904 bytes parent folder | download | duplicates (5)
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
--
-- closeorkill.lua 
-- 
-- This script will first attempt to close a region and, if that fails on
-- a client window and this script is called again within MAX_DIFFTIME 
-- (5 secs) time, kill the application.
--
-- To use, change (when using the default bindings)
--   kpress_waitrel(DEFAULT_MOD.."C", close_sub_or_self)
-- in ioncore-bindings.lua to
--   kpress_waitrel(DEFAULT_MOD.."C", close_or_kill_sub_or_self)
--

local MAX_DIFFTIME=5

local last_tried, last_tried_time

function close_or_kill(reg)
    local time=os.time()
    if last_tried==reg and obj_is(reg, "WClientWin") then
        if os.difftime(time, last_tried_time)<=MAX_DIFFTIME then
            reg:kill()
            last_tried=nil
            return
        end
    end
    
    last_tried=reg
    last_tried_time=time
    reg:close()
end

function close_or_kill_sub_or_self(reg)
    close_or_kill(reg:active_sub() or reg)
end