~ctwm/ctwm/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 *  [ ctwm ]
 *
 *  Copyright 2014 Olaf Seibert
 *
 * Permission to use, copy, modify and distribute this software [ctwm]
 * and its documentation for any purpose is hereby granted without fee,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of Olaf Seibert not be
 * used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission. Olaf Seibert
 * makes no representations about the suitability of this software for
 * any purpose. It is provided "as is" without express or implied
 * warranty.
 *
 * Olaf Seibert DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
 * NO EVENT SHALL Olaf Seibert BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
 * USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Author:  Olaf Seibert [ rhialto@falu.nl ][ May 2014 ]
 */

/*
 * Code to look at a few Motif Window Manager hints.
 *
 * Only the bits marked [v] are actually looked at.
 * For the rest, ctwm has no concept, really.
 *
 * For some information about the meaning of the flags, see
 * the manual page VendorShell(3) from the Motif library.
 */

#include "ctwm.h"

#include <stdio.h>

#include "ctwm_atoms.h"
#include "mwmhints.h"

int GetMWMHints(Window w, MotifWmHints *mwmHints)
{
	int success;
	Atom actual_type;
	int actual_format;
	unsigned long nitems;
	unsigned long bytes_after;
	unsigned long *prop = NULL;

	/* Defaults for when not found */
	mwmHints->flags = 0;
	mwmHints->functions = 0;
	mwmHints->decorations = 0;
#ifdef FULL_MWM_DATA
	mwmHints->input_mode = 0;
	mwmHints->status = 0;
#endif

	success = XGetWindowProperty(
	                  dpy, w, XA__MOTIF_WM_HINTS,
	                  0, 5,           /* long_offset, long long_length, */
	                  False,          /* Bool delete, */
	                  AnyPropertyType,/* Atom req_type */
	                  &actual_type,   /* Atom *actual_type_return, */
	                  &actual_format, /* int *actual_format_return, */
	                  &nitems,        /* unsigned long *nitems_return,  */
	                  &bytes_after,   /* unsigned long * */
	                  (unsigned char **)&prop);       /* unsigned char ** */

	if(success == Success &&
	                actual_type == XA__MOTIF_WM_HINTS &&
	                actual_format == 32 &&
	                nitems >= 3) {
		mwmHints->flags = (int)prop[0];
		mwmHints->functions = (int)prop[1];
		mwmHints->decorations = (int)prop[2];
#ifdef FULL_MWM_DATA
		mwmHints->input_mode = (int)prop[3];
		mwmHints->status = (int)prop[4];
#endif

		if(mwmHints->flags & MWM_HINTS_FUNCTIONS) {
			if(mwmHints->functions & MWM_FUNC_ALL) {
				mwmHints->functions ^= ~0;
			}
		}
		if(mwmHints->flags & MWM_HINTS_DECORATIONS) {
			if(mwmHints->decorations & MWM_DECOR_ALL) {
				mwmHints->decorations ^= ~0;
			}
		}

		success = True;
	}
	else {
		success = False;
	}

	if(prop != NULL) {
		XFree(prop);
	}

	return success;
}