2009-04-17 11:50:20 +02:00
|
|
|
/*
|
|
|
|
* root.c - root window management
|
|
|
|
*
|
|
|
|
* Copyright © 2008-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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-11-21 15:43:15 +01:00
|
|
|
/** awesome root window API.
|
2015-02-27 00:24:23 +01:00
|
|
|
* @author Julien Danjou <julien@danjou.info>
|
|
|
|
* @copyright 2008-2009 Julien Danjou
|
2019-06-06 08:40:00 +02:00
|
|
|
* @coreclassmod root
|
2015-02-27 00:24:23 +01:00
|
|
|
*/
|
|
|
|
|
2009-09-07 17:22:32 +02:00
|
|
|
#include "globalconf.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
|
|
|
|
#include "common/atoms.h"
|
|
|
|
#include "common/xcursor.h"
|
2016-04-17 13:44:05 +02:00
|
|
|
#include "common/xutil.h"
|
2009-09-14 20:29:03 +02:00
|
|
|
#include "objects/button.h"
|
2018-12-26 21:50:21 +01:00
|
|
|
#include "common/luaclass.h"
|
2009-09-17 17:51:06 +02:00
|
|
|
#include "xwindow.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
|
2016-04-18 07:15:15 +02:00
|
|
|
#include "math.h"
|
|
|
|
|
2014-03-30 20:07:48 +02:00
|
|
|
#include <xcb/xtest.h>
|
|
|
|
#include <xcb/xcb_aux.h>
|
|
|
|
#include <cairo-xcb.h>
|
2009-04-17 11:50:20 +02:00
|
|
|
|
2018-12-26 21:50:21 +01:00
|
|
|
static int miss_index_handler = LUA_REFNIL;
|
|
|
|
static int miss_newindex_handler = LUA_REFNIL;
|
|
|
|
static int miss_call_handler = LUA_REFNIL;
|
|
|
|
|
2012-07-29 15:32:04 +02:00
|
|
|
static void
|
|
|
|
root_set_wallpaper_pixmap(xcb_connection_t *c, xcb_pixmap_t p)
|
|
|
|
{
|
|
|
|
xcb_get_property_cookie_t prop_c;
|
|
|
|
xcb_get_property_reply_t *prop_r;
|
|
|
|
const xcb_screen_t *screen = globalconf.screen;
|
|
|
|
|
|
|
|
/* We now have the pattern painted to the pixmap p. Now turn p into the root
|
|
|
|
* window's background pixmap.
|
|
|
|
*/
|
|
|
|
xcb_change_window_attributes(c, screen->root, XCB_CW_BACK_PIXMAP, &p);
|
|
|
|
xcb_clear_area(c, 0, screen->root, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
prop_c = xcb_get_property_unchecked(c, false,
|
|
|
|
screen->root, ESETROOT_PMAP_ID, XCB_ATOM_PIXMAP, 0, 1);
|
|
|
|
|
|
|
|
/* Theoretically, this should be enough to set the wallpaper. However, to
|
|
|
|
* make pseudo-transparency work, clients need a way to get the wallpaper.
|
|
|
|
* You can't query a window's back pixmap, so properties are (ab)used.
|
|
|
|
*/
|
|
|
|
xcb_change_property(c, XCB_PROP_MODE_REPLACE, screen->root, _XROOTPMAP_ID, XCB_ATOM_PIXMAP, 32, 1, &p);
|
|
|
|
xcb_change_property(c, XCB_PROP_MODE_REPLACE, screen->root, ESETROOT_PMAP_ID, XCB_ATOM_PIXMAP, 32, 1, &p);
|
|
|
|
|
|
|
|
/* Now make sure that the old wallpaper is freed (but only do this for ESETROOT_PMAP_ID) */
|
|
|
|
prop_r = xcb_get_property_reply(c, prop_c, NULL);
|
|
|
|
if (prop_r && prop_r->value_len)
|
|
|
|
{
|
|
|
|
xcb_pixmap_t *rootpix = xcb_get_property_value(prop_r);
|
|
|
|
if (rootpix)
|
|
|
|
xcb_kill_client(c, *rootpix);
|
|
|
|
}
|
2014-03-06 18:35:17 +01:00
|
|
|
p_delete(&prop_r);
|
2012-07-29 15:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
root_set_wallpaper(cairo_pattern_t *pattern)
|
|
|
|
{
|
2016-03-27 11:36:23 +02:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
2012-07-29 15:32:04 +02:00
|
|
|
xcb_connection_t *c = xcb_connect(NULL, NULL);
|
|
|
|
xcb_pixmap_t p = xcb_generate_id(c);
|
|
|
|
/* globalconf.connection should be connected to the same X11 server, so we
|
|
|
|
* can just use the info from that other connection.
|
|
|
|
*/
|
|
|
|
const xcb_screen_t *screen = globalconf.screen;
|
|
|
|
uint16_t width = screen->width_in_pixels;
|
|
|
|
uint16_t height = screen->height_in_pixels;
|
|
|
|
bool result = false;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
if (xcb_connection_has_error(c))
|
|
|
|
goto disconnect;
|
|
|
|
|
2013-01-24 18:54:35 +01:00
|
|
|
/* Create a pixmap and make sure it is already created, because we are going
|
|
|
|
* to use it from the other X11 connection (Juggling with X11 connections
|
|
|
|
* is a really, really bad idea).
|
|
|
|
*/
|
2012-07-29 15:32:04 +02:00
|
|
|
xcb_create_pixmap(c, screen->root_depth, p, screen->root, width, height);
|
2013-01-24 18:54:35 +01:00
|
|
|
xcb_aux_sync(c);
|
|
|
|
|
|
|
|
/* Now paint to the picture from the main connection so that cairo sees that
|
|
|
|
* it can tell the X server to copy between the (possible) old pixmap and
|
|
|
|
* the new one directly and doesn't need GetImage and PutImage.
|
|
|
|
*/
|
|
|
|
surface = cairo_xcb_surface_create(globalconf.connection, p, draw_default_visual(screen), width, height);
|
2012-07-29 15:32:04 +02:00
|
|
|
cr = cairo_create(surface);
|
|
|
|
/* Paint the pattern to the surface */
|
|
|
|
cairo_set_source(cr, pattern);
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
cairo_paint(cr);
|
|
|
|
cairo_destroy(cr);
|
2016-03-27 11:36:23 +02:00
|
|
|
cairo_surface_flush(surface);
|
2013-01-24 18:54:35 +01:00
|
|
|
xcb_aux_sync(globalconf.connection);
|
2012-07-29 15:32:04 +02:00
|
|
|
|
2016-03-27 11:36:23 +02:00
|
|
|
/* Change the wallpaper, without sending us a PropertyNotify event */
|
|
|
|
xcb_grab_server(globalconf.connection);
|
|
|
|
xcb_change_window_attributes(globalconf.connection,
|
|
|
|
globalconf.screen->root,
|
|
|
|
XCB_CW_EVENT_MASK,
|
|
|
|
(uint32_t[]) { 0 });
|
2017-05-29 20:08:56 +02:00
|
|
|
root_set_wallpaper_pixmap(globalconf.connection, p);
|
2016-03-27 11:36:23 +02:00
|
|
|
xcb_change_window_attributes(globalconf.connection,
|
|
|
|
globalconf.screen->root,
|
|
|
|
XCB_CW_EVENT_MASK,
|
|
|
|
ROOT_WINDOW_EVENT_MASK);
|
2019-02-27 10:20:22 +01:00
|
|
|
xutil_ungrab_server(globalconf.connection);
|
2012-07-29 15:32:04 +02:00
|
|
|
|
|
|
|
/* Make sure our pixmap is not destroyed when we disconnect. */
|
|
|
|
xcb_set_close_down_mode(c, XCB_CLOSE_DOWN_RETAIN_PERMANENT);
|
|
|
|
|
2016-03-27 11:36:23 +02:00
|
|
|
/* Tell Lua that the wallpaper changed */
|
|
|
|
cairo_surface_destroy(globalconf.wallpaper);
|
|
|
|
globalconf.wallpaper = surface;
|
|
|
|
signal_object_emit(L, &global_signals, "wallpaper_changed", 0);
|
|
|
|
|
2012-07-29 15:32:04 +02:00
|
|
|
result = true;
|
|
|
|
disconnect:
|
Sync instead of flush after setting a wallpaper (#1278)
When setting a wallpaper, we open a second connection to the X11 server
and create a pixmap there. This pixmap is then used as the wallpaper. We
do this so that we can use a "close down mode" called "permanent". This
means that the X11 server will not free the pixmap after we disconnect,
but keeps it allocated. Setting this close down mode is the last thing
that we do on the setup-the-wallpaper-connection before disconnecting.
However, sometimes things didn't work around. The wallpaper was missing
and trying to query it resulted in errors that basically mean "there is
no such pixmap". Thus, the symptoms say that the close down mode did not
work.
This commit is an attempt to fix this. Instead of just flushing before
closing the connection (sending all outstanding requests to the server),
this commit does a sync, which means it sends a request to the server
and waits for a reply. This guarantees that all previously requests were
handled.
The theory here is like this: We send the SetCloseDownMode-request and
then immediately disconnected. If the X11 server notices that we are
disconnected before handling the SetCloseDownMode-request, the request
would be ignored.
This theory is consistent with the symptoms above and in my local
testing this patch seems to fix things, but since the error only
appeared sporadically, I cannot be 100% sure. Still, it all seems to
make sense to me.
Fixes: https://github.com/awesomeWM/awesome/issues/1276
Signed-off-by: Uli Schlachter <psychon@znc.in>
2016-12-19 00:20:07 +01:00
|
|
|
xcb_aux_sync(c);
|
2012-07-29 15:32:04 +02:00
|
|
|
xcb_disconnect(c);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-27 11:28:02 +02:00
|
|
|
void
|
|
|
|
root_update_wallpaper(void)
|
|
|
|
{
|
|
|
|
xcb_get_property_cookie_t prop_c;
|
|
|
|
xcb_get_property_reply_t *prop_r;
|
|
|
|
xcb_get_geometry_cookie_t geom_c;
|
|
|
|
xcb_get_geometry_reply_t *geom_r;
|
|
|
|
xcb_pixmap_t *rootpix;
|
|
|
|
|
|
|
|
cairo_surface_destroy(globalconf.wallpaper);
|
|
|
|
globalconf.wallpaper = NULL;
|
|
|
|
|
|
|
|
prop_c = xcb_get_property_unchecked(globalconf.connection, false,
|
|
|
|
globalconf.screen->root, _XROOTPMAP_ID, XCB_ATOM_PIXMAP, 0, 1);
|
|
|
|
prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
|
|
|
|
|
|
|
|
if (!prop_r || !prop_r->value_len)
|
|
|
|
{
|
|
|
|
p_delete(&prop_r);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rootpix = xcb_get_property_value(prop_r);
|
|
|
|
if (!rootpix)
|
|
|
|
{
|
|
|
|
p_delete(&prop_r);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
geom_c = xcb_get_geometry_unchecked(globalconf.connection, *rootpix);
|
|
|
|
geom_r = xcb_get_geometry_reply(globalconf.connection, geom_c, NULL);
|
|
|
|
if (!geom_r)
|
|
|
|
{
|
|
|
|
p_delete(&prop_r);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only the default visual makes sense, so just the default depth */
|
|
|
|
if (geom_r->depth != draw_visual_depth(globalconf.screen, globalconf.default_visual->visual_id))
|
|
|
|
warn("Got a pixmap with depth %d, but the default depth is %d, continuing anyway",
|
|
|
|
geom_r->depth, draw_visual_depth(globalconf.screen, globalconf.default_visual->visual_id));
|
|
|
|
|
|
|
|
globalconf.wallpaper = cairo_xcb_surface_create(globalconf.connection,
|
|
|
|
*rootpix,
|
|
|
|
globalconf.default_visual,
|
|
|
|
geom_r->width,
|
|
|
|
geom_r->height);
|
|
|
|
|
|
|
|
p_delete(&prop_r);
|
|
|
|
p_delete(&geom_r);
|
|
|
|
}
|
|
|
|
|
2011-12-07 16:13:25 +01:00
|
|
|
static xcb_keycode_t
|
|
|
|
_string_to_key_code(const char *s)
|
|
|
|
{
|
|
|
|
xcb_keysym_t keysym;
|
|
|
|
xcb_keycode_t *keycodes;
|
|
|
|
|
|
|
|
keysym = XStringToKeysym(s);
|
|
|
|
keycodes = xcb_key_symbols_get_keycode(globalconf.keysyms, keysym);
|
|
|
|
|
|
|
|
if(keycodes) {
|
|
|
|
return keycodes[0]; /* XXX only returning the first is probably not
|
|
|
|
* the best */
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-21 20:23:47 +02:00
|
|
|
/** Send fake keyboard or mouse events.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2018-07-21 20:23:47 +02:00
|
|
|
* Usually the currently focused client or the keybindings will receive those
|
|
|
|
* events. If a `keygrabber` or `mousegrabber` is running, then it will get them.
|
|
|
|
*
|
|
|
|
* Some keys have different names compared to the ones generally used in
|
|
|
|
* Awesome. For example, Awesome uses "modifier keys" for keybindings using
|
|
|
|
* their X11 names such as "Control" or "Mod1" (for "Alt"). These are not the
|
|
|
|
* name of the key but is only the name of the modifier they represent. Some
|
|
|
|
* modifiers are even present twice on some keyboard like the left and right
|
|
|
|
* "Shift". Here is a list of the "real" key names matching the modifiers in
|
|
|
|
* `fake_input`:
|
|
|
|
*
|
2019-06-08 01:08:05 +02:00
|
|
|
* <table class='widget_list' border=1>
|
2018-07-21 20:23:47 +02:00
|
|
|
* <tr style='font-weight: bold;'>
|
|
|
|
* <th align='center'>Modifier name </th>
|
|
|
|
* <th align='center'>Key name</th>
|
|
|
|
* <th align='center'>Other key name</th>
|
|
|
|
* </tr>
|
|
|
|
* <tr><td> Mod4</td><td align='center'> Super_L </td><td align='center'> Super_R </td></tr>
|
|
|
|
* <tr><td> Control </td><td align='center'> Control_L </td><td align='center'> Control_R </td></tr>
|
|
|
|
* <tr><td> Shift </td><td align='center'> Shift_L </td><td align='center'> Shift_R </td></tr>
|
|
|
|
* <tr><td> Mod1</td><td align='center'> Alt_L </td><td align='center'> Alt_R </td></tr>
|
|
|
|
* </table>
|
|
|
|
*
|
|
|
|
* Note that this is valid for most of the modern "western" keyboard layouts.
|
|
|
|
* Some older, custom or foreign layouts may break this convention.
|
|
|
|
*
|
|
|
|
* This function is very low level, to be more useful, it can be wrapped into
|
|
|
|
* higher level constructs such as:
|
|
|
|
*
|
|
|
|
* **Sending strings:**
|
|
|
|
*
|
|
|
|
* @DOC_text_root_fake_string_EXAMPLE@
|
|
|
|
*
|
|
|
|
* Note that this example works for most ASCII inputs but may fail depending on
|
|
|
|
* how the string is encoded. Some multi-byte characters may not represent
|
|
|
|
* keys and some UTF-8 encoding format create characters by combining multiple
|
|
|
|
* elements such as accent + base character or various escape sequences. If you
|
|
|
|
* wish to use this example for "real world" i18n use cases, learning about
|
|
|
|
* XKB event and UTF-8 encoding is a prerequisites.
|
|
|
|
*
|
|
|
|
* **Clicking:**
|
|
|
|
*
|
|
|
|
* ![Client geometry](../images/mouse.svg)
|
|
|
|
*
|
|
|
|
* @DOC_text_root_fake_click_EXAMPLE@
|
|
|
|
*
|
|
|
|
* @param event_type The event type: key\_press, key\_release, button\_press,
|
|
|
|
* button\_release or motion\_notify.
|
2015-02-27 00:24:23 +01:00
|
|
|
* @param detail The detail: in case of a key event, this is the keycode
|
|
|
|
* to send, in case of a button event this is the number of the button. In
|
|
|
|
* case of a motion event, this is a boolean value which if true makes the
|
|
|
|
* coordinates relatives.
|
|
|
|
* @param x In case of a motion event, this is the X coordinate.
|
|
|
|
* @param y In case of a motion event, this is the Y coordinate.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct fake_input
|
2009-04-17 11:50:20 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_fake_input(lua_State *L)
|
|
|
|
{
|
|
|
|
if(!globalconf.have_xtest)
|
|
|
|
{
|
|
|
|
luaA_warn(L, "XTest extension is not available, cannot fake input.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-02 18:55:49 +02:00
|
|
|
const char *stype = luaL_checkstring(L, 1);
|
2009-04-17 11:50:20 +02:00
|
|
|
uint8_t type, detail;
|
|
|
|
int x = 0, y = 0;
|
|
|
|
|
2011-11-17 16:38:39 +01:00
|
|
|
if (A_STREQ(stype, "key_press"))
|
2009-04-17 11:50:20 +02:00
|
|
|
{
|
|
|
|
type = XCB_KEY_PRESS;
|
2011-12-07 16:13:25 +01:00
|
|
|
if(lua_type(L, 2) == LUA_TSTRING) {
|
|
|
|
detail = _string_to_key_code(lua_tostring(L, 2)); /* keysym */
|
|
|
|
} else {
|
2016-02-06 13:59:14 +01:00
|
|
|
detail = luaL_checkinteger(L, 2); /* keycode */
|
2011-12-07 16:13:25 +01:00
|
|
|
}
|
2010-09-02 18:55:49 +02:00
|
|
|
}
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(stype, "key_release"))
|
2010-09-02 18:55:49 +02:00
|
|
|
{
|
2009-04-17 11:50:20 +02:00
|
|
|
type = XCB_KEY_RELEASE;
|
2011-12-07 16:13:25 +01:00
|
|
|
if(lua_type(L, 2) == LUA_TSTRING) {
|
|
|
|
detail = _string_to_key_code(lua_tostring(L, 2)); /* keysym */
|
|
|
|
} else {
|
2016-02-06 13:59:14 +01:00
|
|
|
detail = luaL_checkinteger(L, 2); /* keycode */
|
2011-12-07 16:13:25 +01:00
|
|
|
}
|
2010-09-02 18:55:49 +02:00
|
|
|
}
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(stype, "button_press"))
|
2010-09-02 18:55:49 +02:00
|
|
|
{
|
2009-04-17 11:50:20 +02:00
|
|
|
type = XCB_BUTTON_PRESS;
|
2016-02-06 13:59:14 +01:00
|
|
|
detail = luaL_checkinteger(L, 2); /* button number */
|
2010-09-02 18:55:49 +02:00
|
|
|
}
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(stype, "button_release"))
|
2010-09-02 18:55:49 +02:00
|
|
|
{
|
2009-04-17 11:50:20 +02:00
|
|
|
type = XCB_BUTTON_RELEASE;
|
2016-02-06 13:59:14 +01:00
|
|
|
detail = luaL_checkinteger(L, 2); /* button number */
|
2010-09-02 18:55:49 +02:00
|
|
|
}
|
2011-11-17 16:38:39 +01:00
|
|
|
else if(A_STREQ(stype, "motion_notify"))
|
2010-09-02 18:55:49 +02:00
|
|
|
{
|
2009-04-17 11:50:20 +02:00
|
|
|
type = XCB_MOTION_NOTIFY;
|
2009-05-11 08:19:15 +02:00
|
|
|
detail = luaA_checkboolean(L, 2); /* relative to the current position or not */
|
2016-04-18 07:15:15 +02:00
|
|
|
x = round(luaA_checknumber_range(L, 3, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
|
|
|
y = round(luaA_checknumber_range(L, 4, MIN_X11_COORDINATE, MAX_X11_COORDINATE));
|
2009-04-17 11:50:20 +02:00
|
|
|
}
|
2010-09-02 18:55:49 +02:00
|
|
|
else
|
|
|
|
return 0;
|
2009-04-17 11:50:20 +02:00
|
|
|
|
|
|
|
xcb_test_fake_input(globalconf.connection,
|
|
|
|
type,
|
|
|
|
detail,
|
2017-04-15 12:05:42 +02:00
|
|
|
0, /* This is a delay, not a timestamp! */
|
2010-08-16 14:20:45 +02:00
|
|
|
XCB_NONE,
|
2009-04-17 11:50:20 +02:00
|
|
|
x, y,
|
|
|
|
0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-14 16:46:35 +02:00
|
|
|
/** Get or set global key bindings.
|
2018-12-27 04:51:58 +01:00
|
|
|
* These bindings will be available when you press keys on the root window
|
|
|
|
* (the wallpaper).
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2018-12-27 04:51:58 +01:00
|
|
|
* @property keys
|
|
|
|
* @param table
|
|
|
|
* @see awful.key
|
2009-08-14 16:46:35 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_keys(lua_State *L)
|
|
|
|
{
|
|
|
|
if(lua_gettop(L) == 1)
|
|
|
|
{
|
|
|
|
luaA_checktable(L, 1);
|
|
|
|
|
|
|
|
foreach(key, globalconf.keys)
|
2014-12-06 11:07:20 +01:00
|
|
|
luaA_object_unref(L, *key);
|
2009-08-14 16:46:35 +02:00
|
|
|
|
|
|
|
key_array_wipe(&globalconf.keys);
|
|
|
|
key_array_init(&globalconf.keys);
|
|
|
|
|
|
|
|
lua_pushnil(L);
|
|
|
|
while(lua_next(L, 1))
|
2009-09-04 12:46:20 +02:00
|
|
|
key_array_append(&globalconf.keys, luaA_object_ref_class(L, -1, &key_class));
|
2009-08-14 16:46:35 +02:00
|
|
|
|
2010-08-16 14:10:58 +02:00
|
|
|
xcb_screen_t *s = globalconf.screen;
|
2010-08-16 13:47:40 +02:00
|
|
|
xwindow_grabkeys(s->root, &globalconf.keys);
|
2009-08-14 16:52:22 +02:00
|
|
|
|
2009-08-14 16:46:35 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_createtable(L, globalconf.keys.len, 0);
|
|
|
|
for(int i = 0; i < globalconf.keys.len; i++)
|
|
|
|
{
|
2009-06-29 11:02:13 +02:00
|
|
|
luaA_object_push(L, globalconf.keys.tab[i]);
|
2009-08-14 16:46:35 +02:00
|
|
|
lua_rawseti(L, -2, i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-12-26 23:36:54 +01:00
|
|
|
/**
|
|
|
|
* Store the list of mouse buttons to be applied on the wallpaper (also
|
|
|
|
* known as root window).
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2018-12-26 23:36:54 +01:00
|
|
|
* @property buttons
|
|
|
|
* @tparam[opt={}] table buttons The list of buttons.
|
|
|
|
* @see awful.button
|
|
|
|
*
|
|
|
|
* @usage
|
|
|
|
* root.buttons = {
|
|
|
|
* awful.button({ }, 3, function () mymainmenu:toggle() end),
|
|
|
|
* awful.button({ }, 4, awful.tag.viewnext),
|
|
|
|
* awful.button({ }, 5, awful.tag.viewprev),
|
|
|
|
* }
|
2009-08-14 16:46:35 +02:00
|
|
|
*/
|
2018-12-26 23:36:54 +01:00
|
|
|
|
2009-08-14 16:46:35 +02:00
|
|
|
static int
|
|
|
|
luaA_root_buttons(lua_State *L)
|
|
|
|
{
|
|
|
|
if(lua_gettop(L) == 1)
|
|
|
|
{
|
|
|
|
luaA_checktable(L, 1);
|
|
|
|
|
|
|
|
foreach(button, globalconf.buttons)
|
2014-12-06 11:07:20 +01:00
|
|
|
luaA_object_unref(L, *button);
|
2009-08-14 16:46:35 +02:00
|
|
|
|
|
|
|
button_array_wipe(&globalconf.buttons);
|
|
|
|
button_array_init(&globalconf.buttons);
|
|
|
|
|
|
|
|
lua_pushnil(L);
|
|
|
|
while(lua_next(L, 1))
|
2009-06-29 11:02:13 +02:00
|
|
|
button_array_append(&globalconf.buttons, luaA_object_ref(L, -1));
|
2009-08-14 16:46:35 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_createtable(L, globalconf.buttons.len, 0);
|
|
|
|
for(int i = 0; i < globalconf.buttons.len; i++)
|
|
|
|
{
|
2009-06-29 11:02:13 +02:00
|
|
|
luaA_object_push(L, globalconf.buttons.tab[i]);
|
2009-08-14 16:46:35 +02:00
|
|
|
lua_rawseti(L, -2, i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-09-09 08:03:07 +02:00
|
|
|
/** Set the root cursor
|
|
|
|
*
|
|
|
|
* The possible values are:
|
|
|
|
*
|
|
|
|
*@DOC_cursor_c_COMMON@
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
|
|
|
* @param cursor_name A X cursor name.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct cursor
|
2009-04-17 11:50:20 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_cursor(lua_State *L)
|
|
|
|
{
|
|
|
|
const char *cursor_name = luaL_checkstring(L, 1);
|
|
|
|
uint16_t cursor_font = xcursor_font_fromstr(cursor_name);
|
|
|
|
|
|
|
|
if(cursor_font)
|
|
|
|
{
|
2013-09-19 16:48:10 +02:00
|
|
|
uint32_t change_win_vals[] = { xcursor_new(globalconf.cursor_ctx, cursor_font) };
|
2009-04-17 11:50:20 +02:00
|
|
|
|
2010-08-16 13:47:40 +02:00
|
|
|
xcb_change_window_attributes(globalconf.connection,
|
2010-08-16 14:10:58 +02:00
|
|
|
globalconf.screen->root,
|
2010-08-16 13:47:40 +02:00
|
|
|
XCB_CW_CURSOR,
|
|
|
|
change_win_vals);
|
2009-04-17 11:50:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
luaA_warn(L, "invalid cursor %s", cursor_name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-06 13:35:14 +02:00
|
|
|
/** Get the drawins attached to a screen.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
|
|
|
* @return A table with all drawins.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct drawins
|
2009-05-10 15:01:22 +02:00
|
|
|
*/
|
|
|
|
static int
|
2010-10-06 13:35:14 +02:00
|
|
|
luaA_root_drawins(lua_State *L)
|
2009-05-10 15:01:22 +02:00
|
|
|
{
|
2010-10-06 13:35:14 +02:00
|
|
|
lua_createtable(L, globalconf.drawins.len, 0);
|
2009-05-10 15:01:22 +02:00
|
|
|
|
2010-10-06 13:35:14 +02:00
|
|
|
for(int i = 0; i < globalconf.drawins.len; i++)
|
2009-05-10 15:01:22 +02:00
|
|
|
{
|
2010-10-06 13:35:14 +02:00
|
|
|
luaA_object_push(L, globalconf.drawins.tab[i]);
|
2009-05-10 15:01:22 +02:00
|
|
|
lua_rawseti(L, -2, i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-02-27 00:24:23 +01:00
|
|
|
/** Get the wallpaper as a cairo surface or set it as a cairo pattern.
|
|
|
|
*
|
|
|
|
* @param pattern A cairo pattern as light userdata
|
|
|
|
* @return A cairo surface or nothing.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct wallpaper
|
2012-04-07 21:32:45 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_wallpaper(lua_State *L)
|
|
|
|
{
|
2012-07-29 15:32:04 +02:00
|
|
|
if(lua_gettop(L) == 1)
|
|
|
|
{
|
2021-05-24 08:13:26 +02:00
|
|
|
/* Avoid `error()s` down the line. If this happens during
|
|
|
|
* initialization, AwesomeWM can be stuck in an infinite loop */
|
|
|
|
if(lua_isnil(L, -1))
|
|
|
|
return 0;
|
|
|
|
|
2012-07-29 15:32:04 +02:00
|
|
|
cairo_pattern_t *pattern = (cairo_pattern_t *)lua_touserdata(L, -1);
|
|
|
|
lua_pushboolean(L, root_set_wallpaper(pattern));
|
|
|
|
/* Don't return the wallpaper, it's too easy to get memleaks */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-03-27 11:28:02 +02:00
|
|
|
if(globalconf.wallpaper == NULL)
|
2012-04-07 21:32:45 +02:00
|
|
|
return 0;
|
2012-05-27 19:20:34 +02:00
|
|
|
|
|
|
|
/* lua has to make sure this surface gets destroyed */
|
2016-03-27 11:28:02 +02:00
|
|
|
lua_pushlightuserdata(L, cairo_surface_reference(globalconf.wallpaper));
|
2012-05-27 19:20:34 +02:00
|
|
|
return 1;
|
2012-04-07 21:32:45 +02:00
|
|
|
}
|
|
|
|
|
2016-04-09 15:14:48 +02:00
|
|
|
/** Get the size of the root window.
|
|
|
|
*
|
|
|
|
* @return Width of the root window.
|
|
|
|
* @return height of the root window.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct size
|
2016-04-09 15:14:48 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_size(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_pushinteger(L, globalconf.screen->width_in_pixels);
|
|
|
|
lua_pushinteger(L, globalconf.screen->height_in_pixels);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2017-01-25 21:33:59 +01:00
|
|
|
/** Get the physical size of the root window, in millimeter.
|
|
|
|
*
|
|
|
|
* @return Width of the root window, in millimeters.
|
|
|
|
* @return height of the root window, in millimeters.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct size_mm
|
2017-01-25 21:33:59 +01:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_size_mm(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_pushinteger(L, globalconf.screen->width_in_millimeters);
|
|
|
|
lua_pushinteger(L, globalconf.screen->height_in_millimeters);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2015-02-27 00:24:23 +01:00
|
|
|
/** Get the attached tags.
|
|
|
|
* @return A table with all tags.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct tags
|
2012-10-20 17:33:32 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_tags(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_createtable(L, globalconf.tags.len, 0);
|
|
|
|
for(int i = 0; i < globalconf.tags.len; i++)
|
|
|
|
{
|
|
|
|
luaA_object_push(L, globalconf.tags.tab[i]);
|
|
|
|
lua_rawseti(L, -2, i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-12-26 21:50:21 +01:00
|
|
|
/**
|
|
|
|
* Add a custom call handler.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_set_call_handler(lua_State *L)
|
|
|
|
{
|
|
|
|
return luaA_registerfct(L, 1, &miss_call_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a custom property handler (getter).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_set_index_miss_handler(lua_State *L)
|
|
|
|
{
|
|
|
|
return luaA_registerfct(L, 1, &miss_index_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a custom property handler (setter).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_set_newindex_miss_handler(lua_State *L)
|
|
|
|
{
|
|
|
|
return luaA_registerfct(L, 1, &miss_newindex_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Root library.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_index(lua_State *L)
|
|
|
|
{
|
|
|
|
if (miss_index_handler != LUA_REFNIL)
|
|
|
|
return luaA_call_handler(L, miss_index_handler);
|
|
|
|
|
|
|
|
return luaA_default_index(L);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Newindex for root.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_root_newindex(lua_State *L)
|
|
|
|
{
|
|
|
|
/* Call the lua root property handler */
|
|
|
|
if (miss_newindex_handler != LUA_REFNIL)
|
|
|
|
return luaA_call_handler(L, miss_newindex_handler);
|
|
|
|
|
|
|
|
return luaA_default_newindex(L);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct luaL_Reg awesome_root_methods[] =
|
2009-04-17 11:50:20 +02:00
|
|
|
{
|
2018-12-26 21:57:01 +01:00
|
|
|
{ "_buttons", luaA_root_buttons },
|
2018-12-27 04:51:58 +01:00
|
|
|
{ "_keys", luaA_root_keys },
|
2009-04-17 11:50:20 +02:00
|
|
|
{ "cursor", luaA_root_cursor },
|
|
|
|
{ "fake_input", luaA_root_fake_input },
|
2010-10-06 13:35:14 +02:00
|
|
|
{ "drawins", luaA_root_drawins },
|
2021-05-24 08:13:26 +02:00
|
|
|
{ "_wallpaper", luaA_root_wallpaper },
|
2016-04-09 15:14:48 +02:00
|
|
|
{ "size", luaA_root_size },
|
2017-01-25 21:33:59 +01:00
|
|
|
{ "size_mm", luaA_root_size_mm },
|
2012-10-20 17:33:32 +02:00
|
|
|
{ "tags", luaA_root_tags },
|
2018-12-26 21:50:21 +01:00
|
|
|
{ "__index", luaA_root_index },
|
|
|
|
{ "__newindex", luaA_root_newindex },
|
|
|
|
{ "set_index_miss_handler", luaA_root_set_index_miss_handler},
|
|
|
|
{ "set_call_handler", luaA_root_set_call_handler},
|
|
|
|
{ "set_newindex_miss_handler", luaA_root_set_newindex_miss_handler},
|
|
|
|
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct luaL_Reg awesome_root_meta[] =
|
|
|
|
{
|
2009-04-17 11:50:20 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|