-
Notifications
You must be signed in to change notification settings - Fork 572
Added system font recognition for xfce-terminal #36
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
Conversation
Funny thing, i just pushed XFCE theme detection. |
I see it. So this could be done a lot simpler. |
Yes i'm just at reviewing your PR |
src/modules/terminalfont.c
Outdated
|
||
ffParsePropFileConfig(instance, "xfce4/terminal/terminalrc", "FontUseSystem=%[^\n]", fontName.chars); | ||
|
||
if((fontName.chars[0] == '\0') || !ffStrbufCompS(&fontName, "FALSE")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- A
fontName.length == 0
is the better way to test for this when using strbufs. - Maybe an
ffStrbufIgnCaseComp
would be more save to get it right? - I think a
) == 0
is more readable as a!
which implicitly casts anuint32_t
to abool
src/modules/terminalfont.c
Outdated
static void printXCFETerminal(FFinstance* instance) | ||
{ | ||
FFstrbuf fontName; | ||
ffStrbufInitA(&fontName, 256); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is a capacity of 256 really needed?
src/modules/terminalfont.c
Outdated
FFstrbuf fontName; | ||
ffStrbufInitA(&fontName, 256); | ||
|
||
ffParsePropFileConfig(instance, "xfce4/terminal/terminalrc", "FontUseSystem=%[^\n]", fontName.chars); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will need to do a ffStrbufRecalculateLength
after directly writing to the char buffer.
src/modules/terminalfont.c
Outdated
ffStrbufAppendC(&absolutePath, '/'); | ||
ffStrbufAppendS(&absolutePath, ".config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those two lines can be combined to "/.config/x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh
src/modules/terminalfont.c
Outdated
FILE* file = fopen(absolutePath.chars, "r"); | ||
if(file == NULL) | ||
{ | ||
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't open \"%s\"", absolutePath.chars); | ||
ffStrbufDestroy(&absolutePath); | ||
ffStrbufDestroy(&fontName); | ||
|
||
return; | ||
} | ||
|
||
FFstrbuf matchText; | ||
ffStrbufInitAS(&matchText, 64, "<property name=\"MonospaceFontName\" type=\"string\" value=\""); | ||
|
||
char* line = NULL; | ||
size_t len = 0; | ||
|
||
while(getline(&line, &len, file) != -1) | ||
{ | ||
ffStrbufAppendS(&fontName, line); | ||
ffStrbufTrimLeft(&fontName, ' '); | ||
|
||
if(ffStrbufStartsWithS(&fontName, matchText.chars)) | ||
{ | ||
ffStrbufSubstrAfter(&fontName, matchText.length -1); | ||
ffStrbufSubstrBefore(&fontName, fontName.length - 4); // ["/>\n] | ||
break; | ||
} | ||
ffStrbufClear(&fontName); | ||
} | ||
ffStrbufDestroy(&matchText); | ||
ffStrbufDestroy(&absolutePath); | ||
|
||
if(line != NULL) | ||
free(line); | ||
|
||
fclose(file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this whole section can be replaced by a ffParsePropFileConfig
, see my implementation in WM theme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ffParsePropFileConfig
fails if the line has different spacing though. That's why I trimmed the result before the compare. It's very fragile if someone decides to edit the file manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the function be modified to ignore leading/trailing whitespace somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leading would suffice.
Is there a use case for keeping leading white space intact?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its worth implementing a ffSettingsGetXFConf at this point using libxfconf. I will look into this soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But as a note, a single white space in the scanf format string counts as any number of white spaces in the scanned string, thats why i prepended a single white space before the actual format string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the info. I await the new functionality. 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have waited long enough, here it is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. The new system looks a lot better too. 👍
src/modules/terminalfont.c
Outdated
|
||
fclose(file); | ||
|
||
if(fontName.chars[0] != '\0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fontName.length > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using length initially - it failed unless I used Recalculate. This approach worked though.
src/modules/terminalfont.c
Outdated
|
||
static void printXCFETerminal(FFinstance* instance) | ||
{ | ||
FFstrbuf fontName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the following suggestions in mind, i'm not sure if we need a strbuf. Possible i'm wrong at this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying to avoid including strings.h altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am too, but if we never need to modify the buffer we need neither strbufs nor strings.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Will try. :)
Quite happy with this one, apart from the |
This seems fine. There is no problem with including string.h, just with using some dangerous functions out of it. Good resource for this is the commit history of https://github.com/git/git/blob/master/banned.h. I don't see a problem with strcasecmp. |
No description provided.