1 /*****************************************************************************
2 * intf_sdl.c: SDL interface plugin
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
31 #include <SDL/SDL.h> /* for all the SDL stuff */
32 #include <sys/types.h> /* on BSD, uio.h needs types.h */
33 #include <sys/uio.h> /* for input.h */
43 #include "video_output.h"
45 #include "interface.h"
47 #include "keystrokes.h"
51 /*****************************************************************************
52 * intf_sys_t: description and status of SDL interface
53 *****************************************************************************/
54 typedef struct intf_sys_s
56 /* SDL system information */
57 SDL_Surface * p_display; /* display */
62 void intf_SDL_Keymap( intf_thread_t * p_intf );
65 /*****************************************************************************
66 * intf_SDLCreate: initialize and create SDL interface
67 *****************************************************************************/
68 int intf_SDLCreate( intf_thread_t *p_intf )
70 /* Check that b_video is set */
71 if( !p_main->b_video )
73 intf_ErrMsg( "error: SDL interface requires a video output thread\n" );
77 /* Allocate instance and initialize some members */
78 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
79 if( p_intf->p_sys == NULL )
81 intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
85 /* Spawn video output thread */
86 p_intf->p_vout = vout_CreateThread( main_GetPszVariable( VOUT_DISPLAY_VAR,
88 main_GetIntVariable( VOUT_WIDTH_VAR,
90 main_GetIntVariable( VOUT_HEIGHT_VAR,
91 VOUT_HEIGHT_DEFAULT ),
93 (void *)&p_intf->p_sys->p_display );
95 if( p_intf->p_vout == NULL ) /* error */
97 intf_ErrMsg( "error: can't create video output thread\n" );
98 free( p_intf->p_sys );
101 intf_SDL_Keymap( p_intf );
105 /*****************************************************************************
106 * intf_SDLDestroy: destroy interface
107 *****************************************************************************/
108 void intf_SDLDestroy( intf_thread_t *p_intf )
110 /* Close input thread, if any (blocking) */
111 if( p_intf->p_input )
113 input_DestroyThread( p_intf->p_input, NULL );
116 /* Close video output thread, if any (blocking) */
119 vout_DestroyThread( p_intf->p_vout, NULL );
122 /* Destroy structure */
124 SDL_FreeSurface( p_intf->p_sys->p_display ); /* destroy the "screen" */
126 free( p_intf->p_sys );
130 /*****************************************************************************
131 * intf_SDLManage: event loop
132 *****************************************************************************/
133 void intf_SDLManage( intf_thread_t *p_intf )
135 SDL_Event event; /* SDL event */
138 while ( SDL_PollEvent(&event) )
140 i_key = event.key.keysym.sym; /* forward it */
142 switch (event.type) {
143 case SDL_KEYDOWN: /* if a key is pressed */
144 if( intf_ProcessKey( p_intf, (char ) i_key ) )
146 intf_DbgMsg( "unhandled key '%c' (%i)\n",
147 (char) i_key, i_key );
151 intf_ProcessKey( p_intf, INTF_KEY_QUIT );
161 void intf_SDL_Keymap(intf_thread_t * p_intf )
163 p_intf->p_intf_getKey = intf_getKey;
164 intf_AssignKey(p_intf, SDLK_q, INTF_KEY_QUIT, NULL);
165 intf_AssignKey(p_intf, SDLK_ESCAPE, INTF_KEY_QUIT, NULL);
166 /* intf_AssignKey(p_intf,3,'Q'); */
167 intf_AssignKey(p_intf, SDLK_0, INTF_KEY_SET_CHANNEL,0);
168 intf_AssignKey(p_intf, SDLK_1, INTF_KEY_SET_CHANNEL,1);
169 intf_AssignKey(p_intf, SDLK_2, INTF_KEY_SET_CHANNEL,2);
170 intf_AssignKey(p_intf, SDLK_3, INTF_KEY_SET_CHANNEL,3);
171 intf_AssignKey(p_intf, SDLK_4, INTF_KEY_SET_CHANNEL,4);
172 intf_AssignKey(p_intf, SDLK_5, INTF_KEY_SET_CHANNEL,5);
173 intf_AssignKey(p_intf, SDLK_6, INTF_KEY_SET_CHANNEL,6);
174 intf_AssignKey(p_intf, SDLK_7, INTF_KEY_SET_CHANNEL,7);
175 intf_AssignKey(p_intf, SDLK_8, INTF_KEY_SET_CHANNEL,8);
176 intf_AssignKey(p_intf, SDLK_9, INTF_KEY_SET_CHANNEL,9);
177 intf_AssignKey(p_intf, SDLK_PLUS, INTF_KEY_INC_VOLUME, NULL);
178 intf_AssignKey(p_intf, SDLK_MINUS, INTF_KEY_DEC_VOLUME, NULL);
179 intf_AssignKey(p_intf, SDLK_m, INTF_KEY_TOGGLE_VOLUME, NULL);
180 /* intf_AssignKey(p_intf,'M','M'); */
181 intf_AssignSKey(p_intf, SDLK_g, INTF_KEY_DEC_GAMMA, NULL);
182 /* intf_AssignKey(p_intf,'G','G'); */
183 intf_AssignSKey(p_intf, SDLK_c, INTF_KEY_TOGGLE_GRAYSCALE, NULL);
184 intf_AssignSKey(p_intf, SDLK_SPACE, INTF_KEY_TOGGLE_INTERFACE, NULL);
185 intf_AssignSKey(p_intf, 'i', INTF_KEY_TOGGLE_INFO, NULL);
186 intf_AssignSKey(p_intf, SDLK_s, INTF_KEY_TOGGLE_SCALING, NULL);