Optimization of mcview_hexedit_save_changes() function.
[kaloumi3.git] / lib / tty / mouse.c
blob1469211e79d187b5e111629b423444e273b64699
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 "lib/global.h"
36 #include "tty.h"
37 #include "tty-internal.h" /* mouse_enabled */
38 #include "mouse.h"
39 #include "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 #else
51 (void) x;
52 (void) y;
53 #endif /* HAVE_LIBGPM */
56 void
57 init_mouse (void)
59 switch (use_mouse_p) {
60 #ifdef HAVE_LIBGPM
61 case MOUSE_NONE:
62 use_mouse_p = MOUSE_GPM;
63 break;
64 #endif /* HAVE_LIBGPM */
66 case MOUSE_XTERM_NORMAL_TRACKING:
67 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
68 define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
69 break;
71 default:
72 break;
75 enable_mouse ();
78 void
79 enable_mouse (void)
81 if (mouse_enabled)
82 return;
84 switch (use_mouse_p) {
85 #ifdef HAVE_LIBGPM
86 case MOUSE_GPM:
88 int mouse_d;
89 Gpm_Connect conn;
91 conn.eventMask = ~GPM_MOVE;
92 conn.defaultMask = GPM_MOVE;
93 conn.minMod = 0;
94 conn.maxMod = 0;
96 mouse_d = Gpm_Open (&conn, 0);
97 if (mouse_d == -1) {
98 use_mouse_p = MOUSE_NONE;
99 return;
101 mouse_enabled = 1;
103 break;
104 #endif /* HAVE_LIBGPM */
106 case MOUSE_XTERM_NORMAL_TRACKING:
107 /* save old highlight mouse tracking */
108 printf (ESC_STR "[?1001s");
110 /* enable mouse tracking */
111 printf (ESC_STR "[?1000h");
113 fflush (stdout);
114 mouse_enabled = TRUE;
115 break;
117 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
118 /* save old highlight mouse tracking */
119 printf (ESC_STR "[?1001s");
121 /* enable mouse tracking */
122 printf (ESC_STR "[?1002h");
124 fflush (stdout);
125 mouse_enabled = TRUE;
126 break;
128 default:
129 break;
133 void
134 disable_mouse (void)
136 if (!mouse_enabled)
137 return;
139 mouse_enabled = FALSE;
141 switch (use_mouse_p) {
142 #ifdef HAVE_LIBGPM
143 case MOUSE_GPM:
144 Gpm_Close ();
145 break;
146 #endif
147 case MOUSE_XTERM_NORMAL_TRACKING:
148 /* disable mouse tracking */
149 printf (ESC_STR "[?1000l");
151 /* restore old highlight mouse tracking */
152 printf (ESC_STR "[?1001r");
154 fflush (stdout);
155 break;
156 case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
157 /* disable mouse tracking */
158 printf (ESC_STR "[?1002l");
160 /* restore old highlight mouse tracking */
161 printf (ESC_STR "[?1001r");
163 fflush (stdout);
164 break;
165 default:
166 break;