frontend: input: don't configure unprobed devices
[pcsx_rearmed.git] / maemo / hildon.c
... / ...
CommitLineData
1#include <gtk/gtk.h>
2#include <glib.h>
3#include <stdlib.h>
4#include <stdint.h>
5#include <unistd.h>
6#include <hildon/hildon.h>
7#include "plugin_lib.h"
8
9#include "main.h"
10#include "../libpcsxcore/psemu_plugin_defs.h"
11#include "common/readpng.h"
12#include "maemo_common.h"
13
14#define X_RES 800
15#define Y_RES 480
16#define D_WIDTH 640
17#define D_HEIGHT 480
18
19int g_layer_x = (X_RES - D_WIDTH) / 2;
20int g_layer_y = (Y_RES - D_HEIGHT) / 2;
21int g_layer_w = D_WIDTH, g_layer_h = D_HEIGHT;
22
23static GdkImage *image;
24static HildonAnimationActor *actor;
25static GtkWidget *window, *drawing;
26
27static int pl_buf_w, pl_buf_h;
28static int sens, y_def;
29static int keymap[65536];
30
31// map psx4m compatible keymap to PSX keys
32static const unsigned char keymap2[14] = {
33 DKEY_LEFT, // 0
34 DKEY_RIGHT,
35 DKEY_UP,
36 DKEY_DOWN,
37 DKEY_CIRCLE,
38 DKEY_CROSS, // 5
39 DKEY_TRIANGLE,
40 DKEY_SQUARE,
41 DKEY_SELECT,
42 DKEY_START,
43 DKEY_L2, // 10
44 DKEY_R2,
45 DKEY_L1,
46 DKEY_R1,
47};
48
49void hildon_quit()
50{
51 gtk_main_quit();
52 exit(0);
53}
54
55static void
56window_key_proxy(GtkWidget *widget,
57 GdkEventKey *event,
58 gpointer user_data)
59{
60 int key, psxkey1 = -1, psxkey2 = -1;
61
62 key = keymap[event->hardware_keycode];
63 if (key < 0)
64 return;
65
66 if (key < ARRAY_SIZE(keymap2))
67 psxkey1 = keymap2[key];
68 else switch (key) {
69 case 14:
70 hildon_quit();
71 break;
72 case 15:
73 psxkey1 = DKEY_UP;
74 psxkey2 = DKEY_LEFT;
75 break;
76 case 16:
77 psxkey1 = DKEY_UP;
78 psxkey2 = DKEY_RIGHT;
79 break;
80 case 17:
81 psxkey1 = DKEY_DOWN;
82 psxkey2 = DKEY_LEFT;
83 break;
84 case 18:
85 psxkey1 = DKEY_DOWN;
86 psxkey2 = DKEY_RIGHT;
87 break;
88 case 19:
89 if (event->type == GDK_KEY_PRESS)
90 {
91 emu_save_state(state_slot);
92 char buf[MAXPATHLEN];
93 sprintf (buf,"/opt/maemo/usr/games/screenshots%s.%3.3d",file_name,state_slot);
94 writepng(buf, image->mem, pl_buf_w,pl_buf_h);
95 }
96 return;
97 case 20:
98 if (event->type == GDK_KEY_PRESS)
99 emu_load_state(state_slot);
100 return;
101 case 21:
102 if (event->type == GDK_KEY_PRESS)
103 state_slot=(state_slot<9)?state_slot+1:0;
104 return;
105 case 22:
106 if (event->type == GDK_KEY_PRESS)
107 state_slot=(state_slot>0)?state_slot-1:8;
108 return;
109 }
110
111 if (event->type == GDK_KEY_PRESS) {
112 if (psxkey1 >= 0)
113 in_keystate |= 1 << psxkey1;
114 if (psxkey2 >= 0)
115 in_keystate |= 1 << psxkey2;
116 }
117 else if (event->type == GDK_KEY_RELEASE) {
118 if (psxkey1 >= 0)
119 in_keystate &= ~(1 << psxkey1);
120 if (psxkey2 >= 0)
121 in_keystate &= ~(1 << psxkey2);
122
123 emu_set_action(SACTION_NONE);
124 }
125}
126
127void plat_finish()
128{
129 hildon_quit();
130}
131
132void maemo_init(int *argc, char ***argv)
133{
134 FILE* pFile;
135 pFile = fopen("/opt/psx4m/keys", "r"); // assume the file exists and has data
136 int ch;
137 int i=0;
138 for (i=0;i<65536;i++)
139 keymap[i]=164;
140 if (NULL != pFile) {
141 for(i=0;i<21;i++){
142 fscanf(pFile, "%i",&ch);
143 keymap[ch]=i;
144 }
145 fclose(pFile);
146 }
147
148 pFile = fopen("/opt/psx4m/config", "r");
149 if (NULL != pFile) {
150 fscanf(pFile, "%d %d",&sens,&y_def);
151 fclose(pFile);
152 } else {
153 sens=150;
154 y_def=500; //near 45 degrees =)
155 }
156
157 gtk_init (argc, argv);
158
159 window = hildon_stackable_window_new ();
160 gtk_widget_realize (window);
161 gtk_window_fullscreen (GTK_WINDOW(window));
162 g_signal_connect (G_OBJECT (window), "key-press-event",
163 G_CALLBACK (window_key_proxy), NULL);
164 g_signal_connect (G_OBJECT (window), "key-release-event",
165 G_CALLBACK (window_key_proxy), NULL);
166 g_signal_connect (G_OBJECT (window), "delete_event",
167 G_CALLBACK (hildon_quit), NULL);
168 gtk_widget_add_events (window,
169 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
170
171 actor = HILDON_ANIMATION_ACTOR (hildon_animation_actor_new());
172 if (g_maemo_opts & 2)
173 hildon_animation_actor_set_position (actor, 0, 0 );
174 else
175 hildon_animation_actor_set_position (actor, (X_RES - D_WIDTH)/2, (Y_RES - D_HEIGHT)/2 );
176 hildon_animation_actor_set_parent (actor, GTK_WINDOW (window));
177
178 drawing = gtk_image_new ();
179
180 gtk_container_add (GTK_CONTAINER (actor), drawing);
181
182 gtk_widget_show_all (GTK_WIDGET (actor));
183 gtk_widget_show_all (GTK_WIDGET (window));
184}
185
186void menu_loop(void)
187{
188}
189
190void *hildon_set_mode(int w, int h)
191{
192 if (w <= 0 || h <= 0)
193 return pl_vout_buf;
194
195 if (image) gdk_image_destroy(image);
196 image = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(), w, h );
197
198 pl_vout_buf = (void *) image->mem;
199
200 gtk_image_set_from_image (GTK_IMAGE(drawing), image, NULL);
201
202 gtk_window_resize (GTK_WINDOW (actor), w, h);
203 if (g_maemo_opts & 2)
204 hildon_animation_actor_set_scale (actor,
205 (gdouble)800 / (gdouble)w,
206 (gdouble)480 / (gdouble)h
207 );
208 else
209 hildon_animation_actor_set_scale (actor,
210 (gdouble)D_WIDTH / (gdouble)w,
211 (gdouble)D_HEIGHT / (gdouble)h
212 );
213 pl_buf_w=w;pl_buf_h=h;
214 return pl_vout_buf;
215}
216
217void *hildon_flip(void)
218{
219 gtk_widget_queue_draw (drawing);
220
221 // process accelometer
222 if (g_maemo_opts & 4) {
223 int x, y, z;
224 FILE* f = fopen( "/sys/class/i2c-adapter/i2c-3/3-001d/coord", "r" );
225 if( !f ) {printf ("err in accel"); exit(1);}
226 fscanf( f, "%d %d %d", &x, &y, &z );
227 fclose( f );
228
229 if( x > sens ) in_keystate |= 1 << DKEY_LEFT;
230 else if( x < -sens ) in_keystate |= 1 << DKEY_RIGHT;
231 else {in_keystate &= ~(1 << DKEY_LEFT);in_keystate &= ~(1 << DKEY_RIGHT);}
232
233 y+=y_def;
234 if( y > sens )in_keystate |= 1 << DKEY_UP;
235 else if( y < -sens ) in_keystate |= 1 << DKEY_DOWN;
236 else {in_keystate &= ~(1 << DKEY_DOWN);in_keystate &= ~(1 << DKEY_UP);}
237
238 }
239
240 /* process GTK+ events */
241 while (gtk_events_pending())
242 gtk_main_iteration();
243
244 return pl_vout_buf;
245}
246
247int omap_enable_layer(int enabled)
248{
249 return 0;
250}
251
252void menu_notify_mode_change(int w, int h, int bpp)
253{
254}
255
256void *plat_prepare_screenshot(int *w, int *h, int *bpp)
257{
258 return NULL;
259}
260