File: layer-selection.c

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

const char *layer_strs[] = {"Overlay", "Top", "Bottom", "Background", NULL};
GtkLayerShellLayer layer_vals[] = {
    GTK_LAYER_SHELL_LAYER_OVERLAY,
    GTK_LAYER_SHELL_LAYER_TOP,
    GTK_LAYER_SHELL_LAYER_BOTTOM,
    GTK_LAYER_SHELL_LAYER_BACKGROUND};

static void
on_layer_selected(GtkDropDown *dropdown, const GParamSpec *_pspec, GtkWindow *layer_window)
{
    (void)_pspec;
    guint index = gtk_drop_down_get_selected (dropdown);
    gtk_layer_set_layer (layer_window, layer_vals[index]);
}

GtkWidget *
layer_selection_new (GtkWindow *layer_window, GtkLayerShellLayer default_layer)
{
    GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
    {
        GtkWidget *dropdown = gtk_drop_down_new_from_strings(layer_strs);
        gtk_widget_set_tooltip_text (dropdown, "Layer");
        for (unsigned i = 0; i < sizeof(layer_vals) / sizeof(layer_vals[0]); i++) {
            if (layer_vals[i] == default_layer)
                gtk_drop_down_set_selected (GTK_DROP_DOWN (dropdown), i);
        }
        g_signal_connect (dropdown, "notify::selected", G_CALLBACK (on_layer_selected), layer_window);
        gtk_box_append (GTK_BOX (vbox), dropdown);
    }
    return vbox;
}