Contribs: Die if NO_RELOCATION
[vlc/davidf-public.git] / share / lua / intf / hotkeys.lua
blobe2bb5a7d7a5bdb49dbf4d47a364d10fdd24ce05d
1 --[==========================================================================[
2 hotkeys.lua: hotkey handling for VLC
3 --[==========================================================================[
4 Copyright (C) 2007 the VideoLAN team
5 $Id$
7 Authors: Antoine Cellerier <dionoea at videolan dot org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 --]==========================================================================]
24 --[==========================================================================[
25 This is meant to replace modules/control/hotkeys.c
26 (which will require some changes in the VLC core hotkeys stuff)
27 --]==========================================================================]
29 require("common")
30 --common.table_print(vlc,"vlc.\t")
32 bindings = {
33 ["Ctrl-q"] = "quit",
34 ["Space"] = "play-pause",
35 [113] --[[q]] = "quit",
36 [119] --[[w]] = "demo",
37 [120] --[[x]] = "demo2",
40 function quit()
41 print("Bye-bye!")
42 vlc.quit()
43 end
45 function demo()
46 vlc.osd.icon("speaker")
47 end
49 function demo2()
50 if not channel1 then
51 channel1 = vlc.osd.channel_register()
52 channel2 = vlc.osd.channel_register()
53 end
54 vlc.osd.message("Hey!",channel1)
55 vlc.osd.slider( 10, "horizontal", channel2 )
56 end
58 function action(func,delta)
59 return { func = func, delta = delta or 0, last = 0, times = 0 }
60 end
62 actions = {
63 ["quit"] = action(quit),
64 ["play-pause"] = action(play_pause),
65 ["demo"] = action(demo),
66 ["demo2"] = action(demo2),
69 action = nil
71 queue = {}
73 function action_trigger( action )
74 print("action_trigger:",tostring(action))
75 local a = actions[action]
76 if a then
77 local date = vlc.misc.mdate()
78 if a.delta and date > a.last + a.delta then
79 a.times = 0
80 else
81 a.times = a.times + 1
82 end
83 a.last = date
84 table.insert(queue,action)
85 vlc.misc.signal()
86 else
87 vlc.msg.err("Key `"..key.."' points to unknown action `"..bindings[key].."'.")
88 end
89 end
91 function key_press( var, old, new, data )
92 local key = new
93 print("key_press:",tostring(key))
94 if bindings[key] then
95 action_trigger(bindings[key])
96 else
97 vlc.msg.err("Key `"..key.."' isn't bound to any action.")
98 end
99 end
101 vlc.var.add_callback( vlc.object.libvlc(), "key-pressed", key_press )
102 --vlc.var.add_callback( vlc.object.libvlc(), "action-triggered", action_trigger )
104 while not die do
105 if #queue ~= 0 then
106 local action = actions[queue[1]]
107 local ok, msg = pcall( action.func )
108 if not ok then
109 vlc.msg.err("Error while executing action `"..queue[1].."': "..msg)
111 table.remove(queue,1)
112 else
113 die = vlc.misc.lock_and_wait()
117 -- Clean up
118 vlc.var.del_callback( vlc.object.libvlc(), "key-pressed", key_press )
119 --vlc.var.del_callback( vlc.object.libvlc(), "action-triggered", action_trigger )