tag: remove mwfact_{get,set}, use {new,}index

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-01 13:59:40 +02:00
parent f750124d5c
commit ef7379c983
4 changed files with 25 additions and 46 deletions

View File

@ -67,7 +67,7 @@ for s = 1, screen.count() do
for tagnumber = 1, 9 do for tagnumber = 1, 9 do
tags[s][tagnumber] = tag({ name = tagnumber, layout = layouts[1] }) tags[s][tagnumber] = tag({ name = tagnumber, layout = layouts[1] })
-- Add tags to screen one by one -- 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) tags[s][tagnumber]:add(s)
end end
-- I'm sure you want to see at least one tag. -- I'm sure you want to see at least one tag.

View File

@ -21,6 +21,7 @@ height
image image
left left
line line
mwfact
on on
plot_data_add plot_data_add
plot_properties_set plot_properties_set

View File

@ -179,7 +179,7 @@ end
function P.tag.setmwfact(mwfact) function P.tag.setmwfact(mwfact)
local t = P.tag.selected() local t = P.tag.selected()
if t then if t then
t:mwfact_set(mwfact) t.mwfact = mwfact
end end
end end
@ -188,7 +188,7 @@ end
function P.tag.incmwfact(add) function P.tag.incmwfact(add)
local t = P.tag.selected() local t = P.tag.selected()
if t then if t then
t:mwfact_set(t:mwfact_get() + add) t.mwfact = t.mwfact + add
end end
end end

64
tag.c
View File

@ -33,6 +33,8 @@
#include "layoutgen.h" #include "layoutgen.h"
#define TAG_SCREEN_UNDEF (-1)
extern awesome_t globalconf; extern awesome_t globalconf;
DO_LUA_NEW(extern, tag_t, tag, "tag", tag_ref) 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); a_iso2utf8(name, &tag->name);
tag->layout = layout; tag->layout = layout;
/* to avoid error */
tag->screen = TAG_SCREEN_UNDEF;
tag->mwfact = mwfact; tag->mwfact = mwfact;
if(tag->mwfact <= 0 || tag->mwfact >= 1) if(tag->mwfact <= 0 || tag->mwfact >= 1)
tag->mwfact = 0.5; tag->mwfact = 0.5;
@ -175,7 +180,8 @@ tags_get_current(int screen)
static void static void
tag_view_only(tag_t *target) tag_view_only(tag_t *target)
{ {
if (target) { if (target)
{
tag_array_t *tags = &globalconf.screens[target->screen].tags; tag_array_t *tags = &globalconf.screens[target->screen].tags;
for(int i = 0; i < tags->len; i++) 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); 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 /** Set the number of columns. This is used in various layouts to set the number
* of columns used to display non-master windows. * of columns used to display non-master windows.
* \param L The Lua VM state. * \param L The Lua VM state.
@ -555,6 +521,9 @@ luaA_tag_index(lua_State *L)
case A_TK_SELECTED: case A_TK_SELECTED:
lua_pushboolean(L, (*tag)->selected); lua_pushboolean(L, (*tag)->selected);
break; break;
case A_TK_MWFACT:
lua_pushnumber(L, (*tag)->mwfact);
break;
default: default:
return 0; return 0;
} }
@ -572,16 +541,27 @@ luaA_tag_newindex(lua_State *L)
size_t len; size_t len;
tag_t **tag = luaA_checkudata(L, 1, "tag"); tag_t **tag = luaA_checkudata(L, 1, "tag");
const char *attr = luaL_checklstring(L, 2, &len); const char *attr = luaL_checklstring(L, 2, &len);
double d;
switch(a_tokenize(attr, len)) switch(a_tokenize(attr, len))
{ {
case A_TK_SELECTED: case A_TK_SELECTED:
tag_view(*tag, luaA_checkboolean(L, 3)); 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; break;
default: default:
return 0; return 0;
} }
if((*tag)->screen != TAG_SCREEN_UNDEF)
globalconf.screens[(*tag)->screen].need_arrange = true;
return 0; return 0;
} }
@ -596,8 +576,6 @@ const struct luaL_reg awesome_tag_methods[] =
const struct luaL_reg awesome_tag_meta[] = const struct luaL_reg awesome_tag_meta[] =
{ {
{ "add", luaA_tag_add }, { "add", luaA_tag_add },
{ "mwfact_set", luaA_tag_mwfact_set },
{ "mwfact_get", luaA_tag_mwfact_get },
{ "ncol_set", luaA_tag_ncol_set }, { "ncol_set", luaA_tag_ncol_set },
{ "ncol_get", luaA_tag_ncol_get }, { "ncol_get", luaA_tag_ncol_get },
{ "nmaster_set", luaA_tag_nmaster_set }, { "nmaster_set", luaA_tag_nmaster_set },