2007-04-27 11:58:48 -06:00
|
|
|
/*
|
|
|
|
* calmwm - the calm window manager
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
|
|
|
*
|
2008-01-11 09:06:44 -07:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
2008-04-15 14:24:41 -06:00
|
|
|
* $Id: xutil.c,v 1.5 2008/04/15 20:24:41 oga Exp $
|
2007-04-27 11:58:48 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "headers.h"
|
|
|
|
#include "calmwm.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
xu_ptr_grab(Window win, int mask, Cursor curs)
|
|
|
|
{
|
2007-05-28 12:34:27 -06:00
|
|
|
return (XGrabPointer(X_Dpy, win, False, mask,
|
2007-04-27 11:58:48 -06:00
|
|
|
GrabModeAsync, GrabModeAsync,
|
|
|
|
None, curs, CurrentTime) == GrabSuccess ? 0 : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xu_ptr_regrab(int mask, Cursor curs)
|
|
|
|
{
|
2007-05-28 12:34:27 -06:00
|
|
|
return (XChangeActivePointerGrab(X_Dpy, mask,
|
2007-04-27 11:58:48 -06:00
|
|
|
curs, CurrentTime) == GrabSuccess ? 0 : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xu_ptr_ungrab(void)
|
|
|
|
{
|
2007-05-28 12:34:27 -06:00
|
|
|
XUngrabPointer(X_Dpy, CurrentTime);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xu_btn_grab(Window win, int mask, u_int btn)
|
|
|
|
{
|
2008-04-15 14:24:41 -06:00
|
|
|
return (XGrabButton(X_Dpy, btn, mask, win,
|
2007-04-27 11:58:48 -06:00
|
|
|
False, ButtonMask, GrabModeAsync,
|
|
|
|
GrabModeSync, None, None) == GrabSuccess ? 0 : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xu_btn_ungrab(Window win, int mask, u_int btn)
|
|
|
|
{
|
2007-05-28 12:34:27 -06:00
|
|
|
XUngrabButton(X_Dpy, btn, mask, win);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xu_ptr_getpos(Window rootwin, int *x, int *y)
|
|
|
|
{
|
|
|
|
int tmp0, tmp1;
|
|
|
|
u_int tmp2;
|
|
|
|
Window w0, w1;
|
|
|
|
|
2008-04-15 14:24:41 -06:00
|
|
|
XQueryPointer(X_Dpy, rootwin, &w0, &w1, &tmp0, &tmp1, x, y, &tmp2);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xu_ptr_setpos(Window win, int x, int y)
|
|
|
|
{
|
2007-05-28 12:34:27 -06:00
|
|
|
XWarpPointer(X_Dpy, None, win, 0, 0, 0, 0, x, y);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xu_key_grab(Window win, int mask, int keysym)
|
|
|
|
{
|
|
|
|
KeyCode code;
|
|
|
|
|
2007-05-28 12:34:27 -06:00
|
|
|
code = XKeysymToKeycode(X_Dpy, keysym);
|
|
|
|
if ((XKeycodeToKeysym(X_Dpy, code, 0) != keysym) &&
|
|
|
|
(XKeycodeToKeysym(X_Dpy, code, 1) == keysym))
|
2007-04-27 11:58:48 -06:00
|
|
|
mask |= ShiftMask;
|
|
|
|
|
2008-04-15 14:24:41 -06:00
|
|
|
XGrabKey(X_Dpy, XKeysymToKeycode(X_Dpy, keysym), mask, win, True,
|
2007-04-27 11:58:48 -06:00
|
|
|
GrabModeAsync, GrabModeAsync);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xu_sendmsg(struct client_ctx *cc, Atom atm, long val)
|
|
|
|
{
|
|
|
|
XEvent e;
|
|
|
|
|
|
|
|
memset(&e, 0, sizeof(e));
|
|
|
|
e.xclient.type = ClientMessage;
|
|
|
|
e.xclient.window = cc->win;
|
|
|
|
e.xclient.message_type = atm;
|
|
|
|
e.xclient.format = 32;
|
|
|
|
e.xclient.data.l[0] = val;
|
|
|
|
e.xclient.data.l[1] = CurrentTime;
|
|
|
|
|
2007-05-28 12:34:27 -06:00
|
|
|
XSendEvent(X_Dpy, cc->win, False, 0, &e);
|
2007-04-27 11:58:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xu_getprop(struct client_ctx *cc, Atom atm, Atom type, long len, u_char **p)
|
|
|
|
{
|
|
|
|
Atom realtype;
|
|
|
|
u_long n, extra;
|
|
|
|
int format;
|
|
|
|
|
2007-05-28 12:34:27 -06:00
|
|
|
if (XGetWindowProperty(X_Dpy, cc->win, atm, 0L, len, False, type,
|
2007-04-27 11:58:48 -06:00
|
|
|
&realtype, &format, &n, &extra, p) != Success || *p == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
XFree(*p);
|
|
|
|
|
|
|
|
return (n);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xu_getstate(struct client_ctx *cc, int *state)
|
|
|
|
{
|
2007-05-28 12:34:27 -06:00
|
|
|
Atom wm_state = XInternAtom(X_Dpy, "WM_STATE", False);
|
2007-04-27 11:58:48 -06:00
|
|
|
long *p = NULL;
|
|
|
|
|
|
|
|
if (xu_getprop(cc, wm_state, wm_state, 2L, (u_char **)&p) <= 0)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
*state = (int)*p;
|
|
|
|
XFree((char *)p);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xu_setstate(struct client_ctx *cc, int state)
|
|
|
|
{
|
|
|
|
long dat[2];
|
|
|
|
Atom wm_state;
|
|
|
|
|
|
|
|
/* XXX cache */
|
2007-05-28 12:34:27 -06:00
|
|
|
wm_state = XInternAtom(X_Dpy, "WM_STATE", False);
|
2007-04-27 11:58:48 -06:00
|
|
|
|
|
|
|
dat[0] = (long)state;
|
|
|
|
dat[1] = (long)None;
|
|
|
|
|
|
|
|
cc->state = state;
|
2007-05-28 12:34:27 -06:00
|
|
|
XChangeProperty(X_Dpy, cc->win, wm_state, wm_state, 32,
|
2007-04-27 11:58:48 -06:00
|
|
|
PropModeReplace, (unsigned char *)dat, 2);
|
|
|
|
}
|