Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Improve driver detection logging #3085

Merged
merged 1 commit into from Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 23 additions & 5 deletions OpenTabletDriver.Daemon/DriverDaemon.cs
Expand Up @@ -5,6 +5,9 @@
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using OpenTabletDriver.Desktop;
using OpenTabletDriver.Desktop.Binding;
Expand Down Expand Up @@ -55,11 +58,26 @@ public DriverDaemon(Driver driver)

foreach (var driverInfo in DriverInfo.GetDriverInfos())
{
Log.Write("Detect", $"Another tablet driver found: {driverInfo.Name}", LogLevel.Warning);
if (driverInfo.IsBlockingDriver)
Log.Write("Detect", $"Detection for {driverInfo.Name} tablets might be impaired", LogLevel.Warning);
else if (driverInfo.IsSendingInput)
Log.Write("Detect", $"Detected input coming from {driverInfo.Name} driver", LogLevel.Error);
var os = SystemInterop.CurrentPlatform switch
{
SystemPlatform.Windows => "Windows",
SystemPlatform.Linux => "Linux",
SystemPlatform.MacOS => "MacOS",
_ => null
};
var wikiUrl = $"https://opentabletdriver.net/Wiki/FAQ/{os}";

var message = new StringBuilder();
message.Append($"'{driverInfo.Name}' driver is detected.");

if (driverInfo.Status.HasFlag(DriverStatus.Blocking))
message.Append(" It will block detection of tablets.");
if (driverInfo.Status.HasFlag(DriverStatus.Flaky))
message.Append(" It will cause flaky support to tablets.");
if (os != null)
message.Append($" If any problems arise, visit '{wikiUrl}'.");

Log.WriteNotify("Detect", message.ToString(), LogLevel.Warning);
}

LoadUserSettings();
Expand Down
9 changes: 2 additions & 7 deletions OpenTabletDriver/SystemDrivers/DriverInfo.cs
Expand Up @@ -27,14 +27,9 @@ public class DriverInfo
public Process[] Processes { get; internal set; }

/// <summary>
/// Provides hints of whether this driver might interfere with OTD's detection mechanism, or prevent OTD from accessing the tablet.
/// Tells how this driver is currently affecting OpenTabletDriver's operations.
/// </summary>
public bool IsBlockingDriver { get; internal set; }

/// <summary>
/// Returns true if this driver sends input to the operating system.
/// </summary>
public bool IsSendingInput { get; internal set; }
public DriverStatus Status { get; internal set; }

/// <summary>
/// Retrieves all the currently active tablet drivers.
Expand Down
23 changes: 23 additions & 0 deletions OpenTabletDriver/SystemDrivers/DriverStatus.cs
@@ -0,0 +1,23 @@
using System;

namespace OpenTabletDriver.SystemDrivers
{
[Flags]
public enum DriverStatus
{
/// <summary>
/// The driver is actively accessing the device and sends input to OS.
/// </summary>
Active = 1,

/// <summary>
/// The driver is potentially blocking OpenTabletDriver from accessing the device.
/// </summary>
Blocking = 1 << 1,

/// <summary>
/// The existence of this driver causes OpenTabletDriver to have flaky support to the device.
/// </summary>
Flaky = 1 << 2,
}
}
Expand Up @@ -10,7 +10,7 @@ public DriverInfo GetDriverInfo()
return new DriverInfo
{
Name = "OpenTabletDriver",
IsSendingInput = true
Status = DriverStatus.Active
};
}

Expand Down
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -39,12 +40,15 @@ protected virtual DriverInfo GetWinDriverInfo()
.Where(p => WinProcessNames.Concat(Heuristics)
.Any(n => Regex.IsMatch(p.ProcessName, n, RegexOptions.IgnoreCase)));

var status = DriverStatus.Blocking;
if (processes.Any())
status |= DriverStatus.Active;

return new DriverInfo
{
Name = FriendlyName,
Processes = processes.Any() ? processes.ToArray() : null,
IsBlockingDriver = true,
IsSendingInput = processes.Any()
Processes = processes.Any() ? processes.ToArray() : Array.Empty<Process>(),
Status = status
};
}

Expand All @@ -58,8 +62,7 @@ protected virtual DriverInfo GetLinuxDriverInfo()
return new DriverInfo
{
Name = LinuxFriendlyName,
IsBlockingDriver = true,
IsSendingInput = true
Status = DriverStatus.Active | DriverStatus.Blocking
};
}
else
Expand Down
Expand Up @@ -23,8 +23,7 @@ public DriverInfo GetDriverInfo()
{
Name = "TabletDriver",
Processes = processes,
IsBlockingDriver = true, // TabletDriver opens tablets in exclusive mode by default
IsSendingInput = true
Status = DriverStatus.Active | DriverStatus.Blocking // TabletDriver opens tablets in exclusive mode by default
};
}
}
Expand Down
Expand Up @@ -21,7 +21,15 @@ protected override DriverInfo GetWinDriverInfo()
{
var info = base.GetWinDriverInfo();
if (info != null)
info.IsBlockingDriver = false;
{
// wacom drivers doesn't block access/detection.
info.Status &= ~DriverStatus.Blocking;

// wacom filter drivers causes feature reports to be blocked
// which causes issues when wacom driver is not running and the
// tablet has to be re-initialized using a feature report.
info.Status |= DriverStatus.Flaky;
}

return info;
}
Expand All @@ -30,7 +38,10 @@ protected override DriverInfo GetLinuxDriverInfo()
{
var info = base.GetLinuxDriverInfo();
if (info != null)
info.IsBlockingDriver = false;
{
// wacom drivers doesn't block access/detection
info.Status &= ~DriverStatus.Blocking;
}

return info;
}
Expand Down
Expand Up @@ -46,7 +46,7 @@ protected override DriverInfo GetWinDriverInfo()
{
Name = FriendlyName,
Processes = processes.ToArray(),
IsSendingInput = true
Status = DriverStatus.Active
};
}
else
Expand Down