Class: Gtk2AppLib::KeyPressEvents

Inherits:
Object
  • Object
show all
Defined in:
lib/gtk2applib/key_press_events.rb

Overview

Currently used to toggle fullscreen mode with key bindings

Instance Method Summary (collapse)

Constructor Details

- (KeyPressEvents) initialize(program)



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gtk2applib/key_press_events.rb', line 5

def initialize(program)
  @program = program; @control = @shift = false # Cheating tailor :))
  @program.window.signal_connect('key-press-event') do |widget, event|
    keyval, @cascade, @time = event.keyval, false, event.time
    case keyval
    when Gdk::Keyval::GDK_Control_L
      @control = true; @shift = false
    when Gdk::Keyval::GDK_Shift_L
      @shift = true
    else
      key_case(keyval)
      @control = @shift = false
    end
    @cascade
  end
end

Instance Method Details

- (Object) key_case(keyval)

defined: key_case



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gtk2applib/key_press_events.rb', line 58

def key_case(keyval) # defined: key_case
  if @control then
    if @shift then
      key_case_control_shift(keyval)
    else
      key_case_control(keyval)
    end
  else
    key_case_normal(keyval)
  end
end

- (Object) key_case_control(keyval_control)



28
29
30
31
32
33
34
35
36
37
# File 'lib/gtk2applib/key_press_events.rb', line 28

def key_case_control(keyval_control)
  case keyval_control
  when Gdk::Keyval::GDK_Up
    @program.fullscreen
  when Gdk::Keyval::GDK_Down
    @program.unfullscreen
  when Gdk::Keyval::GDK_Left
    popup_menu(keyval_control)
  end
end

- (Object) key_case_control_shift(keyval_control_shift)



39
40
41
42
43
44
45
# File 'lib/gtk2applib/key_press_events.rb', line 39

def key_case_control_shift(keyval_control_shift)
  case keyval_control_shift
  when 70, 102 # Toggle on Ctrl-Shift-F
    #toggle_fs
    @program.fs
  end
end

- (Object) key_case_normal(keyval_normal)



47
48
49
50
51
52
53
54
55
56
# File 'lib/gtk2applib/key_press_events.rb', line 47

def key_case_normal(keyval_normal)
  case keyval_normal
  when Gdk::Keyval::GDK_F4
    popup(keyval_normal)
    @cascade = true
  when Gdk::Keyval::GDK_F6, Gdk::Keyval::GDK_F11
    #toggle_fullscreen
    @program.fs
  end
end


22
23
24
# File 'lib/gtk2applib/key_press_events.rb', line 22

def popup(keyval)
  @program.menu.popup(nil, nil, keyval, @time)
end