1 /** 2 * Mouse module for dcell contains definitions related to mice (pointing devices not rodents). 3 * 4 * Copyright: Copyright 2022 Garrett D'Amore 5 * Authors: Garrett D'Amore 6 * License: 7 * Distributed under the Boost Software License, Version 1.0. 8 * (See accompanying file LICENSE or https://www.boost.org/LICENSE_1_0.txt) 9 * SPDX-License-Identifier: BSL-1.0 10 */ 11 module dcell.mouse; 12 13 public import dcell.coord; 14 public import dcell.key : Modifiers; 15 16 /** 17 * The buttons that may be clicked, etc. on a mouse. These can be cmobined 18 * together as a binary value to represent chording. Scroll wheels are 19 * included. 20 */ 21 enum Buttons : short 22 { 23 none = 0, /// No button or wheel events. 24 button1 = 1 << 0, /// Usually the left or primary mouse button. 25 button2 = 1 << 1, /// Usually the right or secondary mouse button. 26 button3 = 1 << 2, /// Usually the middle mouse button. 27 button4 = 1 << 3, /// Often a side button (thumb/prev). 28 button5 = 1 << 4, 29 button6 = 1 << 5, 30 button7 = 1 << 6, 31 button8 = 1 << 7, 32 wheelUp = 1 << 8, /// Wheel motion up, away from user. 33 wheelDown = 1 << 9, /// Wheel motion down, towards user. 34 wheelLeft = 1 << 10, /// Wheel motion to left. 35 wheelRight = 1 << 11, /// Wheel motion to right. 36 37 primary = button1, 38 secondary = button2, 39 middle = button3, 40 } 41 42 /** 43 * MouseEnable are the different modes that can be enabled for 44 * mouse tracking. The flagse can be OR'd together (except disable 45 * which should be used alone). 46 */ 47 enum MouseEnable 48 { 49 disable = 0, /// no mouse reporting at all 50 buttons = 1 << 0, /// report on button press events only 51 drag = 1 << 2, /// report click-drag events (moving while button depressed) 52 motion = 1 << 3, /// report all motion events 53 all = buttons | drag | motion, /// report everything 54 } 55 56 /** 57 * MouseEvent represents a single pressed key, possibly with modifiers. 58 * It is sent on either mouse up or mouse down events. It is also sent on 59 * mouse motion events - if the terminal supports it. 60 * 61 * We make every effort to ensure that mouse release events are delivered. 62 * Hence, click drag can be identified by a motion event with the mouse down, 63 * without any intervening button release. On some terminals only the initiating 64 * press and terminating release event will be delivered. 65 * 66 * Mouse wheel events, when reported, may appear on their own as individual 67 * impulses; that is, there will normally not be a release event delivered 68 * for mouse wheel movements. 69 * 70 * Most terminals cannot report the state of more than one button at a time -- 71 * and some cannot report motion events unless a button is pressed. 72 * 73 * Applications can inspect the time between events to resolve double or triple 74 * clicks. 75 */ 76 struct MouseEvent 77 { 78 Buttons btn; /// Buttons involved. 79 Modifiers mod; /// Keyboard modifiers pressed during event. 80 Coord pos; /// Coordinates of mouse. 81 }