forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.c
186 lines (161 loc) · 5.4 KB
/
button.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* button.c - button managing
*
* Copyright © 2007-2009 Julien Danjou <[email protected]>
*
* 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.
*
*/
/** 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 <[email protected]>
* @copyright 2008-2009 Julien Danjou
* @coreclassmod button
*/
#include "button.h"
lua_class_t button_class;
/** 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.
* @staticfct instances
*/
/** Set a __index metamethod for all button instances.
* @tparam function cb The meta-method
* @staticfct set_index_miss_handler
*/
/** Set a __newindex metamethod for all button instances.
* @tparam function cb The meta-method
* @staticfct set_newindex_miss_handler
*/
/** When bound mouse button + modifiers are pressed.
* @param ... One or more arguments are possible
* @signal press
*/
/** When property changes.
* @signal property::button
*/
/** When property changes.
* @signal property::modifiers
*/
/** When bound mouse button + modifiers are pressed.
* @param ... One or more arguments are possible
* @signal release
*/
/** 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)
{
return luaA_class_new(L, &button_class);
}
/** 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))
if(luaA_toudata(L, -1, &button_class))
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;
}
LUA_OBJECT_EXPORT_PROPERTY(button, button_t, button, lua_pushinteger);
LUA_OBJECT_EXPORT_PROPERTY(button, button_t, modifiers, luaA_pushmodifiers);
static int
luaA_button_set_modifiers(lua_State *L, button_t *b)
{
b->modifiers = luaA_tomodifiers(L, -1);
luaA_object_emit_signal(L, -3, "property::modifiers", 0);
return 0;
}
static int
luaA_button_set_button(lua_State *L, button_t *b)
{
b->button = luaL_checkinteger(L, -1);
luaA_object_emit_signal(L, -3, "property::button", 0);
return 0;
}
void
button_class_setup(lua_State *L)
{
static const struct luaL_Reg button_methods[] =
{
LUA_CLASS_METHODS(button)
{ "__call", luaA_button_new },
{ NULL, NULL }
};
static const struct luaL_Reg button_meta[] =
{
LUA_OBJECT_META(button)
LUA_CLASS_META
{ NULL, NULL }
};
luaA_class_setup(L, &button_class, "button", NULL,
(lua_class_allocator_t) button_new, NULL, NULL,
luaA_class_index_miss_property, luaA_class_newindex_miss_property,
button_methods, button_meta);
luaA_class_add_property(&button_class, "button",
(lua_class_propfunc_t) luaA_button_set_button,
(lua_class_propfunc_t) luaA_button_get_button,
(lua_class_propfunc_t) luaA_button_set_button);
luaA_class_add_property(&button_class, "modifiers",
(lua_class_propfunc_t) luaA_button_set_modifiers,
(lua_class_propfunc_t) luaA_button_get_modifiers,
(lua_class_propfunc_t) luaA_button_set_modifiers);
}
/* @DOC_cobject_COMMON@ */
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80