File: lock_frame.lua

package info (click to toggle)
notion 3%2B2012042300-1
  • links: PTS, VCS
  • area: non-free
  • in suites: wheezy
  • size: 4,724 kB
  • sloc: ansic: 45,614; makefile: 544; sh: 409; perl: 113
file content (90 lines) | stat: -rw-r--r-- 2,071 bytes parent folder | download
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
--[[
Author: James Gray, Etan Reisner
Email: james at solitaryfield dot org, deryni@unreliablesource.net
IRC: yaarg, deryni
Summary: Allows locking
Version: 0.2
Last Updated: Fri Jun 22 00:59:06 EDT 2007
--]]

-- Usage:
-- F11 toggles the lock of keyboard close and resize on the currently active
-- frame.
-- META-F11 will save the name of the frame and lock it again in subsequent
-- sessions of ion.
--
-- You will need to rebind your close and kill bindings to use the
-- check_before_close and check_before_kill functions for this script to do
-- anything.
--
-- Adding
--    de.substyle("*-*-*-locked", {
--        background_colour = "yellow",
--    }),
--
--    de.substyle("*-*-*-*-locked_saved", {
--        background_colour = "white",
--    }),
-- to your theme's de.defstyle("tab-frame", {...}) style will cause locked and
-- locked+saved frames to be highlighted.

local locks = setmetatable({}, {__mode="k"})
local saved = {}

function lock_frame(frame, save)
	local name = frame:name()

	if locks[frame] then
		locks[frame] = nil
		frame:set_grattr("locked", "unset")
		if save and name then
			frame:set_grattr("locked_saved", "unset")
			saved[name] = nil
		end
	else
		locks[frame] = true
		frame:set_grattr("locked", "set")
		if save and name then
			frame:set_grattr("locked_saved", "set")
			saved[name] = true
		end
	end
end

function check_before_kill(reg)
	if not locks[reg] then
		WClientWin.kill(reg)
	end
end

function check_before_close(reg, sub)
	if (not locks[reg]) and (not locks[sub]) then
		WRegion.rqclose_propagate(reg, sub)
	end
end

ioncore.defbindings("WFrame",{
	kpress("F11", "lock_frame(_)"),
	kpress(META.."F11", "lock_frame(_, true)")
})

function save_locked()
	ioncore.write_savefile("saved_lock_frame", saved)
end

function load_locked()
	local locked = ioncore.read_savefile("saved_lock_frame") or {}

	for k,v in pairs(locked) do
		local reg = ioncore.lookup_region(k)
		lock_frame(reg, true)
	end
end

local hook = ioncore.get_hook("ioncore_deinit_hook")
if hook then
	hook:add(save_locked)
end
hook = nil

load_locked()