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.
- checksums.yaml +4 -4
- data/example/01_wayland-book.rb +2 -4
- data/example/02_memopad.rb +192 -0
- data/example/03_image_pool.rb +64 -0
- data/example/04_cursor_theme.rb +93 -0
- data/example/miw/point.rb +31 -0
- data/example/miw/rectangle.rb +221 -0
- data/example/miw/size.rb +30 -0
- data/example/miw/wl/popup_window.rb +8 -0
- data/example/miw/wl/private.rb +235 -0
- data/example/miw/wl/toplevel.rb +648 -0
- data/example/miw/wl/window.rb +338 -0
- data/example/miw/wl.rb +60 -0
- data/lib/wayland/cairo_support.rb +7 -1
- data/lib/wayland/cursor_support/cursor.rb +81 -0
- data/lib/wayland/cursor_support/xcursor.rb +227 -0
- data/lib/wayland/cursor_support.rb +21 -0
- data/lib/wayland/object_manager.rb +0 -10
- data/lib/wayland/protocol.rb +1 -0
- data/lib/wayland/shared_memory.rb +89 -9
- data/lib/wayland/util/image_pool.rb +56 -0
- data/lib/wayland/wl/display.rb +13 -0
- metadata +16 -5
- data/example/02_window.rb +0 -180
- data/example/rwaylandtk/custom_wl_interface.rb +0 -182
- data/example/rwaylandtk/toplevel_window.rb +0 -208
- data/example/rwaylandtk.rb +0 -27
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
require "miw/wl/window"
|
|
2
|
+
require "miw/wl/private"
|
|
3
|
+
|
|
4
|
+
module MiW
|
|
5
|
+
module Wl
|
|
6
|
+
|
|
7
|
+
BORDER_WIDTH = 16
|
|
8
|
+
TITLEBAR_HEIGHT = 40
|
|
9
|
+
|
|
10
|
+
class Toplevel < Window
|
|
11
|
+
|
|
12
|
+
STATE_MAXIMIZED = 1 << 1
|
|
13
|
+
STATE_FULLSCREEN = 1 << 2
|
|
14
|
+
STATE_RESIZING = 1 << 3
|
|
15
|
+
STATE_ACTIVATED = 1 << 4
|
|
16
|
+
STATE_TILED_LEFT = 1 << 5
|
|
17
|
+
STATE_TILED_RIGHT = 1 << 6
|
|
18
|
+
STATE_TILED_TOP = 1 << 7
|
|
19
|
+
STATE_TILED_BOTTOM = 1 << 8
|
|
20
|
+
STATE_SUSPTENDED = 1 << 9
|
|
21
|
+
STATE_CONSTRAINED_LEFT = 1 << 10
|
|
22
|
+
STATE_CONSTRAINED_RIGHT = 1 << 11
|
|
23
|
+
STATE_CONSTRAINED_TOP = 1 << 12
|
|
24
|
+
STATE_CONSTRAINED_BOTTOM = 1 << 13
|
|
25
|
+
|
|
26
|
+
STATES_RESIZED = (STATE_MAXIMIZED | STATE_FULLSCREEN | STATE_RESIZING |
|
|
27
|
+
STATE_TILED_LEFT | STATE_TILED_RIGHT | STATE_TILED_TOP | STATE_TILED_BOTTOM |
|
|
28
|
+
STATE_CONSTRAINED_LEFT | STATE_CONSTRAINED_RIGHT | STATE_CONSTRAINED_TOP | STATE_CONSTRAINED_BOTTOM)
|
|
29
|
+
|
|
30
|
+
BTN_MOUSE = 0x110
|
|
31
|
+
BTN_LEFT = 0x110
|
|
32
|
+
BTN_RIGHT = 0x111
|
|
33
|
+
BTN_MIDDLE = 0x112
|
|
34
|
+
BTN_SIDE = 0x113
|
|
35
|
+
BTN_EXTRA = 0x114
|
|
36
|
+
BTN_FORWARD = 0x115
|
|
37
|
+
BTN_BACK = 0x116
|
|
38
|
+
BTN_TASK = 0x117
|
|
39
|
+
|
|
40
|
+
class Decoration
|
|
41
|
+
def initialize(toplevel)
|
|
42
|
+
@toplevel = toplevel
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def border_left?(states)
|
|
46
|
+
(states & (STATE_MAXIMIZED | STATE_FULLSCREEN | STATE_TILED_LEFT | STATE_CONSTRAINED_LEFT)) == 0
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def border_right?(states)
|
|
50
|
+
(states & (STATE_MAXIMIZED | STATE_FULLSCREEN | STATE_TILED_RIGHT | STATE_CONSTRAINED_RIGHT)) == 0
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def border_top?(states)
|
|
54
|
+
(states & (STATE_MAXIMIZED | STATE_FULLSCREEN | STATE_TILED_TOP | STATE_CONSTRAINED_TOP)) == 0
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def border_bottom?(states)
|
|
58
|
+
(states & (STATE_MAXIMIZED | STATE_FULLSCREEN | STATE_TILED_BOTTOM | STATE_CONSTRAINED_BOTTOM)) == 0
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def fullscreen?(states)
|
|
62
|
+
(states & STATE_FULLSCREEN) > 0
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def title_bar?(state)
|
|
66
|
+
false
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def adjust_window_geometry(rec_width, rec_height, bounds_width, bounds_height, states)
|
|
70
|
+
bw = bounds_width || Float::INFINITY
|
|
71
|
+
bh = bounds_height || Float::INFINITY
|
|
72
|
+
|
|
73
|
+
# initial size
|
|
74
|
+
iw = rec_width
|
|
75
|
+
ih = rec_height
|
|
76
|
+
|
|
77
|
+
# window size
|
|
78
|
+
ww = [iw, bw].min
|
|
79
|
+
wh = [ih, bh].min
|
|
80
|
+
|
|
81
|
+
# widow geometry
|
|
82
|
+
wx = border_left?(states) ? BORDER_WIDTH : 0
|
|
83
|
+
wy = border_top?(states) ? BORDER_WIDTH : 0
|
|
84
|
+
|
|
85
|
+
Rectangle.new wx, wy, ww, wh
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Descide surface size and window geometry based on init_size
|
|
89
|
+
#
|
|
90
|
+
def initial_window_geometry(client_width, client_height, bounds_width, bounds_height, states)
|
|
91
|
+
# initial size
|
|
92
|
+
iw = client_width
|
|
93
|
+
ih = client_height + (title_bar?(states) ? TITLEBAR_HEIGHT : 0)
|
|
94
|
+
adjust_window_geometry iw, ih, bounds_width, bounds_height, states
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def adjust_client_geometry(client_geometry, window_geometry, states)
|
|
98
|
+
client_geometry.x = window_geometry.x
|
|
99
|
+
client_geometry.y = window_geometry.y
|
|
100
|
+
client_geometry.width = window_geometry.width
|
|
101
|
+
client_geometry.height = window_geometry.height
|
|
102
|
+
if title_bar? states
|
|
103
|
+
client_geometry.y += TITLEBAR_HEIGHT
|
|
104
|
+
client_geometry.height -= TITLEBAR_HEIGHT
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def adjust_surface_size(window, window_geometry, states)
|
|
109
|
+
sw = window_geometry.width
|
|
110
|
+
sh = window_geometry.height
|
|
111
|
+
sw += BORDER_WIDTH if border_left? states
|
|
112
|
+
sw += BORDER_WIDTH if border_right? states
|
|
113
|
+
sh += BORDER_WIDTH if border_top? states
|
|
114
|
+
sh += BORDER_WIDTH if border_bottom? states
|
|
115
|
+
window.resize_to sw, sh
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def draw(cairo)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def hit_test(x, y, window_geometry, states)
|
|
122
|
+
:client
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def pointer_enter(x, y)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def pointer_motion(time, x, y)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def pointer_leave
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def pointer_button(time, button, state)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def activated(active)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def resized
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
class ClientDecoration < Decoration
|
|
145
|
+
def title_bar?(states)
|
|
146
|
+
!fullscreen?(states)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def adjust_window_geometry(rec_width, rec_height, bounds_width, bounds_height, states)
|
|
150
|
+
bw = bounds_width || Float::INFINITY
|
|
151
|
+
bh = bounds_height || Float::INFINITY
|
|
152
|
+
|
|
153
|
+
# initial size
|
|
154
|
+
iw = rec_width
|
|
155
|
+
ih = rec_height
|
|
156
|
+
|
|
157
|
+
# window size
|
|
158
|
+
ww = [iw, bw].min
|
|
159
|
+
wh = [ih, bh].min
|
|
160
|
+
|
|
161
|
+
# widow geometry
|
|
162
|
+
wx = border_left?(states) ? BORDER_WIDTH : 0
|
|
163
|
+
wy = border_top?(states) ? BORDER_WIDTH : 0
|
|
164
|
+
|
|
165
|
+
Rectangle.new wx, wy, ww, wh
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# Descide surface size and window geometry based on init_size
|
|
169
|
+
#
|
|
170
|
+
def initial_window_geometry(client_width, client_height, bounds_width, bounds_height, states)
|
|
171
|
+
# initial size
|
|
172
|
+
iw = client_width
|
|
173
|
+
ih = client_height
|
|
174
|
+
|
|
175
|
+
unless fullscreen?(states)
|
|
176
|
+
ih += TITLEBAR_HEIGHT
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
adjust_window_geometry iw, ih, bounds_width, bounds_height, states
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def adjust_client_geometry(client_geometry, window_geometry, states)
|
|
183
|
+
client_geometry.x = window_geometry.x
|
|
184
|
+
client_geometry.y = window_geometry.y
|
|
185
|
+
client_geometry.width = window_geometry.width
|
|
186
|
+
client_geometry.height = window_geometry.height
|
|
187
|
+
if title_bar? states
|
|
188
|
+
client_geometry.y += TITLEBAR_HEIGHT
|
|
189
|
+
client_geometry.height -= TITLEBAR_HEIGHT
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def adjust_surface_size(window, window_geometry, states)
|
|
194
|
+
sw = window_geometry.width
|
|
195
|
+
sh = window_geometry.height
|
|
196
|
+
sw += BORDER_WIDTH if border_left? states
|
|
197
|
+
sw += BORDER_WIDTH if border_right? states
|
|
198
|
+
sh += BORDER_WIDTH if border_top? states
|
|
199
|
+
sh += BORDER_WIDTH if border_bottom? states
|
|
200
|
+
window.resize_to sw, sh
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
#
|
|
204
|
+
#
|
|
205
|
+
def box_rect(wgeo, type, states)
|
|
206
|
+
return nil unless title_bar? states
|
|
207
|
+
case type
|
|
208
|
+
when :minimize
|
|
209
|
+
n = 3
|
|
210
|
+
when :maximize
|
|
211
|
+
n = 2
|
|
212
|
+
when :close
|
|
213
|
+
n = 1
|
|
214
|
+
else
|
|
215
|
+
return nil
|
|
216
|
+
end
|
|
217
|
+
Rectangle.new wgeo.right - TITLEBAR_HEIGHT * n, wgeo.y, TITLEBAR_HEIGHT, TITLEBAR_HEIGHT
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# Draw non client area
|
|
221
|
+
#
|
|
222
|
+
# +cairo+ :: Cairo::Context
|
|
223
|
+
#
|
|
224
|
+
def draw(cairo)
|
|
225
|
+
sgeo = @toplevel.surface_geometry
|
|
226
|
+
wgeo = @toplevel.window_geometry
|
|
227
|
+
drect = @toplevel.invalid_rect
|
|
228
|
+
states = @toplevel.states
|
|
229
|
+
|
|
230
|
+
cairo.save do
|
|
231
|
+
cairo.rectangle *drect
|
|
232
|
+
cairo.clip
|
|
233
|
+
cairo.operator = Cairo::Operator::SOURCE
|
|
234
|
+
cairo.set_source_rgba 0, 0, 0, 0
|
|
235
|
+
# left
|
|
236
|
+
if wgeo.x > 0 && drect.x <= wgeo.x
|
|
237
|
+
cairo.move_to sgeo.x, sgeo.y
|
|
238
|
+
cairo.line_to wgeo.x, wgeo.y
|
|
239
|
+
cairo.line_to wgeo.x, wgeo.bottom
|
|
240
|
+
cairo.line_to sgeo.x, sgeo.bottom
|
|
241
|
+
cairo.close_path
|
|
242
|
+
cairo.fill
|
|
243
|
+
end
|
|
244
|
+
# right
|
|
245
|
+
if wgeo.right < sgeo.right && drect.right >= wgeo.right
|
|
246
|
+
cairo.move_to wgeo.right, wgeo.y
|
|
247
|
+
cairo.line_to sgeo.right, sgeo.y
|
|
248
|
+
cairo.line_to sgeo.right, sgeo.bottom
|
|
249
|
+
cairo.line_to wgeo.right, wgeo.bottom
|
|
250
|
+
cairo.close_path
|
|
251
|
+
cairo.fill
|
|
252
|
+
end
|
|
253
|
+
# top
|
|
254
|
+
if wgeo.y > 0 && drect.y <= wgeo.y
|
|
255
|
+
cairo.move_to sgeo.x, sgeo.y
|
|
256
|
+
cairo.line_to sgeo.right, sgeo.y
|
|
257
|
+
cairo.line_to wgeo.right, wgeo.y
|
|
258
|
+
cairo.line_to wgeo.x, wgeo.y
|
|
259
|
+
cairo.close_path
|
|
260
|
+
cairo.fill
|
|
261
|
+
end
|
|
262
|
+
# bottom
|
|
263
|
+
if wgeo.bottom < sgeo.bottom && drect.bottom >= wgeo.bottom
|
|
264
|
+
cairo.move_to wgeo.x, wgeo.bottom
|
|
265
|
+
cairo.line_to wgeo.right, wgeo.bottom
|
|
266
|
+
cairo.line_to sgeo.right, sgeo.bottom
|
|
267
|
+
cairo.line_to sgeo.x, sgeo.bottom
|
|
268
|
+
cairo.close_path
|
|
269
|
+
cairo.fill
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# title bar
|
|
273
|
+
return unless title_bar?(states)
|
|
274
|
+
|
|
275
|
+
cairo.rectangle wgeo.x, wgeo.y, wgeo.width, TITLEBAR_HEIGHT
|
|
276
|
+
if @active
|
|
277
|
+
cairo.set_source_rgb(0.7, 0.7, 0.7)
|
|
278
|
+
else
|
|
279
|
+
cairo.set_source_rgb(0.5, 0.5, 0.5)
|
|
280
|
+
end
|
|
281
|
+
cairo.fill
|
|
282
|
+
|
|
283
|
+
## text (TODO)
|
|
284
|
+
|
|
285
|
+
## buttons
|
|
286
|
+
cairo.line_width = 3
|
|
287
|
+
cairo.set_source_rgb(0.2, 0.2, 0.2)
|
|
288
|
+
|
|
289
|
+
icon_ratio = 0.65
|
|
290
|
+
box = box_rect wgeo, :close, states
|
|
291
|
+
ibox = box.dup
|
|
292
|
+
ibox.inset_by TITLEBAR_HEIGHT * (1 - icon_ratio)
|
|
293
|
+
|
|
294
|
+
### close
|
|
295
|
+
if @area == :close
|
|
296
|
+
cairo.save do
|
|
297
|
+
cairo.rectangle *box
|
|
298
|
+
cairo.set_source_rgba 1.0, 0.0, 0.0, 0.4
|
|
299
|
+
cairo.operator = Cairo::Operator::OVER
|
|
300
|
+
cairo.fill
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
cairo.move_to ibox.x, ibox.y
|
|
304
|
+
cairo.line_to ibox.right, ibox.bottom
|
|
305
|
+
cairo.move_to ibox.right, ibox.y
|
|
306
|
+
cairo.line_to ibox.x, ibox.bottom
|
|
307
|
+
cairo.stroke
|
|
308
|
+
|
|
309
|
+
### maximize
|
|
310
|
+
ibox.offset_by -TITLEBAR_HEIGHT, 0
|
|
311
|
+
box.offset_by -TITLEBAR_HEIGHT, 0
|
|
312
|
+
if @area == :maximize
|
|
313
|
+
cairo.save do
|
|
314
|
+
cairo.rectangle *box
|
|
315
|
+
cairo.set_source_rgba 0.0, 1.0, 0.0, 0.4
|
|
316
|
+
cairo.operator = Cairo::Operator::OVER
|
|
317
|
+
cairo.fill
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
if states & STATE_MAXIMIZED == 0
|
|
321
|
+
cairo.rectangle *ibox
|
|
322
|
+
else
|
|
323
|
+
sw = ibox.width / 2
|
|
324
|
+
sh = ibox.height / 2
|
|
325
|
+
cairo.rectangle ibox.x + sw / 2, ibox.y + sh / 2, sw, sh
|
|
326
|
+
end
|
|
327
|
+
cairo.stroke
|
|
328
|
+
|
|
329
|
+
### minimize
|
|
330
|
+
ibox.offset_by -TITLEBAR_HEIGHT, 0
|
|
331
|
+
box.offset_by -TITLEBAR_HEIGHT, 0
|
|
332
|
+
if @area == :minimize
|
|
333
|
+
cairo.save do
|
|
334
|
+
cairo.rectangle *box
|
|
335
|
+
cairo.set_source_rgba 0.0, 0.0, 1.0, 0.4
|
|
336
|
+
cairo.operator = Cairo::Operator::OVER
|
|
337
|
+
cairo.fill
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
cairo.move_to ibox.x, ibox.bottom
|
|
341
|
+
cairo.line_to ibox.right, ibox.bottom
|
|
342
|
+
cairo.stroke
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
HIT_TEST = [:top_left, :top, :top_right,
|
|
347
|
+
:left, :client, :right,
|
|
348
|
+
:bottom_left, :bottom, :bottom_right].freeze
|
|
349
|
+
|
|
350
|
+
def hit_test(x, y, window_geometry, states)
|
|
351
|
+
ans = HIT_TEST[window_geometry.hit_test(x, y)]
|
|
352
|
+
if ans == :client && title_bar?(states) && y < window_geometry.y + TITLEBAR_HEIGHT
|
|
353
|
+
if x >= window_geometry.right - TITLEBAR_HEIGHT
|
|
354
|
+
ans = :close
|
|
355
|
+
elsif x >= window_geometry.right - TITLEBAR_HEIGHT * 2
|
|
356
|
+
ans = :maximize
|
|
357
|
+
elsif x >= window_geometry.right - TITLEBAR_HEIGHT * 3
|
|
358
|
+
ans = :minimize
|
|
359
|
+
else
|
|
360
|
+
ans = :title_bar
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
ans
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
private def invalidate_box(area)
|
|
367
|
+
wgeo = @toplevel.window_geometry
|
|
368
|
+
states = @toplevel.states
|
|
369
|
+
box = box_rect wgeo, area, states
|
|
370
|
+
@toplevel.invalidate *box if box
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
def pointer_enter(x, y)
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
def pointer_motion(time, x, y)
|
|
377
|
+
@pointer_x = x
|
|
378
|
+
@pointer_y = y
|
|
379
|
+
case @button_pressed_area
|
|
380
|
+
when :title_bar
|
|
381
|
+
if (@button_pressed_x - x).abs > 4 || (@button_pressed_y - y).abs > 4
|
|
382
|
+
@toplevel.move
|
|
383
|
+
@button_pressed_area = nil
|
|
384
|
+
end
|
|
385
|
+
when :left, :right, :top, :bottom, :top_left, :top_right, :bottom_left, :bottom_right
|
|
386
|
+
@toplevel.resize @button_pressed_area
|
|
387
|
+
@button_pressed_area = nil
|
|
388
|
+
else
|
|
389
|
+
wgeo = @toplevel.window_geometry
|
|
390
|
+
states = @toplevel.states
|
|
391
|
+
area = hit_test x, y, wgeo, states
|
|
392
|
+
if @area != area
|
|
393
|
+
invalidate_box @area
|
|
394
|
+
invalidate_box area
|
|
395
|
+
end
|
|
396
|
+
@area = area
|
|
397
|
+
end
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
def pointer_leave
|
|
401
|
+
invalidate_box @area
|
|
402
|
+
@area = nil
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
def pointer_button(time, button, state)
|
|
406
|
+
if state == Wayland::Wl::Pointer[:button_state].pressed
|
|
407
|
+
if @button_pressed_area.nil? ||
|
|
408
|
+
button != @button ||
|
|
409
|
+
(@pointer_x - @button_pressed_x).abs > 4 ||
|
|
410
|
+
(@pointer_y - @button_pressed_y).abs > 4 ||
|
|
411
|
+
(time - @button_pressed_time) > 500
|
|
412
|
+
@button_pressed_area = @area
|
|
413
|
+
@button = button
|
|
414
|
+
@button_pressed_x = @pointer_x
|
|
415
|
+
@button_pressed_y = @pointer_y
|
|
416
|
+
@button_pressed_time = time
|
|
417
|
+
@button_pressed_count = 1
|
|
418
|
+
else
|
|
419
|
+
@button_pressed_count += 1
|
|
420
|
+
end
|
|
421
|
+
else
|
|
422
|
+
if @button_pressed_area == @area && button == BTN_LEFT
|
|
423
|
+
case @button_pressed_area
|
|
424
|
+
when :title_bar
|
|
425
|
+
if @button_pressed_count > 1 && (time - @button_pressed_time).abs < 500
|
|
426
|
+
@toplevel.toggle_maximized
|
|
427
|
+
@button_pressed_area = nil
|
|
428
|
+
end
|
|
429
|
+
when :close
|
|
430
|
+
when :minimize
|
|
431
|
+
@toplevel.set_minimized
|
|
432
|
+
@button_pressed_area = nil
|
|
433
|
+
when :maximize
|
|
434
|
+
@toplevel.toggle_maximized
|
|
435
|
+
@button_pressed_area = nil
|
|
436
|
+
end
|
|
437
|
+
end
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def activated(active)
|
|
442
|
+
@active = active
|
|
443
|
+
if title_bar?(@toplevel.states)
|
|
444
|
+
wgeo = @toplevel.window_geometry
|
|
445
|
+
@toplevel.invalidate wgeo.x, wgeo.y, wgeo.width, TITLEBAR_HEIGHT
|
|
446
|
+
end
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
def resized
|
|
450
|
+
@area = nil
|
|
451
|
+
end
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
class ServerDecoration < Decoration
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
def initialize(client, width, height)
|
|
458
|
+
super
|
|
459
|
+
@xdg_toplevel = @xdg_surface.get_toplevel as: [Private::XdgToplevel, self]
|
|
460
|
+
dm = MiW::Wl.display_instance[:zxdg_decoration_manager_v1]
|
|
461
|
+
if dm
|
|
462
|
+
@zxdg_toplevel_decoration_v1 = dm.get_toplevel_decoration(@xdg_toplevel)
|
|
463
|
+
@zxdg_toplevel_decoration_v1.set_mode Wayland::Zxdg::ToplevelDecorationV1[:mode].server_side
|
|
464
|
+
@nonclient = ServerDecoration.new self
|
|
465
|
+
else
|
|
466
|
+
@nonclient = ClientDecoration.new self
|
|
467
|
+
end
|
|
468
|
+
commit_now
|
|
469
|
+
end
|
|
470
|
+
attr_reader :window_geometry
|
|
471
|
+
|
|
472
|
+
def on_xdg_surface_configure(serial)
|
|
473
|
+
@serial = serial
|
|
474
|
+
next_width = @xdg_toplevel.width
|
|
475
|
+
next_height = @xdg_toplevel.height
|
|
476
|
+
next_states = @xdg_toplevel.states.inject(0){|r, i| r | (1 << i) }
|
|
477
|
+
states_diff = @states ^ next_states
|
|
478
|
+
@states = next_states
|
|
479
|
+
resized = false
|
|
480
|
+
if next_width == 0 || next_height == 0 || @window_geometry.nil?
|
|
481
|
+
@window_geometry = @nonclient.initial_window_geometry @init_size.width, @init_size.height,
|
|
482
|
+
@xdg_toplevel.bounds_width, @xdg_toplevel.bounds_height,
|
|
483
|
+
@states
|
|
484
|
+
resized = true
|
|
485
|
+
elsif @window_geometry.width != next_width ||
|
|
486
|
+
@window_geometry.height != next_height ||
|
|
487
|
+
(states_diff & STATES_RESIZED) > 0
|
|
488
|
+
@window_geometry = @nonclient.adjust_window_geometry next_width, next_height,
|
|
489
|
+
@xdg_toplevel.bounds_width, @xdg_toplevel.bounds_height,
|
|
490
|
+
@states
|
|
491
|
+
resized = true
|
|
492
|
+
end
|
|
493
|
+
if states_diff & STATE_ACTIVATED > 0
|
|
494
|
+
activated = ((@states & STATE_ACTIVATED) > 0)
|
|
495
|
+
@client.activated activated
|
|
496
|
+
@nonclient.activated activated
|
|
497
|
+
end
|
|
498
|
+
if resized
|
|
499
|
+
@client_geometry = @window_geometry.dup
|
|
500
|
+
@nonclient.adjust_client_geometry @client_geometry, @window_geometry, @states
|
|
501
|
+
@nonclient.adjust_surface_size self, @window_geometry, @states
|
|
502
|
+
@xdg_surface.set_window_geometry @window_geometry.x, @window_geometry.y,
|
|
503
|
+
@window_geometry.width, @window_geometry.height
|
|
504
|
+
realloc_buffer
|
|
505
|
+
@client.resized
|
|
506
|
+
@nonclient.resized
|
|
507
|
+
end
|
|
508
|
+
update
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
def hit_test(x, y)
|
|
512
|
+
if @client_geometry.contain? x, y
|
|
513
|
+
ans = @client.hit_test *convert_to_client(x, y)
|
|
514
|
+
else
|
|
515
|
+
ans = @nonclient.hit_test x, y, @window_geometry, @states
|
|
516
|
+
end
|
|
517
|
+
ans
|
|
518
|
+
end
|
|
519
|
+
|
|
520
|
+
def on_wl_pointer_enter(serial, x, y)
|
|
521
|
+
@serial = @serial_enter = serial
|
|
522
|
+
@pointer_x = x
|
|
523
|
+
@pointer_y = y
|
|
524
|
+
# 1. change cursor
|
|
525
|
+
## TODO
|
|
526
|
+
# 2. notify event
|
|
527
|
+
@nonclient.pointer_enter x, y
|
|
528
|
+
if @client_geometry.contain? x, y
|
|
529
|
+
@pointer_enter_client = true
|
|
530
|
+
cx, cy = convert_to_client x, y
|
|
531
|
+
@client.pointer_enter cx, cy
|
|
532
|
+
else
|
|
533
|
+
@pointer_enter_client = false
|
|
534
|
+
end
|
|
535
|
+
set_default_cursor @serial_enter, hit_test(x, y)
|
|
536
|
+
lasy_update
|
|
537
|
+
commit_if_needed
|
|
538
|
+
end
|
|
539
|
+
|
|
540
|
+
def on_wl_pointer_leave(serial)
|
|
541
|
+
@serial = serial
|
|
542
|
+
if @pointer_enter_client
|
|
543
|
+
@client.pointer_leave
|
|
544
|
+
end
|
|
545
|
+
@nonclient.pointer_leave
|
|
546
|
+
reset_cursor
|
|
547
|
+
lasy_update
|
|
548
|
+
commit_if_needed
|
|
549
|
+
end
|
|
550
|
+
|
|
551
|
+
def on_wl_pointer_button(serial, time, button, state)
|
|
552
|
+
@serial = serial
|
|
553
|
+
if state == Wayland::Wl::Pointer[:button_state].pressed
|
|
554
|
+
if @current_pointer_handler.nil?
|
|
555
|
+
@current_pointer_handler = @client_geometry.contain?(@pointer_x, @pointer_y) ? @client : @nonclient
|
|
556
|
+
@pointer_button_press_count = 0
|
|
557
|
+
end
|
|
558
|
+
@pointer_button_press_count += 1
|
|
559
|
+
@current_pointer_handler.pointer_button time, button, state
|
|
560
|
+
elsif @current_pointer_handler
|
|
561
|
+
@current_pointer_handler.pointer_button time, button, state
|
|
562
|
+
@pointer_button_press_count -= 1
|
|
563
|
+
@current_pointer_handler = nil if @pointer_button_press_count == 0
|
|
564
|
+
end
|
|
565
|
+
lasy_update
|
|
566
|
+
commit_if_needed
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
def on_wl_pointer_motion(time, x, y)
|
|
570
|
+
@pointer_x = x
|
|
571
|
+
@pointer_y = y
|
|
572
|
+
case @current_pointer_handler
|
|
573
|
+
when @client
|
|
574
|
+
cx, cy = convert_to_client x, y
|
|
575
|
+
@current_pointer_handler.pointer_motion time, cx, cy
|
|
576
|
+
when @nonclient
|
|
577
|
+
@current_pointer_handler.pointer_motion time, x, y
|
|
578
|
+
else
|
|
579
|
+
prev_in_client = @in_client
|
|
580
|
+
if @in_client = @client_geometry.contain?(x, y)
|
|
581
|
+
cx, cy = convert_to_client x, y
|
|
582
|
+
unless prev_in_client
|
|
583
|
+
@nonclient.pointer_leave
|
|
584
|
+
@client.pointer_enter cx, cy
|
|
585
|
+
end
|
|
586
|
+
@client.pointer_motion time, cx, cy
|
|
587
|
+
else
|
|
588
|
+
if prev_in_client
|
|
589
|
+
@client.pointer_leave
|
|
590
|
+
@nonclient.pointer_enter x, y
|
|
591
|
+
end
|
|
592
|
+
@nonclient.pointer_motion time, x, y
|
|
593
|
+
end
|
|
594
|
+
end
|
|
595
|
+
set_default_cursor @serial_enter, hit_test(x, y) unless @current_pointer_handler
|
|
596
|
+
lasy_update
|
|
597
|
+
commit_if_needed
|
|
598
|
+
end
|
|
599
|
+
|
|
600
|
+
def on_wl_pointer_axis(time, axis, value)
|
|
601
|
+
if @client_geometry.contain? @pointer_x, @pointer_y
|
|
602
|
+
@client.pointer_axis(time, axis, value)
|
|
603
|
+
end
|
|
604
|
+
lasy_update
|
|
605
|
+
commit_if_needed
|
|
606
|
+
end
|
|
607
|
+
|
|
608
|
+
def set_minimized
|
|
609
|
+
@xdg_toplevel.set_minimized
|
|
610
|
+
@current_pointer_handler = nil
|
|
611
|
+
end
|
|
612
|
+
|
|
613
|
+
def set_maximized
|
|
614
|
+
@xdg_toplevel.set_maximized
|
|
615
|
+
@current_pointer_handler = nil
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
def unset_maximized
|
|
619
|
+
@xdg_toplevel.unset_maximized
|
|
620
|
+
@current_pointer_handler = nil
|
|
621
|
+
end
|
|
622
|
+
|
|
623
|
+
def toggle_maximized
|
|
624
|
+
if @states & STATE_MAXIMIZED == 0
|
|
625
|
+
set_maximized
|
|
626
|
+
else
|
|
627
|
+
unset_maximized
|
|
628
|
+
end
|
|
629
|
+
end
|
|
630
|
+
|
|
631
|
+
def move
|
|
632
|
+
seat = @display[:wl_seat]
|
|
633
|
+
@xdg_toplevel.move seat, @serial
|
|
634
|
+
@current_pointer_handler = nil
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
def resize(edge)
|
|
638
|
+
seat = @display[:wl_seat]
|
|
639
|
+
@xdg_toplevel.resize seat, @serial, Wayland::Xdg::Toplevel[:resize_edge][edge]
|
|
640
|
+
@current_pointer_handler = nil
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
private def draw_nonclient(cairo)
|
|
644
|
+
@nonclient.draw(cairo)
|
|
645
|
+
end
|
|
646
|
+
end
|
|
647
|
+
end
|
|
648
|
+
end
|