|
22 | 22 | * |
23 | 23 | */ |
24 | 24 |
|
| 25 | +#ifdef __linux |
| 26 | +#include <dlfcn.h> |
| 27 | +#endif |
| 28 | + |
25 | 29 | #include "cds/aotLogging.hpp" |
26 | 30 | #include "cds/cds_globals.hpp" |
27 | 31 | #include "cds/cdsConfig.hpp" |
@@ -3847,6 +3851,36 @@ void Arguments::set_compact_headers_flags() { |
3847 | 3851 | #endif |
3848 | 3852 | } |
3849 | 3853 |
|
| 3854 | +#ifdef __linux |
| 3855 | +// Replaces -Dawt.toolkit.name=auto with either XToolkit (the default) or |
| 3856 | +// WLToolkit, if we are able to connect to the Wayland server. |
| 3857 | +static const char * GetToolkitName() { |
| 3858 | + const char * toolkit_name = "XToolkit"; |
| 3859 | + void* libwayland = dlopen(VERSIONED_JNI_LIB_NAME("wayland-client", "0"), RTLD_LAZY | RTLD_LOCAL); |
| 3860 | + if (!libwayland) { |
| 3861 | + // Fallback to any development version available on the system |
| 3862 | + libwayland = dlopen(JNI_LIB_NAME("wayland-client"), RTLD_LAZY | RTLD_LOCAL); |
| 3863 | + } |
| 3864 | + if (libwayland) { |
| 3865 | + typedef void* (*wl_display_connect_t)(const char*); |
| 3866 | + typedef void (*wl_display_disconnect_t)(void*); |
| 3867 | + |
| 3868 | + wl_display_connect_t fp_wl_display_connect = (wl_display_connect_t) dlsym(libwayland, "wl_display_connect"); |
| 3869 | + wl_display_disconnect_t fp_wl_display_disconnect = (wl_display_disconnect_t) dlsym(libwayland, "wl_display_disconnect"); |
| 3870 | + |
| 3871 | + if (fp_wl_display_connect && fp_wl_display_disconnect) { |
| 3872 | + void* display = fp_wl_display_connect(NULL); |
| 3873 | + if (display) { |
| 3874 | + toolkit_name = "WLToolkit"; |
| 3875 | + fp_wl_display_disconnect(display); |
| 3876 | + } |
| 3877 | + } |
| 3878 | + dlclose(libwayland); |
| 3879 | + } |
| 3880 | + return toolkit_name; |
| 3881 | +} |
| 3882 | +#endif |
| 3883 | + |
3850 | 3884 | jint Arguments::apply_ergo() { |
3851 | 3885 | // Set flags based on ergonomics. |
3852 | 3886 | jint result = set_ergonomics_flags(); |
@@ -3917,6 +3951,15 @@ jint Arguments::apply_ergo() { |
3917 | 3951 | FLAG_SET_DEFAULT(BytecodeVerificationRemote, true); |
3918 | 3952 | } |
3919 | 3953 |
|
| 3954 | +#ifdef __linux |
| 3955 | + const char* toolkit_name = PropertyList_get_value(_system_properties, "awt.toolkit.name"); |
| 3956 | + if (toolkit_name && strcmp(toolkit_name, "auto") == 0) { |
| 3957 | + const char* toolkit_name = GetToolkitName(); |
| 3958 | + PropertyList_unique_add(&_system_properties, "awt.toolkit.name", toolkit_name, |
| 3959 | + AddProperty, WriteableProperty, ExternalProperty); |
| 3960 | + } |
| 3961 | +#endif |
| 3962 | + |
3920 | 3963 | #ifndef PRODUCT |
3921 | 3964 | if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) { |
3922 | 3965 | if (use_vm_log()) { |
|
0 commit comments