From a54636751bef17ad6bbde266ab1d35ad0ad36c0d Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 23 Feb 2014 12:26:13 +0100 Subject: [PATCH] client: Add c.blob property Signed-off-by: Uli Schlachter --- common/atoms.list | 1 + luadoc/client.lua | 1 + objects/client.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ objects/client.h | 5 +++++ 4 files changed, 52 insertions(+) diff --git a/common/atoms.list b/common/atoms.list index 507a7ffa..f52772bc 100644 --- a/common/atoms.list +++ b/common/atoms.list @@ -1,3 +1,4 @@ +AWESOME_NAQUADAH_BLOB _NET_SUPPORTED _NET_STARTUP_ID _NET_CLIENT_LIST diff --git a/luadoc/client.lua b/luadoc/client.lua index b3a3bc35..169efd0b 100644 --- a/luadoc/client.lua +++ b/luadoc/client.lua @@ -45,6 +45,7 @@ module("client") -- @field shape_clip The client's clip shape as set by awesome as a (native) cairo surface. -- @field shape_client_bounding The client's bounding shape as set by the program as a (native) cairo surface. -- @field shape_client_clip The client's clip shape as set by the program as a (native) cairo surface. +-- @field blob A string containing data that will still be available after awesome restarts. -- @class table -- @name client diff --git a/objects/client.c b/objects/client.c index 3838cbcc..89507da7 100644 --- a/objects/client.c +++ b/objects/client.c @@ -431,6 +431,10 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, bool startup) return; } + xcb_get_property_cookie_t blob_q; + blob_q = xcb_get_property(globalconf.connection, false, w, AWESOME_NAQUADAH_BLOB, + XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX); + /* If this is a new client that just has been launched, then request its * startup id. */ xcb_get_property_cookie_t startup_id_q = { 0 }; @@ -496,6 +500,19 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, bool startup) xcb_ungrab_server(globalconf.connection); } + { + /* Request our response */ + xcb_get_property_reply_t *reply = + xcb_get_property_reply(globalconf.connection, blob_q, NULL); + + if (reply) + { + c->blob.length = xcb_get_property_value_length(reply); + c->blob.data = p_dup((char *) xcb_get_property_value(reply), c->blob.length); + } + p_delete(&reply); + } + /* Do this now so that we don't get any events for the above * (Else, reparent could cause an UnmapNotify) */ xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val); @@ -1767,6 +1784,13 @@ luaA_client_get_icon_name(lua_State *L, client_t *c) return 1; } +static int +luaA_client_get_blob(lua_State *L, client_t *c) +{ + lua_pushlstring(L, NONULL(c->blob.data), c->blob.length); + return 1; +} + LUA_OBJECT_EXPORT_PROPERTY(client, client_t, class, lua_pushstring) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, instance, lua_pushstring) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, machine, lua_pushstring) @@ -2076,6 +2100,23 @@ luaA_client_set_shape_clip(lua_State *L, client_t *c) return 0; } +/** Set the client's blob. + * \param L The Lua VM state. + * \param client The client object. + * \return The number of elements pushed on stack. + */ +static int +luaA_client_set_blob(lua_State *L, client_t *c) +{ + const char *blob = luaL_checklstring(L, -1, &c->blob.length); + + p_delete(&c->blob.data); + c->blob.data = p_dup(blob, c->blob.length); + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->window, + AWESOME_NAQUADAH_BLOB, AWESOME_NAQUADAH_BLOB, 8, c->blob.length, blob); + return 0; +} + /** Get or set keys bindings for a client. * \param L The Lua VM state. * \return The number of element pushed on stack. @@ -2310,6 +2351,10 @@ client_class_setup(lua_State *L) NULL, (lua_class_propfunc_t) luaA_client_get_client_shape_clip, NULL); + luaA_class_add_property(&client_class, "blob", + (lua_class_propfunc_t) luaA_client_set_blob, + (lua_class_propfunc_t) luaA_client_get_blob, + (lua_class_propfunc_t) luaA_client_set_blob); signal_add(&client_class.signals, "focus"); signal_add(&client_class.signals, "list"); diff --git a/objects/client.h b/objects/client.h index 5375418f..b07e3042 100644 --- a/objects/client.h +++ b/objects/client.h @@ -124,6 +124,11 @@ struct client_t /** The drawable for this bar. */ drawable_t *drawable; } titlebar[CLIENT_TITLEBAR_COUNT]; + /** The blob! */ + struct { + char *data; + size_t length; + } blob; }; ARRAY_FUNCS(client_t *, client, DO_NOTHING)