--- ja2-0.12.1r6466.orig/sgp/Input.cc	2009-12-25 16:57:37.000000000 +0000
+++ ja2-0.12.1r6466/sgp/Input.cc	2009-12-25 16:55:01.000000000 +0000
@@ -111,6 +111,23 @@
 static BOOLEAN g_down_right;
 #endif
 
+#if defined WITH_MAEMO5
+static BOOLEAN g_down_right;
+BOOLEAN ProximitySensorCovered()
+{
+	char c[7];
+	FILE *file;  /* declare a FILE pointer  */
+	file = fopen("/sys/devices/platform/gpio-switch/proximity/state", "r"); 
+	if(file==NULL) {
+		return FALSE;
+	}
+	else {
+		fgets(c, 7, file); 
+		fclose(file);
+		return strcmp(c, "closed") == 0;
+	}
+}
+#endif
 
 void MouseButtonDown(const SDL_MouseButtonEvent* BtnEv)
 {
@@ -126,6 +143,12 @@
 			g_down_right = key_state[SDLK_F4];
 			if (g_down_right) goto right_button;
 #endif
+#if defined WITH_MAEMO5
+			/* If the proximity sensor is covered, then treat the event as
+			 * right click */
+			g_down_right = ProximitySensorCovered();
+			if (g_down_right) goto right_button;
+#endif
 			guiLeftButtonRepeatTimer = GetClock() + BUTTON_REPEAT_TIMEOUT;
 			gfLeftButtonState = TRUE;
 			QueueMouseEvent(LEFT_BUTTON_DOWN);
@@ -136,6 +159,9 @@
 #if defined WITH_MAEMO
 right_button:
 #endif
+#if defined WITH_MAEMO5
+right_button:
+#endif
 			guiRightButtonRepeatTimer = GetClock() + BUTTON_REPEAT_TIMEOUT;
 			gfRightButtonState = TRUE;
 			QueueMouseEvent(RIGHT_BUTTON_DOWN);
@@ -157,6 +183,9 @@
 #if defined WITH_MAEMO
 			if (g_down_right) goto right_button;
 #endif
+#if defined WITH_MAEMO5
+			if (g_down_right) goto right_button;
+#endif
 			guiLeftButtonRepeatTimer = 0;
 			gfLeftButtonState = FALSE;
 			QueueMouseEvent(LEFT_BUTTON_UP);
@@ -176,6 +205,9 @@
 #if defined WITH_MAEMO
 right_button:
 #endif
+#if defined WITH_MAEMO5
+right_button:
+#endif
 			guiRightButtonRepeatTimer = 0;
 			gfRightButtonState = FALSE;
 			QueueMouseEvent(RIGHT_BUTTON_UP);
