HOWTO: showing a title of focused window in bar (i3wm)
There is no title of focused window in i3bar by default, but it can be reached in many different ways. So it’s my way to do it.
Mostly people use default status program or conky. It’s not a big deal, but I prefer to use i3blocks for one of bars (have 2). Then you can get xtitle for showing current window title, compile it and put somewhere.
Using xtitle is pretty easy:
But that’s not all that you need to do. After setting text for the i3bar and several days of using it you’ll surely notice one bug: you cannot use workspace buttons if a part of the text lays under them. That’s not so bad because you can control text output in linux. So, there’s simple util named cut which does what it should to do – it cuts out a part of your input text. After using it syntax would be like:
./xtitle | cut -c1-70
Notice that a number of showing characters depends on your font and free space in bar.
Moreover, you can continue formatting your output. Remember that we’re using JSON, so we can try to avoid breaking syntax thanks to replacing problem symbols. One of the obvious decisions is using sed. Simple example (remember that syntax differs with different shells and i’m using fish here, not bash):
./bin/xtitle | cut -c1-70 | sed -e ‘s/\”/\’/g’
Here we’re replacing “ (used in JSON as quoting of the value) with‘ (usual symbol in JSON).
Now put these 2 lines into a .sh file, make it executable and put in i3blocks config:
Done! Now you may not use window’s header decorations, it’s useful for split layout and maximized windows because gains extra space.