mouse.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* Mouse managing
  2. Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006,
  3. 2007, 2009 Free Software Foundation, Inc.
  4. Written by:
  5. Andrew Borodin <aborodin@vmail.ru>, 2009.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  17. /** \file mouse.c
  18. * \brief Source: mouse managing
  19. *
  20. * Events received by clients of this library have their coordinates 0 based
  21. */
  22. #include <config.h>
  23. #include <stdio.h>
  24. #include <sys/types.h>
  25. #include <unistd.h>
  26. #include "lib/global.h"
  27. #include "tty.h"
  28. #include "tty-internal.h" /* mouse_enabled */
  29. #include "mouse.h"
  30. #include "key.h" /* define sequence */
  31. gboolean mouse_enabled = FALSE;
  32. const char *xmouse_seq;
  33. void
  34. show_mouse_pointer (int x, int y)
  35. {
  36. #ifdef HAVE_LIBGPM
  37. if (use_mouse_p == MOUSE_GPM)
  38. Gpm_DrawPointer (x, y, gpm_consolefd);
  39. #else
  40. (void) x;
  41. (void) y;
  42. #endif /* HAVE_LIBGPM */
  43. }
  44. void
  45. init_mouse (void)
  46. {
  47. switch (use_mouse_p) {
  48. #ifdef HAVE_LIBGPM
  49. case MOUSE_NONE:
  50. use_mouse_p = MOUSE_GPM;
  51. break;
  52. #endif /* HAVE_LIBGPM */
  53. case MOUSE_XTERM_NORMAL_TRACKING:
  54. case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
  55. define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
  56. break;
  57. default:
  58. break;
  59. }
  60. enable_mouse ();
  61. }
  62. void
  63. enable_mouse (void)
  64. {
  65. if (mouse_enabled)
  66. return;
  67. switch (use_mouse_p) {
  68. #ifdef HAVE_LIBGPM
  69. case MOUSE_GPM:
  70. {
  71. int mouse_d;
  72. Gpm_Connect conn;
  73. conn.eventMask = ~GPM_MOVE;
  74. conn.defaultMask = GPM_MOVE;
  75. conn.minMod = 0;
  76. conn.maxMod = 0;
  77. mouse_d = Gpm_Open (&conn, 0);
  78. if (mouse_d == -1) {
  79. use_mouse_p = MOUSE_NONE;
  80. return;
  81. }
  82. mouse_enabled = 1;
  83. }
  84. break;
  85. #endif /* HAVE_LIBGPM */
  86. case MOUSE_XTERM_NORMAL_TRACKING:
  87. /* save old highlight mouse tracking */
  88. printf (ESC_STR "[?1001s");
  89. /* enable mouse tracking */
  90. printf (ESC_STR "[?1000h");
  91. fflush (stdout);
  92. mouse_enabled = TRUE;
  93. break;
  94. case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
  95. /* save old highlight mouse tracking */
  96. printf (ESC_STR "[?1001s");
  97. /* enable mouse tracking */
  98. printf (ESC_STR "[?1002h");
  99. fflush (stdout);
  100. mouse_enabled = TRUE;
  101. break;
  102. default:
  103. break;
  104. }
  105. }
  106. void
  107. disable_mouse (void)
  108. {
  109. if (!mouse_enabled)
  110. return;
  111. mouse_enabled = FALSE;
  112. switch (use_mouse_p) {
  113. #ifdef HAVE_LIBGPM
  114. case MOUSE_GPM:
  115. Gpm_Close ();
  116. break;
  117. #endif
  118. case MOUSE_XTERM_NORMAL_TRACKING:
  119. /* disable mouse tracking */
  120. printf (ESC_STR "[?1000l");
  121. /* restore old highlight mouse tracking */
  122. printf (ESC_STR "[?1001r");
  123. fflush (stdout);
  124. break;
  125. case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
  126. /* disable mouse tracking */
  127. printf (ESC_STR "[?1002l");
  128. /* restore old highlight mouse tracking */
  129. printf (ESC_STR "[?1001r");
  130. fflush (stdout);
  131. break;
  132. default:
  133. break;
  134. }
  135. }