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