Class: RBGL::GUI::X11::EventParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rbgl/gui/x11/event_parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(data) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rbgl/gui/x11/event_parser.rb', line 7

def parse(data)
  return nil unless data && data.bytesize == 32

  event_type = data.unpack1("C") & 0x7F

  case event_type
  when 2
    key_event(:key_press, data)
  when 3
    key_event(:key_release, data)
  when 4
    button_event(:button_press, data)
  when 5
    button_event(:button_release, data)
  when 6
    x, y = data[24, 4].unpack("ss")
    { type: :motion_notify, x: x, y: y }
  when 12
    { type: :exposure }
  when 22
    width, height = data[20, 4].unpack("vv")
    { type: :configure_notify, width: width, height: height }
  when 33
    {
      type: :client_message,
      format: data[1, 1].unpack1("C"),
      window: data[4, 4].unpack1("V"),
      message_type: data[8, 4].unpack1("V"),
      data32: data[12, 20].unpack("V5")
    }
  else
    { type: :unknown, code: event_type }
  end
end