2007-04-27 21:58:48 +04:00
|
|
|
/*
|
|
|
|
* calmwm - the calm window manager
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Marius Aamodt Eriksen <marius@monkey.org>
|
2008-01-11 19:06:44 +03: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.
|
2007-04-27 21:58:48 +04:00
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "headers.h"
|
|
|
|
#include "calmwm.h"
|
|
|
|
|
2008-04-16 00:24:41 +04:00
|
|
|
int _inwindowbounds(struct client_ctx *, int, int);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-04-16 00:24:41 +04:00
|
|
|
static char emptystring[] = "";
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-04-16 00:24:41 +04:00
|
|
|
struct client_ctx *_curcc = NULL;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
client_setup(void)
|
|
|
|
{
|
2007-05-28 22:34:27 +04:00
|
|
|
TAILQ_INIT(&Clientq);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct client_ctx *
|
|
|
|
client_find(Window win)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct client_ctx *cc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
TAILQ_FOREACH(cc, &Clientq, entry)
|
2007-04-27 21:58:48 +04:00
|
|
|
if (cc->pwin == win || cc->win == win)
|
|
|
|
return (cc);
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct client_ctx *
|
|
|
|
client_new(Window win, struct screen_ctx *sc, int mapped)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct client_ctx *cc;
|
|
|
|
XSetWindowAttributes pxattr;
|
|
|
|
XWindowAttributes wattr;
|
|
|
|
XWMHints *wmhints;
|
|
|
|
long tmp;
|
|
|
|
int x, y, height, width, state;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (win == None)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
XCALLOC(cc, struct client_ctx);
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XGrabServer(X_Dpy);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
cc->state = mapped ? NormalState : IconicState;
|
|
|
|
cc->sc = sc;
|
|
|
|
cc->win = win;
|
2008-04-16 00:24:41 +04:00
|
|
|
cc->size = XAllocSizeHints();
|
2007-04-27 21:58:48 +04:00
|
|
|
if (cc->size->width_inc == 0)
|
|
|
|
cc->size->width_inc = 1;
|
|
|
|
if (cc->size->height_inc == 0)
|
|
|
|
cc->size->height_inc = 1;
|
|
|
|
|
|
|
|
TAILQ_INIT(&cc->nameq);
|
|
|
|
client_setname(cc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* conf_client() needs at least cc->win and cc->name
|
|
|
|
*/
|
|
|
|
conf_client(cc);
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XGetWMNormalHints(X_Dpy, cc->win, cc->size, &tmp);
|
|
|
|
XGetWindowAttributes(X_Dpy, cc->win, &wattr);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (cc->size->flags & PBaseSize) {
|
|
|
|
cc->geom.min_dx = cc->size->base_width;
|
|
|
|
cc->geom.min_dy = cc->size->base_height;
|
|
|
|
} else if (cc->size->flags & PMinSize) {
|
|
|
|
cc->geom.min_dx = cc->size->min_width;
|
|
|
|
cc->geom.min_dy = cc->size->min_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Saved pointer position */
|
|
|
|
cc->ptr.x = -1;
|
|
|
|
cc->ptr.y = -1;
|
|
|
|
|
|
|
|
client_gravitate(cc, 1);
|
|
|
|
|
|
|
|
cc->geom.x = wattr.x;
|
|
|
|
cc->geom.y = wattr.y;
|
|
|
|
cc->geom.width = wattr.width;
|
|
|
|
cc->geom.height = wattr.height;
|
|
|
|
cc->cmap = wattr.colormap;
|
|
|
|
|
|
|
|
if (wattr.map_state != IsViewable) {
|
|
|
|
client_placecalc(cc);
|
2007-05-28 22:34:27 +04:00
|
|
|
if ((wmhints = XGetWMHints(X_Dpy, cc->win)) != NULL) {
|
2007-04-27 21:58:48 +04:00
|
|
|
if (wmhints->flags & StateHint)
|
|
|
|
xu_setstate(cc, wmhints->initial_state);
|
|
|
|
|
|
|
|
XFree(wmhints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xu_getstate(cc, &state) < 0)
|
|
|
|
state = NormalState;
|
|
|
|
|
2008-05-16 01:56:21 +04:00
|
|
|
XSelectInput(X_Dpy, cc->win, ColormapChangeMask | EnterWindowMask |
|
|
|
|
PropertyChangeMask | KeyReleaseMask);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
x = cc->geom.x - cc->bwidth;
|
|
|
|
y = cc->geom.y - cc->bwidth;
|
|
|
|
|
|
|
|
width = cc->geom.width;
|
|
|
|
height = cc->geom.height;
|
|
|
|
if (cc->bwidth > 1) {
|
|
|
|
width += (cc->bwidth)*2;
|
|
|
|
height += (cc->bwidth)*2;
|
|
|
|
}
|
|
|
|
pxattr.override_redirect = True;
|
|
|
|
pxattr.background_pixel = sc->bgcolor.pixel;
|
2008-05-16 01:56:21 +04:00
|
|
|
pxattr.event_mask = ChildMask | ButtonPressMask | ButtonReleaseMask |
|
|
|
|
ExposureMask | EnterWindowMask;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
cc->pwin = XCreateWindow(X_Dpy, sc->rootwin, x, y,
|
2007-04-27 21:58:48 +04:00
|
|
|
width, height, 0, /* XXX */
|
2007-05-28 22:34:27 +04:00
|
|
|
DefaultDepth(X_Dpy, sc->which), CopyFromParent,
|
|
|
|
DefaultVisual(X_Dpy, sc->which),
|
2007-04-27 21:58:48 +04:00
|
|
|
CWOverrideRedirect | CWBackPixel | CWEventMask, &pxattr);
|
|
|
|
|
|
|
|
cc->active = 0;
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XAddToSaveSet(X_Dpy, cc->win);
|
|
|
|
XSetWindowBorderWidth(X_Dpy, cc->win, 0);
|
|
|
|
XReparentWindow(X_Dpy, cc->win, cc->pwin, cc->bwidth, cc->bwidth);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
/* Notify client of its configuration. */
|
|
|
|
xev_reconfig(cc);
|
|
|
|
|
2007-06-08 20:29:19 +04:00
|
|
|
if (state == IconicState)
|
|
|
|
client_hide(cc);
|
|
|
|
else {
|
|
|
|
XMapRaised(X_Dpy, cc->pwin);
|
|
|
|
XMapWindow(X_Dpy, cc->win);
|
|
|
|
}
|
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
xu_setstate(cc, cc->state);
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XSync(X_Dpy, False);
|
|
|
|
XUngrabServer(X_Dpy);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&sc->mruq, cc, mru_entry);
|
2007-05-28 22:34:27 +04:00
|
|
|
TAILQ_INSERT_TAIL(&Clientq, cc, entry);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
client_gethints(cc);
|
|
|
|
client_update(cc);
|
2008-04-16 00:24:41 +04:00
|
|
|
|
2008-05-16 01:56:21 +04:00
|
|
|
if (mapped)
|
2008-03-22 18:09:45 +03:00
|
|
|
group_autogroup(cc);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
return (cc);
|
|
|
|
}
|
|
|
|
|
2008-05-17 07:59:54 +04:00
|
|
|
void
|
|
|
|
client_do_shape(struct client_ctx *cc)
|
|
|
|
{
|
|
|
|
/* Windows not rectangular require more effort */
|
2008-07-11 18:21:28 +04:00
|
|
|
XRectangle *r;
|
|
|
|
int n, tmp;
|
2008-05-17 07:59:54 +04:00
|
|
|
|
|
|
|
if (Doshape) {
|
|
|
|
XShapeSelectInput(X_Dpy, cc->win, ShapeNotifyMask);
|
|
|
|
|
|
|
|
r = XShapeGetRectangles(X_Dpy, cc->win, ShapeBounding,
|
|
|
|
&n, &tmp);
|
|
|
|
|
|
|
|
if (n > 1)
|
|
|
|
XShapeCombineShape(X_Dpy, cc->pwin, ShapeBounding,
|
|
|
|
cc->bwidth, cc->bwidth, cc->win, ShapeBounding,
|
|
|
|
ShapeSet);
|
|
|
|
XFree(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
int
|
|
|
|
client_delete(struct client_ctx *cc, int sendevent, int ignorewindow)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
|
|
|
struct winname *wn;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (cc->state == IconicState && !sendevent)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
group_client_delete(cc);
|
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
XGrabServer(X_Dpy);
|
2007-04-27 21:58:48 +04:00
|
|
|
xu_setstate(cc, WithdrawnState);
|
2007-05-28 22:34:27 +04:00
|
|
|
XRemoveFromSaveSet(X_Dpy, cc->win);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (!ignorewindow) {
|
|
|
|
client_gravitate(cc, 0);
|
2007-05-28 22:34:27 +04:00
|
|
|
XSetWindowBorderWidth(X_Dpy, cc->win, 1); /* XXX */
|
|
|
|
XReparentWindow(X_Dpy, cc->win,
|
2007-04-27 21:58:48 +04:00
|
|
|
sc->rootwin, cc->geom.x, cc->geom.y);
|
|
|
|
}
|
|
|
|
if (cc->pwin)
|
2007-05-28 22:34:27 +04:00
|
|
|
XDestroyWindow(X_Dpy, cc->pwin);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XSync(X_Dpy, False);
|
|
|
|
XUngrabServer(X_Dpy);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
TAILQ_REMOVE(&sc->mruq, cc, mru_entry);
|
2007-05-28 22:34:27 +04:00
|
|
|
TAILQ_REMOVE(&Clientq, cc, entry);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (_curcc == cc)
|
|
|
|
_curcc = NULL;
|
|
|
|
|
|
|
|
XFree(cc->size);
|
|
|
|
|
|
|
|
while ((wn = TAILQ_FIRST(&cc->nameq)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&cc->nameq, wn, entry);
|
|
|
|
if (wn->name != emptystring)
|
|
|
|
XFree(wn->name);
|
|
|
|
xfree(wn);
|
|
|
|
}
|
|
|
|
|
|
|
|
client_freehints(cc);
|
|
|
|
|
|
|
|
xfree(cc);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_leave(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (cc == NULL)
|
|
|
|
cc = _curcc;
|
|
|
|
if (cc == NULL)
|
|
|
|
return;
|
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
sc = CCTOSC(cc);
|
2007-04-27 21:58:48 +04:00
|
|
|
xu_btn_ungrab(sc->rootwin, AnyModifier, Button1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_setactive(struct client_ctx *cc, int fg)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (cc == NULL)
|
|
|
|
cc = _curcc;
|
|
|
|
if (cc == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sc = CCTOSC(cc);
|
|
|
|
|
|
|
|
if (fg) {
|
2007-05-28 22:34:27 +04:00
|
|
|
XInstallColormap(X_Dpy, cc->cmap);
|
|
|
|
XSetInputFocus(X_Dpy, cc->win,
|
2007-04-27 21:58:48 +04:00
|
|
|
RevertToPointerRoot, CurrentTime);
|
2008-06-26 02:37:29 +04:00
|
|
|
conf_grab_mouse(cc);
|
2007-04-27 21:58:48 +04:00
|
|
|
/*
|
|
|
|
* If we're in the middle of alt-tabbing, don't change
|
|
|
|
* the order please.
|
|
|
|
*/
|
|
|
|
if (!sc->altpersist)
|
|
|
|
client_mtf(cc);
|
|
|
|
} else
|
|
|
|
client_leave(cc);
|
|
|
|
|
|
|
|
if (fg && _curcc != cc) {
|
|
|
|
client_setactive(NULL, 0);
|
|
|
|
_curcc = cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
cc->active = fg;
|
|
|
|
client_draw_border(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct client_ctx *
|
|
|
|
client_current(void)
|
|
|
|
{
|
|
|
|
return (_curcc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_gravitate(struct client_ctx *cc, int yes)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
int dx = 0, dy = 0, mult = yes ? 1 : -1;
|
|
|
|
int gravity = (cc->size->flags & PWinGravity) ?
|
|
|
|
cc->size->win_gravity : NorthWestGravity;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-04-16 00:24:41 +04:00
|
|
|
switch (gravity) {
|
2007-04-27 21:58:48 +04:00
|
|
|
case NorthWestGravity:
|
|
|
|
case SouthWestGravity:
|
|
|
|
case NorthEastGravity:
|
|
|
|
case StaticGravity:
|
|
|
|
dx = cc->bwidth;
|
|
|
|
case NorthGravity:
|
|
|
|
dy = cc->bwidth;
|
|
|
|
break;
|
2008-04-16 00:24:41 +04:00
|
|
|
}
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
cc->geom.x += mult * dx;
|
|
|
|
cc->geom.y += mult * dy;
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_maximize(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-16 02:06:48 +04:00
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
if (cc->flags & CLIENT_MAXIMIZED) {
|
|
|
|
cc->geom = cc->savegeom;
|
|
|
|
} else {
|
2008-03-26 18:45:42 +03:00
|
|
|
if (!(cc->flags & CLIENT_VMAXIMIZED))
|
|
|
|
cc->savegeom = cc->geom;
|
2008-09-22 18:28:04 +04:00
|
|
|
cc->geom.x = Conf.gap_left;
|
|
|
|
cc->geom.y = Conf.gap_top;
|
|
|
|
cc->geom.height = sc->ymax - (Conf.gap_top + Conf.gap_bottom);
|
|
|
|
cc->geom.width = sc->xmax - (Conf.gap_left + Conf.gap_right);
|
|
|
|
cc->flags |= CLIENT_DOMAXIMIZE;
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
client_resize(cc);
|
|
|
|
}
|
|
|
|
|
2008-07-16 02:12:09 +04:00
|
|
|
void
|
|
|
|
client_vertmaximize(struct client_ctx *cc)
|
|
|
|
{
|
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
|
|
|
|
|
|
|
if (cc->flags & CLIENT_VMAXIMIZED) {
|
|
|
|
cc->geom = cc->savegeom;
|
|
|
|
} else {
|
|
|
|
if (!(cc->flags & CLIENT_MAXIMIZED))
|
|
|
|
cc->savegeom = cc->geom;
|
2008-09-22 18:28:04 +04:00
|
|
|
cc->geom.y = cc->bwidth + Conf.gap_top;
|
|
|
|
cc->geom.height = (sc->ymax - cc->bwidth * 2) -
|
|
|
|
(Conf.gap_top + Conf.gap_bottom);
|
|
|
|
cc->flags |= CLIENT_DOVMAXIMIZE;
|
2008-07-16 02:12:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
client_resize(cc);
|
|
|
|
}
|
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
void
|
|
|
|
client_resize(struct client_ctx *cc)
|
|
|
|
{
|
2008-03-26 18:45:42 +03:00
|
|
|
if (cc->flags & (CLIENT_MAXIMIZED | CLIENT_VMAXIMIZED))
|
|
|
|
cc->flags &= ~(CLIENT_MAXIMIZED | CLIENT_VMAXIMIZED);
|
|
|
|
|
|
|
|
if (cc->flags & CLIENT_DOMAXIMIZE) {
|
|
|
|
cc->flags &= ~CLIENT_DOMAXIMIZE;
|
|
|
|
cc->flags |= CLIENT_MAXIMIZED;
|
|
|
|
} else if (cc->flags & CLIENT_DOVMAXIMIZE) {
|
|
|
|
cc->flags &= ~CLIENT_DOVMAXIMIZE;
|
|
|
|
cc->flags |= CLIENT_VMAXIMIZED;
|
|
|
|
}
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XMoveResizeWindow(X_Dpy, cc->pwin, cc->geom.x - cc->bwidth,
|
2007-04-27 21:58:48 +04:00
|
|
|
cc->geom.y - cc->bwidth, cc->geom.width + cc->bwidth*2,
|
|
|
|
cc->geom.height + cc->bwidth*2);
|
2007-05-28 22:34:27 +04:00
|
|
|
XMoveResizeWindow(X_Dpy, cc->win, cc->bwidth, cc->bwidth,
|
2007-04-27 21:58:48 +04:00
|
|
|
cc->geom.width, cc->geom.height);
|
|
|
|
xev_reconfig(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_move(struct client_ctx *cc)
|
|
|
|
{
|
2007-05-28 22:34:27 +04:00
|
|
|
XMoveWindow(X_Dpy, cc->pwin,
|
2007-04-27 21:58:48 +04:00
|
|
|
cc->geom.x - cc->bwidth, cc->geom.y - cc->bwidth);
|
|
|
|
xev_reconfig(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_lower(struct client_ctx *cc)
|
|
|
|
{
|
2007-05-28 22:34:27 +04:00
|
|
|
XLowerWindow(X_Dpy, cc->pwin);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_raise(struct client_ctx *cc)
|
|
|
|
{
|
2007-05-28 22:34:27 +04:00
|
|
|
XRaiseWindow(X_Dpy, cc->pwin);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_ptrwarp(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
int x = cc->ptr.x, y = cc->ptr.y;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (x == -1 || y == -1) {
|
|
|
|
x = cc->geom.width / 2;
|
|
|
|
y = cc->geom.height / 2;
|
|
|
|
}
|
|
|
|
|
2007-05-30 02:38:44 +04:00
|
|
|
if (cc->state == IconicState)
|
|
|
|
client_unhide(cc);
|
|
|
|
else
|
|
|
|
client_raise(cc);
|
|
|
|
|
2007-04-27 21:58:48 +04:00
|
|
|
xu_ptr_setpos(cc->pwin, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_ptrsave(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
int x, y;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
xu_ptr_getpos(cc->pwin, &x, &y);
|
2008-04-16 00:24:41 +04:00
|
|
|
if (_inwindowbounds(cc, x, y)) {
|
2007-04-27 21:58:48 +04:00
|
|
|
cc->ptr.x = x;
|
|
|
|
cc->ptr.y = y;
|
2008-04-16 00:24:41 +04:00
|
|
|
}
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_hide(struct client_ctx *cc)
|
|
|
|
{
|
|
|
|
/* XXX - add wm_state stuff */
|
2007-05-28 22:34:27 +04:00
|
|
|
XUnmapWindow(X_Dpy, cc->pwin);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
cc->active = 0;
|
|
|
|
cc->flags |= CLIENT_HIDDEN;
|
|
|
|
xu_setstate(cc, IconicState);
|
|
|
|
|
|
|
|
if (cc == _curcc)
|
|
|
|
_curcc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_unhide(struct client_ctx *cc)
|
|
|
|
{
|
2007-05-28 22:34:27 +04:00
|
|
|
XMapRaised(X_Dpy, cc->pwin);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-05-19 16:56:58 +04:00
|
|
|
cc->highlight = 0;
|
2007-04-27 21:58:48 +04:00
|
|
|
cc->flags &= ~CLIENT_HIDDEN;
|
|
|
|
xu_setstate(cc, NormalState);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_draw_border(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (cc->active) {
|
2007-05-28 22:34:27 +04:00
|
|
|
XSetWindowBackground(X_Dpy, cc->pwin, client_bg_pixel(cc));
|
|
|
|
XClearWindow(X_Dpy, cc->pwin);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (!cc->highlight && cc->bwidth > 1)
|
2007-05-28 22:34:27 +04:00
|
|
|
XDrawRectangle(X_Dpy, cc->pwin, sc->gc, 1, 1,
|
2007-04-27 21:58:48 +04:00
|
|
|
cc->geom.width + cc->bwidth,
|
|
|
|
cc->geom.height + cc->bwidth);
|
|
|
|
} else {
|
|
|
|
if (cc->bwidth > 1)
|
2007-05-28 22:34:27 +04:00
|
|
|
XSetWindowBackgroundPixmap(X_Dpy,
|
2007-04-27 21:58:48 +04:00
|
|
|
cc->pwin, client_bg_pixmap(cc));
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XClearWindow(X_Dpy, cc->pwin);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u_long
|
|
|
|
client_bg_pixel(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
|
|
|
u_long pixl;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
switch (cc->highlight) {
|
|
|
|
case CLIENT_HIGHLIGHT_BLUE:
|
|
|
|
pixl = sc->bluepixl;
|
|
|
|
break;
|
|
|
|
case CLIENT_HIGHLIGHT_RED:
|
|
|
|
pixl = sc->redpixl;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pixl = sc->blackpixl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (pixl);
|
|
|
|
}
|
|
|
|
|
|
|
|
Pixmap
|
|
|
|
client_bg_pixmap(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
|
|
|
Pixmap pix;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
switch (cc->highlight) {
|
|
|
|
case CLIENT_HIGHLIGHT_BLUE:
|
|
|
|
pix = sc->blue;
|
|
|
|
break;
|
|
|
|
case CLIENT_HIGHLIGHT_RED:
|
|
|
|
pix = sc->red;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pix = sc->gray;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (pix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_update(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
Atom *p, wm_delete, wm_protocols, wm_take_focus;
|
|
|
|
int i;
|
|
|
|
long n;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
/* XXX cache these. */
|
2007-05-28 22:34:27 +04:00
|
|
|
wm_delete = XInternAtom(X_Dpy, "WM_DELETE_WINDOW", False);
|
|
|
|
wm_protocols = XInternAtom(X_Dpy, "WM_PROTOCOLS", False);
|
|
|
|
wm_take_focus = XInternAtom(X_Dpy, "WM_TAKE_FOCUS", False);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if ((n = xu_getprop(cc, wm_protocols,
|
|
|
|
XA_ATOM, 20L, (u_char **)&p)) <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
if (p[i] == wm_delete)
|
|
|
|
cc->xproto |= CLIENT_PROTO_DELETE;
|
|
|
|
else if (p[i] == wm_take_focus)
|
|
|
|
cc->xproto |= CLIENT_PROTO_TAKEFOCUS;
|
|
|
|
|
|
|
|
XFree(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_send_delete(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
Atom wm_delete, wm_protocols;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
/* XXX - cache */
|
2007-05-28 22:34:27 +04:00
|
|
|
wm_delete = XInternAtom(X_Dpy, "WM_DELETE_WINDOW", False);
|
|
|
|
wm_protocols = XInternAtom(X_Dpy, "WM_PROTOCOLS", False);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (cc->xproto & CLIENT_PROTO_DELETE)
|
|
|
|
xu_sendmsg(cc, wm_protocols, wm_delete);
|
|
|
|
else
|
2007-05-28 22:34:27 +04:00
|
|
|
XKillClient(X_Dpy, cc->win);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_setname(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct winname *wn;
|
|
|
|
char *newname;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
XFetchName(X_Dpy, cc->win, &newname);
|
2007-04-27 21:58:48 +04:00
|
|
|
if (newname == NULL)
|
|
|
|
newname = emptystring;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(wn, &cc->nameq, entry)
|
|
|
|
if (strcmp(wn->name, newname) == 0) {
|
|
|
|
/* Move to the last since we got a hit. */
|
|
|
|
TAILQ_REMOVE(&cc->nameq, wn, entry);
|
|
|
|
TAILQ_INSERT_TAIL(&cc->nameq, wn, entry);
|
|
|
|
goto match;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMALLOC(wn, struct winname);
|
|
|
|
wn->name = newname;
|
|
|
|
TAILQ_INSERT_TAIL(&cc->nameq, wn, entry);
|
|
|
|
cc->nameqlen++;
|
|
|
|
|
|
|
|
match:
|
|
|
|
cc->name = wn->name;
|
|
|
|
|
|
|
|
/* Now, do some garbage collection. */
|
|
|
|
if (cc->nameqlen > CLIENT_MAXNAMEQLEN) {
|
|
|
|
wn = TAILQ_FIRST(&cc->nameq);
|
|
|
|
assert(wn != NULL);
|
|
|
|
TAILQ_REMOVE(&cc->nameq, wn, entry);
|
|
|
|
if (wn->name != emptystring)
|
|
|
|
XFree(wn->name);
|
|
|
|
xfree(wn);
|
|
|
|
cc->nameqlen--;
|
|
|
|
}
|
|
|
|
|
2008-04-16 00:24:41 +04:00
|
|
|
return;
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct client_ctx *
|
2008-05-19 21:24:19 +04:00
|
|
|
client_cycle(int reverse)
|
2007-04-27 21:58:48 +04:00
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct client_ctx *oldcc, *newcc;
|
|
|
|
struct screen_ctx *sc;
|
2008-05-01 22:01:13 +04:00
|
|
|
int again = 1;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
oldcc = client_current();
|
|
|
|
sc = screen_current();
|
|
|
|
|
2008-05-01 22:01:13 +04:00
|
|
|
/* If no windows then you cant cycle */
|
|
|
|
if (TAILQ_EMPTY(&sc->mruq))
|
|
|
|
return (NULL);
|
2007-06-05 23:03:20 +04:00
|
|
|
|
2008-05-01 22:01:13 +04:00
|
|
|
if (oldcc == NULL)
|
|
|
|
oldcc = (reverse ? TAILQ_LAST(&sc->mruq, cycle_entry_q) :
|
|
|
|
TAILQ_FIRST(&sc->mruq));
|
2007-06-05 23:03:20 +04:00
|
|
|
|
2008-05-01 22:01:13 +04:00
|
|
|
newcc = oldcc;
|
|
|
|
while (again) {
|
|
|
|
again = 0;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-05-01 22:01:13 +04:00
|
|
|
newcc = (reverse ? client_mruprev(newcc) :
|
|
|
|
client_mrunext(newcc));
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-06-30 21:52:37 +04:00
|
|
|
/* Only cycle visible and non-ignored windows. */
|
|
|
|
if (newcc->flags & (CLIENT_HIDDEN|CLIENT_IGNORE))
|
2008-05-01 22:01:13 +04:00
|
|
|
again = 1;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-05-01 22:01:13 +04:00
|
|
|
/* Is oldcc the only non-hidden window? */
|
|
|
|
if (newcc == oldcc) {
|
|
|
|
if (again)
|
|
|
|
return (NULL); /* No windows visible. */
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-05-19 19:17:50 +04:00
|
|
|
break;
|
2008-05-01 22:01:13 +04:00
|
|
|
}
|
|
|
|
}
|
2008-05-19 19:17:50 +04:00
|
|
|
|
2008-05-01 22:01:13 +04:00
|
|
|
/* reset when alt is released. XXX I hate this hack */
|
|
|
|
sc->altpersist = 1;
|
|
|
|
client_ptrsave(oldcc);
|
|
|
|
client_ptrwarp(newcc);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-05-01 22:01:13 +04:00
|
|
|
return (newcc);
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct client_ctx *
|
|
|
|
client_mrunext(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
|
|
|
struct client_ctx *ccc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
return ((ccc = TAILQ_NEXT(cc, mru_entry)) != NULL ?
|
|
|
|
ccc : TAILQ_FIRST(&sc->mruq));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct client_ctx *
|
|
|
|
client_mruprev(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
|
|
|
struct client_ctx *ccc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
return ((ccc = TAILQ_PREV(cc, cycle_entry_q, mru_entry)) != NULL ?
|
|
|
|
ccc : TAILQ_LAST(&sc->mruq, cycle_entry_q));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_placecalc(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc = CCTOSC(cc);
|
|
|
|
int yslack, xslack, xmouse, ymouse;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-09-22 18:28:04 +04:00
|
|
|
yslack = sc->ymax - cc->geom.height - cc->bwidth;
|
|
|
|
xslack = sc->xmax - cc->geom.width - cc->bwidth;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-06-12 08:59:51 +04:00
|
|
|
xu_ptr_getpos(sc->rootwin, &xmouse, &ymouse);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-07-11 18:21:28 +04:00
|
|
|
xmouse = MAX(xmouse, cc->bwidth) - cc->geom.width / 2;
|
|
|
|
ymouse = MAX(ymouse, cc->bwidth) - cc->geom.height / 2;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2008-06-12 08:59:51 +04:00
|
|
|
xmouse = MAX(xmouse, (int)cc->bwidth);
|
|
|
|
ymouse = MAX(ymouse, (int)cc->bwidth);
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (cc->size->flags & USPosition) {
|
2008-09-22 18:28:04 +04:00
|
|
|
if (cc->size->x >= 0)
|
2008-06-12 08:59:51 +04:00
|
|
|
cc->geom.x = MAX(MIN(cc->size->x, xslack), cc->bwidth);
|
|
|
|
else
|
2008-09-22 18:28:04 +04:00
|
|
|
cc->geom.x = cc->bwidth;
|
|
|
|
if (cc->size->y >= 0)
|
2008-06-12 08:59:51 +04:00
|
|
|
cc->geom.y = MAX(MIN(cc->size->y, yslack), cc->bwidth);
|
|
|
|
else
|
2008-09-22 18:28:04 +04:00
|
|
|
cc->geom.y = cc->bwidth;
|
2007-04-27 21:58:48 +04:00
|
|
|
} else {
|
2008-09-22 18:28:04 +04:00
|
|
|
if (xslack >= 0) {
|
2008-06-12 08:59:51 +04:00
|
|
|
cc->geom.x = MAX(MIN(xmouse, xslack),
|
2008-09-22 18:28:04 +04:00
|
|
|
Conf.gap_left + cc->bwidth);
|
2008-06-12 08:59:51 +04:00
|
|
|
if (cc->geom.x > (xslack - Conf.gap_right))
|
|
|
|
cc->geom.x -= Conf.gap_right;
|
2007-04-27 21:58:48 +04:00
|
|
|
} else {
|
2008-09-22 18:28:04 +04:00
|
|
|
cc->geom.x = cc->bwidth + Conf.gap_left;
|
|
|
|
cc->geom.width = sc->xmax - Conf.gap_left;
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
2008-09-22 18:28:04 +04:00
|
|
|
if (yslack >= 0) {
|
2008-06-12 08:59:51 +04:00
|
|
|
cc->geom.y = MAX(MIN(ymouse, yslack),
|
2008-09-22 18:28:04 +04:00
|
|
|
Conf.gap_top + cc->bwidth);
|
2008-06-12 08:59:51 +04:00
|
|
|
if (cc->geom.y > (yslack - Conf.gap_bottom))
|
|
|
|
cc->geom.y -= Conf.gap_bottom;
|
2007-04-27 21:58:48 +04:00
|
|
|
} else {
|
2008-09-22 18:28:04 +04:00
|
|
|
cc->geom.y = cc->bwidth + Conf.gap_top;
|
|
|
|
cc->geom.height = sc->ymax - Conf.gap_top;
|
2007-04-27 21:58:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_mtf(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
struct screen_ctx *sc;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
if (cc == NULL)
|
|
|
|
cc = _curcc;
|
|
|
|
if (cc == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sc = CCTOSC(cc);
|
|
|
|
|
|
|
|
/* Move to front. */
|
|
|
|
TAILQ_REMOVE(&sc->mruq, cc, mru_entry);
|
|
|
|
TAILQ_INSERT_HEAD(&sc->mruq, cc, mru_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_gethints(struct client_ctx *cc)
|
|
|
|
{
|
2008-07-11 18:21:28 +04:00
|
|
|
XClassHint xch;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
Atom mha;
|
|
|
|
struct mwm_hints *mwmh;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
if (XGetClassHint(X_Dpy, cc->win, &xch)) {
|
2007-04-27 21:58:48 +04:00
|
|
|
if (xch.res_name != NULL)
|
|
|
|
cc->app_name = xch.res_name;
|
|
|
|
if (xch.res_class != NULL)
|
|
|
|
cc->app_class = xch.res_class;
|
|
|
|
}
|
|
|
|
|
2007-05-28 22:34:27 +04:00
|
|
|
mha = XInternAtom(X_Dpy, "_MOTIF_WM_HINTS", False);
|
2007-04-27 21:58:48 +04:00
|
|
|
if (xu_getprop(cc, mha, mha, PROP_MWM_HINTS_ELEMENTS,
|
2008-05-16 02:18:00 +04:00
|
|
|
(u_char **)&mwmh) == MWM_NUMHINTS)
|
2007-04-27 21:58:48 +04:00
|
|
|
if (mwmh->flags & MWM_HINTS_DECORATIONS &&
|
|
|
|
!(mwmh->decorations & MWM_DECOR_ALL) &&
|
|
|
|
!(mwmh->decorations & MWM_DECOR_BORDER))
|
|
|
|
cc->bwidth = 0;
|
2007-05-28 22:34:27 +04:00
|
|
|
if (XGetCommand(X_Dpy, cc->win, &argv, &argc)) {
|
2007-04-27 21:58:48 +04:00
|
|
|
#define MAX_ARGLEN 512
|
|
|
|
#define ARG_SEP_ " "
|
2008-07-11 18:21:28 +04:00
|
|
|
int i, o, len = MAX_ARGLEN;
|
|
|
|
char *buf;
|
2007-04-27 21:58:48 +04:00
|
|
|
|
|
|
|
buf = xmalloc(len);
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
|
|
|
for (o = 0, i = 0; o < len && i < argc; i++) {
|
|
|
|
if (argv[i] == NULL)
|
|
|
|
break;
|
|
|
|
strlcat(buf, argv[i], len);
|
|
|
|
o += strlen(buf);
|
2008-04-16 00:24:41 +04:00
|
|
|
strlcat(buf, ARG_SEP_, len);
|
2007-04-27 21:58:48 +04:00
|
|
|
o += strlen(ARG_SEP_);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(buf) > 0)
|
|
|
|
cc->app_cliarg = buf;
|
|
|
|
|
|
|
|
XFreeStringList(argv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
client_freehints(struct client_ctx *cc)
|
|
|
|
{
|
|
|
|
if (cc->app_name != NULL)
|
|
|
|
XFree(cc->app_name);
|
|
|
|
if (cc->app_class != NULL)
|
|
|
|
XFree(cc->app_class);
|
|
|
|
if (cc->app_cliarg != NULL)
|
|
|
|
xfree(cc->app_cliarg);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_inwindowbounds(struct client_ctx *cc, int x, int y)
|
|
|
|
{
|
|
|
|
return (x < cc->geom.width && x >= 0 &&
|
|
|
|
y < cc->geom.height && y >= 0);
|
|
|
|
}
|