jay-config 1.13.0

Configuration crate for the Jay compositor
Documentation
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
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
//! Tools for configuring the look of the compositor.

use crate::_private::WindowThemeKind;
use crate::theme::colors::Colorable;
use crate::theme::sized::Resizable;
use crate::window::Window;
use jay_proc::PrivateEnum;
use serde::Deserialize;
use serde::Serialize;
use std::ops::Deref;

/// A color.
///
/// When specifying RGBA values of a color, the RGB values can either be specified
/// *straight* or *premultiplied*. Premultiplied means that the RGB values have already
/// been multiplied by the alpha value.
///
/// Given a color, to reduce its opacity by half,
///
/// - if you're working with premultiplied values, you would multiply each component by `0.5`;
/// - if you're working with straight values, you would multiply only the alpha component by `0.5`.
///
/// When using hexadecimal notation, `#RRGGBBAA`, the RGB values are usually straight.
// values are stored premultiplied
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub struct Color {
    r: f32,
    g: f32,
    b: f32,
    a: f32,
}

fn to_f32(c: u8) -> f32 {
    c as f32 / 255f32
}

fn to_u8(c: f32) -> u8 {
    (c * 255f32) as u8
}

fn validate_f32(f: f32) -> bool {
    f >= 0.0 && f <= 1.0
}

fn validate_f32_all(f: [f32; 4]) -> bool {
    if !f.into_iter().all(validate_f32) {
        log::warn!(
            "f32 values {:?} are not in the valid color range. Using solid black instead xyz",
            f
        );
        return false;
    }
    true
}

impl Color {
    /// Solid black.
    pub const BLACK: Self = Self {
        r: 0.0,
        g: 0.0,
        b: 0.0,
        a: 1.0,
    };

    /// Creates a new color from `u8` RGB values.
    pub fn new(r: u8, g: u8, b: u8) -> Self {
        Self {
            r: to_f32(r),
            g: to_f32(g),
            b: to_f32(b),
            a: 1.0,
        }
    }

    /// Creates a new color from straight `u8` RGBA values.
    pub fn new_straight(r: u8, g: u8, b: u8, a: u8) -> Self {
        Self::new_f32_straight(to_f32(r), to_f32(g), to_f32(b), to_f32(a))
    }

    /// Creates a new color from premultiplied `f32` RGBA values.
    pub fn new_f32_premultiplied(r: f32, g: f32, b: f32, a: f32) -> Self {
        if !validate_f32_all([r, g, b, a]) {
            Self::BLACK
        } else if r > a || g > a || b > a {
            log::warn!(
                "f32 values {:?} are not valid for a premultiplied color. Using solid black instead.",
                [r, g, b, a]
            );
            Self::BLACK
        } else {
            Self { r, g, b, a }
        }
    }

    /// Creates a new color from straight `f32` RGBA values.
    pub fn new_f32_straight(r: f32, g: f32, b: f32, a: f32) -> Self {
        if !validate_f32_all([r, g, b, a]) {
            Self::BLACK
        } else {
            Self {
                r: r * a,
                g: g * a,
                b: b * a,
                a,
            }
        }
    }

    /// Creates a new color from `f32` RGB values.
    pub fn new_f32(r: f32, g: f32, b: f32) -> Self {
        Self { r, g, b, a: 1.0 }
    }

    /// Converts the color to its premultiplied `f32` RGBA values.
    pub fn to_f32_premultiplied(&self) -> [f32; 4] {
        [self.r, self.g, self.b, self.a]
    }

    /// Converts the color to its straight `f32` RGBA values.
    pub fn to_f32_straight(&self) -> [f32; 4] {
        if self.a == 0.0 {
            [0.0, 0.0, 0.0, 0.0]
        } else {
            let a = self.a;
            [self.r / a, self.g / a, self.b / a, a]
        }
    }

    /// Converts the color to its straight `u8` RGBA values.
    pub fn to_u8_straight(&self) -> [u8; 4] {
        let [r, g, b, a] = self.to_f32_straight();
        [to_u8(r), to_u8(g), to_u8(b), to_u8(a)]
    }
}

/// Resets all sizes to their defaults.
pub fn reset_sizes() {
    get!().reset_sizes();
}

/// Resets all colors to their defaults.
pub fn reset_colors() {
    get!().reset_colors();
}

/// Returns the current font.
pub fn get_font() -> String {
    get!().get_font()
}

/// Sets the font.
///
/// Default: `monospace 8`.
///
/// See also [`set_bar_font`] and [`set_title_font`].
///
/// The font name should be specified in [pango][pango] syntax.
///
/// [pango]: https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html
pub fn set_font(font: &str) {
    get!().set_font(font)
}

/// Sets the font used by the bar.
///
/// If this function is not called, the font set by [`set_font`] is used. See that
/// function for more details.
pub fn set_bar_font(font: &str) {
    get!().set_bar_font(font)
}

/// Sets the font used by window titles.
///
/// If this function is not called, the font set by [`set_font`] is used. See that
/// function for more details.
pub fn set_title_font(font: &str) {
    get!().set_title_font(font)
}

/// Resets the fonts to the defaults.
///
/// Currently the default is `monospace 8`.
pub fn reset_font() {
    get!().reset_font()
}

#[non_exhaustive]
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Default, PrivateEnum)]
pub enum BarPosition {
    #[default]
    Top,
    Bottom,
}

/// Sets the position of the bar.
///
/// Default: `Top`.
pub fn set_bar_position(position: BarPosition) {
    get!().set_bar_position(position.to_private());
}

/// Gets the position of the bar.
pub fn get_bar_position() -> BarPosition {
    get!(BarPosition::Top).get_bar_position().to_public()
}

#[non_exhaustive]
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Default, PrivateEnum)]
pub enum ContainerBorders {
    /// Only separators are drawn between children.
    #[default]
    Separators,
    /// A border is drawn around the entire container.
    Full,
    /// A border is drawn around the entire container, in addition to the separators
    /// between children, unless the container has only one child and is the root
    /// container of the workspace.
    FullSmart,
}

/// Sets the container border style.
///
/// Default: `Separators`.
pub fn set_container_borders(borders: ContainerBorders) {
    get!().set_container_borders(borders.to_private());
}

/// Gets the container border style.
pub fn get_container_borders() -> ContainerBorders {
    get!(ContainerBorders::Separators)
        .get_container_borders()
        .to_public()
}

/// Sets the proportional fonts used by egui windows.
///
/// The default is `["sans-serif", "Noto Sans", "Noto Color Emoji"]`.
pub fn set_egui_proportional_fonts<'a>(fonts: impl IntoIterator<Item = &'a str>) {
    get!().set_egui_fonts(Some(fonts.into_iter().collect()), None);
}

/// Sets the monospace fonts used by egui windows.
///
/// The default is `["monospace", "Noto Sans Mono", "Noto Color Emoji"]`.
pub fn set_egui_monospace_fonts<'a>(fonts: impl IntoIterator<Item = &'a str>) {
    get!().set_egui_fonts(None, Some(fonts.into_iter().collect()));
}

/// Sets whether window icons set by the client are shown.
///
/// The default is `true`.
pub fn set_show_window_icons(show: bool) {
    get!().set_show_window_icons(show);
}

/// Sets whether window icons set by the client are rendered as grayscale.
///
/// This is only supported on the Vulkan renderer.
///
/// The default is `false`.
pub fn set_window_icons_grayscale(grayscale: bool) {
    get!().set_window_icons_grayscale(grayscale);
}

/// Theme overrides of a window or container.
///
/// This type implements the functionality shared by [`WindowTheme`] and
/// [`ContainerTheme`]. Both dereference to this type. See their documentation for the
/// supported settings.
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct ThemeOverrides {
    pub(crate) window: Window,
    pub(crate) kind: WindowThemeKind,
}

impl ThemeOverrides {
    /// Returns the window that the overrides belong to.
    pub fn window(&self) -> Window {
        self.window
    }

    /// Removes all overrides.
    pub fn reset(&self) {
        get!().reset_window_theme(self.window, self.kind);
    }

    /// Sets the color of a GUI element.
    pub fn set_color(&self, element: Colorable, color: Color) {
        get!().set_window_theme_color(self.window, self.kind, element, Some(color));
    }

    /// Removes the color override of a GUI element.
    ///
    /// See also [`set_color`](Self::set_color).
    pub fn unset_color(&self, element: Colorable) {
        get!().set_window_theme_color(self.window, self.kind, element, None);
    }

    /// Gets the color override of a GUI element.
    pub fn get_color(&self, element: Colorable) -> Option<Color> {
        get!().get_window_theme_color(self.window, self.kind, element)
    }

    /// Sets the size of a GUI element.
    pub fn set_size(&self, element: Resizable, size: i32) {
        get!().set_window_theme_size(self.window, self.kind, element, Some(size));
    }

    /// Removes the size override of a GUI element.
    ///
    /// See also [`set_size`](Self::set_size).
    pub fn unset_size(&self, element: Resizable) {
        get!().set_window_theme_size(self.window, self.kind, element, None);
    }

    /// Gets the size override of a GUI element.
    pub fn get_size(&self, element: Resizable) -> Option<i32> {
        get!().get_window_theme_size(self.window, self.kind, element)
    }

    /// Sets whether titles are shown.
    ///
    /// See also [`set_show_titles`](crate::set_show_titles).
    pub fn set_show_titles(&self, show: bool) {
        get!().set_window_theme_show_titles(self.window, self.kind, Some(show));
    }

    /// Removes the override of whether titles are shown.
    ///
    /// See also [`set_show_titles`](Self::set_show_titles).
    pub fn unset_show_titles(&self) {
        get!().set_window_theme_show_titles(self.window, self.kind, None);
    }

    /// Gets the override of whether titles are shown.
    pub fn get_show_titles(&self) -> Option<bool> {
        get!().get_window_theme_show_titles(self.window, self.kind)
    }

    /// Sets whether window icons set by the client are shown.
    ///
    /// See also [`set_show_window_icons`].
    pub fn set_show_window_icons(&self, show: bool) {
        get!().set_window_theme_show_window_icons(self.window, self.kind, Some(show));
    }

    /// Removes the override of whether window icons set by the client are shown.
    ///
    /// See also [`set_show_window_icons`](Self::set_show_window_icons).
    pub fn unset_show_window_icons(&self) {
        get!().set_window_theme_show_window_icons(self.window, self.kind, None);
    }

    /// Sets whether window icons set by the client are rendered as grayscale.
    ///
    /// See also [`set_window_icons_grayscale`].
    pub fn set_window_icons_grayscale(&self, grayscale: bool) {
        get!().set_window_theme_window_icons_grayscale(self.window, self.kind, Some(grayscale));
    }

    /// Removes the override of whether window icons set by the client are rendered as
    /// grayscale.
    ///
    /// See also [`set_window_icons_grayscale`](Self::set_window_icons_grayscale).
    pub fn unset_window_icons_grayscale(&self) {
        get!().set_window_theme_window_icons_grayscale(self.window, self.kind, None);
    }

    /// Sets the font used by window titles.
    ///
    /// See also [`set_title_font`].
    pub fn set_title_font(&self, font: &str) {
        get!().set_window_theme_title_font(self.window, self.kind, Some(font));
    }

    /// Removes the override of the font used by window titles.
    ///
    /// See also [`set_title_font`](Self::set_title_font).
    pub fn unset_title_font(&self) {
        get!().set_window_theme_title_font(self.window, self.kind, None);
    }
}

/// Theme overrides of a window.
///
/// This object is returned by [`Window::theme`]. It contains the theme of the window
/// itself. How a container decorates its children is configured with
/// [`ContainerTheme`].
///
/// Settings that are not set fall back to the theme of the parent container, if any, and
/// then to the global theme. Not every setting has an effect on every window.
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct WindowTheme(pub(crate) ThemeOverrides);

impl Deref for WindowTheme {
    type Target = ThemeOverrides;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

const _: () = {
    use colors::*;
    use sized::*;

    impl WindowTheme {
        /// Sets the color of a GUI element.
        ///
        /// Floating windows use the following elements. This theme takes priority over the
        /// global theme.
        ///
        /// - [`BORDER_COLOR`]
        /// - [`FOCUSED_BORDER_COLOR`]
        /// - [`SEPARATOR_COLOR`]
        /// - [`UNFOCUSED_TITLE_BACKGROUND_COLOR`]
        /// - [`FOCUSED_TITLE_BACKGROUND_COLOR`]
        /// - [`ATTENTION_REQUESTED_BACKGROUND_COLOR`]
        /// - [`UNFOCUSED_TITLE_TEXT_COLOR`]
        /// - [`FOCUSED_TITLE_TEXT_COLOR`]
        ///
        /// Tiled windows use the following elements. This theme takes priority over the
        /// [`ContainerTheme`] of the parent container, which takes priority over the global
        /// theme.
        ///
        /// - [`FOCUSED_BORDER_COLOR`]
        /// - [`BORDER_COLOR`]: only used as the default of `FOCUSED_BORDER_COLOR`. The
        ///   other borders use the border color of the container.
        /// - [`UNFOCUSED_TITLE_BACKGROUND_COLOR`]
        /// - [`FOCUSED_TITLE_BACKGROUND_COLOR`]
        /// - [`FOCUSED_INACTIVE_TITLE_BACKGROUND_COLOR`]
        /// - [`ATTENTION_REQUESTED_BACKGROUND_COLOR`]
        /// - [`UNFOCUSED_TITLE_TEXT_COLOR`]
        /// - [`FOCUSED_TITLE_TEXT_COLOR`]
        /// - [`FOCUSED_INACTIVE_TITLE_TEXT_COLOR`]
        ///
        /// For tiled windows, the separator color is a property of the container and is set
        /// with [`ContainerTheme::set_color`].
        pub fn set_color(&self, element: Colorable, color: Color) {
            self.0.set_color(element, color)
        }

        /// Sets the size of a GUI element.
        ///
        /// The following elements are supported:
        ///
        /// - [`TITLE_HEIGHT`]
        /// - [`BORDER_WIDTH`]
        ///
        /// They are only used for floating windows. This theme takes priority over the
        /// global theme. For tiled windows, these sizes are properties of the container and
        /// are set with [`ContainerTheme::set_size`].
        pub fn set_size(&self, element: Resizable, size: i32) {
            self.0.set_size(element, size)
        }

        /// Sets whether titles are shown.
        ///
        /// This is only used for floating windows. This theme takes priority over the global
        /// theme. For tiled windows, this is a property of the container and is set with
        /// [`ContainerTheme::set_show_titles`].
        ///
        /// See also [`set_show_titles`](crate::set_show_titles).
        pub fn set_show_titles(&self, show: bool) {
            self.0.set_show_titles(show)
        }

        /// Sets whether window icons set by the client are shown.
        ///
        /// For floating windows, this theme takes priority over the global theme. For tiled
        /// windows, this theme takes priority over the [`ContainerTheme`] of the parent
        /// container, which takes priority over the global theme.
        ///
        /// See also [`set_show_window_icons`].
        pub fn set_show_window_icons(&self, show: bool) {
            self.0.set_show_window_icons(show)
        }

        /// Sets whether window icons set by the client are rendered as grayscale.
        ///
        /// For floating windows, this theme takes priority over the global theme. For tiled
        /// windows, this theme takes priority over the [`ContainerTheme`] of the parent
        /// container, which takes priority over the global theme.
        ///
        /// See also [`set_window_icons_grayscale`].
        pub fn set_window_icons_grayscale(&self, grayscale: bool) {
            self.0.set_window_icons_grayscale(grayscale)
        }

        /// Sets the font used by window titles.
        ///
        /// For floating windows, this theme takes priority over the global theme. For tiled
        /// windows, this theme takes priority over the [`ContainerTheme`] of the parent
        /// container, which takes priority over the global theme.
        ///
        /// See also [`set_title_font`].
        pub fn set_title_font(&self, font: &str) {
            self.0.set_title_font(font)
        }
    }
};

/// Theme overrides of how a container decorates its children.
///
/// This object is returned by [`Window::container_theme`]. It has no effect if the
/// window is not a container.
///
/// Settings that are not set fall back to the global theme. Not every setting has an
/// effect on every container.
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct ContainerTheme(pub(crate) ThemeOverrides);

impl Deref for ContainerTheme {
    type Target = ThemeOverrides;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

const _: () = {
    use colors::*;
    use sized::*;

    impl ContainerTheme {
        /// Sets the color of a GUI element.
        ///
        /// The following elements apply to the container as a whole. This theme takes
        /// priority over the global theme.
        ///
        /// - [`BORDER_COLOR`]
        /// - [`SEPARATOR_COLOR`]
        ///
        /// The following elements apply to the decorations of each child. The
        /// [`WindowTheme`] of the child takes priority over this theme, which takes priority
        /// over the global theme.
        ///
        /// - [`FOCUSED_BORDER_COLOR`]
        /// - [`BORDER_COLOR`]: only used as the default of `FOCUSED_BORDER_COLOR`.
        /// - [`UNFOCUSED_TITLE_BACKGROUND_COLOR`]
        /// - [`FOCUSED_TITLE_BACKGROUND_COLOR`]
        /// - [`FOCUSED_INACTIVE_TITLE_BACKGROUND_COLOR`]
        /// - [`ATTENTION_REQUESTED_BACKGROUND_COLOR`]
        /// - [`UNFOCUSED_TITLE_TEXT_COLOR`]
        /// - [`FOCUSED_TITLE_TEXT_COLOR`]
        /// - [`FOCUSED_INACTIVE_TITLE_TEXT_COLOR`]
        pub fn set_color(&self, element: Colorable, color: Color) {
            self.0.set_color(element, color)
        }

        /// Sets the size of a GUI element.
        ///
        /// The following elements are supported:
        ///
        /// - [`TITLE_HEIGHT`]
        /// - [`BORDER_WIDTH`]
        ///
        /// They apply to the container as a whole. This theme takes priority over the global
        /// theme.
        pub fn set_size(&self, element: Resizable, size: i32) {
            self.0.set_size(element, size)
        }

        /// Sets whether titles are shown.
        ///
        /// This applies to the container as a whole. This theme takes priority over the
        /// global theme.
        ///
        /// See also [`set_show_titles`](crate::set_show_titles).
        pub fn set_show_titles(&self, show: bool) {
            self.0.set_show_titles(show)
        }

        /// Sets whether window icons set by the client are shown.
        ///
        /// This applies to the decorations of each child. The [`WindowTheme`] of the child
        /// takes priority over this theme, which takes priority over the global theme.
        ///
        /// See also [`set_show_window_icons`].
        pub fn set_show_window_icons(&self, show: bool) {
            self.0.set_show_window_icons(show)
        }

        /// Sets whether window icons set by the client are rendered as grayscale.
        ///
        /// This applies to the decorations of each child. The [`WindowTheme`] of the child
        /// takes priority over this theme, which takes priority over the global theme.
        ///
        /// See also [`set_window_icons_grayscale`].
        pub fn set_window_icons_grayscale(&self, grayscale: bool) {
            self.0.set_window_icons_grayscale(grayscale)
        }

        /// Sets the font used by window titles.
        ///
        /// This applies to the decorations of each child. The [`WindowTheme`] of the child
        /// takes priority over this theme, which takes priority over the global theme.
        ///
        /// See also [`set_title_font`].
        pub fn set_title_font(&self, font: &str) {
            self.0.set_title_font(font)
        }

        /// Sets the container border style.
        ///
        /// This theme takes priority over the global theme.
        ///
        /// See also [`set_container_borders`].
        pub fn set_container_borders(&self, borders: ContainerBorders) {
            get!().set_window_theme_container_borders(
                self.0.window,
                self.0.kind,
                Some(borders.to_private()),
            );
        }

        /// Removes the override of the container border style.
        ///
        /// See also [`set_container_borders`](Self::set_container_borders).
        pub fn unset_container_borders(&self) {
            get!().set_window_theme_container_borders(self.0.window, self.0.kind, None);
        }

        /// Gets the override of the container border style.
        pub fn get_container_borders(&self) -> Option<ContainerBorders> {
            get!(None)
                .get_window_theme_container_borders(self.0.window, self.0.kind)
                .map(|v| v.to_public())
        }
    }
};

/// Elements of the compositor whose color can be changed.
pub mod colors {
    #![allow(unused_imports)]
    use crate::theme::Color;
    use crate::theme::ContainerBorders;
    use serde::Deserialize;
    use serde::Serialize;

    /// An element of the GUI whose color can be changed.
    #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
    pub struct Colorable(#[doc(hidden)] pub u32);

    impl Colorable {
        /// Sets the color to an RGB value.
        pub fn set(self, r: u8, g: u8, b: u8) {
            let color = Color::new(r, g, b);
            get!().set_color(self, color);
        }

        /// Sets the color to a `Color` that might contain an alpha component.
        pub fn set_color(self, color: Color) {
            get!().set_color(self, color);
        }

        /// Gets the current color.
        pub fn get(self) -> Color {
            get!(Color::BLACK).get_color(self)
        }
    }

    macro_rules! colors {
        ($($(#[$attr:meta])* const $n:expr => $name:ident,)*) => {
            $(
                $(#[$attr])*
                pub const $name: Colorable = Colorable($n);
            )*
        }
    }

    colors! {
        /// The title background color of an unfocused window.
        ///
        /// Default: `#222222`.
        const 01 => UNFOCUSED_TITLE_BACKGROUND_COLOR,
        /// The title background color of a focused window.
        ///
        /// Default: `#285577`.
        const 02 => FOCUSED_TITLE_BACKGROUND_COLOR,
        /// The title background color of an unfocused window that was the last focused
        /// window in its container.
        ///
        /// Default: `#5f676a`.
        const 03 => FOCUSED_INACTIVE_TITLE_BACKGROUND_COLOR,
        /// The background color of the desktop.
        ///
        /// Default: `#001019`.
        ///
        /// You can use an application such as [swaybg][swaybg] to further customize the background.
        ///
        /// [swaybg]: https://github.com/swaywm/swaybg
        const 04 => BACKGROUND_COLOR,
        /// The background color of the bar.
        ///
        /// Default: `#000000`.
        const 05 => BAR_BACKGROUND_COLOR,
        /// The color of the 1px separator below window titles.
        ///
        /// Default: `#333333`.
        const 06 => SEPARATOR_COLOR,
        /// The color of the border between windows.
        ///
        /// Default: `#3f474a`.
        const 07 => BORDER_COLOR,
        /// The title text color of an unfocused window.
        ///
        /// Default: `#888888`.
        const 08 => UNFOCUSED_TITLE_TEXT_COLOR,
        /// The title text color of a focused window.
        ///
        /// Default: `#ffffff`.
        const 09 => FOCUSED_TITLE_TEXT_COLOR,
        /// The title text color of an unfocused window that was the last focused
        /// window in its container.
        ///
        /// Default: `#ffffff`.
        const 10 => FOCUSED_INACTIVE_TITLE_TEXT_COLOR,
        /// The color of the status text in the bar.
        ///
        /// Default: `#ffffff`.
        const 11 => BAR_STATUS_TEXT_COLOR,
        /// The title background color of an unfocused window that might be captured.
        ///
        /// Default: `#220303`.
        const 12 => CAPTURED_UNFOCUSED_TITLE_BACKGROUND_COLOR,
        /// The title background color of a focused window that might be captured.
        ///
        /// Default: `#772831`.
        const 13 => CAPTURED_FOCUSED_TITLE_BACKGROUND_COLOR,
        /// The title background color of a window that has requested attention.
        ///
        /// Default: `#23092c`.
        const 14 => ATTENTION_REQUESTED_BACKGROUND_COLOR,
        /// Color used to highlight parts of the UI.
        ///
        /// Default: `#9d28c67f`.
        const 15 => HIGHLIGHT_COLOR,
        /// The color of the border between windows where at least one of the windows is
        /// focused.
        ///
        /// For containers, this requires `Full` [`ContainerBorders`].
        ///
        /// Default: The `BORDER` color.
        const 16 => FOCUSED_BORDER_COLOR,
    }

    /// Sets the color of GUI element.
    pub fn set_color(element: Colorable, color: Color) {
        get!().set_color(element, color);
    }

    /// Gets the color of GUI element.
    pub fn get_color(element: Colorable) -> Color {
        get!(Color::BLACK).get_color(element)
    }
}

/// Elements of the compositor whose size can be changed.
pub mod sized {
    use serde::Deserialize;
    use serde::Serialize;

    /// An element of the GUI whose size can be changed.
    #[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
    pub struct Resizable(#[doc(hidden)] pub u32);

    impl Resizable {
        /// Gets the current size.
        pub fn get(self) -> i32 {
            get!(0).get_size(self)
        }

        /// Sets the size.
        pub fn set(self, size: i32) {
            get!().set_size(self, size)
        }
    }

    macro_rules! sizes {
        ($($(#[$attr:meta])* const $n:expr => $name:ident,)*) => {
            $(
                $(#[$attr])*
                pub const $name: Resizable = Resizable($n);
            )*
        }
    }

    sizes! {
        /// The height of window titles.
        ///
        /// Default: 17
        const 01 => TITLE_HEIGHT,
        /// The width of borders between windows.
        ///
        /// Default: 4
        const 02 => BORDER_WIDTH,
        /// The height of the bar.
        ///
        /// Defaults to the TITLE_HEIGHT if not set explicitly.
        ///
        /// Default: 17
        const 03 => BAR_HEIGHT,
        /// The width of the bar's separator.
        ///
        /// Default: 1
        const 04 => BAR_SEPARATOR_WIDTH,
    }
}