2009-04-26 10:46:09 +02:00
|
|
|
/*
|
|
|
|
* button.c - button managing
|
|
|
|
*
|
|
|
|
* Copyright © 2007-2009 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-02-27 00:24:23 +01:00
|
|
|
/** awesome button API
|
|
|
|
*
|
|
|
|
* Furthermore to the classes described here, one can also use signals as
|
|
|
|
* described in @{signals}.
|
|
|
|
*
|
|
|
|
* Some signal names are starting with a dot. These dots are artefacts from
|
|
|
|
* the documentation generation, you get the real signal name by
|
|
|
|
* removing the starting dot.
|
|
|
|
*
|
|
|
|
* @author Julien Danjou <julien@danjou.info>
|
|
|
|
* @copyright 2008-2009 Julien Danjou
|
|
|
|
* @release @AWESOME_VERSION@
|
|
|
|
* @classmod button
|
|
|
|
*/
|
|
|
|
|
2009-04-26 10:46:09 +02:00
|
|
|
#include "button.h"
|
|
|
|
|
2015-02-27 00:24:23 +01:00
|
|
|
/** Button object.
|
|
|
|
*
|
|
|
|
* @tfield int button The mouse button number, or 0 for any button.
|
|
|
|
* @tfield table modifiers The modifier key table that should be pressed while the
|
|
|
|
* button is pressed.
|
|
|
|
* @table button
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Get the number of instances.
|
|
|
|
* @treturn int The number of button objects alive.
|
|
|
|
* @function instances
|
|
|
|
*/
|
|
|
|
|
2015-03-14 10:06:53 +01:00
|
|
|
/** Set a __index metamethod for all button instances.
|
|
|
|
* @tparam function cb The meta-method
|
|
|
|
* @function set_index_miss_handler
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Set a __newindex metamethod for all button instances.
|
|
|
|
* @tparam function cb The meta-method
|
|
|
|
* @function set_newindex_miss_handler
|
|
|
|
*/
|
|
|
|
|
2009-04-26 10:46:09 +02:00
|
|
|
/** Create a new mouse button bindings.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_button_new(lua_State *L)
|
|
|
|
{
|
2009-08-17 14:10:03 +02:00
|
|
|
return luaA_class_new(L, &button_class);
|
2009-04-26 10:46:09 +02:00
|
|
|
}
|
|
|
|
|
2009-08-14 16:46:35 +02:00
|
|
|
/** Set a button array with a Lua table.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param oidx The index of the object to store items into.
|
|
|
|
* \param idx The index of the Lua table.
|
|
|
|
* \param buttons The array button to fill.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
luaA_button_array_set(lua_State *L, int oidx, int idx, button_array_t *buttons)
|
|
|
|
{
|
|
|
|
luaA_checktable(L, idx);
|
|
|
|
|
|
|
|
foreach(button, *buttons)
|
|
|
|
luaA_object_unref_item(L, oidx, *button);
|
|
|
|
|
|
|
|
button_array_wipe(buttons);
|
|
|
|
button_array_init(buttons);
|
|
|
|
|
|
|
|
lua_pushnil(L);
|
|
|
|
while(lua_next(L, idx))
|
2009-08-17 15:52:41 +02:00
|
|
|
if(luaA_toudata(L, -1, &button_class))
|
2009-08-14 16:46:35 +02:00
|
|
|
button_array_append(buttons, luaA_object_ref_item(L, oidx, -1));
|
|
|
|
else
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Push an array of button as an Lua table onto the stack.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param oidx The index of the object to get items from.
|
|
|
|
* \param buttons The button array to push.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_button_array_get(lua_State *L, int oidx, button_array_t *buttons)
|
|
|
|
{
|
|
|
|
lua_createtable(L, buttons->len, 0);
|
|
|
|
for(int i = 0; i < buttons->len; i++)
|
|
|
|
{
|
|
|
|
luaA_object_push_item(L, oidx, buttons->tab[i]);
|
|
|
|
lua_rawseti(L, -2, i + 1);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-02-06 13:46:46 +01:00
|
|
|
LUA_OBJECT_EXPORT_PROPERTY(button, button_t, button, lua_pushinteger);
|
2009-08-17 14:10:03 +02:00
|
|
|
LUA_OBJECT_EXPORT_PROPERTY(button, button_t, modifiers, luaA_pushmodifiers);
|
|
|
|
|
2009-04-26 10:46:09 +02:00
|
|
|
static int
|
2009-08-17 14:10:03 +02:00
|
|
|
luaA_button_set_modifiers(lua_State *L, button_t *b)
|
2009-04-26 10:46:09 +02:00
|
|
|
{
|
2009-08-17 14:10:03 +02:00
|
|
|
b->modifiers = luaA_tomodifiers(L, -1);
|
|
|
|
luaA_object_emit_signal(L, -3, "property::modifiers", 0);
|
|
|
|
return 0;
|
2009-04-26 10:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-17 14:10:03 +02:00
|
|
|
luaA_button_set_button(lua_State *L, button_t *b)
|
2009-04-26 10:46:09 +02:00
|
|
|
{
|
2016-02-06 13:59:14 +01:00
|
|
|
b->button = luaL_checkinteger(L, -1);
|
2009-08-17 14:10:03 +02:00
|
|
|
luaA_object_emit_signal(L, -3, "property::button", 0);
|
2009-04-26 10:46:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-17 14:10:03 +02:00
|
|
|
void
|
|
|
|
button_class_setup(lua_State *L)
|
2009-04-26 10:46:09 +02:00
|
|
|
{
|
2012-06-06 23:07:07 +02:00
|
|
|
static const struct luaL_Reg button_methods[] =
|
2009-08-17 14:10:03 +02:00
|
|
|
{
|
|
|
|
LUA_CLASS_METHODS(button)
|
|
|
|
{ "__call", luaA_button_new },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2012-06-06 23:07:07 +02:00
|
|
|
static const struct luaL_Reg button_meta[] =
|
2009-08-17 14:10:03 +02:00
|
|
|
{
|
|
|
|
LUA_OBJECT_META(button)
|
|
|
|
LUA_CLASS_META
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2009-09-30 14:21:25 +02:00
|
|
|
luaA_class_setup(L, &button_class, "button", NULL,
|
2009-10-02 15:48:32 +02:00
|
|
|
(lua_class_allocator_t) button_new, NULL, NULL,
|
2009-08-20 17:37:46 +02:00
|
|
|
luaA_class_index_miss_property, luaA_class_newindex_miss_property,
|
2009-08-17 14:10:03 +02:00
|
|
|
button_methods, button_meta);
|
2010-09-01 15:41:41 +02:00
|
|
|
luaA_class_add_property(&button_class, "button",
|
2009-08-17 14:10:03 +02:00
|
|
|
(lua_class_propfunc_t) luaA_button_set_button,
|
|
|
|
(lua_class_propfunc_t) luaA_button_get_button,
|
|
|
|
(lua_class_propfunc_t) luaA_button_set_button);
|
2010-09-01 15:41:41 +02:00
|
|
|
luaA_class_add_property(&button_class, "modifiers",
|
2009-08-17 14:10:03 +02:00
|
|
|
(lua_class_propfunc_t) luaA_button_set_modifiers,
|
|
|
|
(lua_class_propfunc_t) luaA_button_get_modifiers,
|
|
|
|
(lua_class_propfunc_t) luaA_button_set_modifiers);
|
2010-08-25 23:00:36 +02:00
|
|
|
|
2015-02-27 00:24:23 +01:00
|
|
|
/** When bound mouse button + modifiers are pressed.
|
|
|
|
* @param ... One or more arguments are possible
|
|
|
|
* @signal .press
|
|
|
|
*/
|
2010-08-25 23:00:36 +02:00
|
|
|
signal_add(&button_class.signals, "press");
|
2015-02-27 00:24:23 +01:00
|
|
|
/** When property changes.
|
|
|
|
* @signal property::button
|
|
|
|
*/
|
2010-08-26 17:46:17 +02:00
|
|
|
signal_add(&button_class.signals, "property::button");
|
2015-02-27 00:24:23 +01:00
|
|
|
/** When property changes.
|
|
|
|
* @signal property::modifiers
|
|
|
|
*/
|
2010-08-26 17:46:17 +02:00
|
|
|
signal_add(&button_class.signals, "property::modifiers");
|
2015-02-27 00:24:23 +01:00
|
|
|
/** When bound mouse button + modifiers are pressed.
|
|
|
|
* @param ... One or more arguments are possible
|
|
|
|
* @signal .release
|
|
|
|
*/
|
2010-08-25 23:00:36 +02:00
|
|
|
signal_add(&button_class.signals, "release");
|
2009-08-17 14:10:03 +02:00
|
|
|
}
|
2009-04-26 10:46:09 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|