jay-compositor 1.15.0

The Jay compositor
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
/*
dir output_node {
    @inherit dfs_node,
    id: reg,
    name: reg,
    status: reg,
    is_dummy: reg,
    title_visible: reg,
    tearing: reg,
    damage_scheduled: reg,
    hardware_cursor_needs_render: reg,
    update_render_data_scheduled: reg,
    has_hardware_cursor: reg,
    render_margin_ns: reg,
    flip_margin_ns: reg,
    has_lock_surface: reg,
    num_workspaces: reg,
    num_tray_items: reg,
    num_screencasts: reg,
    num_screencopies: reg,
    num_jay_outputs: reg,
    num_cursor_users: reg,
    pos_live: reg,
    pos_render: reg,
    scale: reg,
    legacy_scale: reg,
    non_exclusive: reg,
    workspace_rect: reg,
    bar: reg,
    exclusive_top: reg,
    exclusive_right: reg,
    exclusive_bottom: reg,
    exclusive_left: reg,
    tray_start_rel: reg,
    workspace: link (opt),
    overlay: link (opt),
    lock_surface: link (opt),
    workspaces: view (key = 0),
    layers: view (key = 0),
    tray_items: view (key = 0),
    color_description_live: reg,
    color_description_render: reg,
    linear_color_description_live: reg,
    linear_color_description_render: reg,
    connector: custom (opt),
}
 */
use crate::dfs::dfs_helpers::format_object_link;
use crate::dfs::dfs_helpers::format_path_link;
use crate::dfs::dfs_helpers::format_workspace_link;
use crate::ifs::wl_surface::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
use crate::tree::OutputNode;
use crate::tree::TreeTimeline::LiveTL;
use crate::tree::TreeTimeline::RenderTL;
use crate::tree::WorkspaceNode;
use crate::tree::output::output_dfs_g_fuse::generated::output_node;
use crate::utils::fuse::fuse_inode::FuseInodeExt;
use crate::utils::fuse::fuse_inode::FuseInodeWithKey;
use crate::utils::fuse::fuse_views::FuseLink;
use crate::utils::fuse::fuse_views::FuseLinkView;
use crate::utils::fuse::fuse_views::IterDir;
use crate::utils::fuse::fuse_views::IterDirKeyed;
use crate::utils::fuse::fuse_views::IterDirKeyedView;
use crate::utils::fuse::fuse_views::IterDirView;
use crate::utils::str_fmt::StrCtx;
use crate::utils::str_fmt::StrFmt;
use crate::utils::type_view::TypeViewExt1;
pub use output_node::View as OutputNodeView;
use std::rc::Rc;
use std::str::FromStr;

impl OutputNode {
    pub(super) fn debugfs(self: Rc<Self>) -> FuseInodeWithKey {
        self.tv_wrap_rc::<output_node::View>().without_key()
    }
}

impl output_node::Dir for OutputNode {
    type ViewWorkspaces = IterDir<Workspaces>;
    type ViewLayers = IterDirKeyed<Layers>;
    type ViewTrayItems = IterDirKeyed<TrayItems>;

    fn read_id(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.id.raw().str_fmt(buf, ctx);
    }

    fn read_name(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.global.connector.name.as_str().str_fmt(buf, ctx);
    }

    fn read_status(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.status.get().as_str().str_fmt(buf, ctx);
    }

    fn read_is_dummy(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.is_dummy.str_fmt(buf, ctx);
    }

    fn read_title_visible(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.title_visible.get().str_fmt(buf, ctx);
    }

    fn read_tearing(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.tearing.get().str_fmt(buf, ctx);
    }

    fn read_damage_scheduled(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.damage_scheduled.get().str_fmt(buf, ctx);
    }

    fn read_hardware_cursor_needs_render(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.hardware_cursor_needs_render.get().str_fmt(buf, ctx);
    }

    fn read_update_render_data_scheduled(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.update_render_data_scheduled.get().str_fmt(buf, ctx);
    }

    fn read_has_hardware_cursor(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.hardware_cursor.get().is_some().str_fmt(buf, ctx);
    }

    fn read_render_margin_ns(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.render_margin_ns.get().str_fmt(buf, ctx);
    }

    fn read_flip_margin_ns(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.flip_margin_ns.get().str_fmt(buf, ctx);
    }

    fn read_has_lock_surface(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[LiveTL]
            .lock_surface
            .get()
            .is_some()
            .str_fmt(buf, ctx);
    }

    fn read_num_workspaces(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.workspaces.iter_valid(LiveTL).count().str_fmt(buf, ctx);
    }

    fn read_num_tray_items(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.tray_items.iter_valid(LiveTL).count().str_fmt(buf, ctx);
    }

    fn read_num_screencasts(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.screencasts.len().str_fmt(buf, ctx);
    }

    fn read_num_screencopies(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.screencopies.len().str_fmt(buf, ctx);
    }

    fn read_num_jay_outputs(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.jay_outputs.len().str_fmt(buf, ctx);
    }

    fn read_num_cursor_users(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.cursor_users.len().str_fmt(buf, ctx);
    }

    fn read_pos_live(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[LiveTL].pos.get().str_fmt(buf, ctx);
    }

    fn read_pos_render(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[RenderTL].pos.get().str_fmt(buf, ctx);
    }

    fn read_scale(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[LiveTL]
            .scale
            .get()
            .to_f64()
            .str_fmt(buf, ctx);
    }

    fn read_legacy_scale(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[LiveTL].legacy_scale.get().str_fmt(buf, ctx);
    }

    fn read_non_exclusive(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[LiveTL]
            .rects
            .non_exclusive
            .get()
            .str_fmt(buf, ctx);
    }

    fn read_workspace_rect(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[LiveTL]
            .rects
            .workspace
            .get()
            .str_fmt(buf, ctx);
    }

    fn read_bar(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[LiveTL].rects.bar.get().str_fmt(buf, ctx);
    }

    fn read_exclusive_top(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.exclusive_zones.get().top.str_fmt(buf, ctx);
    }

    fn read_exclusive_right(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.exclusive_zones.get().right.str_fmt(buf, ctx);
    }

    fn read_exclusive_bottom(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.exclusive_zones.get().bottom.str_fmt(buf, ctx);
    }

    fn read_exclusive_left(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.exclusive_zones.get().left.str_fmt(buf, ctx);
    }

    fn read_tray_start_rel(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.tray_start_rel.get().str_fmt(buf, ctx);
    }

    fn has_workspace(&self) -> bool {
        self.node_state[LiveTL].workspace.is_some()
    }

    fn readlink_workspace(&self, depth: u64, buf: &mut String) {
        if let Some(t) = self.node_state[LiveTL].workspace.get() {
            format_workspace_link(buf, depth, &t);
        }
    }

    fn has_overlay(&self) -> bool {
        self.node_state[LiveTL].overlay.get().is_some()
    }

    fn readlink_overlay(&self, depth: u64, buf: &mut String) {
        if let Some(t) = self.node_state[LiveTL].overlay.get() {
            format_workspace_link(buf, depth, &t);
        }
    }

    fn has_lock_surface(&self) -> bool {
        self.node_state[LiveTL].lock_surface.is_some()
    }

    fn readlink_lock_surface(&self, depth: u64, buf: &mut String) {
        if let Some(t) = self.node_state[LiveTL].lock_surface.get() {
            format_object_link(buf, depth, t.client.id, t.id);
        }
    }

    fn read_color_description_live(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[LiveTL]
            .color_description
            .get()
            .str_fmt(buf, ctx);
    }

    fn read_color_description_render(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[RenderTL]
            .color_description
            .get()
            .str_fmt(buf, ctx);
    }

    fn read_linear_color_description_live(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[LiveTL]
            .linear_color_description
            .get()
            .str_fmt(buf, ctx);
    }

    fn read_linear_color_description_render(&self, buf: &mut String, ctx: &StrCtx<'_>) {
        self.node_state[RenderTL]
            .linear_color_description
            .get()
            .str_fmt(buf, ctx);
    }

    fn get_connector(self: &Rc<Self>, _key: u64) -> Option<FuseInodeWithKey> {
        self.global.connector.connector.clone().debugfs_link()
    }
}

struct Layers;

const LAYER_NAMES: [&str; 4] = ["background", "bottom", "top", "overlay"];

impl IterDirKeyedView<OutputNode> for Layers {
    type Value = OutputNode;
    type View = IterDir<Layer>;

    fn iter(t: Rc<OutputNode>, _key: u64, mut f: impl FnMut(&str, &Rc<Self::Value>, u64)) {
        for (idx, name) in LAYER_NAMES.into_iter().enumerate() {
            f(name, &t, idx as u64);
        }
    }

    fn get(t: Rc<OutputNode>, _key: u64, name: &str) -> Option<(Rc<Self::Value>, u64)> {
        let idx = LAYER_NAMES.iter().position(|n| *n == name)?;
        Some((t, idx as u64))
    }
}

struct Layer;

impl IterDirView<OutputNode> for Layer {
    type Value = ZwlrLayerSurfaceV1;
    type View = FuseLink<LayerLink>;

    fn iter(t: &OutputNode, key: u64, mut f: impl FnMut(&str, &Rc<Self::Value>)) {
        let mut buf = itoa::Buffer::new();
        for ls in t.layers[key as usize].iter_valid(LiveTL) {
            f(buf.format(ls.id.raw()), &ls.item);
        }
    }

    fn get(t: &OutputNode, key: u64, name: &str) -> Option<Rc<Self::Value>> {
        let id = u64::from_str(name).ok()?;
        for ls in t.layers[key as usize].iter_valid(LiveTL) {
            if ls.id.raw() == id {
                return Some(ls.item.clone());
            }
        }
        None
    }
}

struct LayerLink;

impl FuseLinkView<ZwlrLayerSurfaceV1> for LayerLink {
    fn readlink(t: &ZwlrLayerSurfaceV1, _key: u64, depth: u64, buf: &mut String) {
        format_object_link(buf, depth, t.client.id, t.id);
    }
}

struct TrayItems;

impl IterDirKeyedView<OutputNode> for TrayItems {
    type Value = OutputNode;
    type View = FuseLink<TrayItemLink>;

    fn iter(t: Rc<OutputNode>, _key: u64, mut f: impl FnMut(&str, &Rc<Self::Value>, u64)) {
        let mut buf = itoa::Buffer::new();
        for item in t.tray_items.iter_valid(LiveTL) {
            let id = item.data().tray_item_id.raw();
            f(buf.format(id), &t, id);
        }
    }

    fn get(t: Rc<OutputNode>, _key: u64, name: &str) -> Option<(Rc<Self::Value>, u64)> {
        let id = u64::from_str(name).ok()?;
        for item in t.tray_items.iter_valid(LiveTL) {
            if item.data().tray_item_id.raw() == id {
                return Some((t, id));
            }
        }
        None
    }
}

struct TrayItemLink;

impl FuseLinkView<OutputNode> for TrayItemLink {
    fn readlink(t: &OutputNode, key: u64, depth: u64, buf: &mut String) {
        for item in t.tray_items.iter_valid(LiveTL) {
            let data = item.data();
            if data.tray_item_id.raw() == key {
                format_object_link(buf, depth, data.surface.client.id, item.object_id());
                return;
            }
        }
    }
}

struct Workspaces;

impl IterDirView<OutputNode> for Workspaces {
    type Value = WorkspaceNode;
    type View = FuseLink<WorkspaceLink>;

    fn iter(t: &OutputNode, _key: u64, mut f: impl FnMut(&str, &Rc<Self::Value>)) {
        for node in t.workspaces.iter_valid(LiveTL) {
            let ws = &node.item;
            f(&ws.name, ws);
        }
    }

    fn get(t: &OutputNode, _key: u64, name: &str) -> Option<Rc<Self::Value>> {
        for node in t.workspaces.iter_valid(LiveTL) {
            if node.item.name.as_str() == name {
                return Some(node.item.clone());
            }
        }
        None
    }
}

struct WorkspaceLink;

impl FuseLinkView<WorkspaceNode> for WorkspaceLink {
    fn readlink(t: &WorkspaceNode, _key: u64, depth: u64, buf: &mut String) {
        format_path_link(buf, depth, "workspaces", &t.name);
    }
}

// FUSE GENERATED START
include!(concat!(
    env!("OUT_DIR"),
    "/fuse/m_47696bb92bcd93ee6ae08077363adbffe11c5b61751d95e1a6f27dc947e378df.rs",
));
// FUSE GENERATED STOP