From ef7379c983fd09d6cdb36ff8ed414be2fe33c9e7 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 1 Jul 2008 13:59:40 +0200 Subject: [PATCH] tag: remove mwfact_{get,set}, use {new,}index Signed-off-by: Julien Danjou --- awesomerc.lua.in | 2 +- common/tokenize.gperf | 1 + lib/awful.lua | 4 +-- tag.c | 64 ++++++++++++++----------------------------- 4 files changed, 25 insertions(+), 46 deletions(-) diff --git a/awesomerc.lua.in b/awesomerc.lua.in index d3f01609..c7944585 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -67,7 +67,7 @@ for s = 1, screen.count() do for tagnumber = 1, 9 do tags[s][tagnumber] = tag({ name = tagnumber, layout = layouts[1] }) -- Add tags to screen one by one - tags[s][tagnumber]:mwfact_set(0.618033988769) + tags[s][tagnumber].mwfact = 0.618033988769 tags[s][tagnumber]:add(s) end -- I'm sure you want to see at least one tag. diff --git a/common/tokenize.gperf b/common/tokenize.gperf index 5bb64a32..27de170e 100644 --- a/common/tokenize.gperf +++ b/common/tokenize.gperf @@ -21,6 +21,7 @@ height image left line +mwfact on plot_data_add plot_properties_set diff --git a/lib/awful.lua b/lib/awful.lua index 727a86c8..ad51b84f 100644 --- a/lib/awful.lua +++ b/lib/awful.lua @@ -179,7 +179,7 @@ end function P.tag.setmwfact(mwfact) local t = P.tag.selected() if t then - t:mwfact_set(mwfact) + t.mwfact = mwfact end end @@ -188,7 +188,7 @@ end function P.tag.incmwfact(add) local t = P.tag.selected() if t then - t:mwfact_set(t:mwfact_get() + add) + t.mwfact = t.mwfact + add end end diff --git a/tag.c b/tag.c index 953d0458..10c67f88 100644 --- a/tag.c +++ b/tag.c @@ -33,6 +33,8 @@ #include "layoutgen.h" +#define TAG_SCREEN_UNDEF (-1) + extern awesome_t globalconf; DO_LUA_NEW(extern, tag_t, tag, "tag", tag_ref) @@ -69,6 +71,9 @@ tag_new(const char *name, layout_t *layout, double mwfact, int nmaster, int ncol a_iso2utf8(name, &tag->name); tag->layout = layout; + /* to avoid error */ + tag->screen = TAG_SCREEN_UNDEF; + tag->mwfact = mwfact; if(tag->mwfact <= 0 || tag->mwfact >= 1) tag->mwfact = 0.5; @@ -175,7 +180,8 @@ tags_get_current(int screen) static void tag_view_only(tag_t *target) { - if (target) { + if (target) + { tag_array_t *tags = &globalconf.screens[target->screen].tags; for(int i = 0; i < tags->len; i++) @@ -333,46 +339,6 @@ luaA_tag_new(lua_State *L) return luaA_tag_userdata_new(L, tag); } -/** Set the tag master width factor. This value is used in various layouts to - * determine the size of the master window. - * \param L The Lua VM state. - * - * \luastack - * \lvalue A tag. - * \lparam The master width ratio value, between 0 and 1. - */ -static int -luaA_tag_mwfact_set(lua_State *L) -{ - tag_t **tag = luaA_checkudata(L, 1, "tag"); - double mwfact = luaL_checknumber(L, 2); - - if(mwfact < 1 && mwfact > 0) - { - (*tag)->mwfact = mwfact; - globalconf.screens[(*tag)->screen].need_arrange = true; - } - else - luaL_error(L, "bad value, must be between 0 and 1"); - - return 0; -} - -/** Get the tag master width factor. - * \param L The Lua VM state. - * - * \luastack - * \lvalue A tag. - * \lreturn The master width ratio value. - */ -static int -luaA_tag_mwfact_get(lua_State *L) -{ - tag_t **tag = luaA_checkudata(L, 1, "tag"); - lua_pushnumber(L, (*tag)->mwfact); - return 1; -} - /** Set the number of columns. This is used in various layouts to set the number * of columns used to display non-master windows. * \param L The Lua VM state. @@ -555,6 +521,9 @@ luaA_tag_index(lua_State *L) case A_TK_SELECTED: lua_pushboolean(L, (*tag)->selected); break; + case A_TK_MWFACT: + lua_pushnumber(L, (*tag)->mwfact); + break; default: return 0; } @@ -572,16 +541,27 @@ luaA_tag_newindex(lua_State *L) size_t len; tag_t **tag = luaA_checkudata(L, 1, "tag"); const char *attr = luaL_checklstring(L, 2, &len); + double d; switch(a_tokenize(attr, len)) { case A_TK_SELECTED: 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 + luaL_error(L, "bad value, must be between 0 and 1"); break; default: return 0; } + if((*tag)->screen != TAG_SCREEN_UNDEF) + globalconf.screens[(*tag)->screen].need_arrange = true; + return 0; } @@ -596,8 +576,6 @@ const struct luaL_reg awesome_tag_methods[] = const struct luaL_reg awesome_tag_meta[] = { { "add", luaA_tag_add }, - { "mwfact_set", luaA_tag_mwfact_set }, - { "mwfact_get", luaA_tag_mwfact_get }, { "ncol_set", luaA_tag_ncol_set }, { "ncol_get", luaA_tag_ncol_get }, { "nmaster_set", luaA_tag_nmaster_set },