changed indentation to use spaces only
[wmaker-crm.git] / src / motif.c
blobe495e976453ae5db26a25f9da6b2152cef010a50
1 /* motif.c-- stuff for support for mwm hints
3 * Window Maker window manager
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
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 5
72 /* Motif window hints */
73 typedef struct {
74 long flags;
75 long functions;
76 long decorations;
77 long inputMode;
78 long unknown;
79 } MWMHints;
81 static Atom _XA_MOTIF_WM_HINTS;
85 static void
86 setupMWMHints(WWindow *wwin, MWMHints *mwm_hints)
89 * We will ignore all decoration hints that have an equivalent as
90 * functions, because wmaker does not distinguish decoration hints
93 if (mwm_hints->flags & MWM_HINTS_DECORATIONS) {
94 # ifdef DEBUG
95 fprintf(stderr,"has decor hints [ ");
96 # endif
97 WSETUFLAG(wwin, no_titlebar, 1);
98 WSETUFLAG(wwin, no_close_button, 1);
99 WSETUFLAG(wwin, no_miniaturize_button, 1);
100 WSETUFLAG(wwin, no_resizebar, 1);
102 if (mwm_hints->decorations & MWM_DECOR_ALL) {
103 # ifdef DEBUG
104 fprintf(stderr,"ALL ");
105 # endif
106 WSETUFLAG(wwin, no_titlebar, 0);
107 WSETUFLAG(wwin, no_close_button, 0);
108 WSETUFLAG(wwin, no_closable, 0);
109 WSETUFLAG(wwin, no_miniaturize_button, 0);
110 WSETUFLAG(wwin, no_miniaturizable, 0);
111 WSETUFLAG(wwin, no_resizebar, 0);
112 WSETUFLAG(wwin, no_resizable, 0);
115 if (mwm_hints->decorations & MWM_DECOR_BORDER) {
116 # ifdef DEBUG
117 fprintf(stderr,"(BORDER) ");
118 # endif
122 if (mwm_hints->decorations & MWM_DECOR_RESIZEH) {
123 # ifdef DEBUG
124 fprintf(stderr,"RESIZEH ");
125 # endif
126 WSETUFLAG(wwin, no_resizebar, 0);
129 if (mwm_hints->decorations & MWM_DECOR_TITLE) {
130 # ifdef DEBUG
131 fprintf(stderr,"TITLE+close ");
132 # endif
133 WSETUFLAG(wwin, no_titlebar, 0);
134 WSETUFLAG(wwin, no_close_button, 0);
135 WSETUFLAG(wwin, no_closable, 0);
138 if (mwm_hints->decorations & MWM_DECOR_MENU) {
139 # ifdef DEBUG
140 fprintf(stderr,"(MENU) ");
141 # endif
145 if (mwm_hints->decorations & MWM_DECOR_MINIMIZE) {
146 # ifdef DEBUG
147 fprintf(stderr,"MINIMIZE ");
148 # endif
149 WSETUFLAG(wwin, no_miniaturize_button, 0);
150 WSETUFLAG(wwin, no_miniaturizable, 0);
153 if (mwm_hints->decorations & MWM_DECOR_MAXIMIZE) {
154 # ifdef DEBUG
155 fprintf(stderr,"(MAXIMIZE) ");
156 # endif
159 # ifdef DEBUG
160 fprintf(stderr,"]\n");
161 # endif
165 if (mwm_hints->flags & MWM_HINTS_FUNCTIONS) {
166 # ifdef DEBUG
167 fprintf(stderr,"has function hints [ ");
168 # endif
169 WSETUFLAG(wwin, no_closable, 1);
170 WSETUFLAG(wwin, no_miniaturizable, 1);
171 WSETUFLAG(wwin, no_resizable, 1);
173 if (mwm_hints->functions & MWM_FUNC_ALL) {
174 # ifdef DEBUG
175 fprintf(stderr,"ALL ");
176 # endif
177 WSETUFLAG(wwin, no_closable, 0);
178 WSETUFLAG(wwin, no_miniaturizable, 0);
179 WSETUFLAG(wwin, no_resizable, 0);
181 if (mwm_hints->functions & MWM_FUNC_RESIZE) {
182 # ifdef DEBUG
183 fprintf(stderr,"RESIZE ");
184 # endif
185 WSETUFLAG(wwin, no_resizable, 0);
188 if (mwm_hints->functions & MWM_FUNC_MOVE) {
189 # ifdef DEBUG
190 fprintf(stderr,"(MOVE) ");
191 # endif
194 if (mwm_hints->functions & MWM_FUNC_MINIMIZE) {
195 # ifdef DEBUG
196 fprintf(stderr,"MINIMIZE ");
197 # endif
198 WSETUFLAG(wwin, no_miniaturizable, 0);
200 if (mwm_hints->functions & MWM_FUNC_MAXIMIZE) {
201 # ifdef DEBUG
202 fprintf(stderr,"MAXIMIZE ");
203 /* a window must be resizable to be maximizable */
204 WSETUFLAG(wwin, no_resizable, 0);
205 # endif
207 if (mwm_hints->functions & MWM_FUNC_CLOSE) {
208 # ifdef DEBUG
209 fprintf(stderr,"CLOSE ");
210 # endif
211 WSETUFLAG(wwin, no_closable, 0);
213 # ifdef DEBUG
214 fprintf(stderr,"]\n");
215 # endif
220 static int
221 getMWMHints(Window window, MWMHints *mwmhints)
223 unsigned long *data;
224 int count;
226 if (!_XA_MOTIF_WM_HINTS) {
227 _XA_MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
230 data = (unsigned long*)PropGetCheckProperty(window, _XA_MOTIF_WM_HINTS,
231 _XA_MOTIF_WM_HINTS, 32,
232 0, &count);
234 if (!data)
235 return 0;
237 if (count >= 4) {
238 mwmhints->flags = data[0];
239 mwmhints->functions = data[1];
240 mwmhints->decorations = data[2];
241 mwmhints->inputMode = data[3];
242 if (count > 5)
243 mwmhints->unknown = data[4];
245 XFree(data);
247 return 1;
251 void
252 wMWMCheckClientHints(WWindow *wwin)
254 MWMHints hints;
256 if (getMWMHints(wwin->client_win, &hints)) {
257 setupMWMHints(wwin, &hints);
263 #endif /* MWM_HINTS */