(edit_move_block_to_left): reduce variable scope.
[midnight-commander.git] / lib / tty / mouse.c
blobe9542e2d16801a4175a55588891b4538e1e8ad34
1 /*
2 Mouse managing
4 Copyright (C) 1994-2016
5 Free Software Foundation, Inc.
7 Written by:
8 Andrew Borodin <aborodin@vmail.ru>, 2009.
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software: you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation, either version 3 of the License,
15 or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 /** \file mouse.c
27 * \brief Source: mouse managing
29 * Events received by clients of this library have their coordinates 0 based
32 #include <config.h>
34 #include <stdio.h>
35 #include <sys/types.h>
36 #include <unistd.h>
38 #include "lib/global.h"
40 #include "tty.h"
41 #include "tty-internal.h" /* mouse_enabled */
42 #include "mouse.h"
43 #include "key.h" /* define sequence */
45 /*** global variables ****************************************************************************/
47 Mouse_Type use_mouse_p = MOUSE_NONE;
48 gboolean mouse_enabled = FALSE;
49 int mouse_fd = -1; /* for when gpm_fd changes to < 0 and the old one must be cleared from select_set */
50 const char *xmouse_seq;
51 const char *xmouse_extended_seq;
53 /*** file scope macro definitions ****************************************************************/
55 /*** file scope type declarations ****************************************************************/
57 /*** file scope variables ************************************************************************/
59 /*** file scope functions ************************************************************************/
60 /* --------------------------------------------------------------------------------------------- */
62 /* --------------------------------------------------------------------------------------------- */
63 /*** public functions ****************************************************************************/
64 /* --------------------------------------------------------------------------------------------- */
66 void
67 show_mouse_pointer (int x, int y)
69 #ifdef HAVE_LIBGPM
70 if (use_mouse_p == MOUSE_GPM)
71 Gpm_DrawPointer (x, y, gpm_consolefd);
72 #else
73 (void) x;
74 (void) y;
75 #endif /* HAVE_LIBGPM */
78 /* --------------------------------------------------------------------------------------------- */
80 void
81 init_mouse (void)
83 switch (use_mouse_p)
85 #ifdef HAVE_LIBGPM
86 case MOUSE_NONE:
87 use_mouse_p = MOUSE_GPM;
88 break;
89 #endif /* HAVE_LIBGPM */
91 case MOUSE_XTERM_NORMAL_TRACKING:
92 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
93 define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
94 define_sequence (MCKEY_EXTENDED_MOUSE, xmouse_extended_seq, MCKEY_NOACTION);
95 break;
97 default:
98 break;
101 enable_mouse ();
104 /* --------------------------------------------------------------------------------------------- */
106 void
107 enable_mouse (void)
109 if (mouse_enabled)
110 return;
112 switch (use_mouse_p)
114 #ifdef HAVE_LIBGPM
115 case MOUSE_GPM:
117 Gpm_Connect conn;
119 conn.eventMask = ~GPM_MOVE;
120 conn.defaultMask = GPM_MOVE;
121 conn.minMod = 0;
122 conn.maxMod = 0;
124 mouse_fd = Gpm_Open (&conn, 0);
125 if (mouse_fd == -1)
127 use_mouse_p = MOUSE_NONE;
128 return;
130 mouse_enabled = TRUE;
132 break;
133 #endif /* HAVE_LIBGPM */
135 case MOUSE_XTERM_NORMAL_TRACKING:
136 /* save old highlight mouse tracking */
137 printf (ESC_STR "[?1001s");
139 /* enable mouse tracking */
140 printf (ESC_STR "[?1000h");
142 /* enable SGR extended mouse reporting */
143 printf (ESC_STR "[?1006h");
145 fflush (stdout);
146 mouse_enabled = TRUE;
147 break;
149 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
150 /* save old highlight mouse tracking */
151 printf (ESC_STR "[?1001s");
153 /* enable mouse tracking */
154 printf (ESC_STR "[?1002h");
156 /* enable SGR extended mouse reporting */
157 printf (ESC_STR "[?1006h");
159 fflush (stdout);
160 mouse_enabled = TRUE;
161 break;
163 default:
164 break;
168 /* --------------------------------------------------------------------------------------------- */
170 void
171 disable_mouse (void)
173 if (!mouse_enabled)
174 return;
176 mouse_enabled = FALSE;
178 switch (use_mouse_p)
180 #ifdef HAVE_LIBGPM
181 case MOUSE_GPM:
182 Gpm_Close ();
183 break;
184 #endif
185 case MOUSE_XTERM_NORMAL_TRACKING:
186 /* disable SGR extended mouse reporting */
187 printf (ESC_STR "[?1006l");
189 /* disable mouse tracking */
190 printf (ESC_STR "[?1000l");
192 /* restore old highlight mouse tracking */
193 printf (ESC_STR "[?1001r");
195 fflush (stdout);
196 break;
197 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
198 /* disable SGR extended mouse reporting */
199 printf (ESC_STR "[?1006l");
201 /* disable mouse tracking */
202 printf (ESC_STR "[?1002l");
204 /* restore old highlight mouse tracking */
205 printf (ESC_STR "[?1001r");
207 fflush (stdout);
208 break;
209 default:
210 break;
214 /* --------------------------------------------------------------------------------------------- */