annotate src/gpmevent.c @ 365:30d2cfa1092a r21-1-12

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