/** Update the systray * \param L The Lua VM state. * \return The number of elements pushed on stack. * \luastack * \lparam The drawin to display the systray in. * \lparam x X position for the systray. * \lparam y Y position for the systray. * \lparam base_size The size (width and height) each systray item gets. * \lparam horiz If true, the systray is horizontal, else vertical. * \lparam bg Color of the systray background. * \lparam revers If true, the systray icon order will be reversed, else default. * \lparam spacing The size of the spacing between icons. */ int luaA_systray(lua_State *L) { systray_register(); if(lua_gettop(L) != 0) { size_t bg_len; drawin_t *w = luaA_checkudata(L, 1, &drawin_class); int x = luaL_checkinteger(L, 2); int y = luaL_checkinteger(L, 3); int base_size = luaL_checkinteger(L, 4); bool horiz = lua_toboolean(L, 5); const char *bg = luaL_checklstring(L, 6, &bg_len); bool revers = lua_toboolean(L, 7); int spacing = luaL_checkinteger(L, 8); color_t bg_color; if(color_init_reply(color_init_unchecked(&bg_color, bg, bg_len))) { uint32_t config_back[] = { bg_color.pixel }; xcb_change_window_attributes(globalconf.connection, globalconf.systray.window, XCB_CW_BACK_PIXEL, config_back); } if(globalconf.systray.parent != w) xcb_reparent_window(globalconf.connection, globalconf.systray.window, w->window, x, y); else { uint32_t config_vals[2] = { x, y }; xcb_configure_window(globalconf.connection, globalconf.systray.window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, config_vals); } globalconf.systray.parent = w; if(globalconf.embedded.len != 0) { systray_update(base_size, horiz, revers, spacing); xcb_map_window(globalconf.connection, globalconf.systray.window); } else xcb_unmap_window(globalconf.connection, globalconf.systray.window); } lua_pushinteger(L, globalconf.embedded.len); luaA_object_push(L, globalconf.systray.parent); return 2; }
/** 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; }
/** Set the window border color. * \param L The Lua VM state. * \param window The window object. * \return The number of elements pushed on stack. */ static int luaA_window_set_border_color(lua_State *L, window_t *window) { size_t len; const char *color_name = luaL_checklstring(L, -1, &len); if(color_name && color_init_reply(color_init_unchecked(&window->border_color, color_name, len))) { xwindow_set_border_color(window_get(window), &window->border_color); luaA_object_emit_signal(L, -3, "property::border_color", 0); } 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; }
/** Newindex function for graph widget. * \param L The Lua VM state. * \param token The key token. * \return The number of elements pushed on stack. */ static int luaA_graph_newindex(lua_State *L, awesome_token_t token) { size_t len; widget_t *widget = luaA_checkudata(L, 1, &widget_class); graph_data_t *d = widget->data; const char *buf; int width; position_t pos; color_t color; switch(token) { case A_TK_HEIGHT: d->height = luaL_checknumber(L, 3); break; case A_TK_WIDTH: width = luaL_checknumber(L, 3); if(width >= 2 && width != d->width) { d->width = width; d->size = d->width - 2; p_realloc(&d->draw_from, d->size); p_realloc(&d->draw_to, d->size); for(int i = 0; i < d->plots.len; i++) { plot_t *plot = &d->plots.tab[i]; p_realloc(&plot->values, d->size); p_realloc(&plot->lines, d->size); p_clear(plot->values, d->size); p_clear(plot->lines, d->size); plot->index = 0; plot->current_max = 0; plot->max_index = 0; } } else return 0; break; case A_TK_BG: if((buf = luaL_checklstring(L, 3, &len))) { if(color_init_reply(color_init_unchecked(&color, buf, len))) d->bg = color; else return 0; } break; case A_TK_BORDER_COLOR: if((buf = luaL_checklstring(L, 3, &len))) { if(color_init_reply(color_init_unchecked(&color, buf, len))) d->border_color = color; else return 0; } break; case A_TK_GROW: buf = luaL_checklstring(L, 3, &len); switch((pos = position_fromstr(buf, len))) { case Left: case Right: d->grow = pos; break; default: return 0; } break; default: return 0; } widget_invalidate_bywidget(widget); return 0; }