wmaker: Replaced local declaration of system function by proper header call
[wmaker-crm.git] / src / wcore.c
blob3e77fbfa7bc15266745366344ff56998a2205e63
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 /* cursors */
34 extern Cursor wCursor[WCUR_LAST];
35 extern XContext wWinContext;
37 /*----------------------------------------------------------------------
38 * wCoreCreateTopLevel--
39 * Creates a toplevel window used for icons, menus and dialogs.
41 * Returns:
42 * The created window.
43 *--------------------------------------------------------------------- */
44 WCoreWindow *wCoreCreateTopLevel(WScreen *screen, int x, int y, int width, int height, int bwidth, int depth, Visual *visual, Colormap colormap, WMPixel border_pixel)
46 WCoreWindow *core;
47 int vmask;
48 XSetWindowAttributes attribs;
50 core = wmalloc(sizeof(WCoreWindow));
52 vmask = CWBorderPixel | CWCursor | CWEventMask | CWOverrideRedirect | CWColormap;
53 attribs.override_redirect = True;
54 attribs.cursor = wCursor[WCUR_DEFAULT];
55 attribs.background_pixmap = None;
56 attribs.background_pixel = screen->black_pixel;
57 attribs.border_pixel = border_pixel;
58 attribs.event_mask = SubstructureRedirectMask | ButtonPressMask |
59 ButtonReleaseMask | ButtonMotionMask |
60 ExposureMask | EnterWindowMask | LeaveWindowMask;
62 attribs.colormap = colormap;
64 if (wPreferences.use_saveunders) {
65 vmask |= CWSaveUnder;
66 attribs.save_under = True;
69 core->window = XCreateWindow(dpy, screen->root_win, x, y, width, height,
70 bwidth, depth, CopyFromParent, visual, vmask, &attribs);
71 core->width = width;
72 core->height = height;
73 core->screen_ptr = screen;
74 core->descriptor.self = core;
76 XClearWindow(dpy, core->window);
77 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
79 return core;
82 /*----------------------------------------------------------------------
83 * wCoreCreate--
84 * Creates a brand new child window.
85 * The window will have a border width of 0 and color is black.
87 * Returns:
88 * A initialized core window structure.
90 * Side effects:
91 * A window context for the created window is saved.
93 * Notes:
94 * The event mask is initialized to a default value.
95 *--------------------------------------------------------------------- */
96 WCoreWindow *wCoreCreate(WCoreWindow *parent, int x, int y, int width, int height)
98 WCoreWindow *core;
99 int vmask;
100 XSetWindowAttributes attribs;
102 core = wmalloc(sizeof(WCoreWindow));
104 vmask = CWBorderPixel | CWCursor | CWEventMask | CWColormap;
105 attribs.cursor = wCursor[WCUR_DEFAULT];
106 attribs.background_pixmap = None;
107 attribs.background_pixel = parent->screen_ptr->black_pixel;
108 attribs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask |
109 ButtonReleaseMask | ButtonMotionMask |
110 ExposureMask | EnterWindowMask | LeaveWindowMask;
111 attribs.colormap = parent->screen_ptr->w_colormap;
112 core->window = XCreateWindow(dpy, parent->window, x, y, width, height, 0,
113 parent->screen_ptr->w_depth, CopyFromParent,
114 parent->screen_ptr->w_visual, vmask, &attribs);
116 core->width = width;
117 core->height = height;
118 core->screen_ptr = parent->screen_ptr;
119 core->descriptor.self = core;
121 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
122 return core;
125 void wCoreDestroy(WCoreWindow * core)
127 if (core->stacking)
128 wfree(core->stacking);
130 XDeleteContext(dpy, core->window, wWinContext);
131 XDestroyWindow(dpy, core->window);
132 wfree(core);
135 void wCoreConfigure(WCoreWindow * core, int req_x, int req_y, int req_w, int req_h)
137 XWindowChanges xwc;
138 unsigned int mask;
140 mask = CWX | CWY;
141 xwc.x = req_x;
142 xwc.y = req_y;
144 if (req_w <= 0)
145 req_w = core->width;
147 if (req_h <= 0)
148 req_h = core->height;
150 if (req_w != core->width || req_h != core->height) {
151 mask |= CWWidth | CWHeight;
152 xwc.width = req_w;
153 xwc.height = req_h;
154 core->width = req_w;
155 core->height = req_h;
157 XConfigureWindow(dpy, core->window, mask, &xwc);