How to get the initial mouse coords before moving the mouse?

Andre <[email protected]>
Newsgroups gmane.comp.lib.sdl
Message-ID <[email protected]>
Hi everybody,

I have a problem with `SDL_GetMouseState`: I want to get the inital
mouse coords before the user moves the mouse, but the function only
returns 0 for the x and y coord.

I have attached a MWE that shows my problem. The first line that is
printed is always "init: 0, 0". I expected it to give the actual coords.

I tried this example under Linux only.

I really appreciate any help you can provide.

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
sdl_mouse.c (text/x-csrc, 788 B)
#include <SDL2/SDL.h>
#include <stdio.h>

int main(int argc, char *args[]) {
  if (SDL_Init(SDL_INIT_VIDEO) < 0)
    return 1;

  SDL_Window *window =
      SDL_CreateWindow("mouse", SDL_WINDOWPOS_UNDEFINED,
                       SDL_WINDOWPOS_UNDEFINED, 200, 150, SDL_WINDOW_SHOWN);
  if (window == NULL)
    return 1;

  SDL_UpdateWindowSurface(window);

  int x, y;
  SDL_PumpEvents();
  SDL_GetMouseState(&x, &y);
  printf("init: %i, %i\n", x, y);

  SDL_Event event;
  while (1) {
    while (SDL_PollEvent(&event)) {
      if (event.type == SDL_QUIT) {
        return 0;
      } else if (event.type == SDL_MOUSEMOTION) {
        printf("move: %i, %i\n", event.motion.x, event.motion.y);
      }
    }
    SDL_Delay(10);
  }

  SDL_DestroyWindow(window);
  SDL_Quit();
  return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.