1/*
2 * Copyright (c) 2006, Oracle and/or its affiliates. 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#ifdef PANORAMIX
52#include "panoramiXsrv.h"
53#endif
54
55/*
56 * Delete the given overlay client list element from its screen list.
57 */
58void
59compFreeOverlayClient (CompOverlayClientPtr pOcToDel)
60{
61    ScreenPtr		    pScreen = pOcToDel->pScreen;
62    CompScreenPtr	    cs = GetCompScreen (pScreen);
63    CompOverlayClientPtr    *pPrev, pOc;
64
65    for (pPrev = &cs->pOverlayClients; (pOc = *pPrev); pPrev = &pOc->pNext)
66    {
67	if (pOc == pOcToDel) {
68	    *pPrev = pOc->pNext;
69	    free(pOc);
70	    break;
71	}
72    }
73
74    /* Destroy overlay window when there are no more clients using it */
75    if (cs->pOverlayClients == NULL)
76	compDestroyOverlayWindow (pScreen);
77}
78
79/*
80 * Return the client's first overlay client rec from the given screen
81 */
82CompOverlayClientPtr
83compFindOverlayClient (ScreenPtr pScreen, ClientPtr pClient)
84{
85    CompScreenPtr	    cs = GetCompScreen(pScreen);
86    CompOverlayClientPtr    pOc;
87
88    for (pOc = cs->pOverlayClients; pOc != NULL; pOc = pOc->pNext)
89	if (pOc->pClient == pClient)
90	    return pOc;
91
92    return NULL;
93}
94
95/*
96 * Create an overlay client object for the given client
97 */
98CompOverlayClientPtr
99compCreateOverlayClient (ScreenPtr pScreen, ClientPtr pClient)
100{
101    CompScreenPtr    cs = GetCompScreen(pScreen);
102    CompOverlayClientPtr pOc;
103
104    pOc = (CompOverlayClientPtr) malloc(sizeof(CompOverlayClientRec));
105    if (pOc == NULL)
106	return NULL;
107
108    pOc->pClient = pClient;
109    pOc->pScreen = pScreen;
110    pOc->resource = FakeClientID(pClient->index);
111    pOc->pNext = cs->pOverlayClients;
112    cs->pOverlayClients = pOc;
113
114    /*
115     * Create a resource for this element so it can be deleted
116     * when the client goes away.
117     */
118    if (!AddResource (pOc->resource, CompositeClientOverlayType, (pointer) pOc))
119	return NULL;
120
121    return pOc;
122}
123
124/*
125 * Create the overlay window and map it
126 */
127Bool
128compCreateOverlayWindow (ScreenPtr pScreen)
129{
130    CompScreenPtr   cs = GetCompScreen(pScreen);
131    WindowPtr	    pRoot = pScreen->root;
132    WindowPtr	    pWin;
133    XID		    attrs[] = { None, TRUE }; /* backPixmap, overrideRedirect */
134    int		    result;
135    int		    w = pScreen->width;
136    int		    h = pScreen->height;
137
138#ifdef PANORAMIX
139    if (!noPanoramiXExtension)
140    {
141	w = PanoramiXPixWidth;
142	h = PanoramiXPixHeight;
143    }
144#endif
145
146    pWin = cs->pOverlayWin =
147	CreateWindow (cs->overlayWid, pRoot, 0, 0, w, h, 0,
148		      InputOutput, CWBackPixmap | CWOverrideRedirect, &attrs[0],
149		      pRoot->drawable.depth,
150		      serverClient, pScreen->rootVisual, &result);
151    if (pWin == NULL)
152	return FALSE;
153
154    if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin))
155	return FALSE;
156
157    MapWindow(pWin, serverClient);
158
159    return TRUE;
160}
161
162/*
163 * Destroy the overlay window
164 */
165void
166compDestroyOverlayWindow (ScreenPtr pScreen)
167{
168    CompScreenPtr cs = GetCompScreen(pScreen);
169
170    cs->pOverlayWin = NullWindow;
171    FreeResource (cs->overlayWid, RT_NONE);
172}
173
174