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