Logo Search packages:      
Sourcecode: waimea version File versions  Download package

char* expand ( char *  org,
WaWindow *  w 
)

Window info expansion.

Expands a special window info characters in a string. Special info characters are: '' replaced with _NET_WM_PID hint for window '
' replaced with name part of windows WM_CLASS hint '' replaced with class part of windows WM_CLASS hint '' replaced with WM_CLIENT_MACHINE hint

Parameters:
org Original string used as source for expansion
w WaWindow to get expansion info from
Returns:
Expanded version of original string, or NULL if no expansion have been made.

Definition at line 460 of file Waimea.cc.

                                     {
    int i;
    char *insert, *expanded, *tmp;
    bool cont, found = false;

    if (! org) return NULL;

    expanded = org;
    for (i = 0; expanded[i] != '\0';) {
        cont = false;
        for (; expanded[i] != '\0' && expanded[i] != '\\'; i++);
        if (expanded[i] == '\0') break;
        switch (expanded[i + 1]) {
            case 'p':
                if (w->pid) insert = w->pid;
                else insert = "";
                break;
            case 'h':
                if (w->host) insert = w->host;
                else insert = "";
                break;
            case 'n':
                if (w->classhint->res_name) insert = w->classhint->res_name;
                else insert = "";
                break;
            case 'c':
                if (w->classhint->res_class) insert = w->classhint->res_class;
                else insert = "";
                break;
            default:
                cont = true;
        }
        if (cont) continue;
        int ilen = strlen(insert);
        tmp = new char[strlen(expanded) + ilen + 1];
        expanded[i] = '\0';
        sprintf(tmp, "%s%s%s", expanded, insert, &expanded[i + 2]);
        if (found) delete [] expanded;
        else expanded[i] = '\\';
        expanded = tmp;
        found = true;
        i += ilen;
    }
    if (found) return expanded;
    else return NULL;
}


Generated by  Doxygen 1.6.0   Back to index