Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple way to display title of focused window in i3blocks #472

Open
mrgreen3 opened this issue Jun 2, 2023 · 2 comments
Open

Simple way to display title of focused window in i3blocks #472

mrgreen3 opened this issue Jun 2, 2023 · 2 comments

Comments

@mrgreen3
Copy link

mrgreen3 commented Jun 2, 2023

Not so much of an issue as some advice. Currently using this code in i3blocks config:

# Display focused window title in bar... [window title in bar] command=xdotool getactivewindow getwindowname 2> /dev/null || echo "" align=center min_width=1820 interval=1

Which works fine once I set min_width 100 lower that my normal screen width. Is there a way to calculate min_width automatically? Or is there a better way to do this in i3blocks?

@eskalVAR
Copy link

eskalVAR commented Aug 2, 2023

Hello, I used to use unbuffer xtitle -s -t 50 where 50 is the length of the window.

This works well but sometimes de-syncs requiring a quick i3 reload. I now run polybar in the background to stdout as the window command in i3blocks polybar -q --stdout | grep -o -P '(?<=%{l}).*(?=%{PR})' however still the face issue just left often. Let me know how you get on!

@mrgreen3
Copy link
Author

mrgreen3 commented Aug 28, 2023

Sorry for the late reply ;-)

This is more viable script and does work.

#!/bin/bash
# A simple blocket that prints window title in center of panel.
# Very much dependant on guessing the total length?

window_title=$(xdotool getactivewindow getwindowname)

# Estimation of characters in the block (modify this as per your estimate)
total_length=200 

length=${#window_title}
padding_length=$(( total_length - length ))

# Generate the padding string with underscores
padding=$(printf ' %.0s' $(seq 1 $padding_length))

# Print the window title followed by the padding string
echo  "$window_title $padding"

This is a bit of trial and error as finding the 'center' of screen depends on quite a few variables and calculations.

Based total_length by pure guess work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants