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

[Windows] Read Wacom config to check if Windows Ink is disabled and auto switch to WinTab. #102801

Merged
merged 1 commit into from
Feb 13, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1429,9 +1429,14 @@
<member name="input_devices/pen_tablet/driver" type="String" setter="" getter="">
Specifies the tablet driver to use. If left empty, the default driver will be used.
[b]Note:[/b] The driver in use can be overridden at runtime via the [code]--tablet-driver[/code] [url=$DOCS_URL/tutorials/editor/command_line_tutorial.html]command line argument[/url].
[b]Note:[/b] Use [method DisplayServer.tablet_set_current_driver] to switch tablet driver in runtime.
</member>
<member name="input_devices/pen_tablet/driver.windows" type="String" setter="" getter="">
Override for [member input_devices/pen_tablet/driver] on Windows.
Override for [member input_devices/pen_tablet/driver] on Windows. Supported values are:
- [code]auto[/code] (default), uses [code]wintab[/code] if Windows Ink is disabled in the Wacom Tablet Properties or system settings, [code]winink[/code] otherwise.
- [code]winink[/code], uses Windows native "Windows Ink" driver.
- [code]wintab[/code], uses Wacom "WinTab" driver.
- [code]dummy[/code], tablet input is disabled.
</member>
<member name="input_devices/pointing/android/enable_long_press_as_right_click" type="bool" setter="" getter="" default="false">
If [code]true[/code], long press events on an Android touchscreen are transformed into right click events.
Expand Down
4 changes: 2 additions & 2 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3121,7 +3121,7 @@ Error Main::setup2(bool p_show_boot_logo) {
OS::get_singleton()->benchmark_begin_measure("Servers", "Tablet Driver");

GLOBAL_DEF_RST_NOVAL("input_devices/pen_tablet/driver", "");
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "input_devices/pen_tablet/driver.windows", PROPERTY_HINT_ENUM, "winink,wintab,dummy"), "");
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "input_devices/pen_tablet/driver.windows", PROPERTY_HINT_ENUM, "auto,winink,wintab,dummy"), "");

if (tablet_driver.is_empty()) { // specified in project.godot
tablet_driver = GLOBAL_GET("input_devices/pen_tablet/driver");
Expand All @@ -3141,7 +3141,7 @@ Error Main::setup2(bool p_show_boot_logo) {
DisplayServer::get_singleton()->tablet_set_current_driver(DisplayServer::get_singleton()->tablet_get_driver_name(0));
}

print_verbose("Using \"" + tablet_driver + "\" pen tablet driver...");
print_verbose("Using \"" + DisplayServer::get_singleton()->tablet_get_current_driver() + "\" pen tablet driver...");

OS::get_singleton()->benchmark_end_measure("Servers", "Tablet Driver");
}
Expand Down
42 changes: 39 additions & 3 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "core/config/project_settings.h"
#include "core/io/marshalls.h"
#include "core/io/xml_parser.h"
#include "core/version.h"
#include "drivers/png/png_driver_common.h"
#include "main/main.h"
Expand Down Expand Up @@ -6528,15 +6529,27 @@ void DisplayServerWindows::tablet_set_current_driver(const String &p_driver) {
if (tablet_get_driver_count() == 0) {
return;
}

String driver = p_driver;
if (driver == "auto") {
if (winink_available && !winink_disabled) {
driver = "winink";
} else if (wintab_available) {
driver = "wintab";
} else {
driver = "dummy";
}
}

bool found = false;
for (int i = 0; i < tablet_get_driver_count(); i++) {
if (p_driver == tablet_get_driver_name(i)) {
if (driver == tablet_get_driver_name(i)) {
found = true;
}
}
if (found) {
_update_tablet_ctx(tablet_driver, p_driver);
tablet_driver = p_driver;
_update_tablet_ctx(tablet_driver, driver);
tablet_driver = driver;
} else {
ERR_PRINT("Unknown tablet driver " + p_driver + ".");
}
Expand Down Expand Up @@ -6635,6 +6648,8 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
}
}

tablet_drivers.push_back("auto");

// Note: Windows Ink API for pen input, available on Windows 8+ only.
// Note: DPI conversion API, available on Windows 8.1+ only.
HMODULE user32_lib = LoadLibraryW(L"user32.dll");
Expand Down Expand Up @@ -6669,6 +6684,27 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win

tablet_drivers.push_back("dummy");

String wacom_cfg = OS::get_singleton()->get_config_path().path_join("WTablet").path_join("Wacom_Tablet.dat");
if (FileAccess::exists(wacom_cfg)) {
Ref<XMLParser> parser;
parser.instantiate();
if (parser->open(wacom_cfg) == OK) {
while (parser->read() == OK) {
if (parser->get_node_type() != XMLParser::NODE_ELEMENT) {
continue;
}
if (parser->get_node_name() == "WinUseInk") {
parser->read();
if (parser->get_node_type() == XMLParser::NODE_TEXT) {
winink_disabled = (parser->get_node_data().to_lower().strip_edges() != "true");
print_verbose(vformat("Wacom tablet config found at \"%s\", Windows Ink support is %s.", wacom_cfg, winink_disabled ? "disabled" : "enabled"));
break;
}
}
}
}
}

if (OS::get_singleton()->is_hidpi_allowed()) {
HMODULE Shcore = LoadLibraryW(L"Shcore.dll");

Expand Down
1 change: 1 addition & 0 deletions platform/windows/display_server_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ class DisplayServerWindows : public DisplayServer {
void _update_tablet_ctx(const String &p_old_driver, const String &p_new_driver);
String tablet_driver;
Vector<String> tablet_drivers;
bool winink_disabled = false;

enum DriverID {
DRIVER_ID_COMPAT_OPENGL3 = 1 << 0,
Expand Down