2 * button.c - button managing
4 * Copyright © 2007-2009 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "common/tokenize.h"
26 /** Create a new mouse button bindings.
27 * \param L The Lua VM state.
28 * \return The number of elements pushed on stack.
30 * \lparam A table with modifiers keys, or a button to clone.
31 * \lparam A mouse button number, or 0 to match any button.
32 * \lparam A function to execute on click events.
33 * \lparam A function to execute on release events.
34 * \lreturn A mouse button binding.
37 luaA_button_new(lua_State
*L
)
44 luaA_checktable(L
, 2);
45 /* arg 3 is mouse button */
46 xbutton
= luaL_checknumber(L
, 3);
48 /* arg 4 and 5 are callback functions, check they are functions... */
50 luaA_checkfunction(L
, 4);
52 luaA_checkfunction(L
, 5);
54 button
= button_new(L
);
56 button
->press
= luaA_object_ref_item(L
, -1, 4);
57 button
->release
= luaA_object_ref_item(L
, -1, 4);
58 button
->button
= xbutton
;
59 button
->mod
= luaA_tomodifiers(L
, 2);
65 * \param L The Lua VM state.
66 * \return The number of elements pushed on stack.
68 * \lfield press The function called when button press event is received.
69 * \lfield release The function called when button release event is received.
70 * \lfield button The mouse button number, or 0 for any button.
71 * \lfield modifiers The modifier key table that should be pressed while the
75 luaA_button_index(lua_State
*L
)
77 if(luaA_usemetatable(L
, 1, 2))
81 button_t
*button
= luaL_checkudata(L
, 1, "button");
82 const char *attr
= luaL_checklstring(L
, 2, &len
);
84 switch(a_tokenize(attr
, len
))
87 return luaA_object_push_item(L
, 1, button
->press
);
89 return luaA_object_push_item(L
, 1, button
->release
);
91 lua_pushnumber(L
, button
->button
);
94 luaA_pushmodifiers(L
, button
->mod
);
104 * \param L The Lua VM state.
105 * \return The number of elements pushed on stack.
109 luaA_button_newindex(lua_State
*L
)
111 if(luaA_usemetatable(L
, 1, 2))
115 button_t
*button
= luaL_checkudata(L
, 1, "button");
116 const char *attr
= luaL_checklstring(L
, 2, &len
);
118 switch(a_tokenize(attr
, len
))
121 luaA_checkfunction(L
, 3);
122 luaA_object_unref_item(L
, 1, button
->press
);
123 button
->press
= luaA_object_ref_item(L
, 1, 3);
126 luaA_checkfunction(L
, 3);
127 luaA_object_unref_item(L
, 1, button
->release
);
128 button
->release
= luaA_object_ref_item(L
, 1, 3);
131 button
->button
= luaL_checknumber(L
, 3);
134 button
->mod
= luaA_tomodifiers(L
, 3);
143 const struct luaL_reg awesome_button_methods
[] =
145 LUA_CLASS_METHODS(button
)
146 { "__call", luaA_button_new
},
149 const struct luaL_reg awesome_button_meta
[] =
151 LUA_OBJECT_META(button
)
152 { "__index", luaA_button_index
},
153 { "__newindex", luaA_button_newindex
},
154 { "__gc", luaA_object_gc
},
158 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80