Files
wmaker/src/wcore.c
T

155 lines
4.6 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
/*
1998-10-21 14:43:47 +00:00
* Window Maker window manager
2004-10-12 21:28:27 +00:00
*
2003-01-16 23:30:45 +00:00
* Copyright (c) 1997-2003 Alfredo K. Kojima
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1998-09-29 22:36:29 +00:00
*/
#include "wconfig.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdlib.h>
#include <string.h>
#include "WindowMaker.h"
#include "wcore.h"
2012-10-06 17:58:52 +02:00
/*----------------------------------------------------------------------
1998-09-29 22:36:29 +00:00
* wCoreCreateTopLevel--
* Creates a toplevel window used for icons, menus and dialogs.
*
* Returns:
* The created window.
2012-10-06 17:58:52 +02:00
*--------------------------------------------------------------------- */
WCoreWindow *wCoreCreateTopLevel(WScreen *screen, int x, int y, int width, int height, int bwidth, int depth, Visual *visual, Colormap colormap, WMPixel border_pixel)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
WCoreWindow *core;
int vmask;
XSetWindowAttributes attribs;
core = wmalloc(sizeof(WCoreWindow));
vmask = CWBorderPixel | CWCursor | CWEventMask | CWOverrideRedirect | CWColormap;
2009-08-20 00:59:40 +02:00
attribs.override_redirect = True;
attribs.cursor = wPreferences.cursor[WCUR_NORMAL];
attribs.background_pixmap = None;
2009-08-20 00:59:40 +02:00
attribs.background_pixel = screen->black_pixel;
attribs.border_pixel = border_pixel;
2012-10-06 17:58:52 +02:00
attribs.event_mask = SubstructureRedirectMask | ButtonPressMask |
ButtonReleaseMask | ButtonMotionMask |
ExposureMask | EnterWindowMask | LeaveWindowMask;
2009-08-20 00:59:40 +02:00
2012-08-20 15:18:21 +01:00
attribs.colormap = colormap;
2009-08-20 00:59:40 +02:00
if (wPreferences.use_saveunders) {
vmask |= CWSaveUnder;
attribs.save_under = True;
}
2009-08-20 00:59:40 +02:00
core->window = XCreateWindow(dpy, screen->root_win, x, y, width, height,
2012-08-20 15:18:21 +01:00
bwidth, depth, CopyFromParent, visual, vmask, &attribs);
2009-08-20 00:59:40 +02:00
core->width = width;
core->height = height;
core->screen_ptr = screen;
core->descriptor.self = core;
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
XClearWindow(dpy, core->window);
XSaveContext(dpy, core->window, w_global.context.client_win, (XPointer) & core->descriptor);
2009-08-20 00:59:40 +02:00
return core;
}
1998-09-29 22:36:29 +00:00
2012-10-06 17:58:52 +02:00
/*----------------------------------------------------------------------
1998-09-29 22:36:29 +00:00
* wCoreCreate--
* Creates a brand new child window.
* The window will have a border width of 0 and color is black.
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* Returns:
* A initialized core window structure.
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* Side effects:
* A window context for the created window is saved.
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* Notes:
* The event mask is initialized to a default value.
2012-10-06 17:58:52 +02:00
*--------------------------------------------------------------------- */
WCoreWindow *wCoreCreate(WCoreWindow *parent, int x, int y, int width, int height)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
WCoreWindow *core;
int vmask;
XSetWindowAttributes attribs;
core = wmalloc(sizeof(WCoreWindow));
vmask = CWBorderPixel | CWCursor | CWEventMask | CWColormap;
attribs.cursor = wPreferences.cursor[WCUR_NORMAL];
attribs.background_pixmap = None;
2009-08-20 00:59:40 +02:00
attribs.background_pixel = parent->screen_ptr->black_pixel;
2012-10-06 17:58:52 +02:00
attribs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask |
ButtonReleaseMask | ButtonMotionMask |
ExposureMask | EnterWindowMask | LeaveWindowMask;
2012-08-20 15:18:21 +01:00
attribs.colormap = parent->screen_ptr->w_colormap;
2012-10-06 17:58:52 +02:00
core->window = XCreateWindow(dpy, parent->window, x, y, width, height, 0,
2009-08-20 00:59:40 +02:00
parent->screen_ptr->w_depth, CopyFromParent,
parent->screen_ptr->w_visual, vmask, &attribs);
2012-10-06 17:58:52 +02:00
2009-08-20 00:59:40 +02:00
core->width = width;
core->height = height;
core->screen_ptr = parent->screen_ptr;
core->descriptor.self = core;
XSaveContext(dpy, core->window, w_global.context.client_win, (XPointer) & core->descriptor);
2009-08-20 00:59:40 +02:00
return core;
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
void wCoreDestroy(WCoreWindow * core)
1998-09-29 22:36:29 +00:00
{
2012-10-06 17:58:52 +02:00
if (core->stacking)
2009-08-20 00:59:40 +02:00
wfree(core->stacking);
2012-10-06 17:58:52 +02:00
XDeleteContext(dpy, core->window, w_global.context.client_win);
2009-08-20 00:59:40 +02:00
XDestroyWindow(dpy, core->window);
wfree(core);
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
void wCoreConfigure(WCoreWindow * core, int req_x, int req_y, int req_w, int req_h)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
XWindowChanges xwc;
unsigned int mask;
mask = CWX | CWY;
xwc.x = req_x;
xwc.y = req_y;
if (req_w <= 0)
req_w = core->width;
2012-10-06 17:58:52 +02:00
2009-08-20 00:59:40 +02:00
if (req_h <= 0)
req_h = core->height;
if (req_w != core->width || req_h != core->height) {
mask |= CWWidth | CWHeight;
xwc.width = req_w;
xwc.height = req_h;
core->width = req_w;
core->height = req_h;
}
XConfigureWindow(dpy, core->window, mask, &xwc);
1998-09-29 22:36:29 +00:00
}