Home | History | Annotate | Line # | Download | only in libcurses
      1 /*	$NetBSD: mouse.c,v 1.2 2024/12/23 02:58:04 blymn 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.2 2024/12/23 02:58:04 blymn 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 (__predict_false(win == NULL))
     50 		return ERR;
     51 
     52 	if (y < win->begy || y > win->begy + win->maxy ||
     53 	    x < win->begx || x > win->begx + win->maxx)
     54 		return false;
     55 	return true;
     56 }
     57 
     58 bool
     59 mouse_trafo(int *y, int *x, bool to_screen)
     60 {
     61 
     62 	return wmouse_trafo(stdscr, y, x, to_screen);
     63 }
     64 
     65 /*
     66  * Transform y and x from screen relative to window relative
     67  */
     68 bool wmouse_trafo(const WINDOW *win, int *y, int *x, bool to_screen)
     69 {
     70 	int wy = *y, wx = *x;
     71 
     72 	if (__predict_false(win == NULL))
     73 		return ERR;
     74 
     75 	if (to_screen) {
     76 		wy += win->begy;
     77 		wx += win->begx;
     78 	}
     79 
     80 	if (!wenclose(win, wy, wx))
     81 		return false;
     82 
     83 	if (!to_screen) {
     84 		wy -= win->begy;
     85 		wx -= win->begx;
     86 	}
     87 
     88 	*y = wy;
     89 	*x = wx;
     90 	return true;
     91 }
     92 
     93 /*
     94  * The below functions actually need some kind of mouse support.
     95  * We should look into wsmouse(4) support at least as well as xterm.
     96  */
     97 
     98 bool
     99 has_mouse(void)
    100 {
    101 
    102 	return false;
    103 }
    104 
    105 int
    106 getmouse(__unused MEVENT *event)
    107 {
    108 
    109 	return ERR;
    110 }
    111 
    112 int
    113 ungetmouse(__unused MEVENT *event)
    114 {
    115 
    116 	return ERR;
    117 }
    118 
    119 mmask_t
    120 mousemask(__unused mmask_t newmask, __unused mmask_t *oldmask)
    121 {
    122 
    123 	return 0;
    124 }
    125 
    126 int
    127 mouseinterval(__unused int erval)
    128 {
    129 
    130 	return DEFAULT_MAXCLICK;
    131 }
    132