wmaker: Moved global var with list of cursors to the preferences variable
[wmaker-crm.git] / src / wcore.c
blob37cf59ac68694612c02506bf121f5c17e2a94f4a
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 XContext wWinContext;
35 /*----------------------------------------------------------------------
36 * wCoreCreateTopLevel--
37 * Creates a toplevel window used for icons, menus and dialogs.
39 * Returns:
40 * The created window.
41 *--------------------------------------------------------------------- */
42 WCoreWindow *wCoreCreateTopLevel(WScreen *screen, int x, int y, int width, int height, int bwidth, int depth, Visual *visual, Colormap colormap, WMPixel border_pixel)
44 WCoreWindow *core;
45 int vmask;
46 XSetWindowAttributes attribs;
48 core = wmalloc(sizeof(WCoreWindow));
50 vmask = CWBorderPixel | CWCursor | CWEventMask | CWOverrideRedirect | CWColormap;
51 attribs.override_redirect = True;
52 attribs.cursor = wPreferences.cursor[WCUR_DEFAULT];
53 attribs.background_pixmap = None;
54 attribs.background_pixel = screen->black_pixel;
55 attribs.border_pixel = border_pixel;
56 attribs.event_mask = SubstructureRedirectMask | ButtonPressMask |
57 ButtonReleaseMask | ButtonMotionMask |
58 ExposureMask | EnterWindowMask | LeaveWindowMask;
60 attribs.colormap = colormap;
62 if (wPreferences.use_saveunders) {
63 vmask |= CWSaveUnder;
64 attribs.save_under = True;
67 core->window = XCreateWindow(dpy, screen->root_win, x, y, width, height,
68 bwidth, depth, CopyFromParent, visual, vmask, &attribs);
69 core->width = width;
70 core->height = height;
71 core->screen_ptr = screen;
72 core->descriptor.self = core;
74 XClearWindow(dpy, core->window);
75 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
77 return core;
80 /*----------------------------------------------------------------------
81 * wCoreCreate--
82 * Creates a brand new child window.
83 * The window will have a border width of 0 and color is black.
85 * Returns:
86 * A initialized core window structure.
88 * Side effects:
89 * A window context for the created window is saved.
91 * Notes:
92 * The event mask is initialized to a default value.
93 *--------------------------------------------------------------------- */
94 WCoreWindow *wCoreCreate(WCoreWindow *parent, int x, int y, int width, int height)
96 WCoreWindow *core;
97 int vmask;
98 XSetWindowAttributes attribs;
100 core = wmalloc(sizeof(WCoreWindow));
102 vmask = CWBorderPixel | CWCursor | CWEventMask | CWColormap;
103 attribs.cursor = wPreferences.cursor[WCUR_DEFAULT];
104 attribs.background_pixmap = None;
105 attribs.background_pixel = parent->screen_ptr->black_pixel;
106 attribs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask |
107 ButtonReleaseMask | ButtonMotionMask |
108 ExposureMask | EnterWindowMask | LeaveWindowMask;
109 attribs.colormap = parent->screen_ptr->w_colormap;
110 core->window = XCreateWindow(dpy, parent->window, x, y, width, height, 0,
111 parent->screen_ptr->w_depth, CopyFromParent,
112 parent->screen_ptr->w_visual, vmask, &attribs);
114 core->width = width;
115 core->height = height;
116 core->screen_ptr = parent->screen_ptr;
117 core->descriptor.self = core;
119 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
120 return core;
123 void wCoreDestroy(WCoreWindow * core)
125 if (core->stacking)
126 wfree(core->stacking);
128 XDeleteContext(dpy, core->window, wWinContext);
129 XDestroyWindow(dpy, core->window);
130 wfree(core);
133 void wCoreConfigure(WCoreWindow * core, int req_x, int req_y, int req_w, int req_h)
135 XWindowChanges xwc;
136 unsigned int mask;
138 mask = CWX | CWY;
139 xwc.x = req_x;
140 xwc.y = req_y;
142 if (req_w <= 0)
143 req_w = core->width;
145 if (req_h <= 0)
146 req_h = core->height;
148 if (req_w != core->width || req_h != core->height) {
149 mask |= CWWidth | CWHeight;
150 xwc.width = req_w;
151 xwc.height = req_h;
152 core->width = req_w;
153 core->height = req_h;
155 XConfigureWindow(dpy, core->window, mask, &xwc);