annotate src/gpmevent.c @ 529:3a1e2338cd81

[xemacs-hg @ 2001-05-10 11:44:25 by martinb] release cycle for "artichoke" begins
author martinb
date Thu, 10 May 2001 11:44:25 +0000
parents 7039e6323819
children 183866b06e0b
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 "sysdep.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #include "commands.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include "lstream.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #include "sysproc.h" /* for MAXDESC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #include "process.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #ifdef HAVE_GPM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #include "gpmevent.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 #include <gpm.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #if (!defined(__linux__)) /* possible under xterm */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 #define KG_SHIFT 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #define KG_CTRL 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #define KG_ALT 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #include <linux/keyboard.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 extern int gpm_tried;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 extern void *gpm_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 static int (*orig_event_pending_p) (int);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
54 static void (*orig_next_event_cb) (Lisp_Event *);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 static Lisp_Object gpm_event_queue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 static Lisp_Object gpm_event_queue_tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 struct __gpm_state {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 int gpm_tried;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 int gpm_flag;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 void *gpm_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 };
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 static struct __gpm_state gpm_state_information[MAXDESC];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 store_gpm_state (int fd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 gpm_state_information[fd].gpm_tried = gpm_tried;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 gpm_state_information[fd].gpm_flag = gpm_flag;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 gpm_state_information[fd].gpm_stack = gpm_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 }
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 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 restore_gpm_state (int fd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 gpm_tried = gpm_state_information[fd].gpm_tried;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 gpm_flag = gpm_state_information[fd].gpm_flag;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 gpm_stack = gpm_state_information[fd].gpm_stack;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 gpm_consolefd = gpm_fd = fd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 }
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 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 clear_gpm_state (int fd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 if (fd >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 memset(&gpm_state_information[fd], '\0', sizeof(struct __gpm_state));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 gpm_tried = gpm_flag = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 gpm_fd = gpm_consolefd = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 gpm_stack = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 }
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 static int
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
97 get_process_infd (Lisp_Process *p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 Lisp_Object instr, outstr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 get_process_streams (p, &instr, &outstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 assert (!NILP (instr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 return filedesc_stream_fd (XLSTREAM (instr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 }
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 DEFUN ("receive-gpm-event", Freceive_gpm_event, 0, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 Run GPM_GetEvent().
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 This function is the process handler for the GPM connection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 (process, string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 Gpm_Event ev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 int modifiers = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 int button = 1;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
114 Lisp_Object fake_event = Qnil;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
115 Lisp_Event *event = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 static int num_events;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 CHECK_PROCESS (process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 restore_gpm_state (get_process_infd (XPROCESS (process)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 if (!Gpm_GetEvent(&ev))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 warn_when_safe (Qnil, Qcritical, "Gpm_GetEvent failed - %d", gpm_fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 return(Qzero);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 }
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 GCPRO1(fake_event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 num_events++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 fake_event = Fmake_event (Qnil, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 event = XEVENT(fake_event);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 event->timestamp = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 event->channel = Fselected_frame (Qnil); /* CONSOLE_SELECTED_FRAME (con); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 /* Whow, wouldn't named defines be NICE!?!?! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 modifiers = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
142 if (ev.modifiers & 1) modifiers |= XEMACS_MOD_SHIFT;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
143 if (ev.modifiers & 2) modifiers |= XEMACS_MOD_META;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
144 if (ev.modifiers & 4) modifiers |= XEMACS_MOD_CONTROL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
145 if (ev.modifiers & 8) modifiers |= XEMACS_MOD_META;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 if (ev.buttons & GPM_B_LEFT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 button = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 else if (ev.buttons & GPM_B_MIDDLE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 button = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 else if (ev.buttons & GPM_B_RIGHT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 button = 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 }
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 switch (GPM_BARE_EVENTS(ev.type)) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 case GPM_DOWN:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 case GPM_UP:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 event->event_type =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (ev.type & GPM_DOWN) ? button_press_event : button_release_event;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 event->event.button.x = ev.x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 event->event.button.y = ev.y;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 event->event.button.button = button;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 event->event.button.modifiers = modifiers;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 case GPM_MOVE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 case GPM_DRAG:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 event->event_type = pointer_motion_event;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 event->event.motion.x = ev.x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 event->event.motion.y = ev.y;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 event->event.motion.modifiers = modifiers;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 /* This will never happen */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 }
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 /* Handle the event */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 enqueue_event (fake_event, &gpm_event_queue, &gpm_event_queue_tail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 return (Qzero);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 }
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 static void turn_off_gpm (char *process_name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 Lisp_Object process = Fget_process (build_string (process_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 int fd = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 if (NILP (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 /* Something happened to our GPM process - fail silently */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 }
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 fd = get_process_infd (XPROCESS (process));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 restore_gpm_state (fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 Gpm_Close();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 clear_gpm_state (fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 Fdelete_process (build_string (process_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 }
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 #ifdef TIOCLINUX
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 tty_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 struct device *d = decode_device (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 int fd = DEVICE_INFD (d);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 char c = 3;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
219 Lisp_Object output_stream = Qnil;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
220 Lisp_Object terminal_stream = Qnil ;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
221 Lisp_Object output_string = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 struct gcpro gcpro1,gcpro2,gcpro3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 GCPRO3(output_stream,terminal_stream,output_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 /* The ioctl() to paste actually puts things in the input queue of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 ** 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
228 ** supposed to return the actual string selection from this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 ** function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 */
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 /* 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
233 ** problems, and it makes the Lstream_read stuff further down
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 ** error out correctly instead of trying to indefinitely read from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 ** the console.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 ** There is no set_descriptor_blocking() function call, but in my
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 ** testing under linux, it has not proved fatal to leave the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 ** descriptor in non-blocking mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 **
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 ** William Perry Nov 5, 1999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 set_descriptor_non_blocking (fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 /* We need two streams, one for reading from the selected device,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 ** and one to write the data into. There is no writable version
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 ** of the lisp-string lstream, so we make do with a resizing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 ** buffer stream, and make a string out of it after we are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 ** done.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 output_stream = make_resizing_buffer_output_stream ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 terminal_stream = make_filedesc_input_stream (fd, 0, -1, LSTR_BLOCKED_OK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 output_string = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 /* #### We should arguably use a specbind() and an unwind routine here,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 ** #### but I don't care that much right now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 if (NILP (output_stream) || NILP (terminal_stream))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 /* Should we signal an error here? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 goto out;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 }
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 if (ioctl (fd, TIOCLINUX, &c) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 /* Could not get the selection - eek */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 return (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 }
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 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 Bufbyte tempbuf[1024]; /* some random amount */
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
274 Lstream_data_count i;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
275 Lstream_data_count size_in_bytes =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 Lstream_read (XLSTREAM (terminal_stream),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 tempbuf, sizeof (tempbuf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 if (size_in_bytes <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 /* end of the stream */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 }
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 /* convert CR->LF */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 for (i = 0; i < size_in_bytes; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 if (tempbuf[i] == '\r')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 tempbuf[i] = '\n';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 }
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 Lstream_write (XLSTREAM (output_stream), tempbuf, size_in_bytes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 }
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 Lstream_flush (XLSTREAM (output_stream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 output_string = make_string (resizing_buffer_stream_ptr (XLSTREAM (output_stream)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 Lstream_byte_count (XLSTREAM (output_stream)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 Lstream_delete (XLSTREAM (output_stream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 Lstream_delete (XLSTREAM (terminal_stream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 out:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 return (output_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 }
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 static Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
311 tty_selection_exists_p (Lisp_Object selection, Lisp_Object selection_type)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 return (Qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 #endif /* TIOCLINUX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 static Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
319 tty_own_selection (Lisp_Object selection_name, Lisp_Object selection_value,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
320 Lisp_Object how_to_add, Lisp_Object selection_type)
428
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()
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
572 ** calls have even a slight chance of working
428
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);
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
637 dump_add_root_object (&gpm_event_queue);
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 446
diff changeset
638 dump_add_root_object (&gpm_event_queue_tail);
428
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 */