*** empty log message ***
[midnight-commander.git] / src / mouse.c
blob6aa39c331fa8e7c019ef1ec76ff54bc091bb158a
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;
60 enable_mouse ();
63 void enable_mouse (void)
65 if (mouse_enabled) {
66 return;
69 switch (use_mouse_p) {
70 #ifdef HAVE_LIBGPM
71 case MOUSE_GPM:
73 int mouse_d;
74 Gpm_Connect conn;
76 conn.eventMask = ~GPM_MOVE;
77 conn.defaultMask = GPM_MOVE;
78 conn.minMod = 0;
79 conn.maxMod = 0;
81 mouse_d = Gpm_Open (&conn, 0);
82 if (mouse_d == -1) {
83 use_mouse_p = MOUSE_NONE;
84 return;
86 mouse_enabled = 1;
88 break;
89 #endif /* HAVE_LIBGPM */
90 case MOUSE_XTERM:
91 /* save old highlight mouse tracking */
92 printf(ESC_STR "[?1001s");
94 /* enable mouse tracking */
95 printf(ESC_STR "[?1000h");
97 fflush (stdout);
98 mouse_enabled = 1;
99 break;
103 void disable_mouse (void)
105 if (!mouse_enabled) {
106 return;
109 mouse_enabled = 0;
111 switch (use_mouse_p) {
112 #ifdef HAVE_LIBGPM
113 case MOUSE_GPM:
114 Gpm_Close ();
115 break;
116 #endif
117 case MOUSE_XTERM:
118 /* disable mouse tracking */
119 printf(ESC_STR "[?1000l");
121 /* restore old highlight mouse tracking */
122 printf(ESC_STR "[?1001r");
124 fflush (stdout);
125 break;