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