Change to the linux kernel coding style
[wmaker-crm.git] / src / motif.c
1 /* motif.c-- stuff for support for mwm hints
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1998-2003 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.
11 *
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.
16 *
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.
21 */
22
23 #include "wconfig.h"
24
25 #ifdef MWM_HINTS
26
27 #include <X11/Xlib.h>
28 #include <X11/Xutil.h>
29
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33
34 #include "WindowMaker.h"
35
36 #include "wcore.h"
37 #include "framewin.h"
38 #include "window.h"
39 #include "properties.h"
40 #include "icon.h"
41 #include "client.h"
42 #include "funcs.h"
43
44 #include "motif.h"
45
46 /* Motif window hints */
47 #define MWM_HINTS_FUNCTIONS (1L << 0)
48 #define MWM_HINTS_DECORATIONS (1L << 1)
49
50 /* bit definitions for MwmHints.functions */
51 #define MWM_FUNC_ALL (1L << 0)
52 #define MWM_FUNC_RESIZE (1L << 1)
53 #define MWM_FUNC_MOVE (1L << 2)
54 #define MWM_FUNC_MINIMIZE (1L << 3)
55 #define MWM_FUNC_MAXIMIZE (1L << 4)
56 #define MWM_FUNC_CLOSE (1L << 5)
57
58 /* bit definitions for MwmHints.decorations */
59 #define MWM_DECOR_ALL (1L << 0)
60 #define MWM_DECOR_BORDER (1L << 1)
61 #define MWM_DECOR_RESIZEH (1L << 2)
62 #define MWM_DECOR_TITLE (1L << 3)
63 #define MWM_DECOR_MENU (1L << 4)
64 #define MWM_DECOR_MINIMIZE (1L << 5)
65 #define MWM_DECOR_MAXIMIZE (1L << 6)
66
67 #define PROP_MWM_HINTS_ELEMENTS 5
68
69 /* Motif window hints */
70 typedef struct {
71 long flags;
72 long functions;
73 long decorations;
74 long inputMode;
75 long unknown;
76 } MWMHints;
77
78 static Atom _XA_MOTIF_WM_HINTS;
79
80 static void setupMWMHints(WWindow * wwin, MWMHints * mwm_hints)
81 {
82 /*
83 * We will ignore all decoration hints that have an equivalent as
84 * functions, because wmaker does not distinguish decoration hints
85 */
86
87 if (mwm_hints->flags & MWM_HINTS_DECORATIONS) {
88 # ifdef DEBUG
89 fprintf(stderr, "has decor hints [ ");
90 # endif
91 WSETUFLAG(wwin, no_titlebar, 1);
92 WSETUFLAG(wwin, no_close_button, 1);
93 WSETUFLAG(wwin, no_miniaturize_button, 1);
94 WSETUFLAG(wwin, no_resizebar, 1);
95
96 if (mwm_hints->decorations & MWM_DECOR_ALL) {
97 # ifdef DEBUG
98 fprintf(stderr, "ALL ");
99 # endif
100 WSETUFLAG(wwin, no_titlebar, 0);
101 WSETUFLAG(wwin, no_close_button, 0);
102 WSETUFLAG(wwin, no_closable, 0);
103 WSETUFLAG(wwin, no_miniaturize_button, 0);
104 WSETUFLAG(wwin, no_miniaturizable, 0);
105 WSETUFLAG(wwin, no_resizebar, 0);
106 WSETUFLAG(wwin, no_resizable, 0);
107 }
108 /*
109 if (mwm_hints->decorations & MWM_DECOR_BORDER) {
110 # ifdef DEBUG
111 fprintf(stderr,"(BORDER) ");
112 # endif
113 }
114 */
115
116 if (mwm_hints->decorations & MWM_DECOR_RESIZEH) {
117 # ifdef DEBUG
118 fprintf(stderr, "RESIZEH ");
119 # endif
120 WSETUFLAG(wwin, no_resizebar, 0);
121 }
122
123 if (mwm_hints->decorations & MWM_DECOR_TITLE) {
124 # ifdef DEBUG
125 fprintf(stderr, "TITLE+close ");
126 # endif
127 WSETUFLAG(wwin, no_titlebar, 0);
128 WSETUFLAG(wwin, no_close_button, 0);
129 WSETUFLAG(wwin, no_closable, 0);
130 }
131 /*
132 if (mwm_hints->decorations & MWM_DECOR_MENU) {
133 # ifdef DEBUG
134 fprintf(stderr,"(MENU) ");
135 # endif
136 }
137 */
138
139 if (mwm_hints->decorations & MWM_DECOR_MINIMIZE) {
140 # ifdef DEBUG
141 fprintf(stderr, "MINIMIZE ");
142 # endif
143 WSETUFLAG(wwin, no_miniaturize_button, 0);
144 WSETUFLAG(wwin, no_miniaturizable, 0);
145 }
146 /*
147 if (mwm_hints->decorations & MWM_DECOR_MAXIMIZE) {
148 # ifdef DEBUG
149 fprintf(stderr,"(MAXIMIZE) ");
150 # endif
151 }
152 */
153 # ifdef DEBUG
154 fprintf(stderr, "]\n");
155 # endif
156 }
157
158 if (mwm_hints->flags & MWM_HINTS_FUNCTIONS) {
159 # ifdef DEBUG
160 fprintf(stderr, "has function hints [ ");
161 # endif
162 WSETUFLAG(wwin, no_closable, 1);
163 WSETUFLAG(wwin, no_miniaturizable, 1);
164 WSETUFLAG(wwin, no_resizable, 1);
165
166 if (mwm_hints->functions & MWM_FUNC_ALL) {
167 # ifdef DEBUG
168 fprintf(stderr, "ALL ");
169 # endif
170 WSETUFLAG(wwin, no_closable, 0);
171 WSETUFLAG(wwin, no_miniaturizable, 0);
172 WSETUFLAG(wwin, no_resizable, 0);
173 }
174 if (mwm_hints->functions & MWM_FUNC_RESIZE) {
175 # ifdef DEBUG
176 fprintf(stderr, "RESIZE ");
177 # endif
178 WSETUFLAG(wwin, no_resizable, 0);
179 }
180 /*
181 if (mwm_hints->functions & MWM_FUNC_MOVE) {
182 # ifdef DEBUG
183 fprintf(stderr,"(MOVE) ");
184 # endif
185 }
186 */
187 if (mwm_hints->functions & MWM_FUNC_MINIMIZE) {
188 # ifdef DEBUG
189 fprintf(stderr, "MINIMIZE ");
190 # endif
191 WSETUFLAG(wwin, no_miniaturizable, 0);
192 }
193 if (mwm_hints->functions & MWM_FUNC_MAXIMIZE) {
194 # ifdef DEBUG
195 fprintf(stderr, "MAXIMIZE ");
196 /* a window must be resizable to be maximizable */
197 WSETUFLAG(wwin, no_resizable, 0);
198 # endif
199 }
200 if (mwm_hints->functions & MWM_FUNC_CLOSE) {
201 # ifdef DEBUG
202 fprintf(stderr, "CLOSE ");
203 # endif
204 WSETUFLAG(wwin, no_closable, 0);
205 }
206 # ifdef DEBUG
207 fprintf(stderr, "]\n");
208 # endif
209 }
210 }
211
212 static int getMWMHints(Window window, MWMHints * mwmhints)
213 {
214 unsigned long *data;
215 int count;
216
217 if (!_XA_MOTIF_WM_HINTS) {
218 _XA_MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
219 }
220
221 data = (unsigned long *)PropGetCheckProperty(window, _XA_MOTIF_WM_HINTS,
222 _XA_MOTIF_WM_HINTS, 32, 0, &count);
223
224 if (!data)
225 return 0;
226
227 if (count >= 4) {
228 mwmhints->flags = data[0];
229 mwmhints->functions = data[1];
230 mwmhints->decorations = data[2];
231 mwmhints->inputMode = data[3];
232 if (count > 5)
233 mwmhints->unknown = data[4];
234 }
235 XFree(data);
236
237 return 1;
238 }
239
240 void wMWMCheckClientHints(WWindow * wwin)
241 {
242 MWMHints hints;
243
244 if (getMWMHints(wwin->client_win, &hints)) {
245 setupMWMHints(wwin, &hints);
246 }
247 }
248
249 #endif /* MWM_HINTS */