Skip to content

Commit 6a86d7b

Browse files
committed
JBR-9698 Wayland: session auto-detection doesn't work with binary launcher
1 parent f5eca02 commit 6a86d7b

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,34 @@ void Arguments::set_compact_headers_flags() {
38473851
#endif
38483852
}
38493853

3854+
#ifdef __linux
3855+
static const char * get_toolkit_name() {
3856+
const char * toolkit_name = "XToolkit";
3857+
void* libwayland = dlopen(VERSIONED_JNI_LIB_NAME("wayland-client", "0"), RTLD_LAZY | RTLD_LOCAL);
3858+
if (!libwayland) {
3859+
// Fallback to any development version available on the system
3860+
libwayland = dlopen(JNI_LIB_NAME("wayland-client"), RTLD_LAZY | RTLD_LOCAL);
3861+
}
3862+
if (libwayland) {
3863+
typedef void* (*wl_display_connect_t)(const char*);
3864+
typedef void (*wl_display_disconnect_t)(void*);
3865+
3866+
wl_display_connect_t fp_wl_display_connect = (wl_display_connect_t) dlsym(libwayland, "wl_display_connect");
3867+
wl_display_disconnect_t fp_wl_display_disconnect = (wl_display_disconnect_t) dlsym(libwayland, "wl_display_disconnect");
3868+
3869+
if (fp_wl_display_connect && fp_wl_display_disconnect) {
3870+
void* display = fp_wl_display_connect(NULL);
3871+
if (display) {
3872+
toolkit_name = "WLToolkit";
3873+
fp_wl_display_disconnect(display);
3874+
}
3875+
}
3876+
dlclose(libwayland);
3877+
}
3878+
return toolkit_name;
3879+
}
3880+
#endif
3881+
38503882
jint Arguments::apply_ergo() {
38513883
// Set flags based on ergonomics.
38523884
jint result = set_ergonomics_flags();
@@ -3917,6 +3949,17 @@ jint Arguments::apply_ergo() {
39173949
FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
39183950
}
39193951

3952+
#ifdef __linux
3953+
// Replace -Dawt.toolkit.name=auto with either XToolkit (the default) or
3954+
// WLToolkit, if we are able to connect to the Wayland server.
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 = get_toolkit_name();
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)