2009-09-30 16:04:42 +02:00
|
|
|
/*
|
|
|
|
* window.c - window object
|
|
|
|
*
|
|
|
|
* Copyright © 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "luaa.h"
|
|
|
|
#include "xwindow.h"
|
2009-10-01 16:36:46 +02:00
|
|
|
#include "ewmh.h"
|
|
|
|
#include "screen.h"
|
2009-09-30 16:04:42 +02:00
|
|
|
#include "objects/window.h"
|
|
|
|
#include "common/luaobject.h"
|
|
|
|
|
|
|
|
LUA_CLASS_FUNCS(window, window_class)
|
|
|
|
|
2010-07-30 20:54:20 +02:00
|
|
|
static xcb_window_t
|
|
|
|
window_get(window_t *window)
|
|
|
|
{
|
|
|
|
if (window->frame_window != XCB_NONE)
|
|
|
|
return window->frame_window;
|
|
|
|
return window->window;
|
|
|
|
}
|
|
|
|
|
2009-10-02 16:16:34 +02:00
|
|
|
static void
|
|
|
|
window_wipe(window_t *window)
|
|
|
|
{
|
|
|
|
button_array_wipe(&window->buttons);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get or set mouse buttons bindings on a window.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on the stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_window_buttons(lua_State *L)
|
|
|
|
{
|
|
|
|
window_t *window = luaA_checkudata(L, 1, &window_class);
|
|
|
|
|
|
|
|
if(lua_gettop(L) == 2)
|
|
|
|
{
|
|
|
|
luaA_button_array_set(L, 1, 2, &window->buttons);
|
|
|
|
luaA_object_emit_signal(L, 1, "property::buttons", 0);
|
2010-07-30 20:54:20 +02:00
|
|
|
xwindow_buttons_grab(window_get(window), &window->buttons);
|
2009-10-02 16:16:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return luaA_button_array_get(L, 1, &window->buttons);
|
|
|
|
}
|
|
|
|
|
2009-10-01 16:36:46 +02:00
|
|
|
/** Return window struts (reserved space at the edge of the screen).
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_window_struts(lua_State *L)
|
|
|
|
{
|
|
|
|
window_t *window = luaA_checkudata(L, 1, &window_class);
|
|
|
|
|
|
|
|
if(lua_gettop(L) == 2)
|
|
|
|
{
|
|
|
|
luaA_tostrut(L, 2, &window->strut);
|
|
|
|
ewmh_update_strut(window->window, &window->strut);
|
|
|
|
luaA_object_emit_signal(L, 1, "property::struts", 0);
|
|
|
|
if(window->screen)
|
|
|
|
screen_emit_signal(L, window->screen, "property::workarea", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return luaA_pushstrut(L, window->strut);
|
|
|
|
}
|
|
|
|
|
2009-09-30 16:04:42 +02:00
|
|
|
/** Set a window opacity.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param idx The index of the window on the stack.
|
|
|
|
* \param opacity The opacity value.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
window_set_opacity(lua_State *L, int idx, double opacity)
|
|
|
|
{
|
|
|
|
window_t *window = luaA_checkudata(L, idx, &window_class);
|
|
|
|
|
|
|
|
if(window->opacity != opacity)
|
|
|
|
{
|
|
|
|
window->opacity = opacity;
|
2010-07-30 20:54:20 +02:00
|
|
|
xwindow_set_opacity(window_get(window), opacity);
|
2009-09-30 16:04:42 +02:00
|
|
|
luaA_object_emit_signal(L, idx, "property::opacity", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set a window opacity.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param window The window object.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_window_set_opacity(lua_State *L, window_t *window)
|
|
|
|
{
|
|
|
|
if(lua_isnil(L, -1))
|
|
|
|
window_set_opacity(L, -3, -1);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double d = luaL_checknumber(L, -1);
|
|
|
|
if(d >= 0 && d <= 1)
|
|
|
|
window_set_opacity(L, -3, d);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the window opacity.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param window The window object.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_window_get_opacity(lua_State *L, window_t *window)
|
|
|
|
{
|
|
|
|
if(window->opacity >= 0)
|
|
|
|
{
|
|
|
|
lua_pushnumber(L, window->opacity);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-02 16:42:31 +02:00
|
|
|
/** Set the window border color.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param window The window object.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_window_set_border_color(lua_State *L, window_t *window)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const char *color_name = luaL_checklstring(L, -1, &len);
|
|
|
|
|
|
|
|
if(color_name &&
|
|
|
|
xcolor_init_reply(xcolor_init_unchecked(&window->border_color, color_name, len)))
|
|
|
|
{
|
2010-07-30 20:54:20 +02:00
|
|
|
xwindow_set_border_color(window_get(window), &window->border_color);
|
2009-10-02 16:42:31 +02:00
|
|
|
luaA_object_emit_signal(L, -3, "property::border_color", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-06 19:04:36 +02:00
|
|
|
/** Set a window border width.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param idx The window index.
|
|
|
|
* \param width The border width.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
window_set_border_width(lua_State *L, int idx, int width)
|
|
|
|
{
|
|
|
|
window_t *window = luaA_checkudata(L, idx, &window_class);
|
|
|
|
|
|
|
|
if(width == window->border_width || width < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(window->window)
|
2010-07-30 20:54:20 +02:00
|
|
|
xcb_configure_window(globalconf.connection, window_get(window),
|
2009-10-06 19:04:36 +02:00
|
|
|
XCB_CONFIG_WINDOW_BORDER_WIDTH,
|
|
|
|
(uint32_t[]) { width });
|
|
|
|
|
|
|
|
window->border_width = width;
|
|
|
|
|
|
|
|
luaA_object_emit_signal(L, idx, "property::border_width", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
luaA_window_set_border_width(lua_State *L, window_t *c)
|
|
|
|
{
|
|
|
|
window_set_border_width(L, -3, luaL_checknumber(L, -1));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-30 16:04:42 +02:00
|
|
|
LUA_OBJECT_EXPORT_PROPERTY(window, window_t, window, lua_pushnumber)
|
2009-10-02 16:42:31 +02:00
|
|
|
LUA_OBJECT_EXPORT_PROPERTY(window, window_t, border_color, luaA_pushxcolor)
|
2009-10-06 19:04:36 +02:00
|
|
|
LUA_OBJECT_EXPORT_PROPERTY(window, window_t, border_width, lua_pushnumber)
|
2009-09-30 16:04:42 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
window_class_setup(lua_State *L)
|
|
|
|
{
|
|
|
|
static const struct luaL_reg window_methods[] =
|
|
|
|
{
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct luaL_reg window_meta[] =
|
|
|
|
{
|
2009-10-01 16:36:46 +02:00
|
|
|
{ "struts", luaA_window_struts },
|
2009-10-02 16:16:34 +02:00
|
|
|
{ "buttons", luaA_window_buttons },
|
2009-09-30 16:04:42 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
luaA_class_setup(L, &window_class, "window", NULL,
|
2009-10-02 16:16:34 +02:00
|
|
|
NULL, (lua_class_collector_t) window_wipe, NULL,
|
2009-09-30 16:04:42 +02:00
|
|
|
luaA_class_index_miss_property, luaA_class_newindex_miss_property,
|
|
|
|
window_methods, window_meta);
|
|
|
|
|
2010-09-01 15:41:41 +02:00
|
|
|
luaA_class_add_property(&window_class, "window",
|
2009-09-30 16:04:42 +02:00
|
|
|
NULL,
|
|
|
|
(lua_class_propfunc_t) luaA_window_get_window,
|
|
|
|
NULL);
|
2010-09-01 15:41:41 +02:00
|
|
|
luaA_class_add_property(&window_class, "opacity",
|
2009-09-30 16:04:42 +02:00
|
|
|
(lua_class_propfunc_t) luaA_window_set_opacity,
|
|
|
|
(lua_class_propfunc_t) luaA_window_get_opacity,
|
|
|
|
(lua_class_propfunc_t) luaA_window_set_opacity);
|
2010-09-01 15:41:41 +02:00
|
|
|
luaA_class_add_property(&window_class, "border_color",
|
2009-10-02 16:42:31 +02:00
|
|
|
(lua_class_propfunc_t) luaA_window_set_border_color,
|
|
|
|
(lua_class_propfunc_t) luaA_window_get_border_color,
|
|
|
|
(lua_class_propfunc_t) luaA_window_set_border_color);
|
2010-09-01 15:41:41 +02:00
|
|
|
luaA_class_add_property(&window_class, "border_width",
|
2009-10-06 19:04:36 +02:00
|
|
|
(lua_class_propfunc_t) luaA_window_set_border_width,
|
|
|
|
(lua_class_propfunc_t) luaA_window_get_border_width,
|
|
|
|
(lua_class_propfunc_t) luaA_window_set_border_width);
|
2010-08-25 23:00:36 +02:00
|
|
|
|
|
|
|
signal_add(&window_class.signals, "property::border_color");
|
|
|
|
signal_add(&window_class.signals, "property::border_width");
|
|
|
|
signal_add(&window_class.signals, "property::buttons");
|
|
|
|
signal_add(&window_class.signals, "property::opacity");
|
2010-08-26 17:46:17 +02:00
|
|
|
signal_add(&window_class.signals, "property::struts");
|
2009-09-30 16:04:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|