Skip to content

Commit 94eff01

Browse files
mkartashevjbrbot
authored andcommitted
JBR-9698 Wayland: session auto-detection doesn't work with binary launcher
1 parent f5eca02 commit 94eff01

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/hotspot/share/runtime/arguments.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
*
2323
*/
2424

25+
#ifdef __linux
26+
#include <dlfcn.h>
27+
#endif
28+
2529
#include "cds/aotLogging.hpp"
2630
#include "cds/cds_globals.hpp"
2731
#include "cds/cdsConfig.hpp"
@@ -3847,6 +3851,36 @@ void Arguments::set_compact_headers_flags() {
38473851
#endif
38483852
}
38493853

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+
38503884
jint Arguments::apply_ergo() {
38513885
// Set flags based on ergonomics.
38523886
jint result = set_ergonomics_flags();
@@ -3917,6 +3951,15 @@ jint Arguments::apply_ergo() {
39173951
FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
39183952
}
39193953

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+
39203963
#ifndef PRODUCT
39213964
if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
39223965
if (use_vm_log()) {

0 commit comments

Comments
 (0)