src/video/win32/SDL_win32mouse.c
author Szymon Wilczek <kazeuser@gmail.com>
Thu, 14 Aug 2008 08:28:19 +0000
branchgsoc2008_manymouse
changeset 3779 5f599ed92fb9
parent 3774 8b5b67000dc0
permissions -rw-r--r--
Small improvements
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
     1
/*
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
     2
    SDL - Simple DirectMedia Layer
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
     3
    Copyright (C) 1997-2006 Sam Lantinga
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
     4
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
     5
    This library is free software; you can redistribute it and/or
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
     7
    License as published by the Free Software Foundation; either
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
     9
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    10
    This library is distributed in the hope that it will be useful,
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    13
    Lesser General Public License for more details.
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    14
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    16
    License along with this library; if not, write to the Free Software
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    18
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    19
    Sam Lantinga
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    20
    slouken@libsdl.org
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    21
*/
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    22
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
    23
/*we need to define it, so that raw input is included*/
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
    24
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    25
#if (_WIN32_WINNT < 0x0501)
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    26
#undef _WIN32_WINNT
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    27
#define _WIN32_WINNT 0x0501
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    28
#endif
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    29
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    30
#include "SDL_config.h"
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    31
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    32
#include "SDL_win32video.h"
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    33
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    34
#include "../../events/SDL_mouse_c.h"
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    35
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
    36
#include <wintab.h>
3774
8b5b67000dc0 Cursor support added
Szymon Wilczek <kazeuser@gmail.com>
parents: 3771
diff changeset
    37
#define PACKETDATA ( PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_CURSOR)
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
    38
#define PACKETMODE 0
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
    39
#include <pktdef.h>
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    40
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    41
extern HANDLE* mice;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    42
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    43
extern int total_mice;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    44
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
    45
extern int tablet;
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    46
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    47
void
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    48
WIN_InitMouse(_THIS)
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    49
{
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    50
	int index=0;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    51
	RAWINPUTDEVICELIST *deviceList=NULL;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    52
	int devCount=0;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    53
	int i;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    54
	int tmp=0;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    55
	char* buffer=NULL;
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
    56
	char* tab="wacom";/*since windows does't give us handles to tablets, we have to detect a tablet by it's name*/
3779
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
    57
	const char *rdp = "rdp_mou";
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    58
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    59
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    60
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
    61
	/*we're checking for the number of rawinput devices*/
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
    62
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    63
	if(GetRawInputDeviceList(NULL,&devCount,sizeof(RAWINPUTDEVICELIST)))
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    64
	{
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    65
		return;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    66
	}
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    67
	else
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    68
	{
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    69
		deviceList = SDL_malloc(sizeof(RAWINPUTDEVICELIST)*devCount);
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    70
	}
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    71
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
    72
	/*we're getting the raw input device list*/
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
    73
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    74
	GetRawInputDeviceList(deviceList,&devCount,sizeof(RAWINPUTDEVICELIST));
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    75
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    76
	mice = SDL_malloc(devCount*sizeof(HANDLE));
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    77
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
    78
	/*we're getting the details of the devices*/
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
    79
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    80
	for(i=0;i<devCount;++i)
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    81
	{
3779
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
    82
		int is_rdp=0;
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    83
		int j;
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
    84
		int k;
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    85
		char *default_device_name="Pointing device xx";
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    86
		const char *reg_key_root = "System\\CurrentControlSet\\Enum\\";
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    87
		char *device_name=SDL_malloc(256*sizeof(char));
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    88
		char *key_name=NULL;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    89
		char *tmp_name=NULL;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    90
		LONG rc = 0;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    91
		HKEY hkey;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    92
		DWORD regtype = REG_SZ;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    93
		DWORD out=256*sizeof(char);
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    94
		SDL_Mouse mouse;
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
    95
		int l;
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
    96
		if(deviceList[i].dwType!=RIM_TYPEMOUSE) /*if a device isn't a mouse type we don't want it*/
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    97
		{
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    98
			continue;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
    99
		}
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   100
		if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, NULL, &tmp)<0)
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   101
		{
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   102
			continue;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   103
		}
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   104
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   105
		buffer = SDL_malloc((tmp+1)*sizeof(char));
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   106
		key_name = SDL_malloc(tmp + sizeof(reg_key_root)*sizeof(char));
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   107
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   108
		/*we're getting the device registry path and polishing it to get it's name,
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   109
		surely there must be an easier way, but we haven't found it yet*/
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   110
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   111
		if(GetRawInputDeviceInfoA(deviceList[i].hDevice, RIDI_DEVICENAME, buffer, &tmp)<0)
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   112
		{
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   113
			continue;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   114
		}
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   115
		buffer+=4;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   116
		tmp-=4;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   117
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   118
		tmp_name=buffer;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   119
		for(j=0;j<tmp;++j)
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   120
		{
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   121
			if(*tmp_name=='#')
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   122
			{
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   123
				*tmp_name='\\';
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   124
			}
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   125
			else if(*tmp_name=='{')
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   126
			{
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   127
				break;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   128
			}
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   129
			++tmp_name;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   130
		}
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   131
		*tmp_name='\0';
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   132
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   133
	SDL_memcpy(key_name, reg_key_root, SDL_strlen (reg_key_root));
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   134
    SDL_memcpy(key_name + (SDL_strlen (reg_key_root)), buffer, j + 1);
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   135
    
3779
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   136
	l=SDL_strlen(key_name);
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   137
	is_rdp=0;
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   138
	if(l>=7)
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   139
	{
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   140
		for(j=0;j<l-7;++j)
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   141
		{
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   142
			for(k=0;k<7;++k)
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   143
			{
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   144
				if(rdp[k]!=SDL_tolower((unsigned char)key_name[j+k]))
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   145
				{
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   146
					break;
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   147
				}
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   148
			}
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   149
			if(k==7)
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   150
			{
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   151
				is_rdp=1;
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   152
				break;
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   153
			}
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   154
		}
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   155
	}
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   156
	if(is_rdp==1)
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   157
	{
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   158
		SDL_free(buffer);
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   159
		SDL_free(key_name);
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   160
		SDL_free(device_name);
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   161
		is_rdp=0;
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   162
		continue;
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   163
	}
5f599ed92fb9 Small improvements
Szymon Wilczek <kazeuser@gmail.com>
parents: 3774
diff changeset
   164
	
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   165
	/*we're opening the registry key to get the mouse name*/
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   166
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   167
	rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &hkey);
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   168
    
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   169
	if (rc != ERROR_SUCCESS)
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   170
	{
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   171
		SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name));
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   172
	}
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   173
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   174
    rc = RegQueryValueExA(hkey, "DeviceDesc", NULL, &regtype, device_name, &out);
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   175
    RegCloseKey(hkey);
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   176
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   177
    if (rc != ERROR_SUCCESS)
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   178
	{
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   179
        SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name));
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   180
    }
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   181
	/*we're saving the handle to the device*/
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   182
	mice[index]=deviceList[i].hDevice;
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   183
	SDL_zero(mouse);
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   184
	SDL_SetIndexId(index,index);
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   185
	l=SDL_strlen(device_name);
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   186
	/*we're checking if the device isn't by any chance a tablet*/
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   187
	if(tablet==-1)
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   188
	{
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   189
		for(j=0;j<l-5;++j)
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   190
		{
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   191
			for(k=0;k<5;++k)
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   192
			{
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   193
				if(tab[k]!=SDL_tolower((unsigned char)device_name[j+k]))
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   194
				{
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   195
					break;
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   196
				}
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   197
			}
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   198
			if(k==5)
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   199
			{
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   200
				tablet=index;
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   201
				break;
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   202
			}
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   203
		}
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   204
	}
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   205
	/*if it's a tablet, let's read it's maximum and minimum pressure*/
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   206
	if(tablet==index)
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   207
	{
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   208
		AXIS pressure;
3774
8b5b67000dc0 Cursor support added
Szymon Wilczek <kazeuser@gmail.com>
parents: 3771
diff changeset
   209
		int cursors;
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   210
		WTInfo(WTI_DEVICES,DVC_NPRESSURE, &pressure);
3774
8b5b67000dc0 Cursor support added
Szymon Wilczek <kazeuser@gmail.com>
parents: 3771
diff changeset
   211
		WTInfo(WTI_DEVICES,DVC_NCSRTYPES, &cursors);
8b5b67000dc0 Cursor support added
Szymon Wilczek <kazeuser@gmail.com>
parents: 3771
diff changeset
   212
		data->mouse = SDL_AddMouse(&mouse, index,device_name,pressure.axMax,pressure.axMin,cursors);
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   213
	}
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   214
	else
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   215
	{
3774
8b5b67000dc0 Cursor support added
Szymon Wilczek <kazeuser@gmail.com>
parents: 3771
diff changeset
   216
		data->mouse = SDL_AddMouse(&mouse, index,device_name,0,0,1);
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   217
	}
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   218
	++index;
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   219
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   220
	SDL_free(buffer);
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   221
	SDL_free(key_name);
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   222
	}
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   223
	total_mice=index;
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   224
	SDL_free(deviceList);
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   225
}
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   226
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   227
void
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   228
WIN_QuitMouse(_THIS)
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   229
{
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   230
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
3771
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   231
	/*let's delete all of the mouses*/
8cc36a399a12 comments added and improved code look(windows part)
Szymon Wilczek <kazeuser@gmail.com>
parents: 3770
diff changeset
   232
	SDL_MouseQuit();
3768
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   233
}
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   234
1b87a8beab9d Project part1
Szymon Wilczek <kazeuser@gmail.com>
parents: 1895
diff changeset
   235
/* vi: set ts=4 sw=4 expandtab: */
3770
81b649bad6d2 Implementation finished
Szymon Wilczek <kazeuser@gmail.com>
parents: 3768
diff changeset
   236