The i3 FAQ has migrated to https://www.reddit.com/r/i3wm/. All content here is read-only.
Ask Your Question
1

How do I find the criteria for use with i3 config commands like for_window (e.g. to force splashscreens and dialogs to show in floating mode)?

asked 2013-07-10 20:26:34 +0000

ack006 gravatar image

i3 does a very good job at showing splashscreens, "Save As..." dialogs, etc. in floating mode. However, some applications were not designed with (mainly) tiling window managers in mind (one could call that a bug ;-) ), and their splashscreens or other windows may look odd when started in i3. Now, i3 has the ability to force these windows to be floating, but how do I get the necessary criteria for use with for_window, etc.?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
4

answered 2013-07-10 20:42:58 +0000

ack006 gravatar image

updated 2013-07-13 11:59:48 +0000

While xwininfo and xprop will provide the raw data needed to write the criteria, manually copy/pasting all the relevant pieces of output into a criterion list can be tedious, so I've written a small script to automate this.

Running the script and clicking on a window will output all the criteria for it, ready to be copy/pasted after an i3 config command (remove any criteria that aren't needed).

Tip: to catch a splashscreen or transient popup "as it happens", run the script like this (using The GIMP as an example):

$ gimp-2.8 & ./i3-get-window-criteria

and click on the splashscreen as soon as it appears.

Example output for the above command:

[class="Gimp-2.8" id=81788931 instance="gimp-2.8" title="GIMP Startup" window_role="gimp-startup"]

This output can be copy/pasted where needed, then edited to remove any criteria which would make the filter too specific for a particular use case.

Here's the script:

#!/bin/sh

# i3-get-window-criteria - Get criteria for use with i3 config commands

# To use, run this script, then click on a window.
# Output is in the format: [<name>=<value> <name>=<value> ...]

# Known problem: when WM_NAME is used as fallback for the 'title="<string>"' criterion,
# quotes in "<string>" are not escaped properly. This is a problem with the output of `xprop`,
# reported upstream: https://bugs.freedesktop.org/show_bug.cgi?id=66807

PROGNAME=`basename "$0"`

# Check for xwininfo and xprop
for cmd in xwininfo xprop; do
    if ! which $cmd > /dev/null 2>&1; then
        echo "$PROGNAME: $cmd: command not found" >&2
        exit 1
    fi
done

match_int='[0-9][0-9]*'
match_string='".*"'
match_qstring='"[^"\\]*(\\.[^"\\]*)*"' # NOTE: Adds 1 backreference

{
    # Run xwininfo, get window id
    window_id=`xwininfo -int | sed -nre "s/^xwininfo: Window id: ($match_int) .*$/\1/p"`
    echo "id=$window_id"

    # Run xprop, transform its output into i3 criteria. Handle fallback to
    # WM_NAME when _NET_WM_NAME isn't set
    xprop -id $window_id |
        sed -nr \
            -e "s/^WM_CLASS\(STRING\) = ($match_qstring), ($match_qstring)$/instance=\1\nclass=\3/p" \
            -e "s/^WM_WINDOW_ROLE\(STRING\) = ($match_qstring)$/window_role=\1/p" \
            -e "/^WM_NAME\(STRING\) = ($match_string)$/{s//title=\1/; h}" \
            -e "/^_NET_WM_NAME\(UTF8_STRING\) = ($match_qstring)$/{s//title=\1/; h}" \
            -e '${g; p}'
} | sort | tr "\n" " " | sed -r 's/^(.*) $/[\1]\n/'
edit flag offensive delete link more

Comments

Q + A deserve +1. Thanks for sharing!

joepd gravatar imagejoepd ( 2013-07-10 22:11:46 +0000 )edit

Glad you like it :-) Bug (possibly in xprop) reported upstream, let's see what happens. https://bugs.freedesktop.org/show_bug.cgi?id=66807

ack006 gravatar imageack006 ( 2013-07-11 01:50:06 +0000 )edit

Nice script, but for me it's not what I need... if you use this to a browser, for instance, it brings also the webpage title into the i3 rule, which is not optimum... I'd rather have the list of options in an i3 config syntax, and let the user copy&paste whatever he/she wants to use. Makes sense?

bruno.braga gravatar imagebruno.braga ( 2013-07-11 02:09:30 +0000 )edit

The output *is* in i3 config format. You can simply delete whatever criteria you don't want, and keep the rest.

ack006 gravatar imageack006 ( 2013-07-11 02:35:28 +0000 )edit

good feedback, I wish to add 1 to this but does not have the privilege.

diablo465 gravatar imagediablo465 ( 2014-02-04 05:10:17 +0000 )edit
0

answered 2013-07-10 20:29:33 +0000

Michael gravatar image

Use xprop. Also, file a bug report at the application to make the app set the correct hints for splashscreen windows etc., so that window managers can do the right thing.

edit flag offensive delete link more

Comments

Ha :-) I asked the question to be able to share my script with you all, you answered first ;-) I will report a bug (in my case in Eclipse) ASAP.

ack006 gravatar imageack006 ( 2013-07-10 20:45:26 +0000 )edit

Question Tools

Stats

Asked: 2013-07-10 20:26:34 +0000

Seen: 4,691 times

Last updated: Jul 13 '13