Removed type SHELL_ESCAPED_STR in favour of plain char*
[midnight-commander.git] / src / mouse.c
blob276caa06a36f099f090aac5a002cc32c854cec17
1 /* Mouse managing
2 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006,
3 2007 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /* Events received by clients of this library have their coordinates 0 */
20 /* based */
22 #include <config.h>
24 #include <stdio.h>
26 #include <sys/types.h>
27 #include <unistd.h>
29 #include "global.h"
30 #include "tty.h"
31 #include "mouse.h"
32 #include "key.h" /* define sequence */
34 int mouse_enabled = 0;
35 const char *xmouse_seq;
37 #ifdef HAVE_LIBGPM
38 void show_mouse_pointer (int x, int y)
40 if (use_mouse_p == MOUSE_GPM) {
41 Gpm_DrawPointer (x, y, gpm_consolefd);
44 #endif /* HAVE_LIBGPM */
46 void init_mouse (void)
48 switch (use_mouse_p) {
49 #ifdef HAVE_LIBGPM
50 case MOUSE_NONE:
51 use_mouse_p = MOUSE_GPM;
52 break;
53 #endif /* HAVE_LIBGPM */
54 case MOUSE_XTERM_NORMAL_TRACKING:
55 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
56 define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
57 break;
58 default:
59 break;
61 enable_mouse ();
64 void enable_mouse (void)
66 if (mouse_enabled) {
67 return;
70 switch (use_mouse_p) {
71 #ifdef HAVE_LIBGPM
72 case MOUSE_GPM:
74 int mouse_d;
75 Gpm_Connect conn;
77 conn.eventMask = ~GPM_MOVE;
78 conn.defaultMask = GPM_MOVE;
79 conn.minMod = 0;
80 conn.maxMod = 0;
82 mouse_d = Gpm_Open (&conn, 0);
83 if (mouse_d == -1) {
84 use_mouse_p = MOUSE_NONE;
85 return;
87 mouse_enabled = 1;
89 break;
90 #endif /* HAVE_LIBGPM */
91 case MOUSE_XTERM_NORMAL_TRACKING:
92 /* save old highlight mouse tracking */
93 printf(ESC_STR "[?1001s");
95 /* enable mouse tracking */
96 printf(ESC_STR "[?1000h");
98 fflush (stdout);
99 mouse_enabled = 1;
100 break;
101 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
102 /* save old highlight mouse tracking */
103 printf(ESC_STR "[?1001s");
105 /* enable mouse tracking */
106 printf(ESC_STR "[?1002h");
108 fflush (stdout);
109 mouse_enabled = 1;
110 break;
111 default:
112 break;
116 void disable_mouse (void)
118 if (!mouse_enabled) {
119 return;
122 mouse_enabled = 0;
124 switch (use_mouse_p) {
125 #ifdef HAVE_LIBGPM
126 case MOUSE_GPM:
127 Gpm_Close ();
128 break;
129 #endif
130 case MOUSE_XTERM_NORMAL_TRACKING:
131 /* disable mouse tracking */
132 printf(ESC_STR "[?1000l");
134 /* restore old highlight mouse tracking */
135 printf(ESC_STR "[?1001r");
137 fflush (stdout);
138 break;
139 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
140 /* disable mouse tracking */
141 printf(ESC_STR "[?1002l");
143 /* restore old highlight mouse tracking */
144 printf(ESC_STR "[?1001r");
146 fflush (stdout);
147 break;
148 default:
149 break;