bool i_drag(arg_t a) { int dx = 0, dy = 0, i, ox, oy, x, y; unsigned int ui; bool dragging = true, next = false; XEvent e; Window w; if (mode != MODE_IMAGE) return false; if (!XQueryPointer(win.env.dpy, win.xwin, &w, &w, &i, &i, &ox, &oy, &ui)) return false; win_set_cursor(&win, CURSOR_HAND); while (dragging) { if (!next) XMaskEvent(win.env.dpy, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e); switch (e.type) { case ButtonPress: case ButtonRelease: dragging = false; break; case MotionNotify: x = e.xmotion.x; y = e.xmotion.y; if (x >= 0 && x <= win.w && y >= 0 && y <= win.h) { dx += x - ox; dy += y - oy; } ox = x; oy = y; break; } if (dragging) next = XCheckIfEvent(win.env.dpy, &e, is_motionnotify, None); if ((!dragging || !next) && (dx != 0 || dy != 0)) { if (img_move(&img, dx, dy)) img_render(&img); dx = dy = 0; } } win_set_cursor(&win, CURSOR_ARROW); set_timeout(reset_cursor, TO_CURSOR_HIDE, true); reset_timeout(redraw); return false; }
bool it_reload_image(arg_t a) { if (mode == MODE_IMAGE) { load_image(fileidx); } else { win_set_cursor(&win, CURSOR_WATCH); if (!tns_load(&tns, tns.sel, &files[tns.sel], true, false)) { remove_file(tns.sel, false); tns.dirty = true; if (tns.sel >= tns.cnt) tns.sel = tns.cnt - 1; } } return true; }
bool it_shell_cmd(arg_t a) { int n, status; const char *cmdline = (const char*) a; pid_t pid; if (cmdline == NULL || *cmdline == '\0') return false; n = mode == MODE_IMAGE ? fileidx : tns.sel; if (setenv("SXIV_IMG", files[n].path, 1) < 0) { warn("could not set env.-variable: SXIV_IMG. command line was: %s", cmdline); return false; } if ((pid = fork()) == 0) { execl("/bin/sh", "/bin/sh", "-c", cmdline, NULL); warn("could not exec: /bin/sh. command line was: %s", cmdline); exit(EXIT_FAILURE); } else if (pid < 0) { warn("could not fork. command line was: %s", cmdline); return false; } win_set_cursor(&win, CURSOR_WATCH); waitpid(pid, &status, 0); if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0) warn("child exited with non-zero return value: %d. command line was: %s", WEXITSTATUS(status), cmdline); if (mode == MODE_IMAGE) { img_close(&img, true); load_image(fileidx); } if (!tns_load(&tns, n, &files[n], true, mode == MODE_IMAGE) && mode == MODE_THUMB) { remove_file(tns.sel, false); tns.dirty = true; if (tns.sel >= tns.cnt) tns.sel = tns.cnt - 1; } return true; }
int main(int argc, char *argv[]) { byte keypress; client_init(); if( argc > 1 ) /* Command line arguments */ handle_cl_args(argc, argv); srand( time(NULL) ); calc_lookup_tables(DEGREES); win_init(); entity_init(); if( (ent_img_loaded = (char *)malloc(num_entity_types)) == NULL ) { perror("Malloc"); ERR_QUIT("Error allocating ent_img_loaded array", 1); } else { memset(ent_img_loaded, 0, num_entity_types); } /* Load client preferences from file */ read_config_file( &client ); /* Set view dimensions, which are calculated by tile width & heights */ client.view_w = client.x_tiles * TILE_W; client.view_h = client.y_tiles * TILE_H; /* What the client WISHES their dimensions were (this may not be what it actually is, ie in demo's etc */ client.desired_w = client.view_w; client.desired_h = client.view_h; weapon_type_init(); particle_init(); menu_init(); cl_network_init(); client.state = MENU; if( client.demo == DEMO_PLAY ) { cl_network_connect(NULL, 42); client.state = GAME_LOAD; } for( ; ; ) { switch( client.state ) { case MENU: win_ungrab_pointer(); menu_driver(); break; case GAME_LOAD: win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H); wait_till_expose(5); /* Finished loading, we are ready to play */ cl_change_map(client.map, client.gamemode); break; case GAME_RESUME: /* Resume game from menu */ win_set_properties(VERSION, client.view_w, client.view_h+STATUS_H); wait_till_expose(5); input_clear(); draw_status_bar(); cl_netmsg_send_ready(); /* Tell server new details */ cl_net_finish(); /* Send the NETMSG_READY to the server */ client.state = GAME_JOIN; break; case GAME_JOIN: win_set_cursor( client.mousemode!=MOUSEMODE_ROTATE ); win_set_cursor( 1 ); if( client.mousemode ) { win_grab_pointer(); } text_buf_clear(); particle_clear(); case GAME_PLAY: cl_net_update(); if( client.state == GAME_PLAY ) { /* Maybe changed in net_update */ draw_crosshair( my_entity ); if( client.map_target_active ) draw_map_target( my_entity ); text_buf_update(); if( client.netstats ) cl_net_stats(); win_update(); /* Keyboard Input */ client.dir = my_entity.dir; keypress = get_input(); cl_netmsg_send_cl_update(keypress, client.dir); } cl_net_finish(); /* Send things that need sending */ cap_fps(client.fps); break; case QUIT: game_close(); image_close(); /* Free all the images */ win_close(); write_config_file(&client); if( ent_img_loaded != NULL ) free(ent_img_loaded); exit(EXIT_SUCCESS); break; } } return EXIT_SUCCESS; }