diff --git a/Core.cs b/Core.cs index 1714588a6..c8fcca811 100644 --- a/Core.cs +++ b/Core.cs @@ -946,6 +946,10 @@ namespace Terminal { return; } + static void ProcessMouseEvent (MouseEvent me) + { + } + static public RunState Begin (Toplevel toplevel) { if (toplevel == null) @@ -955,7 +959,7 @@ namespace Terminal { Init (); toplevels.Push (toplevel); Current = toplevel; - Driver.PrepareToRun (MainLoop, ProcessKeyEvent); + Driver.PrepareToRun (MainLoop, ProcessKeyEvent, ProcessMouseEvent); toplevel.LayoutSubviews (); toplevel.FocusFirst (); Redraw (toplevel); diff --git a/Driver.cs b/Driver.cs index c336e3c08..0244562d7 100644 --- a/Driver.cs +++ b/Driver.cs @@ -78,7 +78,7 @@ namespace Terminal { public abstract void Move (int col, int row); public abstract void AddCh (int ch); public abstract void AddStr (string str); - public abstract void PrepareToRun (MainLoop mainLoop, Action target); + public abstract void PrepareToRun (MainLoop mainLoop, Action target, Action mouse); public abstract void Refresh (); public abstract void End (); public abstract void RedrawTop (); @@ -226,7 +226,16 @@ namespace Terminal { } } - void ProcessInput (Action keyHandler) + static MouseEvent ToDriverMouse (Curses.MouseEvent cev) + { + return new MouseEvent () { + X = cev.X, + Y = cev.Y, + Flags = (MouseFlags)cev.ButtonState + }; + } + + void ProcessInput (Action keyHandler, Action mouseHandler) { int wch; var code = Curses.get_wch (out wch); @@ -238,15 +247,14 @@ namespace Terminal { } } if (code == Curses.KeyMouse) { - // TODO - // Curses.MouseEvent ev; - // Curses.getmouse (out ev); - // handler.HandleMouse (); + Curses.MouseEvent ev; + Curses.getmouse (out ev); + mouseHandler (ToDriverMouse (ev)); return; } keyHandler (new KeyEvent (MapCursesKey (wch))); return; - } + } // Special handling for ESC, we want to try to catch ESC+letter to simulate alt-letter as well as Alt-Fkey if (wch == 27) { @@ -274,12 +282,12 @@ namespace Terminal { keyHandler (new KeyEvent ((Key)wch)); } - public override void PrepareToRun (MainLoop mainLoop, Action keyHandler) + public override void PrepareToRun (MainLoop mainLoop, Action keyHandler, Action mouseHandler) { Curses.timeout (-1); mainLoop.AddWatch (0, Mono.Terminal.MainLoop.Condition.PollIn, x => { - ProcessInput (keyHandler); + ProcessInput (keyHandler, mouseHandler); return true; }); diff --git a/Event.cs b/Event.cs index 90046a810..50c55b724 100644 --- a/Event.cs +++ b/Event.cs @@ -4,6 +4,8 @@ // Authors: // Miguel de Icaza (miguel@gnome.org) // +using System; + namespace Terminal { /// @@ -81,10 +83,23 @@ namespace Terminal { Unknown } + /// + /// Describes a keyboard event + /// public struct KeyEvent { public Key Key; public int KeyValue => (int)Key; + + /// + /// Gets a value indicating whether the Alt key was pressed (real or synthesized) + /// + /// true if is alternate; otherwise, false. public bool IsAlt => (Key & Key.AltMask) != 0; + + /// + /// Determines whether the value is a control key + /// + /// true if is ctrl; otherwise, false. public bool IsCtrl => ((uint)Key >= 1) && ((uint)Key <= 26); public KeyEvent (Key k) @@ -93,6 +108,61 @@ namespace Terminal { } } + /// + /// Mouse flags reported in MouseEvent. + /// + /// + /// They just happen to map to the ncurses ones. + /// + [Flags] + public enum MouseFlags { + Button1Pressed = unchecked((int)0x2), + Button1Released = unchecked((int)0x1), + Button1Clicked = unchecked((int)0x4), + Button1DoubleClicked = unchecked((int)0x8), + Button1TripleClicked = unchecked((int)0x10), + Button2Pressed = unchecked((int)0x80), + Button2Released = unchecked((int)0x40), + Button2Clicked = unchecked((int)0x100), + Button2DoubleClicked = unchecked((int)0x200), + Button2TrippleClicked = unchecked((int)0x400), + Button3Pressed = unchecked((int)0x2000), + Button3Released = unchecked((int)0x1000), + Button3Clicked = unchecked((int)0x4000), + Button3DoubleClicked = unchecked((int)0x8000), + Button3TripleClicked = unchecked((int)0x10000), + Button4Pressed = unchecked((int)0x80000), + Button4Released = unchecked((int)0x40000), + Button4Clicked = unchecked((int)0x100000), + Button4DoubleClicked = unchecked((int)0x200000), + Button4TripleClicked = unchecked((int)0x400000), + ButtonShift = unchecked((int)0x2000000), + ButtonCtrl = unchecked((int)0x1000000), + ButtonAlt = unchecked((int)0x4000000), + ReportMousePosition = unchecked((int)0x8000000), + AllEvents = unchecked((int)0x7ffffff), + } + + /// + /// Describes a mouse event + /// + public struct MouseEvent { + /// + /// The X (column) location for the mouse event. + /// + public int X; + + /// + /// The Y (column) location for the mouse event. + /// + public int Y; + + /// + /// Flags indicating the kind of mouse event that is being posted. + /// + public MouseFlags Flags; + } + public class Event { public class Key : Event { public int Code { get; private set; }