aboutsummaryrefslogtreecommitdiffstats
path: root/fb
diff options
context:
space:
mode:
Diffstat (limited to 'fb')
-rw-r--r--fb/fbmenu.c169
1 files changed, 169 insertions, 0 deletions
diff --git a/fb/fbmenu.c b/fb/fbmenu.c
new file mode 100644
index 0000000..855a906
--- /dev/null
+++ b/fb/fbmenu.c
@@ -0,0 +1,169 @@
+#include <gtk/gtk.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <getopt.h>
+#include <sys/ioctl.h>
+#include <linux/fb.h>
+
+int fd;
+static int fb;
+struct fb_var_screeninfo fb_var;
+static GtkWidget *window = NULL;
+char *deflt;
+
+void usage() {
+ printf("\nUsage:\n\n\tfbmenu <timeout in second> <menu title> <menu entry 1> <menu entry 2> ... <menu entry n>\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", 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 (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 (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;
+}
+