mwmhints.c revision 645f5050
1645f5050Syouri/*
2645f5050Syouri *  [ ctwm ]
3645f5050Syouri *
4645f5050Syouri *  Copyright 2014 Olaf Seibert
5645f5050Syouri *
6645f5050Syouri * Permission to use, copy, modify and distribute this software [ctwm]
7645f5050Syouri * and its documentation for any purpose is hereby granted without fee,
8645f5050Syouri * provided that the above copyright notice appear in all copies and
9645f5050Syouri * that both that copyright notice and this permission notice appear in
10645f5050Syouri * supporting documentation, and that the name of Olaf Seibert not be
11645f5050Syouri * used in advertising or publicity pertaining to distribution of the
12645f5050Syouri * software without specific, written prior permission. Olaf Seibert
13645f5050Syouri * makes no representations about the suitability of this software for
14645f5050Syouri * any purpose. It is provided "as is" without express or implied
15645f5050Syouri * warranty.
16645f5050Syouri *
17645f5050Syouri * Olaf Seibert DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18645f5050Syouri * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
19645f5050Syouri * NO EVENT SHALL Olaf Seibert BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20645f5050Syouri * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
21645f5050Syouri * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22645f5050Syouri * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
23645f5050Syouri * USE OR PERFORMANCE OF THIS SOFTWARE.
24645f5050Syouri *
25645f5050Syouri * Author:  Olaf Seibert [ rhialto@falu.nl ][ May 2014 ]
26645f5050Syouri */
27645f5050Syouri
28645f5050Syouri/*
29645f5050Syouri * Code to look at a few Motif Window Manager hints.
30645f5050Syouri *
31645f5050Syouri * Only the bits marked [v] are actually looked at.
32645f5050Syouri * For the rest, ctwm has no concept, really.
33645f5050Syouri *
34645f5050Syouri * For some information about the meaning of the flags, see
35645f5050Syouri * the manual page VendorShell(3) from the Motif library.
36645f5050Syouri */
37645f5050Syouri
38645f5050Syouri#include <stdio.h>
39645f5050Syouri
40645f5050Syouri#include "twm.h"
41645f5050Syouri#include "mwmhints.h"
42645f5050Syouri
43645f5050Syouristatic Atom MOTIF_WM_HINTS = None;
44645f5050Syouri
45645f5050Syouriint GetMWMHints(Window w, MotifWmHints *mwmHints)
46645f5050Syouri{
47645f5050Syouri    int success;
48645f5050Syouri    Atom actual_type;
49645f5050Syouri    int actual_format;
50645f5050Syouri    unsigned long nitems;
51645f5050Syouri    unsigned long bytes_after;
52645f5050Syouri    unsigned long *prop = NULL;
53645f5050Syouri
54645f5050Syouri    /* Defaults for when not found */
55645f5050Syouri    mwmHints->flags = 0;
56645f5050Syouri    mwmHints->functions = 0;
57645f5050Syouri    mwmHints->decorations = 0;
58645f5050Syouri#ifdef FULL_MWM_DATA
59645f5050Syouri    mwmHints->input_mode = 0;
60645f5050Syouri    mwmHints->status = 0;
61645f5050Syouri#endif
62645f5050Syouri
63645f5050Syouri    if (MOTIF_WM_HINTS == (Atom)None) {
64645f5050Syouri	MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", True);
65645f5050Syouri    }
66645f5050Syouri
67645f5050Syouri    success = XGetWindowProperty(
68645f5050Syouri			dpy, w, MOTIF_WM_HINTS,
69645f5050Syouri			0, 5, 		/* long_offset, long long_length, */
70645f5050Syouri			False,		/* Bool delete, */
71645f5050Syouri			AnyPropertyType,/* Atom req_type */
72645f5050Syouri			&actual_type, 	/* Atom *actual_type_return, */
73645f5050Syouri			&actual_format, /* int *actual_format_return, */
74645f5050Syouri			&nitems, 	/* unsigned long *nitems_return,  */
75645f5050Syouri			&bytes_after, 	/* unsigned long * */
76645f5050Syouri			(unsigned char **)&prop);	/* unsigned char ** */
77645f5050Syouri
78645f5050Syouri    if (success == Success &&
79645f5050Syouri	    actual_type == MOTIF_WM_HINTS &&
80645f5050Syouri	    actual_format == 32 &&
81645f5050Syouri	    nitems >= 3) {
82645f5050Syouri	mwmHints->flags = (int)prop[0];
83645f5050Syouri	mwmHints->functions = (int)prop[1];
84645f5050Syouri	mwmHints->decorations = (int)prop[2];
85645f5050Syouri#ifdef FULL_MWM_DATA
86645f5050Syouri	mwmHints->input_mode = (int)prop[3];
87645f5050Syouri	mwmHints->status = (int)prop[4];
88645f5050Syouri#endif
89645f5050Syouri
90645f5050Syouri	if (mwmHints->flags & MWM_HINTS_FUNCTIONS) {
91645f5050Syouri	    if (mwmHints->functions & MWM_FUNC_ALL) {
92645f5050Syouri		mwmHints->functions ^= ~0;
93645f5050Syouri	    }
94645f5050Syouri	}
95645f5050Syouri	if (mwmHints->flags & MWM_HINTS_DECORATIONS) {
96645f5050Syouri	    if (mwmHints->decorations & MWM_DECOR_ALL) {
97645f5050Syouri		mwmHints->decorations ^= ~0;
98645f5050Syouri	    }
99645f5050Syouri	}
100645f5050Syouri
101645f5050Syouri	success = True;
102645f5050Syouri    } else {
103645f5050Syouri	success = False;
104645f5050Syouri    }
105645f5050Syouri
106645f5050Syouri    if (prop != NULL) {
107645f5050Syouri    	XFree(prop);
108645f5050Syouri    }
109645f5050Syouri
110645f5050Syouri    return success;
111645f5050Syouri}
112645f5050Syouri
113