[SDL] Cursor disappears when moved

Mark Jenison jenison at enteract.com
Mon Oct 16 20:46:04 PDT 2006


Ilya Olevsky <info <at> valengames.com> writes:

> 
> > Thanks for the advice.
> > 
> > I put this check in my main code loop, and when the program starts up now,
the
> > cursor is hidden.
> > 
> > However, if later something happens on the system that causes the cursor to
> > become an hourglass (disk access, etc), it causes the cursor to reappear.
I
> > would think this code would correctly re-hide the cursor, but it does not. 
Any
> > other ideas?
> 
> Hmm.. That's weird, but then again I've seen Win98/ME do stranger 
> things. Try calling SDL_WM_GrabInput(SDL_GRAB_ON) after you init 
> everything, if you don't do it already. If that doesn't help, try hiding 
> the cursor when the app gains mouse focus (on SDL_APPMOUSEFOCUS instead 
> of SDL_APPINPUTFOCUS) or just check against SDL_APPACTIVE when you get 
> an SDL_ACTIVEEVENT. That's pretty much all I can think of other than 
> checking every frame if the mouse is visible.
> 
> Ilya

Ok, it seems that it's a crap shoot whether or not the mouse is already 
visible upon startup...sometimes it is there, sometimes not.  I tried the
SDL_WM_GrabInput, but that seemed to make it worse.

This is basically the logic I have (I don't use the mouse at all in this app,
just joystick and keyboard):

int main()
{

  if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
  {
  // report error
  }

  input_startup() (initialize keyboard, joystick)

  graphics_startup (set video mode, etc)

  while (!finished)
  {

   if (ready to draw)
   {
    // draw screen
   }

   while(frame_count > 0)
   {
      next_frame();
      handle_events(); (keyboard events)
      update_screen();
      frame_count--; 
   }

   if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)
      || (SDL_GetAppState() & SDL_APPINPUTFOCUS)
      || (SDL_GetAppStaet() & SDL_APPACTIVE))
    {
      SDL_ShowCursor(SDL_DISABLE);
    }
  }
}

If the app starts with the cursor hidden, the cursor appears later at a random
time (seems like it may be due to the system doing some background processing).
But I would think the above code would hide it if it appeared later?

Again, simply pressing a button on the mouse or moving the mouse causes the
cursor to disappear again.

Any other suggestions?







More information about the SDL mailing list