File: 3buttons.c

package info (click to toggle)
libpanel 1.10.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,956 kB
  • sloc: ansic: 19,093; xml: 39; sh: 24; javascript: 13; makefile: 10
file content (43 lines) | stat: -rw-r--r-- 1,243 bytes parent folder | download | duplicates (2)
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
/* Repurposed test-paned.c for autopkgtest
 * Creates a penel with 3 buttons.
 * Clicking a button causes it to disappear.
 * When no buttons are left, quit normally.
 * Author: Nathan Pratta Teodosio <nathan.teodosio@canonical.com>
 */
#include <libpanel.h>
#include <gtk/gtk.h>
GMainLoop *main_loop;
char *argv0 = NULL;

static void removebutton(GtkButton *b, gpointer user_data) {
  PanelPaned *p = (PanelPaned *)user_data;
  panel_paned_remove(p, GTK_WIDGET(b));
  g_print("%s: A button was removed from the panel.\n", argv0);
  if (panel_paned_get_n_children(p) == 0) {
    g_print("%s: No buttons left. Exiting.\n", argv0);
    g_main_loop_quit(main_loop);
  }
}

int main(int argc, char *argv[]) {
  argv0 = argv[0];
  GtkWidget *window;
  GtkWidget *paned;

  gtk_init();
  panel_init();

  main_loop = g_main_loop_new(NULL, FALSE);
  window = gtk_window_new();
  paned = panel_paned_new();
  gtk_window_set_child(GTK_WINDOW(window), paned);

  for (guint i = 0; i < 3; i++) {
    GtkWidget *button = gtk_button_new();
    panel_paned_append(PANEL_PANED(paned), button);
    g_signal_connect(button, "clicked", G_CALLBACK(removebutton), paned);
  }
  gtk_window_present(GTK_WINDOW(window));
  g_main_loop_run(main_loop);
  return 0;
}