1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
|
Common subdirectories: ../libcons.cvs/CVS and ./CVS
diff -upN ../libcons.cvs/Makefile ./Makefile
--- libcons.cvs/Makefile 2002-09-13 23:40:10.000000000 +0000
+++ libcons/Makefile 2004-04-02 07:44:48.000000000 +0000
@@ -23,7 +23,7 @@ SRCS= demuxer.c init-init.c init-loop.c
dir-changed.c file-changed.c opts-std-startup.c cons-lookup.c \
cons-switch.c vcons-remove.c vcons-add.c vcons-open.c \
vcons-close.c vcons-destroy.c vcons-refresh.c vcons-scrollback.c \
- vcons-input.c
+ vcons-input.c vcons-move-mouse.c vcons-event.c
LCLHDRS = priv.h mutations.h
installhdrs = cons.h
diff -upN ../libcons.cvs/cons.h ./cons.h
--- libcons.cvs/cons.h 2003-08-16 18:06:23.000000000 +0000
+++ libcons/cons.h 2004-04-02 07:42:20.000000000 +0000
@@ -123,6 +123,31 @@ struct cons
int slack;
};
+
+enum mouse_movement
+ {
+ MOUSE_MOVE_REL,
+ MOUSE_MOVE_ABS,
+ MOUSE_MOVE_PROC
+ };
+
+enum mouse_button
+ {
+ MOUSE_BUTTON_NO_OP,
+ MOUSE_BUTTON_PRESSED,
+ MOUSE_BUTTON_RELEASED
+ };
+
+typedef struct mouse_event
+{
+ enum mouse_movement mouse_movement;
+ float x;
+ float y;
+
+ enum mouse_button mouse_button;
+ int button;
+} *mouse_event_t;
+
/* The user must define this variable. Set this to the name of the
console client. */
@@ -256,6 +281,14 @@ typedef enum
down. */
int cons_vcons_scrollback (vcons_t vcons, cons_scroll_t type, float value);
+/* Set the mouse cursor position to X, Y. VCONS is locked. */
+error_t cons_vcons_set_mousecursor_pos (vcons_t vcons, float x, float y);
+
+/* If STATUS is set to 0, hide the mouse cursor, otherwise show
+ it. VCONS is locked. */
+error_t cons_vcons_set_mousecursor_status (vcons_t vcons, int status);
+
+
extern const struct argp cons_startup_argp;
@@ -286,4 +319,6 @@ void cons_vcons_destroy (void *port);
/* Redraw the virtual console VCONS, which is locked. */
void cons_vcons_refresh (vcons_t vcons);
+error_t cons_vcons_move_mouse (vcons_t vcons, mouse_event_t ev);
+
#endif /* hurd/cons.h */
diff -upN ../libcons.cvs/file-changed.c ./file-changed.c
--- libcons.cvs/file-changed.c 2003-08-02 21:43:46.000000000 +0000
+++ libcons/file-changed.c 2004-04-02 07:02:31.000000000 +0000
@@ -1,5 +1,5 @@
/* file-changed.c - Handling file changed notifications.
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
Written by Marcus Brinkmann.
This file is part of the GNU Hurd.
@@ -93,6 +93,7 @@ cons_S_file_changed (cons_notify_t notif
/* The cursor was visible before. */
cons_vcons_set_cursor_status (vcons, CONS_CURSOR_INVISIBLE);
+ _cons_vcons_console_event (vcons, CONSEVT_OUTPUT);
cons_vcons_update (vcons);
}
if (change.what.cursor_status)
@@ -185,6 +186,7 @@ cons_S_file_changed (cons_notify_t notif
end - size + 1,
0, (size - vis_start)
/ vcons->state.screen.width);
+ _cons_vcons_console_event (vcons, CONSEVT_OUTPUT);
cons_vcons_update (vcons);
}
vcons->state.screen.cur_line = new_cur_line;
@@ -342,6 +344,7 @@ cons_S_file_changed (cons_notify_t notif
(size - rotate)
/ vcons->state.screen.width);
}
+ _cons_vcons_console_event (vcons, CONSEVT_OUTPUT);
cons_vcons_update (vcons);
}
}
diff -upN ../libcons.cvs/opts-std-startup.c ./opts-std-startup.c
--- libcons.cvs/opts-std-startup.c 2003-08-02 21:43:46.000000000 +0000
+++ libcons/opts-std-startup.c 2004-04-02 00:35:20.000000000 +0000
@@ -1,5 +1,5 @@
/* opts-std-startup.c - Standard startup-time command line parser.
- Copyright (C) 1995,96,97,98,99,2001,02,2003 Free Software Foundation, Inc.
+ Copyright (C) 1995,96,97,98,99,2001,02,2003,2004 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.org> and Marcus Brinkmann.
This file is part of the GNU Hurd.
@@ -25,7 +25,7 @@
#include "priv.h"
-/* Option keys for long-only options in diskfs_common_options. */
+/* Option keys for long-only options in argp_option. */
#define OPT_SLACK 600 /* --slack */
#define OPT_JUMP_DOWN_ON_INPUT 601 /* --jump-down-on-input */
#define OPT_NO_JUMP_DOWN_ON_INPUT 602 /* --no-jump-down-on-input */
@@ -33,13 +33,20 @@
#define OPT_NO_JUMP_DOWN_ON_OUTPUT 604 /* --no-jump-down-on-output */
#define OPT_VISUAL_BELL 605 /* --visual-bell */
#define OPT_AUDIBLE_BELL 606 /* --audible-bell */
+#define OPT_MOUSE_SHOW 607 /* --mouse-show */
+#define OPT_MOUSE_HIDE 608 /* --mouse-hide */
+#define OPT_MOUSE_SENS 609 /* --mouse-sensitivity */
-/* Common value for diskfs_common_options and diskfs_default_sync_interval. */
+/* The number of records the client is allowed to lag behind the server. */
#define DEFAULT_SLACK 100
#define DEFAULT_SLACK_STRING STRINGIFY(DEFAULT_SLACK)
#define STRINGIFY(x) STRINGIFY_1(x)
#define STRINGIFY_1(x) #x
+/* The mouse sensitivity. */
+#define DEFAULT_MOUSE_SENS 3.0
+#define DEFAULT_MOUSE_SENS_STRING STRINGIFY(DEFAULT_SLACK)
+
/* Number of records the client is allowed to lag behind the
server. */
int _cons_slack = DEFAULT_SLACK;
@@ -59,6 +66,15 @@ bell_type_t _cons_visual_bell = BELL_VIS
/* The type of bell used for the audible bell. */
bell_type_t _cons_audible_bell = BELL_AUDIBLE;
+/* The type of events that will make the mouse cursor visible. */
+int _cons_show_mouse = CONSEVT_MOUSEMOVE;
+
+/* The type of events that will hide the mouse cursor. */
+int _cons_hide_mouse = CONSEVT_KEYPRESS;
+
+/* The mouse sensitivity. */
+float _cons_mouse_sens = DEFAULT_MOUSE_SENS;
+
static const struct argp_option
startup_options[] =
{
@@ -76,6 +92,15 @@ startup_options[] =
"off, visual, audible" },
{ "audible-bell", OPT_AUDIBLE_BELL, "BELL", 0, "Audible bell: on (default), "
"off, visual, audible" },
+ { "mouse-show", OPT_MOUSE_SHOW, "EVENTS", 0, "One or more of the events"
+ " MOUSEMOVE, MOUSEBUTTON, KEYPRESS, OUTPUT (default is MOUSEMOVE), if one"
+ " of these events occur the mouse cursor will be made visible" },
+ { "mouse-hide", OPT_MOUSE_HIDE, "EVENTS", 0, "One or more of the events"
+ " MOUSEMOVE, MOUSEBUTTON, KEYPRESS, OUTPUT (default is KEYPRESS), if one"
+ " of these events occur the mouse cursor will be hidden " },
+ { "mouse-sensitivity", OPT_MOUSE_SENS, "SENSITIVITY", 0, "The mouse"
+ " sensitivity (default " DEFAULT_MOUSE_SENS_STRING "). A lower value"
+ " means more sensitive" },
{ 0, 0 }
};
@@ -86,6 +111,30 @@ static const char doc[] = "A console cli
static error_t
parse_startup_opt (int opt, char *arg, struct argp_state *state)
{
+ int parse_events (char *events)
+ {
+ char *evtstr = strdupa (events);
+ char *tok = strtok (evtstr, ",");
+ int evmask = 0;
+
+ while (tok)
+ {
+ if (!strcasecmp ("mousemove", tok))
+ evmask |= CONSEVT_MOUSEMOVE;
+ else if (!strcasecmp ("mousebutton", tok))
+ evmask |= CONSEVT_MOUSEBUTTON;
+ else if (!strcasecmp ("keypress", tok))
+ evmask |= CONSEVT_KEYPRESS;
+ else if (!strcasecmp ("output", tok))
+ evmask |= CONSEVT_OUTPUT;
+ else
+ argp_error (state, "The event can be one of: MOUSEMOVE,"
+ " MOUSEBUTTON, KEYPRESS or OUTPUT");
+ tok = strtok (NULL, ",");
+ }
+ return evmask;
+ }
+
switch (opt)
{
case OPT_SLACK:
@@ -131,7 +180,28 @@ parse_startup_opt (int opt, char *arg, s
argp_error (state, "The visual bell can be one of: on, off, visual, "
"audible");
break;
-
+
+ case OPT_MOUSE_SHOW:
+ _cons_show_mouse = parse_events (arg);
+ break;
+
+ case OPT_MOUSE_HIDE:
+ _cons_hide_mouse = parse_events (arg);
+ break;
+
+ case OPT_MOUSE_SENS:
+ {
+ char *tail;
+
+ errno = 0;
+ _cons_mouse_sens = strtod (arg, &tail);
+ if (tail == NULL || tail == arg || *tail != '\0')
+ argp_error (state, "SENSITIVITY is not a number: %s", arg);
+ if (errno)
+ argp_error (state, "Overflow in argument SENSITIVITY %s", arg);
+ break;
+ }
+
case ARGP_KEY_ARG:
if (state->arg_num > 0)
/* Too many arguments. */
diff -upN ../libcons.cvs/priv.h ./priv.h
--- libcons.cvs/priv.h 2003-08-02 21:43:46.000000000 +0000
+++ libcons/priv.h 2004-04-02 00:52:07.000000000 +0000
@@ -29,6 +29,11 @@ typedef enum
BELL_AUDIBLE
} bell_type_t;
+#define CONSEVT_MOUSEMOVE (1 << 1)
+#define CONSEVT_MOUSEBUTTON (1 << 2)
+#define CONSEVT_KEYPRESS (1 << 4)
+#define CONSEVT_OUTPUT (1 << 8)
+
/* Number of records the client is allowed to lag behind the
server. */
@@ -49,11 +54,26 @@ extern bell_type_t _cons_visual_bell;
/* The type of bell used for the audible bell. */
extern bell_type_t _cons_audible_bell;
+/* The type of events that will make the mouse cursor visible. */
+extern int _cons_show_mouse;
+
+/* The type of events that will hide the mouse cursor. */
+extern int _cons_hide_mouse;
+
+/* The mouse sensitivity. */
+extern float _cons_mouse_sens;
+
/* Non-locking version of cons_vcons_scrollback. Does also not update
the display. */
int _cons_vcons_scrollback (vcons_t vcons, cons_scroll_t type, float value);
+/* Non-locking version of cons_vcons_input. */
+error_t _cons_vcons_input (vcons_t vcons, char *buf, size_t size);
+
+/* Generate the console event EVENT for console VCONS. */
+void _cons_vcons_console_event (vcons_t vcons, int event);
+
/* Called by MiG to translate ports into cons_notify_t. mutations.h
arranges for this to happen for the fs_notify interfaces. */
diff -upN ../libcons.cvs/vcons-event.c ./vcons-event.c
--- libcons.cvs/vcons-event.c 1970-01-01 00:00:00.000000000 +0000
+++ libcons/vcons-event.c 2004-04-02 07:39:07.000000000 +0000
@@ -0,0 +1,31 @@
+/* vcons-event.c - Handle console events.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ Written by Marco Gerards.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include "cons.h"
+#include "priv.h"
+
+void
+_cons_vcons_console_event (vcons_t vcons, int event)
+{
+ if (_cons_show_mouse & event)
+ cons_vcons_set_mousecursor_status (vcons, 1);
+ else if (_cons_hide_mouse & event)
+ cons_vcons_set_mousecursor_status (vcons, 0);
+}
diff -upN ../libcons.cvs/vcons-input.c ./vcons-input.c
--- libcons.cvs/vcons-input.c 2002-09-13 23:53:55.000000000 +0000
+++ libcons/vcons-input.c 2004-04-02 07:02:54.000000000 +0000
@@ -1,5 +1,5 @@
/* vcons-input.c - Add input to a virtual console.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
Written by Marcus Brinkmann.
This file is part of the GNU Hurd.
@@ -24,18 +24,12 @@
#include "cons.h"
#include "priv.h"
-/* Enter SIZE bytes from the buffer BUF into the virtual console
- VCONS. */
+/* Non-locking version of cons_vcons_input. */
error_t
-cons_vcons_input (vcons_t vcons, char *buf, size_t size)
+_cons_vcons_input (vcons_t vcons, char *buf, size_t size)
{
int ret;
- mutex_lock (&vcons->lock);
-
- if (vcons->scrolling && _cons_jump_down_on_input)
- _cons_vcons_scrollback (vcons, CONS_SCROLL_ABSOLUTE_LINE, 0);
-
do
{
ret = write (vcons->input, buf, size);
@@ -47,8 +41,24 @@ cons_vcons_input (vcons_t vcons, char *b
}
while (size && (ret != -1 || errno == EINTR));
- mutex_unlock (&vcons->lock);
return 0;
}
+/* Enter SIZE bytes from the buffer BUF into the virtual console
+ VCONS. */
+error_t
+cons_vcons_input (vcons_t vcons, char *buf, size_t size)
+{
+ mutex_lock (&vcons->lock);
+
+ _cons_vcons_console_event (vcons, CONSEVT_KEYPRESS);
+
+ if (vcons->scrolling && _cons_jump_down_on_input)
+ _cons_vcons_scrollback (vcons, CONS_SCROLL_ABSOLUTE_LINE, 0);
+
+ _cons_vcons_input (vcons, buf, size);
+
+ mutex_unlock (&vcons->lock);
+ return 0;
+}
diff -upN ../libcons.cvs/vcons-move-mouse.c ./vcons-move-mouse.c
--- libcons.cvs/vcons-move-mouse.c 1970-01-01 00:00:00.000000000 +0000
+++ libcons/vcons-move-mouse.c 2004-07-27 07:07:34.000000000 +0000
@@ -0,0 +1,98 @@
+/* vcons-move-mouse.c - Catch mouse events.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ Written by Marco Gerards.
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include "cons.h"
+#include "priv.h"
+
+static float mousepos_x;
+static float mousepos_y;
+
+error_t
+cons_vcons_move_mouse (vcons_t vcons, mouse_event_t ev)
+{
+ int ret;
+ char event[CONS_MOUSE_EVENT_LENGTH];
+ uint32_t report_events = vcons->display->flags & CONS_FLAGS_TRACK_MOUSE;
+
+ mutex_lock (&vcons->lock);
+
+ switch (ev->mouse_movement)
+ {
+ case MOUSE_MOVE_REL:
+ mousepos_x += ((float) ev->x / _cons_mouse_sens);
+ mousepos_y += ((float) ev->y / _cons_mouse_sens);
+ break;
+
+ case MOUSE_MOVE_PROC:
+ case MOUSE_MOVE_ABS:
+ break;
+ }
+
+ /* Keep the mouse cursor in range of the VC. */
+ if (mousepos_x < 0)
+ mousepos_x = 0;
+ if (mousepos_y < 0)
+ mousepos_y = 0;
+ if (mousepos_x >= (float) vcons->state.screen.width)
+ mousepos_x = vcons->state.screen.width - 1;
+ if (mousepos_y >= (float) vcons->state.screen.height)
+ mousepos_y = vcons->state.screen.height - 1;
+
+ cons_vcons_set_mousecursor_pos (vcons, (float) mousepos_x, (float) mousepos_y);
+
+ /* Report a mouse movement event. */
+ if (ev->x || ev->y)
+ _cons_vcons_console_event (vcons, CONSEVT_MOUSEMOVE);
+
+ /* Report a mouse button event. */
+ if (ev->mouse_button != MOUSE_BUTTON_NO_OP)
+ _cons_vcons_console_event (vcons, CONSEVT_MOUSEBUTTON);
+
+ if (report_events)
+ {
+ switch (ev->mouse_button)
+ {
+ case MOUSE_BUTTON_NO_OP:
+ break;
+
+ case MOUSE_BUTTON_PRESSED:
+ /* Make a xterm like event string. */
+ CONS_MOUSE_EVENT (event, ev->button, (int) mousepos_x + 1, (int) mousepos_y + 1);
+
+ _cons_vcons_input (vcons, event, CONS_MOUSE_EVENT_LENGTH);
+ /* And send it to the server. */
+ break;
+
+ case MOUSE_BUTTON_RELEASED:
+ /* Make a xterm like event string. */
+ CONS_MOUSE_EVENT (event, CONS_MOUSE_RELEASE, (int) mousepos_x + 1, (int) mousepos_y + 1);
+
+ /* And send it to the server. */
+ _cons_vcons_input (vcons, event, CONS_MOUSE_EVENT_LENGTH);
+ break;
+ }
+ }
+
+ mutex_unlock (&vcons->lock);
+ return 0;
+}
diff -upN ../libcons.cvs/vcons-refresh.c ./vcons-refresh.c
--- libcons.cvs/vcons-refresh.c 2003-08-15 21:04:10.000000000 +0000
+++ libcons/vcons-refresh.c 2004-04-02 07:03:08.000000000 +0000
@@ -1,5 +1,5 @@
/* vcons-refresh.c - Redraw a virtual console.
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
Written by Marcus Brinkmann.
This file is part of the GNU Hurd.
@@ -22,6 +22,7 @@
#include <assert.h>
#include "cons.h"
+#include "priv.h"
/* Redraw the virtual console VCONS, which is locked. */
void
@@ -70,5 +71,6 @@ cons_vcons_refresh (vcons_t vcons)
cons_vcons_set_cursor_status (vcons, vcons->state.cursor.status);
cons_vcons_set_scroll_lock (vcons, vcons->state.flags
& CONS_FLAGS_SCROLL_LOCK);
+ _cons_vcons_console_event (vcons, CONSEVT_OUTPUT);
cons_vcons_update (vcons);
}
diff -upN ../libcons.cvs/vcons-scrollback.c ./vcons-scrollback.c
--- libcons.cvs/vcons-scrollback.c 2002-09-17 11:47:15.000000000 +0000
+++ libcons/vcons-scrollback.c 2004-04-02 07:03:15.000000000 +0000
@@ -1,5 +1,5 @@
/* vcons-scrollback.c - Move forward and backward in the scrollback buffer.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
Written by Marcus Brinkmann.
This file is part of the GNU Hurd.
@@ -23,6 +23,7 @@
#include <cthreads.h>
#include "cons.h"
+#include "priv.h"
/* Non-locking version of cons_vcons_scrollback. Does also not update
the display. */
@@ -155,6 +156,7 @@ cons_vcons_scrollback (vcons_t vcons, co
mutex_lock (&vcons->lock);
ret = _cons_vcons_scrollback (vcons, type, value);
+ _cons_vcons_console_event (vcons, CONSEVT_OUTPUT);
cons_vcons_update (vcons);
mutex_unlock (&vcons->lock);
return ret;
|