diff --git a/docs/89-NEWS.md b/docs/89-NEWS.md index 0b3170910..a7e5af538 100644 --- a/docs/89-NEWS.md +++ b/docs/89-NEWS.md @@ -14,6 +14,7 @@ This document was last updated at commit v4.3-197-g9085ed631. ## New features +* `mousegrabber` can now take `nil` as a cursor to not change the cursor at all. * `awful.screen` now has a `request::wallpaper` and a `request::desktop_decoration` signal. They make some workflow implementation cleaner. diff --git a/mousegrabber.c b/mousegrabber.c index 35bbeb520..4dc4f554e 100644 --- a/mousegrabber.c +++ b/mousegrabber.c @@ -88,7 +88,8 @@ mousegrabber_handleevent(lua_State *L, int x, int y, uint16_t mask) * * * @tparam function func A callback function as described above. - * @tparam string cursor The name of a X cursor to use while grabbing. + * @tparam string|nil cursor The name of an X cursor to use while grabbing or `nil` + * to not change the cursor. * @noreturn * @staticfct run */ @@ -98,23 +99,28 @@ luaA_mousegrabber_run(lua_State *L) if(globalconf.mousegrabber != LUA_REFNIL) luaL_error(L, "mousegrabber already running"); - uint16_t cfont = xcursor_font_fromstr(luaL_checkstring(L, 2)); + xcb_cursor_t cursor = XCB_NONE; - if(cfont) + if(!lua_isnil(L, 2)) { - xcb_cursor_t cursor = xcursor_new(globalconf.cursor_ctx, cfont); - - luaA_registerfct(L, 1, &globalconf.mousegrabber); - - if(!mousegrabber_grab(cursor)) + uint16_t cfont = xcursor_font_fromstr(luaL_checkstring(L, 2)); + if(!cfont) { - luaA_unregister(L, &globalconf.mousegrabber); - luaL_error(L, "unable to grab mouse pointer"); + luaA_warn(L, "invalid cursor"); + return 0; } - } - else - luaA_warn(L, "invalid cursor"); + cursor = xcursor_new(globalconf.cursor_ctx, cfont); + } + + luaA_registerfct(L, 1, &globalconf.mousegrabber); + + if(!mousegrabber_grab(cursor)) + { + luaA_unregister(L, &globalconf.mousegrabber); + luaL_error(L, "unable to grab mouse pointer"); + } + return 0; }