void creategui() { int x, y, w = width, h = height; XSetWindowAttributes wa; if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fputs("no locale support\n", stderr); screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); initfont(font); cursor = XCreateFontCursor(dpy, XC_left_ptr); dc.norm[ColBG] = getcolor(normbgcolor); dc.norm[ColFG] = getcolor(normfgcolor); dc.sel[ColBG] = getcolor(selbgcolor); dc.sel[ColFG] = getcolor(selfgcolor); dc.drawable = XCreatePixmap(dpy, root, w, 2 * h, DefaultDepth(dpy, screen)); dc.gc = XCreateGC(dpy, root, 0, NULL); XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); if (!dc.font.set) XSetFont(dpy, dc.gc, dc.font.xfont->fid); wa.cursor = cursor; wa.background_pixel = dc.norm[ColBG]; XChangeWindowAttributes(dpy, root, CWBackPixel|CWCursor, &wa); x = (DisplayWidth(dpy, screen) - w) / 2; y = DisplayHeight(dpy, screen) / 2; createinput(userprompt, x, y - h, w, h, innerpx, False); createinput(passprompt, x, y, w, h, innerpx, True); im = XOpenIM(dpy, NULL, NULL, NULL); ic = XCreateIC(im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, inputs->win, XNFocusWindow, inputs->win, NULL); }
int create_sound(char*name,int bufsize,char*fname,int argc,char**argv) { int fd,mode,c; struct sound_t*sp; struct queue_t *q; input_handle hdl; char*buf; fd=open(fname,O_RDONLY); if(fd<0){ log(L_ERROR,"error: couldn't open sound device on input %s file %s",name,fname); return 0; } sp=malloc(sizeof(struct sound_t)); /*reset device:*/ if(ioctl(fd,SNDCTL_DSP_RESET,0)<0){ log(L_ERROR,"unable to reset DSP of input %s file %s",name,fname); free(sp); close(fd); return 0; } if(ioctl(fd,SNDCTL_DSP_GETFMTS,&c)<0){ log(L_ERROR,"unable to get sample size of input %s file %s",name,fname); free(sp); close(fd); return 0; } if(c&AFMT_S16_LE){mode=AFMT_S16_LE;sp->sdiv=2;sp->sch=0;log(L_DEBUG,"16bit Little Endian");}else if(c&AFMT_S16_BE){mode=AFMT_S16_BE;sp->sdiv=2;sp->sch=1;log(L_DEBUG,"16bit Little Endian");}else if(c&AFMT_U8){mode=AFMT_U8;sp->sdiv=1;sp->sch=0;log(L_DEBUG,"8bit");}else { log(L_ERROR,"unknown sample format of input %s file %s",name,fname); free(sp); close(fd); return 0; } if(ioctl(fd,SNDCTL_DSP_SETFMT,&mode)<0){ log(L_ERROR,"cannot set sample size of input %s file %s",name,fname); free(sp); close(fd); return 0; } if((c=1,ioctl(fd,SNDCTL_DSP_STEREO,&c))>=0){ log(L_DEBUG,"stereo"); sp->sdiv*=2; /*use only left channel, since right normally mirrors left*/ }else if((c=0,ioctl(fd,SNDCTL_DSP_STEREO,&c))>=0){ log(L_DEBUG,"mono"); }else{ log(L_ERROR,"error: unable to set mono/stereo of input %s file %s",name,fname); free(sp); close(fd); return 0; } /*try to set a rate:*/ if((c=48000,ioctl(fd,SNDCTL_DSP_SPEED,&c))<0) if((c=44100,ioctl(fd,SNDCTL_DSP_SPEED,&c))<0) if((c=32000,ioctl(fd,SNDCTL_DSP_SPEED,&c))<0) if((c=22050,ioctl(fd,SNDCTL_DSP_SPEED,&c))<0){ log(L_ERROR,"error: unable to set speed of input %s file %s",name,fname); free(sp); close(fd); return 0; } log(L_DEBUG,"Speed=%i samples/s",c); sp->bsize=0; ioctl(fd,SNDCTL_DSP_GETBLKSIZE,&sp->bsize); if(sp->bsize<4||sp->bsize>65536){ log(L_ERROR,"error: illogical blocksize %i of input %s file %s",sp->bsize,name,fname); free(sp); close(fd); return 0; }else{ log(L_DEBUG,"blocksize=%i",sp->bsize); } if(ioctl(fd,SNDCTL_DSP_SYNC,0)<0){ log(L_WARNING,"warning: unable to sync input %s file %s",name,fname); } log(L_INFO,"using 1 bit out of %i bytes; random rate = %i bit/s = %i byte/s on input %s file %s", sp->sdiv,c/sp->sdiv,c/sp->sdiv/8,name,fname); /*throw away some blocks, since these tend to be zero*/ buf=malloc(sp->bsize); for(c=0;c<16;c++) read(fd,buf,sp->bsize); free(buf); /*create entries*/ q=malloc(sizeof(struct queue_t)); q->fd=fd; q->mode=QREAD; q->data=sp; q->handler=soundhandler; hdl=createinput(name,bufsize,soundcallback,sp); if(!hdl){ log(L_ERROR,"unable to create sound input"); free(sp); free(q); close(fd); return 0; } sp->q=q; sp->hdl=hdl; queue(q); return 1; }