/** Send fake events. Usually the current focused client will get it. * \param L The Lua VM state. * \return The number of element pushed on stack. * \luastack * \lparam The event type: key_press, key_release, button_press, button_release * or motion_notify. * \lparam 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 make the coordinates relatives. * \lparam In case of a motion event, this is the X coordinate. * \lparam In case of a motion event, this is the Y coordinate. * If not specified, the current one is used. */ 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; } const char *stype = luaL_checkstring(L, 1); uint8_t type, detail; int x = 0, y = 0; if (A_STREQ(stype, "key_press")) { type = XCB_KEY_PRESS; if(lua_type(L, 2) == LUA_TSTRING) { detail = _string_to_key_code(lua_tostring(L, 2)); /* keysym */ } else { detail = luaL_checknumber(L, 2); /* keycode */ } } else if(A_STREQ(stype, "key_release")) { type = XCB_KEY_RELEASE; if(lua_type(L, 2) == LUA_TSTRING) { detail = _string_to_key_code(lua_tostring(L, 2)); /* keysym */ } else { detail = luaL_checknumber(L, 2); /* keycode */ } } else if(A_STREQ(stype, "button_press")) { type = XCB_BUTTON_PRESS; detail = luaL_checknumber(L, 2); /* button number */ } else if(A_STREQ(stype, "button_release")) { type = XCB_BUTTON_RELEASE; detail = luaL_checknumber(L, 2); /* button number */ } else if(A_STREQ(stype, "motion_notify")) { type = XCB_MOTION_NOTIFY; detail = luaA_checkboolean(L, 2); /* relative to the current position or not */ x = luaL_checknumber(L, 3); y = luaL_checknumber(L, 4); } else return 0; xcb_test_fake_input(globalconf.connection, type, detail, XCB_CURRENT_TIME, XCB_NONE, x, y, 0); return 0; }
/** Send fake events. Usually the current focused client will get it. * \param L The Lua VM state. * \return The number of element pushed on stack. * \luastack * \lparam The event type: key_press, key_release, button_press, button_release * or motion_notify. * \lparam 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 make the coordinates relatives. * \lparam In case of a motion event, this is the X coordinate. * \lparam In case of a motion event, this is the Y coordinate. * \lparam In case of a motion event, this is the screen number to move on. * If not specified, the current one is used. */ 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; } size_t tlen; const char *stype = luaL_checklstring(L, 1, &tlen); uint8_t type, detail; int x = 0, y = 0; xcb_window_t root = XCB_NONE; switch(a_tokenize(stype, tlen)) { case A_TK_KEY_PRESS: type = XCB_KEY_PRESS; if(lua_type(L, 2) == LUA_TSTRING) { detail = _string_to_key_code(lua_tostring(L, 2)); } else { detail = luaL_checknumber(L, 2); /* keycode */ } break; case A_TK_KEY_RELEASE: type = XCB_KEY_RELEASE; if(lua_type(L, 2) == LUA_TSTRING) { detail = _string_to_key_code(lua_tostring(L, 2)); } else { detail = luaL_checknumber(L, 2); /* keycode */ } break; case A_TK_BUTTON_PRESS: type = XCB_BUTTON_PRESS; detail = luaL_checknumber(L, 2); /* button number */ break; case A_TK_BUTTON_RELEASE: type = XCB_BUTTON_RELEASE; detail = luaL_checknumber(L, 2); /* button number */ break; case A_TK_MOTION_NOTIFY: type = XCB_MOTION_NOTIFY; detail = luaA_checkboolean(L, 2); /* relative to the current position or not */ x = luaL_checknumber(L, 3); y = luaL_checknumber(L, 4); if(lua_gettop(L) == 5) { int screen = luaL_checknumber(L, 5) - 1; luaA_checkscreen(screen); root = globalconf.screens.tab[screen].x_screen->root; } break; default: return 0; } xcb_test_fake_input(globalconf.connection, type, detail, XCB_CURRENT_TIME, root, x, y, 0); return 0; }