Moved dir $(srcdir)/syntax into $(srcdir)/misc/syntax
[midnight-commander.git] / src / tty / mouse.c
bloba811c05b47c286f00c0702f770aaf1950e1a2d6f
1 /* Mouse managing
2 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006,
3 2007, 2009 Free Software Foundation, Inc.
5 Written by:
6 Andrew Borodin <aborodin@vmail.ru>, 2009.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 /** \file mouse.c
23 * \brief Source: mouse managing
25 * Events received by clients of this library have their coordinates 0 based
28 #include <config.h>
30 #include <stdio.h>
31 #include <sys/types.h>
32 #include <unistd.h>
34 #include "../../src/global.h"
36 #include "../../src/tty/tty.h"
37 #include "../../src/tty/tty-internal.h" /* mouse_enabled */
38 #include "../../src/tty/mouse.h"
39 #include "../../src/tty/key.h" /* define sequence */
41 gboolean mouse_enabled = FALSE;
42 const char *xmouse_seq;
44 void
45 show_mouse_pointer (int x, int y)
47 #ifdef HAVE_LIBGPM
48 if (use_mouse_p == MOUSE_GPM)
49 Gpm_DrawPointer (x, y, gpm_consolefd);
50 #endif /* HAVE_LIBGPM */
53 void
54 init_mouse (void)
56 switch (use_mouse_p) {
57 #ifdef HAVE_LIBGPM
58 case MOUSE_NONE:
59 use_mouse_p = MOUSE_GPM;
60 break;
61 #endif /* HAVE_LIBGPM */
63 case MOUSE_XTERM_NORMAL_TRACKING:
64 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
65 define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
66 break;
68 default:
69 break;
72 enable_mouse ();
75 void
76 enable_mouse (void)
78 if (mouse_enabled)
79 return;
81 switch (use_mouse_p) {
82 #ifdef HAVE_LIBGPM
83 case MOUSE_GPM:
85 int mouse_d;
86 Gpm_Connect conn;
88 conn.eventMask = ~GPM_MOVE;
89 conn.defaultMask = GPM_MOVE;
90 conn.minMod = 0;
91 conn.maxMod = 0;
93 mouse_d = Gpm_Open (&conn, 0);
94 if (mouse_d == -1) {
95 use_mouse_p = MOUSE_NONE;
96 return;
98 mouse_enabled = 1;
100 break;
101 #endif /* HAVE_LIBGPM */
103 case MOUSE_XTERM_NORMAL_TRACKING:
104 /* save old highlight mouse tracking */
105 printf (ESC_STR "[?1001s");
107 /* enable mouse tracking */
108 printf (ESC_STR "[?1000h");
110 fflush (stdout);
111 mouse_enabled = TRUE;
112 break;
114 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
115 /* save old highlight mouse tracking */
116 printf (ESC_STR "[?1001s");
118 /* enable mouse tracking */
119 printf (ESC_STR "[?1002h");
121 fflush (stdout);
122 mouse_enabled = TRUE;
123 break;
125 default:
126 break;
130 void
131 disable_mouse (void)
133 if (!mouse_enabled)
134 return;
136 mouse_enabled = FALSE;
138 switch (use_mouse_p) {
139 #ifdef HAVE_LIBGPM
140 case MOUSE_GPM:
141 Gpm_Close ();
142 break;
143 #endif
144 case MOUSE_XTERM_NORMAL_TRACKING:
145 /* disable mouse tracking */
146 printf (ESC_STR "[?1000l");
148 /* restore old highlight mouse tracking */
149 printf (ESC_STR "[?1001r");
151 fflush (stdout);
152 break;
153 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
154 /* disable mouse tracking */
155 printf (ESC_STR "[?1002l");
157 /* restore old highlight mouse tracking */
158 printf (ESC_STR "[?1001r");
160 fflush (stdout);
161 break;
162 default:
163 break;