Updating to version 0.20.2
[wmaker-crm.git] / src / wcore.c
blobee73075ef96caeeecfeac3b7b822f72b90465475
1 /*
2 * Window Maker window manager
3 *
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
5 *
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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 * USA.
22 #include "wconfig.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include "WindowMaker.h"
31 #include "wcore.h"
34 /****** Global Variables ******/
35 extern WPreferences wPreferences;
37 /* cursors */
38 extern Cursor wCursor[WCUR_LAST];
40 extern XContext wWinContext;
44 *----------------------------------------------------------------------
45 * wCoreCreateTopLevel--
46 * Creates a toplevel window used for icons, menus and dialogs.
48 * Returns:
49 * The created window.
50 *----------------------------------------------------------------------
52 WCoreWindow*
53 wCoreCreateTopLevel(WScreen *screen, int x, int y, int width, int height,
54 int bwidth)
56 WCoreWindow *core;
57 int vmask;
58 XSetWindowAttributes attribs;
60 core = wmalloc(sizeof(WCoreWindow));
61 memset(core, 0, sizeof(WCoreWindow));
63 vmask = /*CWBackPixmap|*/CWBackPixel|CWBorderPixel|CWCursor|CWEventMask
64 |CWOverrideRedirect;
65 attribs.override_redirect = True;
66 attribs.cursor = wCursor[WCUR_DEFAULT];
67 attribs.background_pixmap = None;
68 attribs.background_pixel = screen->black_pixel;
69 attribs.border_pixel = screen->frame_border_pixel;
70 attribs.event_mask = SubstructureRedirectMask | ButtonPressMask
71 | ButtonReleaseMask | ButtonMotionMask | ExposureMask | EnterWindowMask
72 #ifdef XDE_DND
73 | StructureNotifyMask
74 #endif
75 | LeaveWindowMask;
77 vmask |= CWColormap;
78 attribs.colormap = screen->w_colormap;
80 core->window = XCreateWindow(dpy, screen->root_win, x, y, width, height,
81 bwidth, screen->w_depth, CopyFromParent,
82 screen->w_visual, vmask, &attribs);
83 core->width = width;
84 core->height = height;
85 core->screen_ptr = screen;
87 core->descriptor.self = core;
89 XClearWindow(dpy, core->window);
91 XSaveContext(dpy, core->window, wWinContext, (XPointer)&core->descriptor);
93 return core;
98 *----------------------------------------------------------------------
99 * wCoreCreate--
100 * Creates a brand new child window.
101 * The window will have a border width of 0 and color is black.
103 * Returns:
104 * A initialized core window structure.
106 * Side effects:
107 * A window context for the created window is saved.
109 * Notes:
110 * The event mask is initialized to a default value.
112 *----------------------------------------------------------------------
114 WCoreWindow*
115 wCoreCreate(WCoreWindow *parent, int x, int y, int width, int height)
117 WCoreWindow *core;
118 int vmask;
119 XSetWindowAttributes attribs;
121 core=wmalloc(sizeof(WCoreWindow));
122 memset(core, 0, sizeof(WCoreWindow));
124 vmask = CWBackPixmap|CWBackPixel|CWBorderPixel|CWCursor|CWEventMask;
125 attribs.cursor = wCursor[WCUR_DEFAULT];
126 attribs.background_pixmap = None;
127 attribs.background_pixel = parent->screen_ptr->black_pixel;
128 attribs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
129 | ButtonReleaseMask | ButtonMotionMask | ExposureMask | EnterWindowMask
130 | LeaveWindowMask;
132 vmask |= CWColormap;
133 attribs.colormap = parent->screen_ptr->w_colormap;
135 core->window =
136 XCreateWindow(dpy, parent->window, x, y, width, height, 0,
137 parent->screen_ptr->w_depth, CopyFromParent,
138 parent->screen_ptr->w_visual, vmask, &attribs);
139 core->width=width;
140 core->height=height;
141 core->screen_ptr = parent->screen_ptr;
143 core->descriptor.self = core;
145 XSaveContext(dpy, core->window, wWinContext, (XPointer)&core->descriptor);
146 return core;
151 void
152 wCoreDestroy(WCoreWindow *core)
154 if (core->stacking) {
155 free(core->stacking);
157 XDeleteContext(dpy, core->window, wWinContext);
158 XDestroyWindow(dpy, core->window);
159 free(core);
163 void
164 wCoreConfigure(WCoreWindow *core, int req_x, int req_y, int req_w, int req_h)
166 XWindowChanges xwc;
167 unsigned int mask;
169 mask = CWX|CWY;
170 xwc.x = req_x;
171 xwc.y = req_y;
173 if (req_w <= 0)
174 req_w = core->width;
175 if (req_h <= 0)
176 req_h = core->height;
178 if (req_w != core->width || req_h != core->height) {
179 mask |= CWWidth | CWHeight;
180 xwc.width = req_w;
181 xwc.height = req_h;
182 core->width = req_w;
183 core->height = req_h;
185 XConfigureWindow(dpy, core->window, mask, &xwc);