WPrefs: Code formatting in TexturePanel.c; minimizes checkpatch.pl warnings.
[wmaker-crm.git] / src / motif.c
blob34f6847d44a91094b7ece7f50c7de737ed5c00b7
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "wconfig.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
30 #include "WindowMaker.h"
31 #include "framewin.h"
32 #include "window.h"
33 #include "properties.h"
34 #include "icon.h"
35 #include "client.h"
36 #include "motif.h"
38 /* Motif window hints */
39 #define MWM_HINTS_FUNCTIONS (1L << 0)
40 #define MWM_HINTS_DECORATIONS (1L << 1)
42 /* bit definitions for MwmHints.functions */
43 #define MWM_FUNC_ALL (1L << 0)
44 #define MWM_FUNC_RESIZE (1L << 1)
45 #define MWM_FUNC_MOVE (1L << 2)
46 #define MWM_FUNC_MINIMIZE (1L << 3)
47 #define MWM_FUNC_MAXIMIZE (1L << 4)
48 #define MWM_FUNC_CLOSE (1L << 5)
50 /* bit definitions for MwmHints.decorations */
51 #define MWM_DECOR_ALL (1L << 0)
52 #define MWM_DECOR_BORDER (1L << 1)
53 #define MWM_DECOR_RESIZEH (1L << 2)
54 #define MWM_DECOR_TITLE (1L << 3)
55 #define MWM_DECOR_MENU (1L << 4)
56 #define MWM_DECOR_MINIMIZE (1L << 5)
57 #define MWM_DECOR_MAXIMIZE (1L << 6)
59 /* Motif window hints */
60 typedef struct {
61 long flags;
62 long functions;
63 long decorations;
64 long inputMode;
65 long unknown;
66 } MWMHints;
68 static Atom _XA_MOTIF_WM_HINTS;
70 static void setupMWMHints(WWindow *wwin, MWMHints *mwm_hints)
73 * We will ignore all decoration hints that have an equivalent as
74 * functions, because wmaker does not distinguish decoration hints
77 if (mwm_hints->flags & MWM_HINTS_DECORATIONS) {
78 wwin->client_flags.no_titlebar = 1;
79 wwin->client_flags.no_close_button = 1;
80 wwin->client_flags.no_miniaturize_button = 1;
81 wwin->client_flags.no_resizebar = 1;
82 wwin->client_flags.no_border = 1;
84 if (mwm_hints->decorations & MWM_DECOR_ALL) {
85 wwin->client_flags.no_titlebar = 0;
86 wwin->client_flags.no_close_button = 0;
87 wwin->client_flags.no_closable = 0;
88 wwin->client_flags.no_miniaturize_button = 0;
89 wwin->client_flags.no_miniaturizable = 0;
90 wwin->client_flags.no_resizebar = 0;
91 wwin->client_flags.no_resizable = 0;
92 wwin->client_flags.no_border = 0;
95 if (mwm_hints->decorations & MWM_DECOR_BORDER) {
96 wwin->client_flags.no_border = 0;
99 if (mwm_hints->decorations & MWM_DECOR_RESIZEH)
100 wwin->client_flags.no_resizebar = 0;
102 if (mwm_hints->decorations & MWM_DECOR_TITLE) {
103 wwin->client_flags.no_titlebar = 0;
104 wwin->client_flags.no_close_button = 0;
105 wwin->client_flags.no_closable = 0;
108 if (mwm_hints->decorations * MWM_DECOR_MENU) {
110 * WindowMaker does not include a button to display the menu
111 * for windows, this is done using right mouse button on the
112 * title bar. As a consequence, we ignore this flag because we
113 * have nothing to hide.
117 if (mwm_hints->decorations & MWM_DECOR_MINIMIZE) {
118 wwin->client_flags.no_miniaturize_button = 0;
119 wwin->client_flags.no_miniaturizable = 0;
122 if (mwm_hints->decorations & MWM_DECOR_MAXIMIZE) {
124 * WindowMaker does not display a button to maximize windows,
125 * so we don't need to hide anything more for that flag
130 if (mwm_hints->flags & MWM_HINTS_FUNCTIONS) {
131 wwin->client_flags.no_closable = 1;
132 wwin->client_flags.no_miniaturizable = 1;
133 wwin->client_flags.no_resizable = 1;
135 if (mwm_hints->functions & MWM_FUNC_ALL) {
136 wwin->client_flags.no_closable = 0;
137 wwin->client_flags.no_miniaturizable = 0;
138 wwin->client_flags.no_resizable = 0;
140 if (mwm_hints->functions & MWM_FUNC_RESIZE)
141 wwin->client_flags.no_resizable = 0;
143 if (mwm_hints->functions & MWM_FUNC_MOVE) {
145 * WindowMaker does not allow a window to not be moved, and this
146 * is a good thing, so we explicitly ignore this flag.
150 if (mwm_hints->functions & MWM_FUNC_MINIMIZE)
151 wwin->client_flags.no_miniaturizable = 0;
153 if (mwm_hints->functions & MWM_FUNC_MAXIMIZE) {
154 /* a window must be resizable to be maximizable */
155 wwin->client_flags.no_resizable = 0;
157 if (mwm_hints->functions & MWM_FUNC_CLOSE)
158 wwin->client_flags.no_closable = 0;
162 static int getMWMHints(Window window, MWMHints *mwmhints)
164 unsigned long *data;
165 int count;
167 if (!_XA_MOTIF_WM_HINTS)
168 _XA_MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
170 data = (unsigned long *)PropGetCheckProperty(window, _XA_MOTIF_WM_HINTS,
171 _XA_MOTIF_WM_HINTS, 32, 0, &count);
173 if (!data)
174 return 0;
176 mwmhints->flags = 0;
177 if (count >= 4) {
178 mwmhints->flags = data[0];
179 mwmhints->functions = data[1];
180 mwmhints->decorations = data[2];
181 mwmhints->inputMode = data[3];
182 if (count > 5)
183 mwmhints->unknown = data[4];
185 XFree(data);
187 return 1;
190 void wMWMCheckClientHints(WWindow *wwin)
192 MWMHints hints;
194 if (getMWMHints(wwin->client_win, &hints))
195 setupMWMHints(wwin, &hints);