Cleanup includes of wcore.h, defaults.h and pixmap.h
[wmaker-crm.git] / src / motif.c
blob7b674d7db990989f744e9bafa63667adcbb6c109
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.
23 #include "wconfig.h"
25 #ifdef MWM_HINTS
27 #include <X11/Xlib.h>
28 #include <X11/Xutil.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
34 #include "WindowMaker.h"
36 #include "framewin.h"
37 #include "window.h"
38 #include "properties.h"
39 #include "icon.h"
40 #include "client.h"
41 #include "funcs.h"
43 #include "motif.h"
45 /* Motif window hints */
46 #define MWM_HINTS_FUNCTIONS (1L << 0)
47 #define MWM_HINTS_DECORATIONS (1L << 1)
49 /* bit definitions for MwmHints.functions */
50 #define MWM_FUNC_ALL (1L << 0)
51 #define MWM_FUNC_RESIZE (1L << 1)
52 #define MWM_FUNC_MOVE (1L << 2)
53 #define MWM_FUNC_MINIMIZE (1L << 3)
54 #define MWM_FUNC_MAXIMIZE (1L << 4)
55 #define MWM_FUNC_CLOSE (1L << 5)
57 /* bit definitions for MwmHints.decorations */
58 #define MWM_DECOR_ALL (1L << 0)
59 #define MWM_DECOR_BORDER (1L << 1)
60 #define MWM_DECOR_RESIZEH (1L << 2)
61 #define MWM_DECOR_TITLE (1L << 3)
62 #define MWM_DECOR_MENU (1L << 4)
63 #define MWM_DECOR_MINIMIZE (1L << 5)
64 #define MWM_DECOR_MAXIMIZE (1L << 6)
66 #define PROP_MWM_HINTS_ELEMENTS 5
68 /* Motif window hints */
69 typedef struct {
70 long flags;
71 long functions;
72 long decorations;
73 long inputMode;
74 long unknown;
75 } MWMHints;
77 static Atom _XA_MOTIF_WM_HINTS;
79 static void setupMWMHints(WWindow * wwin, MWMHints * mwm_hints)
82 * We will ignore all decoration hints that have an equivalent as
83 * functions, because wmaker does not distinguish decoration hints
86 if (mwm_hints->flags & MWM_HINTS_DECORATIONS) {
87 # ifdef DEBUG
88 fprintf(stderr, "has decor hints [ ");
89 # endif
90 WSETUFLAG(wwin, no_titlebar, 1);
91 WSETUFLAG(wwin, no_close_button, 1);
92 WSETUFLAG(wwin, no_miniaturize_button, 1);
93 WSETUFLAG(wwin, no_resizebar, 1);
95 if (mwm_hints->decorations & MWM_DECOR_ALL) {
96 # ifdef DEBUG
97 fprintf(stderr, "ALL ");
98 # endif
99 WSETUFLAG(wwin, no_titlebar, 0);
100 WSETUFLAG(wwin, no_close_button, 0);
101 WSETUFLAG(wwin, no_closable, 0);
102 WSETUFLAG(wwin, no_miniaturize_button, 0);
103 WSETUFLAG(wwin, no_miniaturizable, 0);
104 WSETUFLAG(wwin, no_resizebar, 0);
105 WSETUFLAG(wwin, no_resizable, 0);
108 if (mwm_hints->decorations & MWM_DECOR_BORDER) {
109 # ifdef DEBUG
110 fprintf(stderr,"(BORDER) ");
111 # endif
115 if (mwm_hints->decorations & MWM_DECOR_RESIZEH) {
116 # ifdef DEBUG
117 fprintf(stderr, "RESIZEH ");
118 # endif
119 WSETUFLAG(wwin, no_resizebar, 0);
122 if (mwm_hints->decorations & MWM_DECOR_TITLE) {
123 # ifdef DEBUG
124 fprintf(stderr, "TITLE+close ");
125 # endif
126 WSETUFLAG(wwin, no_titlebar, 0);
127 WSETUFLAG(wwin, no_close_button, 0);
128 WSETUFLAG(wwin, no_closable, 0);
131 if (mwm_hints->decorations & MWM_DECOR_MENU) {
132 # ifdef DEBUG
133 fprintf(stderr,"(MENU) ");
134 # endif
138 if (mwm_hints->decorations & MWM_DECOR_MINIMIZE) {
139 # ifdef DEBUG
140 fprintf(stderr, "MINIMIZE ");
141 # endif
142 WSETUFLAG(wwin, no_miniaturize_button, 0);
143 WSETUFLAG(wwin, no_miniaturizable, 0);
146 if (mwm_hints->decorations & MWM_DECOR_MAXIMIZE) {
147 # ifdef DEBUG
148 fprintf(stderr,"(MAXIMIZE) ");
149 # endif
152 # ifdef DEBUG
153 fprintf(stderr, "]\n");
154 # endif
157 if (mwm_hints->flags & MWM_HINTS_FUNCTIONS) {
158 # ifdef DEBUG
159 fprintf(stderr, "has function hints [ ");
160 # endif
161 WSETUFLAG(wwin, no_closable, 1);
162 WSETUFLAG(wwin, no_miniaturizable, 1);
163 WSETUFLAG(wwin, no_resizable, 1);
165 if (mwm_hints->functions & MWM_FUNC_ALL) {
166 # ifdef DEBUG
167 fprintf(stderr, "ALL ");
168 # endif
169 WSETUFLAG(wwin, no_closable, 0);
170 WSETUFLAG(wwin, no_miniaturizable, 0);
171 WSETUFLAG(wwin, no_resizable, 0);
173 if (mwm_hints->functions & MWM_FUNC_RESIZE) {
174 # ifdef DEBUG
175 fprintf(stderr, "RESIZE ");
176 # endif
177 WSETUFLAG(wwin, no_resizable, 0);
180 if (mwm_hints->functions & MWM_FUNC_MOVE) {
181 # ifdef DEBUG
182 fprintf(stderr,"(MOVE) ");
183 # endif
186 if (mwm_hints->functions & MWM_FUNC_MINIMIZE) {
187 # ifdef DEBUG
188 fprintf(stderr, "MINIMIZE ");
189 # endif
190 WSETUFLAG(wwin, no_miniaturizable, 0);
192 if (mwm_hints->functions & MWM_FUNC_MAXIMIZE) {
193 # ifdef DEBUG
194 fprintf(stderr, "MAXIMIZE ");
195 /* a window must be resizable to be maximizable */
196 WSETUFLAG(wwin, no_resizable, 0);
197 # endif
199 if (mwm_hints->functions & MWM_FUNC_CLOSE) {
200 # ifdef DEBUG
201 fprintf(stderr, "CLOSE ");
202 # endif
203 WSETUFLAG(wwin, no_closable, 0);
205 # ifdef DEBUG
206 fprintf(stderr, "]\n");
207 # endif
211 static int getMWMHints(Window window, MWMHints * mwmhints)
213 unsigned long *data;
214 int count;
216 if (!_XA_MOTIF_WM_HINTS) {
217 _XA_MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
220 data = (unsigned long *)PropGetCheckProperty(window, _XA_MOTIF_WM_HINTS,
221 _XA_MOTIF_WM_HINTS, 32, 0, &count);
223 if (!data)
224 return 0;
226 if (count >= 4) {
227 mwmhints->flags = data[0];
228 mwmhints->functions = data[1];
229 mwmhints->decorations = data[2];
230 mwmhints->inputMode = data[3];
231 if (count > 5)
232 mwmhints->unknown = data[4];
234 XFree(data);
236 return 1;
239 void wMWMCheckClientHints(WWindow * wwin)
241 MWMHints hints;
243 if (getMWMHints(wwin->client_win, &hints)) {
244 setupMWMHints(wwin, &hints);
248 #endif /* MWM_HINTS */