/* $Id$ */
/*
* Copyright (c) 2007 Andreas Jaggi <andreas.jaggi@waterwave.ch>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "client.h"
XContext window_context;
//XContext frame_context; /* not used yet */
//XContext decoration_context; /* not used yet */
void init_clients ( ) {
window_context = XUniqueContext();
}
Client* find_client ( Window w ) {
Client* c;
if ( XFindContext(display, w, window_context, (void*)&c) != 0 ) {
c = NULL;
}
return c;
}
Client* create_client ( Window w ) {
XWindowAttributes winattr;
Client* c = malloc(sizeof(Client));
if ( c == NULL ) {
fprintf(stderr, "x-wm: cannot create new Client, not enough memory\n");
return NULL;
}
XGetWindowAttributes(display, w, &winattr);
c->window = w;
c->width = winattr.width;
c->height = winattr.height;
c->x = winattr.x;
c->y = winattr.y;
if ( c->width < DisplayWidth(display, DefaultScreen(display)) || c->height < DisplayHeight(display, DefaultScreen(display)) ) {
c->maximized = 0;
} else {
c->maximized = 1;
}
XSaveContext(display, w, window_context, (void*)c);
return c;
}
void destroy_client ( Window w ) {
Client* c;
c = find_client(w);
XDeleteContext(display, w, window_context);
if ( c != NULL ) {
free(c);
}
}