The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
1

show title of focused window in status bar

asked 2013-04-04 01:12:01 +0000

pau gravatar image

updated 2013-04-05 02:07:49 +0000

Is possible to get the title of the focused window displayed with i3status?

Update:

With a script like the one highlighted by @mschaefer and the hint in faq.i3wm.org/question/854/how-to-force-status-bar-update/ I've been able to get the title of the focused window in the statusbar.

The bar is updated when focus is changed having the refresh ratio to 5 secs in ~/.i3status.

I like to have tiled windows without titlebar and I think this behaiour is cool in such configurations (like dwm does for instance)

If someone is interested, here are the relevant bits that I have in my ~/.i3/config:

bindsym $mod+h focus left; exec killall -USR1 i3status
bindsym $mod+j focus down; exec killall -USR1 i3status
bindsym $mod+k focus up; exec killall -USR1 i3status
bindsym $mod+l focus right; exec killall -USR1 i3status
edit retag flag offensive close merge delete

4 answers

Sort by ยป oldest newest most voted
3

answered 2013-04-04 08:41:17 +0000

updated 2013-04-04 08:51:48 +0000

You can try an external script, see man i3status which has a section "EXTERNAL SCRIPTS/PROGRAMS WITH I3STATUS". Create the following as e.g. ~/mystatus.sh:

#!/bin/bash
i3status | while :
do
    read line
    id=$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')
    name=$(xprop -id $id | awk '/_NET_WM_NAME/{$1=$2="";print}' | cut -d'"' -f2)
    echo "$name | $line" || exit 1
done

Make it executable and run ~/mystatus.sh instead of i3status in your i3 config file.

Please notice that this approach may give you a very long status bar, since the entire window title (e.g. the title of your browser) will be used. Maybe you have a closer look at xprop to filter out something different.

edit flag offensive delete link more

Comments

Thank you! That works well. I didn't know a way to get the active window. I was using `xprop` just to get the `WM_NAME` and `WM_CLASS` of a pointed window :p

pau gravatar imagepau ( 2013-04-04 18:07:49 +0000 )edit

The length of the text can be truncated easily through shell scripting, so I'm not worried about it. The only issue is that the refresh rate of the status bar is about 4 seconds. Is there a way to force the refresh when certain actions (like when changing window focus) happens?

pau gravatar imagepau ( 2013-04-04 18:12:43 +0000 )edit

Your answer is correct. Just waiting for an improvement to mark it as solved. Maybe I must create another question for that? In that case I will create the new one and mark yours as correct

pau gravatar imagepau ( 2013-04-04 18:13:29 +0000 )edit

I'm sorry, that question is currently solved at http://faq.i3wm.org/question/854/how-to-force-status-bar-update/, so this is solved as well. Thank you again!

pau gravatar imagepau ( 2013-04-04 18:37:09 +0000 )edit
0

answered 2013-12-18 23:43:56 +0000

Another way to achieve it:

# the dynamic status bar
bar {
    status_command echo '{"version":1}[[],'; xtitle -s -f '[{"full_text": "%s"}],'
}
# next bar when modkey pressed
bar {
    mode hide
     ...
}

The xtitle binary is a tiny app that you find in github (sorry, insufficient karma to publish links...)

edit flag offensive delete link more

Comments

https://github.com/baskerville/xtitle however, for me there are some dependencies missing, something from the source packages of xcb, but I don't find any references which packages I have to install (using Linux Mint, there are several libxcb-???-dev packages)

mschaefer gravatar imagemschaefer ( 2013-12-26 12:35:31 +0000 )edit

Okay, it seems that libxcb-util0-dev, libxcb-icccm4-dev and libxcb-ewmh-dev are sufficient

mschaefer gravatar imagemschaefer ( 2013-12-26 12:38:05 +0000 )edit
0

answered 2013-08-29 14:55:16 +0000

DocOC gravatar image

The following is a link to a couple scripts (one in perl, the other in python), which allow you to add whatever you want to the status bar, without losing colors.

http://code.stapelberg.de/git/i3statu...

Edit them to fit your needs, put them somewhere in your $PATH, and replace the status_command line in your ~/.i3/config with:

status_command i3status | wrapper.pl

I have mine set to show the current window title, and the state of the moc music daemon, and what song is playing currently, and truncate both those outputs to 70 characters max, so they don't format strangely when you have a very long window title. You could add anything else you want, and set the colors for each item. You will need a little perl or python knowledge.

Also, on the subject of having the window title update when you switch to a new window - a better solution is to edit your ~/.i3status.conf and set

interval = 1

These scripts were originally posted on the faq in the following post: https://faq.i3wm.org/question/459/ext...

edit flag offensive delete link more
0

answered 2013-08-28 21:31:17 +0000

Philippe gravatar image

Here is another version if you use JSON output (output_format = i3bar in your .i3status.conf)

#!/bin/bash
/usr/bin/i3status | (read line && echo $line && read line && echo $line && while :
do
  read line
  id=$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')
  if [ x$id != x ]; then
    name=$(xprop -id $id | awk '/_NET_WM_NAME/{$1=$2="";print}' | cut -d'"' -f2)
    name=${name//\\/\\\\}
    name=${name//\"/\\\"}
    dat="[{\"name\":\"title\",\"full_text\":\"$name\"},"
    echo "${line/[/$dat}" || exit 1
  else
    echo "$line" || exit 1
  fi
done)

I fixed the case when no window is focused (id is empty and xprop prints help message) and I escaped the characters in the title to be json-compatible. I did not escape control sequences, they will probably make i3bar stop processing the json and print errors if a title contains one of them.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-04-04 01:12:01 +0000

Seen: 5,209 times

Last updated: Dec 18 '13