gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data) { //puts(event->string); if (event->keyval == GDK_Escape)gtk_main_quit(); else { int i; for (i = 0; i < cmd_count(); i++) if (strlen(event->string) > 0 && strcmp(event->string, nth_command(i)->shortcut) == 0) break; if (i < cmd_count()) { run_command(nth_command(i)->command); gtk_main_quit(); } } return TRUE; }
ushort check_msg_args(char *cmd) { if (cmd_count(cmd) >= 1) if (strncmp(cmd, BROADCAST_SP, strlen(BROADCAST_SP)) == 0) return (0); return (1); }
ushort check_object_args(char *cmd) { if (cmd_count(cmd) == 1) if (strncmp(cmd, PREND_SP, strlen(PREND_SP)) == 0 || strncmp(cmd, POSE_SP, strlen(POSE_SP)) == 0) if (cmd_object_exists(cmd) == 0) return (0); return (1); }
int show_gui(int *argc, char ***argv) { gtk_init(argc, argv); init_attr_list(); GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(wnd), "AppLauncher"); g_signal_connect(wnd, "destroy", G_CALLBACK(destroy), 0); GtkTable *table = GTK_TABLE(gtk_table_new(cmd_count(), 2, FALSE)); gtk_container_add(GTK_CONTAINER(wnd), GTK_WIDGET(table)); labels = malloc(cmd_count() * sizeof (entry)); for (int i = 0; i < cmd_count(); i++) { create_labels(nth_command(i), labels + i); gtk_table_attach(table, labels[i].shortcut_label, 0, 1, i, i + 1, GTK_EXPAND, GTK_EXPAND, 2, 0); gtk_table_attach(table, labels[i].name_label, 1, 2, i, i + 1, GTK_EXPAND, GTK_EXPAND, 2, 0); } g_signal_connect(wnd, "key-press-event", G_CALLBACK(key_pressed), 0); gtk_window_position(GTK_WINDOW(wnd), GTK_WIN_POS_CENTER); gtk_widget_show_all(wnd); if (get_time() > 0) g_timeout_add_seconds(get_time(), timer_exit, 0); gtk_main(); free(labels); return 0; }
static int run_cmd(int argc, char **argv) { if (strncmp(argv[0], "help", 4) == 0) usage(stdout, 0); else if (strncmp(argv[0], "version", 8) == 0) { about(); return 0; } else if (strncmp(argv[0], "hate", 5) == 0) return cmd_hate(argc, argv); else if (strncmp(argv[0], "love", 5) == 0) return cmd_love(argc, argv); else if (strncmp(argv[0], "kill", 5) == 0) return cmd_kill(argc, argv); else if (strncmp(argv[0], "unkill", 7) == 0) return cmd_unkill(argc, argv); else if (strncmp(argv[0], "rate", 5) == 0) return cmd_rate(argc, argv); else if (strncmp(argv[0], "rateabs", 8) == 0) return cmd_rate_absolute(argc, argv); else if (strncmp(argv[0], "list", 5) == 0) return cmd_list(argc, argv); else if (strncmp(argv[0], "listinfo", 9) == 0) return cmd_listinfo(argc, argv); else if (strncmp(argv[0], "addtag", 7) == 0) return cmd_addtag(argc, argv); else if (strncmp(argv[0], "rmtag", 6) == 0) return cmd_rmtag(argc, argv); else if (strncmp(argv[0], "listtags", 9) == 0) return cmd_listtags(argc, argv); else if (strncmp(argv[0], "count", 6) == 0) return cmd_count(argc, argv); else if (strncmp(argv[0], "karma", 6) == 0) return cmd_karma(argc, argv); fprintf(stderr, "Unknown command `%s'\n", argv[0]); usage(stderr, 1); }