comparison src/gpmevent.c @ 153:25f70ba0133c r20-3b3

Import from CVS: tag r20-3b3
author cvs
date Mon, 13 Aug 2007 09:38:25 +0200
parents
children 43dd3413c7c7
comparison
equal deleted inserted replaced
152:4c132ee2d62b 153:25f70ba0133c
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 */
95 if (EQ (CONSOLE_TYPE (con), Qtty)) {
96 Gpm_Connect conn;
97
98 conn.eventMask = GPM_DOWN|GPM_UP|GPM_MOVE;
99 conn.defaultMask = GPM_MOVE;
100 conn.minMod = 0;
101 conn.maxMod = ((1<<KG_SHIFT)|(1<<KG_ALT)|(1<<KG_CTRL));
102
103 if (Gpm_Open (&conn, 0) == -1) {
104 CONSOLE_TTY_MOUSE_FD (con) = -1;
105 return(0);
106 }
107 set_descriptor_non_blocking (gpm_fd);
108 CONSOLE_TTY_MOUSE_FD (con) = gpm_fd;
109 }
110 }
111 }
112
113 #endif