xlib_ruby 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/ruby-x11.rb ADDED
@@ -0,0 +1,119 @@
1
+ require File.join(File.dirname(__FILE__),'..','ext','x11');
2
+
3
+ module X11
4
+ KEY_MASK_NAMES = [
5
+ :Shift,
6
+ :Lock,
7
+ :Control,
8
+ :Mod1,
9
+ :Mod2,
10
+ :Mod3,
11
+ :Mod4,
12
+ :Mod5,
13
+ :Button1,
14
+ :Button2,
15
+ :Button3,
16
+ :Button4,
17
+ :Button5
18
+ ]
19
+
20
+ ShiftMask = 1 << 0
21
+ LockMask = 1 << 1
22
+ ControlMask = 1 << 2
23
+ Mod1Mask = 1 << 3
24
+ Mod2Mask = 1 << 4
25
+ Mod3Mask = 1 << 5
26
+ Mod4Mask = 1 << 6
27
+ Mod5Mask = 1 << 7
28
+ Button1Mask = 1 << 8
29
+ Button2Mask = 1 << 9
30
+ Button3Mask = 1 << 10
31
+ Button4Mask = 1 << 11
32
+ Button5Mask = 1 << 12
33
+
34
+ EVENT_NAMES = {
35
+ 2 => :KeyPress,
36
+ 3 => :KeyRelease,
37
+ 4 => :ButtonPress,
38
+ 5 => :ButtonRelease,
39
+ 6 => :MotionNotify,
40
+ 7 => :EnterNotify,
41
+ 8 => :LeaveNotify,
42
+ 9 => :FocusIn,
43
+ 10 => :FocusOut,
44
+ 11 => :KeymapNotify,
45
+ 12 => :Expose,
46
+ 13 => :GraphicsExpose,
47
+ 14 => :NoExpose,
48
+ 15 => :VisibilityNotify,
49
+ 16 => :CreateNotify,
50
+ 17 => :DestroyNotify,
51
+ 18 => :UnmapNotify,
52
+ 19 => :MapNotify,
53
+ 20 => :MapRequest,
54
+ 21 => :ReparentNotify,
55
+ 22 => :ConfigureNotify,
56
+ 23 => :ConfigureRequest,
57
+ 24 => :GravityNotify,
58
+ 25 => :ResizeRequest,
59
+ 26 => :CirculateNotify,
60
+ 27 => :CirculateRequest,
61
+ 28 => :PropertyNotify,
62
+ 29 => :SelectionClear,
63
+ 30 => :SelectionRequest,
64
+ 31 => :SelectionNotify,
65
+ 32 => :ColormapNotify,
66
+ 33 => :ClientMessage,
67
+ 34 => :MappingNotify,
68
+ 35 => :GenericEvent
69
+ }
70
+
71
+ KeyPress = 2
72
+ KeyRelease = 3
73
+ ButtonPress = 4
74
+ ButtonRelease = 5
75
+ MotionNotify = 6
76
+ EnterNotify = 7
77
+ LeaveNotify = 8
78
+ FocusIn = 9
79
+ FocusOut = 10
80
+ KeymapNotify = 11
81
+ Expose = 12
82
+ GraphicsExpose = 13
83
+ NoExpose = 14
84
+ VisibilityNotify = 15
85
+ CreateNotify = 16
86
+ DestroyNotify = 17
87
+ UnmapNotify = 18
88
+ MapNotify = 19
89
+ MapRequest = 20
90
+ ReparentNotify = 21
91
+ ConfigureNotify = 22
92
+ ConfigureRequest = 23
93
+ GravityNotify = 24
94
+ ResizeRequest = 25
95
+ CirculateNotify = 26
96
+ CirculateRequest = 27
97
+ PropertyNotify = 28
98
+ SelectionClear = 29
99
+ SelectionRequest = 30
100
+ SelectionNotify = 31
101
+ ColormapNotify = 32
102
+ ClientMessage = 33
103
+ MappingNotify = 34
104
+ GenericEvent = 35
105
+
106
+ class WindowManager
107
+ def debug_event_loop
108
+ loop do
109
+ ev = get_event
110
+ if ev.type == MapRequest && ev.client
111
+ manage ev.client,10,10,100,100
112
+ end
113
+ break if ev.keysym == "Escape"
114
+ puts "#{EVENT_NAMES[ev.type]} #{ev.wid.to_s(16)}:#{ev.client} " \
115
+ "keysym=#{ev.keysym} mods=#{ev.mods} button=#{ev.button} coord=(#{ev.x},#{ev.y})"
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby1.8
2
+
3
+ require 'x11'
4
+ include X11
5
+
6
+ # Monkeypatch event handlers for dynamic fill-in
7
+ class WindowManager
8
+
9
+ def initialize
10
+ events = Thread.new do
11
+ loop do
12
+ if self.event_pending?
13
+ self.query
14
+ eval("@"+self.next_event.downcase).call
15
+ self.event_pop
16
+ puts "Again..."
17
+ end
18
+ sleep 0.1
19
+ end
20
+ end
21
+ end
22
+
23
+ @maprequest = Proc.new { |client| puts "MapRequest" }
24
+ @destroynotify = Proc.new { |client| puts "DestroyNotify" }
25
+ @motionnotify = Proc.new { |client| puts "MotionNotify" }
26
+ @buttonpress = Proc.new { |client| puts "buttonpress" }
27
+ @configurerequest = Proc.new { |client| puts "configurerequest" }
28
+ @configurenotify = Proc.new { |client| puts "configurenotify" }
29
+ @destroynotify = Proc.new { |client| puts "destroynotify" }
30
+ @enternotify = Proc.new { |client| puts "enternotify" }
31
+ @expose = Proc.new { |client| puts "expose" }
32
+ @focusin = Proc.new { |client| puts "focusin" }
33
+ @keypress = Proc.new { |client| puts "keypress" }
34
+ @leavenotify = Proc.new { |client| puts "leavenotify" }
35
+ @mappingnotify = Proc.new { |client| puts "mappingnotify" }
36
+ @maprequest = Proc.new { |client| puts "maprequest" }
37
+ @propertynotify = Proc.new { |client| puts "propertynotify" }
38
+ @unmapnotify = Proc.new { |client| puts "unmapnotify" }
39
+
40
+ def on_maprequest_do(&block)
41
+ @maprequest = block
42
+ end
43
+
44
+ def on_destroynotify_do(&block)
45
+ @destroynotify = block
46
+ end
47
+
48
+ def on_motionnotify_do(&block)
49
+ @motionnotify = block
50
+ end
51
+ end
52
+
53
+ # Create the WM global var
54
+ $windowmanager = WindowManager.new
55
+ $windowmanager.events.start
56
+
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xlib_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tim Felgentreff
9
+ - Konstantin Haase
10
+ - Johannes Wollert
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-01-17 00:00:00.000000000 Z
15
+ dependencies: []
16
+ description: Some base libraries for writing a windowmanager in ruby
17
+ email: timfelgentreff@gmail.com
18
+ executables: []
19
+ extensions:
20
+ - ext/extconf.rb
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ext/.gitignore
24
+ - ext/Makefile.test
25
+ - ext/extconf.rb
26
+ - ext/x11.c
27
+ - ext/x11.h
28
+ - ext/x11_wrap.c
29
+ - lib/ruby-x11.rb
30
+ - lib/windowmanager.rb
31
+ homepage: https://github.com/rkh/xlib_ruby
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ - ext
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project: xlib
52
+ rubygems_version: 1.8.11
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Some base libraries for writing a windowmanager in ruby
56
+ test_files: []