WINGs: fix memory leak in getStreamObjects (Coverity #50119)
[wmaker-crm.git] / src / wcore.c
blobd04d09328f1935977601421757ab56e2a5c17048
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"
33 /*----------------------------------------------------------------------
34 * wCoreCreateTopLevel--
35 * Creates a toplevel window used for icons, menus and dialogs.
37 * Returns:
38 * The created window.
39 *--------------------------------------------------------------------- */
40 WCoreWindow *wCoreCreateTopLevel(WScreen *screen, int x, int y, int width, int height, int bwidth, int depth, Visual *visual, Colormap colormap, WMPixel border_pixel)
42 WCoreWindow *core;
43 int vmask;
44 XSetWindowAttributes attribs;
46 core = wmalloc(sizeof(WCoreWindow));
48 vmask = CWBorderPixel | CWCursor | CWEventMask | CWOverrideRedirect | CWColormap;
49 attribs.override_redirect = True;
50 attribs.cursor = wPreferences.cursor[WCUR_NORMAL];
51 attribs.background_pixmap = None;
52 attribs.background_pixel = screen->black_pixel;
53 attribs.border_pixel = border_pixel;
54 attribs.event_mask = SubstructureRedirectMask | ButtonPressMask |
55 ButtonReleaseMask | ButtonMotionMask |
56 ExposureMask | EnterWindowMask | LeaveWindowMask;
58 attribs.colormap = colormap;
60 if (wPreferences.use_saveunders) {
61 vmask |= CWSaveUnder;
62 attribs.save_under = True;
65 core->window = XCreateWindow(dpy, screen->root_win, x, y, width, height,
66 bwidth, depth, CopyFromParent, visual, vmask, &attribs);
67 core->width = width;
68 core->height = height;
69 core->screen_ptr = screen;
70 core->descriptor.self = core;
72 XClearWindow(dpy, core->window);
73 XSaveContext(dpy, core->window, w_global.context.client_win, (XPointer) & core->descriptor);
75 return core;
78 /*----------------------------------------------------------------------
79 * wCoreCreate--
80 * Creates a brand new child window.
81 * The window will have a border width of 0 and color is black.
83 * Returns:
84 * A initialized core window structure.
86 * Side effects:
87 * A window context for the created window is saved.
89 * Notes:
90 * The event mask is initialized to a default value.
91 *--------------------------------------------------------------------- */
92 WCoreWindow *wCoreCreate(WCoreWindow *parent, int x, int y, int width, int height)
94 WCoreWindow *core;
95 int vmask;
96 XSetWindowAttributes attribs;
98 core = wmalloc(sizeof(WCoreWindow));
100 vmask = CWBorderPixel | CWCursor | CWEventMask | CWColormap;
101 attribs.cursor = wPreferences.cursor[WCUR_NORMAL];
102 attribs.background_pixmap = None;
103 attribs.background_pixel = parent->screen_ptr->black_pixel;
104 attribs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask |
105 ButtonReleaseMask | ButtonMotionMask |
106 ExposureMask | EnterWindowMask | LeaveWindowMask;
107 attribs.colormap = parent->screen_ptr->w_colormap;
108 core->window = XCreateWindow(dpy, parent->window, x, y, width, height, 0,
109 parent->screen_ptr->w_depth, CopyFromParent,
110 parent->screen_ptr->w_visual, vmask, &attribs);
112 core->width = width;
113 core->height = height;
114 core->screen_ptr = parent->screen_ptr;
115 core->descriptor.self = core;
117 XSaveContext(dpy, core->window, w_global.context.client_win, (XPointer) & core->descriptor);
118 return core;
121 void wCoreDestroy(WCoreWindow * core)
123 if (core->stacking)
124 wfree(core->stacking);
126 XDeleteContext(dpy, core->window, w_global.context.client_win);
127 XDestroyWindow(dpy, core->window);
128 wfree(core);
131 void wCoreConfigure(WCoreWindow * core, int req_x, int req_y, int req_w, int req_h)
133 XWindowChanges xwc;
134 unsigned int mask;
136 mask = CWX | CWY;
137 xwc.x = req_x;
138 xwc.y = req_y;
140 if (req_w <= 0)
141 req_w = core->width;
143 if (req_h <= 0)
144 req_h = core->height;
146 if (req_w != core->width || req_h != core->height) {
147 mask |= CWWidth | CWHeight;
148 xwc.width = req_w;
149 xwc.height = req_h;
150 core->width = req_w;
151 core->height = req_h;
153 XConfigureWindow(dpy, core->window, mask, &xwc);