Released version 3-2014010503
[notion/jeffpc.git] / contrib / scripts / lock_frame.lua
blob3d989a7859b921313ab5f3888086b6e3d62c80f0
1 -- Authors: James Gray <james@solitaryfield.org>, Etan Reisner <deryni@gmail.com>
2 -- License: Unknown
3 -- Last Changed: 2007-06-22
4 --
5 --[[
6 Author: James Gray, Etan Reisner
7 Email: james at solitaryfield dot org, deryni@unreliablesource.net
8 IRC: yaarg, deryni
9 Summary: Allows locking
10 Version: 0.2
11 Last Updated: Fri Jun 22 00:59:06 EDT 2007
12 --]]
14 -- Usage:
15 -- F11 toggles the lock of keyboard close and resize on the currently active
16 -- frame.
17 -- META-F11 will save the name of the frame and lock it again in subsequent
18 -- sessions of ion.
20 -- You will need to rebind your close and kill bindings to use the
21 -- check_before_close and check_before_kill functions for this script to do
22 -- anything.
24 -- Adding
25 -- de.substyle("*-*-*-locked", {
26 -- background_colour = "yellow",
27 -- }),
29 -- de.substyle("*-*-*-*-locked_saved", {
30 -- background_colour = "white",
31 -- }),
32 -- to your theme's de.defstyle("tab-frame", {...}) style will cause locked and
33 -- locked+saved frames to be highlighted.
35 local locks = setmetatable({}, {__mode="k"})
36 local saved = {}
38 function lock_frame(frame, save)
39 local name = frame:name()
41 if locks[frame] then
42 locks[frame] = nil
43 frame:set_grattr("locked", "unset")
44 if save and name then
45 frame:set_grattr("locked_saved", "unset")
46 saved[name] = nil
47 end
48 else
49 locks[frame] = true
50 frame:set_grattr("locked", "set")
51 if save and name then
52 frame:set_grattr("locked_saved", "set")
53 saved[name] = true
54 end
55 end
56 end
58 function check_before_kill(reg)
59 if not locks[reg] then
60 WClientWin.kill(reg)
61 end
62 end
64 function check_before_close(reg, sub)
65 if (not locks[reg]) and (not locks[sub]) then
66 WRegion.rqclose_propagate(reg, sub)
67 end
68 end
70 ioncore.defbindings("WFrame",{
71 kpress("F11", "lock_frame(_)"),
72 kpress(META.."F11", "lock_frame(_, true)")
75 function save_locked()
76 ioncore.write_savefile("saved_lock_frame", saved)
77 end
79 function load_locked()
80 local locked = ioncore.read_savefile("saved_lock_frame") or {}
82 for k,v in pairs(locked) do
83 local reg = ioncore.lookup_region(k)
84 lock_frame(reg, true)
85 end
86 end
88 local hook = ioncore.get_hook("ioncore_deinit_hook")
89 if hook then
90 hook:add(save_locked)
91 end
92 hook = nil
94 load_locked()