pure-x11 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c3d89e6c8da43a6f489333c1d50f85485f1357bc0549747f11dbc2cf325e3af1
4
+ data.tar.gz: 9b7ddd2b688c8c5d924a027a1d05b65744b52ad7f84a7e646c26ec610fb93d8e
5
+ SHA512:
6
+ metadata.gz: ab203eb42daeda7e2091becae8de88582291ae8a7636035ed017f86e6195f928d2e7ff5945c356363ddba5ed63f7623158ac0004156cf76d5ff7e75092c32583
7
+ data.tar.gz: 361fb690e60345acf764192386fc511a3ade0c724bb48f7f585fc573dcfe6c50386e7098e875d697a2be9406578c1c75ab7c57ddacda78dd8cc303067ee72bbc
data/.gitignore ADDED
@@ -0,0 +1,48 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+
41
+ # For vim:
42
+ #*.swp
43
+
44
+ # For redcar:
45
+ #.redcar
46
+
47
+ # For rubinius:
48
+ #*.rbc
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+
7
+ group :development do
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pure-x11 (0.0.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (13.0.6)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ pure-x11!
16
+ rake
17
+
18
+ BUNDLED WITH
19
+ 2.4.19
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Richard Ramsden
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ Ruby X11
2
+ ========
3
+
4
+ (under-development) Pure Ruby implementation of the X Window System Protocol.
5
+ This library is based off of Mathieu Bouchard's work on his RubyX11 project.
6
+
7
+ Contributors
8
+ ------------
9
+
10
+ There is still quite a bit of work to do on this repository. If you're thinking
11
+ about contributing you may want to look over the PDF in the docs folder which documents
12
+ the X Window System Protocol.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.test_files = FileList['test/*_test.rb']
6
+ t.verbose = true
7
+ end
data/docs/protocol.pdf ADDED
Binary file
data/example/genie.png ADDED
Binary file
data/example/test.rb ADDED
@@ -0,0 +1,108 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'chunky_png'
4
+ Bundler.setup(:default, :development)
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+
9
+ require 'X11'
10
+
11
+ display = X11::Display.new
12
+ screen = display.screens.first
13
+ root = screen.root
14
+ wid = display.new_id
15
+ display.write_request(X11::Form::CreateWindow.new(
16
+ screen.root_depth,
17
+ wid,
18
+ root,
19
+ 0, #x
20
+ 0, #y
21
+ 1000,#w
22
+ 600,#h
23
+ 0,
24
+ X11::Form::InputOutput,
25
+ X11::Form::CopyFromParent,
26
+ X11::Form::CWBackPixel |
27
+ X11::Form::CWEventMask,
28
+ [0xff8844, # RGB background
29
+ X11::Form::SubstructureNotifyMask |
30
+ # X11::Form::StructureNotifyMask | ## Move
31
+ X11::Form::ExposureMask |
32
+ X11::Form::KeyPressMask |
33
+ X11::Form::ButtonPressMask
34
+ ]
35
+ ))
36
+ puts "Mapping"
37
+ display.write_request(X11::Form::MapWindow.new(wid))
38
+ # Creating GC
39
+ gc = display.new_id
40
+ display.write_request(X11::Form::CreateGC.new(
41
+ gc, screen.root,
42
+ X11::Form::ForegroundMask,
43
+ [0xff0000, # RGB foreground
44
+ ]
45
+ ))
46
+
47
+ $gc2 = display.new_id
48
+ display.write_request(X11::Form::CreateGC.new(
49
+ $gc2,
50
+ screen.root,
51
+ X11::Form::ForegroundMask|X11::Form::BackgroundMask,
52
+ [0xffffff, # RGB foreground
53
+ 0x444444,
54
+ ]
55
+ ))
56
+
57
+ $gc3 = display.new_id
58
+ display.write_request(X11::Form::CreateGC.new(
59
+ $gc3,
60
+ screen.root,
61
+ 0, []
62
+ ))
63
+
64
+
65
+ puts "Main loop"
66
+ p gc
67
+
68
+ # This will wait for a reply
69
+ p display.write_sync(X11::Form::ListFonts.new(10, "*7x13*"),
70
+ X11::Form::ListFontsReply).names.map(&:to_s)
71
+
72
+ fid = display.new_id
73
+ display.write_request(X11::Form::OpenFont.new(fid, "7x13"))
74
+ display.write_request(X11::Form::ChangeGC.new($gc2, X11::Form::FontMask, [fid]))
75
+
76
+ $png = ChunkyPNG::Image.from_file('genie.png')
77
+ p $png.width
78
+ p $png.height
79
+
80
+ def redraw(display, wid, gc)
81
+ p [:redraw, gc]
82
+ display.write_request(X11::Form::PolyFillRectangle.new(
83
+ wid, gc,
84
+ [X11::Form::Rectangle.new(20,20, 60, 80)]
85
+ ))
86
+
87
+ display.write_request(X11::Form::ClearArea.new( false, wid, 30, 30, 5, 5))
88
+ display.write_request(X11::Form::ImageText8.new(wid, $gc2, 30, 70, "Hello World"))
89
+
90
+ depth = 24
91
+ # FIXME: The colors are wrong
92
+ # pixels.pack("N*")
93
+ data = ""
94
+ $png.pixels.each do |px|
95
+ str = [px].pack("N")
96
+ data << str[2] << str[1] << str[0] << str[3]
97
+ end
98
+ display.write_request(X11::Form::PutImage.new(
99
+ X11::Form::ZPixmap, wid, $gc2, $png.width, $png.height, 80, 80, 0, depth, data))
100
+ end
101
+
102
+ loop do
103
+ pkt = display.next_packet
104
+ if pkt
105
+ p pkt
106
+ redraw(display, wid, gc) if pkt.is_a?(X11::Form::Expose)
107
+ end
108
+ end
data/lib/X11/auth.rb ADDED
@@ -0,0 +1,69 @@
1
+ # This module is an approximate ruby replacement for the libXau C library and the
2
+ # xauth(1) program. It reads and interprets the files (usually '~/.Xauthority') that
3
+ # hold authorization data used in connecting to X servers. Since it was written mainly
4
+ # for the use of X11::Protocol, its functionality is currently restricted to reading,
5
+ # not writing, of these files.
6
+
7
+ module X11
8
+ class Auth
9
+ FAILED = 0
10
+ SUCCESS = 1
11
+ AUTHENTICATE = 2
12
+
13
+ ADDRESS_TYPES = {
14
+ 256 => :Local,
15
+ 65535 => :Wild,
16
+ 254 => :Netname,
17
+ 253 => :Krb5Principal,
18
+ 252 => :LocalHost,
19
+ 0 => :Internet,
20
+ 1 => :DECnet,
21
+ 2 => :Chaos
22
+ }
23
+
24
+ AuthInfo = Struct.new :family, :address, :display, :auth_name, :auth_data
25
+
26
+ # Open an authority file, and create an object to handle it.
27
+ # The filename will be taken from the XAUTHORITY environment variable,
28
+ # if present, or '.Xauthority' in the user's home directory, or it may be overridden
29
+ # by an argument.
30
+ def initialize(path = ENV['XAUTHORITY'] || ENV['HOME'] + "/.Xauthority")
31
+ @file = File.open(path)
32
+ end
33
+
34
+ # Get authentication data for a connection of type family to display display_id on host.
35
+ # If family is 'Internet', the host will be translated into an appropriate address by gethostbyname().
36
+ # If no data is found, returns nil
37
+ def get_by_hostname(host, family, display_id)
38
+ host = `hostname`.chomp if host == 'localhost' or host == '127.0.0.1' or host.nil?
39
+ address = TCPSocket.gethostbyname(host) if family == :Internet # this line does nothing for now
40
+
41
+ auth_data = nil
42
+
43
+ # with each entry from XAuthority file
44
+ until @file.eof?
45
+ r = read()
46
+ auth_data = r if r.display.empty? || display_id.to_i == r.display.to_i
47
+ end
48
+
49
+ reset
50
+ return auth_data
51
+ end
52
+
53
+ # returns one entry from Xauthority file
54
+ def read
55
+ auth_info = [] << ADDRESS_TYPES[ @file.read(2).unpack('n').first ]
56
+
57
+ 4.times do
58
+ length = @file.read(2).unpack('n').first
59
+ auth_info << @file.read(length)
60
+ end
61
+ AuthInfo[*auth_info]
62
+ end
63
+
64
+ def reset
65
+ @file.seek(0, IO::SEEK_SET)
66
+ end
67
+
68
+ end
69
+ end