annotate src/gpmevent.c @ 398:74fd4e045ea6 r21-2-29

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