Question

I'm trying to implement an input box with xlib, but i cannot find any ifnormation on how to show the blinking cursor.

Like the following: enter image description here

How can it be done?

Was it helpful?

Solution

xlib has no built-in notions of animation or blinking. You have to run a timer and draw and erase the cursor periodically.

OTHER TIPS

I use something like: This is an excerpt from my project http://open.source.sveena.com You have to complete the missing parts.

// call this periodically
void    FlipCaret()
{
       if( !s_caretgc )return;
       if( s_hidecaret )return;
        XACCESSLOCK;
        if( !s_caretgc )return;
       XFillRectangle(s_caretdisplay, s_caretwindow, s_caretgc, s_caretx, s_carety, s_caretcx, s_caretcy);
        XFlush(s_caretdisplay);
        s_caretvisible = s_caretvisible ? 0 : 1;
}

// to create and destroy caret
static void     s_DestroyCaret()
{
        if( !s_caretgc )return;
        XACCESSLOCK;
        if( s_caretgc ){
                if( s_caretvisible ){
                        FlipCaret();
                }
                XFreeGC( s_caretdisplay, s_caretgc );
                XFlush( s_caretdisplay );
                s_caretgc = 0;
        }
}

static void     s_CreateCaret( MWND* mwnd, Window w )
{
        s_DestroyCaret();
        XACCESSLOCK;
        s_caretdisplay = mwnd->m_Display;
        s_caretmwnd = mwnd;
        s_caretwindow = w;
        s_caretx = mwnd->Caretx;
        s_carety = mwnd->Carety;
        s_caretcx = mwnd->CaretCx;
        s_caretcy = mwnd->CaretCy;
        if( s_caretcx<5 )s_caretcx = 5;
        if( s_caretcx>20 )s_caretcx = 20;
        if( s_caretcy<16 )s_caretcy = 16;
        if( s_caretcy>100 )s_caretcy = 100;
        XGCValues gcval;
        gcval.function = GXinvert;
        gcval.fill_style = FillSolid;
        if( IsValidXWindow( w, "XCreateGC" ) )
        s_caretgc = XCreateGC(s_caretdisplay,w,GCFunction|GCFillStyle,&gcval);
        XFlush( s_caretdisplay );
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top