mouse.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. /*** global variables ****************************************************************************/
  32. gboolean mouse_enabled = FALSE;
  33. const char *xmouse_seq;
  34. /*** file scope macro definitions ****************************************************************/
  35. /*** file scope type declarations ****************************************************************/
  36. /*** file scope variables ************************************************************************/
  37. /*** file scope functions ************************************************************************/
  38. /* --------------------------------------------------------------------------------------------- */
  39. /* --------------------------------------------------------------------------------------------- */
  40. /*** public functions ****************************************************************************/
  41. /* --------------------------------------------------------------------------------------------- */
  42. void
  43. show_mouse_pointer (int x, int y)
  44. {
  45. #ifdef HAVE_LIBGPM
  46. if (use_mouse_p == MOUSE_GPM)
  47. Gpm_DrawPointer (x, y, gpm_consolefd);
  48. #else
  49. (void) x;
  50. (void) y;
  51. #endif /* HAVE_LIBGPM */
  52. }
  53. /* --------------------------------------------------------------------------------------------- */
  54. void
  55. init_mouse (void)
  56. {
  57. switch (use_mouse_p)
  58. {
  59. #ifdef HAVE_LIBGPM
  60. case MOUSE_NONE:
  61. use_mouse_p = MOUSE_GPM;
  62. break;
  63. #endif /* HAVE_LIBGPM */
  64. case MOUSE_XTERM_NORMAL_TRACKING:
  65. case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
  66. define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
  67. break;
  68. default:
  69. break;
  70. }
  71. enable_mouse ();
  72. }
  73. /* --------------------------------------------------------------------------------------------- */
  74. void
  75. enable_mouse (void)
  76. {
  77. if (mouse_enabled)
  78. return;
  79. switch (use_mouse_p)
  80. {
  81. #ifdef HAVE_LIBGPM
  82. case MOUSE_GPM:
  83. {
  84. int mouse_d;
  85. Gpm_Connect conn;
  86. conn.eventMask = ~GPM_MOVE;
  87. conn.defaultMask = GPM_MOVE;
  88. conn.minMod = 0;
  89. conn.maxMod = 0;
  90. mouse_d = Gpm_Open (&conn, 0);
  91. if (mouse_d == -1)
  92. {
  93. use_mouse_p = MOUSE_NONE;
  94. return;
  95. }
  96. mouse_enabled = 1;
  97. }
  98. break;
  99. #endif /* HAVE_LIBGPM */
  100. case MOUSE_XTERM_NORMAL_TRACKING:
  101. /* save old highlight mouse tracking */
  102. printf (ESC_STR "[?1001s");
  103. /* enable mouse tracking */
  104. printf (ESC_STR "[?1000h");
  105. fflush (stdout);
  106. mouse_enabled = TRUE;
  107. break;
  108. case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
  109. /* save old highlight mouse tracking */
  110. printf (ESC_STR "[?1001s");
  111. /* enable mouse tracking */
  112. printf (ESC_STR "[?1002h");
  113. fflush (stdout);
  114. mouse_enabled = TRUE;
  115. break;
  116. default:
  117. break;
  118. }
  119. }
  120. /* --------------------------------------------------------------------------------------------- */
  121. void
  122. disable_mouse (void)
  123. {
  124. if (!mouse_enabled)
  125. return;
  126. mouse_enabled = FALSE;
  127. switch (use_mouse_p)
  128. {
  129. #ifdef HAVE_LIBGPM
  130. case MOUSE_GPM:
  131. Gpm_Close ();
  132. break;
  133. #endif
  134. case MOUSE_XTERM_NORMAL_TRACKING:
  135. /* disable mouse tracking */
  136. printf (ESC_STR "[?1000l");
  137. /* restore old highlight mouse tracking */
  138. printf (ESC_STR "[?1001r");
  139. fflush (stdout);
  140. break;
  141. case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
  142. /* disable mouse tracking */
  143. printf (ESC_STR "[?1002l");
  144. /* restore old highlight mouse tracking */
  145. printf (ESC_STR "[?1001r");
  146. fflush (stdout);
  147. break;
  148. default:
  149. break;
  150. }
  151. }
  152. /* --------------------------------------------------------------------------------------------- */