/** Convert a Lua table to a list of widget nodes.
 * \param L The Lua VM state.
 * \param idx Index of the table where to store the widgets references.
 * \param widgets The linked list of widget node.
 */
static void
luaA_table2widgets(lua_State *L, int idx, widget_node_array_t *widgets)
{
    if(lua_istable(L, -1))
    {
        int table_idx = luaA_absindex(L, idx);
        lua_pushnil(L);
        while(luaA_next(L, -2))
            luaA_table2widgets(L, table_idx, widgets);
        /* remove the table */
        lua_pop(L, 1);
    }
    else
    {
        widget_t *widget = luaA_toudata(L, -1, &widget_class);
        if(widget)
        {
            widget_node_t w;
            p_clear(&w, 1);
            w.widget = luaA_object_ref_item(L, idx, -1);
            widget_node_array_append(widgets, w);
        }
        else
            lua_pop(L, 1); /* remove value */
    }
}
Beispiel #2
0
/** Add a signal to an object.
 * \param L The Lua VM state.
 * \param oud The object index on the stack.
 * \param name The name of the signal.
 * \param ud The index of function to call when signal is emitted.
 */
void
luaA_object_add_signal(lua_State *L, int oud,
                       const char *name, int ud)
{
    luaA_checkfunction(L, ud);
    lua_object_t *obj = lua_touserdata(L, oud);
    signal_add(&obj->signals, name, luaA_object_ref_item(L, oud, ud));
}
Beispiel #3
0
/** Set a key array with a Lua table.
 * \param L The Lua VM state.
 * \param oidx The index of the object to store items into.
 * \param idx The index of the Lua table.
 * \param keys The array key to fill.
 */
void
luaA_key_array_set(lua_State *L, int oidx, int idx, key_array_t *keys)
{
    luaA_checktable(L, idx);

    foreach(key, *keys)
        luaA_object_unref_item(L, oidx, *key);

    key_array_wipe(keys);
    key_array_init(keys);

    lua_pushnil(L);
    while(lua_next(L, idx))
        if(luaA_toudata(L, -1, &key_class))
            key_array_append(keys, luaA_object_ref_item(L, oidx, -1));
        else
            lua_pop(L, 1);
}
Beispiel #4
0
/** Set a button array with a Lua table.
 * \param L The Lua VM state.
 * \param oidx The index of the object to store items into.
 * \param idx The index of the Lua table.
 * \param buttons The array button to fill.
 */
void
luaA_button_array_set(lua_State *L, int oidx, int idx, button_array_t *buttons)
{
    luaA_checktable(L, idx);

    foreach(button, *buttons)
        luaA_object_unref_item(L, oidx, *button);

    button_array_wipe(buttons);
    button_array_init(buttons);

    lua_pushnil(L);
    while(lua_next(L, idx))
        if(luaA_toudata(L, -1, &button_class))
            button_array_append(buttons, luaA_object_ref_item(L, oidx, -1));
        else
            lua_pop(L, 1);
}
Beispiel #5
0
/** The __newindex method for a textbox object.
 * \param L The Lua VM state.
 * \param token The key token.
 * \return The number of elements pushed on stack.
 */
static int
luaA_textbox_newindex(lua_State *L, awesome_token_t token)
{
    size_t len = 0;
    widget_t *widget = luaA_checkudata(L, 1, &widget_class);
    const char *buf = NULL;
    textbox_data_t *d = widget->data;

    switch(token)
    {
      case A_TK_BG_ALIGN:
        buf = luaL_checklstring(L, 3, &len);
        d->bg_align = draw_align_fromstr(buf, len);
        break;
      case A_TK_BG_RESIZE:
        d->bg_resize = luaA_checkboolean(L, 3);
        break;
      case A_TK_BG_IMAGE:
        luaA_checkudataornil(L, -1, &image_class);
        luaA_object_unref_item(L, 1, d->bg_image);
        d->bg_image = luaA_object_ref_item(L, 1, 3);
        break;
      case A_TK_BG:
        if(lua_isnil(L, 3))
            p_clear(&d->bg, 1);
        else if((buf = luaL_checklstring(L, 3, &len)))
            color_init_reply(color_init_unchecked(&d->bg, buf, len));
        break;
      case A_TK_ALIGN:
        if((buf = luaL_checklstring(L, 3, &len)))
            d->align = draw_align_fromstr(buf, len);
        break;
      case A_TK_VALIGN:
        if((buf = luaL_checklstring(L, 3, &len)))
            d->valign = draw_align_fromstr(buf, len);
        break;
      case A_TK_BORDER_COLOR:
        if((buf = luaL_checklstring(L, 3, &len)))
            color_init_reply(color_init_unchecked(&d->border.color, buf, len));
        break;
      case A_TK_BORDER_WIDTH:
        d->border.width = luaL_checknumber(L, 3);
        break;
      case A_TK_TEXT:
        if(lua_isnil(L, 3)
           || (buf = luaL_checklstring(L, 3, &len)))
        {
            /* delete */
            draw_text_context_wipe(&d->data);
            p_clear(&d->data, 1);

            if(buf)
            {
                char *text;
                ssize_t tlen;
                /* if text has been converted to UTF-8 */
                if(draw_iso2utf8(buf, len, &text, &tlen))
                {
                    draw_text_context_init(&d->data, text, tlen);
                    p_delete(&text);
                }
                else
                    draw_text_context_init(&d->data, buf, len);

                d->extents = draw_text_extents(&d->data);
            }
            else
                p_clear(&d->extents, 1);
        }
        break;
      case A_TK_WIDTH:
        d->width = luaL_checknumber(L, 3);
        break;
      case A_TK_HEIGHT:
        d->height = luaL_checknumber(L, 3);
        break;
      case A_TK_WRAP:
        if((buf = luaL_checklstring(L, 3, &len)))
            switch(a_tokenize(buf, len))
            {
              case A_TK_WORD:
                d->wrap = PANGO_WRAP_WORD;
                break;
              case A_TK_CHAR:
                d->wrap = PANGO_WRAP_CHAR;
                break;
              case A_TK_WORD_CHAR:
                d->wrap = PANGO_WRAP_WORD_CHAR;
                break;
              default:
                break;
            }
        break;
      case A_TK_ELLIPSIZE:
        if((buf = luaL_checklstring(L, 3, &len)))
            switch(a_tokenize(buf, len))
            {
              case A_TK_START:
                d->ellip = PANGO_ELLIPSIZE_START;
                break;
              case A_TK_MIDDLE:
                d->ellip = PANGO_ELLIPSIZE_MIDDLE;
                break;
              case A_TK_END:
                d->ellip = PANGO_ELLIPSIZE_END;
                break;
              default:
                break;
            }
        break;
      default:
        return 0;
    }

    widget_invalidate_bywidget(widget);

    return 0;
}