From f7cecd976b196288bd734eace2acff798a36513f Mon Sep 17 00:00:00 2001 From: Marco Gerards Date: Thu, 6 Jan 2005 21:53:26 +0000 Subject: 2005-01-06 Marco Gerards * Makefile (SRCS): Add `vcons-move-mouse.c' and `vcons-event.c'. * cons.h (mouse_movement): New enum. (mouse_button): Likewise. (mouse_event): New struct. (mouse_event_t): New type. (cons_vcons_set_mousecursor_pos): New prototype. (cons_vcons_set_mousecursor_status): Likewise. (cons_vcons_move_mouse): Likewise. * file-changed.c (cons_S_file_changed): Generate the `CONS_EVT_OUTPUT' event, in case there was output. * opts-std-startup.c (OPT_MOUSE_SHOW, OPT_MOUSE_HIDE) (OPT_MOUSE_SENS, DEFAULT_MOUSE_SENS, DEFAULT_MOUSE_SENS_STRING): New macros. (_cons_show_mouse, _cons_hide_mouse, _cons_mouse_sens): New variables. (startup_options): Add the options `--mouse-show-on', `--mouse-hide-on' and `--mouse-sensitivity'. (parse_startup_opt): Parse the options that were added to `startup_options' using the new local function `parse_events'. * priv.h (CONS_EVT_MOUSE_MOVE, CONS_EVT_MOUSE_BUTTON) (CONS_EVT_KEYPRESS, CONS_EVT_OUTPUT): New macros. (_cons_show_mouse, _cons_hide_mouse, _cons_mouse_sens): New declarations. (_cons_vcons_input): New prototype. (_cons_vcons_console_event): Likewise. * vcons-event.c: New file. * vcons-move-mouse.c: Likewise. * vcons-input.c (_cons_vcons_input): New function. (cons_vcons_input): Rewritten to use _cons_vcons_input and report the `CONS_EVT_KEYPRESS' event. * vcons-refresh.c: Include "priv.h". (cons_vcons_refresh): Report the `CONS_EVT_OUTPUT' event. * vcons-scrollback.c: Include "priv.h". (cons_vcons_scrollback): Report the `CONS_EVT_OUTPUT' event. --- libcons/vcons-move-mouse.c | 103 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 libcons/vcons-move-mouse.c (limited to 'libcons/vcons-move-mouse.c') diff --git a/libcons/vcons-move-mouse.c b/libcons/vcons-move-mouse.c new file mode 100644 index 00000000..1e5f7b9f --- /dev/null +++ b/libcons/vcons-move-mouse.c @@ -0,0 +1,103 @@ +/* vcons-move-mouse.c - Catch mouse events. + Copyright (C) 2004, 2005 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 +#include + +#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) +{ + char event[CONS_MOUSE_EVENT_LENGTH]; + uint32_t report_events; + + mutex_lock (&vcons->lock); + report_events = vcons->display->flags & CONS_FLAGS_TRACK_MOUSE; + + switch (ev->mouse_movement) + { + case CONS_VCONS_MOUSE_MOVE_REL: + mousepos_x += ((float) ev->x / _cons_mouse_sens); + mousepos_y += ((float) ev->y / _cons_mouse_sens); + break; + + case CONS_VCONS_MOUSE_MOVE_ABS_PERCENT: + mousepos_x = vcons->state.screen.width * ev->x / 100; + mousepos_y = vcons->state.screen.height * ev->y / 100; + + case CONS_VCONS_MOUSE_MOVE_ABS: + mousepos_x = ev->x; + mousepos_y = ev->y; + 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, CONS_EVT_MOUSE_MOVE); + + /* Report a mouse button event. */ + if (ev->mouse_button != CONS_VCONS_MOUSE_BUTTON_NO_OP) + _cons_vcons_console_event (vcons, CONS_EVT_MOUSE_BUTTON); + + if (report_events) + { + switch (ev->mouse_button) + { + case CONS_VCONS_MOUSE_BUTTON_NO_OP: + break; + + case CONS_VCONS_MOUSE_BUTTON_PRESSED: + /* Make an 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 CONS_VCONS_MOUSE_BUTTON_RELEASED: + /* Make an 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; +} -- cgit v1.2.3