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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-02-27 00:24:23 +01:00
|
|
|
/** Handling of X properties.
|
|
|
|
*
|
|
|
|
* This can not be used as a standalone class, but is instead referenced
|
|
|
|
* explicitely in the classes, where it can be used. In the respective
|
|
|
|
* classes,it then can be used via `classname:get_xproperty(...)` etc.
|
|
|
|
* @classmod xproperties
|
|
|
|
*/
|
|
|
|
|
2016-06-04 17:39:14 +02:00
|
|
|
/**
|
|
|
|
* @signal property::border_color
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @signal property::border_width
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @signal property::buttons
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @signal property::opacity
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @signal property::struts
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @signal property::type
|
|
|
|
*/
|
|
|
|
|
2009-09-30 16:04:42 +02:00
|
|
|
#include "objects/window.h"
|
2010-09-27 22:03:34 +02:00
|
|
|
#include "common/atoms.h"
|
2016-04-17 13:44:05 +02:00
|
|
|
#include "common/xutil.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "ewmh.h"
|
2016-05-08 16:30:37 +02:00
|
|
|
#include "objects/screen.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "property.h"
|
|
|
|
#include "xwindow.h"
|
2009-09-30 16:04:42 +02:00
|
|
|
|
|
|
|
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);
|
2016-05-08 17:30:01 +02:00
|
|
|
xwindow_buttons_grab(window->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);
|
2016-05-08 16:30:37 +02:00
|
|
|
/* We don't know the correct screen, update them all */
|
2011-03-27 16:21:49 +02:00
|
|
|
foreach(s, globalconf.screens)
|
2016-05-08 16:30:37 +02:00
|
|
|
screen_update_workarea(*s);
|
2009-10-01 16:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2012-10-19 13:10:13 +02:00
|
|
|
else
|
|
|
|
/* Let's always return some "good" value */
|
|
|
|
lua_pushnumber(L, 1);
|
|
|
|
return 1;
|
2009-09-30 16:04:42 +02:00
|
|
|
}
|
|
|
|
|
2016-02-28 16:24:30 +01:00
|
|
|
void
|
|
|
|
window_border_refresh(window_t *window)
|
|
|
|
{
|
|
|
|
if(!window->border_need_update)
|
|
|
|
return;
|
|
|
|
window->border_need_update = false;
|
|
|
|
xwindow_set_border_color(window_get(window), &window->border_color);
|
|
|
|
if(window->window)
|
|
|
|
xcb_configure_window(globalconf.connection, window_get(window),
|
|
|
|
XCB_CONFIG_WINDOW_BORDER_WIDTH,
|
|
|
|
(uint32_t[]) { window->border_width });
|
|
|
|
}
|
|
|
|
|
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 &&
|
Make alpha work on window borders
Up to now, we always asked the X11 server for color allocation ("which
pixel value corresponds to (r,g,b)?", an AllocCollor request).
This commit adds direct support for TrueColor and DirectColor visuals.
In such a visual, the X11 server gives tells us where the red, green,
and blue color components are in a pixel value and we can then just
directly compute the pixel value.
Additionally, this commit adds code that assumes that in a depth=32
visual, the remaining values (after handling red, green, blue) is the
alpha channel for colors. Thus, this adds support for transparent client
borders.
This commit also touches code for the systray. However, the systray must
always use the X11 server's default visual and that one always(?) has
depth=24, i.e. does not support an alpha channel. Thus, the systray
background still cannot be transparent.
Also, in theory this commit should support visuals where some color
component does not have 8 bits, for example RGB565. However, this is
just theoretic and I have no idea how to actually test this (without
jumping through too many hoops).
Fixes: https://github.com/awesomeWM/awesome/issues/162
Signed-off-by: Uli Schlachter <psychon@znc.in>
2018-03-02 14:16:51 +01:00
|
|
|
color_init_reply(color_init_unchecked(&window->border_color, color_name, len, globalconf.visual)))
|
2009-10-02 16:42:31 +02:00
|
|
|
{
|
2016-02-28 16:24:30 +01:00
|
|
|
window->border_need_update = true;
|
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);
|
2015-10-10 17:45:24 +02:00
|
|
|
uint16_t old_width = window->border_width;
|
2009-10-06 19:04:36 +02:00
|
|
|
|
|
|
|
if(width == window->border_width || width < 0)
|
|
|
|
return;
|
|
|
|
|
2016-02-28 16:24:30 +01:00
|
|
|
window->border_need_update = true;
|
2009-10-06 19:04:36 +02:00
|
|
|
window->border_width = width;
|
|
|
|
|
2015-10-10 17:45:24 +02:00
|
|
|
if(window->border_width_callback)
|
|
|
|
(*window->border_width_callback)(window, old_width, width);
|
|
|
|
|
2009-10-06 19:04:36 +02:00
|
|
|
luaA_object_emit_signal(L, idx, "property::border_width", 0);
|
|
|
|
}
|
|
|
|
|
2010-09-27 21:16:30 +02:00
|
|
|
/** Get the window type.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param window The window object.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_window_get_type(lua_State *L, window_t *w)
|
|
|
|
{
|
|
|
|
switch(w->type)
|
|
|
|
{
|
|
|
|
case WINDOW_TYPE_DESKTOP:
|
|
|
|
lua_pushliteral(L, "desktop");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_DOCK:
|
|
|
|
lua_pushliteral(L, "dock");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_SPLASH:
|
|
|
|
lua_pushliteral(L, "splash");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_DIALOG:
|
|
|
|
lua_pushliteral(L, "dialog");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_MENU:
|
|
|
|
lua_pushliteral(L, "menu");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_TOOLBAR:
|
|
|
|
lua_pushliteral(L, "toolbar");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_UTILITY:
|
|
|
|
lua_pushliteral(L, "utility");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_DROPDOWN_MENU:
|
|
|
|
lua_pushliteral(L, "dropdown_menu");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_POPUP_MENU:
|
|
|
|
lua_pushliteral(L, "popup_menu");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_TOOLTIP:
|
|
|
|
lua_pushliteral(L, "tooltip");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_NOTIFICATION:
|
|
|
|
lua_pushliteral(L, "notification");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_COMBO:
|
|
|
|
lua_pushliteral(L, "combo");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_DND:
|
|
|
|
lua_pushliteral(L, "dnd");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_NORMAL:
|
|
|
|
lua_pushliteral(L, "normal");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-09-27 22:03:34 +02:00
|
|
|
/** Set the window type.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param window The window object.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_window_set_type(lua_State *L, window_t *w)
|
|
|
|
{
|
2010-09-28 13:07:31 +02:00
|
|
|
window_type_t type;
|
2010-09-27 22:03:34 +02:00
|
|
|
const char *buf = luaL_checkstring(L, -1);
|
|
|
|
|
2011-11-17 16:38:39 +01:00
|
|
|
if (A_STREQ(buf, "desktop"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_DESKTOP;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "dock"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_DOCK;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "splash"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_SPLASH;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "dialog"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_DIALOG;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "menu"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_MENU;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "toolbar"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_TOOLBAR;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "utility"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_UTILITY;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "dropdown_menu"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_DROPDOWN_MENU;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "popup_menu"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_POPUP_MENU;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "tooltip"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_TOOLTIP;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "notification"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_NOTIFICATION;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "combo"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_COMBO;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "dnd"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_DND;
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(buf, "normal"))
|
2010-09-28 13:07:31 +02:00
|
|
|
type = WINDOW_TYPE_NORMAL;
|
2010-09-27 22:03:34 +02:00
|
|
|
else
|
|
|
|
{
|
2015-12-23 14:01:10 +01:00
|
|
|
luaA_warn(L, "Unknown window type '%s'", buf);
|
2010-09-27 22:03:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-28 13:07:31 +02:00
|
|
|
if(w->type != type)
|
|
|
|
{
|
|
|
|
w->type = type;
|
|
|
|
if(w->window != XCB_WINDOW_NONE)
|
2011-11-17 16:38:39 +01:00
|
|
|
ewmh_update_window_type(w->window, window_translate_type(w->type));
|
2014-12-06 11:07:20 +01:00
|
|
|
luaA_object_emit_signal(L, -3, "property::type", 0);
|
2010-09-28 13:07:31 +02:00
|
|
|
}
|
2011-11-17 16:38:39 +01:00
|
|
|
|
2010-09-27 22:03:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-07 13:49:24 +01:00
|
|
|
static xproperty_t *
|
|
|
|
luaA_find_xproperty(lua_State *L, int idx)
|
|
|
|
{
|
|
|
|
const char *name = luaL_checkstring(L, idx);
|
|
|
|
foreach(prop, globalconf.xproperties)
|
|
|
|
if (A_STREQ(prop->name, name))
|
|
|
|
return prop;
|
|
|
|
luaL_argerror(L, idx, "Unknown xproperty");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-23 18:09:32 +01:00
|
|
|
int
|
|
|
|
window_set_xproperty(lua_State *L, xcb_window_t window, int prop_idx, int value_idx)
|
2014-03-07 13:49:24 +01:00
|
|
|
{
|
2014-03-23 18:09:32 +01:00
|
|
|
xproperty_t *prop = luaA_find_xproperty(L, prop_idx);
|
2014-03-07 13:49:24 +01:00
|
|
|
xcb_atom_t type;
|
|
|
|
size_t len;
|
|
|
|
uint32_t number;
|
|
|
|
const void *data;
|
|
|
|
|
2014-03-23 18:09:32 +01:00
|
|
|
if(lua_isnil(L, value_idx))
|
2014-03-07 13:49:24 +01:00
|
|
|
{
|
2014-03-23 18:09:32 +01:00
|
|
|
xcb_delete_property(globalconf.connection, window, prop->atom);
|
2014-03-07 13:49:24 +01:00
|
|
|
} else {
|
2017-11-17 10:30:56 +01:00
|
|
|
uint8_t format;
|
2014-03-07 13:49:24 +01:00
|
|
|
if(prop->type == PROP_STRING)
|
|
|
|
{
|
2014-03-23 18:09:32 +01:00
|
|
|
data = luaL_checklstring(L, value_idx, &len);
|
2014-03-07 13:49:24 +01:00
|
|
|
type = UTF8_STRING;
|
|
|
|
format = 8;
|
|
|
|
} else if(prop->type == PROP_NUMBER || prop->type == PROP_BOOLEAN)
|
|
|
|
{
|
|
|
|
if (prop->type == PROP_NUMBER)
|
2016-04-17 13:44:05 +02:00
|
|
|
number = luaA_checkinteger_range(L, value_idx, 0, UINT32_MAX);
|
2014-03-07 13:49:24 +01:00
|
|
|
else
|
2014-03-23 18:09:32 +01:00
|
|
|
number = luaA_checkboolean(L, value_idx);
|
2014-03-07 13:49:24 +01:00
|
|
|
data = &number;
|
|
|
|
len = 1;
|
|
|
|
type = XCB_ATOM_CARDINAL;
|
|
|
|
format = 32;
|
|
|
|
} else
|
|
|
|
fatal("Got an xproperty with invalid type");
|
|
|
|
|
2014-03-23 18:09:32 +01:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, window,
|
2014-03-07 13:49:24 +01:00
|
|
|
prop->atom, type, format, len, data);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-23 18:09:32 +01:00
|
|
|
int
|
|
|
|
window_get_xproperty(lua_State *L, xcb_window_t window, int prop_idx)
|
2014-03-07 13:49:24 +01:00
|
|
|
{
|
2014-03-23 18:09:32 +01:00
|
|
|
xproperty_t *prop = luaA_find_xproperty(L, prop_idx);
|
2014-03-07 13:49:24 +01:00
|
|
|
xcb_atom_t type;
|
|
|
|
void *data;
|
|
|
|
xcb_get_property_reply_t *reply;
|
2014-03-09 20:22:44 +01:00
|
|
|
uint32_t length;
|
2014-03-07 13:49:24 +01:00
|
|
|
|
|
|
|
type = prop->type == PROP_STRING ? UTF8_STRING : XCB_ATOM_CARDINAL;
|
2014-03-09 20:22:44 +01:00
|
|
|
length = prop->type == PROP_STRING ? UINT32_MAX : 1;
|
2014-03-07 13:49:24 +01:00
|
|
|
reply = xcb_get_property_reply(globalconf.connection,
|
2014-03-23 18:09:32 +01:00
|
|
|
xcb_get_property_unchecked(globalconf.connection, false, window,
|
2014-03-09 20:22:44 +01:00
|
|
|
prop->atom, type, 0, length), NULL);
|
2014-03-07 13:49:24 +01:00
|
|
|
if(!reply)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
data = xcb_get_property_value(reply);
|
|
|
|
|
|
|
|
if(prop->type == PROP_STRING)
|
|
|
|
lua_pushlstring(L, data, reply->value_len);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(reply->value_len <= 0)
|
|
|
|
{
|
|
|
|
p_delete(&reply);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(prop->type == PROP_NUMBER)
|
|
|
|
lua_pushinteger(L, *(uint32_t *) data);
|
|
|
|
else
|
|
|
|
lua_pushboolean(L, *(uint32_t *) data);
|
|
|
|
}
|
|
|
|
|
|
|
|
p_delete(&reply);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-02-27 00:24:23 +01:00
|
|
|
/** Change a xproperty.
|
|
|
|
*
|
|
|
|
* @param name The name of the X11 property
|
|
|
|
* @param value The new value for the property
|
|
|
|
* @function set_xproperty
|
2014-03-23 18:09:32 +01:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_window_set_xproperty(lua_State *L)
|
|
|
|
{
|
|
|
|
window_t *w = luaA_checkudata(L, 1, &window_class);
|
|
|
|
return window_set_xproperty(L, w->window, 2, 3);
|
|
|
|
}
|
|
|
|
|
2015-02-27 00:24:23 +01:00
|
|
|
/** Get the value of a xproperty.
|
|
|
|
*
|
|
|
|
* @param name The name of the X11 property
|
|
|
|
* @function get_xproperty
|
2014-03-23 18:09:32 +01:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_window_get_xproperty(lua_State *L)
|
|
|
|
{
|
|
|
|
window_t *w = luaA_checkudata(L, 1, &window_class);
|
|
|
|
return window_get_xproperty(L, w->window, 2);
|
|
|
|
}
|
|
|
|
|
2015-02-27 00:24:23 +01:00
|
|
|
/* Translate a window_type_t into the corresponding EWMH atom.
|
2010-09-28 13:07:31 +02:00
|
|
|
* @param type The type to return.
|
|
|
|
* @return The EWMH atom for this type.
|
|
|
|
*/
|
|
|
|
uint32_t
|
|
|
|
window_translate_type(window_type_t type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case WINDOW_TYPE_NORMAL:
|
|
|
|
return _NET_WM_WINDOW_TYPE_NORMAL;
|
|
|
|
case WINDOW_TYPE_DESKTOP:
|
|
|
|
return _NET_WM_WINDOW_TYPE_DESKTOP;
|
|
|
|
case WINDOW_TYPE_DOCK:
|
|
|
|
return _NET_WM_WINDOW_TYPE_DOCK;
|
|
|
|
case WINDOW_TYPE_SPLASH:
|
|
|
|
return _NET_WM_WINDOW_TYPE_SPLASH;
|
|
|
|
case WINDOW_TYPE_DIALOG:
|
|
|
|
return _NET_WM_WINDOW_TYPE_DIALOG;
|
|
|
|
case WINDOW_TYPE_MENU:
|
|
|
|
return _NET_WM_WINDOW_TYPE_MENU;
|
|
|
|
case WINDOW_TYPE_TOOLBAR:
|
|
|
|
return _NET_WM_WINDOW_TYPE_TOOLBAR;
|
|
|
|
case WINDOW_TYPE_UTILITY:
|
|
|
|
return _NET_WM_WINDOW_TYPE_UTILITY;
|
|
|
|
case WINDOW_TYPE_DROPDOWN_MENU:
|
|
|
|
return _NET_WM_WINDOW_TYPE_DROPDOWN_MENU;
|
|
|
|
case WINDOW_TYPE_POPUP_MENU:
|
|
|
|
return _NET_WM_WINDOW_TYPE_POPUP_MENU;
|
|
|
|
case WINDOW_TYPE_TOOLTIP:
|
|
|
|
return _NET_WM_WINDOW_TYPE_TOOLTIP;
|
|
|
|
case WINDOW_TYPE_NOTIFICATION:
|
|
|
|
return _NET_WM_WINDOW_TYPE_NOTIFICATION;
|
|
|
|
case WINDOW_TYPE_COMBO:
|
|
|
|
return _NET_WM_WINDOW_TYPE_COMBO;
|
|
|
|
case WINDOW_TYPE_DND:
|
|
|
|
return _NET_WM_WINDOW_TYPE_DND;
|
|
|
|
}
|
|
|
|
return _NET_WM_WINDOW_TYPE_NORMAL;
|
|
|
|
}
|
|
|
|
|
2009-10-06 19:04:36 +02:00
|
|
|
static int
|
|
|
|
luaA_window_set_border_width(lua_State *L, window_t *c)
|
|
|
|
{
|
2016-04-18 07:15:15 +02:00
|
|
|
window_set_border_width(L, -3, round(luaA_checknumber_range(L, -1, 0, MAX_X11_SIZE)));
|
2009-10-06 19:04:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-26 07:09:12 +02:00
|
|
|
LUA_OBJECT_EXPORT_PROPERTY(window, window_t, window, lua_pushinteger)
|
2010-10-06 20:14:19 +02:00
|
|
|
LUA_OBJECT_EXPORT_PROPERTY(window, window_t, border_color, luaA_pushcolor)
|
2015-05-26 07:09:12 +02:00
|
|
|
LUA_OBJECT_EXPORT_PROPERTY(window, window_t, border_width, lua_pushinteger)
|
2009-09-30 16:04:42 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
window_class_setup(lua_State *L)
|
|
|
|
{
|
2012-06-06 23:07:07 +02:00
|
|
|
static const struct luaL_Reg window_methods[] =
|
2009-09-30 16:04:42 +02:00
|
|
|
{
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2012-06-06 23:07:07 +02:00
|
|
|
static const struct luaL_Reg window_meta[] =
|
2009-09-30 16:04:42 +02:00
|
|
|
{
|
2009-10-01 16:36:46 +02:00
|
|
|
{ "struts", luaA_window_struts },
|
2009-10-02 16:16:34 +02:00
|
|
|
{ "buttons", luaA_window_buttons },
|
2014-03-07 13:49:24 +01:00
|
|
|
{ "set_xproperty", luaA_window_set_xproperty },
|
|
|
|
{ "get_xproperty", luaA_window_get_xproperty },
|
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);
|
2009-09-30 16:04:42 +02:00
|
|
|
}
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|