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