-
Notifications
You must be signed in to change notification settings - Fork 3
/
mwmhints.c
152 lines (126 loc) · 3.19 KB
/
mwmhints.c
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright 2014 Olaf Seibert
*/
/*
* 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 "list.h"
#include "mwmhints.h"
#include "screen.h"
bool
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;
}
/*
* Simple test wrappers
*/
static bool
mwm_sets_decorations(MotifWmHints *hints)
{
return (hints->flags & MWM_HINTS_DECORATIONS) ? true : false;
}
/* 1 = yes 0 = no -1 = no opinion */
int
mwm_has_border(MotifWmHints *hints)
{
/* No opinion if hints don't set decoration info */
if(!mwm_sets_decorations(hints)) {
return -1;
}
/* No opinion if the user told us to ignore it */
if(LookInNameList(Scr->MWMIgnore, "DECOR_BORDER")) {
return -1;
}
/* No border if hints said so */
if((hints->decorations & MWM_DECOR_BORDER) == 0) {
return 0;
}
/* Else border */
return 1;
}
bool
mwm_sets_title(MotifWmHints *hints)
{
/* Not if we don't have decoration info */
if(!mwm_sets_decorations(hints)) {
return false;
}
/* Not if the user wants to ignore title frobbing */
if(LookInNameList(Scr->MWMIgnore, "DECOR_TITLE")) {
return false;
}
/* Else we do have info to use */
return true;
}
bool
mwm_has_title(MotifWmHints *hints)
{
if(mwm_sets_decorations(hints)
&& ((hints->decorations & MWM_DECOR_TITLE) == 0)) {
return false;
}
return true;
}