rwayland 0.2.2 → 0.3.0

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.
@@ -1,208 +0,0 @@
1
- require 'rwaylandtk/custom_wl_interface'
2
-
3
- module RWaylandTk
4
-
5
- class ToplevelWindow
6
-
7
- include CustomWaylandInterface
8
-
9
- def initialize(width, height)
10
- @display = RWaylandTk.display_instance
11
- @width = width
12
- @height = height
13
- @valid = false
14
- @wl_surface = @display[:wl_compositor].create_surface as: [WlSurface, self]
15
- @xdg_surface = @display[:xdg_wm_base].get_xdg_surface @wl_surface, as: [XdgSurface, self]
16
- @xdg_toplevel = @xdg_surface.get_toplevel as: [XdgToplevel, self]
17
- if @display[:zxdg_decoration_manager_v1]
18
- @server_decoration = true
19
- dm = @display[:zxdg_decoration_manager_v1]
20
- @zxdg_toplevel_decoration = dm.get_toplevel_decoration @xdg_toplevel
21
- mode = @server_decoration ?
22
- Wayland::Zxdg::ToplevelDecorationV1[:mode][:server_side] :
23
- Wayland::Zxdg::ToplevelDecorationV1[:mode][:client_side]
24
- @zxdg_toplevel_decoration.set_mode mode
25
- end
26
- end
27
- attr_reader :width, :height
28
- attr_reader :server_decoration
29
-
30
- # User hook
31
-
32
- def mouse_enter(x, y); end
33
- def mouse_leave; end
34
- def mouse_moved(x, y); end
35
- def mouse_up(button, time, serial); end
36
- def mouse_down(button, time, serial); end
37
- def axis(time, axis, value) ; end
38
- def resized(width, height); end
39
- def key_down(data); end
40
- def key_up(data); end
41
-
42
- BGCOLOR = [1.0, 1.0, 1.0, 1.0]
43
-
44
- def draw
45
- cairo = cairo_context
46
- cairo.save do
47
- cairo.set_source_color BGCOLOR
48
- cairo.rectangle 0, 0, width, height
49
- cairo.fill
50
- end
51
- end
52
-
53
- # Hook
54
-
55
- def _mouse_enter(x, y)
56
- # p [:mouse_enter, x, y]
57
- mouse_enter x, y
58
- # update_if_needed
59
- end
60
-
61
- def _mouse_leave
62
- # p [:mouse_leave]
63
- mouse_leave
64
- # update_if_needed
65
- end
66
-
67
- def _mouse_moved(x, y)
68
- mouse_moved x, y
69
- update_if_needed
70
- end
71
-
72
- def _mouse_up(button, time, serial)
73
- mouse_up(button, time, serial)
74
- update_if_needed
75
- end
76
-
77
- def _mouse_down(button, time, serial)
78
- mouse_down(button, time, serial)
79
- update_if_needed
80
- end
81
-
82
- def _axis(time, axis, value)
83
- axis(time, axis, value)
84
- update_if_needed
85
- end
86
-
87
- def _resize(width, height)
88
- if width > 0 && height > 0
89
- @width = width
90
- @height = height
91
- resized width, height
92
- update_if_needed
93
- end
94
- end
95
-
96
- def _frame_done
97
- @frame_requested = false
98
- realloc_buffer
99
- draw
100
- _expose
101
- end
102
-
103
- def _expose
104
- @wl_surface.attach @wl_buffer, 0, 0
105
- @wl_buffer.attached
106
- @wl_surface.damage_buffer 0, 0, 0x7fffffff, 0x7fffffff
107
- @wl_surface.commit
108
- validate
109
- end
110
-
111
- def _configure(serial)
112
- p :_configure
113
- realloc_buffer
114
- draw
115
- _expose
116
- end
117
-
118
- def _key_down(data)
119
- key_down(data)
120
- update_if_needed
121
- end
122
-
123
- def _key_up(data)
124
- key_up(data)
125
- update_if_needed
126
- end
127
-
128
- # API
129
-
130
- def cairo_context
131
- @wl_buffer.cairo_context
132
- end
133
-
134
- def request_frame
135
- unless @frame_requested
136
- @wl_surface.frame as: [FrameCB, self]
137
- @wl_surface.commit
138
- @frame_requested = true
139
- end
140
- end
141
-
142
- def update_if_needed
143
- return if valid?
144
- request_frame
145
- end
146
-
147
- def set_title(title, app_id, commit = true)
148
- @xdg_toplevel.set_title title
149
- @xdg_toplevel.set_app_id app_id
150
- @wl_surface.commit if commit
151
- @title = title
152
- @app_id = app_id
153
- end
154
- attr_reader :title, :app_id
155
-
156
- def bpp; 4 end # pseudo
157
-
158
- def buffer_realloc?
159
- return false if width == 0 || height == 0
160
- return true unless @wl_buffer
161
- return true if @wl_buffer.attached?
162
- return false if @wl_buffer.width == width && @wl_buffer.height == height
163
- return true
164
- end
165
-
166
- def realloc_buffer
167
- if buffer_realloc?
168
- stride = width * bpp
169
- size = stride * height
170
- shm = Wayland::SharedMemory.new size: size
171
- pool = @display[:wl_shm].create_pool shm.fd, size
172
- format = Wayland::Wl::Shm[:format].xrgb8888
173
- buffer = pool.create_buffer(0, width, height, stride, format,
174
- as: [WlBuffer, width, height, stride, format, shm])
175
- pool.destroy
176
- shm.close
177
- @wl_buffer.destroy_on_release if @wl_buffer
178
- cairo = buffer.cairo_context
179
- cairo.save do
180
- cairo.set_source_color BGCOLOR
181
- cairo.rectangle 0, 0, width, height
182
- cairo.fill
183
- end
184
- @wl_buffer = buffer
185
- end
186
- @wl_buffer
187
- end
188
-
189
- def invalidate
190
- @valid = false
191
- end
192
-
193
- def validate
194
- @valid = false
195
- end
196
-
197
- def valid?
198
- @valid
199
- end
200
-
201
- def show
202
- # invalidate
203
- # realloc_buffer
204
- # draw
205
- # _expose
206
- end
207
- end
208
- end
@@ -1,27 +0,0 @@
1
- require 'wayland'
2
- require 'rwaylandtk/custom_wl_interface'
3
- require 'rwaylandtk/toplevel_window'
4
- require 'logger'
5
-
6
- module RWaylandTk
7
- def self.init
8
- @@display = Wayland::Wl::Display.connect
9
- @@display.set_logger Logger.new(STDOUT)
10
- registry = @@display.get_registry
11
- registry.set_global_module :wl_seat => CustomWaylandInterface::WlSeat
12
- @@display.roundtrip
13
- nil
14
- end
15
-
16
- def self.display_instance
17
- @@display
18
- end
19
-
20
- def self.set_logger(logger)
21
- @@display.set_logger logger
22
- end
23
-
24
- def self.main_loop
25
- loop{ @@display.dispatch }
26
- end
27
- end