small typo
[midnight-commander.git] / src / mouse.c
blob4d2a3042c8a9f66d12db647182822112808de197
1 /* Mouse managing
2 Copyright (C) 1994 Miguel de Icaza.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* Events received by clients of this library have their coordinates 0 */
19 /* based */
21 /* "$Id$" */
23 #include <config.h>
24 #include <sys/types.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28 #include <fcntl.h>
29 #include <stdio.h>
31 #include "global.h"
32 #include "tty.h"
33 #include "mouse.h"
34 #include "key.h" /* define sequence */
36 int mouse_enabled = 0;
37 char *xmouse_seq;
39 #ifdef HAVE_LIBGPM
40 void show_mouse_pointer (int x, int y)
42 if (use_mouse_p == MOUSE_GPM) {
43 Gpm_DrawPointer (x, y, gpm_consolefd);
46 #endif /* HAVE_LIBGPM */
48 void init_mouse (void)
50 switch (use_mouse_p) {
51 #ifdef HAVE_LIBGPM
52 case MOUSE_NONE:
53 use_mouse_p = MOUSE_GPM;
54 break;
55 #endif /* HAVE_LIBGPM */
56 case MOUSE_XTERM:
57 define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
58 break;
59 default:
60 break;
62 enable_mouse ();
65 void enable_mouse (void)
67 if (mouse_enabled) {
68 return;
71 switch (use_mouse_p) {
72 #ifdef HAVE_LIBGPM
73 case MOUSE_GPM:
75 int mouse_d;
76 Gpm_Connect conn;
78 conn.eventMask = ~GPM_MOVE;
79 conn.defaultMask = GPM_MOVE;
80 conn.minMod = 0;
81 conn.maxMod = 0;
83 mouse_d = Gpm_Open (&conn, 0);
84 if (mouse_d == -1) {
85 use_mouse_p = MOUSE_NONE;
86 return;
88 mouse_enabled = 1;
90 break;
91 #endif /* HAVE_LIBGPM */
92 case MOUSE_XTERM:
93 /* save old highlight mouse tracking */
94 printf(ESC_STR "[?1001s");
96 /* enable mouse tracking */
97 printf(ESC_STR "[?1000h");
99 fflush (stdout);
100 mouse_enabled = 1;
101 break;
102 default:
103 break;
107 void disable_mouse (void)
109 if (!mouse_enabled) {
110 return;
113 mouse_enabled = 0;
115 switch (use_mouse_p) {
116 #ifdef HAVE_LIBGPM
117 case MOUSE_GPM:
118 Gpm_Close ();
119 break;
120 #endif
121 case MOUSE_XTERM:
122 /* disable mouse tracking */
123 printf(ESC_STR "[?1000l");
125 /* restore old highlight mouse tracking */
126 printf(ESC_STR "[?1001r");
128 fflush (stdout);
129 break;
130 default:
131 break;