annotate libvo/sdl_common.c @ 36858:bb067298265a

Fix bug with btnSet(). Only change the pressed state if the item actually has a button. Additionally, change variable name.
author ib
date Fri, 28 Feb 2014 14:11:25 +0000
parents 60cb31e9e55d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31032
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
1 /*
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
2 * common SDL routines
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
3 *
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
4 * This file is part of MPlayer.
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
5 *
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
9 * (at your option) any later version.
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
10 *
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
14 * GNU General Public License for more details.
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
15 *
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License along
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
19 */
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
20
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
21 #include "sdl_common.h"
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
22 #include "mp_msg.h"
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
23 #include "mp_fifo.h"
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
24 #include "osdep/keycodes.h"
34645
0bce77ccae9a Fix compiling with osdep setenv
al
parents: 34614
diff changeset
25 #include "osdep/setenv.h"
31032
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
26 #include "input/input.h"
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
27 #include "input/mouse.h"
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
28 #include "video_out.h"
34614
f9f91ba805b9 SDL: add support for setting window position.
reimar
parents: 34611
diff changeset
29 #include "geometry.h"
31032
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
30
31035
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
31 static int old_w;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
32 static int old_h;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
33 static int mode_flags;
31043
80036ef586ff Add reinitialization support. Necessary for fullscreen on OSX.
reimar
parents: 31042
diff changeset
34 static int reinit;
31035
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
35
34482
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
36 /**
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
37 * Update vo_screenwidth and vo_screenheight.
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
38 *
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
39 * This function only works with SDL since 1.2.10 and
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
40 * even then only when called before the first
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
41 * SDL_SetVideoMode.
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
42 * Once there's a better way available implement an
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
43 * update_xinerama_info function.
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
44 */
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
45 static void get_screensize(void) {
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
46 const SDL_VideoInfo *vi;
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
47 // TODO: better to use a check that gets the runtime version instead?
34843
ec5d1147164e Change if() condition into #if.
reimar
parents: 34812
diff changeset
48 #if SDL_VERSION_ATLEAST(1, 2, 10)
34482
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
49 // Keep user-provided settings
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
50 if (vo_screenwidth > 0 || vo_screenheight > 0) return;
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
51 vi = SDL_GetVideoInfo();
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
52 vo_screenwidth = vi->current_w;
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
53 vo_screenheight = vi->current_h;
34843
ec5d1147164e Change if() condition into #if.
reimar
parents: 34812
diff changeset
54 #endif
34482
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
55 }
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
56
31037
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
57 int vo_sdl_init(void)
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
58 {
31043
80036ef586ff Add reinitialization support. Necessary for fullscreen on OSX.
reimar
parents: 31042
diff changeset
59 reinit = 0;
80036ef586ff Add reinitialization support. Necessary for fullscreen on OSX.
reimar
parents: 31042
diff changeset
60
34551
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
61 if (!SDL_WasInit(SDL_INIT_VIDEO)) {
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
62 // Unfortunately SDL_WINDOWID must be set at SDL_Init
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
63 // and is ignored afterwards, thus it cannot work per-file.
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
64 // Also, a value of 0 does not work for selecting the root window.
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
65 if (WinID > 0) {
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
66 char envstr[20];
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
67 snprintf(envstr, sizeof(envstr), "0x%"PRIx64, WinID);
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
68 setenv("SDL_WINDOWID", envstr, 1);
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
69 }
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
70 if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0)
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
71 return 0;
4f7637d076a4 Support -wid for vo_sdl.
reimar
parents: 34482
diff changeset
72 }
31037
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
73
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
74 // Setup Keyrepeats (500/30 are defaults)
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
75 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, 100 /*SDL_DEFAULT_REPEAT_INTERVAL*/);
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
76
31038
3e67417271d7 Make uppercase characters and in general all ASCII characters work
reimar
parents: 31037
diff changeset
77 // Easiest way to get uppercase characters
3e67417271d7 Make uppercase characters and in general all ASCII characters work
reimar
parents: 31037
diff changeset
78 SDL_EnableUNICODE(1);
3e67417271d7 Make uppercase characters and in general all ASCII characters work
reimar
parents: 31037
diff changeset
79
31037
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
80 // We don't want those in our event queue.
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
81 SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
82 SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
83 SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
84
34482
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
85 // Try to get a sensible default for fullscreen.
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
86 get_screensize();
3c51a42da09c SDL: Try to select a fullscreen mode that does not require resolution changes by default.
reimar
parents: 31318
diff changeset
87
31037
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
88 return 1;
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
89 }
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
90
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
91 void vo_sdl_uninit(void)
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
92 {
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
93 if (SDL_WasInit(SDL_INIT_VIDEO))
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
94 SDL_QuitSubSystem(SDL_INIT_VIDEO);
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
95 }
4f273572e445 Share SDL initialization code.
reimar
parents: 31035
diff changeset
96
34812
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
97 int vo_sdl_config(int w, int h, int flags, const char *title)
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
98 {
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
99 SDL_WM_SetCaption(title, NULL);
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
100 vo_dwidth = old_w = w;
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
101 vo_dheight = old_h = h;
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
102 vo_fs = !!(flags & VOFLAG_FULLSCREEN);
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
103 if (vo_fs) {
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
104 vo_dwidth = vo_screenwidth;
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
105 vo_dheight = vo_screenheight;
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
106 }
34844
60cb31e9e55d SDL: add support for quadbuffer stereo.
reimar
parents: 34843
diff changeset
107 SDL_GL_SetAttribute(SDL_GL_STEREO, !!(flags & VOFLAG_STEREO));
34812
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
108 return 1;
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
109 }
f2274219a79c Fix -fs with SDL-based vo gl.
reimar
parents: 34645
diff changeset
110
31035
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
111 void vo_sdl_fullscreen(void)
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
112 {
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
113 if (vo_fs) {
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
114 vo_dwidth = old_w;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
115 vo_dheight = old_h;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
116 } else {
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
117 old_w = vo_dwidth;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
118 old_h = vo_dheight;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
119 vo_dwidth = vo_screenwidth;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
120 vo_dheight = vo_screenheight;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
121 }
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
122 vo_fs = !vo_fs;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
123 sdl_set_mode(0, mode_flags);
31043
80036ef586ff Add reinitialization support. Necessary for fullscreen on OSX.
reimar
parents: 31042
diff changeset
124 // on OSX at least we now need to do a full reinit.
80036ef586ff Add reinitialization support. Necessary for fullscreen on OSX.
reimar
parents: 31042
diff changeset
125 // TODO: this should only be set if really necessary.
80036ef586ff Add reinitialization support. Necessary for fullscreen on OSX.
reimar
parents: 31042
diff changeset
126 reinit = 1;
31035
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
127 }
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
128
34611
f1a31e5fc35f vo_sdl: reuse some more sdl_common code.
reimar
parents: 34597
diff changeset
129 SDL_Surface *sdl_set_mode(int bpp, uint32_t flags)
31033
8d1080e9c92d Window resizing support for -vo gl with SDL backend.
reimar
parents: 31032
diff changeset
130 {
31035
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
131 SDL_Surface *s;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
132 mode_flags = flags;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
133 if (vo_fs) flags |= SDL_FULLSCREEN;
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
134 // doublebuf with opengl creates flickering
34611
f1a31e5fc35f vo_sdl: reuse some more sdl_common code.
reimar
parents: 34597
diff changeset
135 #if !defined( __AMIGAOS4__ ) && !defined( __APPLE__ )
31035
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
136 if (vo_doublebuffering && !(flags & SDL_OPENGL))
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
137 flags |= SDL_DOUBLEBUF;
34611
f1a31e5fc35f vo_sdl: reuse some more sdl_common code.
reimar
parents: 34597
diff changeset
138 #endif
34597
e227a8ae4418 Support -noborder with SDL.
reimar
parents: 34551
diff changeset
139 if (!vo_border)
e227a8ae4418 Support -noborder with SDL.
reimar
parents: 34551
diff changeset
140 flags |= SDL_NOFRAME;
34614
f9f91ba805b9 SDL: add support for setting window position.
reimar
parents: 34611
diff changeset
141 if (geometry_xy_changed) {
f9f91ba805b9 SDL: add support for setting window position.
reimar
parents: 34611
diff changeset
142 char envstr[20];
f9f91ba805b9 SDL: add support for setting window position.
reimar
parents: 34611
diff changeset
143 snprintf(envstr, sizeof(envstr), "%i,%i", vo_dx, vo_dy);
f9f91ba805b9 SDL: add support for setting window position.
reimar
parents: 34611
diff changeset
144 setenv("SDL_VIDEO_WINDOW_POS", envstr, 1);
f9f91ba805b9 SDL: add support for setting window position.
reimar
parents: 34611
diff changeset
145 }
31035
5aae99fd6ca7 Fullscreen support for -vo gl using SDL.
reimar
parents: 31033
diff changeset
146 s = SDL_SetVideoMode(vo_dwidth, vo_dheight, bpp, flags);
31033
8d1080e9c92d Window resizing support for -vo gl with SDL backend.
reimar
parents: 31032
diff changeset
147 if (!s) {
8d1080e9c92d Window resizing support for -vo gl with SDL backend.
reimar
parents: 31032
diff changeset
148 mp_msg(MSGT_VO, MSGL_FATAL, "SDL SetVideoMode failed: %s\n", SDL_GetError());
34611
f1a31e5fc35f vo_sdl: reuse some more sdl_common code.
reimar
parents: 34597
diff changeset
149 return NULL;
31033
8d1080e9c92d Window resizing support for -vo gl with SDL backend.
reimar
parents: 31032
diff changeset
150 }
8d1080e9c92d Window resizing support for -vo gl with SDL backend.
reimar
parents: 31032
diff changeset
151 vo_dwidth = s->w;
8d1080e9c92d Window resizing support for -vo gl with SDL backend.
reimar
parents: 31032
diff changeset
152 vo_dheight = s->h;
34611
f1a31e5fc35f vo_sdl: reuse some more sdl_common code.
reimar
parents: 34597
diff changeset
153 return s;
31033
8d1080e9c92d Window resizing support for -vo gl with SDL backend.
reimar
parents: 31032
diff changeset
154 }
8d1080e9c92d Window resizing support for -vo gl with SDL backend.
reimar
parents: 31032
diff changeset
155
31040
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
156 static const struct mp_keymap keysym_map[] = {
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
157 {SDLK_RETURN, KEY_ENTER}, {SDLK_ESCAPE, KEY_ESC},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
158 {SDLK_F1, KEY_F+1}, {SDLK_F2, KEY_F+2}, {SDLK_F3, KEY_F+3},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
159 {SDLK_F4, KEY_F+4}, {SDLK_F5, KEY_F+5}, {SDLK_F6, KEY_F+6},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
160 {SDLK_F7, KEY_F+7}, {SDLK_F8, KEY_F+8}, {SDLK_F9, KEY_F+9},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
161 {SDLK_F10, KEY_F+10}, {SDLK_F11, KEY_F+11}, {SDLK_F12, KEY_F+12},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
162 {SDLK_KP_PLUS, '+'}, {SDLK_KP_MINUS, '-'}, {SDLK_TAB, KEY_TAB},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
163 {SDLK_PAGEUP, KEY_PAGE_UP}, {SDLK_PAGEDOWN, KEY_PAGE_DOWN},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
164 {SDLK_UP, KEY_UP}, {SDLK_DOWN, KEY_DOWN},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
165 {SDLK_LEFT, KEY_LEFT}, {SDLK_RIGHT, KEY_RIGHT},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
166 {SDLK_KP_MULTIPLY, '*'}, {SDLK_KP_DIVIDE, '/'},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
167 {SDLK_KP0, KEY_KP0}, {SDLK_KP1, KEY_KP1}, {SDLK_KP2, KEY_KP2},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
168 {SDLK_KP3, KEY_KP3}, {SDLK_KP4, KEY_KP4}, {SDLK_KP5, KEY_KP5},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
169 {SDLK_KP6, KEY_KP6}, {SDLK_KP7, KEY_KP7}, {SDLK_KP8, KEY_KP8},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
170 {SDLK_KP9, KEY_KP9},
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
171 {SDLK_KP_PERIOD, KEY_KPDEC}, {SDLK_KP_ENTER, KEY_KPENTER},
31318
2211cc2fb0c3 100l, add missing 0-termination of keymap file.
reimar
parents: 31051
diff changeset
172 {0, 0}
31040
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
173 };
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
174
31032
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
175 int sdl_default_handle_event(SDL_Event *event)
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
176 {
31040
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
177 int mpkey;
31043
80036ef586ff Add reinitialization support. Necessary for fullscreen on OSX.
reimar
parents: 31042
diff changeset
178 if (!event) {
80036ef586ff Add reinitialization support. Necessary for fullscreen on OSX.
reimar
parents: 31042
diff changeset
179 int res = reinit ? VO_EVENT_REINIT : 0;
80036ef586ff Add reinitialization support. Necessary for fullscreen on OSX.
reimar
parents: 31042
diff changeset
180 reinit = 0;
80036ef586ff Add reinitialization support. Necessary for fullscreen on OSX.
reimar
parents: 31042
diff changeset
181 return res;
80036ef586ff Add reinitialization support. Necessary for fullscreen on OSX.
reimar
parents: 31042
diff changeset
182 }
31032
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
183 switch (event->type) {
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
184 case SDL_VIDEORESIZE:
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
185 vo_dwidth = event->resize.w;
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
186 vo_dheight = event->resize.h;
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
187 return VO_EVENT_RESIZE;
31046
93acb406a855 Minor cosmetics.
reimar
parents: 31043
diff changeset
188
31042
91eb3b0b9b7a Handle SDL expose events with -vo gl.
reimar
parents: 31040
diff changeset
189 case SDL_VIDEOEXPOSE:
91eb3b0b9b7a Handle SDL expose events with -vo gl.
reimar
parents: 31040
diff changeset
190 return VO_EVENT_EXPOSE;
31046
93acb406a855 Minor cosmetics.
reimar
parents: 31043
diff changeset
191
31050
340fd8115a78 Support mouse movements in SDL.
reimar
parents: 31046
diff changeset
192 case SDL_MOUSEMOTION:
340fd8115a78 Support mouse movements in SDL.
reimar
parents: 31046
diff changeset
193 vo_mouse_movement(event->motion.x, event->motion.y);
340fd8115a78 Support mouse movements in SDL.
reimar
parents: 31046
diff changeset
194 break;
340fd8115a78 Support mouse movements in SDL.
reimar
parents: 31046
diff changeset
195
31032
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
196 case SDL_MOUSEBUTTONDOWN:
31046
93acb406a855 Minor cosmetics.
reimar
parents: 31043
diff changeset
197 if (!vo_nomouse_input)
93acb406a855 Minor cosmetics.
reimar
parents: 31043
diff changeset
198 mplayer_put_key((MOUSE_BTN0 + event->button.button - 1) | MP_KEY_DOWN);
31032
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
199 break;
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
200
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
201 case SDL_MOUSEBUTTONUP:
31051
109e37bbb151 Missing space after if.
reimar
parents: 31050
diff changeset
202 if (!vo_nomouse_input)
31046
93acb406a855 Minor cosmetics.
reimar
parents: 31043
diff changeset
203 mplayer_put_key(MOUSE_BTN0 + event->button.button - 1);
31032
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
204 break;
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
205
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
206 case SDL_KEYDOWN:
31040
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
207 mpkey = lookup_keymap_table(keysym_map, event->key.keysym.sym);
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
208 if (!mpkey &&
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
209 event->key.keysym.unicode > 0 &&
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
210 event->key.keysym.unicode < 128)
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
211 mpkey = event->key.keysym.unicode;
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
212 if (mpkey)
85809d9fdc95 Simplify SDL key symbol mapping.
reimar
parents: 31039
diff changeset
213 mplayer_put_key(mpkey);
31032
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
214 break;
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
215
31046
93acb406a855 Minor cosmetics.
reimar
parents: 31043
diff changeset
216 case SDL_QUIT:
93acb406a855 Minor cosmetics.
reimar
parents: 31043
diff changeset
217 mplayer_put_key(KEY_CLOSE_WIN);
93acb406a855 Minor cosmetics.
reimar
parents: 31043
diff changeset
218 break;
31032
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
219 }
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
220 return 0;
362425fe3de8 Add sdl_common file and use it to share the input handling between -vo gl
reimar
parents:
diff changeset
221 }