/** 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; }
/** Send fake events. Usually the current focused client will get it. * \param L The Lua VM state. * \return The number of element pushed on stack. * \luastack * \lparam The event type: key_press, key_release, button_press, button_release * or motion_notify. * \lparam The detail: in case of a key event, this is the keycode to send, in * case of a button event this is the number of the button. In case of a motion * event, this is a boolean value which if true make the coordinates relatives. * \lparam In case of a motion event, this is the X coordinate. * \lparam In case of a motion event, this is the Y coordinate. * \lparam In case of a motion event, this is the screen number to move on. * If not specified, the current one is used. */ static int luaA_root_fake_input(lua_State *L) { if(!globalconf.have_xtest) { luaA_warn(L, "XTest extension is not available, cannot fake input."); return 0; } size_t tlen; const char *stype = luaL_checklstring(L, 1, &tlen); uint8_t type, detail; int x = 0, y = 0; xcb_window_t root = XCB_NONE; switch(a_tokenize(stype, tlen)) { case A_TK_KEY_PRESS: type = XCB_KEY_PRESS; detail = luaL_checknumber(L, 2); /* keycode */ break; case A_TK_KEY_RELEASE: type = XCB_KEY_RELEASE; detail = luaL_checknumber(L, 2); /* keycode */ break; case A_TK_BUTTON_PRESS: type = XCB_BUTTON_PRESS; detail = luaL_checknumber(L, 2); /* button number */ break; case A_TK_BUTTON_RELEASE: type = XCB_BUTTON_RELEASE; detail = luaL_checknumber(L, 2); /* button number */ break; case A_TK_MOTION_NOTIFY: type = XCB_MOTION_NOTIFY; detail = luaA_checkboolean(L, 2); /* relative to the current position or not */ x = luaL_checknumber(L, 3); y = luaL_checknumber(L, 4); if(lua_gettop(L) == 5 && !globalconf.xinerama_is_active) { int screen = luaL_checknumber(L, 5) - 1; luaA_checkscreen(screen); root = xutil_screen_get(globalconf.connection, screen)->root; } break; default: return 0; } xcb_test_fake_input(globalconf.connection, type, detail, XCB_CURRENT_TIME, root, x, y, 0); return 0; }
/** Set various plot graph properties. * \param L The Lua VM state. * \return The number of elements pushed on stack. * \luastack * \lvalue A widget. * \lparam A plot name. * \lparam A table with various properties set. */ static int luaA_graph_plot_properties_set(lua_State *L) { widget_t *widget = luaA_checkudata(L, 1, &widget_class); graph_data_t *d = widget->data; float max_value; const char *title, *buf; size_t len; plot_t *plot = NULL; color_init_cookie_t reqs[3]; int i, reqs_nbr = -1; title = luaL_checkstring(L, 2); luaA_checktable(L, 3); plot = graph_plot_get(d, title); if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len))) reqs[++reqs_nbr] = color_init_unchecked(&plot->color_start, buf, len); if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len))) reqs[++reqs_nbr] = color_init_unchecked(&plot->pcolor_center, buf, len); if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len))) reqs[++reqs_nbr] = color_init_unchecked(&plot->pcolor_end, buf, len); plot->vertical_gradient = luaA_getopt_boolean(L, 3, "vertical_gradient", plot->vertical_gradient); plot->scale = luaA_getopt_boolean(L, 3, "scale", plot->scale); max_value = luaA_getopt_number(L, 3, "max_value", plot->max_value); if(max_value != plot->max_value) plot->max_value = plot->current_max = max_value; if((buf = luaA_getopt_lstring(L, 3, "style", NULL, &len))) switch (a_tokenize(buf, len)) { case A_TK_BOTTOM: plot->draw_style = Bottom_Style; break; case A_TK_LINE: plot->draw_style = Line_Style; break; case A_TK_TOP: plot->draw_style = Top_Style; break; default: break; } for(i = 0; i <= reqs_nbr; i++) color_init_reply(reqs[i]); widget_invalidate_bywidget(widget); return 0; }
/** Get a orientation type from a string. * \param pos The orientation. * \param len The string length, -1 if unknown. * \return A orientation. */ orientation_t orientation_fromstr(const char *pos, ssize_t len) { switch(a_tokenize(pos, len)) { default: return North; case A_TK_SOUTH: return South; case A_TK_EAST: return East; } }
/** Tag newindex. * \param L The Lua VM state. * \return The number of elements pushed on stack. */ static int luaA_tag_newindex(lua_State *L) { size_t len; tag_t *tag = luaL_checkudata(L, 1, "tag"); const char *attr = luaL_checklstring(L, 2, &len); switch(a_tokenize(attr, len)) { int screen; case A_TK_NAME: { const char *buf = luaL_checklstring(L, 3, &len); p_delete(&tag->name); a_iso2utf8(buf, len, &tag->name, NULL); } break; case A_TK_SCREEN: if(!lua_isnil(L, 3)) { screen = luaL_checknumber(L, 3) - 1; luaA_checkscreen(screen); } else screen = SCREEN_UNDEF; if(tag->screen != SCREEN_UNDEF) tag_remove_from_screen(tag); if(screen != SCREEN_UNDEF) { /* push tag on top of the stack */ lua_pushvalue(L, 1); tag_append_to_screen(&globalconf.screens[screen]); } break; case A_TK_SELECTED: if(tag->screen != SCREEN_UNDEF) tag_view(tag, luaA_checkboolean(L, 3)); return 0; default: return 0; } if(tag->screen != SCREEN_UNDEF && tag->selected) globalconf.screens[tag->screen].need_arrange = true; return 0; }
/** Get a position type from a string. * \param pos The position. * \param len The string length, -1 if unknown. * \return A position. */ position_t position_fromstr(const char *pos, ssize_t len) { switch(a_tokenize(pos, len)) { default: return Top; case A_TK_BOTTOM: return Bottom; case A_TK_RIGHT: return Right; case A_TK_LEFT: return Left; } }
/** 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; }
/** 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; }
/** Index function of wtable objects. * \param L The Lua VM state. * \return The number of elements pushed on stack. */ static int luaA_wtable_index(lua_State *L) { size_t len; const char *buf; lua_pushvalue(L, 2); /* check for size, waiting lua 5.2 and __len on tables */ if((buf = lua_tolstring(L, -1, &len))) if(a_tokenize(buf, len) == A_TK_LEN) { lua_pushnumber(L, lua_objlen(L, lua_upvalueindex(1))); return 1; } lua_pop(L, 1); /* upvalue 1 is content table */ lua_rawget(L, lua_upvalueindex(1)); return 1; }
/** 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; }
/** Tag newindex. * \param L The Lua VM state. * \return The number of elements pushed on stack. */ static int luaA_tag_newindex(lua_State *L) { size_t len; tag_t **tag = luaA_checkudata(L, 1, "tag"); const char *buf, *attr = luaL_checklstring(L, 2, &len); double d; int i, screen; layout_t *l; switch(a_tokenize(attr, len)) { case A_TK_NAME: buf = luaL_checklstring(L, 3, &len); p_delete(&(*tag)->name); a_iso2utf8(&(*tag)->name, buf, len); break; case A_TK_SCREEN: if(!lua_isnil(L, 3)) { screen = luaL_checknumber(L, 3) - 1; luaA_checkscreen(screen); } else screen = SCREEN_UNDEF; if((*tag)->screen != SCREEN_UNDEF) tag_remove_from_screen(*tag); if(screen != SCREEN_UNDEF) tag_append_to_screen(*tag, &globalconf.screens[screen]); break; case A_TK_LAYOUT: buf = luaL_checkstring(L, 3); l = name_func_lookup(buf, LayoutList); if(l) (*tag)->layout = l; else { luaA_warn(L, "unknown layout: %s", buf); return 0; } break; case A_TK_SELECTED: if((*tag)->screen != SCREEN_UNDEF) tag_view(*tag, luaA_checkboolean(L, 3)); return 0; case A_TK_MWFACT: d = luaL_checknumber(L, 3); if(d > 0 && d < 1) (*tag)->mwfact = d; else { luaA_warn(L, "bad value, must be between 0 and 1"); return 0; } break; case A_TK_NMASTER: i = luaL_checknumber(L, 3); if(i >= 0) (*tag)->nmaster = i; else { luaA_warn(L, "bad value, must be greater than 0"); return 0; } break; case A_TK_NCOL: i = luaL_checknumber(L, 3); if(i >= 1) (*tag)->ncol = i; else { luaA_warn(L, "bad value, must be greater than 1"); return 0; } break; default: return 0; } if((*tag)->screen != SCREEN_UNDEF && (*tag)->selected) globalconf.screens[(*tag)->screen].need_arrange = true; return 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; }