-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.c
237 lines (193 loc) · 6.16 KB
/
window.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include <string.h>
#include <X11/Xmd.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include "common.h"
#include "window.h"
#define CLS_NAME "Says"
#define MWM_HINTS_DECORATIONS 1 << 1
#define WIN_STATE_STICKY 1 << 0
#define WIN_STATE_FIXED_POSITION 1 << 8
#define WIN_HINTS_SKIP_FOCUS 1 << 0
#define WIN_HINTS_SKIP_WINLIST 1 << 1
#define WIN_HINTS_SKIP_TASKBAR 1 << 2
#define WIN_LAYER_ABOVE_DOCK 10
#define WIN_LAYER_DOCK 2
#define NOT_A_DESKTOP 65535
WinInfo win;
static XTextProperty wmn = {(uchar*)APP_NAME,XA_STRING,8,sizeof(APP_NAME)-1};
static XClassHint wmch = {APP_NAME,CLS_NAME};
static char* atom_names[] = {
"_MOTIF_WM_HINTS",
"_NET_CURRENT_DESKTOP",
"_NET_WORKAREA",
"_WIN_WORKSPACE",
"_WIN_WORKAREA",
"_WIN_HINTS",
"_NET_WM_STRUT",
"_NET_WM_STRUT_PARTIAL",
"_WIN_LAYER",
"_NET_NUMBER_OF_DESKTOPS",
"_WIN_WORKSPACE_COUNT",
"_WIN_STATE",
"WM_STATE",
"_NET_WM_WINDOW_TYPE",
"_NET_WM_WINDOW_TYPE_DOCK",
"_NET_WM_STATE",
"_NET_WM_STATE_STAYS_ON_TOP"
};
#define ATOM_COUNT sizeof(atom_names)/sizeof(char*)
Atom atoms[ATOM_COUNT];
void toggle_strut()
{
static uchar at_top=1;
long strut[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; /* left, right, top, bottom */
int elem_size=(sizeof(strut[0]) / 4) / (sizeof(long) / 4);
enum {
STRUT_LEFT = 0,
STRUT_RIGHT = 1,
STRUT_TOP = 2,
STRUT_BOTTOM = 3
};
at_top= !at_top;
if (at_top) {
strut[STRUT_TOP] = win.height + 1 + win.work_area.y;
strut[10] = win.work_area.width;
} else {
strut[STRUT_BOTTOM] = win.height + 3;
strut[11] = win.work_area.width;
}
change_property(atoms[ai_NET_WM_STRUT], XA_CARDINAL, 32, &strut, 4*elem_size );
change_property(atoms[ai_NET_WM_STRUT_PARTIAL], XA_CARDINAL, 32, &strut, 12*elem_size );
XMoveResizeWindow( win.dpy, win.win, win.work_area.x,
at_top?win.work_area.y:(win.work_area.y+win.work_area.height)-win.height,
win.work_area.width, win.height);
}
static int get_net_workarea()
{
unsigned long*data=NULL;
Atom type_ret;
int format_ret;
unsigned long items_ret;
unsigned long after_ret;
unsigned long desktop;
XGetWindowProperty( win.dpy, win.root, atoms[ai_NET_CURRENT_DESKTOP], 0, 1,
False, XA_CARDINAL, &type_ret, &format_ret,
&items_ret, &after_ret, (void*)&data );
if ( data && items_ret ) {
desktop= *data;
XFree(data);
data=NULL;
XGetWindowProperty( win.dpy, win.root, atoms[ai_NET_WORKAREA],
desktop*4, 4, False, XA_CARDINAL, &type_ret,
&format_ret, &items_ret, &after_ret, (void*)&data );
if ( data ) {
if ( 4 == items_ret ) {
win.work_area.x=data[0];
win.work_area.y=data[1];
win.work_area.width=data[2];
win.work_area.height=data[3];
XFree(data);
return 1;
}
XFree(data);
}
}
return 0;
}
static int get_win_workarea()
{
unsigned long*data=NULL;
Atom type_ret;
int format_ret;
unsigned long items_ret;
unsigned long after_ret;
data=NULL;
XGetWindowProperty( win.dpy, win.root, atoms[ai_WIN_WORKAREA], 0, 4, False,
XA_CARDINAL, &type_ret, &format_ret, &items_ret,
&after_ret, (void*)&data );
if ( data ) {
if ( 4 == items_ret ) {
win.work_area.x=data[0];
win.work_area.y=data[1];
win.work_area.width=data[2];
win.work_area.height=data[3];
XFree(data);
return 1;
}
XFree(data);
}
return 0;
}
static int get_default_workarea()
{
win.work_area.x=0;
win.work_area.y=0;
win.work_area.width=win.scr.width;
win.work_area.height=win.scr.height;
return 1;
}
int get_work_area()
{
return get_net_workarea()||get_win_workarea()||get_default_workarea();
}
typedef struct {
ulong flags;
ulong functions;
ulong decorations;
long input_mode;
ulong status;
} MwmHints;
void create_window()
{
MwmHints mwm;
XSizeHints size_hints;
XWMHints wmhints;
XSetWindowAttributes att;
CARD32 win_width=win.scr.width;
int win_left=0;
unsigned int card;
Atom atom;
XInternAtoms(win.dpy, atom_names, ATOM_COUNT, 0, &atoms[0]);
att.background_pixel= win.frame_color;
att.event_mask= ButtonPressMask | ExposureMask;
win.top = win.scr.height-win.height;
win.win = XCreateWindow( win.dpy, win.root,
win_left, win.top, win_width, win.height,
0, CopyFromParent, InputOutput,
XDefaultVisual(win.dpy, win.scr.id),
CWBackPixel | CWEventMask, &att );
if ( app_name && *app_name ) {
wmn.value=(uchar*)app_name;
wmn.nitems=strlen(app_name);
wmch.res_name=app_name;
}
XSetWMName(win.dpy, win.win, &wmn);
XSetWMIconName(win.dpy, win.win, &wmn);
XSetClassHint(win.dpy, win.win, &wmch);
get_work_area();
atom=atoms[ai_NET_WM_WINDOW_TYPE_DOCK];
change_property(atoms[ai_NET_WM_WINDOW_TYPE], XA_ATOM, 32, &atom, 1);
atom=atoms[ai_NET_WM_STATE_STAYS_ON_TOP];
change_property(atoms[ai_NET_WM_STATE], XA_ATOM, 32, &atom, 1);
card=WIN_STATE_STICKY | WIN_STATE_FIXED_POSITION;
change_property(atoms[ai_WIN_STATE], XA_CARDINAL, 32, &card,1);
card= WIN_HINTS_SKIP_FOCUS | WIN_HINTS_SKIP_WINLIST | WIN_HINTS_SKIP_TASKBAR;
change_property(atoms[ai_WIN_HINTS], XA_CARDINAL, 32, &card, 1);
mwm.flags=0;
memset(&mwm, '\0', sizeof(mwm));
mwm.flags= MWM_HINTS_DECORATIONS; /* borderless motif hint */
change_property( atoms[ai_MOTIF_WM_HINTS], atoms[ai_MOTIF_WM_HINTS], 32,
&mwm, (sizeof(MwmHints) / 4) / (sizeof(long) / 4) );
size_hints.flags= PPosition; /* tell the WM to obey the window position */
change_property( XA_WM_NORMAL_HINTS, XA_WM_SIZE_HINTS, 32, &size_hints,
sizeof (XSizeHints) / 4 );
wmhints.flags= InputHint; /* Make the window unfocusable */
wmhints.input= 0;
change_property(XA_WM_HINTS, XA_WM_HINTS, 32, &wmhints, sizeof(XWMHints) / 4 );
card=WIN_LAYER_DOCK;
change_property(atoms[ai_WIN_LAYER], XA_CARDINAL, 32, &card, 1);
XMapWindow(win.dpy, win.win);
toggle_strut();
if (opts.start_at_top) { toggle_strut(); }
}