File: closeorkill.lua

package info (click to toggle)
notion 3%2B2014010901-1
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 4,940 kB
  • ctags: 6,104
  • sloc: ansic: 46,870; sh: 2,008; makefile: 598; perl: 270
file content (39 lines) | stat: -rw-r--r-- 969 bytes parent folder | download | duplicates (2)
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
37
38
39
-- Authors: Unknown
-- License: Unknown
-- Last Changed: Unknown
--
-- 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