1 /* $NetBSD: mouse.c,v 1.1 2020/03/23 13:37:36 roy Exp $ */ 2 3 /*- 4 * Copyright (c) 2020 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Roy Marples. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 #ifndef lint 34 __RCSID("$NetBSD: mouse.c,v 1.1 2020/03/23 13:37:36 roy Exp $"); 35 #endif /* not lint */ 36 37 #include "curses.h" 38 #include "curses_private.h" 39 40 #define DEFAULT_MAXCLICK 166 /* ncurses default */ 41 42 /* 43 * Return true if screen relative y and x are enclosed by the window. 44 */ 45 bool 46 wenclose(const WINDOW *win, int y, int x) 47 { 48 49 if (y < win->begy || y > win->begy + win->maxy || 50 x < win->begx || x > win->begx + win->maxx) 51 return false; 52 return true; 53 } 54 55 bool 56 mouse_trafo(int *y, int *x, bool to_screen) 57 { 58 59 return wmouse_trafo(stdscr, y, x, to_screen); 60 } 61 62 /* 63 * Transform y and x from screen relative to window relative 64 */ 65 bool wmouse_trafo(const WINDOW *win, int *y, int *x, bool to_screen) 66 { 67 int wy = *y, wx = *x; 68 69 if (to_screen) { 70 wy += win->begy; 71 wx += win->begx; 72 } 73 74 if (!wenclose(win, wy, wx)) 75 return false; 76 77 if (!to_screen) { 78 wy -= win->begy; 79 wx -= win->begx; 80 } 81 82 *y = wy; 83 *x = wx; 84 return true; 85 } 86 87 /* 88 * The below functions actually need some kind of mouse support. 89 * We should look into wsmouse(4) support at least as well as xterm. 90 */ 91 92 bool 93 has_mouse(void) 94 { 95 96 return false; 97 } 98 99 int 100 getmouse(__unused MEVENT *event) 101 { 102 103 return ERR; 104 } 105 106 int 107 ungetmouse(__unused MEVENT *event) 108 { 109 110 return ERR; 111 } 112 113 mmask_t 114 mousemask(__unused mmask_t newmask, __unused mmask_t *oldmask) 115 { 116 117 return 0; 118 } 119 120 int 121 mouseinterval(__unused int erval) 122 { 123 124 return DEFAULT_MAXCLICK; 125 } 126