xlib-objects 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9c4da9ee32958e2f1e4e43b8835fdd448296e97
4
- data.tar.gz: 785ff3eebe82631886e79e7dbb557c32b61bc6d0
3
+ metadata.gz: 618e5374b429ba0d48824d30e13d755e4664408e
4
+ data.tar.gz: 915a8a62603ae84bab9a479f6298a38a3417f3bd
5
5
  SHA512:
6
- metadata.gz: 14374fec2bf80b0107b7c6caff07e1c9a0d532a9378cd85a70a9bf41491526043f48dc82b6d9203467e93d1ff449f2d3ea002d77a040e1512d74887413110482
7
- data.tar.gz: 2acfd879198ce45c68c55230eff53d429d4c40fe128fa7272c910b5ad59a1485dc1f2673f445db33ec3cec06f56ad44341c12566a120bbec464eca6bdb151e81
6
+ metadata.gz: 25ee4211bff0abea0ae06c1e9d19501e21128580207afc41cfa049d7d1e5b79a9b261202025eed789746634c9266ff97f9c761aef65aeb7c94868f065d172740
7
+ data.tar.gz: 02387a2ad113840131cf87501f433746e10e4eb9759e11c87953ce6df0f83fb4f3f8afcb2d665782c352f2f1c66bdc813555e4659e112eb77794fe474b4bafb7
data/lib/display.rb CHANGED
@@ -45,7 +45,35 @@ module XlibObj
45
45
  handle_event(next_event) while pending_events > 0
46
46
  end
47
47
 
48
+ def on_error(&callback)
49
+ @error_handler = if callback
50
+ FFI::Function.new(:pointer, [:pointer, :pointer]) do |display_ptr, error_ptr|
51
+ next if display_ptr != to_native
52
+ x_error = Xlib::XErrorEvent.new(error_ptr)
53
+ callback.call Error.new(self, x_error)
54
+ end
55
+ else
56
+ nil
57
+ end
58
+
59
+ Xlib.XSetErrorHandler(@error_handler)
60
+ end
61
+
62
+ def on_io_error(&callback)
63
+ @io_error_handler = if callback
64
+ FFI::Function.new(:pointer, [:pointer]) do |display_ptr|
65
+ next if display_ptr != to_native
66
+ callback.call
67
+ end
68
+ else
69
+ nil
70
+ end
71
+
72
+ Xlib.XSetIOErrorHandler(@io_error_handler)
73
+ end
74
+
48
75
  private
76
+
49
77
  def pending_events
50
78
  Xlib.XPending(to_native)
51
79
  end
data/lib/error.rb ADDED
@@ -0,0 +1,87 @@
1
+ #
2
+ # Copyright (c) 2014 Christopher Aue <mail@christopheraue.net>
3
+ #
4
+ # This file is part of the ruby xlib-objects gem. It is subject to the license
5
+ # terms in the LICENSE file found in the top-level directory of this
6
+ # distribution and at http://github.com/christopheraue/ruby-xlib-objects.
7
+ #
8
+
9
+ module XlibObj
10
+ class Error
11
+ def initialize(display, error)
12
+ @display = display
13
+ @error = error
14
+ end
15
+
16
+ def code
17
+ @error[:error_code]
18
+ end
19
+
20
+ def minor_code
21
+ @error[:minor_code]
22
+ end
23
+
24
+ def request
25
+ @error[:request_code]
26
+ end
27
+
28
+ def resource
29
+ @error[:resourceid]
30
+ end
31
+
32
+ def description
33
+ "#{general_description}\n" <<
34
+ " #{code_description}\n" <<
35
+ ((code >= 128) ? " #{minor_code_description}\n" : "") <<
36
+ " #{resource_description}"
37
+ end
38
+
39
+ def general_description
40
+ type_size = 2**16
41
+ type = FFI::MemoryPointer.new(:char, type_size)
42
+ Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, 'XError', 'X Error', type,
43
+ type_size)
44
+
45
+ details_size = 2**16
46
+ details = FFI::MemoryPointer.new(:char, details_size)
47
+ Xlib.XGetErrorText(@display.to_native, code, details, details_size)
48
+
49
+ "#{type.read_string}: #{details.read_string}"
50
+ end
51
+
52
+ def code_description
53
+ message_size = 2**16
54
+ message = FFI::MemoryPointer.new(:char, message_size)
55
+ Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, 'MajorCode',
56
+ 'Request Major code %d', message, message_size)
57
+ message.read_string.gsub('%d', code.to_s)
58
+ end
59
+
60
+ def minor_code_description
61
+ message_size = 2**16
62
+ message = FFI::MemoryPointer.new(:char, message_size)
63
+ Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, 'MinorCode',
64
+ 'Request Minor code %d', message, message_size)
65
+ message.read_string.gsub('%d', minor_code.to_s)
66
+ end
67
+
68
+ def resource_description
69
+ message_size = 2**16
70
+ message = FFI::MemoryPointer.new(:char, message_size)
71
+
72
+ if [Xlib::BadWindow, Xlib::BadPixmap, Xlib::BadCursor, Xlib::BadFont, Xlib::BadDrawable,
73
+ Xlib::BadColor, Xlib::BadGC, Xlib::BadIDChoice].include?(code)
74
+ Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, "ResourceID",
75
+ "ResourceID 0x%x", message, message_size)
76
+ elsif code == Xlib::BadValue
77
+ Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, "Value", "Value 0x%x",
78
+ message, message_size)
79
+ elsif code == Xlib::BadAtom
80
+ Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, "AtomID", "AtomID 0x%x",
81
+ message, message_size)
82
+ end
83
+
84
+ message.read_string.gsub('%x', resource.to_s)
85
+ end
86
+ end
87
+ end
data/lib/xlib-objects.rb CHANGED
@@ -13,6 +13,7 @@ module XlibObj; end
13
13
  require_relative 'atom'
14
14
  require_relative 'display'
15
15
  require_relative 'event'
16
+ require_relative 'error'
16
17
  require_relative 'event/client_message'
17
18
  require_relative 'screen'
18
19
  require_relative 'screen/crtc'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlib-objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Aue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-29 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xlib
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '1.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '1.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +74,7 @@ extra_rdoc_files: []
74
74
  files:
75
75
  - lib/atom.rb
76
76
  - lib/display.rb
77
+ - lib/error.rb
77
78
  - lib/event.rb
78
79
  - lib/event/client_message.rb
79
80
  - lib/screen.rb
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  version: '0'
104
105
  requirements: []
105
106
  rubyforge_project:
106
- rubygems_version: 2.2.2
107
+ rubygems_version: 2.4.5
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: A light object wrapper around xlib