1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #if defined(MAEMO)
24
25 #define FORBIDDEN_SYMBOL_EXCEPTION_getenv
26
27 #include "common/scummsys.h"
28 #include "common/config-manager.h"
29
30 #include "backends/platform/maemo/maemo.h"
31 #include "backends/events/maemosdl/maemosdl-events.h"
32 #include "backends/graphics/maemosdl/maemosdl-graphics.h"
33 #include "backends/keymapper/action.h"
34 #include "backends/keymapper/keymapper.h"
35 #include "backends/keymapper/keymapper-defaults.h"
36 #include "common/textconsole.h"
37 #include "common/translation.h"
38
39 namespace Maemo {
40
OSystem_SDL_Maemo()41 OSystem_SDL_Maemo::OSystem_SDL_Maemo()
42 :
43 _eventObserver(0),
44 OSystem_POSIX() {
45 }
46
~OSystem_SDL_Maemo()47 OSystem_SDL_Maemo::~OSystem_SDL_Maemo() {
48 delete _eventObserver;
49 }
50
init()51 void OSystem_SDL_Maemo::init() {
52 // Use an iconless window for Maemo
53 // also N900 is hit by SDL_WM_SetIcon bug (window cannot receive input)
54 // http://bugzilla.libsdl.org/show_bug.cgi?id=586
55 initSDL();
56 _window = new SdlIconlessWindow();
57
58 OSystem_POSIX::init();
59 }
60
initBackend()61 void OSystem_SDL_Maemo::initBackend() {
62 ConfMan.registerDefault("fullscreen", true);
63 ConfMan.registerDefault("aspect_ratio", true);
64
65 // Create the events manager
66 if (_eventSource == 0)
67 _eventSource = new MaemoSdlEventSource();
68
69 if (_graphicsManager == 0)
70 _graphicsManager = new MaemoSdlGraphicsManager(_eventSource, _window);
71
72 if (_eventObserver == 0)
73 _eventObserver = new MaemoSdlEventObserver((MaemoSdlEventSource *)_eventSource);
74
75 _model = detectModel();
76
77 // Call parent implementation of this method
78 OSystem_POSIX::initBackend();
79 initObserver();
80 }
81
quit()82 void OSystem_SDL_Maemo::quit() {
83 delete this;
84 }
85
fatalError()86 void OSystem_SDL_Maemo::fatalError() {
87 delete this;
88 }
89
setXWindowName(const char * caption)90 void OSystem_SDL_Maemo::setXWindowName(const char *caption) {
91 SDL_SysWMinfo info;
92 if (_window->getSDLWMInformation(&info)) {
93 Display *dpy = info.info.x11.display;
94 Window win;
95 win = info.info.x11.fswindow;
96 if (win) XStoreName(dpy, win, caption);
97 win = info.info.x11.wmwindow;
98 if (win) XStoreName(dpy, win, caption);
99 }
100 }
101
setWindowCaption(const Common::U32String & caption)102 void OSystem_SDL_Maemo::setWindowCaption(const Common::U32String &caption) {
103 Common::String cap = caption.encode();
104 _window->setWindowCaption(cap);
105
106 Common::String cap2("ScummVM - "); // 2 lines in OS2008 task switcher, set first line
107 cap = cap2 + cap;
108 setXWindowName(cap.c_str());
109 }
110
111 static const Model models[] = {
112 {"SU-18", kModelType770, "770", false, true},
113 {"RX-34", kModelTypeN800, "N800", false, true},
114 {"RX-44", kModelTypeN810, "N810", true, true},
115 {"RX-48", kModelTypeN810, "N810W", true, true},
116 {"RX-51", kModelTypeN900, "N900", true, false},
117 {0, kModelTypeInvalid, 0, true, true}
118 };
119
detectModel()120 const Maemo::Model OSystem_SDL_Maemo::detectModel() {
121 Common::String deviceHwId = Common::String(getenv("SCUMMVM_MAEMO_DEVICE"));
122 const Model *model;
123 for (model = models; model->hwId; ++model) {
124 if (deviceHwId.equals(model->hwId))
125 return *model;
126 }
127 return *model;
128 }
129
130 static const Common::KeyTableEntry maemoKeys[] = {
131 // Function keys
132 {"MENU", Common::KEYCODE_F11, "Menu"},
133 {"HOME", Common::KEYCODE_F12, "Home"},
134 {"FULLSCREEN", Common::KEYCODE_F13, "FullScreen"},
135 {"ZOOMPLUS", Common::KEYCODE_F14, "Zoom+"},
136 {"ZOOMMINUS", Common::KEYCODE_F15, "Zoom-"},
137
138 {0, Common::KEYCODE_INVALID, 0}
139 };
140
getHardwareInputSet()141 Common::HardwareInputSet *OSystem_SDL_Maemo::getHardwareInputSet() {
142 Common::CompositeHardwareInputSet *inputSet = new Common::CompositeHardwareInputSet();
143 inputSet->addHardwareInputSet(new Common::MouseHardwareInputSet(Common::defaultMouseButtons));
144 inputSet->addHardwareInputSet(new Common::KeyboardHardwareInputSet(maemoKeys, Common::defaultModifiers));
145 inputSet->addHardwareInputSet(new Common::KeyboardHardwareInputSet(Common::defaultKeys, Common::defaultModifiers));
146
147 return inputSet;
148 }
149
getGlobalKeymaps()150 Common::KeymapArray OSystem_SDL_Maemo::getGlobalKeymaps() {
151 using namespace Common;
152 KeymapArray globalMaps = OSystem_POSIX::getGlobalKeymaps();
153
154 Keymap *globalMap = new Keymap(Keymap::kKeymapTypeGlobal, "maemo", "Maemo");
155
156 Action *act;
157
158 act = new Action("CLKM", _("Click Mode"));
159 act->setCustomBackendActionEvent(Maemo::kEventClickMode);
160 globalMap->addAction(act);
161
162 act = new Action(kStandardActionLeftClick, _("Left Click"));
163 act->setLeftClickEvent();
164 globalMap->addAction(act);
165
166 act = new Action(kStandardActionMiddleClick, _("Middle Click"));
167 act->setMiddleClickEvent();
168 globalMap->addAction(act);
169
170 act = new Action(kStandardActionRightClick, _("Right Click"));
171 act->setRightClickEvent();
172 globalMap->addAction(act);
173
174 globalMaps.push_back(globalMap);
175
176 return globalMaps;
177 }
178
getKeymapperDefaultBindings()179 Common::KeymapperDefaultBindings *OSystem_SDL_Maemo::getKeymapperDefaultBindings() {
180 Common::KeymapperDefaultBindings *keymapperDefaultBindings = new Common::KeymapperDefaultBindings();
181
182 keymapperDefaultBindings->setDefaultBinding("gui", "REMP", "HOME");
183 keymapperDefaultBindings->setDefaultBinding("global", "REMP", "HOME");
184
185 if (_model.hasMenuKey && _model.hasHwKeyboard) {
186 keymapperDefaultBindings->setDefaultBinding("gui", "FULS", "FULLSCREEN");
187 keymapperDefaultBindings->setDefaultBinding("global", "FULS", "FULLSCREEN");
188 }
189
190 if (_model.hasHwKeyboard) {
191 keymapperDefaultBindings->setDefaultBinding("gui", "VIRT", "C+ZOOMMINUS");
192 keymapperDefaultBindings->setDefaultBinding("global", "VIRT", "C+ZOOMMINUS");
193 } else {
194 keymapperDefaultBindings->setDefaultBinding("gui", "VIRT", "FULLSCREEN");
195 keymapperDefaultBindings->setDefaultBinding("global", "VIRT", "FULLSCREEN");
196 }
197
198 if (_model.hasMenuKey )
199 keymapperDefaultBindings->setDefaultBinding("global", "MENU", "MENU");
200 else
201 keymapperDefaultBindings->setDefaultBinding("global", "MENU", "S+C+M");
202
203 keymapperDefaultBindings->setDefaultBinding("gui", "CLOS", "ESCAPE");
204
205 keymapperDefaultBindings->setDefaultBinding("maemo", kStandardActionRightClick, "ZOOMPLUS");
206 keymapperDefaultBindings->setDefaultBinding("maemo", "CLKM", "ZOOMMINUS");
207
208 return keymapperDefaultBindings;
209 }
210
initObserver()211 void OSystem_SDL_Maemo::initObserver() {
212 assert(_eventManager);
213 _eventManager->getEventDispatcher()->registerObserver(_eventObserver, 10, false);
214 }
215
216 } //namespace Maemo
217
218 #endif
219