/** * Do needed steps to start showing the gui */ static int setup () { // Create pid file int pfd = create_pid_file ( pidfile ); if ( pfd >= 0 ) { // Request truecolor visual. x11_create_visual_and_colormap ( ); textbox_setup (); } return pfd; }
int main (int argc, char *argv[]) { GtkWidget *label; GdkPixbuf *icon_pixbuf; GError *err = NULL; bindtextdomain(PACKAGE, LOCALEDIR); bind_textdomain_codeset(PACKAGE, "UTF-8"); textdomain(PACKAGE); srand (time(NULL)); gnome_program_init (APPID, APPVERSION, LIBGNOMEUI_MODULE, argc, argv, GNOME_PARAM_POPT_TABLE, options, GNOME_PARAM_NONE); textbox_setup (); /* needs to be done before text boxes are created */ /* Initialize the GConf library */ if (!gconf_init (argc, argv, &err)) { fprintf (stderr, _("Failed to init GConf: %s\n"), err->message); g_error_free (err); err = NULL; } /* Start a GConf client */ gconf_client = gconf_client_get_default (); /* Add the GTetrinet directories to the list of directories that GConf client must watch */ gconf_client_add_dir (gconf_client, "/apps/gtetrinet/sound", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); gconf_client_add_dir (gconf_client, "/apps/gtetrinet/themes", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); gconf_client_add_dir (gconf_client, "/apps/gtetrinet/keys", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); gconf_client_add_dir (gconf_client, "/apps/gtetrinet/partyline", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); /* Request notification of change for these gconf keys */ gconf_client_notify_add (gconf_client, "/apps/gtetrinet/sound/midi_player", (GConfClientNotifyFunc) sound_midi_player_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/sound/enable_sound", (GConfClientNotifyFunc) sound_enable_sound_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/sound/enable_midi", (GConfClientNotifyFunc) sound_enable_midi_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/themes/theme_dir", (GConfClientNotifyFunc) themes_theme_dir_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/down", (GConfClientNotifyFunc) keys_down_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/left", (GConfClientNotifyFunc) keys_left_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/right", (GConfClientNotifyFunc) keys_right_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/rotate_left", (GConfClientNotifyFunc) keys_rotate_left_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/rotate_right", (GConfClientNotifyFunc) keys_rotate_right_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/drop", (GConfClientNotifyFunc) keys_drop_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/message", (GConfClientNotifyFunc) keys_message_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/discard", (GConfClientNotifyFunc) keys_discard_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special1", (GConfClientNotifyFunc) keys_special1_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special2", (GConfClientNotifyFunc) keys_special2_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special3", (GConfClientNotifyFunc) keys_special3_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special4", (GConfClientNotifyFunc) keys_special4_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special5", (GConfClientNotifyFunc) keys_special5_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special6", (GConfClientNotifyFunc) keys_special6_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/keys/special_self", (GConfClientNotifyFunc) keys_special_self_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/partyline/enable_timestamps", (GConfClientNotifyFunc) partyline_enable_timestamps_changed, NULL, NULL, NULL); gconf_client_notify_add (gconf_client, "/apps/gtetrinet/partyline/enable_channel_list", (GConfClientNotifyFunc) partyline_enable_channel_list_changed, NULL, NULL, NULL); /* load settings */ config_loadconfig (); /* initialise some stuff */ fields_init (); if (!g_thread_supported()) g_thread_init (NULL); /* first set up the display */ /* create the main window */ app = gnome_app_new (APPID, APPNAME); g_signal_connect (G_OBJECT(app), "destroy", GTK_SIGNAL_FUNC(destroymain), NULL); keypress_signal = g_signal_connect (G_OBJECT(app), "key-press-event", GTK_SIGNAL_FUNC(keypress), NULL); g_signal_connect (G_OBJECT(app), "key-release-event", GTK_SIGNAL_FUNC(keyrelease), NULL); gtk_widget_set_events (app, GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK); gtk_window_set_resizable (GTK_WINDOW (app), TRUE); /* create and set the window icon */ icon_pixbuf = gdk_pixbuf_new_from_file (PIXMAPSDIR "/gtetrinet.png", NULL); if (icon_pixbuf) { gtk_window_set_icon (GTK_WINDOW (app), icon_pixbuf); gdk_pixbuf_unref (icon_pixbuf); } /* create the notebook */ notebook = gtk_notebook_new (); gtk_notebook_set_tab_pos (GTK_NOTEBOOK(notebook), GTK_POS_TOP); /* put it in the main window */ gnome_app_set_contents (GNOME_APP(app), notebook); /* make menus + toolbar */ make_menus (GNOME_APP(app)); /* create the pages in the notebook */ fieldswidget = fields_page_new (); gtk_widget_set_sensitive (fieldswidget, TRUE); gtk_widget_show (fieldswidget); pfields = gtk_hbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER(pfields), 0); gtk_container_add (GTK_CONTAINER(pfields), fieldswidget); gtk_widget_show (pfields); g_object_set_data (G_OBJECT(fieldswidget), "title", "Playing Fields"); // FIXME label = pixmapdata_label (fields_xpm, _("Playing Fields")); gtk_widget_show (label); gtk_notebook_append_page (GTK_NOTEBOOK(notebook), pfields, label); partywidget = partyline_page_new (); gtk_widget_show (partywidget); pparty = gtk_hbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER(pparty), 0); gtk_container_add (GTK_CONTAINER(pparty), partywidget); gtk_widget_show (pparty); g_object_set_data (G_OBJECT(partywidget), "title", "Partyline"); // FIXME label = pixmapdata_label (partyline_xpm, _("Partyline")); gtk_widget_show (label); gtk_notebook_append_page (GTK_NOTEBOOK(notebook), pparty, label); winlistwidget = winlist_page_new (); gtk_widget_show (winlistwidget); pwinlist = gtk_hbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER(pwinlist), 0); gtk_container_add (GTK_CONTAINER(pwinlist), winlistwidget); gtk_widget_show (pwinlist); g_object_set_data (G_OBJECT(winlistwidget), "title", "Winlist"); // FIXME label = pixmapdata_label (winlist_xpm, _("Winlist")); gtk_widget_show (label); gtk_notebook_append_page (GTK_NOTEBOOK(notebook), pwinlist, label); /* add signal to focus the text entry when switching to the partyline page*/ g_signal_connect_after(G_OBJECT (notebook), "switch-page", GTK_SIGNAL_FUNC (switch_focus), NULL); gtk_widget_show (notebook); g_object_set (G_OBJECT (notebook), "can-focus", FALSE, NULL); partyline_show_channel_list (list_enabled); gtk_widget_show (app); // gtk_widget_set_size_request (partywidget, 480, 360); // gtk_widget_set_size_request (winlistwidget, 480, 360); /* initialise some stuff */ commands_checkstate (); /* check command line params */ #ifdef DEBUG printf ("option_connect: %s\n" "option_nick: %s\n" "option_team: %s\n" "option_pass: %s\n" "option_spec: %i\n", option_connect, option_nick, option_team, option_pass, option_spec); #endif if (option_nick) GTET_O_STRCPY(nick, option_nick); if (option_team) GTET_O_STRCPY(team, option_team); if (option_pass) GTET_O_STRCPY(specpassword, option_pass); if (option_spec) spectating = TRUE; if (option_connect) { client_init (option_connect, nick); } /* Don't schedule if data is ready, glib should do this itself, * but welcome to anything that works... */ g_main_context_set_poll_func(NULL, gtetrinet_poll_func); /* gtk_main() */ gtk_main (); client_disconnect (); /* cleanup */ fields_cleanup (); sound_stopmidi (); return 0; }
int main ( int argc, char **argv ) { // Get DISPLAY const char *display_str = getenv ( "DISPLAY" ); if ( !( display = XOpenDisplay ( display_str ) ) ) { fprintf ( stderr, "cannot open display!\n" ); return EXIT_FAILURE; } TASSERT( display != NULL ); Screen *screen = DefaultScreenOfDisplay ( display ); Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) ); Window mw = XCreateSimpleWindow ( display, root, 0, 0, 200, 100, config.menu_bw, color_get ( display, config.menu_bc ), color_get ( display, config.menu_bg ) ); TASSERT( mw != None ); textbox_setup ( config.menu_bg, config.menu_fg, config.menu_hlbg, config.menu_hlfg ); textbox *box = textbox_create(mw , TB_EDITABLE|TB_AUTOWIDTH|TB_AUTOHEIGHT, 0,0, -1, -1, NORMAL, "test"); TASSERT( box != NULL ); textbox_cursor_end ( box ); TASSERT ( box->cursor == 4); textbox_cursor ( box, -1 ); TASSERT ( box->cursor == 0 ); textbox_cursor ( box, 8 ); TASSERT ( box->cursor == 4 ); textbox_cursor ( box, 2 ); TASSERT ( box->cursor == 2 ); textbox_insert ( box, 3, "bo"); TASSERT ( strcmp(box->text, "tesbot") == 0 ); textbox_cursor_end ( box ); TASSERT ( box->cursor == 6); TASSERT( textbox_get_width( box) > 0 ); TASSERT( textbox_get_height( box) > 0 ); TASSERT( textbox_get_width( box) >= textbox_get_font_width( box) ); TASSERT( textbox_get_height( box) >= textbox_get_font_height( box) ); TASSERT( textbox_get_estimated_char_width ( box) > 0 ); textbox_cursor_bkspc ( box ); TASSERT ( strcmp(box->text, "tesbo") == 0 ); TASSERT ( box->cursor == 5); textbox_cursor_dec ( box ); TASSERT ( box->cursor == 4); textbox_cursor_del ( box ); TASSERT ( strcmp(box->text, "tesb") == 0 ); textbox_cursor_dec ( box ); TASSERT ( box->cursor == 3); textbox_cursor_inc ( box ); TASSERT ( box->cursor == 4); textbox_cursor_inc ( box ); TASSERT ( box->cursor == 4); // Cursor after delete section. textbox_delete ( box, 0, 1 ); TASSERT ( strcmp(box->text, "esb") == 0 ); TASSERT ( box->cursor == 3); // Cursor before delete. textbox_text( box, "aap noot mies"); TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); textbox_cursor( box, 3 ); TASSERT ( box->cursor == 3); textbox_delete ( box, 3, 6 ); TASSERT ( strcmp(box->text, "aapmies") == 0 ); TASSERT ( box->cursor == 3); // Cursor within delete textbox_text( box, "aap noot mies"); TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); textbox_cursor( box, 5 ); TASSERT ( box->cursor == 5); textbox_delete ( box, 3, 6 ); TASSERT ( strcmp(box->text, "aapmies") == 0 ); TASSERT ( box->cursor == 3); // Cursor after delete. textbox_text( box, "aap noot mies"); TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); textbox_cursor( box, 11 ); TASSERT ( box->cursor == 11); textbox_delete ( box, 3, 6 ); TASSERT ( strcmp(box->text, "aapmies") == 0 ); TASSERT ( box->cursor == 5); textbox_font ( box, HIGHLIGHT ); textbox_draw( box ); textbox_show( box ); textbox_move ( box, 12, 13); TASSERT ( box->x == 12 ); TASSERT ( box->y == 13 ); textbox_hide( box ); textbox_free(box); textbox_cleanup(); XDestroyWindow ( display, mw); XCloseDisplay ( display ); }