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