compoverlay.c revision 6747b715
1/*
2 * Copyright © 2006 Sun Microsystems, Inc.  All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Copyright © 2003 Keith Packard
24 *
25 * Permission to use, copy, modify, distribute, and sell this software and its
26 * documentation for any purpose is hereby granted without fee, provided that
27 * the above copyright notice appear in all copies and that both that
28 * copyright notice and this permission notice appear in supporting
29 * documentation, and that the name of Keith Packard not be used in
30 * advertising or publicity pertaining to distribution of the software without
31 * specific, written prior permission.  Keith Packard makes no
32 * representations about the suitability of this software for any purpose.  It
33 * is provided "as is" without express or implied warranty.
34 *
35 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
36 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
37 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
38 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
39 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
40 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
41 * PERFORMANCE OF THIS SOFTWARE.
42 */
43
44#ifdef HAVE_DIX_CONFIG_H
45#include <dix-config.h>
46#endif
47
48#include "compint.h"
49#include "xace.h"
50
51/*
52 * Delete the given overlay client list element from its screen list.
53 */
54void
55compFreeOverlayClient (CompOverlayClientPtr pOcToDel)
56{
57    ScreenPtr		    pScreen = pOcToDel->pScreen;
58    CompScreenPtr	    cs = GetCompScreen (pScreen);
59    CompOverlayClientPtr    *pPrev, pOc;
60
61    for (pPrev = &cs->pOverlayClients; (pOc = *pPrev); pPrev = &pOc->pNext)
62    {
63	if (pOc == pOcToDel) {
64	    *pPrev = pOc->pNext;
65	    free(pOc);
66	    break;
67	}
68    }
69
70    /* Destroy overlay window when there are no more clients using it */
71    if (cs->pOverlayClients == NULL)
72	compDestroyOverlayWindow (pScreen);
73}
74
75/*
76 * Return the client's first overlay client rec from the given screen
77 */
78CompOverlayClientPtr
79compFindOverlayClient (ScreenPtr pScreen, ClientPtr pClient)
80{
81    CompScreenPtr	    cs = GetCompScreen(pScreen);
82    CompOverlayClientPtr    pOc;
83
84    for (pOc = cs->pOverlayClients; pOc != NULL; pOc = pOc->pNext)
85	if (pOc->pClient == pClient)
86	    return pOc;
87
88    return NULL;
89}
90
91/*
92 * Create an overlay client object for the given client
93 */
94CompOverlayClientPtr
95compCreateOverlayClient (ScreenPtr pScreen, ClientPtr pClient)
96{
97    CompScreenPtr    cs = GetCompScreen(pScreen);
98    CompOverlayClientPtr pOc;
99
100    pOc = (CompOverlayClientPtr) malloc(sizeof(CompOverlayClientRec));
101    if (pOc == NULL)
102	return NULL;
103
104    pOc->pClient = pClient;
105    pOc->pScreen = pScreen;
106    pOc->resource = FakeClientID(pClient->index);
107    pOc->pNext = cs->pOverlayClients;
108    cs->pOverlayClients = pOc;
109
110    /*
111     * Create a resource for this element so it can be deleted
112     * when the client goes away.
113     */
114    if (!AddResource (pOc->resource, CompositeClientOverlayType, (pointer) pOc))
115	return NULL;
116
117    return pOc;
118}
119
120/*
121 * Create the overlay window and map it
122 */
123Bool
124compCreateOverlayWindow (ScreenPtr pScreen)
125{
126    CompScreenPtr   cs = GetCompScreen(pScreen);
127    WindowPtr	    pRoot = pScreen->root;
128    WindowPtr	    pWin;
129    XID		    attrs[] = { None, TRUE }; /* backPixmap, overrideRedirect */
130    int		    result;
131
132    pWin = cs->pOverlayWin =
133	CreateWindow (cs->overlayWid, pRoot,
134		      0, 0, pScreen->width, pScreen->height, 0,
135		      InputOutput, CWBackPixmap | CWOverrideRedirect, &attrs[0],
136		      pRoot->drawable.depth,
137		      serverClient, pScreen->rootVisual, &result);
138    if (pWin == NULL)
139	return FALSE;
140
141    if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin))
142	return FALSE;
143
144    MapWindow(pWin, serverClient);
145
146    return TRUE;
147}
148
149/*
150 * Destroy the overlay window
151 */
152void
153compDestroyOverlayWindow (ScreenPtr pScreen)
154{
155    CompScreenPtr cs = GetCompScreen(pScreen);
156
157    cs->pOverlayWin = NullWindow;
158    FreeResource (cs->overlayWid, RT_NONE);
159}
160
161