From 8e587549a1f4fcf09cf229898442a7b0e10988a7 Mon Sep 17 00:00:00 2001 From: Szymon Wilczek Date: Mon, 25 Aug 2008 18:02:14 +0000 Subject: [PATCH] Removed unneccesary code lines. Fixed mousename bug. Added lacking code in mousebutton --- include/SDL_mouse.h | 43 +++++++++++++++++++++++++++++++---- src/events/SDL_mouse.c | 8 +++++-- src/video/x11/SDL_x11window.c | 6 ++--- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/include/SDL_mouse.h b/include/SDL_mouse.h index 4695a8b07..31fad5ca7 100644 --- a/include/SDL_mouse.h +++ b/include/SDL_mouse.h @@ -54,6 +54,17 @@ typedef struct SDL_Cursor SDL_Cursor; /* Implementation dependent */ */ extern DECLSPEC int SDLCALL SDL_GetNumMice(void); +/** + * \fn char* SDL_GetMouseName(int index) + * + * \brief Gets the name of a mouse with the given index. + * + * \param index is the index of the mouse, which name is to be returned. + * + * \return the name of the mouse with the specified index + */ +extern DECLSPEC char *SDLCALL SDL_GetMouseName(int index); + /** * \fn int SDL_SelectMouse(int index) * @@ -206,13 +217,35 @@ extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle); Button 3: Right mouse button */ -/* FIXME: Where do these functions go in this header? - Also, add doxygen documentation for these... -*/ -extern DECLSPEC char *SDLCALL SDL_GetMouseName(int index); - +/** + * \fn int SDL_GetCursorsNumber(int index) + * + * \brief Gets the number of cursors a pointing device supports. + * Useful for tablet users. Useful only under Windows. + * + * \param index is the index of the pointing device, which number of cursors we + * want to receive. + * + * \return the number of cursors supported by the pointing device. On Windows + * if a device is a tablet it returns a number >=1. Normal mice always return 1. + * On Linux every device reports one cursor. + */ extern DECLSPEC int SDLCALL SDL_GetCursorsNumber(int index); +/** + * \fn int SDL_GetCurrentCursor(int index) + * + * \brief Returns the index of the current cursor used by a specific pointing + * device. Useful only under Windows. + * + * \param index is the index of the pointing device, which cursor index we want + * to receive. + * + * \return the index of the cursor currently used by a specific pointing device. + * Always 0 under Linux. On Windows if the device isn't a tablet it returns 0. + * If the device is the tablet it returns the cursor index. + * 0 - stylus, 1 - eraser, 2 - cursor. + */ extern DECLSPEC int SDLCALL SDL_GetCurrentCursor(int index); #define SDL_BUTTON(X) (1 << ((X)-1)) diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index a6b77e59c..50b24aa06 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -116,8 +116,8 @@ SDL_AddMouse(const SDL_Mouse * mouse, int index, char *name, int pressure_max, /* we're setting the mouse properties */ length = 0; length = SDL_strlen(name); - SDL_mice[index]->name = SDL_malloc((length + 1) * sizeof(char)); - SDL_strlcpy(SDL_mice[index]->name, name, length); + SDL_mice[index]->name = SDL_malloc((length + 2) * sizeof(char)); + SDL_strlcpy(SDL_mice[index]->name, name, length+1); SDL_mice[index]->pressure_max = pressure_max; SDL_mice[index]->pressure_min = pressure_min; SDL_mice[index]->cursor_shown = SDL_TRUE; @@ -512,6 +512,10 @@ SDL_SendMouseButton(int id, Uint8 state, Uint8 button) mouse->buttonstate |= SDL_BUTTON(button); break; case SDL_RELEASED: + if(!(mouse->buttonstate & SDL_BUTTON(button))) { + /* Ignore this event, no state change */ + return 0; + } type = SDL_MOUSEBUTTONUP; mouse->buttonstate &= ~SDL_BUTTON(button); break; diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index c5f747fd1..391ac3e86 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -483,7 +483,6 @@ X11_CreateWindow(_THIS, SDL_Window * window) Uint32 fevent = 0; pXGetICValues(((SDL_WindowData *) window->driverdata)->ic, XNFilterEvents, &fevent, NULL); - XMapWindow(data->display, w); XSelectInput(data->display, w, (FocusChangeMask | EnterWindowMask | LeaveWindowMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | @@ -492,13 +491,14 @@ X11_CreateWindow(_THIS, SDL_Window * window) KeymapStateMask | fevent)); } #else - XMapWindow(data->display, w); - XSelectInput(data->display, w, + { + XSelectInput(data->display, w, (FocusChangeMask | EnterWindowMask | LeaveWindowMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | KeyPressMask | KeyReleaseMask | PropertyChangeMask | StructureNotifyMask | KeymapStateMask)); + } #endif /* we're informing the display what extension events we want to receive from it */