xlib-objects 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/display.rb +12 -2
- data/lib/error.rb +1 -1
- data/lib/event/client_message.rb +2 -2
- data/lib/screen.rb +16 -0
- data/lib/window.rb +51 -6
- data/lib/window/event_handler.rb +9 -1
- data/lib/window/property.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22f4f88902d97b0d31c2610f90bfa14b2378571a
|
4
|
+
data.tar.gz: 0139801c5a443d34350d5ac3aeed21d87d58d3e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a409bdbcfbd75f89e9fb0fe4ac8a3b2c72790d9dbb857a0a7f38dec73efe4b00309291b8005bfb31e30efa58e865ade4c4dd035b0262312631f8365906a8471e
|
7
|
+
data.tar.gz: fcdabd70932efe480f6a8a18e98da2544de3bac50b52311ee8a706c35142df89082519d376da418c0e12af9d75e0733bbdea724c80be4caba26fb42a0fa522ed
|
data/lib/display.rb
CHANGED
@@ -41,10 +41,20 @@ module XlibObj
|
|
41
41
|
(0..@struct[:nscreens]-1).map{ |number| screen(number) }
|
42
42
|
end
|
43
43
|
|
44
|
+
def focused_window
|
45
|
+
screens.reduce(nil){ |focused_window, s| focused_window or s.focused_window }
|
46
|
+
end
|
47
|
+
|
44
48
|
def handle_events
|
45
49
|
handle_event(next_event) while pending_events > 0
|
46
50
|
end
|
47
51
|
|
52
|
+
def clipboard(type = :CLIPBOARD, &on_receive)
|
53
|
+
@internal_window ||= screen.root_window.create_window
|
54
|
+
@internal_window.request_selection(type: type, &on_receive)
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
48
58
|
def on_error(&callback)
|
49
59
|
@error_handler = if callback
|
50
60
|
FFI::Function.new(:pointer, [:pointer, :pointer]) do |display_ptr, error_ptr|
|
@@ -85,7 +95,7 @@ module XlibObj
|
|
85
95
|
end
|
86
96
|
|
87
97
|
def handle_event(event)
|
88
|
-
handling_window_id = event.event || event.parent || event.window
|
98
|
+
handling_window_id = event.event || event.parent || event.window || event.requestor
|
89
99
|
handling_window = Window.new(self, handling_window_id)
|
90
100
|
handling_window.handle(event)
|
91
101
|
end
|
@@ -94,7 +104,7 @@ module XlibObj
|
|
94
104
|
@struct[:screens] + number*Xlib::Screen.size
|
95
105
|
end
|
96
106
|
|
97
|
-
def screen(number)
|
107
|
+
def screen(number = 0)
|
98
108
|
Screen.new(self, screen_pointer(number))
|
99
109
|
end
|
100
110
|
end
|
data/lib/error.rb
CHANGED
@@ -72,7 +72,7 @@ module XlibObj
|
|
72
72
|
if [Xlib::BadWindow, Xlib::BadPixmap, Xlib::BadCursor, Xlib::BadFont, Xlib::BadDrawable,
|
73
73
|
Xlib::BadColor, Xlib::BadGC, Xlib::BadIDChoice].include?(code)
|
74
74
|
Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, "ResourceID",
|
75
|
-
"ResourceID
|
75
|
+
"ResourceID %x", message, message_size)
|
76
76
|
elsif code == Xlib::BadValue
|
77
77
|
Xlib.XGetErrorDatabaseText(@display.to_native, @display.name, "Value", "Value 0x%x",
|
78
78
|
message, message_size)
|
data/lib/event/client_message.rb
CHANGED
@@ -21,12 +21,12 @@ module XlibObj
|
|
21
21
|
raise "The client message needs a type at least." unless @type
|
22
22
|
@receiver = receiver
|
23
23
|
Xlib.XSendEvent(@receiver.display.to_native, @receiver.to_native, false,
|
24
|
-
Xlib::SubstructureNotifyMask | Xlib::SubstructureRedirectMask,
|
25
|
-
to_native)
|
24
|
+
Xlib::SubstructureNotifyMask | Xlib::SubstructureRedirectMask, to_native)
|
26
25
|
Xlib.XFlush(@receiver.display.to_native)
|
27
26
|
end
|
28
27
|
|
29
28
|
private
|
29
|
+
|
30
30
|
def to_native
|
31
31
|
event = Xlib::XEvent.new
|
32
32
|
event[:xclient][:type] = Xlib::ClientMessage
|
data/lib/screen.rb
CHANGED
@@ -40,6 +40,21 @@ module XlibObj
|
|
40
40
|
@root_window ||= Window.new(@display, Xlib.XRootWindowOfScreen(to_native))
|
41
41
|
end
|
42
42
|
|
43
|
+
def focused_window
|
44
|
+
window_ptr = FFI::MemoryPointer.new :Window
|
45
|
+
trash_ptr = FFI::MemoryPointer.new :int
|
46
|
+
Xlib.XGetInputFocus(@display.to_native, window_ptr, trash_ptr)
|
47
|
+
window = window_ptr.read_int
|
48
|
+
|
49
|
+
if window == Xlib::PointerRoot
|
50
|
+
root_window
|
51
|
+
elsif window == Xlib::None
|
52
|
+
nil
|
53
|
+
else
|
54
|
+
Window.new(@display, window)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
43
58
|
def crtcs
|
44
59
|
(0..resources[:ncrtc]-1).map do |crtc_number|
|
45
60
|
crtc_id(resources[:crtcs], crtc_number)
|
@@ -49,6 +64,7 @@ module XlibObj
|
|
49
64
|
end
|
50
65
|
|
51
66
|
private
|
67
|
+
|
52
68
|
def resources
|
53
69
|
unless @resources
|
54
70
|
resources_ptr = Xlib.XRRGetScreenResources(@display.to_native,
|
data/lib/window.rb
CHANGED
@@ -20,8 +20,7 @@ module XlibObj
|
|
20
20
|
|
21
21
|
def attribute(name)
|
22
22
|
attributes = Xlib::WindowAttributes.new
|
23
|
-
Xlib.XGetWindowAttributes(@display.to_native, @to_native, attributes.
|
24
|
-
pointer)
|
23
|
+
Xlib.XGetWindowAttributes(@display.to_native, @to_native, attributes.pointer)
|
25
24
|
attributes[name.to_sym]
|
26
25
|
rescue
|
27
26
|
nil
|
@@ -43,22 +42,25 @@ module XlibObj
|
|
43
42
|
Property.new(self, name).set(value)
|
44
43
|
end
|
45
44
|
|
45
|
+
def delete_property(name)
|
46
|
+
Property.new(self, name).delete
|
47
|
+
end
|
48
|
+
|
46
49
|
def absolute_position
|
47
50
|
x_abs = FFI::MemoryPointer.new :int
|
48
51
|
y_abs = FFI::MemoryPointer.new :int
|
49
52
|
child = FFI::MemoryPointer.new :Window
|
50
53
|
root_win = screen.root_window
|
51
54
|
|
52
|
-
Xlib.XTranslateCoordinates(@display.to_native, @to_native,
|
53
|
-
|
55
|
+
Xlib.XTranslateCoordinates(@display.to_native, @to_native, root_win.to_native, 0, 0, x_abs,
|
56
|
+
y_abs, child)
|
54
57
|
|
55
58
|
{ x: x_abs.read_int, y: y_abs.read_int }
|
56
59
|
end
|
57
60
|
|
58
61
|
# Commands
|
59
62
|
def move_resize(x, y, width, height)
|
60
|
-
Xlib.XMoveResizeWindow(@display.to_native, @to_native, x, y, width,
|
61
|
-
height)
|
63
|
+
Xlib.XMoveResizeWindow(@display.to_native, @to_native, x, y, width, height)
|
62
64
|
Xlib.XFlush(@display.to_native)
|
63
65
|
self
|
64
66
|
end
|
@@ -87,6 +89,12 @@ module XlibObj
|
|
87
89
|
self
|
88
90
|
end
|
89
91
|
|
92
|
+
def focus
|
93
|
+
Xlib.XSetInputFocus(@display.to_native, @to_native, Xlib::RevertToParent, Xlib::CurrentTime)
|
94
|
+
Xlib.XFlush(@display.to_native)
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
90
98
|
def on(mask, type, &callback)
|
91
99
|
@event_handler.on(mask, type, &callback)
|
92
100
|
end
|
@@ -103,6 +111,43 @@ module XlibObj
|
|
103
111
|
|
104
112
|
def send_to_itself(type, data = nil, subject = nil)
|
105
113
|
Event::ClientMessage.new(type, data, subject).send_to(self)
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
117
|
+
def request_selection(type: :PRIMARY, format: :UTF8_STRING, property: :XSEL_DATA, &on_receive)
|
118
|
+
# will only receive the selection notify event, if the window has been created by the process
|
119
|
+
# running this very code
|
120
|
+
selection_handler = on(:no_event, :selection_notify) do |event|
|
121
|
+
next if Atom.new(@display, event.selection).name != type
|
122
|
+
|
123
|
+
if event.property == Xlib::None
|
124
|
+
selection = nil
|
125
|
+
else
|
126
|
+
selection = property(event.property)
|
127
|
+
delete_property(event.property)
|
128
|
+
end
|
129
|
+
on_receive.call(selection, type)
|
130
|
+
off(:no_event, :selection_notify, selection_handler)
|
131
|
+
end
|
132
|
+
|
133
|
+
type_atom = Atom.new(@display, type)
|
134
|
+
property_atom = Atom.new(@display, property)
|
135
|
+
format_atom = Atom.new(@display, format)
|
136
|
+
Xlib.XConvertSelection(@display.to_native, type_atom.to_native, format_atom.to_native,
|
137
|
+
property_atom.to_native, @to_native, Xlib::CurrentTime)
|
138
|
+
Xlib.XFlush(@display.to_native)
|
139
|
+
self
|
140
|
+
end
|
141
|
+
|
142
|
+
def create_window
|
143
|
+
black = Xlib.XBlackPixel(@display.to_native, 0)
|
144
|
+
win_id = Xlib.XCreateSimpleWindow(@display.to_native, to_native, 0, 0, 1, 1, 0, black, black)
|
145
|
+
XlibObj::Window.new(@display, win_id)
|
146
|
+
end
|
147
|
+
|
148
|
+
def destroy
|
149
|
+
@event_handler.destroy
|
150
|
+
Xlib.XDestroyWindow(@display.to_native, to_native)
|
106
151
|
end
|
107
152
|
end
|
108
153
|
end
|
data/lib/window/event_handler.rb
CHANGED
@@ -15,6 +15,10 @@ module XlibObj
|
|
15
15
|
@handlers[display] ||= {}
|
16
16
|
@handlers[display][window_id] ||= new(display, window_id)
|
17
17
|
end
|
18
|
+
|
19
|
+
def remove(display, window_id)
|
20
|
+
@handlers[display].delete(window_id) if @handlers and @handlers[display]
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
def initialize(display, window_id)
|
@@ -46,6 +50,10 @@ module XlibObj
|
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
53
|
+
def destroy
|
54
|
+
self.class.remove(@display, @window_id)
|
55
|
+
end
|
56
|
+
|
49
57
|
private
|
50
58
|
def add_event_mask(mask)
|
51
59
|
check_mask(mask)
|
@@ -91,7 +99,7 @@ module XlibObj
|
|
91
99
|
end
|
92
100
|
|
93
101
|
def check_mask(mask)
|
94
|
-
if
|
102
|
+
if XlibObj::Event::MASK[mask].nil? && XlibObj::Event::RR_MASK[mask].nil?
|
95
103
|
raise("Unknown event mask #{mask}.")
|
96
104
|
end
|
97
105
|
end
|
data/lib/window/property.rb
CHANGED
@@ -73,6 +73,10 @@ module XlibObj
|
|
73
73
|
self
|
74
74
|
end
|
75
75
|
|
76
|
+
def delete
|
77
|
+
Xlib.XDeleteProperty(@window.display.to_native, @window.to_native, @atom.to_native)
|
78
|
+
end
|
79
|
+
|
76
80
|
private
|
77
81
|
def read_bytes(pointer, width, count)
|
78
82
|
pointer.read_pointer.read_string(count*native_width(width))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlib-objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Aue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xlib
|