summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/sdl
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/sdl')
-rw-r--r--firmware/target/hosted/sdl/app/button-application.c16
-rw-r--r--firmware/target/hosted/sdl/button-sdl.c27
-rw-r--r--firmware/target/hosted/sdl/button-sdl.h2
-rw-r--r--firmware/target/hosted/sdl/lcd-bitmap.c14
-rw-r--r--firmware/target/hosted/sdl/system-sdl.c50
5 files changed, 107 insertions, 2 deletions
diff --git a/firmware/target/hosted/sdl/app/button-application.c b/firmware/target/hosted/sdl/app/button-application.c
index 2ad09dc373..72f4a1770d 100644
--- a/firmware/target/hosted/sdl/app/button-application.c
+++ b/firmware/target/hosted/sdl/app/button-application.c
@@ -30,6 +30,9 @@ int key_to_button(int keyboard_key)
30 int new_btn = BUTTON_NONE; 30 int new_btn = BUTTON_NONE;
31 switch (keyboard_key) 31 switch (keyboard_key)
32 { 32 {
33#if (CONFIG_PLATFORM & PLATFORM_MAEMO4)
34 case SDLK_ESCAPE:
35#endif
33 case SDLK_KP7: 36 case SDLK_KP7:
34 new_btn = BUTTON_TOPLEFT; 37 new_btn = BUTTON_TOPLEFT;
35 break; 38 break;
@@ -37,6 +40,9 @@ int key_to_button(int keyboard_key)
37 case SDLK_UP: 40 case SDLK_UP:
38 new_btn = BUTTON_TOPMIDDLE; 41 new_btn = BUTTON_TOPMIDDLE;
39 break; 42 break;
43#if (CONFIG_PLATFORM & PLATFORM_MAEMO4)
44 case SDLK_F7:
45#endif
40 case SDLK_KP9: 46 case SDLK_KP9:
41 new_btn = BUTTON_TOPRIGHT; 47 new_btn = BUTTON_TOPRIGHT;
42 break; 48 break;
@@ -44,6 +50,10 @@ int key_to_button(int keyboard_key)
44 case SDLK_LEFT: 50 case SDLK_LEFT:
45 new_btn = BUTTON_MIDLEFT; 51 new_btn = BUTTON_MIDLEFT;
46 break; 52 break;
53#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
54 case SDLK_RETURN:
55 case SDLK_KP_ENTER:
56#endif
47 case SDLK_KP5: 57 case SDLK_KP5:
48 new_btn = BUTTON_CENTER; 58 new_btn = BUTTON_CENTER;
49 break; 59 break;
@@ -51,6 +61,9 @@ int key_to_button(int keyboard_key)
51 case SDLK_RIGHT: 61 case SDLK_RIGHT:
52 new_btn = BUTTON_MIDRIGHT; 62 new_btn = BUTTON_MIDRIGHT;
53 break; 63 break;
64#if (CONFIG_PLATFORM & PLATFORM_MAEMO4)
65 case SDLK_F6:
66#endif
54 case SDLK_KP1: 67 case SDLK_KP1:
55 new_btn = BUTTON_BOTTOMLEFT; 68 new_btn = BUTTON_BOTTOMLEFT;
56 break; 69 break;
@@ -58,6 +71,9 @@ int key_to_button(int keyboard_key)
58 case SDLK_DOWN: 71 case SDLK_DOWN:
59 new_btn = BUTTON_BOTTOMMIDDLE; 72 new_btn = BUTTON_BOTTOMMIDDLE;
60 break; 73 break;
74#if (CONFIG_PLATFORM & PLATFORM_MAEMO4)
75 case SDLK_F8:
76#endif
61 case SDLK_KP3: 77 case SDLK_KP3:
62 new_btn = BUTTON_BOTTOMRIGHT; 78 new_btn = BUTTON_BOTTOMRIGHT;
63 break; 79 break;
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index 3321a01bc6..25dad09341 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -67,6 +67,8 @@ struct event_queue button_queue;
67 67
68static int btn = 0; /* Hopefully keeps track of currently pressed keys... */ 68static int btn = 0; /* Hopefully keeps track of currently pressed keys... */
69 69
70int sdl_app_has_input_focus = 1;
71
70#ifdef HAS_BUTTON_HOLD 72#ifdef HAS_BUTTON_HOLD
71bool hold_button_state = false; 73bool hold_button_state = false;
72bool button_hold(void) { 74bool button_hold(void) {
@@ -209,11 +211,34 @@ static void mouse_event(SDL_MouseButtonEvent *event, bool button_up)
209 211
210static bool event_handler(SDL_Event *event) 212static bool event_handler(SDL_Event *event)
211{ 213{
214 SDLKey ev_key;
215
212 switch(event->type) 216 switch(event->type)
213 { 217 {
218 case SDL_ACTIVEEVENT:
219 if (event->active.state & SDL_APPINPUTFOCUS)
220 {
221 if (event->active.gain == 1)
222 sdl_app_has_input_focus = 1;
223 else
224 sdl_app_has_input_focus = 0;
225 }
226 break;
214 case SDL_KEYDOWN: 227 case SDL_KEYDOWN:
215 case SDL_KEYUP: 228 case SDL_KEYUP:
216 button_event(event->key.keysym.sym, event->type == SDL_KEYDOWN); 229 ev_key = event->key.keysym.sym;
230#if (CONFIG_PLATFORM & PLATFORM_MAEMO5)
231 /* N900 with shared up/down cursor mapping. Seen on the German,
232 Finnish, Italian, French and Russian version. Probably more. */
233 if (event->key.keysym.mod & KMOD_MODE)
234 {
235 if (ev_key == SDLK_LEFT)
236 ev_key = SDLK_UP;
237 else if (ev_key == SDLK_RIGHT)
238 ev_key = SDLK_DOWN;
239 }
240#endif
241 button_event(ev_key, event->type == SDL_KEYDOWN);
217 break; 242 break;
218#ifdef HAVE_TOUCHSCREEN 243#ifdef HAVE_TOUCHSCREEN
219 case SDL_MOUSEMOTION: 244 case SDL_MOUSEMOTION:
diff --git a/firmware/target/hosted/sdl/button-sdl.h b/firmware/target/hosted/sdl/button-sdl.h
index e6fcb9ea83..6b7f632eaf 100644
--- a/firmware/target/hosted/sdl/button-sdl.h
+++ b/firmware/target/hosted/sdl/button-sdl.h
@@ -26,6 +26,8 @@
26#include <stdbool.h> 26#include <stdbool.h>
27#include "config.h" 27#include "config.h"
28 28
29extern int sdl_app_has_input_focus;
30
29bool button_hold(void); 31bool button_hold(void);
30#undef button_init_device 32#undef button_init_device
31void button_init_device(void); 33void button_init_device(void);
diff --git a/firmware/target/hosted/sdl/lcd-bitmap.c b/firmware/target/hosted/sdl/lcd-bitmap.c
index 7058b26e8c..4c296924af 100644
--- a/firmware/target/hosted/sdl/lcd-bitmap.c
+++ b/firmware/target/hosted/sdl/lcd-bitmap.c
@@ -22,8 +22,12 @@
22#include "debug.h" 22#include "debug.h"
23#include "sim-ui-defines.h" 23#include "sim-ui-defines.h"
24#include "system.h" 24#include "system.h"
25#include "button-sdl.h"
25#include "lcd-sdl.h" 26#include "lcd-sdl.h"
26#include "screendump.h" 27#include "screendump.h"
28#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
29#include "maemo-thread.h"
30#endif
27 31
28SDL_Surface* lcd_surface; 32SDL_Surface* lcd_surface;
29 33
@@ -123,6 +127,16 @@ void lcd_update(void)
123 127
124void lcd_update_rect(int x_start, int y_start, int width, int height) 128void lcd_update_rect(int x_start, int y_start, int width, int height)
125{ 129{
130#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
131 /* Don't update display if not shown */
132 if (!maemo_display_on)
133 return;
134
135 /* Don't update if we don't have the input focus */
136 if (!sdl_app_has_input_focus)
137 return;
138#endif
139
126 sdl_update_rect(lcd_surface, x_start, y_start, width, height, 140 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
127 LCD_WIDTH, LCD_HEIGHT, get_lcd_pixel); 141 LCD_WIDTH, LCD_HEIGHT, get_lcd_pixel);
128 sdl_gui_update(lcd_surface, x_start, y_start, width, 142 sdl_gui_update(lcd_surface, x_start, y_start, width,
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
index b900d38b43..9ea25c1014 100644
--- a/firmware/target/hosted/sdl/system-sdl.c
+++ b/firmware/target/hosted/sdl/system-sdl.c
@@ -40,6 +40,13 @@
40#include "panic.h" 40#include "panic.h"
41#include "debug.h" 41#include "debug.h"
42 42
43#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
44#include <glib.h>
45#include <glib-object.h>
46#include "maemo-thread.h"
47
48#endif
49
43SDL_Surface *gui_surface; 50SDL_Surface *gui_surface;
44 51
45bool background = true; /* use backgrounds by default */ 52bool background = true; /* use backgrounds by default */
@@ -82,9 +89,13 @@ static int sdl_event_thread(void * param)
82{ 89{
83 SDL_InitSubSystem(SDL_INIT_VIDEO); 90 SDL_InitSubSystem(SDL_INIT_VIDEO);
84 91
92#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
93 SDL_sem *wait_for_maemo_startup;
94#endif
85 SDL_Surface *picture_surface = NULL; 95 SDL_Surface *picture_surface = NULL;
86 int width, height; 96 int width, height;
87 int depth; 97 int depth;
98 Uint32 flags;
88 99
89 /* Try and load the background image. If it fails go without */ 100 /* Try and load the background image. If it fails go without */
90 if (background) { 101 if (background) {
@@ -121,10 +132,21 @@ static int sdl_event_thread(void * param)
121 if (depth < 8) 132 if (depth < 8)
122 depth = 16; 133 depth = 16;
123 134
124 if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, depth, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) { 135 flags = SDL_HWSURFACE|SDL_DOUBLEBUF;
136#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
137 /* Fullscreen mode for maemo app */
138 flags |= SDL_FULLSCREEN;
139#endif
140
141 if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, depth, flags)) == NULL) {
125 panicf("%s", SDL_GetError()); 142 panicf("%s", SDL_GetError());
126 } 143 }
127 144
145#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
146 /* Hide mouse cursor on real touchscreen device */
147 SDL_ShowCursor(SDL_DISABLE);
148#endif
149
128 SDL_WM_SetCaption(UI_TITLE, NULL); 150 SDL_WM_SetCaption(UI_TITLE, NULL);
129 151
130 if (background && picture_surface != NULL) 152 if (background && picture_surface != NULL)
@@ -133,10 +155,30 @@ static int sdl_event_thread(void * param)
133 /* let system_init proceed */ 155 /* let system_init proceed */
134 SDL_SemPost((SDL_sem *)param); 156 SDL_SemPost((SDL_sem *)param);
135 157
158#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
159 /* Start maemo thread: Listen to display on/off events and battery monitoring */
160 wait_for_maemo_startup = SDL_CreateSemaphore(0); /* 0-count so it blocks */
161 SDL_Thread *maemo_thread = SDL_CreateThread(maemo_thread_func, wait_for_maemo_startup);
162#endif
163
136 /* 164 /*
137 * finally enter the button loop */ 165 * finally enter the button loop */
138 gui_message_loop(); 166 gui_message_loop();
139 167
168#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
169 /* Ensure maemo thread is up and running */
170 SDL_SemWait(wait_for_maemo_startup);
171 SDL_DestroySemaphore(wait_for_maemo_startup);
172
173#if (CONFIG_PLATFORM & PLATFORM_MAEMO5)
174 pcm_shutdown_gstreamer();
175#endif
176
177 g_main_loop_quit (maemo_main_loop);
178 g_main_loop_unref(maemo_main_loop);
179 SDL_WaitThread(maemo_thread, NULL);
180#endif
181
140 if(picture_surface) 182 if(picture_surface)
141 SDL_FreeSurface(picture_surface); 183 SDL_FreeSurface(picture_surface);
142 184
@@ -161,6 +203,12 @@ void system_init(void)
161{ 203{
162 SDL_sem *s; 204 SDL_sem *s;
163 205
206#if (CONFIG_PLATFORM & PLATFORM_MAEMO)
207 /* Make glib thread safe */
208 g_thread_init(NULL);
209 g_type_init();
210#endif
211
164 if (SDL_Init(SDL_INIT_TIMER)) 212 if (SDL_Init(SDL_INIT_TIMER))
165 panicf("%s", SDL_GetError()); 213 panicf("%s", SDL_GetError());
166 214