Code update for Window Maker version 0.50.0
[wmaker-crm.git] / src / motif.c
blob46b6da94a38c3d2ddedfbb91eb70442b38123bd4
1 /* motif.c-- stuff for support for mwm hints
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1998, 1999 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
24 #include "wconfig.h"
26 #ifdef MWM_HINTS
28 #include <X11/Xlib.h>
29 #include <X11/Xutil.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
36 #include "WindowMaker.h"
38 #include "wcore.h"
39 #include "framewin.h"
40 #include "window.h"
41 #include "properties.h"
42 #include "icon.h"
43 #include "client.h"
44 #include "funcs.h"
46 #include "motif.h"
49 /* Motif window hints */
50 #define MWM_HINTS_FUNCTIONS (1L << 0)
51 #define MWM_HINTS_DECORATIONS (1L << 1)
53 /* bit definitions for MwmHints.functions */
54 #define MWM_FUNC_ALL (1L << 0)
55 #define MWM_FUNC_RESIZE (1L << 1)
56 #define MWM_FUNC_MOVE (1L << 2)
57 #define MWM_FUNC_MINIMIZE (1L << 3)
58 #define MWM_FUNC_MAXIMIZE (1L << 4)
59 #define MWM_FUNC_CLOSE (1L << 5)
61 /* bit definitions for MwmHints.decorations */
62 #define MWM_DECOR_ALL (1L << 0)
63 #define MWM_DECOR_BORDER (1L << 1)
64 #define MWM_DECOR_RESIZEH (1L << 2)
65 #define MWM_DECOR_TITLE (1L << 3)
66 #define MWM_DECOR_MENU (1L << 4)
67 #define MWM_DECOR_MINIMIZE (1L << 5)
68 #define MWM_DECOR_MAXIMIZE (1L << 6)
70 #define PROP_MWM_HINTS_ELEMENTS 4
72 /* Motif window hints */
73 typedef struct {
74 long flags;
75 long functions;
76 long decorations;
77 long inputMode;
78 } MWMHints;
80 static Atom _XA_MOTIF_WM_HINTS;
84 static void
85 setupMWMHints(WWindow *wwin, MWMHints *mwm_hints)
87 /*
88 * We will ignore all decoration hints that have an equivalent as
89 * functions, because wmaker does not distinguish decoration hints
92 if (mwm_hints->flags & MWM_HINTS_DECORATIONS) {
93 # ifdef DEBUG
94 fprintf(stderr,"has decor hints [ ");
95 # endif
96 WSETUFLAG(wwin, no_titlebar, 1);
97 WSETUFLAG(wwin, no_close_button, 1);
98 WSETUFLAG(wwin, no_miniaturize_button, 1);
99 WSETUFLAG(wwin, no_resizebar, 1);
101 if (mwm_hints->decorations & MWM_DECOR_ALL) {
102 # ifdef DEBUG
103 fprintf(stderr,"ALL ");
104 # endif
105 WSETUFLAG(wwin, no_titlebar, 0);
106 WSETUFLAG(wwin, no_close_button, 0);
107 WSETUFLAG(wwin, no_closable, 0);
108 WSETUFLAG(wwin, no_miniaturize_button, 0);
109 WSETUFLAG(wwin, no_miniaturizable, 0);
110 WSETUFLAG(wwin, no_resizebar, 0);
111 WSETUFLAG(wwin, no_resizable, 0);
114 if (mwm_hints->decorations & MWM_DECOR_BORDER) {
115 # ifdef DEBUG
116 fprintf(stderr,"(BORDER) ");
117 # endif
121 if (mwm_hints->decorations & MWM_DECOR_RESIZEH) {
122 # ifdef DEBUG
123 fprintf(stderr,"RESIZEH ");
124 # endif
125 WSETUFLAG(wwin, no_resizebar, 0);
128 if (mwm_hints->decorations & MWM_DECOR_TITLE) {
129 # ifdef DEBUG
130 fprintf(stderr,"TITLE+close ");
131 # endif
132 WSETUFLAG(wwin, no_titlebar, 0);
133 WSETUFLAG(wwin, no_close_button, 0);
134 WSETUFLAG(wwin, no_closable, 0);
137 if (mwm_hints->decorations & MWM_DECOR_MENU) {
138 # ifdef DEBUG
139 fprintf(stderr,"(MENU) ");
140 # endif
144 if (mwm_hints->decorations & MWM_DECOR_MINIMIZE) {
145 # ifdef DEBUG
146 fprintf(stderr,"MINIMIZE ");
147 # endif
148 WSETUFLAG(wwin, no_miniaturize_button, 0);
149 WSETUFLAG(wwin, no_miniaturizable, 0);
152 if (mwm_hints->decorations & MWM_DECOR_MAXIMIZE) {
153 # ifdef DEBUG
154 fprintf(stderr,"(MAXIMIZE) ");
155 # endif
158 # ifdef DEBUG
159 fprintf(stderr,"]\n");
160 # endif
164 if (mwm_hints->flags & MWM_HINTS_FUNCTIONS) {
165 # ifdef DEBUG
166 fprintf(stderr,"has function hints [ ");
167 # endif
168 WSETUFLAG(wwin, no_closable, 1);
169 WSETUFLAG(wwin, no_miniaturizable, 1);
170 WSETUFLAG(wwin, no_resizable, 1);
172 if (mwm_hints->functions & MWM_FUNC_ALL) {
173 # ifdef DEBUG
174 fprintf(stderr,"ALL ");
175 # endif
176 WSETUFLAG(wwin, no_closable, 0);
177 WSETUFLAG(wwin, no_miniaturizable, 0);
178 WSETUFLAG(wwin, no_resizable, 0);
180 if (mwm_hints->functions & MWM_FUNC_RESIZE) {
181 # ifdef DEBUG
182 fprintf(stderr,"RESIZE ");
183 # endif
184 WSETUFLAG(wwin, no_resizable, 0);
187 if (mwm_hints->functions & MWM_FUNC_MOVE) {
188 # ifdef DEBUG
189 fprintf(stderr,"(MOVE) ");
190 # endif
193 if (mwm_hints->functions & MWM_FUNC_MINIMIZE) {
194 # ifdef DEBUG
195 fprintf(stderr,"MINIMIZE ");
196 # endif
197 WSETUFLAG(wwin, no_miniaturizable, 0);
199 if (mwm_hints->functions & MWM_FUNC_MAXIMIZE) {
200 # ifdef DEBUG
201 fprintf(stderr,"MAXIMIZE ");
202 /* a window must be resizable to be maximizable */
203 WSETUFLAG(wwin, no_resizable, 0);
204 # endif
206 if (mwm_hints->functions & MWM_FUNC_CLOSE) {
207 # ifdef DEBUG
208 fprintf(stderr,"CLOSE ");
209 # endif
210 WSETUFLAG(wwin, no_closable, 0);
212 # ifdef DEBUG
213 fprintf(stderr,"]\n");
214 # endif
219 static int
220 getMWMHints(Window window, MWMHints *mwmhints)
222 unsigned long *data;
224 if (!_XA_MOTIF_WM_HINTS) {
225 _XA_MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
228 data = (unsigned long*)PropGetCheckProperty(window, _XA_MOTIF_WM_HINTS,
229 _XA_MOTIF_WM_HINTS, 32,
230 PROP_MWM_HINTS_ELEMENTS, NULL);
232 if (!data)
233 return 0;
235 mwmhints->flags = data[0];
236 mwmhints->functions = data[1];
237 mwmhints->decorations = data[2];
238 mwmhints->inputMode = data[3];
240 XFree(data);
242 return 1;
246 void
247 wMWMCheckClientHints(WWindow *wwin)
249 MWMHints hints;
251 if (getMWMHints(wwin->client_win, &hints)) {
252 setupMWMHints(wwin, &hints);
258 #endif /* MWM_HINTS */