class Rabbit::KeyHandler
Public Class Methods
Source
# File lib/rabbit/key-handler.rb, line 22 def initialize(canvas, window) @canvas = canvas @window = window init end
Public Instance Methods
Source
# File lib/rabbit/key-handler.rb, line 84 def attach @window.insert_action_group("rabbit", @canvas.actions.group) @window.add_controller(@shortcut_controller) @window.add_controller(@toggle_terminal_shortcut_controller) @window.add_controller(@user_shortcut_controller) end
Source
# File lib/rabbit/key-handler.rb, line 266 def calc_slide_number(val, modifier) val += 10 if modifier.control_mask? val += 20 if modifier.alt_mask? val end
Source
# File lib/rabbit/key-handler.rb, line 58 def clear super clear_user_shortcuts end
Calls superclass method
Source
# File lib/rabbit/key-handler.rb, line 163 def clear_user_accel_group @user_accel_group = Gtk::AccelGroup.new end
Source
# File lib/rabbit/key-handler.rb, line 80 def clear_user_shortcuts @user_shortcuts.remove_all end
Source
# File lib/rabbit/key-handler.rb, line 29 def connect_key(keyval, modifier, flags, &block) trigger = Gtk::KeyvalTrigger.new(keyval, modifier) action = Gio::SimpleAction.new action.signal_connect do block.call end shortcut = Gtk::Shortcut.new(trigger, action) @user_shortcuts.append(shortcut) end
Source
# File lib/rabbit/key-handler.rb, line 63 def detach @window.insert_action_group("rabbit", nil) @window.remove_controller(@user_shortcut_controller) @window.remove_controller(@toggle_terminal_controller) @window.remove_controller(@shortcut_controller) end
Source
# File lib/rabbit/key-handler.rb, line 39 def disconnect_key(keyval, modifier) @user_shortcuts.each_with_index do |shortcut, i | if shortcut.keyval == keyval and shortcut.modifier == modifier @user_shortcuts.remove(i) break end end end
Source
# File lib/rabbit/key-handler.rb, line 71 def init @user_shortcuts = Gio::ListStore.new(Gtk::Shortcut) @user_shortcut_controller = Gtk::ShortcutController.new(@user_shortcuts) init_shortcuts init_toggle_terminal_shortcuts attach end
Source
# File lib/rabbit/key-handler.rb, line 173 def init_accel_group @accel_group = Gtk::AccelGroup.new init_keys end
Source
# File lib/rabbit/key-handler.rb, line 371 def init_alt_keys mod = Gdk::ModifierType::ALT_MASK [ ["ResetAdjustment", Keys::Alt::RESET_ADJUSTMENT_KEYS], ["ResetTimer", Keys::Alt::RESET_TIMER_KEYS], ].each do |action_name, keys| set_keys(action_name, nil, keys, mod) end end
Source
# File lib/rabbit/key-handler.rb, line 352 def init_control_keys mod = Gdk::ModifierType::CONTROL_MASK [ ["ClearGraffiti", Keys::Control::CLEAR_GRAFFITI_KEYS], ["UndoGraffiti", Keys::Control::UNDO_GRAFFITI_KEYS], ["ClearSlide", Keys::Control::CLEAR_SLIDE_KEYS], ["Print", Keys::Control::PRINT_KEYS], ["SearchSlideForward", Keys::Control::SEARCH_SLIDE_FORWARD_KEYS], ["SearchSlideBackward", Keys::Control::SEARCH_SLIDE_BACKWARD_KEYS], ["SearchSlideForwardNext", Keys::Control::SEARCH_SLIDE_FORWARD_NEXT_KEYS], ["SearchSlideBackwardNext", Keys::Control::SEARCH_SLIDE_BACKWARD_NEXT_KEYS], ["StopSlideSearch", Keys::Control::STOP_SLIDE_SEARCH_KEYS], ].each do |action_name, keys| set_keys(action_name, nil, keys, mod) end end
Source
# File lib/rabbit/key-handler.rb, line 253 def init_keys init_move_slide_keys init_no_prefix_keys init_shift_keys init_control_keys init_alt_keys end
Source
# File lib/rabbit/key-handler.rb, line 272 def init_move_slide_keys no_mod = Gdk::ModifierType.new mods = Utils.power_set([ Gdk::ModifierType::CONTROL_MASK, Gdk::ModifierType::ALT_MASK, ]) mods.each do |mod| mod = mod.inject(no_mod) do |result, item| result | item end (0..9).each do |i| key = Gdk::Keyval.const_get("KEY_#{i}") index = calc_slide_number(i, mod) set_keys("JumpToSlide", GLib::Variant.new(index, "i"), [key], mod) end (0..9).each do |i| key = Gdk::Keyval.const_get("KEY_KP_#{i}") index = calc_slide_number(i, mod) set_keys("JumpToSlide", GLib::Variant.new(index, "i"), [key], mod) end if mod == no_mod set_keys("NextSlide", nil, Keys::MOVE_TO_NEXT_SLIDE_KEYS, mod) set_keys("PreviousSlide", nil, Keys::MOVE_TO_PREVIOUS_SLIDE_KEYS, mod) else set_keys("JumpToRelativeSlide", GLib::Variant.new(calc_slide_number(0, mod), "i"), Keys::MOVE_TO_NEXT_SLIDE_KEYS, mod) set_keys("JumpToRelativeSlide", GLib::Variant.new(-calc_slide_number(0, mod), "i"), Keys::MOVE_TO_PREVIOUS_SLIDE_KEYS, mod) end end end
Source
# File lib/rabbit/key-handler.rb, line 314 def init_no_prefix_keys mod = Gdk::ModifierType.new [ ["Quit", Keys::QUIT_KEYS], ["Next", Keys::MOVE_TO_NEXT_KEYS], ["Previous", Keys::MOVE_TO_PREVIOUS_KEYS], ["FirstSlide", Keys::MOVE_TO_FIRST_KEYS], ["LastSlide", Keys::MOVE_TO_LAST_KEYS], ["ToggleFullscreen", Keys::TOGGLE_FULLSCREEN_KEYS], ["ReloadTheme", Keys::RELOAD_THEME_KEYS], ["SaveAsImage", Keys::SAVE_AS_IMAGE_KEYS], ["Iconify", Keys::ICONIFY_KEYS], ["ToggleIndexMode", Keys::TOGGLE_INDEX_MODE_KEYS], ["CacheAllSlides", Keys::CACHE_ALL_SLIDES_KEYS], ["SearchSlideForward", Keys::SEARCH_SLIDE_FORWARD_KEYS], ["SearchSlideBackward", Keys::SEARCH_SLIDE_BACKWARD_KEYS], ["SearchSlideForwardNext", Keys::SEARCH_SLIDE_FORWARD_NEXT_KEYS], ].each do |action_name, keys| set_keys(action_name, nil, keys, mod) end end
Source
# File lib/rabbit/key-handler.rb, line 336 def init_shift_keys mod = Gdk::ModifierType::SHIFT_MASK [ ["ToggleWhiteout", Keys::Shift::WHITE_OUT_KEYS], ["ToggleBlackout", Keys::Shift::BLACK_OUT_KEYS], ["ExpandHole", Keys::Shift::EXPAND_HOLE_KEYS], ["NarrowHole", Keys::Shift::NARROW_HOLE_KEYS], ["ToggleGraffitiMode", Keys::Shift::TOGGLE_GRAFFITI_MODE_KEYS], ["SearchSlideBackwardNext", Keys::Shift::SEARCH_SLIDE_BACKWARD_NEXT_KEYS], ["ToggleInfoWindow", Keys::Shift::TOGGLE_INFO_WINDOW_KEYS], ].each do |action_name, keys| set_keys(action_name, nil, keys, mod) end end
Source
# File lib/rabbit/key-handler.rb, line 91 def init_shortcuts @shortcuts = Gio::ListStore.new(Gtk::Shortcut) @shortcut_controller = Gtk::ShortcutController.new(@shortcuts) init_keys end
Source
# File lib/rabbit/key-handler.rb, line 178 def init_toggle_terminal_accel_group @toggle_terminal_accel_group = Gtk::AccelGroup.new mod = Gdk::ModifierType::SHIFT_MASK | Gdk::ModifierType::CONTROL_MASK | Gdk::ModifierType::ALT_MASK keys = Keys::ShiftControlAlt::TOGGLE_TERMINAL_KEYS set_keys("ToggleTerminal", nil, keys, mod, nil, @toggle_terminal_accel_group) end
Source
# File lib/rabbit/key-handler.rb, line 97 def init_toggle_terminal_shortcuts @toggle_terminal_shortcuts = Gio::ListStore.new(Gtk::Shortcut) @toggle_terminal_shortcut_controller = Gtk::ShortcutController.new(@toggle_terminal_shortcuts) keys = Keys::ShiftControlAlt::TOGGLE_TERMINAL_KEYS modifiers = Gdk::ModifierType::SHIFT_MASK | Gdk::ModifierType::CONTROL_MASK | Gdk::ModifierType::ALT_MASK set_keys("ToggleTerminal", nil, keys, modifiers, @toggle_terminal_shortcuts) end
Source
# File lib/rabbit/key-handler.rb, line 53 def post_terminal @window.add_controller(@shortcut_controller) @window.add_controller(@user_shortcut_controller) end
Source
# File lib/rabbit/key-handler.rb, line 48 def pre_terminal @window.remove_controller(@user_shortcut_controller) @window.remove_controller(@shortcut_controller) end
Source
# File lib/rabbit/key-handler.rb, line 210 def set_key_press_event # We can't use Gtk::AccelGroup with unmodified direction # keys. See gtk_accelerator_valid() for details. prev_keys = [ Gdk::Keyval::KEY_Up, Gdk::Keyval::KEY_Left, Gdk::Keyval::KEY_KP_Up, Gdk::Keyval::KEY_KP_Left, ] next_keys = [ Gdk::Keyval::KEY_Right, Gdk::Keyval::KEY_Down, Gdk::Keyval::KEY_KP_Right, Gdk::Keyval::KEY_KP_Down, ] @key_press_event_id = @window.signal_connect("key_press_event") do |_widget, event| handled = true modifier = event.state case event.keyval when *prev_keys if have_slide_number_related_mask?(modifier) index = calc_slide_number(0, modifier) @canvas.activate("JumpToRelativeSlide", GLib::Variant.new(-index, "i")) else @canvas.activate("PreviousSlide") end when *next_keys if have_slide_number_related_mask?(modifier) index = calc_slide_number(0, modifier) @canvas.activate("JumpToRelativeSlide", GLib::Variant.new(index, "i")) else @canvas.activate("NextSlide") end else handled = false end handled end end
Source
# File lib/rabbit/key-handler.rb, line 112 def set_keys(action_name, action_arguments, keys, modifiers, shortcuts=@shortcuts) keys.each do |key| trigger = Gtk::KeyvalTrigger.new(key, modifiers) action = Gtk::NamedAction.new("rabbit.#{action_name}") shortcut = Gtk::Shortcut.new(trigger, action) shortcut.arguments = action_arguments shortcuts.append(shortcut) end end