Input system reorganized to fix several coroutine bugs
[conkeror.git] / modules / global-overlay-keymap.js
blobed77061a18ab81e8407978f984f8a4acfcf00d9b
1 /**
2  * (C) Copyright 2008 Jeremy Maitin-Shepard
3  * (C) Copyright 2008-2009 John J. Foerch
4  *
5  * Use, modification, and distribution are subject to the terms specified in the
6  * COPYING file.
7 **/
9 require("input.js");
11 define_keymap("global_overlay_keymap");
14 function global_overlay_keymap_handler (window, I, true_event) {
15     var binding = keymap_lookup([global_overlay_keymap], I.combo, I.event);
16     if (!binding)
17         return false;
18     input_handle_binding(I, true_event, binding);
19     return true;
23 define_global_mode("global_overlay_keymap_mode",
24                    function () {
25                        add_hook("keypress_hook", global_overlay_keymap_handler);
26                    },
27                    function () {
28                        remove_hook("keypress_hook", global_overlay_keymap_handler);
29                    });
32 function define_key_alias (typed_key, generated_key) {
33     var name = "generate-key-event:"+generated_key;
35     // This is not a prefix command, because we need finer-grained control over the input state.
36     interactive(name,
37         "Generate a fake key press event for the key: "+generated_key,
38         function (I) {
39             // Effectively leave the input state almost exactly as it was prior to this key event
40             if (!I.first_event)
41                 input_continue_with_state(I);
43             // Warning: event handler is called before send_key_as_event returns
44             send_key_as_event(I.window,
45                               I.buffer.focused_element,
46                               generated_key);
47         });
48     define_key(global_overlay_keymap, typed_key, name);
49     global_overlay_keymap_mode(true);
51 ignore_function_for_get_caller_source_code_reference("define_key_alias");
54 function define_sticky_modifier (typed_key, modifiers) {
55     var name = "sticky-modifiers:"+modifiers;
56     interactive(name, "Set sticky modifiers: "+modifiers,
57                 function (I) {
58                     I.sticky_modifiers = modifiers;
59                 }, $prefix);
60     define_key(global_overlay_keymap, typed_key, name);
61     global_overlay_keymap_mode(true);
63 ignore_function_for_get_caller_source_code_reference("define_sticky_modifier");
65 provide("global-overlay-keymap");