Merge pull request #3842 from jgilje/set-wmclass-instance-from-vmname

update WM_CLASS instance name from vm_name
This commit is contained in:
Miran Grča
2023-11-22 18:13:30 +01:00
committed by GitHub
4 changed files with 52 additions and 0 deletions

View File

@@ -371,6 +371,8 @@ if (APPLE AND CMAKE_MACOSX_BUNDLE)
endif()
if (UNIX AND NOT APPLE AND NOT HAIKU)
target_sources(ui PRIVATE x11_util.c)
find_package(X11 REQUIRED)
target_link_libraries(ui PRIVATE X11::X11 X11::Xi)
target_sources(ui PRIVATE evdev_keyboard.cpp xinput2_mouse.cpp)

View File

@@ -117,6 +117,11 @@ extern int qt_nvr_save(void);
# undef KeyRelease
#endif
#if defined Q_OS_UNIX && !defined Q_OS_HAIKU && !defined Q_OS_MACOS
#include <qpa/qplatformwindow.h>
#include "x11_util.h"
#endif
#ifdef Q_OS_MACOS
# include "cocoa_keyboard.hpp"
// The namespace is required to avoid clashing typedefs; we only use this
@@ -712,6 +717,20 @@ MainWindow::MainWindow(QWidget *parent)
# endif
{}
#endif
#if defined Q_OS_UNIX && !defined Q_OS_MACOS && !defined Q_OS_HAIKU
if (QApplication::platformName().contains("xcb")) {
QTimer::singleShot(0, this, [this] {
auto whandle = windowHandle();
if (! whandle) {
qWarning() << "No window handle";
} else {
QPlatformWindow *window = whandle->handle();
set_wm_class(window->winId(), vm_name);
}
});
}
#endif
}
void

22
src/qt/x11_util.c Normal file
View File

@@ -0,0 +1,22 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include "x11_util.h"
void set_wm_class(unsigned long window, char *res_name) {
Display* display = XOpenDisplay(NULL);
if (display == NULL) {
return;
}
XClassHint hint;
XGetClassHint(display, window, &hint);
hint.res_name = res_name;
XSetClassHint(display, window, &hint);
// During testing, I've had to issue XGetClassHint after XSetClassHint
// to get the window manager to recognize the change.
XGetClassHint(display, window, &hint);
}

9
src/qt/x11_util.h Normal file
View File

@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif
void set_wm_class(unsigned long window, char *res_name);
#ifdef __cplusplus
}
#endif