Skip to content

add script to get the currently focused VM #9701

Description

@zaz

The problem you're addressing

Currently, many scripts and users and rolling ad-hoc methods of determining the currently focused VM. For example:

  1. For the i3 window manager, @marmarek added a function to do this
  2. Sven's “poor man’s” pre-loaded DispVM

and I've seen this used in other places too.

The solution you'd like

A new script /usr/bin/qubes-focused-vm:

#!/bin/bash

# get ID of currently focused window
id=$(xprop -root _NET_ACTIVE_WINDOW)
id=${id##* }

vm=$(xprop -id $id | grep '_QUBES_VMNAME(STRING)')

if [ "$vm$ == "" ]; then
    echo "dom0"
    # dom0 does not set _QUBES_VMNAME
else
    # extract VM name
    vm=${vm#*\"} 
    echo ${vm%\"*}
fi

Note that I have added the if statement for forward compatibility in case dom0 ever sets _QUBES_VMNAME (why doesn't it, by the way?). It assumes dom0 is the only VM that doesn't set _QUBES_VMNAME.

The value to a user, and who that user might be

This simplifies various existing scripts. Also, users may want to add their own shell scripts that bind to a hotkey and perform some action on the currently focused VM. Having a script like this greatly simplifies readability. For example, in my i3 config, I have:

bindsym $mod+Shift+Return exec qrexec-client -e -d "$(qubes-focused-vm)" 'DEFAULT:alacritty -e ranger'

which would by a total mess without the above script.

In fact, it may be worth creating a qubes-run-in-focused-vm script too.


I'd be happy to submit a pull request if you just let me know where's the best place. Possibly here?

Metadata

Metadata

Assignees

Labels

C: desktop-linuxThis issue pertains to dom0's desktop in Qubes OS.P: defaultPriority: default. Default priority for new issues, to be replaced given sufficient information.S: needs reviewStatus: needs review. Waiting for a core dev to review the contributed code.good first issueThis is a recommended issue for first-time contributors.pr submittedA pull request has been submitted for this issue.

Fields

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions