Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

KeyRemapper.cxx 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #include <stdio.h>
  19. #include <os/Mutex.h>
  20. #include <rfb/KeyRemapper.h>
  21. #include <rfb/Configuration.h>
  22. #include <rfb/LogWriter.h>
  23. using namespace rfb;
  24. static LogWriter vlog("KeyRemapper");
  25. KeyRemapper KeyRemapper::defInstance;
  26. KeyRemapper::KeyRemapper(const char* m)
  27. {
  28. mutex = new os::Mutex;
  29. setMapping(m);
  30. }
  31. KeyRemapper::~KeyRemapper()
  32. {
  33. delete mutex;
  34. }
  35. void KeyRemapper::setMapping(const char* m) {
  36. os::AutoMutex a(mutex);
  37. mapping.clear();
  38. while (m[0]) {
  39. int from, to;
  40. char bidi;
  41. const char* nextComma = strchr(m, ',');
  42. if (!nextComma)
  43. nextComma = m + strlen(m);
  44. if (sscanf(m, "0x%x%c>0x%x", &from,
  45. &bidi, &to) == 3) {
  46. if (bidi != '-' && bidi != '<')
  47. vlog.error("warning: unknown operation %c>, assuming ->", bidi);
  48. mapping[from] = to;
  49. if (bidi == '<')
  50. mapping[to] = from;
  51. } else {
  52. vlog.error("warning: bad mapping %.*s", (int)(nextComma-m), m);
  53. }
  54. m = nextComma;
  55. if (nextComma[0])
  56. m++;
  57. }
  58. }
  59. rdr::U32 KeyRemapper::remapKey(rdr::U32 key) const {
  60. os::AutoMutex a(mutex);
  61. std::map<rdr::U32,rdr::U32>::const_iterator i = mapping.find(key);
  62. if (i != mapping.end())
  63. return i->second;
  64. return key;
  65. }
  66. class KeyMapParameter : public StringParameter {
  67. public:
  68. KeyMapParameter()
  69. : StringParameter("RemapKeys", "Comma-separated list of incoming keysyms to remap. Mappings are expressed as two hex values, prefixed by 0x, and separated by ->", "") {
  70. setParam(value);
  71. }
  72. bool setParam(const char* v) {
  73. KeyRemapper::defInstance.setMapping(v);
  74. return StringParameter::setParam(v);
  75. }
  76. } defaultParam;