You are not logged in.

#1 2014-04-17 22:52:43

Vixus
Member
Registered: 2012-11-02
Posts: 60

xftwidth: calculates pixel width of a string using a given Xft font

When you want to right-align stuff in dzen2 it's pretty painful.

I got fed up with dzen's textwidth that doesn't really work with modern fonts. I wrote a (pretty crappy) C program to do the same job but with Xft support.
Needs Xft and fontconfig of course smile

https://github.com/vixus0/xftwidth

Now you can just:

#!/usr/bin/bash

left="some text"
right="more text"
width=`xftwidth font:size=9 "${right}"`
echo "${left}^p(_RIGHT)^p(-$width)${right}" | dzen2

Offline

#2 2014-04-18 08:03:44

moetunes
Member
From: A comfortable couch
Registered: 2010-10-09
Posts: 1,033

Re: xftwidth: calculates pixel width of a string using a given Xft font

I like to always free a malloc'd pointer.
http://www.gnu.org/software/libc/manual … alloc.html

HTH


You're just jealous because the voices only talk to me.

Offline

#3 2014-04-18 10:39:21

Vixus
Member
Registered: 2012-11-02
Posts: 60

Re: xftwidth: calculates pixel width of a string using a given Xft font

Yup, knew I'd forget something. Thanks smile

Offline

Board footer

Powered by FluxBB