Rename INSTALL.pt
[wmaker-crm.git] / src / wcore.c
blob50b691dbb905f94ac0de6fd27c0e29b93a13fd06
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
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"
33 /****** Global Variables ******/
34 extern WPreferences wPreferences;
36 /* cursors */
37 extern Cursor wCursor[WCUR_LAST];
39 extern XContext wWinContext;
42 *----------------------------------------------------------------------
43 * wCoreCreateTopLevel--
44 * Creates a toplevel window used for icons, menus and dialogs.
46 * Returns:
47 * The created window.
48 *----------------------------------------------------------------------
50 WCoreWindow *wCoreCreateTopLevel(WScreen * screen, int x, int y, int width, int height, int bwidth)
52 WCoreWindow *core;
53 int vmask;
54 XSetWindowAttributes attribs;
56 core = wmalloc(sizeof(WCoreWindow));
57 memset(core, 0, sizeof(WCoreWindow));
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;
71 vmask |= CWColormap;
72 attribs.colormap = screen->w_colormap;
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;
80 core->descriptor.self = core;
82 XClearWindow(dpy, core->window);
84 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
86 return core;
90 *----------------------------------------------------------------------
91 * wCoreCreate--
92 * Creates a brand new child window.
93 * The window will have a border width of 0 and color is black.
95 * Returns:
96 * A initialized core window structure.
98 * Side effects:
99 * A window context for the created window is saved.
101 * Notes:
102 * The event mask is initialized to a default value.
104 *----------------------------------------------------------------------
106 WCoreWindow *wCoreCreate(WCoreWindow * parent, int x, int y, int width, int height)
108 WCoreWindow *core;
109 int vmask;
110 XSetWindowAttributes attribs;
112 core = wmalloc(sizeof(WCoreWindow));
113 memset(core, 0, sizeof(WCoreWindow));
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;
122 vmask |= CWColormap;
123 attribs.colormap = parent->screen_ptr->w_colormap;
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;
133 core->descriptor.self = core;
135 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
136 return core;
139 void wCoreDestroy(WCoreWindow * core)
141 if (core->stacking) {
142 wfree(core->stacking);
144 XDeleteContext(dpy, core->window, wWinContext);
145 XDestroyWindow(dpy, core->window);
146 wfree(core);
149 void wCoreConfigure(WCoreWindow * core, int req_x, int req_y, int req_w, int req_h)
151 XWindowChanges xwc;
152 unsigned int mask;
154 mask = CWX | CWY;
155 xwc.x = req_x;
156 xwc.y = req_y;
158 if (req_w <= 0)
159 req_w = core->width;
160 if (req_h <= 0)
161 req_h = core->height;
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;
170 XConfigureWindow(dpy, core->window, mask, &xwc);