Improve dockapp recognition
[wmaker-crm.git] / src / motif.c
blobc371e3893fef8c8231bbdc27c576f78ddfdc601b
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>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
33 #include "WindowMaker.h"
34 #include "framewin.h"
35 #include "window.h"
36 #include "properties.h"
37 #include "icon.h"
38 #include "client.h"
39 #include "funcs.h"
40 #include "motif.h"
42 /* Motif window hints */
43 #define MWM_HINTS_FUNCTIONS (1L << 0)
44 #define MWM_HINTS_DECORATIONS (1L << 1)
46 /* bit definitions for MwmHints.functions */
47 #define MWM_FUNC_ALL (1L << 0)
48 #define MWM_FUNC_RESIZE (1L << 1)
49 #define MWM_FUNC_MOVE (1L << 2)
50 #define MWM_FUNC_MINIMIZE (1L << 3)
51 #define MWM_FUNC_MAXIMIZE (1L << 4)
52 #define MWM_FUNC_CLOSE (1L << 5)
54 /* bit definitions for MwmHints.decorations */
55 #define MWM_DECOR_ALL (1L << 0)
56 #define MWM_DECOR_BORDER (1L << 1)
57 #define MWM_DECOR_RESIZEH (1L << 2)
58 #define MWM_DECOR_TITLE (1L << 3)
59 #define MWM_DECOR_MENU (1L << 4)
60 #define MWM_DECOR_MINIMIZE (1L << 5)
61 #define MWM_DECOR_MAXIMIZE (1L << 6)
63 /* Motif window hints */
64 typedef struct {
65 long flags;
66 long functions;
67 long decorations;
68 long inputMode;
69 long unknown;
70 } MWMHints;
72 static Atom _XA_MOTIF_WM_HINTS;
74 static void setupMWMHints(WWindow *wwin, MWMHints *mwm_hints)
77 * We will ignore all decoration hints that have an equivalent as
78 * functions, because wmaker does not distinguish decoration hints
81 if (mwm_hints->flags & MWM_HINTS_DECORATIONS) {
82 WSETUFLAG(wwin, no_titlebar, 1);
83 WSETUFLAG(wwin, no_close_button, 1);
84 WSETUFLAG(wwin, no_miniaturize_button, 1);
85 WSETUFLAG(wwin, no_resizebar, 1);
87 if (mwm_hints->decorations & MWM_DECOR_ALL) {
88 WSETUFLAG(wwin, no_titlebar, 0);
89 WSETUFLAG(wwin, no_close_button, 0);
90 WSETUFLAG(wwin, no_closable, 0);
91 WSETUFLAG(wwin, no_miniaturize_button, 0);
92 WSETUFLAG(wwin, no_miniaturizable, 0);
93 WSETUFLAG(wwin, no_resizebar, 0);
94 WSETUFLAG(wwin, no_resizable, 0);
97 if (mwm_hints->decorations & MWM_DECOR_RESIZEH)
98 WSETUFLAG(wwin, no_resizebar, 0);
100 if (mwm_hints->decorations & MWM_DECOR_TITLE) {
101 WSETUFLAG(wwin, no_titlebar, 0);
102 WSETUFLAG(wwin, no_close_button, 0);
103 WSETUFLAG(wwin, no_closable, 0);
106 if (mwm_hints->decorations & MWM_DECOR_MINIMIZE) {
107 WSETUFLAG(wwin, no_miniaturize_button, 0);
108 WSETUFLAG(wwin, no_miniaturizable, 0);
112 if (mwm_hints->flags & MWM_HINTS_FUNCTIONS) {
113 WSETUFLAG(wwin, no_closable, 1);
114 WSETUFLAG(wwin, no_miniaturizable, 1);
115 WSETUFLAG(wwin, no_resizable, 1);
117 if (mwm_hints->functions & MWM_FUNC_ALL) {
118 WSETUFLAG(wwin, no_closable, 0);
119 WSETUFLAG(wwin, no_miniaturizable, 0);
120 WSETUFLAG(wwin, no_resizable, 0);
122 if (mwm_hints->functions & MWM_FUNC_RESIZE)
123 WSETUFLAG(wwin, no_resizable, 0);
125 if (mwm_hints->functions & MWM_FUNC_MINIMIZE)
126 WSETUFLAG(wwin, no_miniaturizable, 0);
128 if (mwm_hints->functions & MWM_FUNC_MAXIMIZE) {
129 /* a window must be resizable to be maximizable */
130 WSETUFLAG(wwin, no_resizable, 0);
132 if (mwm_hints->functions & MWM_FUNC_CLOSE)
133 WSETUFLAG(wwin, no_closable, 0);
137 static int getMWMHints(Window window, MWMHints *mwmhints)
139 unsigned long *data;
140 int count;
142 if (!_XA_MOTIF_WM_HINTS)
143 _XA_MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
145 data = (unsigned long *)PropGetCheckProperty(window, _XA_MOTIF_WM_HINTS,
146 _XA_MOTIF_WM_HINTS, 32, 0, &count);
148 if (!data)
149 return 0;
151 mwmhints->flags = 0;
152 if (count >= 4) {
153 mwmhints->flags = data[0];
154 mwmhints->functions = data[1];
155 mwmhints->decorations = data[2];
156 mwmhints->inputMode = data[3];
157 if (count > 5)
158 mwmhints->unknown = data[4];
160 XFree(data);
162 return 1;
165 void wMWMCheckClientHints(WWindow *wwin)
167 MWMHints hints;
169 if (getMWMHints(wwin->client_win, &hints))
170 setupMWMHints(wwin, &hints);
173 #endif /* MWM_HINTS */