1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
use libc;
use libc::*;
use wayland_sys::common::*;
use wayland_sys::server::*;
extern "C" {
pub fn wlc_get_outputs(memb: *mut libc::size_t) -> *const libc::uintptr_t;
pub fn wlc_get_focused_output() -> uintptr_t;
pub fn wlc_output_get_name(output: uintptr_t) -> *const c_char;
pub fn wlc_handle_get_user_data(handle: uintptr_t) -> *mut c_void;
pub fn wlc_handle_set_user_data(handle: uintptr_t, userdata: *const c_void);
pub fn wlc_output_get_sleep(output: uintptr_t) -> bool;
pub fn wlc_output_set_sleep(output: uintptr_t, sleep: bool);
pub fn wlc_output_get_resolution(output: uintptr_t) -> *const Size;
pub fn wlc_output_set_resolution(output: uintptr_t, resolution: *const Size, scale: uint32_t);
pub fn wlc_output_get_scale(output: uintptr_t) -> uint32_t;
pub fn wlc_output_get_virtual_resolution(output: uintptr_t) -> *const Size;
pub fn wlc_output_get_mask(output: uintptr_t) -> u32;
pub fn wlc_output_set_mask(output: uintptr_t, mask: u32);
pub fn wlc_output_get_views(output: uintptr_t,
out_memb: *mut libc::size_t) -> *const uintptr_t;
pub fn wlc_output_set_views(output: uintptr_t, views: *const uintptr_t, memb: libc::size_t) -> bool;
pub fn wlc_output_focus(output: uintptr_t);
pub fn wlc_view_focus(view: uintptr_t);
pub fn wlc_view_close(view: uintptr_t);
pub fn wlc_view_get_output(view: uintptr_t) -> uintptr_t;
pub fn wlc_view_set_output(view: uintptr_t, output: uintptr_t);
pub fn wlc_view_send_to_back(view: uintptr_t);
pub fn wlc_view_send_below(view: uintptr_t, other: uintptr_t);
pub fn wlc_view_bring_above(view: uintptr_t, other: uintptr_t);
pub fn wlc_view_bring_to_front(view: uintptr_t);
pub fn wlc_view_get_mask(view: uintptr_t) -> u32;
pub fn wlc_view_set_mask(view: uintptr_t, mask: u32);
pub fn wlc_view_get_geometry(view: uintptr_t) -> *const Geometry;
pub fn wlc_view_get_visible_geometry(view: uintptr_t, geo: *mut Geometry);
pub fn wlc_view_set_geometry(view: uintptr_t, edges: u32, geo: *const Geometry);
pub fn wlc_view_get_type(view: uintptr_t) -> ViewType;
pub fn wlc_view_set_type(view: uintptr_t, view_type: ViewType, toggle: bool);
pub fn wlc_view_get_state(view: uintptr_t) -> ViewState;
pub fn wlc_view_set_state(view: uintptr_t, state: ViewState, toggle: bool);
pub fn wlc_view_get_parent(view: uintptr_t) -> uintptr_t;
pub fn wlc_view_set_parent(view: uintptr_t, parent: uintptr_t);
pub fn wlc_view_get_title(view: uintptr_t) -> *const c_char;
pub fn wlc_view_get_class(view: uintptr_t) -> *const c_char;
pub fn wlc_view_get_app_id(view: uintptr_t) -> *const c_char;
pub fn wlc_view_get_pid(view: uintptr_t)-> pid_t;
pub fn wlc_handle_from_wl_surface_resource(resource: *const wl_resource) -> uintptr_t;
pub fn wlc_handle_from_wl_output_resource(resource: *const wl_resource) -> uintptr_t;
pub fn wlc_view_get_surface(view: uintptr_t) -> uintptr_t;
pub fn wlc_view_get_wl_client(view: uintptr_t) -> *mut wl_client;
pub fn wlc_view_get_role(view: uintptr_t) -> *mut wl_resource;
pub fn wlc_view_from_surface(surface: uintptr_t, client: *const wl_client, interface: *const wl_interface,
implementation: *const c_void, version: uint32_t, id: uint32_t, userdata: *mut c_void)
-> uintptr_t;
}
use libc::{uintptr_t, pid_t};
use super::types::{Geometry, ResizeEdge, Point, Size, ViewType, ViewState};
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WlcView(pub uintptr_t);
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WlcOutput(pub uintptr_t);
impl From<WlcView> for WlcOutput {
fn from(view: WlcView) -> Self {
WlcOutput(view.0)
}
}
impl From<WlcOutput> for WlcView {
fn from(output: WlcOutput) -> Self {
WlcView(output.0)
}
}
static ZERO_RES: Size = Size { w: 0, h: 0 };
impl WlcOutput {
pub fn as_view(self) -> WlcView {
return WlcView::from(self)
}
#[inline]
pub fn is_null(self) -> bool {
self.0 == 0
}
pub fn dummy(code: u32) -> WlcOutput {
WlcOutput(code as uintptr_t)
}
pub unsafe fn get_user_data<T>(&self) -> &mut T {
unimplemented!()
}
pub unsafe fn set_user_data<T>(&self, data: &T) {
unimplemented!()
}
pub fn schedule_render(&self) {
}
pub fn list() -> Vec<WlcOutput> {
vec![]
}
pub fn focused() -> WlcOutput {
WlcOutput(0)
}
pub fn get_name(&self) -> String {
"".to_string()
}
pub fn get_sleep(&self) -> bool {
false
}
pub fn set_sleep(&self, sleep: bool) {
}
pub fn get_resolution(&self) -> Option<Size> {
Some(ZERO_RES)
}
pub fn set_resolution(&self, size: Size, scaling: u32) {
}
pub fn get_views(&self) -> Vec<WlcView> {
Vec::new()
}
pub fn get_mask(&self) -> u32 {
0
}
pub fn set_mask(&self, mask: u32) {
}
pub fn get_mutable_views(&self) -> Vec<WlcView> {
self.get_views()
}
pub fn set_views(&self, views: &mut Vec<WlcView>) -> Result<(), &'static str> {
Err("Currently running dummy-rustwlc")
}
pub fn focus(output: Option<WlcOutput>) {
}
}
impl WlcView {
pub fn as_output(self) -> WlcOutput {
WlcOutput::from(self)
}
pub fn dummy(code: u32) -> WlcView {
WlcView(code as uintptr_t)
}
pub fn root() -> WlcView {
WlcView(0)
}
#[inline]
pub fn is_root(&self) -> bool {
self.0 == 0
}
#[inline]
pub fn is_window(&self) -> bool {
self.0 != 0
}
pub unsafe fn get_user_data<T>(&self) -> &mut T {
unimplemented!()
}
pub unsafe fn set_user_data<T>(&self, data: &T) {
unimplemented!()
}
pub fn close(self) {
}
pub fn get_output(&self) -> WlcOutput {
WlcOutput::dummy(0)
}
pub fn set_output(&self, output: WlcOutput) {
}
pub fn focus(self) {
}
pub fn send_to_back(&self) {
}
pub fn send_below(&self, other: WlcView) {
}
pub fn bring_above(&self, other: WlcView) {
}
pub fn bring_to_front(&self) {
}
pub fn get_mask(&self) -> u32 {
0
}
pub fn set_mask(&self, mask: u32) {
}
pub fn get_geometry(&self) -> Option<Geometry> {
Some(Geometry {
origin: Point { x: 0, y: 0},
size: Size { w: 0, h: 0}
})
}
pub fn get_visible_geometry(&self) -> Geometry {
let geo = Geometry { origin: Point { x: 0, y: 0}, size: Size { w: 0, h: 0 }};
return geo;
}
pub fn set_geometry(&self, edges: ResizeEdge, geometry: Geometry) {
}
pub fn get_type(&self) -> ViewType {
ViewType::empty()
}
pub fn set_type(&self, view_type: ViewType, toggle: bool) {
}
pub fn get_state(&self) -> ViewState {
ViewState::empty()
}
pub fn set_state(&self, state: ViewState, toggle: bool) {
}
pub fn get_parent(&self) -> WlcView {
WlcView::root()
}
pub fn set_parent(&self, parent: WlcView) {
}
pub fn get_title(&self) -> String {
"".to_string()
}
pub fn get_class(&self) -> String {
"".to_string()
}
pub fn get_pid(self) -> pid_t {
0 as pid_t
}
pub fn get_app_id(&self) -> String {
"".to_string()
}
}
#[cfg(test)]
mod tests {
use super::super::*;
#[test]
fn dummy_views() {
let dummy = WlcView::dummy(1);
assert!(!dummy.is_root(), "Dummy(1) is root");
assert!(dummy.is_window(), "Dummy(1) is root");
let _title = dummy.get_title();
let _class = dummy.get_class();
let _app_id = dummy.get_app_id();
dummy.close();
let output = dummy.get_output();
assert!(output == WlcOutput::dummy(0));
dummy.set_output(output);
let mask = dummy.get_mask();
dummy.set_mask(mask);
let geometry = dummy.get_geometry();
dummy.set_geometry(EDGE_NONE, &Geometry {
origin: Point { x: 0, y: 0 },
size: Size { w: 0, h: 0 }
});
let view_type = dummy.get_type();
assert!(view_type.is_empty(), "Dummy had a view type");
dummy.set_type(ViewType::empty(), true);
let view_state = dummy.get_state();
assert!(view_state.is_empty(), "Dummu had a view state");
dummy.set_state(view_state, true);
let parent = dummy.get_parent();
assert!(parent.is_root(), "Dummy had real parent");
dummy.set_parent(parent);
}
#[test]
fn dummy_outputs() {
let dummy = WlcOutput::dummy(1);
dummy.schedule_render();
let _name = dummy.get_name();
let sleep = dummy.get_sleep();
dummy.set_sleep(sleep);
let _resolution = dummy.get_resolution();
let mut views = dummy.get_views();
dummy.set_views(&mut views).unwrap_err();
let mask = dummy.get_mask();
dummy.set_mask(mask);
WlcOutput::focus(Some(dummy));
}
}