Repository: fastfetch-cli/fastfetch
File: src/common/detectWMDE.c (C)

Code before:

        ffStrbufSubstrBeforeFirstC(&result->deVersion, '(');
        ffStrbufSubstrAfterFirstC(&result->deVersion, ' ');
        ffStrbufTrim(&result->deVersion, ' ');
    }
}

static void getLXQt(FFinstance* instance, FFWMDEResult* result)
{
    ffStrbufSetS(&result->deProcessName, "lxqt-session");
    ffStrbufSetS(&result->dePrettyName, "LXQt");
    ffParsePropFile("/usr/share/cmake/lxqt/lxqt-config.cmake", "set(LXQT_VERSION", &result->deVersion);

    if(result->deVersion.length == 0 && instance->config.allowSlowOperations)
    {
        //This is really, really, really slow. Thank you, LXQt developers
        ffProcessAppendStdOut(&result->deVersion, (char* const[]){
            "lxqt-session",
            "-v",
            NULL
        });

        FF_STRBUF_CREATE(tmp);
        ffGetPropValueFromLines(result->deVersion.chars , "liblxqt", &tmp);
        ffStrbufSet(&result->deVersion, &tmp);
        ffStrbufDestroy(&tmp);
    }
}

static inline void getDEFromHint(FFinstance* instance, FFWMDEResult* result, ProcData* procData)
{
    getFromProcDir(result, procData, false);

    if(procData->deHint == FF_DE_HINT_UNKNOWN)
        return;

    if(procData->deHint == FF_DE_HINT_PLASMA)
        getKDE(result);
    else if(procData->deHint == FF_DE_HINT_GNOME)
        getGnome(result);
    else if(procData->deHint == FF_DE_HINT_CINNAMON)
        getCinnamon(result);
    else if(procData->deHint == FF_DE_HINT_XFCE4)
        getXFCE4(instance, result);
    else if(procData->deHint == FF_DE_HINT_MATE)
        getMate(instance, result);
    else if(procData->deHint == FF_DE_HINT_LXQT)
        getLXQt(instance, result);
}

static inline void getDE(FFinstance* instance, FFWMDEResult* result, ProcData* procData)

Review comment (suggestion):
This is a unnecesarry buffer allocation. Since we will always copy back to front, in an index increasing order, we can safely use only one buffer. We set the length to 0, so appending will start at index 0, but leave the null byte at the old index, because `ffgetPropValue*` functions use it to detect the length. Implementation would look something like this:
```c
result->deVersion.length = 0; //don't set '\0' byte
ffGetPropValueFromLines(result->deVersion.chars , "liblxqt", &result->deVersion);
```
I didn't test it, but it _should_ work.

Code after:

        ffStrbufSubstrBeforeFirstC(&result->deVersion, '(');
        ffStrbufSubstrAfterFirstC(&result->deVersion, ' ');
        ffStrbufTrim(&result->deVersion, ' ');
    }
}

static void getLXQt(FFinstance* instance, FFWMDEResult* result)
{
    ffStrbufSetS(&result->deProcessName, "lxqt-session");
    ffStrbufSetS(&result->dePrettyName, "LXQt");
    ffParsePropFile("/usr/lib/pkgconfig/lxqt.pc", "Version:", &result->deVersion);

    if(result->deVersion.length == 0)
        ffParsePropFile("/usr/share/cmake/lxqt/lxqt-config.cmake", "set ( LXQT_VERSION", &result->deVersion);
    if(result->deVersion.length == 0)
        ffParsePropFile("/usr/share/cmake/lxqt/lxqt-config-version.cmake", "set ( PACKAGE_VERSION", &result->deVersion);

    if(result->deVersion.length == 0 && instance->config.allowSlowOperations)
    {
        //This is really, really, really slow. Thank you, LXQt developers
        ffProcessAppendStdOut(&result->deVersion, (char* const[]){
            "lxqt-session",
            "-v",
            NULL
        });

        result->deVersion.length = 0; //don't set '\0' byte
        ffGetPropValueFromLines(result->deVersion.chars , "liblxqt", &result->deVersion);
    }
}

static inline void getDEFromHint(FFinstance* instance, FFWMDEResult* result, ProcData* procData)
{
    getFromProcDir(result, procData, false);

    if(procData->deHint == FF_DE_HINT_UNKNOWN)
        return;

    if(procData->deHint == FF_DE_HINT_PLASMA)
        getKDE(result);
    else if(procData->deHint == FF_DE_HINT_GNOME)
        getGnome(result);
    else if(procData->deHint == FF_DE_HINT_CINNAMON)
        getCinnamon(result);
    else if(procData->deHint == FF_DE_HINT_XFCE4)
        getXFCE4(instance, result);
    else if(procData->deHint == FF_DE_HINT_MATE)
        getMate(instance, result);
    else if(procData->deHint == FF_DE_HINT_LXQT)
        getLXQt(instance, result);