src/video/x11/SDL_x11modes.c
author Bob Pendleton <bob@pendleton.com>
Fri, 07 Mar 2008 20:54:11 +0000
changeset 2325 c7bcf84ba1b9
parent 1951 7177581dc9fa
child 2859 99210400e8b9
permissions -rw-r--r--
Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
input event with the character รจ. You still get the keypress keyrelease events for the individual keys that go into composing the character.
slouken@1950
     1
/*
slouken@1950
     2
    SDL - Simple DirectMedia Layer
slouken@1950
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1950
     4
slouken@1950
     5
    This library is free software; you can redistribute it and/or
slouken@1950
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1950
     7
    License as published by the Free Software Foundation; either
slouken@1950
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1950
     9
slouken@1950
    10
    This library is distributed in the hope that it will be useful,
slouken@1950
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1950
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1950
    13
    Lesser General Public License for more details.
slouken@1950
    14
slouken@1950
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1950
    16
    License along with this library; if not, write to the Free Software
slouken@1950
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1950
    18
slouken@1950
    19
    Sam Lantinga
slouken@1950
    20
    slouken@libsdl.org
slouken@1950
    21
*/
slouken@1950
    22
#include "SDL_config.h"
slouken@1950
    23
slouken@1950
    24
#include "SDL_x11video.h"
slouken@1950
    25
slouken@1950
    26
slouken@1950
    27
static int
slouken@1950
    28
get_visualinfo(Display * display, int screen, XVisualInfo * vinfo)
slouken@1950
    29
{
slouken@1950
    30
    const char *visual_id = SDL_getenv("SDL_VIDEO_X11_VISUALID");
slouken@1950
    31
    int use_directcolor = 1;
slouken@1950
    32
    int depth;
slouken@1950
    33
slouken@1950
    34
    /* Look for an exact visual, if requested */
slouken@1950
    35
    if (visual_id) {
slouken@1950
    36
        XVisualInfo *vi, template;
slouken@1950
    37
        int nvis;
slouken@1950
    38
slouken@1950
    39
        SDL_zero(template);
slouken@1950
    40
        template.visualid = SDL_strtol(visual_id, NULL, 0);
slouken@1950
    41
        vi = XGetVisualInfo(display, VisualIDMask, &template, &nvis);
slouken@1950
    42
        if (vi) {
slouken@1950
    43
            *vinfo = *vi;
slouken@1950
    44
            XFree(vi);
slouken@1950
    45
            return 0;
slouken@1950
    46
        }
slouken@1950
    47
    }
slouken@1950
    48
slouken@1950
    49
    depth = DefaultDepth(display, screen);
slouken@1950
    50
    if ((use_directcolor &&
slouken@1950
    51
         XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) ||
slouken@1950
    52
        XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) ||
slouken@1950
    53
        XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) ||
slouken@1950
    54
        XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) {
slouken@1950
    55
        return 0;
slouken@1950
    56
    }
slouken@1950
    57
    return -1;
slouken@1950
    58
}
slouken@1950
    59
slouken@1950
    60
void
slouken@1950
    61
X11_InitModes(_THIS)
slouken@1950
    62
{
slouken@1950
    63
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1950
    64
    int screen;
slouken@1950
    65
    int n;
slouken@1950
    66
    XPixmapFormatValues *p;
slouken@1950
    67
slouken@1950
    68
    p = XListPixmapFormats(data->display, &n);
slouken@1950
    69
    for (screen = 0; screen < ScreenCount(data->display); ++screen) {
slouken@1950
    70
        XVisualInfo vinfo;
slouken@1950
    71
        int i, bpp;
slouken@1950
    72
        Uint32 Rmask, Gmask, Bmask, Amask;
slouken@1950
    73
        SDL_VideoDisplay display;
slouken@1950
    74
        SDL_DisplayData *displaydata;
slouken@1950
    75
        SDL_DisplayMode mode;
slouken@1950
    76
slouken@1950
    77
        if (get_visualinfo(data->display, screen, &vinfo) < 0) {
slouken@1950
    78
            continue;
slouken@1950
    79
        }
slouken@1950
    80
slouken@1950
    81
        bpp = vinfo.depth;
slouken@1950
    82
        for (i = 0; i < n; ++i) {
slouken@1950
    83
            if (p[i].depth == vinfo.depth) {
slouken@1950
    84
                bpp = p[i].bits_per_pixel;
slouken@1950
    85
                break;
slouken@1950
    86
            }
slouken@1950
    87
        }
slouken@1950
    88
        Rmask = vinfo.visual->red_mask;
slouken@1950
    89
        Gmask = vinfo.visual->green_mask;
slouken@1950
    90
        Bmask = vinfo.visual->blue_mask;
slouken@1950
    91
        if (vinfo.depth == 32) {
slouken@1950
    92
            Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
slouken@1950
    93
        } else {
slouken@1950
    94
            Amask = 0;
slouken@1950
    95
        }
slouken@1950
    96
        mode.format =
slouken@1950
    97
            SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
slouken@1950
    98
        mode.w = DisplayWidth(data->display, screen);
slouken@1950
    99
        mode.h = DisplayHeight(data->display, screen);
slouken@1950
   100
        mode.refresh_rate = 0;
slouken@1950
   101
        mode.driverdata = NULL;
slouken@1950
   102
slouken@1950
   103
        displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
slouken@1950
   104
        if (!displaydata) {
slouken@1950
   105
            continue;
slouken@1950
   106
        }
slouken@1950
   107
        displaydata->screen = screen;
slouken@1950
   108
        displaydata->visual = vinfo.visual;
slouken@1951
   109
        displaydata->depth = vinfo.depth;
slouken@1950
   110
slouken@1950
   111
        SDL_zero(display);
slouken@1950
   112
        display.desktop_mode = mode;
slouken@1950
   113
        display.current_mode = mode;
slouken@1950
   114
        display.driverdata = displaydata;
slouken@1950
   115
        SDL_AddVideoDisplay(&display);
slouken@1950
   116
    }
slouken@1950
   117
    XFree(p);
slouken@1950
   118
}
slouken@1950
   119
slouken@1950
   120
void
slouken@1950
   121
X11_GetDisplayModes(_THIS)
slouken@1950
   122
{
slouken@1950
   123
    SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
slouken@1950
   124
    SDL_DisplayMode mode;
slouken@1950
   125
    //SDL_AddDisplayMode(_this->current_display, &mode);
slouken@1950
   126
}
slouken@1950
   127
slouken@1950
   128
int
slouken@1950
   129
X11_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
slouken@1950
   130
{
slouken@1950
   131
    //SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
slouken@1950
   132
    return -1;
slouken@1950
   133
}
slouken@1950
   134
slouken@1950
   135
void
slouken@1950
   136
X11_QuitModes(_THIS)
slouken@1950
   137
{
slouken@1950
   138
}
slouken@1950
   139
slouken@1950
   140
/* vi: set ts=4 sw=4 expandtab: */