wmaker: Changed math on floating point by integer operation
[wmaker-crm.git] / src / wcore.c
bloba2aff96ae993f7cc4c6ba52b7388f4c56661e4a8
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 WPreferences wPreferences;
35 /* cursors */
36 extern Cursor wCursor[WCUR_LAST];
37 extern XContext wWinContext;
39 /*----------------------------------------------------------------------
40 * wCoreCreateTopLevel--
41 * Creates a toplevel window used for icons, menus and dialogs.
43 * Returns:
44 * The created window.
45 *--------------------------------------------------------------------- */
46 WCoreWindow *wCoreCreateTopLevel(WScreen *screen, int x, int y, int width, int height, int bwidth, int depth, Visual *visual, Colormap colormap, WMPixel border_pixel)
48 WCoreWindow *core;
49 int vmask;
50 XSetWindowAttributes attribs;
52 core = wmalloc(sizeof(WCoreWindow));
54 vmask = CWBorderPixel | CWCursor | CWEventMask | CWOverrideRedirect | CWColormap;
55 attribs.override_redirect = True;
56 attribs.cursor = wCursor[WCUR_DEFAULT];
57 attribs.background_pixmap = None;
58 attribs.background_pixel = screen->black_pixel;
59 attribs.border_pixel = border_pixel;
60 attribs.event_mask = SubstructureRedirectMask | ButtonPressMask |
61 ButtonReleaseMask | ButtonMotionMask |
62 ExposureMask | EnterWindowMask | LeaveWindowMask;
64 attribs.colormap = colormap;
66 if (wPreferences.use_saveunders) {
67 vmask |= CWSaveUnder;
68 attribs.save_under = True;
71 core->window = XCreateWindow(dpy, screen->root_win, x, y, width, height,
72 bwidth, depth, CopyFromParent, visual, vmask, &attribs);
73 core->width = width;
74 core->height = height;
75 core->screen_ptr = screen;
76 core->descriptor.self = core;
78 XClearWindow(dpy, core->window);
79 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
81 return core;
84 /*----------------------------------------------------------------------
85 * wCoreCreate--
86 * Creates a brand new child window.
87 * The window will have a border width of 0 and color is black.
89 * Returns:
90 * A initialized core window structure.
92 * Side effects:
93 * A window context for the created window is saved.
95 * Notes:
96 * The event mask is initialized to a default value.
97 *--------------------------------------------------------------------- */
98 WCoreWindow *wCoreCreate(WCoreWindow *parent, int x, int y, int width, int height)
100 WCoreWindow *core;
101 int vmask;
102 XSetWindowAttributes attribs;
104 core = wmalloc(sizeof(WCoreWindow));
106 vmask = CWBorderPixel | CWCursor | CWEventMask | CWColormap;
107 attribs.cursor = wCursor[WCUR_DEFAULT];
108 attribs.background_pixmap = None;
109 attribs.background_pixel = parent->screen_ptr->black_pixel;
110 attribs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask |
111 ButtonReleaseMask | ButtonMotionMask |
112 ExposureMask | EnterWindowMask | LeaveWindowMask;
113 attribs.colormap = parent->screen_ptr->w_colormap;
114 core->window = XCreateWindow(dpy, parent->window, x, y, width, height, 0,
115 parent->screen_ptr->w_depth, CopyFromParent,
116 parent->screen_ptr->w_visual, vmask, &attribs);
118 core->width = width;
119 core->height = height;
120 core->screen_ptr = parent->screen_ptr;
121 core->descriptor.self = core;
123 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
124 return core;
127 void wCoreDestroy(WCoreWindow * core)
129 if (core->stacking)
130 wfree(core->stacking);
132 XDeleteContext(dpy, core->window, wWinContext);
133 XDestroyWindow(dpy, core->window);
134 wfree(core);
137 void wCoreConfigure(WCoreWindow * core, int req_x, int req_y, int req_w, int req_h)
139 XWindowChanges xwc;
140 unsigned int mask;
142 mask = CWX | CWY;
143 xwc.x = req_x;
144 xwc.y = req_y;
146 if (req_w <= 0)
147 req_w = core->width;
149 if (req_h <= 0)
150 req_h = core->height;
152 if (req_w != core->width || req_h != core->height) {
153 mask |= CWWidth | CWHeight;
154 xwc.width = req_w;
155 xwc.height = req_h;
156 core->width = req_w;
157 core->height = req_h;
159 XConfigureWindow(dpy, core->window, mask, &xwc);