X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=blobdiff_plain;f=view.c;h=32ae7d7df8a8a39ecd9ad0785f0d2870bed54c89;hp=0121cad460d6ba29972c59471e44452b1527a756;hb=c01a4fe080a448234b39afb7ea7f7a3c9c229fb7;hpb=df4fafe44b168dc0e79489e558fc00b3a2b7da3f diff --git a/view.c b/view.c index 0121cad..32ae7d7 100644 --- a/view.c +++ b/view.c @@ -337,7 +337,7 @@ static void make_z_rotation(double rotz[D3][D3], double cz, double sz) { rotz[0][0]= cz; rotz[0][1]= sz; rotz[0][2]= 0; rotz[1][0]= -sz; rotz[1][1]= cz; rotz[1][2]= 0; rotz[2][0]= 0; rotz[2][1]= 0; rotz[2][2]= 1; -} +} static void drag_rotate_delta(double dx, double dy) { /* We multiple our transformation matrix by a matrix: @@ -540,10 +540,38 @@ static void event_motion(int x, int y) { drag_position(x,y); } +static void transform_preset_record(const char *fn, const char *fn_new) { + FILE *f; + f= fopen(fn_new,"wb"); + if (!f) diee("open new transform"); + if (fwrite(transform,sizeof(transform),1,f) != 1) diee("write transform"); + if (fclose(f)) diee("fclose new transform"); + if (rename(fn_new,fn)) diee("install transform"); +} + +static void transform_preset_playback(const char *fn) { + FILE *f; + f= fopen(fn,"rb"); + if (!f && errno==ENOENT) { + fprintf(stderr,"no preset %s\n",fn); + XBell(display,100); + return; + } + errno= 0; + if (fread(transform,sizeof(transform),1,f) != 1) { + perror("read preset!"); + XBell(display,100); + return; + } + fclose(f); + show(); +} + static void event_key(XKeyEvent *e) { KeySym ks; - char buf[10]; - int r; + XKeyEvent e_nomod; + char buf[10], buf_nomod[10]; + int r, r_nomod; r= XLookupString(e,buf,sizeof(buf)-1,&ks,0); if (!r) { @@ -564,11 +592,31 @@ static void event_key(XKeyEvent *e) { eyes_apart= eyes_apart>0 ? eyes_apart_min : eyes_apart_preferred; show(); return; - } else { - printf("unknown key keycode=%d state=0x%x char=%c 0x%02x\n", - e->keycode, e->state, buf[0]>' ' && buf[0]<127 ? buf[0] : '?', - buf[0]); } + + e_nomod= *e; + e_nomod.state= 0; + buf_nomod[0]= 0; + r_nomod= XLookupString(&e_nomod,buf_nomod,sizeof(buf_nomod)-1,&ks,0); + if (r_nomod && !buf_nomod[1] && buf_nomod[0]>='0' && buf_nomod[0]<='9') { + char filename[20], filename_new[25]; + snprintf(filename,sizeof(filename)-1,".view-preset-%s",buf_nomod); + snprintf(filename_new,sizeof(filename_new)-1,"%s.new",filename); + printf("transform preset %d %s\n", e->state, filename); + if (e->state) transform_preset_record(filename,filename_new); + else transform_preset_playback(filename); + return; + } + + printf("unknown key keycode=%d state=0x%x char=%c 0x%02x " + "[rnm=%d bnm[0,1]=0x%02x,%02x]\n", + e->keycode, e->state, buf[0]>' ' && buf[0]<127 ? buf[0] : '?', + buf[0], r_nomod, buf_nomod[0], buf_nomod[1]); + printf("%d %d %d %d\n", + r_nomod, + !buf_nomod[1], + buf_nomod[0]>='0', + buf_nomod[0]<='9'); } static void event_config(XConfigureEvent *e) {