mouse.c 5.1 KB

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