Beispiel #1
0
/** Tag object.
 * \param L The Lua VM state.
 * \return The number of elements pushed on stack.
 * \luastack
 * \lfield name Tag name.
 * \lfield screen Screen number of the tag.
 * \lfield layout Tag layout.
 * \lfield selected True if the client is selected to be viewed.
 */
static int
luaA_tag_index(lua_State *L)
{
    size_t len;
    tag_t *tag = luaL_checkudata(L, 1, "tag");
    const char *attr;

    if(luaA_usemetatable(L, 1, 2))
        return 1;

    attr = luaL_checklstring(L, 2, &len);

    switch(a_tokenize(attr, len))
    {
      case A_TK_NAME:
        lua_pushstring(L, tag->name);
        break;
      case A_TK_SCREEN:
        if(tag->screen == SCREEN_UNDEF)
            return 0;
        lua_pushnumber(L, tag->screen + 1);
        break;
      case A_TK_SELECTED:
        lua_pushboolean(L, tag->selected);
        break;
      default:
        return 0;
    }

    return 1;
}
Beispiel #2
0
static int luaA_mixer_get(lua_State *L) {
    mixer_t **mixer = luaL_checkudata(L, 1, "mixer_dev");
    if ((*mixer)->fh < 0) return 0;
    if (luaA_usemetatable(L, 1, 2)) return 1;

    int devno = -1;
    const char* devname;

    if (lua_isnumber(L, 2)) {
        devno = luaL_checknumber(L, 2) - 1;
        if (devno < 0) return 0;
    } else {
        devname = luaL_checkstring(L, 2);
    }

    int i, nrext;

    mixer_ext_t *mext = lua_newuserdata(L, sizeof(mixer_ext_t));
    mext->mixer = *mixer;
    mext->ext.dev = (*mixer)->num;

    if (devno < 0) {
        nrext = (*mixer)->num;
        if (ioctl((*mixer)->fh, SNDCTL_MIX_NREXT, &nrext) < 0)
            return 0;

        for (i = 0; i < nrext; i++) {
            mext->ext.ctrl = i;
            if (ioctl((*mixer)->fh, SNDCTL_MIX_EXTINFO, &(mext->ext)) < 0)
                return 0;

            if ((strcmp(mext->ext.extname, devname) == 0)) { // || (strcmp(mext->ext.id, devname) == 0)) {
                devno = i;
                break;
            }
        }

        if (devno < 0) return 0;

    } else {
        mext->ext.ctrl = devno;
        if (ioctl((*mixer)->fh, SNDCTL_MIX_EXTINFO, &(mext->ext)) < 0)
            return 0;
    }

    mext->devno = devno;
    (*mixer)->refcnt++;
    warn("Mixer %p refcount increased to %d", *mixer, (*mixer)->refcnt);

    luaL_getmetatable(L, "mixer_ext");
    lua_setmetatable(L, -2);

    return 1;
}
Beispiel #3
0
/** awesome global table.
 * \param L The Lua VM state.
 * \return The number of elements pushed on stack.
 * \luastack
 * \lfield conffile The configuration file which has been loaded.
 * \lfield version The version of awesome.
 * \lfield release The release name of awesome.
 * \lfield startup True if we are still in startup, false otherwise.
 * \lfield startup_errors Error message for errors that occured during startup.
 * \lfield composite_manager_running True if a composite manager is running.
 */
static int
luaA_awesome_index(lua_State *L)
{
    if(luaA_usemetatable(L, 1, 2))
        return 1;

    const char *buf = luaL_checkstring(L, 2);

    if(A_STREQ(buf, "conffile"))
    {
        lua_pushstring(L, conffile);
        return 1;
    }

    if(A_STREQ(buf, "version"))
    {
        lua_pushstring(L, awesome_version_string());
        return 1;
    }

    if(A_STREQ(buf, "release"))
    {
        lua_pushstring(L, awesome_release_string());
        return 1;
    }

    if(A_STREQ(buf, "startup"))
    {
        lua_pushboolean(L, globalconf.loop == NULL);
        return 1;
    }

    if(A_STREQ(buf, "startup_errors"))
    {
        if (globalconf.startup_errors.len == 0)
            return 0;
        lua_pushstring(L, globalconf.startup_errors.s);
        return 1;
    }

    if(A_STREQ(buf, "composite_manager_running"))
    {
        lua_pushboolean(L, composite_manager_running());
        return 1;
    }

    return luaA_default_index(L);
}
Beispiel #4
0
/** awesome global table.
 * \param L The Lua VM state.
 * \return The number of elements pushed on stack.
 * \luastack
 * \lfield font The default font.
 * \lfield font_height The default font height.
 * \lfield conffile The configuration file which has been loaded.
 */
static int
luaA_awesome_index(lua_State *L)
{
    if(luaA_usemetatable(L, 1, 2))
        return 1;

    size_t len;
    const char *buf = luaL_checklstring(L, 2, &len);

    switch(a_tokenize(buf, len))
    {
      case A_TK_FONT:
        {
            char *font = pango_font_description_to_string(globalconf.font->desc);
            lua_pushstring(L, font);
            g_free(font);
        }
        break;
      case A_TK_FONT_HEIGHT:
        lua_pushnumber(L, globalconf.font->height);
        break;
      case A_TK_CONFFILE:
        lua_pushstring(L, globalconf.conffile);
        break;
      case A_TK_FG:
        luaA_pushxcolor(L, globalconf.colors.fg);
        break;
      case A_TK_BG:
        luaA_pushxcolor(L, globalconf.colors.bg);
        break;
      case A_TK_VERSION:
        lua_pushliteral(L, AWESOME_VERSION);
        break;
      case A_TK_RELEASE:
        lua_pushliteral(L, AWESOME_RELEASE);
        break;
      case A_TK_STARTUP_ERRORS:
        if (globalconf.startup_errors.len == 0)
            return 0;
        lua_pushstring(L, globalconf.startup_errors.s);
      default:
        return 0;
    }

    return 1;
}
Beispiel #5
0
/** Tag object.
 * \param L The Lua VM state.
 * \return The number of elements pushed on stack.
 * \luastack
 * \lfield name Tag name.
 * \lfield screen Screen number of the tag.
 * \lfield layout Tag layout.
 * \lfield selected True if the client is selected to be viewed.
 * \lfield mwfact Master width factor.
 * \lfield nmaster Number of master windows.
 * \lfield ncol Number of column for slave windows.
 */
static int
luaA_tag_index(lua_State *L)
{
    size_t len;
    tag_t **tag = luaA_checkudata(L, 1, "tag");
    const char *attr;

    if(luaA_usemetatable(L, 1, 2))
        return 1;

    attr = luaL_checklstring(L, 2, &len);

    switch(a_tokenize(attr, len))
    {
      case A_TK_NAME:
        lua_pushstring(L, (*tag)->name);
        break;
      case A_TK_SCREEN:
        if((*tag)->screen == SCREEN_UNDEF)
            return 0;
        lua_pushnumber(L, (*tag)->screen + 1);
        break;
      case A_TK_LAYOUT:
        lua_pushstring(L, name_func_rlookup((*tag)->layout, LayoutList));
        break;
      case A_TK_SELECTED:
        lua_pushboolean(L, (*tag)->selected);
        break;
      case A_TK_MWFACT:
        lua_pushnumber(L, (*tag)->mwfact);
        break;
      case A_TK_NMASTER:
        lua_pushnumber(L, (*tag)->nmaster);
        break;
      case A_TK_NCOL:
        lua_pushnumber(L, (*tag)->ncol);
        break;
      default:
        return 0;
    }

    return 1;
}
Beispiel #6
0
/** Newindex function for the awesome global table.
 * \param L The Lua VM state.
 * \return The number of elements pushed on stack.
 */
static int
luaA_awesome_newindex(lua_State *L)
{
    if(luaA_usemetatable(L, 1, 2))
        return 1;

    size_t len;
    const char *buf = luaL_checklstring(L, 2, &len);

    switch(a_tokenize(buf, len))
    {
      case A_TK_FONT:
        {
            const char *newfont = luaL_checkstring(L, 3);
            draw_font_delete(&globalconf.font);
            globalconf.font = draw_font_new(newfont);
            /* refresh all wiboxes */
            foreach(wibox, globalconf.wiboxes)
                (*wibox)->need_update = true;
            foreach(c, globalconf.clients)
                if((*c)->titlebar)
                    (*c)->titlebar->need_update = true;
        }
        break;
      case A_TK_FG:
        if((buf = luaL_checklstring(L, 3, &len)))
           xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.fg, buf, len));
        break;
      case A_TK_BG:
        if((buf = luaL_checklstring(L, 3, &len)))
           xcolor_init_reply(xcolor_init_unchecked(&globalconf.colors.bg, buf, len));
        break;
      default:
        return 0;
    }

    return 0;
}
Beispiel #7
0
static int luaA_mixer_ext_get(lua_State *L) {
    mixer_ext_t *mext = luaL_checkudata(L, 1, "mixer_ext");
    if (luaA_usemetatable(L, 1, 2)) return 1;

    int value, i;
    
    if (lua_isnumber(L, 2)) {
        i = luaL_checknumber(L, 2);
        if (i < 1 || 2 < i) return 0;

        value = read_mixer(mext);
        if (format_stereo_value(L, mext, value) == 0)
            return 0;

        lua_remove(L, -i);
        return 1;
    }

    const char *index = luaL_checkstring(L, 2);
    oss_mixer_enuminfo enuminf;
    int result;

    if (strcmp(index, "type") == 0) {
        switch (mext->ext.type) {
        case MIXT_3D             : lua_pushstring(L, "3d"); break;
        case MIXT_DEVROOT        : lua_pushstring(L, "devroot"); break;
        case MIXT_ENUM           : lua_pushstring(L, "enum"); break;
        case MIXT_GROUP          : lua_pushstring(L, "group"); break;
        case MIXT_HEXVALUE       : lua_pushstring(L, "hexvalue"); break;
        case MIXT_MARKER         : lua_pushstring(L, "marker"); break;
        case MIXT_MESSAGE        : lua_pushstring(L, "message"); break;
        case MIXT_MONODB         : lua_pushstring(L, "mono db"); break;
        case MIXT_MONOPEAK       : lua_pushstring(L, "mono peak"); break;
        case MIXT_MONOSLIDER16   : lua_pushstring(L, "mono slider16"); break;
        case MIXT_MONOSLIDER     : lua_pushstring(L, "mono slider"); break;
        case MIXT_MONOVU         : lua_pushstring(L, "mono vu"); break;
        case MIXT_MUTE           : lua_pushstring(L, "mute"); break;
        case MIXT_ONOFF          : lua_pushstring(L, "switch"); break;
        case MIXT_RADIOGROUP     : lua_pushstring(L, "radio group"); break;
        /*case MIXT_ROOT           : lua_pushstring(L, "root"); break;*/
        case MIXT_SLIDER         : lua_pushstring(L, "slider"); break;
        case MIXT_STEREODB       : lua_pushstring(L, "stereo db"); break;
        case MIXT_STEREOPEAK     : lua_pushstring(L, "stereo peak"); break;
        case MIXT_STEREOSLIDER16 : lua_pushstring(L, "stereo slider16"); break;
        case MIXT_STEREOSLIDER   : lua_pushstring(L, "stereo slider"); break;
        case MIXT_STEREOVU       : lua_pushstring(L, "stereo vu"); break;
        case MIXT_VALUE          : lua_pushstring(L, "value"); break;
        default: return 0;
        }
        return 1;

    } else if (strcmp(index, "name") == 0) {
        lua_pushstring(L, mext->ext.extname);
        return 1;

    } else if (strcmp(index, "id") == 0) {
        lua_pushstring(L, mext->ext.id);
        return 1;

    } else if (strcmp(index, "value") == 0) {
        value = read_mixer(mext);
        if (value < 0) return 0;

        if (result = format_normal_value(L, mext, value));
        else if (result = format_stereo_value(L, mext, value));
        else if (result = format_mono_value(L, mext, value));
        else if (result = format_switch_value(L, mext, value));
        else if (result = format_enum_value(L, mext, value));
        else return 0;

        if (result > 1) pack_into_table(L, result);
        return 1;

    } else if (strcmp(index, "min") == 0) {
        lua_pushnumber(L, mext->ext.minvalue);
        return 1;

    } else if (strcmp(index, "max") == 0) {
        lua_pushnumber(L, mext->ext.maxvalue);
        return 1;

    } else if (strcmp(index, "color") == 0) {
        lua_pushnumber(L, mext->ext.rgbcolor);
        return 1;

    } else if (strcmp(index, "enum") == 0) {
        if (mext->ext.type != MIXT_ENUM) return 0;

        enuminf.dev = mext->ext.dev;
        enuminf.ctrl = mext->ext.ctrl;
        if (ioctl(mext->mixer->fh, SNDCTL_MIX_ENUMINFO, &enuminf) < 0) return 0;

        lua_createtable(L, mext->ext.maxvalue, 0);

        value = 0;
        for (i = 0; i < mext->ext.maxvalue; i++) {
            if (!IN_ENUM(mext->ext.enum_present, i)) continue;
            lua_pushstring(L, enuminf.strings + enuminf.strindex[i]);
            lua_rawseti(L, -2, ++value);
        }

        return 1;

    } else if (strcmp(index, "readonly") == 0) {
        lua_pushboolean(L, (mext->ext.flags & MIXF_WRITEABLE) == 0);
        return 1;
    }

    return 0;
}