Class: XlibObj::Error

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

Instance Method Summary collapse

Constructor Details

#initialize(display, error) ⇒ Error

Returns a new instance of Error.



11
12
13
14
# File 'lib/error.rb', line 11

def initialize(display, error)
  @display = display
  @error = error
end

Instance Method Details

#codeObject



16
17
18
# File 'lib/error.rb', line 16

def code
  @error[:error_code]
end

#code_descriptionObject



52
53
54
55
56
57
58
# File 'lib/error.rb', line 52

def code_description
  message_size = 2**16
  message = FFI::MemoryPointer.new(:char, message_size)
  Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, 'MajorCode',
    'Request Major code %d', message, message_size)
  message.read_string.gsub('%d', code.to_s)
end

#descriptionObject



32
33
34
35
36
37
# File 'lib/error.rb', line 32

def description
  "#{general_description}\n" <<
  " #{code_description}\n" <<
  ((code >= 128) ? " #{minor_code_description}\n" : "") <<
  " #{resource_description}"
end

#general_descriptionObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/error.rb', line 39

def general_description
  type_size = 2**16
  type = FFI::MemoryPointer.new(:char, type_size)
  Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, 'XError', 'X Error', type,
    type_size)

  details_size = 2**16
  details = FFI::MemoryPointer.new(:char, details_size)
  Xlib.XGetErrorText(@display.to_native, code, details, details_size)

  "#{type.read_string}: #{details.read_string}"
end

#minor_codeObject



20
21
22
# File 'lib/error.rb', line 20

def minor_code
  @error[:minor_code]
end

#minor_code_descriptionObject



60
61
62
63
64
65
66
# File 'lib/error.rb', line 60

def minor_code_description
  message_size = 2**16
  message = FFI::MemoryPointer.new(:char, message_size)
  Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, 'MinorCode',
    'Request Minor code %d', message, message_size)
  message.read_string.gsub('%d', minor_code.to_s)
end

#requestObject



24
25
26
# File 'lib/error.rb', line 24

def request
  @error[:request_code]
end

#resourceObject



28
29
30
# File 'lib/error.rb', line 28

def resource
  @error[:resourceid]
end

#resource_descriptionObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/error.rb', line 68

def resource_description
  message_size = 2**16
  message = FFI::MemoryPointer.new(:char, message_size)

  if [Xlib::BadWindow, Xlib::BadPixmap, Xlib::BadCursor, Xlib::BadFont, Xlib::BadDrawable,
    Xlib::BadColor, Xlib::BadGC, Xlib::BadIDChoice].include?(code)
    Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, "ResourceID",
      "ResourceID %x", message, message_size)
  elsif code == Xlib::BadValue
    Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, "Value", "Value 0x%x",
      message, message_size)
  elsif code == Xlib::BadAtom
    Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, "AtomID", "AtomID 0x%x",
      message, message_size)
  end

  message.read_string.gsub('%x', resource.to_s)
end