void restart() { // let's restart the game init_defaults(); init_drugs(); init_screens(); init_sheets(); }
main() { int i; init_screens (); /* Initialisiation du 2Šme ‚cran */ gem_init(); /* Se trouve dans fichier Include GEM_INEX.C */ v_hide_c (handle); /* D‚sactiver pointeur souris */ for (i=20; i<=300; i++) { Cconws ("\33E"); /* Effacer ‚cran */ v_gtext (handle, i, i, "Salut!"); /* Affichage texte sous GEM */ swap_screens (); /* Commuter ‚crans log./phys. */ Vsync(); /* Attente retour image */ } Crawcin(); /* Attente appui touche */ Setscreen (screen1, screen1, -1); /* Retour … l'‚cran normal */ v_show_c (handle, 1); /* Pointeur souris actif */ gem_exit(); }
void do_buy(int drug, int ammount) { game.old_price[drug] += game.price[drug]*ammount; game.money -= game.price[drug]*ammount; game.coat += ammount; game.drugs[drug] += ammount; init_screens(); }
void do_sell(int drug, int ammount) { int avg; avg = (game.old_price[drug] / game.drugs[drug]); game.old_price[drug] -= avg*ammount; game.money += game.price[drug]*ammount; game.coat -= ammount; game.drugs[drug] -= ammount; init_screens(); }
void new_idw_window() { idw_gc = GrNewGC(); GrGetScreenInfo(&screen_info); init_defaults(); init_drugs(); init_screens(); init_sheets(); idw_wid = pz_new_window(0, HEADER_TOPLINE + 1, screen_info.cols, screen_info.rows - (HEADER_TOPLINE + 1), idw_do_draw, idw_do_keystroke); GrSelectEvents(idw_wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_KEY_DOWN); GrMapWindow(idw_wid); }
/** * Program main entry */ int main(int argc, char *argv[]) { static const GOptionEntry options[]={ { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, N_("Print debug info to stdout")}, { "emulate", 'e', 0, G_OPTION_ARG_NONE, &emulate, N_("Don't apply any rules, only emulate execution")}, { "folder", 'f', 0, G_OPTION_ARG_STRING, &script_folder, N_("Search for scripts in this folder"),N_("FOLDER")}, { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, N_("Show Devilspie2 version and quit")}, #ifdef HAVE_GTK3 // libwnck Version Information is only availible if you have // libwnck 3.0 or later { "wnck-version", 'w', 0, G_OPTION_ARG_NONE, &show_wnck_version, N_("Show libwnck version and quit")}, #endif { NULL } }; GError *error = NULL; GOptionContext *context; // Init gettext stuff setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); bind_textdomain_codeset(PACKAGE, ""); textdomain(PACKAGE); gdk_init(&argc, &argv); gchar *devilspie2_description = g_strdup_printf(_("apply rules on windows")); gchar *full_desc_string = g_strdup_printf("- %s", devilspie2_description); context=g_option_context_new(full_desc_string); g_option_context_add_main_entries(context,options,NULL); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_print(_("option parsing failed: %s"), error->message); printf("\n"); exit(EXIT_FAILURE); } g_free(full_desc_string); g_free(devilspie2_description); // if the folder is NULL, default to ~/.config/devilspie2/ if (script_folder == NULL) { temp_folder = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), "devilspie2", NULL); // check if the folder does exist if (!g_file_test(temp_folder, G_FILE_TEST_IS_DIR)) { // - and if it doesn't, create it. if (g_mkdir(temp_folder, 0700) != 0) { printf("%s", _("Couldn't create the default folder for devilspie2 scripts.")); printf("\n"); exit(EXIT_FAILURE); } } script_folder = temp_folder; } if (show_version) { printf("Devilspie2 v%s\n\n", DEVILSPIE2_VERSION); exit(EXIT_SUCCESS); } #ifdef HAVE_GTK3 // libwnck Version Information is only availible if you have // libwnck 3.0 or later if (show_wnck_version) { printf("libwnck v%d.%d.%d\n\n", WNCK_MAJOR_VERSION, WNCK_MINOR_VERSION, WNCK_MICRO_VERSION); exit(EXIT_SUCCESS); } #endif #if (GTK_MAJOR_VERSION >= 3) if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) { printf("%s", _("An X11 display is required for devilspie2.")); printf("\n\n"); return EXIT_FAILURE; } #endif if (init_script_error_messages()!=0) { printf("%s", _("Couldn't init script error messages!")); printf("\n"); exit(EXIT_FAILURE); } config_filename = g_build_filename(script_folder, "devilspie2.lua", NULL); if (load_config(config_filename)!=0) { devilspie_exit(); return EXIT_FAILURE; } if (debug) { if (emulate) { printf("%s", _("Running devilspie2 in debug and emulate mode.")); } else { printf("%s", _("Running devilspie2 in debug mode.")); } printf("\n\n"); printf(_("Using scripts from folder: %s"), script_folder); printf("\n"); devilspie2_debug = TRUE; } // Should we only run an emulation (don't modify any windows) if (emulate) devilspie2_emulate = emulate; GFile *directory_file; directory_file = g_file_new_for_path(script_folder); // mon = g_file_monitor_directory(directory_file, G_FILE_MONITOR_WATCH_MOUNTS, mon = g_file_monitor_directory(directory_file, G_FILE_MONITOR_NONE, NULL, NULL); if (!mon) { printf("%s", _("Couldn't create directory monitor!")); printf("\n"); return EXIT_FAILURE; } g_signal_connect(mon, "changed", G_CALLBACK(folder_changed_callback), (gpointer)(config_filename)); global_lua_state = init_script(); print_script_lists(); if (debug) printf("------------\n"); // remove stuff cleanly atexit(devilspie_exit); struct sigaction signal_action; sigemptyset(&signal_action.sa_mask); signal_action.sa_flags = 0; signal_action.sa_handler = signal_handler; if (sigaction(SIGINT, &signal_action, NULL) == -1) { exit(EXIT_FAILURE); } init_screens(); loop=g_main_loop_new(NULL, TRUE); g_main_loop_run(loop); return EXIT_SUCCESS; }
static int idw_do_keystroke (GR_EVENT *event) { TSheet event_sheet; int n; if ( game.dismiss_sheet ) { if (event->keystroke.ch == '\r') { if (game.days == game.max_days) restart(); game.dismiss_sheet = 0; game.in_transaction = 0; idw_do_draw(); } return 1; } switch (event->keystroke.ch) { case '\r': /* Wheel button */ if (! game.screen->menuitems[game.select].sheet) break; if ( (game.screen == &buy) && (!afford(game.select)) ) break; if ( (game.screen == &sell) && (!game.drugs[game.select]) ) break; if ( (game.screen->menuitems[game.select].sheet == &borrow_sheet) && (!game.debt) ) break; if ( (game.screen->menuitems[game.select].sheet == &withdraw_sheet) && (!game.bank) ) break; init_sheets(); if (! game.in_transaction ) { // set initial ammount value to be shown on the sheet game.ammount = game.screen->menuitems[game.select].sheet->ammount; init_sheets(); } init_screens(); if ( game.screen == &jet ) { if (game.city == game.select) break; travel(); // let's get a random event (high-low)+low n = (rand() % EVENT_COUNT); // it has a 50-50 chance of occurring if (! (rand() % 2)) { event_sheet = random_event(n); idw_draw_sheet(&event_sheet); init_screens(); } else { init_screens(); idw_do_draw(); } check_over(); break; } if ( game.in_transaction ) { // we're going to buy/sell if (game.screen == &buy) do_buy(game.select, game.ammount); if (game.screen == &sell) do_sell(game.select, game.ammount); if (game.screen->menuitems[game.select].sheet == &deposit_sheet) do_deposit(); if (game.screen->menuitems[game.select].sheet == &withdraw_sheet) do_withdraw(); if (game.screen->menuitems[game.select].sheet == &pay_sheet) do_pay(); if (game.screen->menuitems[game.select].sheet == &borrow_sheet) do_borrow(); // transaction finished game.in_transaction = 0; init_screens(); idw_do_draw(); break; } idw_draw_sheet(NULL); break; case 'd': /* Play/pause button */ break; case 'w': /* Rewind button */ if (game.in_transaction) break; if (!game.screen->prev) break; game.screen = game.screen->prev; game.select=0; idw_do_draw(); break; case 'f': /* Fast forward button */ if (game.in_transaction) break; if (!game.screen->next) break; game.screen = game.screen->next; game.select=0; idw_do_draw(); break; case 'l': /* Wheel left */ if (game.in_transaction) { if (game.ammount) game.ammount--; init_sheets(); idw_draw_sheet(NULL); break; } if (game.select <= 0) break; game.select--; idw_do_draw(); break; case 'r': /* Wheel right */ if (game.in_transaction) { if (game.ammount < game.screen->menuitems[game.select].sheet->ammount) game.ammount++; init_sheets(); idw_draw_sheet(NULL); break; } if (game.select >= game.screen->count-1) break; game.select++; idw_do_draw(); break; case 'm': /* Menu button */ //if (game.in_transaction) { // cancel transaction // game.in_transaction = 0; // game.ammount = 0; // idw_do_draw(); // break; // } // pz_close_window (idw_wid); // GrDestroyGC(idw_gc); // break; // default: GrDestroyGC( idw_gc ); pz_close_window( idw_wid ); break; } return 1; }
int main(int argc, char *argv[]) { IxpMsg m; char **oargv; char *wmiirc, *s; int i; quotefmtinstall(); fmtinstall('r', errfmt); fmtinstall('a', afmt); fmtinstall('C', Cfmt); extern int fmtevent(Fmt*); fmtinstall('E', fmtevent); wmiirc = "wmiirc"; oargv = argv; ARGBEGIN{ case 'a': address = EARGF(usage()); break; case 'r': wmiirc = EARGF(usage()); break; case 'v': print("%s", version); exit(0); case 'D': s = EARGF(usage()); m = ixp_message(s, strlen(s), 0); msg_debug(&m); break; default: usage(); break; }ARGEND; if(argc) usage(); setlocale(LC_CTYPE, ""); starting = true; initdisplay(); traperrors(true); selectinput(&scr.root, EnterWindowMask | SubstructureRedirectMask); if(traperrors(false)) fatal("another window manager is already running"); passwd = getpwuid(getuid()); user = estrdup(passwd->pw_name); init_environment(); fmtinstall('F', Ffmt); ixp_printfcall = printfcall; sock = ixp_announce(address); if(sock < 0) fatal("Can't create socket '%s': %r", address); closeexec(ConnectionNumber(display)); closeexec(sock); if(wmiirc[0]) spawn_command(wmiirc); init_traps(); init_cursors(); init_lock_keys(); ewmh_init(); xext_init(); srv.preselect = check_preselect; ixp_listen(&srv, sock, &p9srv, serve_9pcon, nil); ixp_listen(&srv, ConnectionNumber(display), nil, check_x_event, closedisplay); def.border = 1; def.colmode = Colstack; def.font = loadfont(FONT); def.incmode = ISqueeze; def.mod = Mod1Mask; strcpy(def.grabmod, "Mod1"); loadcolor(&def.focuscolor, FOCUSCOLORS); loadcolor(&def.normcolor, NORMCOLORS); disp.sel = pointerscreen(); init_screens(); root_init(); disp.focus = nil; setfocus(screen->barwin, RevertToParent); view_select("1"); scan_wins(); starting = false; view_update_all(); ewmh_updateviews(); event("FocusTag %s\n", selview->name); i = ixp_serverloop(&srv); if(i) fprint(2, "%s: error: %r\n", argv0); else event("Quit"); cleanup(); if(exitsignal) raise(exitsignal); if(execstr) { char *toks[32]; int n; n = unquote(strdup(execstr), toks, nelem(toks)-1); toks[n] = nil; execvp(toks[0], toks); fprint(2, "%s: failed to exec %q: %r\n", argv0, execstr); execvp(argv0, oargv); fatal("failed to exec myself"); } return i; }