annotate src/gpmevent.c @ 440:8de8e3f6228a r21-2-28

Import from CVS: tag r21-2-28
author cvs
date Mon, 13 Aug 2007 11:33:38 +0200
parents 84b14dcb0985
children abe6d1db359e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1 /* GPM (General purpose mouse) functions
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1997 William M. Perry <wmperry@gnu.org>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1999 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* Authors: William Perry */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "console.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "console-tty.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #include "device.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "events.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "events-mod.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #include "sysdep.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include "commands.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #include "lstream.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #include "sysproc.h" /* for MAXDESC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #include "process.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #ifdef HAVE_GPM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 #include "gpmevent.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #include <gpm.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 #if (!defined(__linux__)) /* possible under xterm */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #define KG_SHIFT 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #define KG_CTRL 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #define KG_ALT 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #include <linux/keyboard.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 extern int gpm_tried;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 extern void *gpm_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 static int (*orig_event_pending_p) (int);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
55 static void (*orig_next_event_cb) (Lisp_Event *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 static Lisp_Object gpm_event_queue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 static Lisp_Object gpm_event_queue_tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 struct __gpm_state {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 int gpm_tried;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 int gpm_flag;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 void *gpm_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 static struct __gpm_state gpm_state_information[MAXDESC];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 store_gpm_state (int fd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 gpm_state_information[fd].gpm_tried = gpm_tried;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 gpm_state_information[fd].gpm_flag = gpm_flag;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 gpm_state_information[fd].gpm_stack = gpm_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 restore_gpm_state (int fd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 gpm_tried = gpm_state_information[fd].gpm_tried;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 gpm_flag = gpm_state_information[fd].gpm_flag;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 gpm_stack = gpm_state_information[fd].gpm_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 gpm_consolefd = gpm_fd = fd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 clear_gpm_state (int fd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 if (fd >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 memset(&gpm_state_information[fd], '\0', sizeof(struct __gpm_state));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 gpm_tried = gpm_flag = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 gpm_fd = gpm_consolefd = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 gpm_stack = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 static int
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
98 get_process_infd (Lisp_Process *p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 Lisp_Object instr, outstr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 get_process_streams (p, &instr, &outstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 assert (!NILP (instr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 return filedesc_stream_fd (XLSTREAM (instr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 DEFUN ("receive-gpm-event", Freceive_gpm_event, 0, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 Run GPM_GetEvent().
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 This function is the process handler for the GPM connection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 (process, string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 Gpm_Event ev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 int modifiers = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 int button = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 Lisp_Object fake_event;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
116 Lisp_Event *event = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 static int num_events;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 CHECK_PROCESS (process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 restore_gpm_state (get_process_infd (XPROCESS (process)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 if (!Gpm_GetEvent(&ev))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 warn_when_safe (Qnil, Qcritical, "Gpm_GetEvent failed - %d", gpm_fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 return(Qzero);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 GCPRO1(fake_event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 num_events++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 fake_event = Fmake_event (Qnil, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 event = XEVENT(fake_event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 event->timestamp = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 event->channel = Fselected_frame (Qnil); /* CONSOLE_SELECTED_FRAME (con); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 /* Whow, wouldn't named defines be NICE!?!?! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 modifiers = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 if (ev.modifiers & 1) modifiers |= MOD_SHIFT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 if (ev.modifiers & 2) modifiers |= MOD_META;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 if (ev.modifiers & 4) modifiers |= MOD_CONTROL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 if (ev.modifiers & 8) modifiers |= MOD_META;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 if (ev.buttons & GPM_B_LEFT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 button = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 else if (ev.buttons & GPM_B_MIDDLE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 button = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 else if (ev.buttons & GPM_B_RIGHT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 button = 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 switch (GPM_BARE_EVENTS(ev.type)) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 case GPM_DOWN:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 case GPM_UP:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 event->event_type =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (ev.type & GPM_DOWN) ? button_press_event : button_release_event;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 event->event.button.x = ev.x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 event->event.button.y = ev.y;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 event->event.button.button = button;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 event->event.button.modifiers = modifiers;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 case GPM_MOVE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 case GPM_DRAG:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 event->event_type = pointer_motion_event;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 event->event.motion.x = ev.x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 event->event.motion.y = ev.y;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 event->event.motion.modifiers = modifiers;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 /* This will never happen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 /* Handle the event */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 enqueue_event (fake_event, &gpm_event_queue, &gpm_event_queue_tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 return (Qzero);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 static void turn_off_gpm (char *process_name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 Lisp_Object process = Fget_process (build_string (process_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 int fd = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 if (NILP (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 /* Something happened to our GPM process - fail silently */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 fd = get_process_infd (XPROCESS (process));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 restore_gpm_state (fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 Gpm_Close();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 clear_gpm_state (fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 Fdelete_process (build_string (process_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 #ifdef TIOCLINUX
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 tty_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 struct device *d = decode_device (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 int fd = DEVICE_INFD (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 char c = 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 Lisp_Object output_stream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 Lisp_Object terminal_stream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 Lisp_Object output_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 struct gcpro gcpro1,gcpro2,gcpro3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 GCPRO3(output_stream,terminal_stream,output_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 /* The ioctl() to paste actually puts things in the input queue of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 ** the virtual console, so we need to trap that data, since we are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 ** supposed to return the actual string selection from this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 ** function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 /* I really hate doing this, but it doesn't seem to cause any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 ** problems, and it makes the Lstream_read stuff further down
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 ** error out correctly instead of trying to indefinitely read from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 ** the console.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 ** There is no set_descriptor_blocking() function call, but in my
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 ** testing under linux, it has not proved fatal to leave the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 ** descriptor in non-blocking mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 ** William Perry Nov 5, 1999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 set_descriptor_non_blocking (fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 /* We need two streams, one for reading from the selected device,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 ** and one to write the data into. There is no writable version
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 ** of the lisp-string lstream, so we make do with a resizing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 ** buffer stream, and make a string out of it after we are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 ** done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 output_stream = make_resizing_buffer_output_stream ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 terminal_stream = make_filedesc_input_stream (fd, 0, -1, LSTR_BLOCKED_OK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 output_string = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 /* #### We should arguably use a specbind() and an unwind routine here,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 ** #### but I don't care that much right now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 if (NILP (output_stream) || NILP (terminal_stream))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 /* Should we signal an error here? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 goto out;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 if (ioctl (fd, TIOCLINUX, &c) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 /* Could not get the selection - eek */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 return (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 Bufbyte tempbuf[1024]; /* some random amount */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 ssize_t i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 ssize_t size_in_bytes =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 Lstream_read (XLSTREAM (terminal_stream),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 tempbuf, sizeof (tempbuf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 if (size_in_bytes <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 /* end of the stream */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 /* convert CR->LF */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 for (i = 0; i < size_in_bytes; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 if (tempbuf[i] == '\r')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 tempbuf[i] = '\n';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 Lstream_write (XLSTREAM (output_stream), tempbuf, size_in_bytes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 Lstream_flush (XLSTREAM (output_stream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 output_string = make_string (resizing_buffer_stream_ptr (XLSTREAM (output_stream)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 Lstream_byte_count (XLSTREAM (output_stream)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 Lstream_delete (XLSTREAM (output_stream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 Lstream_delete (XLSTREAM (terminal_stream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 out:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 return (output_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 tty_selection_exists_p (Lisp_Object selection)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 return (Qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 #endif /* TIOCLINUX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 tty_own_selection (Lisp_Object selection_name, Lisp_Object selection_value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 /* There is no way to do this cleanly - the GPM selection
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 ** 'protocol' (actually the TIOCLINUX ioctl) requires a start and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 ** end position on the _screen_, not a string to stick in there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 ** Lame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 ** William Perry Nov 4, 1999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 /* This function appears to work once in a blue moon. I'm not sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 ** exactly why either. *sigh*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 ** William Perry Nov 4, 1999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 ** Apparently, this is the way (mouse-position) is supposed to work,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 ** and I was just expecting something else. (mouse-pixel-position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 ** works just fine.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 ** William Perry Nov 7, 1999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 tty_get_mouse_position (struct device *d, Lisp_Object *frame, int *x, int *y)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 Gpm_Event ev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 int num_buttons;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 memset(&ev,'\0',sizeof(ev));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 num_buttons = Gpm_GetSnapshot(&ev);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 if (!num_buttons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 /* This means there are events pending... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 /* #### In theory, we should drain the events pending, stick
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 ** #### them in the queue, and return the mouse position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 ** #### anyway.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 return(-1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 *x = ev.x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 *y = ev.y;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 *frame = DEVICE_SELECTED_FRAME (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 tty_set_mouse_position (struct window *w, int x, int y)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
372 /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 #### I couldn't find any GPM functions that set the mouse position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 #### Mr. Perry had left this function empty; that must be why.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 #### karlheg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 static int gpm_event_pending_p (int user_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 Lisp_Object event;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 EVENT_CHAIN_LOOP (event, gpm_event_queue)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 if (!user_p || command_event_p (event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 return (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 return (orig_event_pending_p (user_p));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
393 static void gpm_next_event_cb (Lisp_Event *event)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 /* #### It would be nice to preserve some sort of ordering of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 ** #### different types of events, but that would be quite a bit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 ** #### of work, and would more than likely break the abstraction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 ** #### between the other event loops and this one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
400
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 if (!NILP (gpm_event_queue))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 Lisp_Object queued_event = dequeue_event (&gpm_event_queue, &gpm_event_queue_tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 *event = *(XEVENT (queued_event));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 if (event->event_type == pointer_motion_event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 struct device *d = decode_device (event->channel);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 int fd = DEVICE_INFD (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 /* Ok, now this is just freaky. Bear with me though.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 ** If you run gnuclient and attach to a XEmacs running in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 ** X or on another TTY, the mouse cursor does not get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 ** drawn correctly. This is because the ioctl() fails
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 ** with EPERM because the TTY specified is not our
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 ** controlling terminal. If you are the superuser, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 ** will work just spiffy. The appropriate source file (at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 ** least in linux 2.2.x) is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 ** .../linux/drivers/char/console.c in the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 ** tioclinux(). The following bit of code is brutal to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 ** us:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 ** if (current->tty != tty && !suser())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 ** return -EPERM;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 ** I even tried setting us as a process leader, removing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 ** our controlling terminal, and then using the TIOCSCTTY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 ** to set up a new controlling terminal, all with no luck.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 ** What is even weirder is if you run XEmacs in a VC, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 ** attach to it from another VC with gnuclient, go back to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 ** the original VC and hit a key, the mouse pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 ** displays (in BOTH VCs), until you hit a key in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 ** second VC, after which it does not display in EITHER
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 ** VC. Bizarre, no?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 ** All I can say is thank god Linux comes with source code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 ** or I would have been completely confused. Well, ok,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 ** I'm still completely confused. I don't see why they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 ** don't just check the permissions on the device
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 ** (actually, if you have enough access to it to get the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 ** console's file descriptor, you should be able to do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 ** with it as you wish, but maybe that is just me).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 ** William M. Perry - Nov 9, 1999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 Gpm_DrawPointer (event->event.motion.x,event->event.motion.y, fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 428
diff changeset
455 orig_next_event_cb (event);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 static void hook_event_callbacks_once (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 static int hooker;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 if (!hooker)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 orig_event_pending_p = event_stream->event_pending_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 orig_next_event_cb = event_stream->next_event_cb;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 event_stream->event_pending_p = gpm_event_pending_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 event_stream->next_event_cb = gpm_next_event_cb;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 hooker = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 static void hook_console_methods_once (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 static int hooker;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 if (!hooker)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 /* Install the mouse position methods for the TTY console type */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 CONSOLE_HAS_METHOD (tty, get_mouse_position);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 CONSOLE_HAS_METHOD (tty, set_mouse_position);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 CONSOLE_HAS_METHOD (tty, get_foreign_selection);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 CONSOLE_HAS_METHOD (tty, selection_exists_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 CONSOLE_HAS_METHOD (tty, own_selection);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 DEFUN ("gpm-enabled-p", Fgpm_enabled_p, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 Return non-nil if GPM mouse support is currently enabled on DEVICE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 (device))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 char *console_name = ttyname (DEVICE_INFD (decode_device (device)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 char process_name[1024];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 Lisp_Object proc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 if (!console_name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 return (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 memset (process_name, '\0', sizeof(process_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 snprintf (process_name, sizeof(process_name) - 1, "gpm for %s", console_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 proc = Fget_process (build_string (process_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 if (NILP (proc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 return (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 if (1) /* (PROCESS_LIVE_P (proc)) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 return (Qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 return (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 DEFUN ("gpm-enable", Fgpm_enable, 0, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 Toggle accepting of GPM mouse events.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 (device, arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 Gpm_Connect conn;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 int rval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 Lisp_Object gpm_process;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 Lisp_Object gpm_filter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 struct device *d = decode_device (device);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 int fd = DEVICE_INFD (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 char *console_name = ttyname (fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 char process_name[1024];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 hook_event_callbacks_once ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 hook_console_methods_once ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 if (noninteractive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 error ("Can't connect to GPM in batch mode.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 if (!console_name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 /* Something seriously wrong here... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 return (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 memset (process_name, '\0', sizeof(process_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 snprintf (process_name, sizeof(process_name) - 1, "gpm for %s", console_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 if (NILP (arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 turn_off_gpm (process_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 return (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 /* DANGER DANGER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 ** Though shalt not call (gpm-enable t) after we have already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 ** started, or stuff blows up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 if (!NILP (Fgpm_enabled_p (device)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 error ("GPM already enabled for this console.");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 conn.eventMask = GPM_DOWN|GPM_UP|GPM_MOVE|GPM_DRAG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 conn.defaultMask = GPM_MOVE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 conn.minMod = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 conn.maxMod = ((1<<KG_SHIFT)|(1<<KG_ALT)|(1<<KG_CTRL));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 /* Reset some silly static variables so that multiple Gpm_Open()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 ** calls have even a sligh chance of working
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 gpm_tried = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 gpm_flag = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 gpm_stack = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 /* Make sure Gpm_Open() does ioctl() on the correct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 ** descriptor, or it can get the wrong terminal sizes, etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 gpm_consolefd = fd;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
582
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 /* We have to pass the virtual console manually, otherwise if you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 ** use 'gnuclient -nw' to connect to an XEmacs that is running in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 ** X, Gpm_Open() tries to use ttyname(0 | 1 | 2) to find out which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 ** console you are using, which is of course not correct for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 ** new tty device.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 if (strncmp (console_name, "/dev/tty",8) || !isdigit (console_name[8]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 /* Urk, something really wrong */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 return (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 rval = Gpm_Open (&conn, atoi(console_name + 8));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 switch (rval) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 case -1: /* General failure */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 case -2: /* We are running under an XTerm */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 Gpm_Close();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 /* Is this really necessary? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 set_descriptor_non_blocking (gpm_fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 store_gpm_state (gpm_fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 gpm_process = connect_to_file_descriptor (build_string (process_name), Qnil,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 make_int (gpm_fd),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 make_int (gpm_fd));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 if (!NILP (gpm_process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 rval = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 Fprocess_kill_without_query (gpm_process, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 XSETSUBR (gpm_filter, &SFreceive_gpm_event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 set_process_filter (gpm_process, gpm_filter, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 /* Keep track of the device for later */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 /* Fput (gpm_process, intern ("gpm-device"), device); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 Gpm_Close();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 rval = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 return(rval ? Qnil : Qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 void vars_of_gpmevent (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 gpm_event_queue = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 gpm_event_queue_tail = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 staticpro (&gpm_event_queue);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 staticpro (&gpm_event_queue_tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 pdump_wire (&gpm_event_queue);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 pdump_wire (&gpm_event_queue_tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 void syms_of_gpmevent (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 DEFSUBR (Freceive_gpm_event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 DEFSUBR (Fgpm_enable);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 DEFSUBR (Fgpm_enabled_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 #endif /* HAVE_GPM */