summaryrefslogtreecommitdiff
path: root/src/libxcwm/init.c
blob: 14f259337f16aa06719869e34a048c959b2738cc (plain)
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
/* Copyright (c) 2012 David Snyder, Ben Carr, Jess VanDerwalker
 *
 * init.c
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>
#include "xcwm_internal.h"

int _damage_event = 0;

xcwm_wm_atoms *_wm_atoms = NULL;

xcb_query_extension_reply_t *
_xcwm_init_extension (xcb_connection_t *conn, char *extension_name)
{
    xcb_query_extension_cookie_t cookie = xcb_query_extension(conn, strlen(extension_name), extension_name);
	xcb_query_extension_reply_t *reply = xcb_query_extension_reply(conn, cookie, NULL);
	if (!reply->present) {
		free(reply);
        printf("%s extension not present\n", extension_name);
        exit(1);
	} else {
        printf("%s extension present\n", extension_name);
    }
    
	return reply;
}

void
_xcwm_init_damage(xcwm_context_t *contxt)
{
    
    xcb_query_extension_reply_t *reply =
        _xcwm_init_extension(contxt->conn, "DAMAGE");
    
    xcb_damage_query_version_cookie_t version_cookie = 
    xcb_damage_query_version(contxt->conn, 
                             XCB_DAMAGE_MAJOR_VERSION,
                             XCB_DAMAGE_MINOR_VERSION);
	xcb_damage_query_version_reply_t* version_reply =
        xcb_damage_query_version_reply(contxt->conn, version_cookie, NULL);
    
    _damage_event = reply->first_event + XCB_DAMAGE_NOTIFY;
    
	free(version_reply);
	free(reply);
    
    xcb_damage_damage_t damage = xcb_generate_id(contxt->conn);
    
    /* Refer to the Damage Protocol. Using
     * DamageReportLevelBoundingBox. Another level may be more
     * appropriate. */
    uint8_t level = XCB_DAMAGE_REPORT_LEVEL_BOUNDING_BOX;
    xcb_damage_create(contxt->conn,
                      damage,
                      contxt->root_window->window_id,
                      level);
    
    /* Assign this damage object to the roots window's context */
    contxt->root_window->damage = damage;
    
}

void 
_xcwm_init_composite(xcwm_context_t *contxt) {
    xcb_query_extension_reply_t *reply =
        _xcwm_init_extension(contxt->conn, "Composite");
    
    xcb_composite_query_version_cookie_t cookie =
        xcb_composite_query_version (contxt->conn,
                                     XCB_COMPOSITE_MAJOR_VERSION,
                                     XCB_COMPOSITE_MINOR_VERSION);
    
    xcb_composite_query_version_reply_t *version_reply = 
        xcb_composite_query_version_reply (contxt->conn, cookie, NULL);
    
    xcb_composite_redirect_subwindows_checked(contxt->conn,
                                              contxt->root_window->window_id,
                                              XCB_COMPOSITE_REDIRECT_MANUAL);
    
    free(version_reply);
    free(reply);
    
}

void
_xcwm_init_xfixes (xcwm_context_t *contxt)
{
    xcb_xfixes_query_version_cookie_t cookie = 
    xcb_xfixes_query_version(contxt->conn, 4, 0);
    
    xcb_xfixes_query_version_reply_t *reply = 
    xcb_xfixes_query_version_reply(contxt->conn, cookie, NULL);
    
    free(reply);
}

void
_xcwm_get_wm_atoms (xcwm_context_t *context)
{
	xcb_intern_atom_reply_t *atom_reply;
	xcb_intern_atom_cookie_t atom_cookie;

    _wm_atoms = malloc(sizeof(xcwm_wm_atoms));

    /* WM_PROTOCOLS */
	atom_cookie = xcb_intern_atom(context->conn,
								  0,
								  12,
								  "WM_PROTOCOLS");
	atom_reply = xcb_intern_atom_reply(context->conn,
									   atom_cookie,
									   NULL);
	if (!atom_reply) {
        _wm_atoms->wm_protocols_atom = 0;
    } else {
        _wm_atoms->wm_protocols_atom = atom_reply->atom;
        free(atom_reply);
    }

	/* WM_DELETE_WINDOW atom */
	atom_cookie = xcb_intern_atom(context->conn,
								  0,
								  16,
								  "WM_DELETE_WINDOW");
	atom_reply = xcb_intern_atom_reply(context->conn,
									   atom_cookie,
									   NULL);
    if (!atom_reply) {
        _wm_atoms->wm_delete_window_atom = 0;
    } else {
        _wm_atoms->wm_delete_window_atom = atom_reply->atom;
        free(atom_reply);
    }
}