mwmhints.c revision 645f5050
1/* 2 * [ ctwm ] 3 * 4 * Copyright 2014 Olaf Seibert 5 * 6 * Permission to use, copy, modify and distribute this software [ctwm] 7 * and its documentation for any purpose is hereby granted without fee, 8 * provided that the above copyright notice appear in all copies and 9 * that both that copyright notice and this permission notice appear in 10 * supporting documentation, and that the name of Olaf Seibert not be 11 * used in advertising or publicity pertaining to distribution of the 12 * software without specific, written prior permission. Olaf Seibert 13 * makes no representations about the suitability of this software for 14 * any purpose. It is provided "as is" without express or implied 15 * warranty. 16 * 17 * Olaf Seibert DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN 19 * NO EVENT SHALL Olaf Seibert BE LIABLE FOR ANY SPECIAL, INDIRECT OR 20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 21 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 22 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE 23 * USE OR PERFORMANCE OF THIS SOFTWARE. 24 * 25 * Author: Olaf Seibert [ rhialto@falu.nl ][ May 2014 ] 26 */ 27 28/* 29 * Code to look at a few Motif Window Manager hints. 30 * 31 * Only the bits marked [v] are actually looked at. 32 * For the rest, ctwm has no concept, really. 33 * 34 * For some information about the meaning of the flags, see 35 * the manual page VendorShell(3) from the Motif library. 36 */ 37 38#include <stdio.h> 39 40#include "twm.h" 41#include "mwmhints.h" 42 43static Atom MOTIF_WM_HINTS = None; 44 45int GetMWMHints(Window w, MotifWmHints *mwmHints) 46{ 47 int success; 48 Atom actual_type; 49 int actual_format; 50 unsigned long nitems; 51 unsigned long bytes_after; 52 unsigned long *prop = NULL; 53 54 /* Defaults for when not found */ 55 mwmHints->flags = 0; 56 mwmHints->functions = 0; 57 mwmHints->decorations = 0; 58#ifdef FULL_MWM_DATA 59 mwmHints->input_mode = 0; 60 mwmHints->status = 0; 61#endif 62 63 if (MOTIF_WM_HINTS == (Atom)None) { 64 MOTIF_WM_HINTS = XInternAtom(dpy, "_MOTIF_WM_HINTS", True); 65 } 66 67 success = XGetWindowProperty( 68 dpy, w, MOTIF_WM_HINTS, 69 0, 5, /* long_offset, long long_length, */ 70 False, /* Bool delete, */ 71 AnyPropertyType,/* Atom req_type */ 72 &actual_type, /* Atom *actual_type_return, */ 73 &actual_format, /* int *actual_format_return, */ 74 &nitems, /* unsigned long *nitems_return, */ 75 &bytes_after, /* unsigned long * */ 76 (unsigned char **)&prop); /* unsigned char ** */ 77 78 if (success == Success && 79 actual_type == MOTIF_WM_HINTS && 80 actual_format == 32 && 81 nitems >= 3) { 82 mwmHints->flags = (int)prop[0]; 83 mwmHints->functions = (int)prop[1]; 84 mwmHints->decorations = (int)prop[2]; 85#ifdef FULL_MWM_DATA 86 mwmHints->input_mode = (int)prop[3]; 87 mwmHints->status = (int)prop[4]; 88#endif 89 90 if (mwmHints->flags & MWM_HINTS_FUNCTIONS) { 91 if (mwmHints->functions & MWM_FUNC_ALL) { 92 mwmHints->functions ^= ~0; 93 } 94 } 95 if (mwmHints->flags & MWM_HINTS_DECORATIONS) { 96 if (mwmHints->decorations & MWM_DECOR_ALL) { 97 mwmHints->decorations ^= ~0; 98 } 99 } 100 101 success = True; 102 } else { 103 success = False; 104 } 105 106 if (prop != NULL) { 107 XFree(prop); 108 } 109 110 return success; 111} 112 113