Change to the linux kernel coding style
[wmaker-crm.git] / src / wcore.c
1 /*
2 * Window Maker window manager
3 *
4 * Copyright (c) 1997-2003 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.
10 *
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.
15 *
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.
20 */
21
22 #include "wconfig.h"
23
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include "WindowMaker.h"
31 #include "wcore.h"
32
33 /****** Global Variables ******/
34 extern WPreferences wPreferences;
35
36 /* cursors */
37 extern Cursor wCursor[WCUR_LAST];
38
39 extern XContext wWinContext;
40
41 /*
42 *----------------------------------------------------------------------
43 * wCoreCreateTopLevel--
44 * Creates a toplevel window used for icons, menus and dialogs.
45 *
46 * Returns:
47 * The created window.
48 *----------------------------------------------------------------------
49 */
50 WCoreWindow *wCoreCreateTopLevel(WScreen * screen, int x, int y, int width, int height, int bwidth)
51 {
52 WCoreWindow *core;
53 int vmask;
54 XSetWindowAttributes attribs;
55
56 core = wmalloc(sizeof(WCoreWindow));
57 memset(core, 0, sizeof(WCoreWindow));
58
59 /* don't set CWBackPixel so that transparent XRender windows
60 are see-through */
61 vmask = /*CWBackPixmap|CWBackPixel| */ CWBorderPixel | CWCursor | CWEventMask
62 | CWOverrideRedirect;
63 attribs.override_redirect = True;
64 attribs.cursor = wCursor[WCUR_DEFAULT];
65 attribs.background_pixmap = None;
66 attribs.background_pixel = screen->black_pixel;
67 attribs.border_pixel = screen->frame_border_pixel;
68 attribs.event_mask = SubstructureRedirectMask | ButtonPressMask
69 | ButtonReleaseMask | ButtonMotionMask | ExposureMask | EnterWindowMask | LeaveWindowMask;
70
71 vmask |= CWColormap;
72 attribs.colormap = screen->w_colormap;
73
74 core->window = XCreateWindow(dpy, screen->root_win, x, y, width, height,
75 bwidth, screen->w_depth, CopyFromParent, screen->w_visual, vmask, &attribs);
76 core->width = width;
77 core->height = height;
78 core->screen_ptr = screen;
79
80 core->descriptor.self = core;
81
82 XClearWindow(dpy, core->window);
83
84 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
85
86 return core;
87 }
88
89 /*
90 *----------------------------------------------------------------------
91 * wCoreCreate--
92 * Creates a brand new child window.
93 * The window will have a border width of 0 and color is black.
94 *
95 * Returns:
96 * A initialized core window structure.
97 *
98 * Side effects:
99 * A window context for the created window is saved.
100 *
101 * Notes:
102 * The event mask is initialized to a default value.
103 *
104 *----------------------------------------------------------------------
105 */
106 WCoreWindow *wCoreCreate(WCoreWindow * parent, int x, int y, int width, int height)
107 {
108 WCoreWindow *core;
109 int vmask;
110 XSetWindowAttributes attribs;
111
112 core = wmalloc(sizeof(WCoreWindow));
113 memset(core, 0, sizeof(WCoreWindow));
114
115 vmask = /*CWBackPixmap|CWBackPixel| */ CWBorderPixel | CWCursor | CWEventMask;
116 attribs.cursor = wCursor[WCUR_DEFAULT];
117 attribs.background_pixmap = None;
118 attribs.background_pixel = parent->screen_ptr->black_pixel;
119 attribs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
120 | ButtonReleaseMask | ButtonMotionMask | ExposureMask | EnterWindowMask | LeaveWindowMask;
121 /*
122 vmask |= CWColormap;
123 attribs.colormap = parent->screen_ptr->w_colormap;
124 */
125 core->window =
126 XCreateWindow(dpy, parent->window, x, y, width, height, 0,
127 parent->screen_ptr->w_depth, CopyFromParent,
128 parent->screen_ptr->w_visual, vmask, &attribs);
129 core->width = width;
130 core->height = height;
131 core->screen_ptr = parent->screen_ptr;
132
133 core->descriptor.self = core;
134
135 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
136 return core;
137 }
138
139 void wCoreDestroy(WCoreWindow * core)
140 {
141 if (core->stacking) {
142 wfree(core->stacking);
143 }
144 XDeleteContext(dpy, core->window, wWinContext);
145 XDestroyWindow(dpy, core->window);
146 wfree(core);
147 }
148
149 void wCoreConfigure(WCoreWindow * core, int req_x, int req_y, int req_w, int req_h)
150 {
151 XWindowChanges xwc;
152 unsigned int mask;
153
154 mask = CWX | CWY;
155 xwc.x = req_x;
156 xwc.y = req_y;
157
158 if (req_w <= 0)
159 req_w = core->width;
160 if (req_h <= 0)
161 req_h = core->height;
162
163 if (req_w != core->width || req_h != core->height) {
164 mask |= CWWidth | CWHeight;
165 xwc.width = req_w;
166 xwc.height = req_h;
167 core->width = req_w;
168 core->height = req_h;
169 }
170 XConfigureWindow(dpy, core->window, mask, &xwc);
171 }