VirtualBox

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#19650 closed defect (fixed)

XWayland: Fix shortcuts like alt-tab not working under [X]wayland

Reported by: Frank Batschulat (Oracle) Owned by: gombara
Component: GUI Version: VirtualBox 6.1.10
Keywords: wayland Cc:
Guest type: Linux Host type: Linux

Description

From: "Hans de Goede" <> To: vbox-dev <vbox-dev@…> Subject: [vbox-dev] [PATCH][resend] Fix shortcuts like alt-tab not working under [X]wayland Date: Mon, 08 Jun 2020 17:18:57 +0200

Hi,

Note this is a resend since my first submission was ignored. This patch makes virtualbox work much better (things like alt+tab will work in the VM) when run inside a Wayland session. Can we please get this merged?

The attached patch tackles a long-standing issue when running VirtualBox under [X]wayland. By default keyboard-grabs are denied to X11 apps under Xwayland, this causes e.g. alt-tab to not be send to the VM, but to go to the host window-environment.

The attached patch modifies VirtualBox to send a special ClientMessage which lets mutter knows that VirtualBox works properly with emulated grabs and that they should be allowed.

As usual, the patch is released under the MIT license.

Regards,

Hans

diff -up VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp~ VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp
--- VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp~	2020-02-18 18:19:59.000000000 +0100
+++ VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp	2020-04-06 13:30:21.274027340 +0200
@@ -2203,6 +2204,17 @@ void UICommon::setWMClass(QWidget *pWidg
     XSetClassHint(QX11Info::display(), pWidget->window()->winId(), &windowClass);
 }
 
+/* static */
+void UICommon::setXwaylandMayGrabKeyboardFlag(QWidget *pWidget)
+{
+    /* Tell the WM we are well behaved wrt Xwayland keyboard-grabs. This will
+     * make the WM turn our grab into a Wayland shortcut inhibition request,
+     * so that e.g. alt+tab will get send to the VM instead of moving the
+     * focus away from the VM. */
+    XXSendClientMessage(QX11Info::display(), pWidget->window()->winId(),
+                        "_XWAYLAND_MAY_GRAB_KEYBOARD", 1);
+}
+
 #endif /* VBOX_WS_X11 */
 
 /* static */
diff -up VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h~ VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h
--- VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h~	2020-02-18 18:19:59.000000000 +0100
+++ VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h	2020-04-06 13:30:20.345012390 +0200
@@ -416,6 +416,8 @@ public:
 
         /** Assigns WM_CLASS property for passed @a pWidget. */
         static void setWMClass(QWidget *pWidget, const QString &strNameString, const QString &strClassString);
+        /** Tell the WM the passed @a pWidget window is well behaved wrt XWayland keyboard-grabs. */
+        static void setXwaylandMayGrabKeyboardFlag(QWidget *pWidget);
 #endif /* VBOX_WS_X11 */
 
         /** Assigns minimum @a pSpinBox to correspond to @a cCount digits. */
diff -up VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp~ VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp
--- VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp~	2020-04-06 13:18:46.000000000 +0200
+++ VirtualBox-6.1.4/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp	2020-04-06 13:25:52.235673962 +0200
@@ -135,6 +135,8 @@ void UIMachineWindow::prepare()
         strWindowName = QString("VirtualBox Machine UUID: %1").arg(uiCommon().managedVMUuid().toString());
     /* Assign WM_CLASS property: */
     UICommon::setWMClass(this, strWindowName, strWindowClass);
+    /* Tell the WM we are well behaved wrt Xwayland keyboard-grabs: */
+    UICommon::setXwaylandMayGrabKeyboardFlag(this);
 #endif
 }
 

Change History (4)

comment:1 by Frank Batschulat (Oracle), 4 years ago

Keywords: wayland added
Owner: set to Frank Batschulat (Oracle)
Status: newaccepted

comment:2 by gombara, 4 years ago

Owner: changed from Frank Batschulat (Oracle) to gombara
Status: acceptedassigned

comment:3 by gombara, 4 years ago

Resolution: fixed
Status: assignedclosed

Hi Hans. Thanks for the patch. It has been integrated into our development branch and backported to 6.1.

comment:4 by Frank Batschulat (Oracle), 4 years ago

this has been fixed in Trunk revision r138534 and has been backported to 6.1.X revision r138535 and will be included in the next releases. The fix is already included in the test builds for Trunk and 6.1.X containing above revisions: https://www.virtualbox.org/wiki/Testbuilds

Note: See TracTickets for help on using tickets.

© 2023 Oracle
ContactPrivacy policyTerms of Use