按键时如何更改输入窗口的背景色

时间:2018-10-15 05:49:14

标签: xlib

在此代码中有四个输入框。当我们按下键盘上的向上键或向下键时,指针会相应地向上或向下移动。我也想在失去输入或获得焦点时更改输入窗口的背景颜色,但是XSetWindowBackground不会更改颜色,它将如何解决

while ( done == 0 ) {
    XNextEvent (mydisplay , &baseEvent ) ;
    switch ( baseEvent . type ) {
    case Expose :
        break ;
    case KeyPress :
        count = XLookupString(&baseEvent . xkey , bytes , 3 , &character , &cs ) ;
        index = 0 ;
        for ( i =0; i <4; i ++)
        if ( ring [i] . id == baseEvent . xkey .window ) index = i ;
        switch ( count ) {
        case 0 : /* Control cha r a c t e r */
        switch ( character ) {
        case XK_Up: /* Up arrow key */
        case XK_KP_Up:
        XSetWindowBackground(mydisplay , ring[index].id,  0xff00FF00) ;
        index--;
        XSetWindowBackground(mydisplay , ring[index].id,  0xFF0000FF) ;
        if ( index < 0 ) index = 3 ;

        XWarpPointer (mydisplay , None , ring [ index ] . id ,
        0 , 0 , 0 , 0 , ring [ index ] . last * charinc , 10 ) ;
        break ;
        case XK_Down: /* Down arrow key */
        case XK_KP_Down:
        XSetWindowBackground(mydisplay , ring[index].id,  0xff00FF00) ;
        index++;
        XSetWindowBackground(mydisplay , ring[index].id,  0xFF0000FF) ;
        if ( index > 3 ) index = 0 ;
        XWarpPointer (mydisplay , None , ring [ index ] . id ,
        0 , 0 , 0 , 0 , ring [ index ] . last * charinc , 10 ) ;
        break ;
        }
        break ;
        case 1 : /* Pr int abl e cha r a c t e r */
        ring [ index ] . array [ ring [ index ] . last ] = bytes [ 0 ] ;
        XDrawString (mydisplay , ring [ index ] . id , mygc , ring [ index ] . last * charinc , 15 , bytes , 1 ) ;
        ring [ index ] . last ++;
        break ;
        }
        break ;
        }
    }

0 个答案:

没有答案