Skip to content

Commit

Permalink
Fixes #1535. Added IsMouseDisabled prop to Application (#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
BDisp authored Dec 18, 2021
1 parent 239191c commit f013627
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Terminal.Gui/Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public static bool AlwaysSetPosition {
/// <value>The main loop.</value>
public static MainLoop MainLoop { get; private set; }

/// <summary>
/// Disable or enable the mouse in this <see cref="Application"/>
/// </summary>
public static bool IsMouseDisabled { get; set; }

/// <summary>
/// This event is raised on each iteration of the <see cref="MainLoop"/>
/// </summary>
Expand Down Expand Up @@ -523,6 +528,10 @@ public static void UngrabMouse ()

static void ProcessMouseEvent (MouseEvent me)
{
if (IsMouseDisabled) {
return;
}

var view = FindDeepestView (Current, me.X, me.Y, out int rx, out int ry);

if (view != null && view.WantContinuousButtonPressed)
Expand Down
17 changes: 17 additions & 0 deletions UICatalog/UICatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,26 @@ static List<MenuItem []> CreateDiagnosticMenuItems ()
menuItems.Add (new MenuItem [] { null });
menuItems.Add (CreateSizeStyle ());
menuItems.Add (CreateAlwaysSetPosition ());
menuItems.Add (CreateDisabledEnabledMouse ());
return menuItems;
}

private static MenuItem [] CreateDisabledEnabledMouse ()
{
List<MenuItem> menuItems = new List<MenuItem> ();
var item = new MenuItem ();
item.Title = "_Disable/Enable Mouse";
item.Shortcut = Key.CtrlMask | Key.AltMask | (Key)item.Title.ToString ().Substring (1, 1) [0];
item.CheckType |= MenuItemCheckStyle.Checked;
item.Checked = Application.IsMouseDisabled;
item.Action += () => {
item.Checked = Application.IsMouseDisabled = !item.Checked;
};
menuItems.Add (item);

return menuItems.ToArray ();
}

static MenuItem [] CreateAlwaysSetPosition ()
{
List<MenuItem> menuItems = new List<MenuItem> ();
Expand Down

0 comments on commit f013627

Please sign in to comment.