chiark / gitweb /
Imported Debian patch 1.0.0-5
[e16] / src / mwm.c
1 /*
2  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies of the Software, its documentation and marketing & publicity
13  * materials, and acknowledgment shall be given in the documentation, materials
14  * and software packages that this Software was used.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #include "E.h"
24 #include "ewins.h"
25 #include "hints.h"
26
27 /* Motif window hints */
28 #define MWM_HINTS_FUNCTIONS           (1L << 0)
29 #define MWM_HINTS_DECORATIONS         (1L << 1)
30 #define MWM_HINTS_INPUT_MODE          (1L << 2)
31 #define MWM_HINTS_STATUS              (1L << 3)
32
33 /* bit definitions for MwmHints.functions */
34 #define MWM_FUNC_ALL            (1L << 0)
35 #define MWM_FUNC_RESIZE         (1L << 1)
36 #define MWM_FUNC_MOVE           (1L << 2)
37 #define MWM_FUNC_MINIMIZE       (1L << 3)
38 #define MWM_FUNC_MAXIMIZE       (1L << 4)
39 #define MWM_FUNC_CLOSE          (1L << 5)
40
41 /* bit definitions for MwmHints.decorations */
42 #define MWM_DECOR_ALL                 (1L << 0)
43 #define MWM_DECOR_BORDER              (1L << 1)
44 #define MWM_DECOR_RESIZEH             (1L << 2)
45 #define MWM_DECOR_TITLE               (1L << 3)
46 #define MWM_DECOR_MENU                (1L << 4)
47 #define MWM_DECOR_MINIMIZE            (1L << 5)
48 #define MWM_DECOR_MAXIMIZE            (1L << 6)
49
50 /* bit definitions for MwmHints.inputMode */
51 #define MWM_INPUT_MODELESS                  0
52 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
53 #define MWM_INPUT_SYSTEM_MODAL              2
54 #define MWM_INPUT_FULL_APPLICATION_MODAL    3
55
56 #define PROP_MWM_HINTS_ELEMENTS             5
57 #define PROP_MWM_HINTS_ELEMENTS_MIN         4
58
59 static Atom         _MOTIF_WM_HINTS = 0;
60
61 /* Motif window hints */
62 typedef struct {
63    long                flags;
64    long                functions;
65    long                decorations;
66    long                inputMode;
67    long                status;
68 } MWMHints;
69
70 void
71 MWM_GetHints(EWin * ewin, Atom atom_change)
72 {
73    int                 fmt;
74    Atom                a2;
75    unsigned long       num, end;
76    MWMHints           *mwmhints;
77    unsigned char      *puc;
78
79    if (EwinIsInternal(ewin))
80       return;
81
82    if (!_MOTIF_WM_HINTS)
83       _MOTIF_WM_HINTS = EInternAtom("_MOTIF_WM_HINTS");
84
85    if (atom_change && atom_change != _MOTIF_WM_HINTS)
86       return;
87
88    ewin->mwm.valid = 1;
89    ewin->mwm.decor_border = 1;
90    ewin->mwm.decor_resizeh = 1;
91    ewin->mwm.decor_title = 1;
92    ewin->mwm.decor_menu = 1;
93    ewin->mwm.decor_minimize = 1;
94    ewin->mwm.decor_maximize = 1;
95    ewin->mwm.func_resize = 1;
96    ewin->mwm.func_move = 1;
97    ewin->mwm.func_minimize = 1;
98    ewin->mwm.func_maximize = 1;
99    ewin->mwm.func_close = 1;
100
101    puc = NULL;
102    XGetWindowProperty(disp, EwinGetClientXwin(ewin), _MOTIF_WM_HINTS, 0, 20,
103                       False, _MOTIF_WM_HINTS, &a2, &fmt, &num, &end, &puc);
104    mwmhints = (MWMHints *) puc;
105    if (!mwmhints)
106       return;
107
108    if (num < PROP_MWM_HINTS_ELEMENTS_MIN)
109       goto done;
110
111    if (mwmhints->flags & MWM_HINTS_DECORATIONS)
112      {
113         ewin->mwm.decor_border = 0;
114         ewin->mwm.decor_resizeh = 0;
115         ewin->mwm.decor_title = 0;
116         ewin->mwm.decor_menu = 0;
117         ewin->mwm.decor_minimize = 0;
118         ewin->mwm.decor_maximize = 0;
119         if (mwmhints->decorations & MWM_DECOR_ALL)
120           {
121              ewin->mwm.decor_border = 1;
122              ewin->mwm.decor_resizeh = 1;
123              ewin->mwm.decor_title = 1;
124              ewin->mwm.decor_menu = 1;
125              ewin->mwm.decor_minimize = 1;
126              ewin->mwm.decor_maximize = 1;
127           }
128         if (mwmhints->decorations & MWM_DECOR_BORDER)
129            ewin->mwm.decor_border = 1;
130         if (mwmhints->decorations & MWM_DECOR_RESIZEH)
131            ewin->mwm.decor_resizeh = 1;
132         if (mwmhints->decorations & MWM_DECOR_TITLE)
133            ewin->mwm.decor_title = 1;
134         if (mwmhints->decorations & MWM_DECOR_MENU)
135            ewin->mwm.decor_menu = 1;
136         if (mwmhints->decorations & MWM_DECOR_MINIMIZE)
137            ewin->mwm.decor_minimize = 1;
138         if (mwmhints->decorations & MWM_DECOR_MAXIMIZE)
139            ewin->mwm.decor_maximize = 1;
140      }
141
142    if (mwmhints->flags & MWM_HINTS_FUNCTIONS)
143      {
144         ewin->mwm.func_resize = 0;
145         ewin->mwm.func_move = 0;
146         ewin->mwm.func_minimize = 0;
147         ewin->mwm.func_maximize = 0;
148         ewin->mwm.func_close = 0;
149         if (mwmhints->functions & MWM_FUNC_ALL)
150           {
151              ewin->mwm.func_resize = 1;
152              ewin->mwm.func_move = 1;
153              ewin->mwm.func_minimize = 1;
154              ewin->mwm.func_maximize = 1;
155              ewin->mwm.func_close = 1;
156           }
157         if (mwmhints->functions & MWM_FUNC_RESIZE)
158            ewin->mwm.func_resize = 1;
159         if (mwmhints->functions & MWM_FUNC_MOVE)
160            ewin->mwm.func_move = 1;
161         if (mwmhints->functions & MWM_FUNC_MINIMIZE)
162            ewin->mwm.func_minimize = 1;
163         if (mwmhints->functions & MWM_FUNC_MAXIMIZE)
164            ewin->mwm.func_maximize = 1;
165         if (mwmhints->functions & MWM_FUNC_CLOSE)
166            ewin->mwm.func_close = 1;
167      }
168
169    if (!ewin->mwm.decor_title && !ewin->mwm.decor_border)
170       ewin->props.no_border = 1;
171
172  done:
173    if (mwmhints)
174       XFree(mwmhints);
175 }
176
177 void
178 MWM_SetInfo(void)
179 {
180    Atom                a1;
181    struct {
182       long                flags;
183       Window              win;
184    } mwminfo;
185
186    a1 = EInternAtom("_MOTIF_WM_INFO");
187    mwminfo.flags = 2;
188    mwminfo.win = WinGetXwin(VROOT);
189    XChangeProperty(disp, WinGetXwin(VROOT), a1, a1, 32, PropModeReplace,
190                    (unsigned char *)&mwminfo, 2);
191 }