File: test-shortcut-tooltip.c

package info (click to toggle)
libdazzle 3.44.0-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,964 kB
  • sloc: ansic: 64,328; xml: 69; javascript: 19; makefile: 12
file content (89 lines) | stat: -rw-r--r-- 2,777 bytes parent folder | download | duplicates (4)
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
/* test-shortcut-tooltip.c
 *
 * Copyright 2018 Christian Hergert <chergert@redhat.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include <dazzle.h>

static const DzlShortcutEntry entries[] = {
  {
    "org.gnome.dazzle.test.fullscreen",
    DZL_SHORTCUT_PHASE_CAPTURE,
    "F11",
    "Window",
    "Management",
    "Fullscreen window",
    NULL
  }
};

static void
button_clicked_cb (GtkButton          *button,
                   DzlShortcutTooltip *tooltip)
{
  static guint count;

  count++;

  dzl_shortcut_tooltip_set_accel (tooltip, count % 2 ? "<Shift>F11" : "F11");
  dzl_shortcut_tooltip_set_title (tooltip, count % 2 ? "Unfullscreen window" : "Fullscreen window");
}

gint
main (gint argc,
      gchar *argv[])
{
  GtkWindow *window;
  GtkWidget *button;
  g_autoptr(DzlShortcutTooltip) tooltip = NULL;
  DzlShortcutController *controller;

  gtk_init (&argc, &argv);

  dzl_shortcut_manager_add_shortcut_entries (NULL, entries, G_N_ELEMENTS (entries), NULL);

  window = g_object_new (GTK_TYPE_WINDOW,
                         "title", "Shorcut tooltip test",
                         NULL);
  button = g_object_new (GTK_TYPE_BUTTON,
                         "visible", TRUE,
                         "label", "Test Button",
                         NULL);
  controller = dzl_shortcut_controller_find (button);
  dzl_shortcut_controller_add_command_action (controller,
                                              "org.gnome.dazzle.test.fullscreen",
                                              "F11",
                                              DZL_SHORTCUT_PHASE_CAPTURE,
                                              "win.fullscren");

  gtk_container_add (GTK_CONTAINER (window), button);

  tooltip = dzl_shortcut_tooltip_new ();

  dzl_shortcut_tooltip_set_widget (tooltip, button);
  dzl_shortcut_tooltip_set_command_id (tooltip, "org.gnome.dazzle.test.fullscreen");

  g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), tooltip);

  g_signal_connect (window, "delete-event", gtk_main_quit, NULL);
  gtk_window_present (GTK_WINDOW (window));

  gtk_main ();

  return 0;
}