153
|
1 /* William Perry 1997 */
|
|
2
|
|
3 #include <config.h>
|
|
4 #include "lisp.h"
|
|
5 #include "console-tty.h"
|
|
6 #include "device.h"
|
|
7 #include "events.h"
|
|
8 #include "events-mod.h"
|
|
9 #include "process.h"
|
|
10 #include "sysdep.h"
|
|
11 #include "sysproc.h" /* select stuff */
|
|
12 #include "systime.h"
|
|
13
|
|
14 #ifdef HAVE_GPM
|
|
15 #include "gpmevent.h"
|
|
16 #include <gpm.h>
|
|
17
|
|
18 #if (!defined(__linux__)) /* possible under xterm */
|
|
19 #define KG_SHIFT 0
|
|
20 #define KG_CTRL 2
|
|
21 #define KG_ALT 3
|
|
22 #else
|
|
23 #include <linux/keyboard.h>
|
|
24 #endif
|
|
25
|
|
26 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
|
|
27 extern SELECT_TYPE process_only_mask, device_only_mask;
|
|
28 void select_filedesc (int fd, Lisp_Object what);
|
|
29
|
|
30 int handle_gpm_read(struct Lisp_Event *event, struct console *con, int fd)
|
|
31 {
|
|
32 Gpm_Event ev;
|
|
33 int modifiers,type,button;
|
|
34
|
|
35 type = -1;
|
|
36 button = 1;
|
|
37
|
|
38 if (!Gpm_GetEvent(&ev))
|
|
39 return(0);
|
|
40
|
|
41 event->timestamp = 0;
|
|
42 event->channel = CONSOLE_SELECTED_FRAME (con);
|
|
43
|
|
44 /* Whow, wouldn't named defines be NICE!?!?! */
|
|
45 modifiers = 0;
|
|
46
|
|
47 if (ev.modifiers & 1) modifiers |= MOD_SHIFT;
|
|
48 if (ev.modifiers & 2) modifiers |= MOD_META;
|
|
49 if (ev.modifiers & 4) modifiers |= MOD_CONTROL;
|
|
50 if (ev.modifiers & 8) modifiers |= MOD_META;
|
|
51
|
|
52 if (ev.type & GPM_DOWN)
|
|
53 type = GPM_DOWN;
|
|
54 else if (ev.type & GPM_UP)
|
|
55 type = GPM_UP;
|
|
56 else if (ev.type & GPM_MOVE) {
|
|
57 type = GPM_MOVE;
|
|
58 GPM_DRAWPOINTER(&ev);
|
|
59 }
|
|
60
|
|
61 if (ev.buttons & GPM_B_LEFT)
|
|
62 button = 1;
|
|
63 else if (ev.buttons & GPM_B_MIDDLE)
|
|
64 button = 2;
|
|
65 else if (ev.buttons & GPM_B_RIGHT)
|
|
66 button = 3;
|
|
67
|
|
68 switch (type) {
|
|
69 case GPM_DOWN:
|
|
70 case GPM_UP:
|
|
71 if (type == GPM_DOWN)
|
|
72 event->event_type = button_press_event;
|
|
73 else event->event_type = button_release_event;
|
|
74 event->event.button.x = ev.x;
|
|
75 event->event.button.y = ev.y;
|
|
76 event->event.button.button = button;
|
|
77 event->event.button.modifiers = modifiers;
|
|
78 break;
|
|
79 case GPM_MOVE:
|
|
80 event->event_type = pointer_motion_event;
|
|
81 event->event.motion.x = ev.x;
|
|
82 event->event.motion.y = ev.y;
|
|
83 event->event.motion.modifiers = modifiers;
|
|
84 default:
|
|
85 return (0);
|
|
86 }
|
|
87 return (1);
|
|
88 }
|
|
89
|
|
90 int connect_to_gpm(struct console *con)
|
|
91 {
|
|
92 /* Only do this if we are running after dumping and really interactive */
|
|
93 if (!noninteractive && initialized) {
|
|
94 /* We really only want to do this on a TTY */
|
155
|
95 CONSOLE_TTY_MOUSE_FD (con) = -1;
|
153
|
96 if (EQ (CONSOLE_TYPE (con), Qtty)) {
|
|
97 Gpm_Connect conn;
|
155
|
98 int rval;
|
153
|
99
|
|
100 conn.eventMask = GPM_DOWN|GPM_UP|GPM_MOVE;
|
|
101 conn.defaultMask = GPM_MOVE;
|
|
102 conn.minMod = 0;
|
|
103 conn.maxMod = ((1<<KG_SHIFT)|(1<<KG_ALT)|(1<<KG_CTRL));
|
|
104
|
155
|
105 rval = Gpm_Open (&conn, 0);
|
|
106 switch (rval) {
|
|
107 case -1: /* General failure */
|
|
108 break;
|
|
109 case -2: /* We are running under an XTerm */
|
|
110 Gpm_Close();
|
|
111 break;
|
|
112 default:
|
|
113 set_descriptor_non_blocking (gpm_fd);
|
|
114 CONSOLE_TTY_MOUSE_FD (con) = gpm_fd;
|
153
|
115 }
|
|
116 }
|
|
117 }
|
|
118 }
|
|
119
|
|
120 #endif
|