/** Grab the mouse pointer and list motions, calling callback function at each * motion. The callback function must return a boolean value: true to * continue grabbing, false to stop. * The function is called with one argument: * a table containing modifiers pointer coordinates. * * \param L The Lua VM state. * \return The number of elements pushed on stack. * * \luastack * * \lparam A callback function as described above. */ static int 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)); if(cfont) { xcb_cursor_t cursor = xcursor_new(globalconf.display, cfont); luaA_registerfct(L, 1, &globalconf.mousegrabber); if(!mousegrabber_grab(cursor)) { luaA_unregister(L, &globalconf.mousegrabber); luaL_error(L, "unable to grab mouse pointer"); } } else luaA_warn(L, "invalid cursor"); return 0; }
/** Initialize a drawin. * \param w The drawin to initialize. */ static void drawin_init(drawin_t *w) { xcb_screen_t *s = globalconf.screen; w->window = xcb_generate_id(globalconf.connection); xcb_create_window(globalconf.connection, globalconf.default_depth, w->window, s->root, w->geometry.x, w->geometry.y, w->geometry.width, w->geometry.height, w->border_width, XCB_COPY_FROM_PARENT, globalconf.visual->visual_id, XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_BIT_GRAVITY | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP | XCB_CW_CURSOR, (const uint32_t []) { w->bg_color.pixel, w->border_color.pixel, XCB_GRAVITY_NORTH_WEST, 1, XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_PROPERTY_CHANGE, globalconf.default_cmap, xcursor_new(globalconf.connection, xcursor_font_fromstr(w->cursor)) });
/** Set the root cursor. * \param L The Lua VM state. * \return The number of element pushed on stack. * \luastack * \lparam A X cursor name. */ 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) { uint32_t change_win_vals[] = { xcursor_new(globalconf.connection, cursor_font) }; xcb_change_window_attributes(globalconf.connection, globalconf.screen->root, XCB_CW_CURSOR, change_win_vals); } else luaA_warn(L, "invalid cursor %s", cursor_name); return 0; }
/** Set the root cursor. * \param L The Lua VM state. * \return The number of element pushed on stack. * \luastack * \lparam A X cursor name. */ 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) { uint32_t change_win_vals[] = { xcursor_new(globalconf.connection, cursor_font) }; for(int screen_nbr = 0; screen_nbr < xcb_setup_roots_length(xcb_get_setup(globalconf.connection)); screen_nbr++) xcb_change_window_attributes(globalconf.connection, xutil_screen_get(globalconf.connection, screen_nbr)->root, XCB_CW_CURSOR, change_win_vals); } else luaA_warn(L, "invalid cursor %s", cursor_name); return 0; }