Change to the linux kernel coding style
[wmaker-crm.git] / src / wcore.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/*
9af1c6c4 dan1998-10-21 14:43:47 +00002 * Window Maker window manager
6830b057 dan2004-10-12 21:28:27 +00003 *
4153e2fd dan2003-01-16 23:30:45 +00004 * Copyright (c) 1997-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00005 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00006 * 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
6830b057 dan2004-10-12 21:28:27 +000018 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000019 * 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
9d2e6ef9 scottc1998-09-29 22:36:29 +000033/****** Global Variables ******/
34extern WPreferences wPreferences;
35
36/* cursors */
37extern Cursor wCursor[WCUR_LAST];
38
39extern XContext wWinContext;
40
9d2e6ef9 scottc1998-09-29 22:36:29 +000041/*
42 *----------------------------------------------------------------------
43 * wCoreCreateTopLevel--
44 * Creates a toplevel window used for icons, menus and dialogs.
45 *
46 * Returns:
47 * The created window.
48 *----------------------------------------------------------------------
49 */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020050WCoreWindow *wCoreCreateTopLevel(WScreen * screen, int x, int y, int width, int height, int bwidth)
9d2e6ef9 scottc1998-09-29 22:36:29 +000051{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020052 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;
9d2e6ef9 scottc1998-09-29 22:36:29 +000081
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020082 XClearWindow(dpy, core->window);
83
84 XSaveContext(dpy, core->window, wWinContext, (XPointer) & core->descriptor);
85
86 return core;
87}
9d2e6ef9 scottc1998-09-29 22:36:29 +000088
89/*
6830b057 dan2004-10-12 21:28:27 +000090 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +000091 * wCoreCreate--
92 * Creates a brand new child window.
93 * The window will have a border width of 0 and color is black.
6830b057 dan2004-10-12 21:28:27 +000094 *
9d2e6ef9 scottc1998-09-29 22:36:29 +000095 * Returns:
96 * A initialized core window structure.
6830b057 dan2004-10-12 21:28:27 +000097 *
9d2e6ef9 scottc1998-09-29 22:36:29 +000098 * Side effects:
99 * A window context for the created window is saved.
6830b057 dan2004-10-12 21:28:27 +0000100 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000101 * Notes:
102 * The event mask is initialized to a default value.
6830b057 dan2004-10-12 21:28:27 +0000103 *
104 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +0000105 */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200106WCoreWindow *wCoreCreate(WCoreWindow * parent, int x, int y, int width, int height)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000107{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200108 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;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000137}
138
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200139void wCoreDestroy(WCoreWindow * core)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000140{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200141 if (core->stacking) {
142 wfree(core->stacking);
143 }
144 XDeleteContext(dpy, core->window, wWinContext);
145 XDestroyWindow(dpy, core->window);
146 wfree(core);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000147}
148
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200149void wCoreConfigure(WCoreWindow * core, int req_x, int req_y, int req_w, int req_h)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000150{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200151 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);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000171}