summaryrefslogtreecommitdiff
authoralwin <alwin>2004-08-02 08:19:00 (UTC)
committer alwin <alwin>2004-08-02 08:19:00 (UTC)
commiteb1b398e44c55058d65be0a8d5d8c24db9b6d874 (patch) (unidiff)
tree5c7b84214e1a414f1de7d006cea49f57addabc82
parent26e22b14963afc0e75b9bfdbdf97110249ae87c5 (diff)
downloadopie-eb1b398e44c55058d65be0a8d5d8c24db9b6d874.zip
opie-eb1b398e44c55058d65be0a8d5d8c24db9b6d874.tar.gz
opie-eb1b398e44c55058d65be0a8d5d8c24db9b6d874.tar.bz2
ignore keys no actions are defined
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/zkbapplet/keyzcfg/zkb.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/noncore/applets/zkbapplet/keyzcfg/zkb.cpp b/noncore/applets/zkbapplet/keyzcfg/zkb.cpp
index a357b88..3cc3669 100644
--- a/noncore/applets/zkbapplet/keyzcfg/zkb.cpp
+++ b/noncore/applets/zkbapplet/keyzcfg/zkb.cpp
@@ -166,212 +166,213 @@ State::State(State* p):parent(p), keys(0) {
166 166
167State::State(const State& s) { 167State::State(const State& s) {
168 parent = s.parent; 168 parent = s.parent;
169 keys = new Action[Key_Max * 2 + 1]; 169 keys = new Action[Key_Max * 2 + 1];
170 memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1)); 170 memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1));
171} 171}
172 172
173State::~State() { 173State::~State() {
174 if (keys!=0) { 174 if (keys!=0) {
175 delete [] keys; 175 delete [] keys;
176 } 176 }
177} 177}
178 178
179Action* State::get(int keycode, bool pressed, bool follow) const { 179Action* State::get(int keycode, bool pressed, bool follow) const {
180 Action* ret = 0; 180 Action* ret = 0;
181 int n = translateKeycode(keycode); 181 int n = translateKeycode(keycode);
182 182
183 if (n != -1 && keys != 0) { 183 if (n != -1 && keys != 0) {
184 if (pressed) { 184 if (pressed) {
185 n += Key_Max; 185 n += Key_Max;
186 } 186 }
187 ret = &keys[n]; 187 ret = &keys[n];
188 } 188 }
189 189
190 if (ret==0 || !ret->isDefined()) { 190 if (ret==0 || !ret->isDefined()) {
191 if (follow && parent!=0) { 191 if (follow && parent!=0) {
192 ret = parent->get(keycode, pressed, follow); 192 ret = parent->get(keycode, pressed, follow);
193 } 193 }
194 } 194 }
195 195
196 return ret; 196 return ret;
197} 197}
198 198
199bool State::set(int keycode, bool pressed, Action& action) { 199bool State::set(int keycode, bool pressed, Action& action) {
200 int n = translateKeycode(keycode); 200 int n = translateKeycode(keycode);
201 201
202 if (n==-1 || keys==0) { 202 if (n==-1 || keys==0) {
203 return false; 203 return false;
204 } 204 }
205 205
206 if (pressed) { 206 if (pressed) {
207 n += Key_Max + 1; 207 n += Key_Max + 1;
208 } 208 }
209 209
210 keys[n] = action; 210 keys[n] = action;
211 return true; 211 return true;
212} 212}
213 213
214State* State::getParent() const { 214State* State::getParent() const {
215 return parent; 215 return parent;
216} 216}
217 217
218void State::setParent(State* s) { 218void State::setParent(State* s) {
219 parent = s; 219 parent = s;
220} 220}
221 221
222int State::translateKeycode(int keycode) const { 222int State::translateKeycode(int keycode) const {
223 if (keycode < 0x20) { 223 if (keycode < 0x20) {
224 return -1; 224 return -1;
225 } 225 }
226 226
227 if (keycode < 0x80) { 227 if (keycode < 0x80) {
228 return x1[keycode - 0x20]; 228 return x1[keycode - 0x20];
229 } 229 }
230 230
231 if (keycode < 0x1000) { 231 if (keycode < 0x1000) {
232 return -1; 232 return -1;
233 } 233 }
234 234
235 if (keycode < 0x1057) { 235 if (keycode < 0x1057) {
236 return x2[keycode - 0x1000]; 236 return x2[keycode - 0x1000];
237 } 237 }
238 238
239 return -1; 239 return -1;
240} 240}
241 241
242// Implementation of Keymap class 242// Implementation of Keymap class
243Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { 243Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) {
244 repeatDelay=400; 244 repeatDelay=400;
245 repeatPeriod=80; 245 repeatPeriod=80;
246 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); 246 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat()));
247} 247}
248 248
249Keymap::~Keymap() { 249Keymap::~Keymap() {
250 odebug << "removing keyboard filter for zkb"<<oendl; 250 odebug << "removing keyboard filter for zkb"<<oendl;
251 Opie::Core::OKeyFilter::inst()->remHandler(this); 251 Opie::Core::OKeyFilter::inst()->remHandler(this);
252 QMap<QString, State*>::Iterator it; 252 QMap<QString, State*>::Iterator it;
253 for(it = states.begin(); it != states.end(); ++it) { 253 for(it = states.begin(); it != states.end(); ++it) {
254 delete it.data(); 254 delete it.data();
255 } 255 }
256 states.clear(); 256 states.clear();
257} 257}
258 258
259bool Keymap::filter(int unicode, int keycode, int modifiers, 259bool Keymap::filter(int unicode, int keycode, int modifiers,
260 bool isPress, bool autoRepeat) { 260 bool isPress, bool autoRepeat) {
261 261
262 odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode
263 << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl;
264
265 if (!enabled) { 262 if (!enabled) {
266 return false; 263 return false;
267 } 264 }
268 265
266 odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode
267 << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl;
268
269 // the second check is workaround to make suspend work if 269 // the second check is workaround to make suspend work if
270 // the user pressed it right after he did resume. for some 270 // the user pressed it right after he did resume. for some
271 // reason the event sent by qt has autoRepeat true in this 271 // reason the event sent by qt has autoRepeat true in this
272 // case 272 // case
273 if (autoRepeat && keycode != 4177) { 273 if (autoRepeat && keycode != 4177) {
274 return true; 274 return true;
275 } 275 }
276 276
277 (void) unicode; (void) modifiers; 277 (void) unicode; (void) modifiers;
278 278
279 Action* action = currentState->get(keycode, isPress, true); 279 Action* action = currentState->get(keycode, isPress, true);
280 if (action==0 || !action->isDefined()) { 280 if (action==0 || !action->isDefined()) {
281 return true; 281 odebug << "no action defined for that"<<oendl;
282 return false;
282 } 283 }
283 284
284 if (action->hasEvent()) { 285 if (action->hasEvent()) {
285 odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode() 286 odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode()
286 << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl; 287 << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl;
287 288
288 QWSServer::sendKeyEvent(action->getUnicode(), 289 QWSServer::sendKeyEvent(action->getUnicode(),
289 action->getKeycode(), action->getModifiers(), 290 action->getKeycode(), action->getModifiers(),
290 action->isPressed(), false); 291 action->isPressed(), false);
291 } 292 }
292 293
293 if (action->isAutorepeat()) { 294 if (action->isAutorepeat()) {
294 autoRepeatAction = action; 295 autoRepeatAction = action;
295 repeater.start(repeatDelay, TRUE); 296 repeater.start(repeatDelay, TRUE);
296 } else { 297 } else {
297 autoRepeatAction = 0; 298 autoRepeatAction = 0;
298 } 299 }
299 300
300 State* nstate = action->getState(); 301 State* nstate = action->getState();
301 if (nstate != 0) { 302 if (nstate != 0) {
302 setCurrentState(nstate); 303 setCurrentState(nstate);
303 QString lbl = getCurrentLabel(); 304 QString lbl = getCurrentLabel();
304 if (!lbl.isEmpty()) { 305 if (!lbl.isEmpty()) {
305 emit stateChanged(lbl); 306 emit stateChanged(lbl);
306 } 307 }
307 } 308 }
308 309
309 310
310 return true; 311 return true;
311} 312}
312 313
313void Keymap::enable() { 314void Keymap::enable() {
314 enabled = true; 315 enabled = true;
315} 316}
316 317
317void Keymap::disable() { 318void Keymap::disable() {
318 enabled = false; 319 enabled = false;
319} 320}
320 321
321QStringList Keymap::listStates() { 322QStringList Keymap::listStates() {
322 QStringList ret; 323 QStringList ret;
323 324
324 QMap<QString, State*>::Iterator it; 325 QMap<QString, State*>::Iterator it;
325 for(it = states.begin(); it != states.end(); ++it) { 326 for(it = states.begin(); it != states.end(); ++it) {
326 ret.append(it.key()); 327 ret.append(it.key());
327 } 328 }
328 329
329 return ret; 330 return ret;
330} 331}
331 332
332State* Keymap::getStateByName(const QString& name) { 333State* Keymap::getStateByName(const QString& name) {
333 QMap<QString, State*>::Iterator it = states.find(name); 334 QMap<QString, State*>::Iterator it = states.find(name);
334 335
335 if (it == states.end()) { 336 if (it == states.end()) {
336 return 0; 337 return 0;
337 } 338 }
338 339
339 return it.data(); 340 return it.data();
340} 341}
341 342
342QStringList Keymap::listLabels() { 343QStringList Keymap::listLabels() {
343 QStringList ret; 344 QStringList ret;
344 345
345 for(uint i = 0; i < labelList.count(); i++) { 346 for(uint i = 0; i < labelList.count(); i++) {
346 ret.append(*labelList.at(i)); 347 ret.append(*labelList.at(i));
347 } 348 }
348 349
349 return ret; 350 return ret;
350} 351}
351 352
352State* Keymap::getStateByLabel(const QString& label) { 353State* Keymap::getStateByLabel(const QString& label) {
353 QMap<QString, QString>::Iterator lit = labels.find(label); 354 QMap<QString, QString>::Iterator lit = labels.find(label);
354 State* state = 0; 355 State* state = 0;
355 356
356 if (lit == labels.end()) { 357 if (lit == labels.end()) {
357 return 0; 358 return 0;
358 } 359 }
359 360
360 QString name = lit.data(); 361 QString name = lit.data();
361 362
362 int n = name.find(":*"); 363 int n = name.find(":*");
363 if (n>=0 && n==(int)(name.length()-2)) { 364 if (n>=0 && n==(int)(name.length()-2)) {
364 name=name.left(name.length() - 1); 365 name=name.left(name.length() - 1);
365 366
366 n = currentStateName.findRev(":"); 367 n = currentStateName.findRev(":");
367 if (n >= 0) { 368 if (n >= 0) {
368 name += currentStateName.mid(n+1); 369 name += currentStateName.mid(n+1);
369 } 370 }
370 } 371 }
371 372
372// odebug << "look for: " << name.utf8() << "\n" << oendl; 373// odebug << "look for: " << name.utf8() << "\n" << oendl;
373 QMap<QString, State*>::Iterator sit = states.find(name); 374 QMap<QString, State*>::Iterator sit = states.find(name);
374 if (sit != states.end()) { 375 if (sit != states.end()) {
375 state = sit.data(); 376 state = sit.data();
376 } 377 }
377 378