src/video/gem/SDL_gemevents.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1420 2405517b5eab
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

The headers are being converted to automatically generate doxygen documentation.
slouken@281
     1
/*
slouken@281
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@281
     4
slouken@281
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@281
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@281
     9
slouken@281
    10
    This library is distributed in the hope that it will be useful,
slouken@281
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@281
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@281
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@281
    18
slouken@281
    19
    Sam Lantinga
slouken@281
    20
    slouken@libsdl.org
slouken@281
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@281
    23
slouken@281
    24
/*
slouken@281
    25
 * GEM SDL video driver implementation
slouken@281
    26
 * inspired from the Dummy SDL driver
slouken@281
    27
 * 
slouken@281
    28
 * Patrice Mandin
slouken@281
    29
 * and work from
slouken@281
    30
 * Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
slouken@281
    31
 */
slouken@281
    32
slouken@281
    33
#include <gem.h>
slouken@281
    34
slouken@1361
    35
#include "../../events/SDL_sysevents.h"
slouken@1361
    36
#include "../../events/SDL_events_c.h"
slouken@281
    37
#include "SDL_gemvideo.h"
slouken@281
    38
#include "SDL_gemevents_c.h"
slouken@1662
    39
#include "../ataricommon/SDL_atarikeys.h"       /* for keyboard scancodes */
patmandin@1412
    40
#include "../ataricommon/SDL_atarievents_c.h"
patmandin@1412
    41
#include "../ataricommon/SDL_xbiosevents_c.h"
patmandin@1420
    42
#include "../ataricommon/SDL_ataridevmouse_c.h"
slouken@281
    43
slouken@281
    44
/* Defines */
slouken@281
    45
slouken@281
    46
#define ATARIBIOS_MAXKEYS 128
slouken@281
    47
slouken@281
    48
/* Variables */
slouken@281
    49
slouken@281
    50
static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    51
static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    52
static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
slouken@281
    53
slouken@281
    54
/* The translation tables from a console scancode to a SDL keysym */
slouken@281
    55
static SDLKey keymap[ATARIBIOS_MAXKEYS];
slouken@281
    56
slouken@281
    57
/* Functions prototypes */
slouken@281
    58
slouken@1662
    59
static SDL_keysym *TranslateKey (int scancode, int asciicode,
slouken@1662
    60
                                 SDL_keysym * keysym, SDL_bool pressed);
slouken@1662
    61
static int do_messages (_THIS, short *message);
slouken@1662
    62
static void do_keyboard (short kc, short ks);
slouken@1662
    63
static void do_mouse (_THIS, short mx, short my, short mb, short ks);
slouken@281
    64
slouken@281
    65
/* Functions */
slouken@281
    66
slouken@1662
    67
static SDL_keysym *
slouken@1662
    68
TranslateKey (int scancode, int asciicode, SDL_keysym * keysym,
slouken@1662
    69
              SDL_bool pressed)
slouken@281
    70
{
slouken@1662
    71
    /* Set the keysym information */
slouken@1662
    72
    keysym->scancode = scancode;
slouken@281
    73
slouken@1662
    74
    if (asciicode)
slouken@1662
    75
        keysym->sym = asciicode;
slouken@1662
    76
    else
slouken@1662
    77
        keysym->sym = keymap[scancode];
slouken@281
    78
slouken@1662
    79
    keysym->mod = KMOD_NONE;
slouken@1662
    80
    keysym->unicode = 0;
slouken@1662
    81
    if (SDL_TranslateUNICODE && pressed) {
slouken@1662
    82
        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
slouken@1662
    83
    }
slouken@281
    84
slouken@1662
    85
    return (keysym);
slouken@281
    86
}
slouken@281
    87
slouken@1662
    88
void
slouken@1662
    89
GEM_InitOSKeymap (_THIS)
slouken@281
    90
{
slouken@1662
    91
    int i;
slouken@281
    92
slouken@1662
    93
    SDL_memset (gem_currentkeyboard, 0, sizeof (gem_currentkeyboard));
slouken@1662
    94
    SDL_memset (gem_previouskeyboard, 0, sizeof (gem_previouskeyboard));
slouken@1662
    95
    SDL_memset (gem_currentascii, 0, sizeof (gem_currentascii));
slouken@281
    96
slouken@1662
    97
    /* Initialize keymap */
slouken@1662
    98
    for (i = 0; i < sizeof (keymap); i++)
slouken@1662
    99
        keymap[i] = SDLK_UNKNOWN;
slouken@281
   100
slouken@1662
   101
    /* Functions keys */
slouken@1662
   102
    for (i = 0; i < 10; i++)
slouken@1662
   103
        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
slouken@281
   104
slouken@1662
   105
    /* Cursor keypad */
slouken@1662
   106
    keymap[SCANCODE_HELP] = SDLK_HELP;
slouken@1662
   107
    keymap[SCANCODE_UNDO] = SDLK_UNDO;
slouken@1662
   108
    keymap[SCANCODE_INSERT] = SDLK_INSERT;
slouken@1662
   109
    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
slouken@1662
   110
    keymap[SCANCODE_UP] = SDLK_UP;
slouken@1662
   111
    keymap[SCANCODE_DOWN] = SDLK_DOWN;
slouken@1662
   112
    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
slouken@1662
   113
    keymap[SCANCODE_LEFT] = SDLK_LEFT;
slouken@281
   114
slouken@1662
   115
    /* Special keys */
slouken@1662
   116
    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
slouken@1662
   117
    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
slouken@1662
   118
    keymap[SCANCODE_TAB] = SDLK_TAB;
slouken@1662
   119
    keymap[SCANCODE_ENTER] = SDLK_RETURN;
slouken@1662
   120
    keymap[SCANCODE_DELETE] = SDLK_DELETE;
slouken@1662
   121
    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
slouken@1662
   122
    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
slouken@1662
   123
    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
slouken@1662
   124
    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
slouken@1662
   125
    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
slouken@281
   126
slouken@1662
   127
    /* Mouse init */
slouken@1662
   128
    GEM_mouse_relative = SDL_FALSE;
slouken@281
   129
}
slouken@281
   130
slouken@1662
   131
void
slouken@1662
   132
GEM_PumpEvents (_THIS)
slouken@281
   133
{
slouken@1662
   134
    short mousex, mousey, mouseb, dummy;
slouken@1662
   135
    short kstate, prevkc, prevks;
slouken@1662
   136
    int i;
slouken@1662
   137
    SDL_keysym keysym;
slouken@281
   138
slouken@1662
   139
    SDL_memset (gem_currentkeyboard, 0, sizeof (gem_currentkeyboard));
slouken@1662
   140
    prevkc = prevks = 0;
slouken@281
   141
slouken@1662
   142
    for (;;) {
slouken@1662
   143
        int quit, resultat, event_mask, mouse_event;
slouken@1662
   144
        short buffer[8], kc;
slouken@1662
   145
        short x2, y2, w2, h2;
slouken@281
   146
slouken@1662
   147
        quit = mouse_event = x2 = y2 = w2 = h2 = 0;
patmandin@1067
   148
slouken@1662
   149
        event_mask = MU_MESAG | MU_TIMER | MU_KEYBD;
slouken@1662
   150
        if (!GEM_fullscreen && (GEM_handle >= 0)) {
slouken@1662
   151
            wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
slouken@1662
   152
            event_mask |= MU_M1;
slouken@1662
   153
            if ((SDL_GetAppState () & SDL_APPMOUSEFOCUS)) {
slouken@1662
   154
                mouse_event = MO_LEAVE;
slouken@1662
   155
            } else {
slouken@1662
   156
                mouse_event = MO_ENTER;
slouken@1662
   157
            }
slouken@1662
   158
        }
slouken@281
   159
slouken@1662
   160
        resultat = evnt_multi (event_mask,
slouken@1662
   161
                               0, 0, 0,
slouken@1662
   162
                               mouse_event, x2, y2, w2, h2,
slouken@1662
   163
                               0, 0, 0, 0, 0,
slouken@1662
   164
                               buffer,
slouken@1662
   165
                               10,
slouken@1662
   166
                               &dummy, &dummy, &dummy, &kstate, &kc, &dummy);
slouken@281
   167
slouken@1662
   168
        /* Message event ? */
slouken@1662
   169
        if (resultat & MU_MESAG)
slouken@1662
   170
            quit = do_messages (this, buffer);
slouken@281
   171
slouken@1662
   172
        /* Keyboard event ? */
slouken@1662
   173
        if (resultat & MU_KEYBD) {
slouken@1662
   174
            if ((prevkc != kc) || (prevks != kstate)) {
slouken@1662
   175
                do_keyboard (kc, kstate);
slouken@1662
   176
            } else {
slouken@1662
   177
                /* Avoid looping, if repeating same key */
slouken@1662
   178
                break;
slouken@1662
   179
            }
slouken@1662
   180
        }
patmandin@1067
   181
slouken@1662
   182
        /* Mouse entering/leaving window */
slouken@1662
   183
        if (resultat & MU_M1) {
slouken@1662
   184
            if (this->input_grab == SDL_GRAB_OFF) {
slouken@1662
   185
                if (SDL_GetAppState () & SDL_APPMOUSEFOCUS) {
slouken@1662
   186
                    SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
slouken@1662
   187
                } else {
slouken@1662
   188
                    SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
slouken@1662
   189
                }
slouken@1662
   190
            }
slouken@1662
   191
        }
slouken@281
   192
slouken@1662
   193
        /* Timer event ? */
slouken@1662
   194
        if ((resultat & MU_TIMER) || quit)
slouken@1662
   195
            break;
slouken@1662
   196
    }
slouken@281
   197
slouken@1662
   198
    /* Update mouse */
slouken@1662
   199
    graf_mkstate (&mousex, &mousey, &mouseb, &kstate);
slouken@1662
   200
    do_mouse (this, mousex, mousey, mouseb, kstate);
slouken@281
   201
slouken@1662
   202
    /* Now generate keyboard events */
slouken@1662
   203
    for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
slouken@1662
   204
        /* Key pressed ? */
slouken@1662
   205
        if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
slouken@1662
   206
            SDL_PrivateKeyboard (SDL_PRESSED,
slouken@1662
   207
                                 TranslateKey (i, gem_currentascii[i],
slouken@1662
   208
                                               &keysym, SDL_TRUE));
patmandin@996
   209
slouken@1662
   210
        /* Key unpressed ? */
slouken@1662
   211
        if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
slouken@1662
   212
            SDL_PrivateKeyboard (SDL_RELEASED,
slouken@1662
   213
                                 TranslateKey (i, gem_currentascii[i],
slouken@1662
   214
                                               &keysym, SDL_FALSE));
slouken@1662
   215
    }
slouken@1662
   216
slouken@1662
   217
    SDL_memcpy (gem_previouskeyboard, gem_currentkeyboard,
slouken@1662
   218
                sizeof (gem_previouskeyboard));
slouken@1662
   219
slouken@1662
   220
    /* Refresh window name ? */
slouken@1662
   221
    if (GEM_refresh_name) {
slouken@1662
   222
        if (SDL_GetAppState () & SDL_APPACTIVE) {
slouken@1662
   223
            /* Fullscreen/windowed */
slouken@1662
   224
            if (GEM_title_name) {
slouken@1662
   225
                wind_set (GEM_handle, WF_NAME,
slouken@1662
   226
                          (short) (((unsigned long) GEM_title_name) >>
slouken@1662
   227
                                   16),
slouken@1662
   228
                          (short) (((unsigned long) GEM_title_name) &
slouken@1662
   229
                                   0xffff), 0, 0);
slouken@1662
   230
            }
slouken@1662
   231
        } else {
slouken@1662
   232
            /* Iconified */
slouken@1662
   233
            if (GEM_icon_name) {
slouken@1662
   234
                wind_set (GEM_handle, WF_NAME,
slouken@1662
   235
                          (short) (((unsigned long) GEM_icon_name) >>
slouken@1662
   236
                                   16),
slouken@1662
   237
                          (short) (((unsigned long) GEM_icon_name) &
slouken@1662
   238
                                   0xffff), 0, 0);
slouken@1662
   239
            }
slouken@1662
   240
        }
slouken@1662
   241
        GEM_refresh_name = SDL_FALSE;
slouken@1662
   242
    }
slouken@281
   243
}
slouken@281
   244
slouken@1662
   245
static int
slouken@1662
   246
do_messages (_THIS, short *message)
slouken@281
   247
{
slouken@1662
   248
    int quit, posted;
slouken@1662
   249
    short x2, y2, w2, h2;
slouken@281
   250
slouken@1662
   251
    quit = 0;
slouken@1662
   252
    switch (message[0]) {
slouken@1662
   253
    case WM_CLOSED:
slouken@1662
   254
    case AP_TERM:
slouken@1662
   255
        posted = SDL_PrivateQuit ();
slouken@1662
   256
        quit = 1;
slouken@1662
   257
        break;
slouken@1662
   258
    case WM_MOVED:
slouken@1662
   259
        wind_set (message[3], WF_CURRXYWH, message[4], message[5],
slouken@1662
   260
                  message[6], message[7]);
slouken@1662
   261
        break;
slouken@1662
   262
    case WM_TOPPED:
slouken@1662
   263
        wind_set (message[3], WF_TOP, message[4], 0, 0, 0);
slouken@1662
   264
        /* Continue with TOP event processing */
slouken@1662
   265
    case WM_ONTOP:
slouken@1662
   266
        SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
slouken@1662
   267
        if (VDI_setpalette) {
slouken@1662
   268
            VDI_setpalette (this, VDI_curpalette);
slouken@1662
   269
        }
slouken@1662
   270
        break;
slouken@1662
   271
    case WM_REDRAW:
slouken@1662
   272
        if (!GEM_lock_redraw) {
slouken@1662
   273
            GEM_wind_redraw (this, message[3], &message[4]);
slouken@1662
   274
        }
slouken@1662
   275
        break;
slouken@1662
   276
    case WM_ICONIFY:
slouken@1662
   277
    case WM_ALLICONIFY:
slouken@1662
   278
        wind_set (message[3], WF_ICONIFY, message[4], message[5],
slouken@1662
   279
                  message[6], message[7]);
slouken@1662
   280
        /* If we're active, make ourselves inactive */
slouken@1662
   281
        if (SDL_GetAppState () & SDL_APPACTIVE) {
slouken@1662
   282
            /* Send an internal deactivate event */
slouken@1662
   283
            SDL_PrivateAppActive (0, SDL_APPACTIVE);
slouken@1662
   284
        }
slouken@1662
   285
        /* Update window title */
slouken@1662
   286
        if (GEM_refresh_name && GEM_icon_name) {
slouken@1662
   287
            wind_set (GEM_handle, WF_NAME,
slouken@1662
   288
                      (short) (((unsigned long) GEM_icon_name) >> 16),
slouken@1662
   289
                      (short) (((unsigned long) GEM_icon_name) & 0xffff),
slouken@1662
   290
                      0, 0);
slouken@1662
   291
            GEM_refresh_name = SDL_FALSE;
slouken@1662
   292
        }
slouken@1662
   293
        break;
slouken@1662
   294
    case WM_UNICONIFY:
slouken@1662
   295
        wind_set (message[3], WF_UNICONIFY, message[4], message[5],
slouken@1662
   296
                  message[6], message[7]);
slouken@1662
   297
        /* If we're not active, make ourselves active */
slouken@1662
   298
        if (!(SDL_GetAppState () & SDL_APPACTIVE)) {
slouken@1662
   299
            /* Send an internal activate event */
slouken@1662
   300
            SDL_PrivateAppActive (1, SDL_APPACTIVE);
slouken@1662
   301
        }
slouken@1662
   302
        if (GEM_refresh_name && GEM_title_name) {
slouken@1662
   303
            wind_set (GEM_handle, WF_NAME,
slouken@1662
   304
                      (short) (((unsigned long) GEM_title_name) >> 16),
slouken@1662
   305
                      (short) (((unsigned long) GEM_title_name) & 0xffff),
slouken@1662
   306
                      0, 0);
slouken@1662
   307
            GEM_refresh_name = SDL_FALSE;
slouken@1662
   308
        }
slouken@1662
   309
        break;
slouken@1662
   310
    case WM_SIZED:
slouken@1662
   311
        wind_set (message[3], WF_CURRXYWH, message[4], message[5],
slouken@1662
   312
                  message[6], message[7]);
slouken@1662
   313
        wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
slouken@1662
   314
        GEM_win_fulled = SDL_FALSE;     /* Cancel maximized flag */
slouken@1662
   315
        GEM_lock_redraw = SDL_TRUE;     /* Prevent redraw till buffers resized */
slouken@1662
   316
        SDL_PrivateResize (w2, h2);
slouken@1662
   317
        break;
slouken@1662
   318
    case WM_FULLED:
slouken@1662
   319
        {
slouken@1662
   320
            short x, y, w, h;
slouken@281
   321
slouken@1662
   322
            if (GEM_win_fulled) {
slouken@1662
   323
                wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
slouken@1662
   324
                GEM_win_fulled = SDL_FALSE;
slouken@1662
   325
            } else {
slouken@1662
   326
                x = GEM_desk_x;
slouken@1662
   327
                y = GEM_desk_y;
slouken@1662
   328
                w = GEM_desk_w;
slouken@1662
   329
                h = GEM_desk_h;
slouken@1662
   330
                GEM_win_fulled = SDL_TRUE;
slouken@1662
   331
            }
slouken@1662
   332
            wind_set (message[3], WF_CURRXYWH, x, y, w, h);
slouken@1662
   333
            wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
slouken@1662
   334
            GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
slouken@1662
   335
            SDL_PrivateResize (w2, h2);
slouken@1662
   336
        }
slouken@1662
   337
        break;
slouken@1662
   338
    case WM_BOTTOMED:
slouken@1662
   339
        wind_set (message[3], WF_BOTTOM, 0, 0, 0, 0);
slouken@1662
   340
        /* Continue with BOTTOM event processing */
slouken@1662
   341
    case WM_UNTOPPED:
slouken@1662
   342
        SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
slouken@1662
   343
        if (VDI_setpalette) {
slouken@1662
   344
            VDI_setpalette (this, VDI_oldpalette);
slouken@1662
   345
        }
slouken@1662
   346
        break;
slouken@1662
   347
    }
slouken@1662
   348
slouken@1662
   349
    return quit;
slouken@281
   350
}
slouken@281
   351
slouken@1662
   352
static void
slouken@1662
   353
do_keyboard (short kc, short ks)
slouken@281
   354
{
slouken@1662
   355
    int scancode, asciicode;
slouken@281
   356
slouken@1662
   357
    if (kc) {
slouken@1662
   358
        scancode = (kc >> 8) & 127;
slouken@1662
   359
        asciicode = kc & 255;
slouken@281
   360
slouken@1662
   361
        gem_currentkeyboard[scancode] = 0xFF;
slouken@1662
   362
        gem_currentascii[scancode] = asciicode;
slouken@1662
   363
    }
slouken@281
   364
slouken@1662
   365
    /* Read special keys */
slouken@1662
   366
    if (ks & K_RSHIFT)
slouken@1662
   367
        gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF;
slouken@1662
   368
    if (ks & K_LSHIFT)
slouken@1662
   369
        gem_currentkeyboard[SCANCODE_LEFTSHIFT] = 0xFF;
slouken@1662
   370
    if (ks & K_CTRL)
slouken@1662
   371
        gem_currentkeyboard[SCANCODE_LEFTCONTROL] = 0xFF;
slouken@1662
   372
    if (ks & K_ALT)
slouken@1662
   373
        gem_currentkeyboard[SCANCODE_LEFTALT] = 0xFF;
slouken@281
   374
}
slouken@281
   375
slouken@1662
   376
static void
slouken@1662
   377
do_mouse (_THIS, short mx, short my, short mb, short ks)
slouken@281
   378
{
slouken@1662
   379
    static short prevmousex = 0, prevmousey = 0, prevmouseb = 0;
slouken@1662
   380
    short x2, y2, w2, h2;
patmandin@926
   381
slouken@1662
   382
    /* Don't return mouse events if out of window */
slouken@1662
   383
    if ((SDL_GetAppState () & SDL_APPMOUSEFOCUS) == 0) {
slouken@1662
   384
        return;
slouken@1662
   385
    }
patmandin@1067
   386
slouken@1662
   387
    /* Retrieve window coords, and generate mouse events accordingly */
slouken@1662
   388
    x2 = y2 = 0;
slouken@1662
   389
    w2 = VDI_w;
slouken@1662
   390
    h2 = VDI_h;
slouken@1662
   391
    if ((!GEM_fullscreen) && (GEM_handle >= 0)) {
slouken@1662
   392
        wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
patmandin@926
   393
slouken@1662
   394
        /* Do not generate mouse button event if out of window working area */
slouken@1662
   395
        if ((mx < x2) || (mx >= x2 + w2) || (my < y2) || (my >= y2 + h2)) {
slouken@1662
   396
            mb = prevmouseb;
slouken@1662
   397
        }
slouken@1662
   398
    }
slouken@319
   399
slouken@1662
   400
    /* Mouse motion ? */
slouken@1662
   401
    if (GEM_mouse_relative) {
slouken@1662
   402
        if (GEM_usedevmouse) {
slouken@1662
   403
            SDL_AtariDevMouse_PostMouseEvents (this, SDL_FALSE);
slouken@1662
   404
        } else {
slouken@1662
   405
            SDL_AtariXbios_PostMouseEvents (this, SDL_FALSE);
slouken@1662
   406
        }
slouken@1662
   407
    } else {
slouken@1662
   408
        if ((prevmousex != mx) || (prevmousey != my)) {
slouken@1662
   409
            int posx, posy;
patmandin@926
   410
slouken@1662
   411
            /* Give mouse position relative to window position */
slouken@1662
   412
            posx = mx - x2;
slouken@1662
   413
            if (posx < 0)
slouken@1662
   414
                posx = 0;
slouken@1662
   415
            if (posx > w2)
slouken@1662
   416
                posx = w2 - 1;
slouken@1662
   417
            posy = my - y2;
slouken@1662
   418
            if (posy < 0)
slouken@1662
   419
                posy = 0;
slouken@1662
   420
            if (posy > h2)
slouken@1662
   421
                posy = h2 - 1;
patmandin@926
   422
slouken@1662
   423
            SDL_PrivateMouseMotion (0, 0, posx, posy);
slouken@1662
   424
        }
slouken@1662
   425
        prevmousex = mx;
slouken@1662
   426
        prevmousey = my;
slouken@1662
   427
    }
slouken@281
   428
slouken@1662
   429
    /* Mouse button ? */
slouken@1662
   430
    if (prevmouseb != mb) {
slouken@1662
   431
        int i;
slouken@281
   432
slouken@1662
   433
        for (i = 0; i < 2; i++) {
slouken@1662
   434
            int curbutton, prevbutton;
slouken@319
   435
slouken@1662
   436
            curbutton = mb & (1 << i);
slouken@1662
   437
            prevbutton = prevmouseb & (1 << i);
slouken@1662
   438
slouken@1662
   439
            if (curbutton && !prevbutton) {
slouken@1662
   440
                SDL_PrivateMouseButton (SDL_PRESSED, i + 1, 0, 0);
slouken@1662
   441
            }
slouken@1662
   442
            if (!curbutton && prevbutton) {
slouken@1662
   443
                SDL_PrivateMouseButton (SDL_RELEASED, i + 1, 0, 0);
slouken@1662
   444
            }
slouken@1662
   445
        }
slouken@1662
   446
        prevmouseb = mb;
slouken@1662
   447
    }
slouken@1662
   448
slouken@1662
   449
    /* Read special keys */
slouken@1662
   450
    if (ks & K_RSHIFT)
slouken@1662
   451
        gem_currentkeyboard[SCANCODE_RIGHTSHIFT] = 0xFF;
slouken@1662
   452
    if (ks & K_LSHIFT)
slouken@1662
   453
        gem_currentkeyboard[SCANCODE_LEFTSHIFT] = 0xFF;
slouken@1662
   454
    if (ks & K_CTRL)
slouken@1662
   455
        gem_currentkeyboard[SCANCODE_LEFTCONTROL] = 0xFF;
slouken@1662
   456
    if (ks & K_ALT)
slouken@1662
   457
        gem_currentkeyboard[SCANCODE_LEFTALT] = 0xFF;
slouken@281
   458
}
slouken@1662
   459
slouken@1662
   460
/* vi: set ts=4 sw=4 expandtab: */