-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.c
161 lines (137 loc) · 4.95 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
#include "window.h"
#include <string.h>
#include <xcb/xcb_ewmh.h>
#include <xcb/xcb_icccm.h>
/** Hold EWMH protocol information. */
static xcb_ewmh_connection_t _ewmh;
int _has_ewmh = 0;
static xcb_intern_atom_cookie_t* _ewmh_cookie = NULL;
void request_ewmh(xcb_connection_t* c)
{
if(_has_ewmh)
return;
_ewmh_cookie = xcb_ewmh_init_atoms(c, &_ewmh);
}
void close_ewmh()
{
if(has_ewmh())
xcb_ewmh_connection_wipe(&_ewmh);
}
int has_ewmh()
{
if(_has_ewmh)
return 1;
else if(!_ewmh_cookie || !xcb_ewmh_init_atoms_replies(&_ewmh, _ewmh_cookie, NULL))
return 0;
_has_ewmh = 1;
return 1;
}
srv_window_t open_window(xcb_connection_t* c, xcb_screen_t* scr,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h,
const char* title)
{
srv_window_t win;
xcb_icccm_wm_hints_t hints;
xcb_size_hints_t size;
uint32_t mask;
uint32_t values[3];
if(!has_ewmh()) {
win.opened = 0;
return win;
}
win.opened = 1;
win.width = w;
win.height = h;
/* Creating the window. */
win.xcbwin = xcb_generate_id(c);
mask = XCB_CW_BACK_PIXEL
| XCB_CW_OVERRIDE_REDIRECT
| XCB_CW_EVENT_MASK;
values[0] = scr->black_pixel;
values[1] = 1;
values[2] = XCB_EVENT_MASK_EXPOSURE;
xcb_create_window(c,
XCB_COPY_FROM_PARENT,
win.xcbwin,
scr->root,
x, y, w, h, 1,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
scr->root_visual,
mask, values
);
/* Setting its name. */
xcb_change_property(c, XCB_PROP_MODE_REPLACE, win.xcbwin, XCB_ATOM_WM_NAME,
XCB_ATOM_STRING, 8, strlen(title), title);
xcb_change_property(c, XCB_PROP_MODE_REPLACE, win.xcbwin, _ewmh._NET_WM_NAME,
XCB_ATOM_STRING, 8, strlen(title), title);
xcb_change_property(c, XCB_PROP_MODE_REPLACE, win.xcbwin, _ewmh._NET_WM_VISIBLE_NAME,
XCB_ATOM_STRING, 8, strlen(title), title);
/* Setting EWMH parameters. */
values[0] = 0xFFFFFFFF;
xcb_change_property(c, XCB_PROP_MODE_REPLACE, win.xcbwin, _ewmh._NET_WM_DESKTOP,
XCB_ATOM_INTEGER, 32, 1, &values[0]);
xcb_change_property(c, XCB_PROP_MODE_REPLACE, win.xcbwin, _ewmh._NET_WM_WINDOW_TYPE,
XCB_ATOM_ATOM, 32, 1, &(_ewmh._NET_WM_WINDOW_TYPE_NOTIFICATION));
xcb_change_property(c, XCB_PROP_MODE_APPEND, win.xcbwin, _ewmh._NET_WM_WINDOW_TYPE,
XCB_ATOM_ATOM, 32, 1, &(_ewmh._NET_WM_WINDOW_TYPE_TOOLTIP));
xcb_change_property(c, XCB_PROP_MODE_APPEND, win.xcbwin, _ewmh._NET_WM_WINDOW_TYPE,
XCB_ATOM_ATOM, 32, 1, &(_ewmh._NET_WM_WINDOW_TYPE_DIALOG));
xcb_change_property(c, XCB_PROP_MODE_APPEND, win.xcbwin, _ewmh._NET_WM_WINDOW_TYPE,
XCB_ATOM_ATOM, 32, 1, &(_ewmh._NET_WM_WINDOW_TYPE_NORMAL));
xcb_change_property(c, XCB_PROP_MODE_REPLACE, win.xcbwin, _ewmh._NET_WM_STATE,
XCB_ATOM_ATOM, 32, 1, &(_ewmh._NET_WM_STATE_ABOVE));
xcb_change_property(c, XCB_PROP_MODE_APPEND, win.xcbwin, _ewmh._NET_WM_STATE,
XCB_ATOM_ATOM, 32, 1, &(_ewmh._NET_WM_STATE_STICKY));
xcb_change_property(c, XCB_PROP_MODE_APPEND, win.xcbwin, _ewmh._NET_WM_STATE,
XCB_ATOM_ATOM, 32, 1, &(_ewmh._NET_WM_STATE_SKIP_TASKBAR));
xcb_change_property(c, XCB_PROP_MODE_REPLACE, win.xcbwin, _ewmh.WM_PROTOCOLS,
XCB_ATOM_ATOM, 32, 1, &(_ewmh._NET_WM_PING));
xcb_change_property(c, XCB_PROP_MODE_APPEND, win.xcbwin, _ewmh.WM_PROTOCOLS,
XCB_ATOM_ATOM, 32, 1, &(_ewmh._NET_WM_SYNC_REQUEST));
/* Setting ICCCM hints. */
hints.flags = XCB_ICCCM_WM_HINT_INPUT | XCB_ICCCM_WM_HINT_STATE;
hints.input = 0;
hints.initial_state = XCB_ICCCM_WM_STATE_NORMAL;
xcb_icccm_set_wm_hints(c, win.xcbwin, &hints);
size.flags = XCB_ICCCM_SIZE_HINT_P_POSITION
| XCB_ICCCM_SIZE_HINT_US_POSITION
| XCB_ICCCM_SIZE_HINT_US_SIZE
| XCB_ICCCM_SIZE_HINT_P_SIZE
| XCB_ICCCM_SIZE_HINT_P_MIN_SIZE
| XCB_ICCCM_SIZE_HINT_P_MAX_SIZE
| XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY;
size.x = x;
size.y = y;
size.width = size.max_width = size.min_width = w;
size.height = size.max_height = size.min_height = h;
size.win_gravity = XCB_GRAVITY_STATIC;
xcb_icccm_set_wm_size_hints(c, win.xcbwin, XCB_ATOM_WM_NORMAL_HINTS, &size);
xcb_map_window(c, win.xcbwin);
return win;
}
int opened(srv_window_t win)
{
return win.opened;
}
void close_window(xcb_connection_t* c, srv_window_t win)
{
xcb_destroy_window(c, win.xcbwin);
}
void show_window(xcb_connection_t* c, srv_window_t win, int toshow)
{
if(toshow)
xcb_map_window(c, win.xcbwin);
else
xcb_unmap_window(c, win.xcbwin);
}
void move_window(xcb_connection_t* c, srv_window_t win, uint32_t x, uint32_t y)
{
uint32_t mask;
uint32_t values[2];
mask = XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y;
values[0] = x;
values[1] = y;
xcb_configure_window(c, win.xcbwin, mask, values);
}