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