Using icons in X11 c++ app
Foroughi opened this issue · 3 comments
Hi there.
It's been a while since I'm trying to use this icon pack header in my X11 window manager (written in c++) but I couldn't.
I hope you can help me with that.
So here is what I have done :
1 - Downloaded the c++ header file. As I noticed in each header file it has been mentioned what font I should use. So I downloaded the fonts accordingly. put them in .font
folder and fc-cache -rv
2 - then I tried to use the following code to show an icon but what I get is an empty rectangle. (I tried to simplify it as much as i could but you can find the link of repo at the end)
#define ICON_FONT "Font Awesome 6 Free-7"
//also tested with "FontAwesome-7"
//also tested with "fontawesome-7"
auto d = XftDrawCreate(this->CurrentDisplay, this->root, DefaultVisual(this->CurrentDisplay, DefaultScreen(this->CurrentDisplay)), DefaultColormap(this->CurrentDisplay, DefaultScreen(this->CurrentDisplay)));
auto iconfont = XftFontOpenName(this->CurrentDisplay, DefaultScreen(this->CurrentDisplay), ICON_FONT);
XftDrawString8(d, &selectedcolor, iconfont, 10 , 10 , (FcChar8 *)ICON_MAX_FA, 1);
Btw that code is working when I want simply to draw a text.
Also here is the whole repo in case you want to check
Note that ICON_MAX_FA
is not a UTF8 string, it is an integer value for the largest icon. If you want to test drawing an icon you should use one such as ICON_FA_ADDRESS_BOOK
.
We don't have any experience with using these fonts directly with Xft, however if the above does not work I would first check that XftFontOpenName
is loading the font correctly. I note from this xft-example code that the fontname might also need to specify size.
Sadly using ICON_FA_ADDRESS_BOOK
didn't help. I also changed the font name and it didn't help. I am gonna check the example you sent.
Let me know if you found any examples.
thanks for the help anyway.
In case anyone else went through the same problem, please include the font style if you want to use font awesome. So in this case I used Font Awesome 6 Free:size=14:style=Solid
and it worked like a charm.