libx11 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5470e66191c0df5203bc4201954f1af174ceb01f
4
+ data.tar.gz: 18233f3455a6506909fd94069fb27948adbd40c0
5
+ SHA512:
6
+ metadata.gz: 6e3f28123a72e3685d4559dc657e49d9aaa332583f87b2138bede8655b7218755c127d006f6333111fbb2d651d1d332748be8e6ef8302f32ba1be39efb2fd27e
7
+ data.tar.gz: 7264300898eae2f4aba5a28d662f0754fe15fdfc257f4c31644819a7d3aa068335799f15ccca6ffc0b089980c04779c9562572fd9cbc6bf5b879f5e84f8cb19b
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in libx11.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Takashi Kokubun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,11 @@
1
+ # LibX11
2
+
3
+ Ruby binding for libx11 including xlib.
4
+
5
+ ## Status
6
+
7
+ Still in development
8
+
9
+ ## License
10
+
11
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require 'rake/extensiontask'
7
+
8
+ task :build => :compile
9
+
10
+ Rake::ExtensionTask.new('libx11_ruby') do |ext|
11
+ ext.lib_dir = 'lib/libx11'
12
+ end
13
+
14
+ task :default => [:clobber, :compile, :spec]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "libx11"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ require 'libx11'
2
+
3
+ WINDOW_POS_X = 100
4
+ WINDOW_POS_Y = 100
5
+ WINDOW_WIDTH = 400
6
+ WINDOW_HEIGHT = 300
7
+ BORDER_WIDTH = 2
8
+
9
+ display = LibX11.xopen_display('')
10
+
11
+ root = display.default_root_window
12
+ screen = display.default_screen
13
+
14
+ white = display.white_pixel(screen)
15
+ black = display.black_pixel(screen)
16
+
17
+ window = LibX11.xcreate_simple_window(
18
+ display, root,
19
+ WINDOW_POS_X, WINDOW_POS_Y, WINDOW_WIDTH, WINDOW_HEIGHT,
20
+ BORDER_WIDTH, black, white,
21
+ )
22
+
23
+ display.xselect_input(window, LibX11::XEvent::KEY_PRESS_MASK)
24
+ display.xmap_window(window)
25
+
26
+ loop do
27
+ event = LibX11.xnext_event(display)
28
+
29
+ case event.type
30
+ when LibX11::XEvent::KEY_PRESS
31
+ LibX11.xdestroy_window(display, window)
32
+ LibX11.xclose_display(display)
33
+ break
34
+ end
35
+ end
@@ -0,0 +1,146 @@
1
+ #include "libx11_ruby.h"
2
+ #include <X11/Xlib.h>
3
+
4
+ VALUE rb_cDisplay;
5
+
6
+ static size_t
7
+ display_dsize(const void *arg)
8
+ {
9
+ const Display *display = arg;
10
+ return sizeof(display);
11
+ }
12
+
13
+ const rb_data_type_t display_type = {
14
+ .wrap_struct_name = "libx11_display",
15
+ .function = {
16
+ .dmark = NULL,
17
+ .dfree = NULL,
18
+ .dsize = display_dsize,
19
+ .reserved = { NULL, NULL },
20
+ },
21
+ .parent = NULL,
22
+ .data = NULL,
23
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
24
+ };
25
+
26
+ /*
27
+ * Xlib XOpenDisplay
28
+ */
29
+ static VALUE
30
+ rb_libx11_xopen_display(VALUE self, VALUE display_name)
31
+ {
32
+ Display *display;
33
+ Check_Type(display_name, T_STRING);
34
+
35
+ display = XOpenDisplay(RSTRING_PTR(display_name));
36
+ return TypedData_Wrap_Struct(rb_cDisplay, &display_type, display);
37
+ }
38
+
39
+ /*
40
+ * Xlib XCloseDisplay
41
+ */
42
+ static VALUE
43
+ rb_libx11_xclose_display(VALUE self, VALUE obj)
44
+ {
45
+ int ret;
46
+ Display *display;
47
+
48
+ TypedData_Get_Struct(obj, Display, &display_type, display);
49
+ ret = XCloseDisplay(display);
50
+ return INT2FIX(ret);
51
+ }
52
+
53
+ /*
54
+ * Xlib DefaultScreen
55
+ */
56
+ static VALUE
57
+ rb_display_default_screen(VALUE self)
58
+ {
59
+ Display *display;
60
+
61
+ TypedData_Get_Struct(self, Display, &display_type, display);
62
+ return INT2NUM(DefaultScreen(display));
63
+ }
64
+
65
+ /*
66
+ * Xlib DefaultRootWindow
67
+ */
68
+ static VALUE
69
+ rb_display_default_root_window(VALUE self)
70
+ {
71
+ Display *display;
72
+ Window window;
73
+
74
+ TypedData_Get_Struct(self, Display, &display_type, display);
75
+ window = DefaultRootWindow(display);
76
+ return ULONG2NUM(window);
77
+ }
78
+
79
+ /*
80
+ * Xlib BlackPixel
81
+ */
82
+ static VALUE
83
+ rb_display_black_pixel(VALUE self, VALUE screen_obj)
84
+ {
85
+ Display *display;
86
+ int screen = FIX2INT(screen_obj);
87
+
88
+ TypedData_Get_Struct(self, Display, &display_type, display);
89
+ return ULONG2NUM(BlackPixel(display, screen));
90
+ }
91
+
92
+ /*
93
+ * Xlib WhitePixel
94
+ */
95
+ static VALUE
96
+ rb_display_white_pixel(VALUE self, VALUE screen_obj)
97
+ {
98
+ Display *display;
99
+ int screen = FIX2INT(screen_obj);
100
+
101
+ TypedData_Get_Struct(self, Display, &display_type, display);
102
+ return ULONG2NUM(WhitePixel(display, screen));
103
+ }
104
+
105
+ /*
106
+ * Xlib XSelectInput
107
+ */
108
+ static VALUE
109
+ rb_display_xselect_input(VALUE self, VALUE window, VALUE event_mask)
110
+ {
111
+ Display *display;
112
+ int ret;
113
+
114
+ TypedData_Get_Struct(self, Display, &display_type, display);
115
+ ret = XSelectInput(display, NUM2ULONG(window), NUM2LONG(event_mask));
116
+ return INT2NUM(ret);
117
+ }
118
+
119
+ /*
120
+ * Xlib XMapWindow
121
+ */
122
+ static VALUE
123
+ rb_display_xmap_window(VALUE self, VALUE window)
124
+ {
125
+ Display *display;
126
+ int ret;
127
+
128
+ TypedData_Get_Struct(self, Display, &display_type, display);
129
+ ret = XMapWindow(display, NUM2ULONG(window));
130
+ return INT2NUM(ret);
131
+ }
132
+
133
+ void
134
+ Init_libx11_display(void)
135
+ {
136
+ rb_define_singleton_method(rb_mLibX11, "xopen_display", rb_libx11_xopen_display, 1);
137
+ rb_define_singleton_method(rb_mLibX11, "xclose_display", rb_libx11_xclose_display, 1);
138
+
139
+ rb_cDisplay = rb_define_class_under(rb_mLibX11, "Display", rb_cData);
140
+ rb_define_method(rb_cDisplay, "default_root_window", rb_display_default_root_window, 0);
141
+ rb_define_method(rb_cDisplay, "default_screen", rb_display_default_screen, 0);
142
+ rb_define_method(rb_cDisplay, "black_pixel", rb_display_black_pixel, 1);
143
+ rb_define_method(rb_cDisplay, "white_pixel", rb_display_white_pixel, 1);
144
+ rb_define_method(rb_cDisplay, "xmap_window", rb_display_xmap_window, 1);
145
+ rb_define_method(rb_cDisplay, "xselect_input", rb_display_xselect_input, 2);
146
+ }
@@ -0,0 +1,70 @@
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
+ }
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ $CFLAGS << ' -Wall -Wextra'
4
+ abort 'Cannot find libx11' unless have_library('X11')
5
+
6
+ create_makefile('libx11/libx11_ruby')
@@ -0,0 +1,11 @@
1
+ #include "libx11_ruby.h"
2
+
3
+ void
4
+ Init_libx11_ruby(void)
5
+ {
6
+ rb_mLibX11 = rb_define_module("LibX11");
7
+
8
+ Init_libx11_display();
9
+ Init_libx11_event();
10
+ Init_libx11_window();
11
+ }
@@ -0,0 +1,13 @@
1
+ #ifndef LIBX11_RUBY_H
2
+ #define LIBX11_RUBY_H 1
3
+
4
+ #include "ruby.h"
5
+ #include <X11/Xlib.h>
6
+
7
+ VALUE rb_mLibX11;
8
+
9
+ void Init_libx11_display(void);
10
+ void Init_libx11_event(void);
11
+ void Init_libx11_window(void);
12
+
13
+ #endif /* LIBX11_RUBY_H */
@@ -0,0 +1,41 @@
1
+ #include "libx11_ruby.h"
2
+ #include <X11/Xlib.h>
3
+
4
+ extern rb_data_type_t display_type;
5
+
6
+ /*
7
+ * Xlib XCreateSimpleWindow
8
+ */
9
+ static VALUE
10
+ rb_libx11_xcreate_simple_window(VALUE self, VALUE display_obj, VALUE parent_window, VALUE x, VALUE y,
11
+ VALUE width, VALUE height, VALUE border_width, VALUE border_color, VALUE background_color)
12
+ {
13
+ Display *display;
14
+ Window ret;
15
+
16
+ TypedData_Get_Struct(display_obj, Display, &display_type, display);
17
+ ret = XCreateSimpleWindow(display, NUM2ULONG(parent_window), NUM2INT(x), NUM2INT(y),
18
+ NUM2UINT(width), NUM2UINT(height), FIX2UINT(border_width), NUM2ULONG(border_color), NUM2ULONG(background_color));
19
+ return ULONG2NUM(ret);
20
+ }
21
+
22
+ /*
23
+ * Xlib XDestroyWindow
24
+ */
25
+ static VALUE
26
+ rb_libx11_xdestroy_window(VALUE self, VALUE display_obj, VALUE window)
27
+ {
28
+ Display *display;
29
+ int ret;
30
+
31
+ TypedData_Get_Struct(display_obj, Display, &display_type, display);
32
+ ret = XDestroyWindow(display, NUM2ULONG(window));
33
+ return INT2NUM(ret);
34
+ }
35
+
36
+ void
37
+ Init_libx11_window(void)
38
+ {
39
+ rb_define_singleton_method(rb_mLibX11, "xcreate_simple_window", rb_libx11_xcreate_simple_window, 9);
40
+ rb_define_singleton_method(rb_mLibX11, "xdestroy_window", rb_libx11_xdestroy_window, 2);
41
+ }
@@ -0,0 +1,2 @@
1
+ require 'libx11/version'
2
+ require 'libx11/libx11_ruby'
@@ -0,0 +1,3 @@
1
+ module LibX11
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'libx11/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'libx11'
8
+ spec.version = LibX11::VERSION
9
+ spec.authors = ['Takashi Kokubun']
10
+ spec.email = ['takashikkbn@gmail.com']
11
+
12
+ spec.summary = 'Ruby binding for libx11 including xlib'
13
+ spec.description = 'Ruby binding for libx11 including xlib'
14
+ spec.homepage = 'https://github.com/k0kubun/libx11-ruby'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+ spec.extensions = ['ext/libx11_ruby/extconf.rb']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.11'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rake-compiler'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libx11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Takashi Kokubun
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Ruby binding for libx11 including xlib
70
+ email:
71
+ - takashikkbn@gmail.com
72
+ executables: []
73
+ extensions:
74
+ - ext/libx11_ruby/extconf.rb
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - example/create_window.rb
87
+ - ext/libx11_ruby/display.c
88
+ - ext/libx11_ruby/event.c
89
+ - ext/libx11_ruby/extconf.rb
90
+ - ext/libx11_ruby/libx11_ruby.c
91
+ - ext/libx11_ruby/libx11_ruby.h
92
+ - ext/libx11_ruby/window.c
93
+ - lib/libx11.rb
94
+ - lib/libx11/version.rb
95
+ - libx11.gemspec
96
+ homepage: https://github.com/k0kubun/libx11-ruby
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.5.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Ruby binding for libx11 including xlib
120
+ test_files: []
121
+ has_rdoc: