📄 glav_main.c
字号:
gtk_label_set_text(GTK_LABEL(gtk_xlav->StatDisp),"Play <"); } else if(cur_speed < -1) { sprintf(label,"<<%2dx",-cur_speed); gtk_label_set_text(GTK_LABEL(gtk_xlav->StatDisp),label); } else if(cur_speed > 1) { sprintf(label,">>%2dx",cur_speed); gtk_label_set_text(GTK_LABEL(gtk_xlav->StatDisp),label); } old_speed = cur_speed; } return; } else { fprintf(stderr, "++: %s\n", inpbuff); }}static void get_input(gpointer data, gint fd, GdkInputCondition condition){ char input[4096]; int i, n; n = read(fd,input,4096); if(n==0) exit(0); for(i=0;i<n;i++) { if(input[i]=='\n') { inpbuff[inplen] = '\0'; dispatch_input(); inplen = 0; continue; } if(inplen<MAXINP-1) inpbuff[inplen++] = input[i]; }}void timeslider_cb(GtkAdjustment *adjustment, gpointer data){gfloat val;char out[256]; if (0 < slider_pause) { --slider_pause; } else { val = ((GTK_ADJUSTMENT(gtk_xlav->timeslider)->value)); sprintf(out,"s%d\n",(int)((val*total_frames)/100)); write(out_pipe,out,strlen(out)); }}void button_cb(GtkWidget *ob, long data){ switch(data) { case 1: write(out_pipe,"s0\n",3); break; /* go to beginning */ case 2: write(out_pipe,"s10000000\n",10); break; /* go to end */ /* moved this to frame_skip_pressed case 3: write(out_pipe,"-\n",2); break; case 4: write(out_pipe,"+\n",2); break; */ }}static guint skip_frame(char *mychar) { struct timeval current_time; gettimeofday(¤t_time,0); if (frame_skip_button_up == 0 ) { if (((current_time.tv_sec-time_when_pressed.tv_sec)*1000+(current_time.tv_usec-time_when_pressed.tv_usec)/1000)>500) { char out[10]; sprintf(out,"%c\n",frame_skip_char); write(out_pipe,out,2); number_of_skipped_frames++; } } return (! frame_skip_button_up);}void frame_skip_pressed(GtkWidget *ob, long data) { frame_skip_button_up=0; gettimeofday(&time_when_pressed,0); number_of_skipped_frames=0; switch(data) { case 3: frame_skip_char='-'; /* frame reverse */ gtk_timeout_add(10,(GtkFunction)skip_frame,(gpointer)0); break; case 4: frame_skip_char='+'; /* frame advance */ gtk_timeout_add(10,(GtkFunction)skip_frame,(gpointer)0); break; default: break; }}void frame_skip_released(GtkWidget *ob, long data){ frame_skip_button_up=1; if(number_of_skipped_frames==0){ char out[10]; sprintf(out,"%c\n",frame_skip_char); write(out_pipe,out,2); }}void rb_cb(GtkWidget *ob, long data){ char out[32]; if (data!=1) fr_stat = 0; if (data!=5) ff_stat = 0; switch(data) { case 1: fr_stat++; if(fr_stat>3) fr_stat=1; sprintf(out,"p-%d\n",ff_speed[fr_stat]); write(out_pipe,out,strlen(out)); break; case 2: write(out_pipe,"p-1\n",4); break; case 3: write(out_pipe,"p0\n",3); break; case 4: write(out_pipe,"p1\n",3); break; case 5: ff_stat++; if(ff_stat>3) ff_stat=1; sprintf(out,"p%d\n",ff_speed[ff_stat]); write(out_pipe,out,strlen(out)); break; case 0: /* this is here for a callback that does nothing */ break; default: break; }}#if 0 /* No Audio mute at the moment */void Audio_cb(GtkWidget *ob, long data){ if(fl_get_button(gtk_xlav->Audio)) write(out_pipe,"a1\n",3); else write(out_pipe,"a0\n",3);}#endifvoid do_real_exit(int ID, void *data){ int status; /* Kill all our children and exit */ printf("real exit here\n"); kill(pid,9); waitpid(pid,&status,0); exit(0);}void Exit_cb(GtkWidget *ob, long data){ /* Try to exit gracefully, wait 1 second, do real exit */ write(out_pipe,"q\n\n\n",4); gtk_timeout_add(1000,(GtkFunction)do_real_exit,0);}void signal_cb(int signum, void *data){ Exit_cb(0,0);}static int check_selection(void){ if(selection_start>=0 && selection_end>=selection_start) return 0; quick_message("Selection invalid!!!"); return -1;}void selection_cb(GtkWidget *ob, long data){ char str[256]; switch(data) { case 1: selection_start = cur_pos; calc_timecode(cur_pos,1); gtk_label_set_text(GTK_LABEL(gtk_xlav->FSelStart),timecode); break; case 2: selection_end = cur_pos; calc_timecode(cur_pos,1); gtk_label_set_text(GTK_LABEL(gtk_xlav->FSelEnd),timecode); break; case 3: /* Clear */ selection_start = -1; selection_end = -1; gtk_label_set_text(GTK_LABEL(gtk_xlav->FSelStart),"-:--:--:--"); gtk_label_set_text(GTK_LABEL(gtk_xlav->FSelEnd),"-:--:--:--"); break; case 4: /* Cut */ case 5: /* Copy */ if(check_selection()) return; sprintf(str,"e%c %d %d\n",(data==4)?'u':'o',selection_start,selection_end); write(out_pipe,str,strlen(str)); if(data==4) { selection_start = -1; selection_end = -1; gtk_label_set_text(GTK_LABEL(gtk_xlav->FSelStart),"-:--:--:--"); gtk_label_set_text(GTK_LABEL(gtk_xlav->FSelEnd),"-:--:--:--"); } break; case 6: /* Paste */ if(check_selection()) return; selection_start = -1; selection_end = -1; gtk_label_set_text(GTK_LABEL(gtk_xlav->FSelStart),"-:--:--:--"); gtk_label_set_text(GTK_LABEL(gtk_xlav->FSelEnd),"-:--:--:--"); write(out_pipe,"ep\n",3); break; case 7: /* Save All */ savetype=SAVE_ALL; create_file_selection(); break; case 8: /* Save */ if(check_selection()) return; savetype=SAVE_SEL; create_file_selection(); break; case 11: if(selection_start >= 0) { sprintf(str,"s%d\n",selection_start); write(out_pipe,str,strlen(str)); } else printf("Selection Start is not set!\n"); break; case 12: if(selection_end >= 0) { sprintf(str,"s%d\n",selection_end); write(out_pipe,str,strlen(str)); } else printf("Selection End is not set!\n"); break; default: printf("selection %ld\n",data); }}static void create_child(const char **args){ int ipipe[2], opipe[2]; int n, vlen; char version[32]; if(pipe(ipipe)!=0 || pipe(opipe)!=0) { perror("Starting "PLAY_PROG); exit(1); } pid = fork(); if(pid<0) { perror("Starting "PLAY_PROG); exit(1); } if (pid) { /* We are the parent */ inp_pipe = ipipe[0]; close(ipipe[1]); out_pipe = opipe[1]; close(opipe[0]); } else { /* We are the child */ close(ipipe[0]); close(opipe[1]); close(0); n = dup(opipe[0]); if(n!=0) exit(1); close(opipe[0]); close(1); n = dup(ipipe[1]); if(n!=1) exit(1); close(ipipe[1]); close(2); n = dup(1); if(n!=2) exit(1); execvp(PLAY_PROG,(char *const*)args); /* if exec returns, an error occured */ exit(1); } /* Check if child sends right version number */ vlen = strlen(LAVPLAY_VSTR); n = read(inp_pipe,version,vlen+1); /* vlen+1: for trailing \n */ version[vlen] = 0; if(n!=vlen+1 || strncmp(version,LAVPLAY_VSTR,vlen)!=0) { fprintf(stderr,"%s did not send correct version info\n",PLAY_PROG); fprintf(stderr,"Got: \"%s\" Expected: \"%s\"\n",version,LAVPLAY_VERSION); do_real_exit(0,0); }}int main(int argc, char *argv[]){ int i; /* copy our argument list */ const char **argvn = (const char **) malloc(sizeof(char*)*(argc+3)); if(argvn==0) { fprintf(stderr,"malloc failed\n"); exit(1); } argvn[0] = PLAY_PROG; argvn[1] = "-q"; argvn[2] = "-g"; for(i=1;i<argc;i++) argvn[i+2] = argv[i]; argvn[argc+2] = 0; create_child(argvn); gtk_init (&argc, &argv); gtk_xlav = create_form_xlav();// old: gtk_signal_connect (GTK_OBJECT (gtk_xlav->xlav), "destroy",// old: GTK_SIGNAL_FUNC(gtk_main_quit), NULL); g_signal_connect_swapped(G_OBJECT (gtk_xlav->xlav), "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_widget_show(gtk_xlav->xlav); /* show the main window */ gdk_input_add(inp_pipe,GDK_INPUT_READ,(GdkInputFunction)get_input,(gpointer)0); gtk_main(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -