rwm 0.0.1.alpha.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.
@@ -0,0 +1,64 @@
1
+ #--
2
+ # Copyleft shura. [ shura1991@gmail.com ]
3
+ #
4
+ # This file is part of rwm.
5
+ #
6
+ # rwm is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # rwm is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with rwm. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ module X11
21
+ Mask = Class.new(Hash) {
22
+ alias __get__ []
23
+
24
+ def [](what)
25
+ self.__get__(what) ||
26
+ self.__get__(what.is_a?(String) ? what.to_sym : what.to_s)
27
+ end
28
+ }.new.merge({
29
+ NoEvent: 0,
30
+ KeyPress: 1,
31
+ KeyRelease: (1<<1),
32
+ ButtonPress: (1<<2),
33
+ ButtonRelease: (1<<3),
34
+ EnterWindow: (1<<4),
35
+ LeaveWindow: (1<<5),
36
+ PointerMotion: (1<<6),
37
+ PointerMotionHint: (1<<7),
38
+ Button1Motion: (1<<8),
39
+ Button2Motion: (1<<9),
40
+ Button3Motion: (1<<10),
41
+ Button4Motion: (1<<11),
42
+ Button5Motion: (1<<12),
43
+ ButtonMotion: (1<<13),
44
+ KeymapState: (1<<14),
45
+ Exposure: (1<<15),
46
+ VisibilityChange: (1<<16),
47
+ StructureNotify: (1<<17),
48
+ ResizeRedirect: (1<<18),
49
+ SubstructureNotify: (1<<19),
50
+ SubstructureRedirect: (1<<20),
51
+ FocusChange: (1<<21),
52
+ PropertyChange: (1<<22),
53
+ ColormapChange: (1<<23),
54
+ OwnerGrabButton: (1<<24),
55
+ Shift: 1,
56
+ Lock: (1<<1),
57
+ Control: (1<<2),
58
+ Mod1: (1<<3),
59
+ Mod2: (1<<4),
60
+ Mod3: (1<<5),
61
+ Mod4: (1<<6),
62
+ Mod5: (1<<7)
63
+ }).freeze
64
+ end
@@ -0,0 +1,227 @@
1
+ #--
2
+ # Copyleft shura. [ shura1991@gmail.com ]
3
+ #
4
+ # This file is part of rwm.
5
+ #
6
+ # rwm is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # rwm is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with rwm. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ module X11
21
+ class Display
22
+ def initialize (name=nil)
23
+ pointer = (name.is_a?(String) or !name) ? X11::C.XOpenDisplay(name) : name
24
+ @dpy = pointer.is_a?(X11::C::Display) ? pointer : pointer.typecast(X11::C::Display)
25
+ end
26
+
27
+ def ungrab_pointer (time=0)
28
+ C.XUngrabPointer(to_c, time)
29
+ end
30
+
31
+ def keysym_to_keycode (keysym)
32
+ C.XKeysymToKeycode(to_c, keysym)
33
+ end
34
+
35
+ def check_typed_event (event)
36
+ event = Event.index(event)
37
+ ev = FFI::MemoryPointer.new(C::XEvent)
38
+ C.XCheckTypedEvent(to_c, event, ev) or return
39
+ Event.new(ev)
40
+ end
41
+
42
+ def screen (which)
43
+ Screen.new(self, @dpy[:screens] + (which * C::Screen.size))
44
+ end
45
+
46
+ def default_screen
47
+ self.screen(@dpy[:default_screen])
48
+ end
49
+
50
+ def screens
51
+ (0...@dpy[:nscreens]).map {|i|
52
+ self.screen(i)
53
+ }
54
+ end
55
+
56
+ def next_event
57
+ ev = FFI::MemoryPointer.new(C::XEvent)
58
+ C.XNextEvent(to_c, ev)
59
+ Event.new(ev)
60
+ end
61
+
62
+ def each_event
63
+ loop {
64
+ next_event.tap {|ev|
65
+ yield ev if block_given?
66
+ }
67
+ }
68
+ end
69
+
70
+ def to_c
71
+ @dpy.pointer
72
+ end
73
+ end
74
+
75
+ class Screen
76
+ def initialize (dpy, screen)
77
+ @dpy = dpy
78
+ @scr = screen.typecast(X11::C::Screen)
79
+ end
80
+
81
+ def root_window
82
+ Window.new(@dpy, @scr[:root])
83
+ end
84
+
85
+ def to_c
86
+ @scr.pointer
87
+ end
88
+ end
89
+
90
+ class Window
91
+ class Attributes
92
+ def initialize (attr)
93
+ attr = attr.typecast(C::XWindowAttributes) unless attr.is_a?(C::XWindowAttributes)
94
+ @attr = attr
95
+ end
96
+
97
+ %w{x y width height border_width depth bit_gravity win_gravity backing_store
98
+ backing_planes backing_pixel colormap map_state all_event_masks your_event_masks
99
+ do_not_propagate_mask}.each {|meth|
100
+ class_eval {
101
+ define_method(meth) {
102
+ @attr[meth.to_sym]
103
+ }
104
+ }
105
+ }
106
+
107
+ def override_redirect?
108
+ @attr[:override_redirect]
109
+ end
110
+
111
+ def save_under?
112
+ @attr[:save_under]
113
+ end
114
+
115
+ def map_installed?
116
+ @attr[:map_installed]
117
+ end
118
+
119
+ def c_class
120
+ @attr[:class]
121
+ end
122
+
123
+ def root
124
+ Window.new(@attr[:root])
125
+ end
126
+
127
+ def visual
128
+ Visual.new(@attr[:visual])
129
+ end
130
+
131
+ def screen
132
+ Screen.new(@attr.screen)
133
+ end
134
+ end
135
+
136
+ GRAB_MODE = {sync: false, async: true}
137
+
138
+ def initialize (dpy, window)
139
+ @dpy = dpy
140
+ @win = window
141
+ end
142
+
143
+ def nil?
144
+ @win.zero?
145
+ end
146
+
147
+ def attributes
148
+ attr = FFI::MemoryPointer.new(C::XWindowAttributes)
149
+ C.XGetWindowAttributes(@dpy.to_c, @win, attr)
150
+ Attributes.new(attr)
151
+ end
152
+ alias attr attributes
153
+
154
+ def grab_pointer (owner_events=true, event_mask=0, pointer_mode=:async,
155
+ keyboard_mode=:async, confine_to=0, cursor=0, time=0)
156
+ C.XGrabPointer(@dpy.to_c, @win, !!owner_events, event_mask, mode2int(pointer_mode),
157
+ mode2int(keyboard_mode), confine_to.to_c, cursor, time)
158
+ end
159
+
160
+ def ungrab_pointer (time=0)
161
+ @dpy.ungrab_pointer(time)
162
+ end
163
+
164
+ def keysym_to_keycode (keysym)
165
+ C.XKeysymToKeycode(to_c, keysym)
166
+ end
167
+
168
+ def move_resize (x, y, width, height)
169
+ C.XMoveResizeWindow(@dpy.to_c, @win, x, y, width, height)
170
+ end
171
+
172
+ def raise
173
+ C.XRaiseWindow(@dpy.to_c, @win)
174
+ end
175
+
176
+ def grab_key (keycode, modifiers=0, owner_events=true, pointer_mode=:async, keyboard_mode=:async)
177
+ C.XGrabKey(@dpy.to_c, keycode.to_keycode, modifiers, @win, !!owner_events,
178
+ mode2int(pointer_mode), mode2int(keyboard_mode))
179
+ end
180
+
181
+ def ungrab_key (keycode, modifiers=0)
182
+ C.XUngrabKey(@dpy.to_c, keycode.to_keycode, modifiers, @win)
183
+ end
184
+
185
+ def grab_button (button, modifiers=0, owner_events=true, event_mask=4,
186
+ pointer_mode=:async, keyboard_mode=:async, confine_to=0, cursor=0)
187
+ C.XGrabButton(@dpy.to_c, button, modifiers, @win, !!owner_events, event_mask,
188
+ mode2int(pointer_mode), mode2int(keyboard_mode), confine_to.to_c, cursor.to_c)
189
+ end
190
+
191
+ def ungrab_button (button, modifiers=0)
192
+ C.XUngrabButton(@dpy.to_c, button, modifiers, @win)
193
+ end
194
+
195
+ def to_c
196
+ @win
197
+ end
198
+
199
+ private
200
+ def mode2int (mode)
201
+ (mode == true or GRAB_MODE[mode]) ? 1 : 0
202
+ end
203
+ end
204
+
205
+ class Visual
206
+ def initialize (visual)
207
+ visual = visual.typecast(C::Visual) unless visual.is_a?(C::Visual)
208
+ @vis = visual
209
+ end
210
+
211
+ %w{red_mask green_mask blue_mask bits_per_rgb map_entries}.each {|meth|
212
+ class_eval {
213
+ define_method(meth) {
214
+ @vis[meth]
215
+ }
216
+ }
217
+ }
218
+
219
+ def visual_id
220
+ @vis[:VisualID]
221
+ end
222
+
223
+ def c_class
224
+ @vis[:class]
225
+ end
226
+ end
227
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rwm
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ - alpha
10
+ - 1
11
+ version: 0.0.1.alpha.1
12
+ platform: ruby
13
+ authors:
14
+ - shura
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-07-01 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: ffi
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Simple ruby written windows manager
36
+ email: shura1991@gmail.com
37
+ executables:
38
+ - rwm
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/rwm.rb
45
+ - lib/rwm/extensions.rb
46
+ - lib/rwm/x11/c.rb
47
+ - lib/rwm/x11/events.rb
48
+ - lib/rwm/x11/types.rb
49
+ - lib/rwm/x11/c/types.rb
50
+ - lib/rwm/x11/c/functions.rb
51
+ - lib/rwm/x11/masks.rb
52
+ - lib/rwm/x11.rb
53
+ - bin/rwm
54
+ has_rdoc: true
55
+ homepage: http://github.com/shurizzle/rwm
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">"
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 1
78
+ - 3
79
+ - 1
80
+ version: 1.3.1
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.7
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Simple ruby written windows manager
88
+ test_files: []
89
+