1 /* $NetBSD: ms.c,v 1.1 2010/01/11 02:18:45 pooka Exp $ */ 2 3 /* 4 * Copyright (c) 2010 Antti Kantee. All Rights Reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 /* 29 * Experimental proof-of-concept program: 30 * 31 * Read mouse events and draw silly cursor on screen. 32 */ 33 34 #include <sys/types.h> 35 #include <sys/time.h> 36 37 #include <dev/wscons/wsconsio.h> 38 39 #include <rump/rump.h> 40 #include <rump/rump_syscalls.h> 41 42 #include <curses.h> 43 #include <err.h> 44 #include <paths.h> 45 #include <string.h> 46 #include <stdio.h> 47 #include <stdlib.h> 48 49 int 50 main(int argc, char *argv[]) 51 { 52 struct wscons_event *wev; 53 char buf[128]; 54 int fd, x = 0, y = 0; 55 56 rump_boot_sethowto(RUMP_AB_VERBOSE); 57 rump_init(); 58 59 fd = rump_sys_open("/dev/wsmouse", 0); 60 if (fd == -1) 61 err(1, "open"); 62 63 initscr(); 64 65 while (rump_sys_read(fd, buf, sizeof(buf)) > 0) { 66 /* XXX: timespec in 5.0 vs. -current */ 67 wev = (void *)buf; 68 69 switch (wev->type) { 70 case WSCONS_EVENT_MOUSE_DELTA_X: 71 if (wev->value > 1) 72 x++; 73 else if (wev->value < 1) 74 x--; 75 if (x < 0) 76 x = 0; 77 break; 78 case WSCONS_EVENT_MOUSE_DELTA_Y: 79 if (wev->value > 1) 80 y--; 81 else if (wev->value < 1) 82 y++; 83 if (y < 0) 84 y = 0; 85 break; 86 case WSCONS_EVENT_MOUSE_DOWN: 87 mvprintw(0, 0, "button %d pressed", wev->value); 88 break; 89 case WSCONS_EVENT_MOUSE_UP: 90 clear(); 91 break; 92 default: 93 break; 94 } 95 move(y, x); 96 refresh(); 97 } 98 } 99