annotate src/gpmevent.c @ 155:43dd3413c7c7 r20-3b4

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