Change to the linux kernel coding style
[wmaker-crm.git] / src / motif.c
Commit [+]AuthorDateLineData
0261c326 dan1999-01-06 15:22:33 +00001/* motif.c-- stuff for support for mwm hints
6830b057 dan2004-10-12 21:28:27 +00002 *
0261c326 dan1999-01-06 15:22:33 +00003 * Window Maker window manager
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1998-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
0261c326 dan1999-01-06 15:22:33 +00007 * 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
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
0261c326 dan1999-01-06 15:22:33 +000020 * USA.
21 */
22
0261c326 dan1999-01-06 15:22:33 +000023#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
0261c326 dan1999-01-06 15:22:33 +000034#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
0261c326 dan1999-01-06 15:22:33 +000046/* 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
cb320b2f dan1999-01-11 12:28:12 +000067#define PROP_MWM_HINTS_ELEMENTS 5
0261c326 dan1999-01-06 15:22:33 +000068
69/* Motif window hints */
70typedef struct {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020071 long flags;
72 long functions;
73 long decorations;
74 long inputMode;
75 long unknown;
0261c326 dan1999-01-06 15:22:33 +000076} MWMHints;
77
78static Atom _XA_MOTIF_WM_HINTS;
79
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020080static void setupMWMHints(WWindow * wwin, MWMHints * mwm_hints)
0261c326 dan1999-01-06 15:22:33 +000081{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020082 /*
83 * We will ignore all decoration hints that have an equivalent as
84 * functions, because wmaker does not distinguish decoration hints
85 */
0261c326 dan1999-01-06 15:22:33 +000086
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020087 if (mwm_hints->flags & MWM_HINTS_DECORATIONS) {
0261c326 dan1999-01-06 15:22:33 +000088# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020089 fprintf(stderr, "has decor hints [ ");
0261c326 dan1999-01-06 15:22:33 +000090# endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020091 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);
0261c326 dan1999-01-06 15:22:33 +000095
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020096 if (mwm_hints->decorations & MWM_DECOR_ALL) {
0261c326 dan1999-01-06 15:22:33 +000097# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020098 fprintf(stderr, "ALL ");
0261c326 dan1999-01-06 15:22:33 +000099# endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200100 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) {
0261c326 dan1999-01-06 15:22:33 +0000117# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200118 fprintf(stderr, "RESIZEH ");
0261c326 dan1999-01-06 15:22:33 +0000119# endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200120 WSETUFLAG(wwin, no_resizebar, 0);
121 }
0261c326 dan1999-01-06 15:22:33 +0000122
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200123 if (mwm_hints->decorations & MWM_DECOR_TITLE) {
0261c326 dan1999-01-06 15:22:33 +0000124# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200125 fprintf(stderr, "TITLE+close ");
0261c326 dan1999-01-06 15:22:33 +0000126# endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200127 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) {
0261c326 dan1999-01-06 15:22:33 +0000140# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200141 fprintf(stderr, "MINIMIZE ");
0261c326 dan1999-01-06 15:22:33 +0000142# endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200143 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 */
0261c326 dan1999-01-06 15:22:33 +0000153# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200154 fprintf(stderr, "]\n");
0261c326 dan1999-01-06 15:22:33 +0000155# endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200156 }
0261c326 dan1999-01-06 15:22:33 +0000157
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200158 if (mwm_hints->flags & MWM_HINTS_FUNCTIONS) {
0261c326 dan1999-01-06 15:22:33 +0000159# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200160 fprintf(stderr, "has function hints [ ");
0261c326 dan1999-01-06 15:22:33 +0000161# endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200162 WSETUFLAG(wwin, no_closable, 1);
163 WSETUFLAG(wwin, no_miniaturizable, 1);
164 WSETUFLAG(wwin, no_resizable, 1);
6830b057 dan2004-10-12 21:28:27 +0000165
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200166 if (mwm_hints->functions & MWM_FUNC_ALL) {
6830b057 dan2004-10-12 21:28:27 +0000167# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200168 fprintf(stderr, "ALL ");
0261c326 dan1999-01-06 15:22:33 +0000169# endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200170 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) {
6830b057 dan2004-10-12 21:28:27 +0000175# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200176 fprintf(stderr, "RESIZE ");
0261c326 dan1999-01-06 15:22:33 +0000177# endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200178 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) {
6830b057 dan2004-10-12 21:28:27 +0000188# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200189 fprintf(stderr, "MINIMIZE ");
0261c326 dan1999-01-06 15:22:33 +0000190# endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200191 WSETUFLAG(wwin, no_miniaturizable, 0);
192 }
193 if (mwm_hints->functions & MWM_FUNC_MAXIMIZE) {
6830b057 dan2004-10-12 21:28:27 +0000194# ifdef DEBUG
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200195 fprintf(stderr, "MAXIMIZE ");
196 /* a window must be resizable to be maximizable */
197 WSETUFLAG(wwin, no_resizable, 0);
0261c326 dan1999-01-06 15:22:33 +0000198# endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200199 }
200 if (mwm_hints->functions & MWM_FUNC_CLOSE) {
6830b057 dan2004-10-12 21:28:27 +0000201# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200202 fprintf(stderr, "CLOSE ");
0261c326 dan1999-01-06 15:22:33 +0000203# endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200204 WSETUFLAG(wwin, no_closable, 0);
205 }
6830b057 dan2004-10-12 21:28:27 +0000206# ifdef DEBUG
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200207 fprintf(stderr, "]\n");
0261c326 dan1999-01-06 15:22:33 +0000208# endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200209 }
0261c326 dan1999-01-06 15:22:33 +0000210}
211
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200212static int getMWMHints(Window window, MWMHints * mwmhints)
0261c326 dan1999-01-06 15:22:33 +0000213{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200214 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;
0261c326 dan1999-01-06 15:22:33 +0000238}
239
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200240void wMWMCheckClientHints(WWindow * wwin)
0261c326 dan1999-01-06 15:22:33 +0000241{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200242 MWMHints hints;
6830b057 dan2004-10-12 21:28:27 +0000243
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200244 if (getMWMHints(wwin->client_win, &hints)) {
245 setupMWMHints(wwin, &hints);
246 }
0261c326 dan1999-01-06 15:22:33 +0000247}
248
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200249#endif /* MWM_HINTS */