File: mscl-toggles.c

package info (click to toggle)
gtk4-layer-shell 1.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 616 kB
  • sloc: ansic: 3,537; xml: 417; python: 333; makefile: 9
file content (67 lines) | stat: -rw-r--r-- 2,416 bytes parent folder | download
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
#include "gtk-layer-demo.h"

gboolean
on_exclusive_zone_state_set (GtkToggleButton *_toggle_button, gboolean state, GtkWindow *layer_window)
{
    (void)_toggle_button;

    if (state) {
        gtk_layer_auto_exclusive_zone_enable (layer_window);
    } else {
        gtk_layer_set_exclusive_zone (layer_window, 0);
    }
    return FALSE;
}

gboolean
on_fixed_size_set (GtkToggleButton *_toggle_button, gboolean state, GtkWindow *layer_window)
{
    (void)_toggle_button;

    if (state) {
        gtk_window_set_default_size (layer_window, fixed_size_width, fixed_size_height);
    } else {
        gtk_window_set_default_size (layer_window, 0, 0);
    }
    return FALSE;
}

struct {
    const char *name;
    const char *tooltip;
    gboolean (*callback) (GtkToggleButton *toggle_button, gboolean state, GtkWindow *layer_window);
} const mscl_toggles[] = {
    {"Exclusive", "Create an exclusive zone when anchored", on_exclusive_zone_state_set},
    {"Fixed size", "Set a fixed window size (ignored depending on anchors)", on_fixed_size_set},
};

GtkWidget *
mscl_toggles_new (GtkWindow *layer_window,
                  gboolean default_auto_exclusive_zone,
                  gboolean default_fixed_size)
{
    GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
    for (unsigned i = 0; i < sizeof (mscl_toggles) / sizeof (mscl_toggles[0]); i++) {
        GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
        gtk_widget_set_halign (hbox, GTK_ALIGN_END);
        gtk_box_append (GTK_BOX (vbox), hbox);
        {
            GtkWidget *label = gtk_label_new (mscl_toggles[i].name);
            gtk_box_append (GTK_BOX (hbox), label);
        }{
            GtkWidget *toggle = gtk_switch_new ();
            gtk_widget_set_tooltip_text (toggle, mscl_toggles[i].tooltip);
            gboolean default_value;
            if (mscl_toggles[i].callback == on_exclusive_zone_state_set)
                default_value = default_auto_exclusive_zone;
            else if (mscl_toggles[i].callback == on_fixed_size_set)
                default_value = default_fixed_size;
            else
                g_assert_not_reached ();
            gtk_switch_set_active (GTK_SWITCH (toggle), default_value);
            g_signal_connect (toggle, "state-set", G_CALLBACK (mscl_toggles[i].callback), layer_window);
            gtk_box_append (GTK_BOX (hbox), toggle);
        }
    }
    return vbox;
}