bulletmark / raise-or-run

Linux shell script to raise app window, or run app if window not already open
4 stars 0 forks source link

The WM_CLASS does not work on QEMU's virtual machines #1

Open gusbemacbe opened 4 years ago

gusbemacbe commented 4 years ago

Hello!

  1. I created a shell script file (.sh) to run QEMU, opening a specific virtual machine. The original WM_CLASS of Qemu is Qemu-system-x86.
  2. I symlinked the shell script file to /usr/bin/qemu-macos-mojave.
  3. I created the qemu-macos-mojave.desktop, setting -c following:
[Desktop Entry]
Categories = OperatingSystem; OS; System; VirtualMachine;
Comment = Run and open the virtual machine of macOS Mojave with QEMU
Exec=bash -c 'cd "/media/Gustavo/Virtual Machines/macOS Mojave/" && /usr/bin/raise-or-run -c mojave qemu-macos-mojave'
GenericName = Virtual Machine
Icon = qemu
Name = macOS Mojave
StartupNotify = false
StartupWMClass = mojave
Terminal = false
Type = Application
Version = 1.1
bulletmark commented 4 years ago

Sorry "does not work" is not a useful description. Please describe exactly what output + result you are expecting and exactly what output + result you get.

gusbemacbe commented 4 years ago

Observe that the window title in the panel:

image

I wanted to replace Qemu-system-x86_64 for macOS Mojave, like you see in the StartupWMClass = mojave, which is detected by Exec that intercepted the option -c <WM_CLASS>.

So I saw that your project offers the option of setting WM_CLASS name by middle of applying -c <WM_CLASS>.

References:

  1. https://superuser.com/questions/1118101/use-multiple-firefox-wm-classes-in-same-profile
  2. https://bgstack15.wordpress.com/2019/01/04/x11-change-application-titlebar-and-icon-in-window-manager-panel/
bulletmark commented 4 years ago

Read the opening paragraph of the README here. This little script just checks if you already have a window open for that app + file, else it opens a new window. Is that what you are trying to do?

gusbemacbe commented 4 years ago

Yes, I have read the whole README. Yes, it is. The desktop file's window manager title still holds the Qemu-x86_64.

If I change to StartupWMClass = Qemu-x86_64, it will work and the desktop file window manager title will appear normally as "macOS Mojave", but I have other Qemu virtual machines with different desktop files that will appear with the same name of "macOS Mojave" because they belong to the same app whose original WM_CLASS is same.

I tested, using your project for different desktop files of same app with different shell scripts, different names and different StartupWMClass, but I did not get.

bulletmark commented 4 years ago

What does "but I did not get" mean at the end of that last sentence?

gusbemacbe commented 4 years ago

It meant that the option -c did not replace the WM_CLASS name in the command Exec, with or without the original or modified StartupWMClass.

I think because my file is a shell script file.

If you do not understand yet due to my language barrier, I will explain what I will do, with input, output, result and expected.

gusbemacbe commented 4 years ago

Without the use of raise-or-run

Input

  1. I install the app called Qemu. The original WM_CLASS string of the app QEMU is Qemu-system-x86_64. The command line of the app is qemu-system-x86_64.
  2. I create two shell script files called qemu-macos-mojave.sh and qemu-macos--catalina.sh in the folder called VMs, following the sample and simple codes:

The file qemu-macos-mojave.sh:

#!/bin/bash

qemu-system-x86_64 \
  -enable-kvm \
  -m 512 \
  -device virtio-vga,virgl=on 
  -display sdl,gl=on \ 
  -netdev user,id=ethernet.0,hostfwd=tcp::10022-:22 
  -device rtl8139,netdev=ethernet.0 \ 
  -soundhw ac97 \
  -device ich9-ahci,id=sata \
  -drive id=ESP,if=none,format=qcow2,file=ESP.qcow2 \
  -device ide-hd,bus=sata.2,drive=ESP \
  -drive id=SystemDisk,if=none,file=mojave.qcow2 \
  -device ide-hd,bus=sata.4,drive=SystemDisk \

The file qemu-macos-catalina.sh:

#!/bin/bash

qemu-system-x86_64 \
  -enable-kvm \
  -m 512 \
  -device virtio-vga,virgl=on 
  -display sdl,gl=on \ 
  -netdev user,id=ethernet.0,hostfwd=tcp::10022-:22 
  -device rtl8139,netdev=ethernet.0 \ 
  -soundhw ac97 \
  -device ich9-ahci,id=sata \
  -drive id=ESP,if=none,format=qcow2,file=ESP.qcow2 \
  -device ide-hd,bus=sata.2,drive=ESP \
  -drive id=SystemDisk,if=none,file=catalina.qcow2 \
  -device ide-hd,bus=sata.4,drive=SystemDisk \
  1. I create the symlinks of these two files to /usr/bin/qemu-macos-mojave and to /usr/bin/qemu-macos-catalina.
  2. I create two desktop files called qemu-macos-mojave.desktop and qemu-macos-catalina.desktop. Pay attention to the Name and StartupWMCLass.

The file qemu-macos-mojave.desktop:

[Desktop Entry]
Categories = OperatingSystem; OS; System; VirtualMachine;
Comment = Run and open the virtual machine of macOS Mojave with QEMU
Exec=bash -c 'cd "$HOME/VMs" && qemu-macos-mojave'
GenericName = Virtual Machine
Icon = qemu
Name = macOS Mojave
StartupNotify = false
StartupWMClass = Qemu-system-x86_64
Terminal = false
Type = Application
Version = 1.1

The file qemu-macos-catalina.desktop:

[Desktop Entry]
Categories = OperatingSystem; OS; System; VirtualMachine;
Comment = Run and open the virtual machine of macOS Catalina with QEMU
Exec=bash -c 'cd "$HOME/VMs" && qemu-macos-catalina'
GenericName = Virtual Machine
Icon = qemu
Name = macOS Catalina
StartupNotify = false
StartupWMClass = Qemu-system-x86_64
Terminal = false
Type = Application
Version = 1.1

Output and result

Only the desktop file qemu-macos-mojave.desktop worked, because its WM_CLASS appeared as macOS Mojave instead of Qemu-system-x86_64. Perfect! But the another file, qemu-macos-catalina.desktop, did not work, because its WM_CLASS also appeared as macOS Mojave instead of macOS Catalina because both files share the same original StartupWMClass.

Expected

With the use of raise-or-run

Input

I open the desktop files qemu-macos-mojave.desktop and qemu-macos-catalina.desktop. Pay attention to the Exec (notice the option -c), Name and StartupWMCLass.

  1. In the file qemu-macos-mojave.desktop, I replaced:
    • Exec=bash -c 'cd "$HOME/VMs" && qemu-macos-mojave' for Exec=bash -c 'cd "$HOME/VMs" && /usr/bin/raise-or-run -c mojave qemu-macos-mojave';
    • StartupWMClass = Qemu-system-x86_64 for StartupWMClass = mojave;
    • The name continues the same.
  2. In the file qemu-macos-catalina.desktop, I replaced:
    • Exec=bash -c 'cd "$HOME/VMs" && qemu-macos-catalina' for Exec=bash -c 'cd "$HOME/VMs" && /usr/bin/raise-or-run -c catalina qemu-macos-catalina';
    • StartupWMClass = Qemu-system-x86_64 for StartupWMClass = catalina;
    • The name continues the same.

Output and result

The same problems continue as in the previous result. The -c really did not replace the WM_CLASS, and the windows still continued as Qemu-system-x86_64. Maybe your project does not detect the StartupWMClass string if the -c is equal.

Expected

Did you understand this whole explanation?

bulletmark commented 4 years ago

You say "The -c really did not replace the WM_CLASS". Are you expecting that raise-or-run changes something to do with your app etc? This utility is trivial. It merely looks to see if a window is already open with the class you specify + file name. Runwctrl -lx yourself to see what the script looks at. That is all the script uses in it's tiny lines of logic.

BTW, completely separate unrelated issue but as a matter of style you really should not be creating symlinks in /usr/bin (i.e as root) for the above. Get rid of those because everything else you are doing above is created and run as your normal user. Just change the exec line to

Exec=bash -c 'cd "$HOME/VMs" && ./qemu-macos-mojave.sh'
gusbemacbe commented 4 years ago

Are you expecting that raise-or-run changes something to do with your app etc? This utility is trivial. It merely looks to see if a window is already open with the class you specify + file name. Runwctrl -lx yourself to see what the script looks at. That is all the script uses in it's tiny lines of logic.

Yes, all this is what I wanted.