예제 #1
0
파일: menu.c 프로젝트: Soren-Nordstrom/Ion3
static WMenuEntry *preprocess_menu(ExtlTab tab, int *n_entries)
{
    WMenuEntry *entries;
    ExtlTab entry;
    int i, n;
    
    n=extl_table_get_n(tab);
    *n_entries=n;
    
    if(n<=0)
        return NULL;

    entries=ALLOC_N(WMenuEntry, n);  
    
    if(entries==NULL)
        return NULL;
        
    init_attr();
    
    /* Initialise entries and check submenus */
    for(i=1; i<=n; i++){
        WMenuEntry *ent=&entries[i-1];
        
        ent->title=NULL;
        ent->flags=0;
        
        gr_stylespec_init(&ent->attr);
        
        if(extl_table_geti_t(tab, i, &entry)){
            char *attr;
            ExtlTab sub;
            ExtlFn fn;
            
            if(extl_table_gets_s(entry, "attr", &attr)){
                gr_stylespec_load_(&ent->attr, attr, TRUE);
                free(attr);
            }
            
            if(extl_table_gets_f(entry, "submenu_fn", &fn)){
                ent->flags|=WMENUENTRY_SUBMENU;
                extl_unref_fn(fn);
            }else if(extl_table_gets_t(entry, "submenu", &sub)){
                ent->flags|=WMENUENTRY_SUBMENU;
                extl_unref_table(sub);
            }
            
            if(ent->flags&WMENUENTRY_SUBMENU)
                gr_stylespec_set(&ent->attr, GR_ATTR(submenu));
            
            extl_unref_table(entry);
        }
    }
    
    return entries;
}
예제 #2
0
bool infowin_init(WInfoWin *p, WWindow *parent, const WFitParams *fp,
                  const char *style)
{
    XSetWindowAttributes attr;
    
    if(!window_init(&(p->wwin), parent, fp))
        return FALSE;
    
    p->buffer=ALLOC_N(char, INFOWIN_BUFFER_LEN);
    if(p->buffer==NULL)
        goto fail;
    p->buffer[0]='\0';
    
    if(style==NULL)
        p->style=scopy("*");
    else
        p->style=scopy(style);
    if(p->style==NULL)
        goto fail2;
    
    p->brush=NULL;
    
    gr_stylespec_init(&p->attr);
    
    infowin_updategr(p);
    
    if(p->brush==NULL)
        goto fail3;
    
    /* Enable save unders */
    attr.save_under=True;
    XChangeWindowAttributes(ioncore_g.dpy, p->wwin.win, CWSaveUnder, &attr);
    
    window_select_input(&(p->wwin), IONCORE_EVENTMASK_NORMAL);

    return TRUE;

fail3:
    gr_stylespec_unalloc(&p->attr);
    free(p->style);
fail2:
    free(p->buffer);
fail:    
    window_deinit(&(p->wwin));
    return FALSE;
}
예제 #3
0
파일: gr.c 프로젝트: JoeNotCharles/notion
bool gr_stylespec_load_(GrStyleSpec *spec, const char *str, bool no_order_score)
{
    uint score=(no_order_score ? 1 : count_dashes(str)+1);
    
    gr_stylespec_init(spec);
    
    while(str!=NULL){
        GrAttr a;
        const char *p=strchr(str, '-');
    
        if(p==NULL){
            a=stringstore_alloc(str);
            str=p;
        }else{
            a=stringstore_alloc_n(str, p-str);
            str=p+1;
        }
        
        if(a==STRINGID_NONE)
            goto fail;
            
        if(!gr_stylespec_add(spec, a, score))
            goto fail;
            
        stringstore_free(a);
        
        if(!no_order_score)
            score--;
    }
    
    return TRUE;
    
fail:
    gr_stylespec_unalloc(spec);
    
    return FALSE;
}