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

Move tablet driver API from OS to DisplayServer #46131

Merged
merged 1 commit into from
Feb 18, 2021
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
23 changes: 0 additions & 23 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,22 +681,6 @@ String _OS::get_unique_id() const {
return OS::get_singleton()->get_unique_id();
}

int _OS::get_tablet_driver_count() const {
return OS::get_singleton()->get_tablet_driver_count();
}

String _OS::get_tablet_driver_name(int p_driver) const {
return OS::get_singleton()->get_tablet_driver_name(p_driver);
}

String _OS::get_current_tablet_driver() const {
return OS::get_singleton()->get_current_tablet_driver();
}

void _OS::set_current_tablet_driver(const String &p_driver) {
OS::get_singleton()->set_current_tablet_driver(p_driver);
}

_OS *_OS::singleton = nullptr;

void _OS::_bind_methods() {
Expand Down Expand Up @@ -780,19 +764,12 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("request_permissions"), &_OS::request_permissions);
ClassDB::bind_method(D_METHOD("get_granted_permissions"), &_OS::get_granted_permissions);

ClassDB::bind_method(D_METHOD("get_tablet_driver_count"), &_OS::get_tablet_driver_count);
ClassDB::bind_method(D_METHOD("get_tablet_driver_name", "idx"), &_OS::get_tablet_driver_name);
ClassDB::bind_method(D_METHOD("get_current_tablet_driver"), &_OS::get_current_tablet_driver);
ClassDB::bind_method(D_METHOD("set_current_tablet_driver", "name"), &_OS::set_current_tablet_driver);

ADD_PROPERTY(PropertyInfo(Variant::INT, "exit_code"), "set_exit_code", "get_exit_code");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "low_processor_usage_mode_sleep_usec"), "set_low_processor_usage_mode_sleep_usec", "get_low_processor_usage_mode_sleep_usec");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "tablet_driver"), "set_current_tablet_driver", "get_current_tablet_driver");

// Those default values need to be specified for the docs generator,
// to avoid using values from the documentation writer's own OS instance.
ADD_PROPERTY_DEFAULT("tablet_driver", "");
ADD_PROPERTY_DEFAULT("exit_code", 0);
ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false);
ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900);
Expand Down
5 changes: 0 additions & 5 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,6 @@ class _OS : public Object {
bool request_permissions();
Vector<String> get_granted_permissions() const;

int get_tablet_driver_count() const;
String get_tablet_driver_name(int p_driver) const;
String get_current_tablet_driver() const;
void set_current_tablet_driver(const String &p_driver);

static _OS *get_singleton() { return singleton; }

_OS() { singleton = this; }
Expand Down
5 changes: 0 additions & 5 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ class OS {
bool is_layered_allowed() const { return _allow_layered; }
bool is_hidpi_allowed() const { return _allow_hidpi; }

virtual int get_tablet_driver_count() const { return 0; };
virtual String get_tablet_driver_name(int p_driver) const { return ""; };
virtual String get_current_tablet_driver() const { return ""; };
virtual void set_current_tablet_driver(const String &p_driver){};

void ensure_user_data_dir();

virtual MainLoop *get_main_loop() const = 0;
Expand Down
36 changes: 36 additions & 0 deletions doc/classes/DisplayServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,42 @@
<description>
</description>
</method>
<method name="tablet_get_current_driver" qualifiers="const">
<return type="String">
</return>
<description>
Returns current active tablet driver name.
[b]Note:[/b] This method is implemented on Windows.
</description>
</method>
<method name="tablet_get_driver_count" qualifiers="const">
<return type="int">
</return>
<description>
Returns the total number of available tablet drivers.
[b]Note:[/b] This method is implemented on Windows.
</description>
</method>
<method name="tablet_get_driver_name" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="idx" type="int">
</argument>
<description>
Returns the tablet driver name for the given index.
[b]Note:[/b] This method is implemented on Windows.
</description>
</method>
<method name="tablet_set_current_driver">
<return type="void">
</return>
<argument index="0" name="name" type="String">
</argument>
<description>
Set active tablet driver name.
[b]Note:[/b] This method is implemented on Windows.
</description>
</method>
<method name="virtual_keyboard_get_height" qualifiers="const">
<return type="int">
</return>
Expand Down
21 changes: 0 additions & 21 deletions doc/classes/OS.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,24 +304,6 @@
[b]Note:[/b] This method is implemented on Android, Linux, macOS and Windows.
</description>
</method>
<method name="get_tablet_driver_count" qualifiers="const">
<return type="int">
</return>
<description>
Returns the total number of available tablet drivers.
[b]Note:[/b] This method is implemented on Windows.
</description>
</method>
<method name="get_tablet_driver_name" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="idx" type="int">
</argument>
<description>
Returns the tablet driver name for the given index.
[b]Note:[/b] This method is implemented on Windows.
</description>
</method>
<method name="get_thread_caller_id" qualifiers="const">
<return type="int">
</return>
Expand Down Expand Up @@ -563,9 +545,6 @@
<member name="low_processor_usage_mode_sleep_usec" type="int" setter="set_low_processor_usage_mode_sleep_usec" getter="get_low_processor_usage_mode_sleep_usec" default="6900">
The amount of sleeping between frames when the low-processor usage mode is enabled (in microseconds). Higher values will result in lower CPU usage.
</member>
<member name="tablet_driver" type="String" setter="set_current_tablet_driver" getter="get_current_tablet_driver" default="&quot;&quot;">
The current tablet driver in use.
</member>
</members>
<constants>
<constant name="VIDEO_DRIVER_GLES2" value="0" enum="VideoDriver">
Expand Down
9 changes: 6 additions & 3 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@
<member name="display/mouse_cursor/tooltip_position_offset" type="Vector2" setter="" getter="" default="Vector2( 10, 10 )">
Position offset for tooltips, relative to the mouse cursor's hotspot.
</member>
<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.
</member>
<member name="input_devices/pen_tablet/driver.windows" type="String" setter="" getter="">
Override for [member input_devices/pen_tablet/driver] on Windows.
</member>
<member name="display/window/dpi/allow_hidpi" type="bool" setter="" getter="" default="false">
If [code]true[/code], allows HiDPI display on Windows and macOS. This setting has no effect on desktop Linux, as DPI-awareness fallbacks are not supported there.
</member>
Expand Down Expand Up @@ -513,9 +519,6 @@
<member name="display/window/size/width" type="int" setter="" getter="" default="1024">
Sets the game's main viewport width. On desktop platforms, this is the default window size. Stretch mode settings also use this as a reference when enabled.
</member>
<member name="display/window/tablet_driver" type="String" setter="" getter="">
Specifies the tablet driver to use. If left empty, the default driver will be used.
</member>
<member name="display/window/text_name" type="String" setter="" getter="" default="&quot;&quot;">
Specifies the [TextServer] to use. If left empty, the default will be used.
</member>
Expand Down
77 changes: 32 additions & 45 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ static bool _start_success = false;

// Drivers

String tablet_driver = "";
String text_driver = "";

static int text_driver_idx = -1;
static int display_driver_idx = -1;
static int audio_driver_idx = -1;
Expand Down Expand Up @@ -329,13 +331,7 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" --enable-vsync-via-compositor When vsync is enabled, vsync via the OS' window compositor (Windows only).\n");
OS::get_singleton()->print(" --disable-vsync-via-compositor Disable vsync via the OS' window compositor (Windows only).\n");
OS::get_singleton()->print(" --single-window Use a single window (no separate subwindows).\n");
OS::get_singleton()->print(" --tablet-driver Tablet input driver (");
for (int i = 0; i < OS::get_singleton()->get_tablet_driver_count(); i++) {
if (i != 0)
OS::get_singleton()->print(", ");
OS::get_singleton()->print("'%s'", OS::get_singleton()->get_tablet_driver_name(i).utf8().get_data());
}
OS::get_singleton()->print(") (Windows only).\n");
OS::get_singleton()->print(" --tablet-driver Pen tablet input driver.\n");
OS::get_singleton()->print("\n");
#endif

Expand Down Expand Up @@ -556,7 +552,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph

String display_driver = "";
String audio_driver = "";
String tablet_driver = "";
String project_path = ".";
bool upwards = false;
String debug_uri = "";
Expand Down Expand Up @@ -725,19 +720,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--tablet-driver") {
if (I->next()) {
tablet_driver = I->next()->get();
bool found = false;
for (int i = 0; i < OS::get_singleton()->get_tablet_driver_count(); i++) {
if (tablet_driver == OS::get_singleton()->get_tablet_driver_name(i)) {
found = true;
}
}

if (!found) {
OS::get_singleton()->print("Unknown tablet driver '%s', aborting.\n",
tablet_driver.utf8().get_data());
goto error;
}

N = I->next()->next();
} else {
OS::get_singleton()->print("Missing tablet driver argument, aborting.\n");
Expand Down Expand Up @@ -1267,29 +1249,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph

OS::get_singleton()->_vsync_via_compositor = window_vsync_via_compositor;

{
GLOBAL_DEF_RST_NOVAL("input_devices/tablet/driver", "");
GLOBAL_DEF_RST_NOVAL("input_devices/tablet/driver.windows", "");
ProjectSettings::get_singleton()->set_custom_property_info("input_devices/tablet/driver.windows", PropertyInfo(Variant::STRING, "input_devices/tablet/driver.windows", PROPERTY_HINT_ENUM, "wintab,winink"));
}
if (tablet_driver == "") { // specified in project.godot
tablet_driver = GLOBAL_GET("input_devices/tablet/driver");
if (tablet_driver == "") {
tablet_driver = OS::get_singleton()->get_tablet_driver_name(0);
}
}

for (int i = 0; i < OS::get_singleton()->get_tablet_driver_count(); i++) {
if (tablet_driver == OS::get_singleton()->get_tablet_driver_name(i)) {
OS::get_singleton()->set_current_tablet_driver(OS::get_singleton()->get_tablet_driver_name(i));
break;
}
}

if (tablet_driver == "") {
OS::get_singleton()->set_current_tablet_driver(OS::get_singleton()->get_tablet_driver_name(0));
}

/* todo restore
OS::get_singleton()->_allow_layered = GLOBAL_DEF("display/window/per_pixel_transparency/allowed", false);
video_mode.layered = GLOBAL_DEF("display/window/per_pixel_transparency/enabled", false);
Expand Down Expand Up @@ -1511,7 +1470,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
}
}
}
printf("Using %s text server...\n", TextServerManager::get_interface_name(text_driver_idx).utf8().get_data());
print_verbose("Using \"" + TextServerManager::get_interface_name(text_driver_idx) + "\" text server...");

/* Initialize Text Server */

Expand Down Expand Up @@ -1571,6 +1530,34 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
display_server->screen_set_orientation(window_orientation);
}

/* Initialize Pen Table Driver */

{
GLOBAL_DEF_RST_NOVAL("input_devices/pen_tablet/driver", "");
GLOBAL_DEF_RST_NOVAL("input_devices/pen_tablet/driver.windows", "");
ProjectSettings::get_singleton()->set_custom_property_info("input_devices/pen_tablet/driver.windows", PropertyInfo(Variant::STRING, "input_devices/pen_tablet/driver.windows", PROPERTY_HINT_ENUM, "wintab,winink"));
}

if (tablet_driver == "") { // specified in project.godot
tablet_driver = GLOBAL_GET("input_devices/pen_tablet/driver");
if (tablet_driver == "") {
tablet_driver = DisplayServer::get_singleton()->tablet_get_driver_name(0);
}
}

for (int i = 0; i < DisplayServer::get_singleton()->tablet_get_driver_count(); i++) {
if (tablet_driver == DisplayServer::get_singleton()->tablet_get_driver_name(i)) {
DisplayServer::get_singleton()->tablet_set_current_driver(DisplayServer::get_singleton()->tablet_get_driver_name(i));
break;
}
}

if (DisplayServer::get_singleton()->tablet_get_current_driver() == "") {
DisplayServer::get_singleton()->tablet_set_current_driver(DisplayServer::get_singleton()->tablet_get_driver_name(0));
}

print_verbose("Using \"" + tablet_driver + "\" pen tablet driver...");

/* Initialize Visual Server */

rendering_server = memnew(RenderingServerDefault(OS::get_singleton()->get_render_thread_mode() == OS::RENDER_SEPARATE_THREAD));
Expand Down
Loading