libx11 0.0.1 → 0.0.2

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: 5470e66191c0df5203bc4201954f1af174ceb01f
4
- data.tar.gz: 18233f3455a6506909fd94069fb27948adbd40c0
3
+ metadata.gz: 996d4981cc702796abf6b30fb2b661e5361ae55b
4
+ data.tar.gz: 84f21999388262f0e1160a20edc1cd78e9aac4aa
5
5
  SHA512:
6
- metadata.gz: 6e3f28123a72e3685d4559dc657e49d9aaa332583f87b2138bede8655b7218755c127d006f6333111fbb2d651d1d332748be8e6ef8302f32ba1be39efb2fd27e
7
- data.tar.gz: 7264300898eae2f4aba5a28d662f0754fe15fdfc257f4c31644819a7d3aa068335799f15ccca6ffc0b089980c04779c9562572fd9cbc6bf5b879f5e84f8cb19b
6
+ metadata.gz: b2f137d6b53df72a7b4253346eef3b438ebce9900ea88d9e0324d8390230253f138f726acc7721b0ea13991a1e9bad6130010f057c0c9bcb419b592e961a905a
7
+ data.tar.gz: 6017df38ffec47e0d79bc41f1fdfad7c2a048f220799ba8bcfe5ae0fa249a9a504dad401d56e488f2eebaf7712d224eb363bd9caeab2205160f5eb61cf1c2d30
@@ -2,3 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 2.3.0
4
4
  before_install: gem install bundler -v 1.11.2
5
+ script:
6
+ - bundle install
7
+ - bundle exec rake compile
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # LibX11
1
+ # LibX11 [![Build Status](https://travis-ci.org/k0kubun/libx11-ruby.svg?branch=master)](https://travis-ci.org/k0kubun/libx11-ruby)
2
2
 
3
- Ruby binding for libx11 including xlib.
3
+ Ruby binding of libx11 mostly for xlib.
4
4
 
5
5
  ## Status
6
6
 
@@ -1,14 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "libx11"
3
+ require 'bundler/setup'
4
+ require 'libx11'
5
5
 
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
6
+ require 'pry'
7
+ Pry.start
@@ -0,0 +1,53 @@
1
+ require 'libx11'
2
+
3
+ class XServer
4
+ def self.with_connection
5
+ display = LibX11.xopen_display
6
+ yield(display)
7
+ ensure
8
+ LibX11.xclose_display(display)
9
+ end
10
+
11
+ def self.bind_events(display, window, event_mask)
12
+ wm_detected = false
13
+ LibX11.xset_error_handler do |display, error|
14
+ if error.error_code == LibX11::XErrorEvent::BAD_ACCESS
15
+ wm_detected = true
16
+ end
17
+ end
18
+
19
+ display.xselect_input(window, event_mask)
20
+ display.xsync(false)
21
+
22
+ if wm_detected
23
+ abort "Another window manager detected!\n#{display.xdisplay_string}"
24
+ end
25
+ end
26
+ end
27
+
28
+ XServer.with_connection do |display|
29
+ XServer.bind_events(
30
+ display, display.default_root_window,
31
+ LibX11::XEvent::KEY_PRESS_MASK |
32
+ LibX11::XEvent::SUBSTRUCTURE_REDIRECT_MASK |
33
+ LibX11::XEvent::SUBSTRUCTURE_NOTIFY_MASK,
34
+ )
35
+
36
+ LibX11.xset_error_handler do |display, error|
37
+ $stderr.puts "Error detected: (error_code=#{error.error_code})"
38
+ end
39
+
40
+ loop do
41
+ event = LibX11.xnext_event(display)
42
+ case event.type
43
+ when LibX11::XEvent::CREATE_NOTIFY
44
+ # hook creation
45
+ when LibX11::XEvent::DESTROY_NOTIFY
46
+ # hook destruction
47
+ when LibX11::XEvent::REPARENT_NOTIFY
48
+ # hook reparenting
49
+ when LibX11::XEvent::KEY_PRESS
50
+ break
51
+ end
52
+ end
53
+ end
@@ -27,12 +27,20 @@ const rb_data_type_t display_type = {
27
27
  * Xlib XOpenDisplay
28
28
  */
29
29
  static VALUE
30
- rb_libx11_xopen_display(VALUE self, VALUE display_name)
30
+ rb_libx11_xopen_display(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self))
31
31
  {
32
32
  Display *display;
33
- Check_Type(display_name, T_STRING);
34
33
 
35
- display = XOpenDisplay(RSTRING_PTR(display_name));
34
+ if (argc == 0) {
35
+ display = XOpenDisplay(NULL);
36
+ } else {
37
+ VALUE display_name;
38
+
39
+ rb_check_arity(argc, 1, 1);
40
+ rb_scan_args(argc, argv, "10", &display_name);
41
+ Check_Type(display_name, T_STRING);
42
+ display = XOpenDisplay(RSTRING_PTR(display_name));
43
+ }
36
44
  return TypedData_Wrap_Struct(rb_cDisplay, &display_type, display);
37
45
  }
38
46
 
@@ -62,6 +70,18 @@ rb_display_default_screen(VALUE self)
62
70
  return INT2NUM(DefaultScreen(display));
63
71
  }
64
72
 
73
+ /*
74
+ * Xlib XDisplayString
75
+ */
76
+ static VALUE
77
+ rb_display_xdisplay_string(VALUE self)
78
+ {
79
+ Display *display;
80
+
81
+ TypedData_Get_Struct(self, Display, &display_type, display);
82
+ return rb_str_new_cstr(XDisplayString(display));
83
+ }
84
+
65
85
  /*
66
86
  * Xlib DefaultRootWindow
67
87
  */
@@ -130,17 +150,33 @@ rb_display_xmap_window(VALUE self, VALUE window)
130
150
  return INT2NUM(ret);
131
151
  }
132
152
 
153
+ /*
154
+ * Xlib XSync
155
+ */
156
+ static VALUE
157
+ rb_display_xsync(VALUE self, VALUE discard)
158
+ {
159
+ Display *display;
160
+ int ret;
161
+
162
+ TypedData_Get_Struct(self, Display, &display_type, display);
163
+ ret = XSync(display, RTEST(discard));
164
+ return INT2NUM(ret);
165
+ }
166
+
133
167
  void
134
168
  Init_libx11_display(void)
135
169
  {
136
- rb_define_singleton_method(rb_mLibX11, "xopen_display", rb_libx11_xopen_display, 1);
170
+ rb_define_singleton_method(rb_mLibX11, "xopen_display", rb_libx11_xopen_display, -1);
137
171
  rb_define_singleton_method(rb_mLibX11, "xclose_display", rb_libx11_xclose_display, 1);
138
172
 
139
173
  rb_cDisplay = rb_define_class_under(rb_mLibX11, "Display", rb_cData);
140
174
  rb_define_method(rb_cDisplay, "default_root_window", rb_display_default_root_window, 0);
141
175
  rb_define_method(rb_cDisplay, "default_screen", rb_display_default_screen, 0);
176
+ rb_define_method(rb_cDisplay, "xdisplay_string", rb_display_xdisplay_string, 0);
142
177
  rb_define_method(rb_cDisplay, "black_pixel", rb_display_black_pixel, 1);
143
178
  rb_define_method(rb_cDisplay, "white_pixel", rb_display_white_pixel, 1);
144
179
  rb_define_method(rb_cDisplay, "xmap_window", rb_display_xmap_window, 1);
145
180
  rb_define_method(rb_cDisplay, "xselect_input", rb_display_xselect_input, 2);
181
+ rb_define_method(rb_cDisplay, "xsync", rb_display_xsync, 1);
146
182
  }
@@ -6,6 +6,7 @@ Init_libx11_ruby(void)
6
6
  rb_mLibX11 = rb_define_module("LibX11");
7
7
 
8
8
  Init_libx11_display();
9
- Init_libx11_event();
10
9
  Init_libx11_window();
10
+ Init_libx11_xerror_event();
11
+ Init_libx11_xevent();
11
12
  }
@@ -2,12 +2,12 @@
2
2
  #define LIBX11_RUBY_H 1
3
3
 
4
4
  #include "ruby.h"
5
- #include <X11/Xlib.h>
6
5
 
7
6
  VALUE rb_mLibX11;
8
7
 
9
8
  void Init_libx11_display(void);
10
- void Init_libx11_event(void);
11
9
  void Init_libx11_window(void);
10
+ void Init_libx11_xerror_event(void);
11
+ void Init_libx11_xevent(void);
12
12
 
13
13
  #endif /* LIBX11_RUBY_H */
@@ -0,0 +1,104 @@
1
+ #include "libx11_ruby.h"
2
+ #include <X11/Xlib.h>
3
+
4
+ extern VALUE rb_cDisplay;
5
+ VALUE rb_cXErrorEvent;
6
+
7
+ extern rb_data_type_t display_type;
8
+
9
+ static size_t
10
+ xerror_event_dsize(const void *arg)
11
+ {
12
+ const XErrorEvent *event = arg;
13
+ return sizeof(event);
14
+ }
15
+
16
+ const rb_data_type_t xerror_event_type = {
17
+ .wrap_struct_name = "libx11_xerror_event",
18
+ .function = {
19
+ .dmark = NULL,
20
+ .dfree = NULL,
21
+ .dsize = xerror_event_dsize,
22
+ .reserved = { NULL, NULL },
23
+ },
24
+ .parent = NULL,
25
+ .data = NULL,
26
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
27
+ };
28
+
29
+ static VALUE error_handler_proc = Qnil;
30
+
31
+ static int
32
+ error_handler_func(Display *display, XErrorEvent *event)
33
+ {
34
+ if (NIL_P(error_handler_proc)) {
35
+ return 1;
36
+ } else {
37
+ VALUE args = rb_ary_new();
38
+ rb_ary_push(args, TypedData_Wrap_Struct(rb_cDisplay, &display_type, display));
39
+ rb_ary_push(args, TypedData_Wrap_Struct(rb_cXErrorEvent, &xerror_event_type, event));
40
+ rb_proc_call(error_handler_proc, args);
41
+ return 0;
42
+ }
43
+ }
44
+
45
+ /*
46
+ * Xlib XSetErrorHandler
47
+ */
48
+ static VALUE
49
+ rb_libx11_xset_error_handler(int argc, VALUE *argv, VALUE self)
50
+ {
51
+ rb_check_arity(argc, 0, 0);
52
+ rb_scan_args(argc, argv, "00&", &error_handler_proc);
53
+
54
+ XSetErrorHandler(error_handler_func);
55
+ return Qnil;
56
+ }
57
+
58
+ static VALUE
59
+ rb_xerror_event_error_code(VALUE self)
60
+ {
61
+ XErrorEvent *event;
62
+ TypedData_Get_Struct(self, XErrorEvent, &xerror_event_type, event);
63
+ return INT2FIX(event->error_code);
64
+ }
65
+
66
+ static VALUE
67
+ rb_xerror_event_type(VALUE self)
68
+ {
69
+ XErrorEvent *event;
70
+ TypedData_Get_Struct(self, XErrorEvent, &xerror_event_type, event);
71
+ return INT2FIX(event->type);
72
+ }
73
+
74
+ void
75
+ Init_libx11_xerror_event(void)
76
+ {
77
+ rb_define_singleton_method(rb_mLibX11, "xset_error_handler", rb_libx11_xset_error_handler, -1);
78
+
79
+ rb_cXErrorEvent = rb_define_class_under(rb_mLibX11, "XErrorEvent", rb_cData);
80
+ rb_define_method(rb_cXErrorEvent, "error_code", rb_xerror_event_error_code, 0);
81
+ rb_define_method(rb_cXErrorEvent, "type", rb_xerror_event_type, 0);
82
+
83
+ // error codes
84
+ rb_define_const(rb_cXErrorEvent, "SUCCESS", INT2FIX(Success));
85
+ rb_define_const(rb_cXErrorEvent, "BAD_REQUEST", INT2FIX(BadRequest));
86
+ rb_define_const(rb_cXErrorEvent, "BAD_VALUE", INT2FIX(BadValue));
87
+ rb_define_const(rb_cXErrorEvent, "BAD_WINDOW", INT2FIX(BadWindow));
88
+ rb_define_const(rb_cXErrorEvent, "BAD_PIXMAP", INT2FIX(BadPixmap));
89
+ rb_define_const(rb_cXErrorEvent, "BAD_ATOM", INT2FIX(BadAtom));
90
+ rb_define_const(rb_cXErrorEvent, "BAD_CURSOR", INT2FIX(BadCursor));
91
+ rb_define_const(rb_cXErrorEvent, "BAD_FONT", INT2FIX(BadFont));
92
+ rb_define_const(rb_cXErrorEvent, "BAD_MATCH", INT2FIX(BadMatch));
93
+ rb_define_const(rb_cXErrorEvent, "BAD_DRAWABLE", INT2FIX(BadDrawable));
94
+ rb_define_const(rb_cXErrorEvent, "BAD_ACCESS", INT2FIX(BadAccess));
95
+ rb_define_const(rb_cXErrorEvent, "BAD_ALLOC", INT2FIX(BadAlloc));
96
+ rb_define_const(rb_cXErrorEvent, "BAD_COLOR", INT2FIX(BadColor));
97
+ rb_define_const(rb_cXErrorEvent, "BAD_GC", INT2FIX(BadGC));
98
+ rb_define_const(rb_cXErrorEvent, "BAD_ID_CHOICE", INT2FIX(BadIDChoice));
99
+ rb_define_const(rb_cXErrorEvent, "BAD_NAME", INT2FIX(BadName));
100
+ rb_define_const(rb_cXErrorEvent, "BAD_LENGTH", INT2FIX(BadLength));
101
+ rb_define_const(rb_cXErrorEvent, "BAD_IMPLEMENTATION", INT2FIX(BadImplementation));
102
+ rb_define_const(rb_cXErrorEvent, "FIRST_EXTENSION_ERROR", INT2FIX(FirstExtensionError));
103
+ rb_define_const(rb_cXErrorEvent, "LAST_EXTENSION_ERROR", INT2FIX(LastExtensionError));
104
+ }
@@ -0,0 +1,132 @@
1
+ #include "libx11_ruby.h"
2
+ #include <X11/Xlib.h>
3
+
4
+ VALUE rb_cXEvent;
5
+
6
+ extern rb_data_type_t display_type;
7
+
8
+ static void
9
+ xevent_dfree(void *arg)
10
+ {
11
+ XEvent *event = arg;
12
+ free(event);
13
+ }
14
+
15
+ static size_t
16
+ xevent_dsize(const void *arg)
17
+ {
18
+ const XEvent *event = arg;
19
+ return sizeof(event);
20
+ }
21
+
22
+ const rb_data_type_t xevent_type = {
23
+ .wrap_struct_name = "libx11_xevent",
24
+ .function = {
25
+ .dmark = NULL,
26
+ .dfree = xevent_dfree,
27
+ .dsize = xevent_dsize,
28
+ .reserved = { NULL, NULL },
29
+ },
30
+ .parent = NULL,
31
+ .data = NULL,
32
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
33
+ };
34
+
35
+ /*
36
+ * Xlib XNextEvent
37
+ */
38
+ static VALUE
39
+ rb_libx11_xnext_event(VALUE self, VALUE obj)
40
+ {
41
+ Display *display;
42
+ XEvent *event;
43
+
44
+ TypedData_Get_Struct(obj, Display, &display_type, display);
45
+
46
+ event = (XEvent *)malloc(sizeof(XEvent));
47
+ XNextEvent(display, event);
48
+ return TypedData_Wrap_Struct(rb_cXEvent, &xevent_type, event);
49
+ }
50
+
51
+ static VALUE
52
+ rb_xevent_type(VALUE self)
53
+ {
54
+ XEvent *event;
55
+
56
+ TypedData_Get_Struct(self, XEvent, &xevent_type, event);
57
+ return INT2NUM(event->type);
58
+ }
59
+
60
+ void
61
+ Init_libx11_xevent(void)
62
+ {
63
+ rb_define_singleton_method(rb_mLibX11, "xnext_event", rb_libx11_xnext_event, 1);
64
+
65
+ rb_cXEvent = rb_define_class_under(rb_mLibX11, "XEvent", rb_cData);
66
+ rb_define_method(rb_cXEvent, "type", rb_xevent_type, 0);
67
+
68
+ // event masks
69
+ rb_define_const(rb_cXEvent, "NO_EVENT_MASK", LONG2NUM(NoEventMask));
70
+ rb_define_const(rb_cXEvent, "KEY_PRESS_MASK", LONG2NUM(KeyPressMask));
71
+ rb_define_const(rb_cXEvent, "KEY_RELEASE_MASK", LONG2NUM(KeyReleaseMask));
72
+ rb_define_const(rb_cXEvent, "BUTTON_PRESS_MASK", LONG2NUM(ButtonPressMask));
73
+ rb_define_const(rb_cXEvent, "BUTTON_RELEASE_MASK", LONG2NUM(ButtonReleaseMask));
74
+ rb_define_const(rb_cXEvent, "ENTER_WINDOW_MASK", LONG2NUM(EnterWindowMask));
75
+ rb_define_const(rb_cXEvent, "LEAVE_WINDOW_MASK", LONG2NUM(LeaveWindowMask));
76
+ rb_define_const(rb_cXEvent, "POINTER_MOTION_MASK", LONG2NUM(PointerMotionMask));
77
+ rb_define_const(rb_cXEvent, "POINTER_MOTION_HINT_MASK", LONG2NUM(PointerMotionHintMask));
78
+ rb_define_const(rb_cXEvent, "BUTTON1_MOTION_MASK", LONG2NUM(Button1MotionMask));
79
+ rb_define_const(rb_cXEvent, "BUTTON2_MOTION_MASK", LONG2NUM(Button2MotionMask));
80
+ rb_define_const(rb_cXEvent, "BUTTON3_MOTION_MASK", LONG2NUM(Button3MotionMask));
81
+ rb_define_const(rb_cXEvent, "BUTTON4_MOTION_MASK", LONG2NUM(Button4MotionMask));
82
+ rb_define_const(rb_cXEvent, "BUTTON5_MOTION_MASK", LONG2NUM(Button5MotionMask));
83
+ rb_define_const(rb_cXEvent, "BUTTON_MOTION_MASK", LONG2NUM(ButtonMotionMask));
84
+ rb_define_const(rb_cXEvent, "KEYMAP_STATE_MASK", LONG2NUM(KeymapStateMask));
85
+ rb_define_const(rb_cXEvent, "EXPOSURE_MASK", LONG2NUM(ExposureMask));
86
+ rb_define_const(rb_cXEvent, "VISIBILITY_CHANGE_MASK", LONG2NUM(VisibilityChangeMask));
87
+ rb_define_const(rb_cXEvent, "STRUCTURE_NOTIFY_MASK", LONG2NUM(StructureNotifyMask));
88
+ rb_define_const(rb_cXEvent, "RESIZE_REDIRECT_MASK", LONG2NUM(ResizeRedirectMask));
89
+ rb_define_const(rb_cXEvent, "SUBSTRUCTURE_NOTIFY_MASK", LONG2NUM(SubstructureNotifyMask));
90
+ rb_define_const(rb_cXEvent, "SUBSTRUCTURE_REDIRECT_MASK", LONG2NUM(SubstructureRedirectMask));
91
+ rb_define_const(rb_cXEvent, "FOCUS_CHANGE_MASK", LONG2NUM(FocusChangeMask));
92
+ rb_define_const(rb_cXEvent, "PROPERTY_CHANGE_MASK", LONG2NUM(PropertyChangeMask));
93
+ rb_define_const(rb_cXEvent, "COLORMAP_CHANGE_MASK", LONG2NUM(ColormapChangeMask));
94
+ rb_define_const(rb_cXEvent, "OWNER_GRAB_BUTTON_MASK", LONG2NUM(OwnerGrabButtonMask));
95
+
96
+ // event
97
+ rb_define_const(rb_cXEvent, "KEY_PRESS", INT2FIX(KeyPress));
98
+ rb_define_const(rb_cXEvent, "KEY_RELEASE", INT2FIX(KeyRelease));
99
+ rb_define_const(rb_cXEvent, "BUTTON_PRESS", INT2FIX(ButtonPress));
100
+ rb_define_const(rb_cXEvent, "BUTTON_RELEASE", INT2FIX(ButtonRelease));
101
+ rb_define_const(rb_cXEvent, "MOTION_NOTIFY", INT2FIX(MotionNotify));
102
+ rb_define_const(rb_cXEvent, "ENTER_NOTIFY", INT2FIX(EnterNotify));
103
+ rb_define_const(rb_cXEvent, "LEAVE_NOTIFY", INT2FIX(LeaveNotify));
104
+ rb_define_const(rb_cXEvent, "FOCUS_IN", INT2FIX(FocusIn));
105
+ rb_define_const(rb_cXEvent, "FOCUS_OUT", INT2FIX(FocusOut));
106
+ rb_define_const(rb_cXEvent, "KEYMAP_NOTIFY", INT2FIX(KeymapNotify));
107
+ rb_define_const(rb_cXEvent, "EXPOSE", INT2FIX(Expose));
108
+ rb_define_const(rb_cXEvent, "GRAPHICS_EXPOSE", INT2FIX(GraphicsExpose));
109
+ rb_define_const(rb_cXEvent, "NO_EXPOSE", INT2FIX(NoExpose));
110
+ rb_define_const(rb_cXEvent, "VISIBILITY_NOTIFY", INT2FIX(VisibilityNotify));
111
+ rb_define_const(rb_cXEvent, "CREATE_NOTIFY", INT2FIX(CreateNotify));
112
+ rb_define_const(rb_cXEvent, "DESTROY_NOTIFY", INT2FIX(DestroyNotify));
113
+ rb_define_const(rb_cXEvent, "UNMAP_NOTIFY", INT2FIX(UnmapNotify));
114
+ rb_define_const(rb_cXEvent, "MAP_NOTIFY", INT2FIX(MapNotify));
115
+ rb_define_const(rb_cXEvent, "MAP_REQUEST", INT2FIX(MapRequest));
116
+ rb_define_const(rb_cXEvent, "REPARENT_NOTIFY", INT2FIX(ReparentNotify));
117
+ rb_define_const(rb_cXEvent, "CONFIGURE_NOTIFY", INT2FIX(ConfigureNotify));
118
+ rb_define_const(rb_cXEvent, "CONFIGURE_REQUEST", INT2FIX(ConfigureRequest));
119
+ rb_define_const(rb_cXEvent, "GRAVITY_NOTIFY", INT2FIX(GravityNotify));
120
+ rb_define_const(rb_cXEvent, "RESIZE_REQUEST", INT2FIX(ResizeRequest));
121
+ rb_define_const(rb_cXEvent, "CIRCULATE_NOTIFY", INT2FIX(CirculateNotify));
122
+ rb_define_const(rb_cXEvent, "CIRCULATE_REQUEST", INT2FIX(CirculateRequest));
123
+ rb_define_const(rb_cXEvent, "PROPERTY_NOTIFY", INT2FIX(PropertyNotify));
124
+ rb_define_const(rb_cXEvent, "SELECTION_CLEAR", INT2FIX(SelectionClear));
125
+ rb_define_const(rb_cXEvent, "SELECTION_REQUEST", INT2FIX(SelectionRequest));
126
+ rb_define_const(rb_cXEvent, "SELKECTION_NOTIFY", INT2FIX(SelectionNotify));
127
+ rb_define_const(rb_cXEvent, "COLORMAP_NOTIFY", INT2FIX(ColormapNotify));
128
+ rb_define_const(rb_cXEvent, "CLIENT_MESSAGE", INT2FIX(ClientMessage));
129
+ rb_define_const(rb_cXEvent, "MAPPING_NOTIFY", INT2FIX(MappingNotify));
130
+ rb_define_const(rb_cXEvent, "GENERIC_EVENT", INT2FIX(GenericEvent));
131
+ rb_define_const(rb_cXEvent, "LAST_EVENT", INT2FIX(LASTEvent));
132
+ }
@@ -1,3 +1,3 @@
1
1
  module LibX11
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Takashi Kokubun']
10
10
  spec.email = ['takashikkbn@gmail.com']
11
11
 
12
- spec.summary = 'Ruby binding for libx11 including xlib'
13
- spec.description = 'Ruby binding for libx11 including xlib'
12
+ spec.summary = 'Ruby binding of libx11 mostly for xlib'
13
+ spec.description = 'Ruby binding of libx11 mostly for xlib'
14
14
  spec.homepage = 'https://github.com/k0kubun/libx11-ruby'
15
15
  spec.license = 'MIT'
16
16
 
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
25
  spec.add_development_dependency 'rake-compiler'
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'pry-byebug'
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libx11
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-06 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,21 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
- description: Ruby binding for libx11 including xlib
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby binding of libx11 mostly for xlib
70
84
  email:
71
85
  - takashikkbn@gmail.com
72
86
  executables: []
@@ -84,12 +98,14 @@ files:
84
98
  - bin/console
85
99
  - bin/setup
86
100
  - example/create_window.rb
101
+ - example/window_manager.rb
87
102
  - ext/libx11_ruby/display.c
88
- - ext/libx11_ruby/event.c
89
103
  - ext/libx11_ruby/extconf.rb
90
104
  - ext/libx11_ruby/libx11_ruby.c
91
105
  - ext/libx11_ruby/libx11_ruby.h
92
106
  - ext/libx11_ruby/window.c
107
+ - ext/libx11_ruby/xerror_event.c
108
+ - ext/libx11_ruby/xevent.c
93
109
  - lib/libx11.rb
94
110
  - lib/libx11/version.rb
95
111
  - libx11.gemspec
@@ -116,6 +132,6 @@ rubyforge_project:
116
132
  rubygems_version: 2.5.1
117
133
  signing_key:
118
134
  specification_version: 4
119
- summary: Ruby binding for libx11 including xlib
135
+ summary: Ruby binding of libx11 mostly for xlib
120
136
  test_files: []
121
137
  has_rdoc:
@@ -1,70 +0,0 @@
1
- #include "libx11_ruby.h"
2
- #include <X11/Xlib.h>
3
-
4
- VALUE rb_cXEvent;
5
-
6
- extern rb_data_type_t display_type;
7
-
8
- static void
9
- xevent_dfree(void *arg)
10
- {
11
- XEvent *event = arg;
12
- free(event);
13
- }
14
-
15
- static size_t
16
- xevent_dsize(const void *arg)
17
- {
18
- const XEvent *event = arg;
19
- return sizeof(event);
20
- }
21
-
22
- const rb_data_type_t xevent_type = {
23
- .wrap_struct_name = "libx11_xevent",
24
- .function = {
25
- .dmark = NULL,
26
- .dfree = xevent_dfree,
27
- .dsize = xevent_dsize,
28
- .reserved = { NULL, NULL },
29
- },
30
- .parent = NULL,
31
- .data = NULL,
32
- .flags = RUBY_TYPED_FREE_IMMEDIATELY,
33
- };
34
-
35
- /*
36
- * Xlib XNextEvent
37
- */
38
- static VALUE
39
- rb_libx11_xnext_event(VALUE self, VALUE obj)
40
- {
41
- Display *display;
42
- XEvent *event;
43
-
44
- TypedData_Get_Struct(obj, Display, &display_type, display);
45
-
46
- event = (XEvent *)malloc(sizeof(XEvent));
47
- XNextEvent(display, event);
48
- return TypedData_Wrap_Struct(rb_cXEvent, &xevent_type, event);
49
- }
50
-
51
- static VALUE
52
- rb_xevent_type(VALUE self)
53
- {
54
- XEvent *event;
55
-
56
- TypedData_Get_Struct(self, XEvent, &xevent_type, event);
57
- return INT2NUM(event->type);
58
- }
59
-
60
- void
61
- Init_libx11_event(void)
62
- {
63
- rb_define_singleton_method(rb_mLibX11, "xnext_event", rb_libx11_xnext_event, 1);
64
-
65
- rb_cXEvent = rb_define_class_under(rb_mLibX11, "XEvent", rb_cData);
66
- rb_define_method(rb_cXEvent, "type", rb_xevent_type, 0);
67
-
68
- rb_define_const(rb_cXEvent, "KEY_PRESS_MASK", LONG2FIX(KeyPressMask));
69
- rb_define_const(rb_cXEvent, "KEY_PRESS", INT2FIX(KeyPress));
70
- }