src/video/ataricommon/SDL_ataridevmouse.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1420 2405517b5eab
child 1668 4da1ee79c9af
     1.1 --- a/src/video/ataricommon/SDL_ataridevmouse.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/video/ataricommon/SDL_ataridevmouse.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -44,116 +44,123 @@
     1.4  
     1.5  /* Functions */
     1.6  
     1.7 -int SDL_AtariDevMouse_Open(void)
     1.8 +int
     1.9 +SDL_AtariDevMouse_Open (void)
    1.10  {
    1.11 -	int r;
    1.12 -	const char *mousedev;
    1.13 +    int r;
    1.14 +    const char *mousedev;
    1.15  
    1.16 -	/*
    1.17 -		TODO: Fix the MiNT device driver, that locks mouse for other
    1.18 -		applications, so this is disabled till fixed
    1.19 -	 */
    1.20 -	return 0;
    1.21 +    /*
    1.22 +       TODO: Fix the MiNT device driver, that locks mouse for other
    1.23 +       applications, so this is disabled till fixed
    1.24 +     */
    1.25 +    return 0;
    1.26  
    1.27 -	/* First, try SDL_MOUSEDEV device */
    1.28 -	mousedev = SDL_getenv("SDL_MOUSEDEV");
    1.29 -	if (!mousedev) {
    1.30 -		handle = open(mousedev, 0);
    1.31 -	}
    1.32 +    /* First, try SDL_MOUSEDEV device */
    1.33 +    mousedev = SDL_getenv ("SDL_MOUSEDEV");
    1.34 +    if (!mousedev) {
    1.35 +        handle = open (mousedev, 0);
    1.36 +    }
    1.37  
    1.38 -	/* Failed, try default device */
    1.39 -	if (handle<0) {
    1.40 -		handle = open(DEVICE_NAME, 0);
    1.41 -	}
    1.42 +    /* Failed, try default device */
    1.43 +    if (handle < 0) {
    1.44 +        handle = open (DEVICE_NAME, 0);
    1.45 +    }
    1.46  
    1.47 -	if (handle<0) {
    1.48 -		handle = -1;
    1.49 -		return 0;
    1.50 -	}
    1.51 +    if (handle < 0) {
    1.52 +        handle = -1;
    1.53 +        return 0;
    1.54 +    }
    1.55  
    1.56 -	/* Set non blocking mode */
    1.57 -	r = fcntl(handle, F_GETFL, 0);
    1.58 -	if (r<0) {
    1.59 -		close(handle);
    1.60 -		handle = -1;
    1.61 -		return 0;
    1.62 -	}
    1.63 +    /* Set non blocking mode */
    1.64 +    r = fcntl (handle, F_GETFL, 0);
    1.65 +    if (r < 0) {
    1.66 +        close (handle);
    1.67 +        handle = -1;
    1.68 +        return 0;
    1.69 +    }
    1.70  
    1.71 -	r |= O_NDELAY;
    1.72 +    r |= O_NDELAY;
    1.73  
    1.74 -	r = fcntl(handle, F_SETFL, r);
    1.75 -	if (r<0) {
    1.76 -		close(handle);
    1.77 -		handle = -1;
    1.78 -		return 0;
    1.79 -	}
    1.80 +    r = fcntl (handle, F_SETFL, r);
    1.81 +    if (r < 0) {
    1.82 +        close (handle);
    1.83 +        handle = -1;
    1.84 +        return 0;
    1.85 +    }
    1.86  
    1.87 -	prev_mouseb = 7;
    1.88 -	return 1;
    1.89 +    prev_mouseb = 7;
    1.90 +    return 1;
    1.91  }
    1.92  
    1.93 -void SDL_AtariDevMouse_Close(void)
    1.94 +void
    1.95 +SDL_AtariDevMouse_Close (void)
    1.96  {
    1.97 -	if (handle>0) {
    1.98 -		close(handle);
    1.99 -		handle = -1;
   1.100 -	}
   1.101 +    if (handle > 0) {
   1.102 +        close (handle);
   1.103 +        handle = -1;
   1.104 +    }
   1.105  }
   1.106  
   1.107 -static int atari_GetButton(int button)
   1.108 +static int
   1.109 +atari_GetButton (int button)
   1.110  {
   1.111 -	switch(button)
   1.112 -	{
   1.113 -		case 0:
   1.114 -			return SDL_BUTTON_RIGHT;
   1.115 -		case 1:
   1.116 -			return SDL_BUTTON_MIDDLE;
   1.117 -		default:
   1.118 -			break;
   1.119 -	}
   1.120 +    switch (button) {
   1.121 +    case 0:
   1.122 +        return SDL_BUTTON_RIGHT;
   1.123 +    case 1:
   1.124 +        return SDL_BUTTON_MIDDLE;
   1.125 +    default:
   1.126 +        break;
   1.127 +    }
   1.128  
   1.129 -	return SDL_BUTTON_LEFT;
   1.130 +    return SDL_BUTTON_LEFT;
   1.131  }
   1.132  
   1.133 -void SDL_AtariDevMouse_PostMouseEvents(_THIS, SDL_bool buttonEvents)
   1.134 +void
   1.135 +SDL_AtariDevMouse_PostMouseEvents (_THIS, SDL_bool buttonEvents)
   1.136  {
   1.137 -	unsigned char buffer[3];
   1.138 -	int mousex, mousey;
   1.139 +    unsigned char buffer[3];
   1.140 +    int mousex, mousey;
   1.141  
   1.142 -	if (handle<0) {
   1.143 -		return;
   1.144 -	}
   1.145 +    if (handle < 0) {
   1.146 +        return;
   1.147 +    }
   1.148  
   1.149 -	mousex = mousey = 0;
   1.150 -	while (read(handle, buffer, sizeof(buffer))==sizeof(buffer)) {
   1.151 -		mouseb = buffer[0] & 7;
   1.152 -		mousex += (char) buffer[1];
   1.153 -		mousey += (char) buffer[2];
   1.154 +    mousex = mousey = 0;
   1.155 +    while (read (handle, buffer, sizeof (buffer)) == sizeof (buffer)) {
   1.156 +        mouseb = buffer[0] & 7;
   1.157 +        mousex += (char) buffer[1];
   1.158 +        mousey += (char) buffer[2];
   1.159  
   1.160 -		/* Mouse button events */
   1.161 -		if (buttonEvents && (mouseb != prev_mouseb)) {
   1.162 -			int i;
   1.163 +        /* Mouse button events */
   1.164 +        if (buttonEvents && (mouseb != prev_mouseb)) {
   1.165 +            int i;
   1.166  
   1.167 -			for (i=0;i<3;i++) {
   1.168 -				int curbutton, prevbutton;
   1.169 +            for (i = 0; i < 3; i++) {
   1.170 +                int curbutton, prevbutton;
   1.171  
   1.172 -				curbutton = mouseb & (1<<i);
   1.173 -				prevbutton = prev_mouseb & (1<<i);
   1.174 -			
   1.175 -				if (curbutton && !prevbutton) {
   1.176 -					SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
   1.177 -				}
   1.178 -				if (!curbutton && prevbutton) {
   1.179 -					SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
   1.180 -				}
   1.181 -			}
   1.182 +                curbutton = mouseb & (1 << i);
   1.183 +                prevbutton = prev_mouseb & (1 << i);
   1.184  
   1.185 -			prev_mouseb = mouseb;
   1.186 -		}
   1.187 -	}
   1.188 +                if (curbutton && !prevbutton) {
   1.189 +                    SDL_PrivateMouseButton (SDL_RELEASED,
   1.190 +                                            atari_GetButton (i), 0, 0);
   1.191 +                }
   1.192 +                if (!curbutton && prevbutton) {
   1.193 +                    SDL_PrivateMouseButton (SDL_PRESSED,
   1.194 +                                            atari_GetButton (i), 0, 0);
   1.195 +                }
   1.196 +            }
   1.197  
   1.198 -	/* Mouse motion event */
   1.199 -	if (mousex || mousey) {
   1.200 -		SDL_PrivateMouseMotion(0, 1, mousex, -mousey);
   1.201 -	}
   1.202 +            prev_mouseb = mouseb;
   1.203 +        }
   1.204 +    }
   1.205 +
   1.206 +    /* Mouse motion event */
   1.207 +    if (mousex || mousey) {
   1.208 +        SDL_PrivateMouseMotion (0, 1, mousex, -mousey);
   1.209 +    }
   1.210  }
   1.211 +
   1.212 +/* vi: set ts=4 sw=4 expandtab: */