Maximus: Tiled Maximization
[wmaker-crm.git] / src / motif.c
blobfeb123f8ce7e41db978e0f5d00104fcba8f72068
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 "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"
44 #include "motif.h"
46 /* Motif window hints */
47 #define MWM_HINTS_FUNCTIONS (1L << 0)
48 #define MWM_HINTS_DECORATIONS (1L << 1)
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)
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)
67 #define PROP_MWM_HINTS_ELEMENTS 5
69 /* Motif window hints */
70 typedef struct {
71 long flags;
72 long functions;
73 long decorations;
74 long inputMode;
75 long unknown;
76 } MWMHints;
78 static Atom _XA_MOTIF_WM_HINTS;
80 static void setupMWMHints(WWindow * wwin, MWMHints * mwm_hints)
83 * We will ignore all decoration hints that have an equivalent as
84 * functions, because wmaker does not distinguish decoration hints
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);
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);
109 if (mwm_hints->decorations & MWM_DECOR_BORDER) {
110 # ifdef DEBUG
111 fprintf(stderr,"(BORDER) ");
112 # endif
116 if (mwm_hints->decorations & MWM_DECOR_RESIZEH) {
117 # ifdef DEBUG
118 fprintf(stderr, "RESIZEH ");
119 # endif
120 WSETUFLAG(wwin, no_resizebar, 0);
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);
132 if (mwm_hints->decorations & MWM_DECOR_MENU) {
133 # ifdef DEBUG
134 fprintf(stderr,"(MENU) ");
135 # endif
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);
147 if (mwm_hints->decorations & MWM_DECOR_MAXIMIZE) {
148 # ifdef DEBUG
149 fprintf(stderr,"(MAXIMIZE) ");
150 # endif
153 # ifdef DEBUG
154 fprintf(stderr, "]\n");
155 # endif
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);
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);
174 if (mwm_hints->functions & MWM_FUNC_RESIZE) {
175 # ifdef DEBUG
176 fprintf(stderr, "RESIZE ");
177 # endif
178 WSETUFLAG(wwin, no_resizable, 0);
181 if (mwm_hints->functions & MWM_FUNC_MOVE) {
182 # ifdef DEBUG
183 fprintf(stderr,"(MOVE) ");
184 # endif
187 if (mwm_hints->functions & MWM_FUNC_MINIMIZE) {
188 # ifdef DEBUG
189 fprintf(stderr, "MINIMIZE ");
190 # endif
191 WSETUFLAG(wwin, no_miniaturizable, 0);
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
200 if (mwm_hints->functions & MWM_FUNC_CLOSE) {
201 # ifdef DEBUG
202 fprintf(stderr, "CLOSE ");
203 # endif
204 WSETUFLAG(wwin, no_closable, 0);
206 # ifdef DEBUG
207 fprintf(stderr, "]\n");
208 # endif
212 static int getMWMHints(Window window, MWMHints * mwmhints)
214 unsigned long *data;
215 int count;
217 if (!_XA_MOTIF_WM_HINTS) {
218 _XA_MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
221 data = (unsigned long *)PropGetCheckProperty(window, _XA_MOTIF_WM_HINTS,
222 _XA_MOTIF_WM_HINTS, 32, 0, &count);
224 if (!data)
225 return 0;
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];
235 XFree(data);
237 return 1;
240 void wMWMCheckClientHints(WWindow * wwin)
242 MWMHints hints;
244 if (getMWMHints(wwin->client_win, &hints)) {
245 setupMWMHints(wwin, &hints);
249 #endif /* MWM_HINTS */