#include #include #include #include #include #include #include #include #include #include #include #include int fd; static int fb; struct fb_var_screeninfo fb_var; static GtkWidget *window = NULL; char *deflt; void usage() { printf("\nUsage:\n\n\tfbmenu ... \n\n"); exit(1); } void message_dialog_clicked (GtkButton *button, gpointer user_data) { g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window); gtk_widget_destroy (window); printf("\nRESULT=\"%s\"\n", (char *) user_data); exit(0); } static GtkWidget * create_bbox (gint horizontal, char *title, gint spacing, gint layout, int argc, char **argv) { GtkWidget *frame; GtkWidget *bbox; GtkWidget *button; int i; frame = gtk_frame_new (title); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); if (horizontal) bbox = gtk_hbutton_box_new (); else bbox = gtk_vbutton_box_new (); gtk_container_set_border_width (GTK_CONTAINER (bbox), 5); gtk_container_add (GTK_CONTAINER (frame), bbox); gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout); gtk_box_set_spacing (GTK_BOX (bbox), spacing); for (i = 0; i < argc; i++) { button = gtk_button_new_with_mnemonic (argv[i]); g_signal_connect (button, "clicked", G_CALLBACK (message_dialog_clicked), argv[i]); gtk_container_add (GTK_CONTAINER (bbox), button); } return frame; } GtkWidget * do_button_box (GtkWidget *do_widget, int argc, char** argv) { static GtkWidget *window = NULL; GtkWidget *main_vbox; GtkWidget *eventbox; GtkWidget *hbox; int x,y; if (!window) { if (-1 == ioctl(fb,FBIOGET_VSCREENINFO,&fb_var)) { x = 800; y = 600; } else { x = fb_var.xres; y = fb_var.yres; } window = gtk_window_new (GTK_WINDOW_POPUP); gtk_window_set_screen (GTK_WINDOW (window), gtk_widget_get_screen (do_widget)); gtk_window_set_title (GTK_WINDOW (window), argv[0]); gtk_window_resize(GTK_WINDOW(window), x, y); //gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window); gtk_container_set_border_width (GTK_CONTAINER (window), 10); main_vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (window), main_vbox); hbox = gtk_hbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); gtk_box_pack_start (GTK_BOX (main_vbox), hbox, TRUE, FALSE, 5); eventbox = gtk_event_box_new (); gtk_event_box_set_visible_window (GTK_EVENT_BOX (eventbox), TRUE); gtk_box_pack_start (GTK_BOX (hbox), eventbox, TRUE, FALSE, 5); gtk_container_add (GTK_CONTAINER (eventbox), create_bbox (FALSE, argv[0], 30, GTK_BUTTONBOX_START, argc - 1, argv + 1)); } if (!GTK_WIDGET_VISIBLE (window)) { gtk_widget_show_all (window); } else { gtk_widget_destroy (window); window = NULL; } return window; } void return_default(int x) { printf("\nRESULT=\"%s\"\n", deflt); exit(0); } int main(int argc, char **argv) { int i; int shift = 2; int title = 2; if (argc < 4) { usage(); } if (argc == 4) { printf("\nRESULT=\"%s\"\n", argv[3]); exit(0); } deflt = argv[3]; if (-1 == open("/dev/fb0",O_RDWR) && getenv("DISPLAY") == NULL) { signal(SIGALRM, return_default); alarm(atoi(argv[1])); do { fprintf(stderr,"\n"); for (i = 1; i < argc - shift; i++) { fprintf(stderr,"%d - %s\n", i, argv[i + shift]); } fprintf(stderr,"\n%s: ", argv[title]); if (!scanf("%d", &i)) scanf("%*s"); } while (i < 1 || i >= (argc - shift)); printf("\nRESULT=\"%s\"\n", argv[i + shift]); } else { gtk_init (&argc, &argv); do_button_box(window, argc - shift, argv + shift); g_timeout_add(atoi(argv[1]) * 1000, return_default, NULL); gtk_main (); } return 0; }