Use instinsic X11 functions for key/btn/ptr grab/ungrab/regrab requests;

the one line wrappers provided no value and limited altering calls where
needed; additionally, most of them had but one caller.
This commit is contained in:
okan 2016-09-30 18:28:06 +00:00
parent e49083a483
commit 54cccf114b
5 changed files with 50 additions and 90 deletions

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $OpenBSD: calmwm.h,v 1.317 2016/09/30 15:12:19 okan Exp $
* $OpenBSD: calmwm.h,v 1.318 2016/09/30 18:28:06 okan Exp $
*/
#ifndef _CALMWM_H_
@ -542,17 +542,10 @@ void conf_screen(struct screen_ctx *);
void xev_process(void);
void xu_btn_grab(Window, int, unsigned int);
void xu_btn_ungrab(Window);
int xu_getprop(Window, Atom, Atom, long, unsigned char **);
int xu_getstrprop(Window, Atom, char **);
void xu_key_grab(Window, unsigned int, KeySym);
void xu_key_ungrab(Window);
void xu_ptr_getpos(Window, int *, int *);
int xu_ptr_grab(Window, unsigned int, Cursor);
int xu_ptr_regrab(unsigned int, Cursor);
void xu_ptr_setpos(Window, int, int);
void xu_ptr_ungrab(void);
void xu_xorcolor(XftColor, XftColor, XftColor *);
void xu_ewmh_net_supported(struct screen_ctx *);

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $OpenBSD: conf.c,v 1.207 2016/09/29 00:21:55 okan Exp $
* $OpenBSD: conf.c,v 1.208 2016/09/30 18:28:06 okan Exp $
*/
#include <sys/types.h>
@ -655,28 +655,48 @@ conf_cursor(struct conf *c)
c->cursor[i] = XCreateFontCursor(X_Dpy, cursor_binds[i]);
}
static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask };
void
conf_grab_mouse(Window win)
{
struct binding *mb;
unsigned int i;
xu_btn_ungrab(win);
XUngrabButton(X_Dpy, AnyButton, AnyModifier, win);
TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
if (mb->context == CWM_CONTEXT_CLIENT)
xu_btn_grab(win, mb->modmask, mb->press.button);
if (mb->context != CWM_CONTEXT_CLIENT)
continue;
for (i = 0; i < nitems(ign_mods); i++) {
XGrabButton(X_Dpy, mb->press.button,
(mb->modmask | ign_mods[i]), win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync,
None, None);
}
}
}
void
conf_grab_kbd(Window win)
{
struct binding *kb;
KeyCode kc;
unsigned int i;
xu_key_ungrab(win);
XUngrabKey(X_Dpy, AnyKey, AnyModifier, win);
TAILQ_FOREACH(kb, &Conf.keybindingq, entry)
xu_key_grab(win, kb->modmask, kb->press.keysym);
TAILQ_FOREACH(kb, &Conf.keybindingq, entry) {
kc = XKeysymToKeycode(X_Dpy, kb->press.keysym);
if ((XkbKeycodeToKeysym(X_Dpy, kc, 0, 0) != kb->press.keysym) &&
(XkbKeycodeToKeysym(X_Dpy, kc, 0, 1) == kb->press.keysym))
kb->modmask |= ShiftMask;
for (i = 0; i < nitems(ign_mods); i++)
XGrabKey(X_Dpy, kc, (kb->modmask | ign_mods[i]), win,
True, GrabModeAsync, GrabModeAsync);
}
}
static char *cwmhints[] = {

View File

@ -16,7 +16,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $OpenBSD: menu.c,v 1.95 2016/09/30 15:12:19 okan Exp $
* $OpenBSD: menu.c,v 1.96 2016/09/30 18:28:06 okan Exp $
*/
#include <sys/types.h>
@ -121,10 +121,12 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, const char *prompt,
XSelectInput(X_Dpy, sc->menu.win, evmask);
XMapRaised(X_Dpy, sc->menu.win);
if (xu_ptr_grab(sc->menu.win, MENUGRABMASK,
Conf.cursor[CF_QUESTION]) < 0) {
if (XGrabPointer(X_Dpy, sc->menu.win, False, MENUGRABMASK,
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_QUESTION],
CurrentTime) != GrabSuccess) {
XUnmapWindow(X_Dpy, sc->menu.win);
return(NULL);
}
XGetInputFocus(X_Dpy, &focuswin, &focusrevert);
@ -172,7 +174,7 @@ out:
xu_ptr_getpos(sc->rootwin, &xcur, &ycur);
if (xcur == mc.geom.x && ycur == mc.geom.y)
xu_ptr_setpos(sc->rootwin, xsave, ysave);
xu_ptr_ungrab();
XUngrabPointer(X_Dpy, CurrentTime);
XMoveResizeWindow(X_Dpy, sc->menu.win, 0, 0, 1, 1);
XUnmapWindow(X_Dpy, sc->menu.win);
@ -472,10 +474,13 @@ menu_handle_move(XEvent *e, struct menu_ctx *mc, struct menu_q *resultq)
if (mc->prev != -1)
menu_draw_entry(mc, resultq, mc->prev, 0);
if (mc->entry != -1) {
(void)xu_ptr_regrab(MENUGRABMASK, Conf.cursor[CF_NORMAL]);
XChangeActivePointerGrab(X_Dpy, MENUGRABMASK,
Conf.cursor[CF_NORMAL], CurrentTime);
menu_draw_entry(mc, resultq, mc->entry, 1);
} else
(void)xu_ptr_regrab(MENUGRABMASK, Conf.cursor[CF_DEFAULT]);
} else {
XChangeActivePointerGrab(X_Dpy, MENUGRABMASK,
Conf.cursor[CF_DEFAULT], CurrentTime);
}
}
static struct menu *

View File

@ -16,7 +16,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $OpenBSD: mousefunc.c,v 1.110 2016/09/30 15:12:19 okan Exp $
* $OpenBSD: mousefunc.c,v 1.111 2016/09/30 18:28:06 okan Exp $
*/
#include <sys/types.h>
@ -45,7 +45,9 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg)
client_raise(cc);
client_ptrsave(cc);
if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_RESIZE]) < 0)
if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE],
CurrentTime) != GrabSuccess)
return;
xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h);
@ -71,7 +73,7 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg)
client_resize(cc, 1);
XUnmapWindow(X_Dpy, sc->menu.win);
XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0);
xu_ptr_ungrab();
XUngrabPointer(X_Dpy, CurrentTime);
/* Make sure the pointer stays within the window. */
if (cc->ptr.x > cc->geom.w)
@ -99,7 +101,9 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg)
if (cc->flags & CLIENT_FREEZE)
return;
if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_MOVE]) < 0)
if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_MOVE],
CurrentTime) != GrabSuccess)
return;
xu_ptr_getpos(cc->win, &px, &py);
@ -134,7 +138,7 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg)
client_move(cc);
XUnmapWindow(X_Dpy, sc->menu.win);
XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0);
xu_ptr_ungrab();
XUngrabPointer(X_Dpy, CurrentTime);
return;
}
}

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $OpenBSD: xutil.c,v 1.105 2016/09/28 17:06:33 okan Exp $
* $OpenBSD: xutil.c,v 1.106 2016/09/30 18:28:06 okan Exp $
*/
#include <sys/types.h>
@ -31,68 +31,6 @@
#include "calmwm.h"
static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask };
void
xu_btn_grab(Window win, int mask, unsigned int btn)
{
unsigned int i;
for (i = 0; i < nitems(ign_mods); i++)
XGrabButton(X_Dpy, btn, (mask | ign_mods[i]), win,
False, BUTTONMASK, GrabModeAsync,
GrabModeSync, None, None);
}
void
xu_btn_ungrab(Window win)
{
XUngrabButton(X_Dpy, AnyButton, AnyModifier, win);
}
void
xu_key_grab(Window win, unsigned int mask, KeySym keysym)
{
KeyCode code;
unsigned int i;
code = XKeysymToKeycode(X_Dpy, keysym);
if ((XkbKeycodeToKeysym(X_Dpy, code, 0, 0) != keysym) &&
(XkbKeycodeToKeysym(X_Dpy, code, 0, 1) == keysym))
mask |= ShiftMask;
for (i = 0; i < nitems(ign_mods); i++)
XGrabKey(X_Dpy, code, (mask | ign_mods[i]), win,
True, GrabModeAsync, GrabModeAsync);
}
void
xu_key_ungrab(Window win)
{
XUngrabKey(X_Dpy, AnyKey, AnyModifier, win);
}
int
xu_ptr_grab(Window win, unsigned int mask, Cursor curs)
{
return(XGrabPointer(X_Dpy, win, False, mask,
GrabModeAsync, GrabModeAsync,
None, curs, CurrentTime) == GrabSuccess ? 0 : -1);
}
int
xu_ptr_regrab(unsigned int mask, Cursor curs)
{
return(XChangeActivePointerGrab(X_Dpy, mask,
curs, CurrentTime) == GrabSuccess ? 0 : -1);
}
void
xu_ptr_ungrab(void)
{
XUngrabPointer(X_Dpy, CurrentTime);
}
void
xu_ptr_getpos(Window win, int *x, int *y)
{