Update local copy of GPLv2 and FSF address in copyrights
[wmaker-crm.git] / src / wcore.c
blob854c573ffd346a2e7df8128e5d84f1576ad0b4df
1 /*
2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "wconfig.h"
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
26 #include <stdlib.h>
27 #include <string.h>
29 #include "WindowMaker.h"
30 #include "wcore.h"
32 /****** Global Variables ******/
33 extern WPreferences wPreferences;
35 /* cursors */
36 extern Cursor wCursor[WCUR_LAST];
38 extern XContext wWinContext;
41 *----------------------------------------------------------------------
42 * wCoreCreateTopLevel--
43 * Creates a toplevel window used for icons, menus and dialogs.
45 * Returns:
46 * The created window.
47 *----------------------------------------------------------------------
49 WCoreWindow *wCoreCreateTopLevel(WScreen * screen, int x, int y, int width, int height, int bwidth)
51 WCoreWindow *core;
52 int vmask;
53 XSetWindowAttributes attribs;
55 core = wmalloc(sizeof(WCoreWindow));
56 memset(core, 0, sizeof(WCoreWindow));
58 /* don't set CWBackPixel so that transparent XRender windows
59 are see-through */
60 vmask = /*CWBackPixmap|CWBackPixel| */ CWBorderPixel | CWCursor | CWEventMask
61 | CWOverrideRedirect;
62 attribs.override_redirect = True;
63 attribs.cursor = wCursor[WCUR_DEFAULT];
64 attribs.background_pixmap = None;
65 attribs.background_pixel = screen->black_pixel;
66 attribs.border_pixel = screen->frame_border_pixel;
67 attribs.event_mask = SubstructureRedirectMask | ButtonPressMask
68 | ButtonReleaseMask | ButtonMotionMask | ExposureMask | EnterWindowMask | LeaveWindowMask;
70 vmask |= CWColormap;
71 attribs.colormap = screen->w_colormap;
73 core->window = XCreateWindow(dpy, screen->root_win, x, y, width, height,
74 bwidth, screen->w_depth, CopyFromParent, screen->w_visual, vmask, &attribs);
75 core->width = width;
76 core->height = height;
77 core->screen_ptr = screen;
79 core->descriptor.self = core;
81 XClearWindow(dpy, core->window);
83 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
85 return core;
89 *----------------------------------------------------------------------
90 * wCoreCreate--
91 * Creates a brand new child window.
92 * The window will have a border width of 0 and color is black.
94 * Returns:
95 * A initialized core window structure.
97 * Side effects:
98 * A window context for the created window is saved.
100 * Notes:
101 * The event mask is initialized to a default value.
103 *----------------------------------------------------------------------
105 WCoreWindow *wCoreCreate(WCoreWindow * parent, int x, int y, int width, int height)
107 WCoreWindow *core;
108 int vmask;
109 XSetWindowAttributes attribs;
111 core = wmalloc(sizeof(WCoreWindow));
112 memset(core, 0, sizeof(WCoreWindow));
114 vmask = /*CWBackPixmap|CWBackPixel| */ CWBorderPixel | CWCursor | CWEventMask;
115 attribs.cursor = wCursor[WCUR_DEFAULT];
116 attribs.background_pixmap = None;
117 attribs.background_pixel = parent->screen_ptr->black_pixel;
118 attribs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
119 | ButtonReleaseMask | ButtonMotionMask | ExposureMask | EnterWindowMask | LeaveWindowMask;
121 vmask |= CWColormap;
122 attribs.colormap = parent->screen_ptr->w_colormap;
124 core->window =
125 XCreateWindow(dpy, parent->window, x, y, width, height, 0,
126 parent->screen_ptr->w_depth, CopyFromParent,
127 parent->screen_ptr->w_visual, vmask, &attribs);
128 core->width = width;
129 core->height = height;
130 core->screen_ptr = parent->screen_ptr;
132 core->descriptor.self = core;
134 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
135 return core;
138 void wCoreDestroy(WCoreWindow * core)
140 if (core->stacking) {
141 wfree(core->stacking);
143 XDeleteContext(dpy, core->window, wWinContext);
144 XDestroyWindow(dpy, core->window);
145 wfree(core);
148 void wCoreConfigure(WCoreWindow * core, int req_x, int req_y, int req_w, int req_h)
150 XWindowChanges xwc;
151 unsigned int mask;
153 mask = CWX | CWY;
154 xwc.x = req_x;
155 xwc.y = req_y;
157 if (req_w <= 0)
158 req_w = core->width;
159 if (req_h <= 0)
160 req_h = core->height;
162 if (req_w != core->width || req_h != core->height) {
163 mask |= CWWidth | CWHeight;
164 xwc.width = req_w;
165 xwc.height = req_h;
166 core->width = req_w;
167 core->height = req_h;
169 XConfigureWindow(dpy, core->window, mask, &xwc);