Ticket #757: remotekey.patch
File remotekey.patch, 18.9 KB (added by , 19 years ago) |
---|
-
libs/libmythtv/tv_play.cpp
52 52 53 53 void TV::InitKeys(void) 54 54 { 55 REG_KEY("TV Frontend", "PAGEUP", "Page Up", "3 ");56 REG_KEY("TV Frontend", "PAGEDOWN", "Page Down", "9 ");55 REG_KEY("TV Frontend", "PAGEUP", "Page Up", "3,remote3"); 56 REG_KEY("TV Frontend", "PAGEDOWN", "Page Down", "9,remote9"); 57 57 REG_KEY("TV Frontend", "DELETE", "Delete Program", "D"); 58 REG_KEY("TV Frontend", "PLAYBACK", "Play Program", "P ");58 REG_KEY("TV Frontend", "PLAYBACK", "Play Program", "P,remotePlay"); 59 59 REG_KEY("TV Frontend", "TOGGLERECORD", "Toggle recording status of current " 60 "program", "R ");60 "program", "R,remoteRecord"); 61 61 REG_KEY("TV Frontend", "DAYLEFT", "Page the program guide back one day", 62 62 "Home,7"); 63 63 REG_KEY("TV Frontend", "DAYRIGHT", "Page the program guide forward one day", … … 80 80 REG_KEY("TV Frontend", "DETAILS", "Show program details", "U"); 81 81 82 82 REG_KEY("TV Playback", "CLEAROSD", "Clear OSD", "Backspace"); 83 REG_KEY("TV Playback", "PAUSE", "Pause", "P ");83 REG_KEY("TV Playback", "PAUSE", "Pause", "P,remotePause"); 84 84 REG_KEY("TV Playback", "DELETE", "Delete Program", "D"); 85 REG_KEY("TV Playback", "SEEKFFWD", "Fast Forward", "Right ");86 REG_KEY("TV Playback", "SEEKRWND", "Rewind", "Left ");87 REG_KEY("TV Playback", "ARBSEEK", "Arbitrary Seek", "* ");88 REG_KEY("TV Playback", "CHANNELUP", "Channel up", "Up ");89 REG_KEY("TV Playback", "CHANNELDOWN", "Channel down", "Down ");85 REG_KEY("TV Playback", "SEEKFFWD", "Fast Forward", "Right,remoteRight"); 86 REG_KEY("TV Playback", "SEEKRWND", "Rewind", "Left,remoteLeft"); 87 REG_KEY("TV Playback", "ARBSEEK", "Arbitrary Seek", "*,remote*"); 88 REG_KEY("TV Playback", "CHANNELUP", "Channel up", "Up,remoteCh+"); 89 REG_KEY("TV Playback", "CHANNELDOWN", "Channel down", "Down,remoteCh-"); 90 90 REG_KEY("TV Playback", "NEXTFAV", "Switch to the next favorite channel", 91 91 "/"); 92 92 REG_KEY("TV Playback", "PREVCHAN", "Switch to the previous channel", "H"); 93 REG_KEY("TV Playback", "JUMPFFWD", "Jump ahead", "PgDown ");94 REG_KEY("TV Playback", "JUMPRWND", "Jump back", "PgUp ");93 REG_KEY("TV Playback", "JUMPFFWD", "Jump ahead", "PgDown,remoteDown"); 94 REG_KEY("TV Playback", "JUMPRWND", "Jump back", "PgUp,remoteUp"); 95 95 REG_KEY("TV Playback", "JUMPBKMRK", "Jump to bookmark", "K"); 96 96 REG_KEY("TV Playback", "FFWDSTICKY", "Fast Forward (Sticky) or Forward one " 97 "frame while paused", ">,. ");97 "frame while paused", ">,.,remoteFastForward"); 98 98 REG_KEY("TV Playback", "RWNDSTICKY", "Rewind (Sticky) or Rewind one frame " 99 "while paused", ",,< ");99 "while paused", ",,<,remoteRewind"); 100 100 REG_KEY("TV Playback", "TOGGLEINPUTS", "Toggle Inputs", "C"); 101 101 REG_KEY("TV Playback", "SWITCHCARDS", "Switch Capture Cards", "Y"); 102 REG_KEY("TV Playback", "SKIPCOMMERCIAL", "Skip Commercial", "Z,End ");102 REG_KEY("TV Playback", "SKIPCOMMERCIAL", "Skip Commercial", "Z,End,remoteSkipForward"); 103 103 REG_KEY("TV Playback", "SKIPCOMMBACK", "Skip Commercial (Reverse)", 104 "Q,Home ");104 "Q,Home,remoteSkipBackward"); 105 105 REG_KEY("TV Playback", "JUMPSTART", "Jump to the start of the recording.", "Ctrl+B"); 106 106 REG_KEY("TV Playback", "TOGGLEBROWSE", "Toggle channel browse mode", "O"); 107 107 REG_KEY("TV Playback", "TOGGLERECORD", "Toggle recording status of current " 108 "program", "R ");108 "program", "R,remoteRecord"); 109 109 REG_KEY("TV Playback", "TOGGLEFAV", "Toggle the current channel as a " 110 110 "favorite", "?"); 111 REG_KEY("TV Playback", "VOLUMEDOWN", "Volume down", "[,{,F10 ");112 REG_KEY("TV Playback", "VOLUMEUP", "Volume up", "],},F11 ");113 REG_KEY("TV Playback", "MUTE", "Mute", "|,\\,F9 ");111 REG_KEY("TV Playback", "VOLUMEDOWN", "Volume down", "[,{,F10,remoteVol+"); 112 REG_KEY("TV Playback", "VOLUMEUP", "Volume up", "],},F11,remoteVol-"); 113 REG_KEY("TV Playback", "MUTE", "Mute", "|,\\,F9,remoteMute"); 114 114 REG_KEY("TV Playback", "TOGGLEPIPMODE", "Toggle Picture-in-Picture mode", 115 115 "V"); 116 116 REG_KEY("TV Playback", "TOGGLEPIPWINDOW", "Toggle active PiP window", "B"); … … 137 137 REG_KEY("TV Playback", "TOGGLERECCONTROLS", "Turn on the recording picture " 138 138 "adjustment controls", "G"); 139 139 REG_KEY("TV Playback", "TOGGLEEDIT", "Start Edit Mode", "E"); 140 REG_KEY("TV Playback", "GUIDE", "Show the Program Guide", "S ");140 REG_KEY("TV Playback", "GUIDE", "Show the Program Guide", "S,remoteGuide"); 141 141 REG_KEY("TV Playback", "TOGGLESLEEP", "Toggle the Sleep Timer", "F8"); 142 REG_KEY("TV Playback", "PLAY", "Play", "Ctrl+P ");142 REG_KEY("TV Playback", "PLAY", "Play", "Ctrl+P,remotePlay"); 143 143 REG_KEY("TV Playback", "NEXTAUDIO", "Switch to the next audio track", "+"); 144 144 REG_KEY("TV Playback", "PREVAUDIO", "Switch to the previous audio track", "-"); 145 145 REG_KEY("TV Playback", "NEXTSUBTITLE", "Switch to the next subtitle track", ""); … … 151 151 REG_KEY("TV Editing", "INVERTMAP", "Invert Begin/End cut points", "I"); 152 152 REG_KEY("TV Editing", "LOADCOMMSKIP", "Load cut list from commercial skips", 153 153 "Z,End"); 154 REG_KEY("TV Editing", "NEXTCUT", "Jump to the next cut point", "PgDown ");155 REG_KEY("TV Editing", "PREVCUT", "Jump to the previous cut point", "PgUp ");154 REG_KEY("TV Editing", "NEXTCUT", "Jump to the next cut point", "PgDown,remoteDown"); 155 REG_KEY("TV Editing", "PREVCUT", "Jump to the previous cut point", "PgUp,remoteUp"); 156 156 REG_KEY("TV Editing", "BIGJUMPREW", "Jump back 10x the normal amount", 157 ",,< ");157 ",,<,remoteRewind"); 158 158 REG_KEY("TV Editing", "BIGJUMPFWD", "Jump forward 10x the normal amount", 159 ">,. ");160 REG_KEY("TV Editing", "TOGGLEEDIT", "Exit out of Edit Mode", "E ");159 ">,.,remoteFastForward"); 160 REG_KEY("TV Editing", "TOGGLEEDIT", "Exit out of Edit Mode", "E,remoteBack"); 161 161 /* 162 162 keys already used: 163 163 -
libs/libmyth/lirc.cpp
6 6 #include <sys/wait.h> 7 7 #include <sys/types.h> 8 8 #include <unistd.h> 9 #include <stdio.h> 9 10 10 11 #include "mythcontext.h" 11 12 … … 43 44 { 44 45 cerr << "Failed to read lirc config " << config_file << " for " 45 46 << program << endl; 46 lirc_deinit(); 47 return -1; 47 lircConfig = NULL; 48 48 } 49 49 50 50 external_app = gContext->GetSetting("LircKeyPressedApp") + " &"; … … 63 63 char *code = 0; 64 64 char *ir = 0; 65 65 int ret; 66 QString prevKey = ""; 66 67 67 68 /* Process all events read */ 68 69 while (lirc_nextcode(&ir) == 0) 69 70 { 70 71 if (!ir) 71 72 continue; 72 while ((ret = lirc_code2char(lircConfig, ir, &code)) == 0 && 73 QStringList parseKey = QStringList::split(" ", ir); 74 QString remKey = parseKey[2]; 75 76 int naction = 0; 77 78 while (lircConfig && (ret = lirc_code2char(lircConfig, ir, &code)) == 0 && 73 79 code != NULL) 74 80 { 75 81 QKeySequence a(code); 82 naction++; 76 83 77 84 int keycode = 0; 78 85 … … 87 94 { 88 95 keycode = a[i]; 89 96 90 QApplication::postEvent(mainWindow, new LircKeycodeEvent( code,97 QApplication::postEvent(mainWindow, new LircKeycodeEvent(remKey, 91 98 keycode, true)); 92 QApplication::postEvent(mainWindow, new LircKeycodeEvent( code,99 QApplication::postEvent(mainWindow, new LircKeycodeEvent(remKey, 93 100 keycode, false)); 94 101 95 102 SpawnApp(); 96 103 } 97 104 } 98 105 106 if (naction == 0) 107 { 108 /* LIRC failed to give an action for this key. Need to distinguish between 109 * 1) Key is held-down and LIRC is configured to not give repeat action (yet?) 110 * 2) Key is not configured in .mythtv/lircrc 111 * In the second case, issue event with remote keycode. It is detectable 112 * because parseKey[1] for it is "00" 113 */ 114 QString id = parseKey[1]; 115 if (id == "00") 116 { 117 QApplication::postEvent(mainWindow, new LircKeycodeEvent(remKey, 118 0, true)); 119 QApplication::postEvent(mainWindow, new LircKeycodeEvent(remKey, 120 0, false)); 121 122 SpawnApp(); 123 } 124 } 125 126 prevKey = remKey; 127 99 128 free(ir); 100 129 if (ret == -1) 101 130 break; -
libs/libmyth/mythdialogs.cpp
42 42 #include "screensaver.h" 43 43 #include "mythdbcon.h" 44 44 45 typedef QValueList<int> KeyList; 46 45 47 #ifdef USE_LIRC 46 48 static void *SpawnLirc(void *param) 47 49 { … … 113 115 class MythMainWindowPrivate 114 116 { 115 117 public: 116 int TranslateKeyNum(QKeyEvent *e); 118 MythMainWindowPrivate(void) { nextKeycode = Qt::UNICODE_ACCEL; } 119 KeyList TranslateKeyNum(QKeyEvent *e); 120 int TranslateRemoteKey(QString key); 117 121 118 122 float wmult, hmult; 119 123 int screenwidth, screenheight; … … 138 142 QMap<QString, MHData> mediaHandlerMap; 139 143 QMap<QString, MPData> mediaPluginMap; 140 144 145 QMap<QString, int> remoteKeymap; 146 147 QMap<QString, int> remoteMap; 148 int nextKeycode; 149 141 150 void (*exitmenucallback)(void); 142 151 143 152 void (*exitmenumediadevicecallback)(MythMediaDevice* mediadevice); … … 146 155 int escapekey; 147 156 }; 148 157 158 int MythMainWindowPrivate::TranslateRemoteKey(QString key) 159 { 160 key = key.lower(); 161 if (!remoteKeymap.contains(key)) 162 remoteKeymap.insert(key, nextKeycode++); 163 return remoteKeymap[key]; 164 } 165 149 166 // Make keynum in QKeyEvent be equivalent to what's in QKeySequence 150 int MythMainWindowPrivate::TranslateKeyNum(QKeyEvent* e)167 KeyList MythMainWindowPrivate::TranslateKeyNum(QKeyEvent* e) 151 168 { 169 KeyList rv; 152 170 int keynum = e->key(); 153 171 172 QString text = e->text(); 173 if (text.left(6) == "remote") 174 { 175 QString remoteKey = text.mid(6); 176 rv.append(TranslateRemoteKey(remoteKey)); 177 } 178 154 179 if (keynum != Qt::Key_Escape && 155 180 (keynum < Qt::Key_Shift || keynum > Qt::Key_ScrollLock)) 156 181 { … … 164 189 ((modifiers & Qt::MetaButton) ? Qt::META : 0) | 165 190 ((modifiers & Qt::AltButton) ? Qt::ALT : 0); 166 191 modnum &= ~Qt::UNICODE_ACCEL; 167 return (keynum |= modnum); 192 rv.append(keynum | modnum); 193 return rv; 168 194 } 169 195 } 170 196 171 return keynum; 197 rv.append(keynum); 198 return rv; 172 199 } 173 200 174 201 MythMainWindow::MythMainWindow(QWidget *parent, const char *name, bool modal, … … 207 234 208 235 d->keyContexts.setAutoDelete(true); 209 236 210 RegisterKey("Global", "UP", "Up Arrow", "Up ");211 RegisterKey("Global", "DOWN", "Down Arrow", "Down ");212 RegisterKey("Global", "LEFT", "Left Arrow", "Left ");213 RegisterKey("Global", "RIGHT", "Right Arrow", "Right ");214 RegisterKey("Global", "SELECT", "Select", "Return,Enter,Space ");215 RegisterKey("Global", "ESCAPE", "Escape", "Esc ");216 RegisterKey("Global", "MENU", "Pop-up menu", "M ");237 RegisterKey("Global", "UP", "Up Arrow", "Up,remoteUp"); 238 RegisterKey("Global", "DOWN", "Down Arrow", "Down,remoteDown"); 239 RegisterKey("Global", "LEFT", "Left Arrow", "Left,remoteLeft"); 240 RegisterKey("Global", "RIGHT", "Right Arrow", "Right,remoteRight"); 241 RegisterKey("Global", "SELECT", "Select", "Return,Enter,Space,remoteOK,remoteEnter"); 242 RegisterKey("Global", "ESCAPE", "Escape", "Esc,remoteBack"); 243 RegisterKey("Global", "MENU", "Pop-up menu", "M,remoteMenu"); 217 244 RegisterKey("Global", "INFO", "More information", "I"); 218 245 219 246 RegisterKey("Global", "PAGEUP", "Page Up", "PgUp"); … … 224 251 225 252 RegisterKey("Global", "HELP", "Help", "F1"); 226 253 227 RegisterKey("Global", "0", "0", "0 ");228 RegisterKey("Global", "1", "1", "1 ");229 RegisterKey("Global", "2", "2", "2 ");230 RegisterKey("Global", "3", "3", "3 ");231 RegisterKey("Global", "4", "4", "4 ");232 RegisterKey("Global", "5", "5", "5 ");233 RegisterKey("Global", "6", "6", "6 ");234 RegisterKey("Global", "7", "7", "7 ");235 RegisterKey("Global", "8", "8", "8 ");236 RegisterKey("Global", "9", "9", "9 ");254 RegisterKey("Global", "0", "0", "0,remote0"); 255 RegisterKey("Global", "1", "1", "1,remote1"); 256 RegisterKey("Global", "2", "2", "2,remote2"); 257 RegisterKey("Global", "3", "3", "3,remote3"); 258 RegisterKey("Global", "4", "4", "4,remote4"); 259 RegisterKey("Global", "5", "5", "5,remote5"); 260 RegisterKey("Global", "6", "6", "6,remote6"); 261 RegisterKey("Global", "7", "7", "7,remote7"); 262 RegisterKey("Global", "8", "8", "8,remote8"); 263 RegisterKey("Global", "9", "9", "9,remote9"); 237 264 } 238 265 239 266 MythMainWindow::~MythMainWindow() … … 410 437 bool allowJumps) 411 438 { 412 439 actions.clear(); 413 int keynum = d->TranslateKeyNum(e);440 QString text = e->text(); 414 441 415 if (allowJumps && 416 d->jumpMap.count(keynum) > 0 && d->exitmenucallback == NULL) 417 { 418 d->exitingtomain = true; 419 d->exitmenucallback = d->jumpMap[keynum]->callback; 420 QApplication::postEvent(this, new ExitToMainMenuEvent()); 421 return false; 422 } 442 KeyList keylist = d->TranslateKeyNum(e); 423 443 424 444 bool retval = false; 425 445 426 if (d->keyContexts[context])446 for (unsigned int i = 0; i < keylist.count(); i++) 427 447 { 428 if (d->keyContexts[context]->GetMapping(keynum, actions)) 429 retval = true; 448 int keynum = keylist[i]; 449 450 if (allowJumps && 451 d->jumpMap.count(keynum) > 0 && d->exitmenucallback == NULL) 452 { 453 d->exitingtomain = true; 454 d->exitmenucallback = d->jumpMap[keynum]->callback; 455 QApplication::postEvent(this, new ExitToMainMenuEvent()); 456 return false; 457 } 458 459 if (d->keyContexts[context]) 460 { 461 if (d->keyContexts[context]->GetMapping(keynum, actions)) 462 retval = true; 463 } 464 465 if (d->keyContexts["Global"]->GetMapping(keynum, actions)) 466 retval = true; 430 467 } 431 468 432 if (d->keyContexts["Global"]->GetMapping(keynum, actions))433 retval = true;434 435 469 return retval; 436 470 } 437 471 … … 463 497 } 464 498 } 465 499 500 void MythMainWindow::ParseKeys(QString key, QValueList<int> &keyseq) 501 { 502 /* This handles "," mappings funnily. The first part produces 503 * empty entries in keys for them. numremote ensures that these 504 * empty entries recreate the ,'s in the output, so that 505 * QKeySequence gets something it'll interpret as a comma. 506 */ 507 keyseq.clear(); 508 if (key.isEmpty()) return; 509 QStringList keys = QStringList::split(",", key, true); 510 QString nonremoteKeys = ""; 511 int numremote = 0; 512 for (unsigned int i = 0; i < keys.count(); i++) 513 { 514 QString code = keys[i]; 515 if (code.left(6) == "remote") 516 keyseq.append(d->TranslateRemoteKey(code.mid(6))); 517 else 518 { 519 if (numremote > 0) nonremoteKeys += ','; 520 nonremoteKeys += code; 521 numremote++; 522 } 523 } 524 if (!nonremoteKeys.isEmpty()) 525 { 526 QKeySequence keycodeSeq(nonremoteKeys); 527 for (unsigned int i = 0; i < keycodeSeq.count(); i++) 528 { 529 keyseq.append(keycodeSeq[i] & ~Qt::UNICODE_ACCEL); 530 } 531 } 532 } 533 534 466 535 void MythMainWindow::BindKey(const QString &context, const QString &action, 467 536 const QString &key) 468 537 { 469 QKeySequence keyseq(key);470 471 538 if (!d->keyContexts[context]) 472 539 d->keyContexts.insert(context, new KeyContext()); 473 540 541 QValueList<int> keyseq; 542 ParseKeys(key, keyseq); 543 474 544 for (unsigned int i = 0; i < keyseq.count(); i++) 475 545 { 476 546 int keynum = keyseq[i]; 477 keynum &= ~Qt::UNICODE_ACCEL;478 547 479 548 QStringList dummyaction = ""; 480 549 if (d->keyContexts[context]->GetMapping(keynum, dummyaction)) … … 591 660 return; 592 661 } 593 662 594 QKeySequence keyseq(key); 663 QValueList<int> keyseq; 664 ParseKeys(key, keyseq); 595 665 596 666 if (!keyseq.isEmpty()) 597 667 { 598 668 int keynum = keyseq[0]; 599 keynum &= ~Qt::UNICODE_ACCEL;600 669 601 670 if (d->jumpMap.count(keynum) == 0) 602 671 { … … 812 881 { 813 882 LircKeycodeEvent *lke = (LircKeycodeEvent *)ce; 814 883 int keycode = lke->getKeycode(); 884 QString text; 815 885 886 int mod = keycode & MODIFIER_MASK; 887 int ascii = 0; 888 int k = keycode & ~MODIFIER_MASK; /* trim off the mod */ 889 890 gContext->ResetScreensaver(); 891 816 892 if (keycode) 817 893 { 818 gContext->ResetScreensaver();819 894 820 int mod = keycode & MODIFIER_MASK;821 int k = keycode & ~MODIFIER_MASK; /* trim off the mod */822 int ascii = 0;823 QString text;824 825 895 if (k & UNICODE_ACCEL) 826 896 { 827 897 QChar c(k & ~UNICODE_ACCEL); … … 834 904 ((mod & Qt::ALT) ? Qt::AltButton : 0) | 835 905 ((mod & Qt::SHIFT) ? Qt::ShiftButton : 0); 836 906 837 QKeyEvent key(lke->isKeyDown() ? QEvent::KeyPress :838 QEvent::KeyRelease, k, ascii, mod, text);907 } 908 text = QString("remote") + lke->getLircText(); 839 909 840 QObject *key_target = getTarget(key); 910 QKeyEvent key(lke->isKeyDown() ? QEvent::KeyPress : 911 QEvent::KeyRelease, k, ascii, mod, text); 841 912 842 QApplication::sendEvent(key_target, &key);843 } 844 else845 {846 847 848 849 }913 QObject *key_target = getTarget(key); 914 915 QApplication::sendEvent(key_target, &key); 916 /* 917 cerr << "LircClient warning: attempt to convert '" 918 << lke->getLircText() << "' to a key sequence failed. Fix" 919 " your key mappings.\n"; 920 */ 850 921 } 851 922 else if (ce->type() == kLircMuteEventType) 852 923 { -
libs/libmyth/mythdialogs.h
118 118 void JumpTo(const QString &destination); 119 119 bool DestinationExists(const QString &destination) const; 120 120 121 122 121 protected: 123 122 void keyPressEvent(QKeyEvent *e); 124 123 void customEvent(QCustomEvent *ce); … … 126 125 127 126 void ExitToMainMenu(); 128 127 128 void ParseKeys(QString key, QValueList<int> &keylist); 129 129 QObject *getTarget(QKeyEvent &key); 130 130 131 131 MythMainWindowPrivate *d;