src/video/gem/SDL_gemevents.c
author Patrice Mandin <patmandin@gmail.com>
Fri, 12 Oct 2012 18:25:28 +0200
branchSDL-1.2
changeset 6582 8b7e21749630
parent 6572 0d391c407a4f
child 6583 15c1dc6ac329
permissions -rw-r--r--
gem: Move special keys handling in a separate function
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
6137
4720145f848b Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 5867
diff changeset
     3
    Copyright (C) 1997-2012 Sam Lantinga
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1310
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1310
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1310
diff changeset
    13
    Lesser General Public License for more details.
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1310
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1310
diff changeset
    16
    License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1310
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
    Sam Lantinga
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
    slouken@libsdl.org
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    22
#include "SDL_config.h"
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
/*
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
 * GEM SDL video driver implementation
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
 * inspired from the Dummy SDL driver
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
 * 
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
 * Patrice Mandin
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
 * and work from
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
 * Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
 */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include <gem.h>
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    35
#include "../../events/SDL_sysevents.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
    36
#include "../../events/SDL_events_c.h"
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
#include "SDL_gemvideo.h"
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
#include "SDL_gemevents_c.h"
5649
02ab15cfa992 Fix various warnings for uninitialized or unused variables and functions
Patrice Mandin <patmandin@gmail.com>
parents: 4564
diff changeset
    39
#include "SDL_gemmouse_c.h"
1412
a8181c4040b8 Fixed include files
Patrice Mandin <patmandin@gmail.com>
parents: 1402
diff changeset
    40
#include "../ataricommon/SDL_atarikeys.h"	/* for keyboard scancodes */
a8181c4040b8 Fixed include files
Patrice Mandin <patmandin@gmail.com>
parents: 1402
diff changeset
    41
#include "../ataricommon/SDL_atarievents_c.h"
a8181c4040b8 Fixed include files
Patrice Mandin <patmandin@gmail.com>
parents: 1402
diff changeset
    42
#include "../ataricommon/SDL_xbiosevents_c.h"
1420
2405517b5eab Added preliminary support for MiNT /dev/mouse driver (disabled atm)
Patrice Mandin <patmandin@gmail.com>
parents: 1412
diff changeset
    43
#include "../ataricommon/SDL_ataridevmouse_c.h"
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
/* Variables */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
/* Functions prototypes */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
static int do_messages(_THIS, short *message);
6582
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
    53
static void do_keyboard(short kc);
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
    54
static void do_keyboard_special(short ks);
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
    55
static void do_mouse(_THIS, short mx, short my, short mb);
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
/* Functions */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
void GEM_InitOSKeymap(_THIS)
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
{
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    61
	SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    62
	SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
	/* Mouse init */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
	GEM_mouse_relative = SDL_FALSE;
3861
c3625a895caf Use new keyboard mapping routines
Patrice Mandin <patmandin@gmail.com>
parents: 3854
diff changeset
    66
c3625a895caf Use new keyboard mapping routines
Patrice Mandin <patmandin@gmail.com>
parents: 3854
diff changeset
    67
	SDL_Atari_InitInternalKeymap(this);
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
void GEM_PumpEvents(_THIS)
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
{
6582
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
    72
	short prevkc;
4564
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
    73
	static short maskmouseb=0;
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
	int i;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
	SDL_keysym	keysym;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    77
	SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
6582
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
    78
	prevkc = 0;
4564
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
    79
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
	for (;;)
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
	{
1092
1f37386ef508 Forgot variable declaration
Patrice Mandin <patmandin@gmail.com>
parents: 1091
diff changeset
    82
		int quit, resultat, event_mask, mouse_event;
319
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
    83
		short buffer[8], kc;
1067
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
    84
		short x2,y2,w2,h2;
4564
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
    85
		short mousex, mousey, mouseb, dummy;
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
    86
		short kstate;
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
1089
b3f7c4af00e0 Don't use both mouse events for the same task
Patrice Mandin <patmandin@gmail.com>
parents: 1088
diff changeset
    88
		quit =
b3f7c4af00e0 Don't use both mouse events for the same task
Patrice Mandin <patmandin@gmail.com>
parents: 1088
diff changeset
    89
			mouse_event =
b3f7c4af00e0 Don't use both mouse events for the same task
Patrice Mandin <patmandin@gmail.com>
parents: 1088
diff changeset
    90
			x2=y2=w2=h2 = 0;
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
4564
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
    92
		event_mask = MU_MESAG|MU_TIMER|MU_KEYBD|MU_BUTTON;
1067
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
    93
		if (!GEM_fullscreen && (GEM_handle>=0)) {
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
    94
			wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
1089
b3f7c4af00e0 Don't use both mouse events for the same task
Patrice Mandin <patmandin@gmail.com>
parents: 1088
diff changeset
    95
			event_mask |= MU_M1;
4060
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
    96
			mouse_event = ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
    97
				== SDL_APPMOUSEFOCUS) ? MO_LEAVE : MO_ENTER;
1067
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
    98
		}
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
    99
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
		resultat = evnt_multi(
1067
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   101
			event_mask,
4564
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
   102
			0x101,7,maskmouseb,
1089
b3f7c4af00e0 Don't use both mouse events for the same task
Patrice Mandin <patmandin@gmail.com>
parents: 1088
diff changeset
   103
			mouse_event,x2,y2,w2,h2,
b3f7c4af00e0 Don't use both mouse events for the same task
Patrice Mandin <patmandin@gmail.com>
parents: 1088
diff changeset
   104
			0,0,0,0,0,
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
			buffer,
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
			10,
4564
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
   107
			&mousex,&mousey,&mouseb,&kstate,&kc,&dummy
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
		);
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
		/* Message event ? */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
		if (resultat & MU_MESAG)
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
			quit = do_messages(this, buffer);
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
6582
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   114
		/* Special keys ? */
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   115
		if (resultat & (MU_KEYBD|MU_BUTTON))
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   116
			do_keyboard_special(kstate);
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   117
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
		/* Keyboard event ? */
319
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   119
		if (resultat & MU_KEYBD) {
6582
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   120
			if (prevkc != kc) {
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   121
				do_keyboard(kc);
6572
0d391c407a4f Use variables for what they were created for
Patrice Mandin <patmandin@gmail.com>
parents: 6137
diff changeset
   122
				prevkc = kc;
319
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   123
			} else {
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   124
				/* Avoid looping, if repeating same key */
6582
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   125
				quit = 1;
319
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   126
			}
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   127
		}
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
1067
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   129
		/* Mouse entering/leaving window */
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   130
		if (resultat & MU_M1) {
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   131
			if (this->input_grab == SDL_GRAB_OFF) {
4060
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   132
				/* Switch mouse focus state */
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   133
				SDL_PrivateAppActive((mouse_event == MO_ENTER),
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   134
					SDL_APPMOUSEFOCUS);
1067
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   135
			}
4060
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   136
			GEM_CheckMouseMode(this);
1067
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   137
		}
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   138
4564
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
   139
		/* Mouse button event ? */
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
   140
		if (resultat & MU_BUTTON) {
6582
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   141
			do_mouse(this, mousex, mousey, mouseb);
4564
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
   142
			maskmouseb = mouseb & 7;
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
   143
		}
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
   144
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
		/* Timer event ? */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
		if ((resultat & MU_TIMER) || quit)
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
			break;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
	}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
319
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   150
	/* Now generate keyboard events */
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
		/* Key pressed ? */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
		if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
1209
a55ac374271c Added preliminary missingtranslation from Atari to Unicode charset
Patrice Mandin <patmandin@gmail.com>
parents: 1092
diff changeset
   154
			SDL_PrivateKeyboard(SDL_PRESSED,
3861
c3625a895caf Use new keyboard mapping routines
Patrice Mandin <patmandin@gmail.com>
parents: 3854
diff changeset
   155
				SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
			
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
		/* Key unpressed ? */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
		if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
1209
a55ac374271c Added preliminary missingtranslation from Atari to Unicode charset
Patrice Mandin <patmandin@gmail.com>
parents: 1092
diff changeset
   159
			SDL_PrivateKeyboard(SDL_RELEASED,
3861
c3625a895caf Use new keyboard mapping routines
Patrice Mandin <patmandin@gmail.com>
parents: 3854
diff changeset
   160
				SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
	}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   163
	SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
996
54bb19455081 Forgot to change window title in the normal case
Patrice Mandin <patmandin@gmail.com>
parents: 964
diff changeset
   164
54bb19455081 Forgot to change window title in the normal case
Patrice Mandin <patmandin@gmail.com>
parents: 964
diff changeset
   165
	/* Refresh window name ? */
54bb19455081 Forgot to change window title in the normal case
Patrice Mandin <patmandin@gmail.com>
parents: 964
diff changeset
   166
	if (GEM_refresh_name) {
4059
57b017e6aebf Simplify setting window title
Patrice Mandin <patmandin@gmail.com>
parents: 3861
diff changeset
   167
		const char *window_name =
57b017e6aebf Simplify setting window title
Patrice Mandin <patmandin@gmail.com>
parents: 3861
diff changeset
   168
			(SDL_GetAppState() & SDL_APPACTIVE)
57b017e6aebf Simplify setting window title
Patrice Mandin <patmandin@gmail.com>
parents: 3861
diff changeset
   169
			? GEM_title_name : GEM_icon_name;
57b017e6aebf Simplify setting window title
Patrice Mandin <patmandin@gmail.com>
parents: 3861
diff changeset
   170
		if (window_name) {
57b017e6aebf Simplify setting window title
Patrice Mandin <patmandin@gmail.com>
parents: 3861
diff changeset
   171
			wind_set(GEM_handle,WF_NAME,
57b017e6aebf Simplify setting window title
Patrice Mandin <patmandin@gmail.com>
parents: 3861
diff changeset
   172
				(short)(((unsigned long)window_name)>>16),
57b017e6aebf Simplify setting window title
Patrice Mandin <patmandin@gmail.com>
parents: 3861
diff changeset
   173
				(short)(((unsigned long)window_name) & 0xffff),
57b017e6aebf Simplify setting window title
Patrice Mandin <patmandin@gmail.com>
parents: 3861
diff changeset
   174
				0,0);
996
54bb19455081 Forgot to change window title in the normal case
Patrice Mandin <patmandin@gmail.com>
parents: 964
diff changeset
   175
		}
54bb19455081 Forgot to change window title in the normal case
Patrice Mandin <patmandin@gmail.com>
parents: 964
diff changeset
   176
		GEM_refresh_name = SDL_FALSE;
54bb19455081 Forgot to change window title in the normal case
Patrice Mandin <patmandin@gmail.com>
parents: 964
diff changeset
   177
	}
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
static int do_messages(_THIS, short *message)
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
{
5867
94e0116059f4 Remove unused variables
Patrice Mandin <patmandin@gmail.com>
parents: 5649
diff changeset
   182
	int quit, check_mouse_mode;
922
7b920743ce57 Correctly set window size if resized or maximized
Patrice Mandin <patmandin@gmail.com>
parents: 919
diff changeset
   183
	short x2,y2,w2,h2;
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
4060
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   185
	quit = check_mouse_mode = 0;
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
	switch (message[0]) {
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
		case WM_CLOSED:
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
		case AP_TERM:    
5867
94e0116059f4 Remove unused variables
Patrice Mandin <patmandin@gmail.com>
parents: 5649
diff changeset
   189
			SDL_PrivateQuit();
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
			quit=1;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
			break;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
		case WM_MOVED:
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
			wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
			break;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
		case WM_TOPPED:
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
			wind_set(message[3],WF_TOP,message[4],0,0,0);
1091
67b7f0f410a2 Correctly process top/bottom event messages
Patrice Mandin <patmandin@gmail.com>
parents: 1090
diff changeset
   197
			/* Continue with TOP event processing */
67b7f0f410a2 Correctly process top/bottom event messages
Patrice Mandin <patmandin@gmail.com>
parents: 1090
diff changeset
   198
		case WM_ONTOP:
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
			SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
1074
936da0056ed3 Save/restore system palette when application topped/untopped
Patrice Mandin <patmandin@gmail.com>
parents: 1073
diff changeset
   200
			if (VDI_setpalette) {
936da0056ed3 Save/restore system palette when application topped/untopped
Patrice Mandin <patmandin@gmail.com>
parents: 1073
diff changeset
   201
				VDI_setpalette(this, VDI_curpalette);
936da0056ed3 Save/restore system palette when application topped/untopped
Patrice Mandin <patmandin@gmail.com>
parents: 1073
diff changeset
   202
			}
4060
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   203
			check_mouse_mode = 1;
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
			break;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
		case WM_REDRAW:
964
d9209754ebee Prevent redraws till internal buffers are correctly setup
Patrice Mandin <patmandin@gmail.com>
parents: 928
diff changeset
   206
			if (!GEM_lock_redraw) {
d9209754ebee Prevent redraws till internal buffers are correctly setup
Patrice Mandin <patmandin@gmail.com>
parents: 928
diff changeset
   207
				GEM_wind_redraw(this, message[3],&message[4]);
d9209754ebee Prevent redraws till internal buffers are correctly setup
Patrice Mandin <patmandin@gmail.com>
parents: 928
diff changeset
   208
			}
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
			break;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
		case WM_ICONIFY:
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
		case WM_ALLICONIFY:
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
			wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
			/* If we're active, make ourselves inactive */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
			if ( SDL_GetAppState() & SDL_APPACTIVE ) {
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
				/* Send an internal deactivate event */
1088
6091b9ca1a97 Don't generate multiple mouse focus events
Patrice Mandin <patmandin@gmail.com>
parents: 1074
diff changeset
   216
				SDL_PrivateAppActive(0, SDL_APPACTIVE);
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
			}
736
028e03e273c8 Use new C2P routine + corrections for iconification window
Patrice Mandin <patmandin@gmail.com>
parents: 319
diff changeset
   218
			/* Update window title */
028e03e273c8 Use new C2P routine + corrections for iconification window
Patrice Mandin <patmandin@gmail.com>
parents: 319
diff changeset
   219
			if (GEM_refresh_name && GEM_icon_name) {
028e03e273c8 Use new C2P routine + corrections for iconification window
Patrice Mandin <patmandin@gmail.com>
parents: 319
diff changeset
   220
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
028e03e273c8 Use new C2P routine + corrections for iconification window
Patrice Mandin <patmandin@gmail.com>
parents: 319
diff changeset
   221
				GEM_refresh_name = SDL_FALSE;
028e03e273c8 Use new C2P routine + corrections for iconification window
Patrice Mandin <patmandin@gmail.com>
parents: 319
diff changeset
   222
			}
4060
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   223
			check_mouse_mode = 1;
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
			break;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
		case WM_UNICONIFY:
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
			wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
			/* If we're not active, make ourselves active */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
			if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
				/* Send an internal activate event */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
				SDL_PrivateAppActive(1, SDL_APPACTIVE);
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
			}
736
028e03e273c8 Use new C2P routine + corrections for iconification window
Patrice Mandin <patmandin@gmail.com>
parents: 319
diff changeset
   232
			if (GEM_refresh_name && GEM_title_name) {
028e03e273c8 Use new C2P routine + corrections for iconification window
Patrice Mandin <patmandin@gmail.com>
parents: 319
diff changeset
   233
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
028e03e273c8 Use new C2P routine + corrections for iconification window
Patrice Mandin <patmandin@gmail.com>
parents: 319
diff changeset
   234
				GEM_refresh_name = SDL_FALSE;
028e03e273c8 Use new C2P routine + corrections for iconification window
Patrice Mandin <patmandin@gmail.com>
parents: 319
diff changeset
   235
			}
4060
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   236
			check_mouse_mode = 1;
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
			break;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
		case WM_SIZED:
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
			wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
964
d9209754ebee Prevent redraws till internal buffers are correctly setup
Patrice Mandin <patmandin@gmail.com>
parents: 928
diff changeset
   240
			wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
			GEM_win_fulled = SDL_FALSE;		/* Cancel maximized flag */
964
d9209754ebee Prevent redraws till internal buffers are correctly setup
Patrice Mandin <patmandin@gmail.com>
parents: 928
diff changeset
   242
			GEM_lock_redraw = SDL_TRUE;		/* Prevent redraw till buffers resized */
922
7b920743ce57 Correctly set window size if resized or maximized
Patrice Mandin <patmandin@gmail.com>
parents: 919
diff changeset
   243
			SDL_PrivateResize(w2, h2);
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
			break;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
		case WM_FULLED:
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
			{
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
				short x,y,w,h;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
				if (GEM_win_fulled) {
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
					wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
					GEM_win_fulled = SDL_FALSE;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
				} else {
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
					x = GEM_desk_x;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
					y = GEM_desk_y;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
					w = GEM_desk_w;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
					h = GEM_desk_h;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
					GEM_win_fulled = SDL_TRUE;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
				}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
				wind_set (message[3], WF_CURRXYWH, x, y, w, h);
922
7b920743ce57 Correctly set window size if resized or maximized
Patrice Mandin <patmandin@gmail.com>
parents: 919
diff changeset
   260
				wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
964
d9209754ebee Prevent redraws till internal buffers are correctly setup
Patrice Mandin <patmandin@gmail.com>
parents: 928
diff changeset
   261
				GEM_lock_redraw = SDL_TRUE;		/* Prevent redraw till buffers resized */
922
7b920743ce57 Correctly set window size if resized or maximized
Patrice Mandin <patmandin@gmail.com>
parents: 919
diff changeset
   262
				SDL_PrivateResize(w2, h2);
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
			}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
			break;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
		case WM_BOTTOMED:
1091
67b7f0f410a2 Correctly process top/bottom event messages
Patrice Mandin <patmandin@gmail.com>
parents: 1090
diff changeset
   266
			wind_set(message[3],WF_BOTTOM,0,0,0,0);
67b7f0f410a2 Correctly process top/bottom event messages
Patrice Mandin <patmandin@gmail.com>
parents: 1090
diff changeset
   267
			/* Continue with BOTTOM event processing */
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
		case WM_UNTOPPED:
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
			SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
1074
936da0056ed3 Save/restore system palette when application topped/untopped
Patrice Mandin <patmandin@gmail.com>
parents: 1073
diff changeset
   270
			if (VDI_setpalette) {
936da0056ed3 Save/restore system palette when application topped/untopped
Patrice Mandin <patmandin@gmail.com>
parents: 1073
diff changeset
   271
				VDI_setpalette(this, VDI_oldpalette);
936da0056ed3 Save/restore system palette when application topped/untopped
Patrice Mandin <patmandin@gmail.com>
parents: 1073
diff changeset
   272
			}
4060
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   273
			check_mouse_mode = 1;
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
			break;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
	}
4060
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   276
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   277
	if (check_mouse_mode) {
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   278
		GEM_CheckMouseMode(this);
0b4ebec67cad Call GEM_CheckMouseMode everytime something may change mouse form, and do it properly
Patrice Mandin <patmandin@gmail.com>
parents: 4059
diff changeset
   279
	}
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
	
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
	return quit;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
6582
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   284
static void do_keyboard(short kc)
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
{
3861
c3625a895caf Use new keyboard mapping routines
Patrice Mandin <patmandin@gmail.com>
parents: 3854
diff changeset
   286
	int scancode;
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
	if (kc) {
3861
c3625a895caf Use new keyboard mapping routines
Patrice Mandin <patmandin@gmail.com>
parents: 3854
diff changeset
   289
		scancode=(kc>>8) & (ATARIBIOS_MAXKEYS-1);
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
		gem_currentkeyboard[scancode]=0xFF;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
	}
6582
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   292
}
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
6582
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   294
static void do_keyboard_special(short ks)
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   295
{
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
	/* Read special keys */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
	if (ks & K_RSHIFT)
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
	if (ks & K_LSHIFT)
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
	if (ks & K_CTRL)
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
	if (ks & K_ALT)
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
6582
8b7e21749630 gem: Move special keys handling in a separate function
Patrice Mandin <patmandin@gmail.com>
parents: 6572
diff changeset
   307
static void do_mouse(_THIS, short mx, short my, short mb)
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
{
319
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   309
	static short prevmousex=0, prevmousey=0, prevmouseb=0;
926
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   310
	short x2, y2, w2, h2;
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   311
1067
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   312
	/* Don't return mouse events if out of window */
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   313
	if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) {
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   314
		return;
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   315
	}
f73b199bcd75 Better mouse lose/gain focus
Patrice Mandin <patmandin@gmail.com>
parents: 1065
diff changeset
   316
926
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   317
	/* Retrieve window coords, and generate mouse events accordingly */
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   318
	x2 = y2 = 0;
928
6c87754f324c Forgot to initialize maximum position for mouse
Patrice Mandin <patmandin@gmail.com>
parents: 927
diff changeset
   319
	w2 = VDI_w;
6c87754f324c Forgot to initialize maximum position for mouse
Patrice Mandin <patmandin@gmail.com>
parents: 927
diff changeset
   320
	h2 = VDI_h;
926
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   321
	if ((!GEM_fullscreen) && (GEM_handle>=0)) {
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   322
		wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   323
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   324
		/* Do not generate mouse button event if out of window working area */
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   325
		if ((mx<x2) || (mx>=x2+w2) || (my<y2) || (my>=y2+h2)) {
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   326
			mb=prevmouseb;
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   327
		}
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   328
	}
319
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   329
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
	/* Mouse motion ? */
1267
fdc7ef6ecab4 Correctly manage mouse relative motion
Patrice Mandin <patmandin@gmail.com>
parents: 1237
diff changeset
   331
	if (GEM_mouse_relative) {
1420
2405517b5eab Added preliminary support for MiNT /dev/mouse driver (disabled atm)
Patrice Mandin <patmandin@gmail.com>
parents: 1412
diff changeset
   332
		if (GEM_usedevmouse) {
2405517b5eab Added preliminary support for MiNT /dev/mouse driver (disabled atm)
Patrice Mandin <patmandin@gmail.com>
parents: 1412
diff changeset
   333
			SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
2405517b5eab Added preliminary support for MiNT /dev/mouse driver (disabled atm)
Patrice Mandin <patmandin@gmail.com>
parents: 1412
diff changeset
   334
		} else {
2405517b5eab Added preliminary support for MiNT /dev/mouse driver (disabled atm)
Patrice Mandin <patmandin@gmail.com>
parents: 1412
diff changeset
   335
			SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
2405517b5eab Added preliminary support for MiNT /dev/mouse driver (disabled atm)
Patrice Mandin <patmandin@gmail.com>
parents: 1412
diff changeset
   336
		}
1267
fdc7ef6ecab4 Correctly manage mouse relative motion
Patrice Mandin <patmandin@gmail.com>
parents: 1237
diff changeset
   337
	} else {
fdc7ef6ecab4 Correctly manage mouse relative motion
Patrice Mandin <patmandin@gmail.com>
parents: 1237
diff changeset
   338
		if ((prevmousex!=mx) || (prevmousey!=my)) {
926
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   339
			int posx, posy;
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   340
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   341
			/* Give mouse position relative to window position */
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   342
			posx = mx - x2;
927
c5689bd09eaa Wrong check for minimum mouse position
Patrice Mandin <patmandin@gmail.com>
parents: 926
diff changeset
   343
			if (posx<0) posx = 0;
926
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   344
			if (posx>w2) posx = w2-1;
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   345
			posy = my - y2;
927
c5689bd09eaa Wrong check for minimum mouse position
Patrice Mandin <patmandin@gmail.com>
parents: 926
diff changeset
   346
			if (posy<0) posy = 0;
926
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   347
			if (posy>h2) posy = h2-1;
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   348
83db694556eb Give mouse position relative to window position, and do not generate mouse button event if outside of the window
Patrice Mandin <patmandin@gmail.com>
parents: 922
diff changeset
   349
			SDL_PrivateMouseMotion(0, 0, posx, posy);
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   350
		}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
		prevmousex = mx;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
		prevmousey = my;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
	}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
	/* Mouse button ? */
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
	if (prevmouseb!=mb) {
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
		int i;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
4564
5002d6aeb85c Use proper GEM API to handle mouse button events
Patrice Mandin <patmandin@gmail.com>
parents: 4159
diff changeset
   359
		for (i=0;i<3;i++) {
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
			int curbutton, prevbutton;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
		
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
			curbutton = mb & (1<<i);
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
			prevbutton = prevmouseb & (1<<i);
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
		
319
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   365
			if (curbutton && !prevbutton) {
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   366
				SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
			}
319
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   368
			if (!curbutton && prevbutton) {
189a6a3416c7 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
   369
				SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
281
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   370
			}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   371
		}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   372
		prevmouseb = mb;
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   373
	}
c5010ab8ba35 Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   374
}