2
* Xplugin rootless implementation frame functions
5
* Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
6
* Copyright (c) 2003 Torrey T. Lyons. All Rights Reserved.
8
* Permission is hereby granted, free of charge, to any person obtaining a
9
* copy of this software and associated documentation files (the "Software"),
10
* to deal in the Software without restriction, including without limitation
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
* and/or sell copies of the Software, and to permit persons to whom the
13
* Software is furnished to do so, subject to the following conditions:
15
* The above copyright notice and this permission notice shall be included in
16
* all copies or substantial portions of the Software.
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
22
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
* DEALINGS IN THE SOFTWARE.
26
* Except as contained in this notice, the name(s) of the above copyright
27
* holders shall not be used in advertising or otherwise to promote the sale,
28
* use or other dealings in this Software without prior written authorization.
30
/* $XdotOrg: xserver/xorg/hw/darwin/quartz/xpr/xprFrame.c,v 1.5 2005/07/01 22:43:08 daniels Exp $ */
31
/* $XFree86: xc/programs/Xserver/hw/darwin/quartz/xpr/xprFrame.c,v 1.4 2003/11/12 20:21:52 torrey Exp $ */
34
#include "rootlessCommon.h"
38
#include "applewmExt.h"
40
#include "propertyst.h"
42
#include <X11/Xatom.h>
43
#include "windowstr.h"
47
#define DEFINE_ATOM_HELPER(func,atom_name) \
48
static Atom func (void) { \
49
static int generation; \
51
if (generation != serverGeneration) { \
52
generation = serverGeneration; \
53
atom = MakeAtom (atom_name, strlen (atom_name), TRUE); \
58
DEFINE_ATOM_HELPER(xa_native_window_id, "_NATIVE_WINDOW_ID")
60
/* Maps xp_window_id -> RootlessWindowRec */
61
static x_hash_table *window_hash;
62
static pthread_mutex_t window_hash_mutex;
64
static Bool no_configure_window;
67
static inline xp_error
68
xprConfigureWindow(xp_window_id id, unsigned int mask,
69
const xp_window_changes *values)
71
if (!no_configure_window)
72
return xp_configure_window(id, mask, values);
79
xprSetNativeProperty(RootlessWindowPtr pFrame)
82
unsigned int native_id;
85
err = xp_get_native_window((xp_window_id) pFrame->wid, &native_id);
88
/* FIXME: move this to AppleWM extension */
91
ChangeWindowProperty(pFrame->win, xa_native_window_id(),
92
XA_INTEGER, 32, PropModeReplace, 1, &data, TRUE);
98
* Create and display a new frame.
101
xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
102
int newX, int newY, RegionPtr pShape)
104
WindowPtr pWin = pFrame->win;
105
xp_window_changes wc;
106
unsigned int mask = 0;
111
wc.width = pFrame->width;
112
wc.height = pFrame->height;
113
wc.bit_gravity = XP_GRAVITY_NONE;
116
if (pWin->drawable.depth == 8)
118
wc.depth = XP_DEPTH_INDEX8;
120
wc.colormap = xprColormapCallback;
121
wc.colormap_data = pScreen;
125
else if (pWin->drawable.depth == 15)
126
wc.depth = XP_DEPTH_RGB555;
127
else if (pWin->drawable.depth == 24)
128
wc.depth = XP_DEPTH_ARGB8888;
130
wc.depth = XP_DEPTH_NIL;
135
wc.shape_nrects = REGION_NUM_RECTS(pShape);
136
wc.shape_rects = REGION_RECTS(pShape);
137
wc.shape_tx = wc.shape_ty = 0;
141
err = xp_create_window(mask, &wc, (xp_window_id *) &pFrame->wid);
148
if (window_hash == NULL)
150
window_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
151
pthread_mutex_init(&window_hash_mutex, NULL);
154
pthread_mutex_lock(&window_hash_mutex);
155
x_hash_table_insert(window_hash, pFrame->wid, pFrame);
156
pthread_mutex_unlock(&window_hash_mutex);
158
xprSetNativeProperty(pFrame);
168
xprDestroyFrame(RootlessFrameID wid)
170
pthread_mutex_lock(&window_hash_mutex);
171
x_hash_table_remove(window_hash, wid);
172
pthread_mutex_unlock(&window_hash_mutex);
174
xp_destroy_window((xp_window_id) wid);
179
* Move a frame on screen.
182
xprMoveFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY)
184
xp_window_changes wc;
189
xprConfigureWindow((xp_window_id) wid, XP_ORIGIN, &wc);
194
* Resize and move a frame.
197
xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen,
198
int newX, int newY, unsigned int newW, unsigned int newH,
199
unsigned int gravity)
201
xp_window_changes wc;
207
wc.bit_gravity = gravity;
209
/* It's unlikely that being async will save us anything here.
210
But it can't hurt. */
212
xprConfigureWindow((xp_window_id) wid, XP_BOUNDS, &wc);
217
* Change frame stacking.
220
xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid)
222
xp_window_changes wc;
224
/* Stack frame below nextWid it if it exists, or raise
225
frame above everything otherwise. */
229
wc.stack_mode = XP_MAPPED_ABOVE;
234
wc.stack_mode = XP_MAPPED_BELOW;
235
wc.sibling = (xp_window_id) nextWid;
238
xprConfigureWindow((xp_window_id) wid, XP_STACKING, &wc);
243
* Change the frame's shape.
246
xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape)
248
xp_window_changes wc;
252
wc.shape_nrects = REGION_NUM_RECTS(pShape);
253
wc.shape_rects = REGION_RECTS(pShape);
257
wc.shape_nrects = -1;
258
wc.shape_rects = NULL;
261
wc.shape_tx = wc.shape_ty = 0;
263
xprConfigureWindow((xp_window_id) wid, XP_SHAPE, &wc);
271
xprUnmapFrame(RootlessFrameID wid)
273
xp_window_changes wc;
275
wc.stack_mode = XP_UNMAPPED;
278
xprConfigureWindow((xp_window_id) wid, XP_STACKING, &wc);
283
* Start drawing to a frame.
284
* Prepare for direct access to its backing buffer.
287
xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
290
unsigned int rowbytes[2];
293
err = xp_lock_window((xp_window_id) wid, NULL, NULL, data, rowbytes, NULL);
295
FatalError("Could not lock window %i for drawing.", (int) wid);
297
*pixelData = data[0];
298
*bytesPerRow = rowbytes[0];
303
* Stop drawing to a frame.
306
xprStopDrawing(RootlessFrameID wid, Bool flush)
308
xp_unlock_window((xp_window_id) wid, flush);
313
* Flush drawing updates to the screen.
316
xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage)
318
xp_flush_window((xp_window_id) wid);
323
* Mark damaged rectangles as requiring redisplay to screen.
326
xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects,
327
int shift_x, int shift_y)
329
xp_mark_window((xp_window_id) wid, nrects, rects, shift_x, shift_y);
334
* Called after the window associated with a frame has been switched
335
* to a new top-level parent.
338
xprSwitchWindow(RootlessWindowPtr pFrame, WindowPtr oldWin)
340
DeleteProperty(oldWin, xa_native_window_id());
342
xprSetNativeProperty(pFrame);
347
* Called to check if the frame should be reordered when it is restacked.
349
Bool xprDoReorderWindow(RootlessWindowPtr pFrame)
351
WindowPtr pWin = pFrame->win;
353
return AppleWMDoReorderWindow(pWin);
358
* Copy area in frame to another part of frame.
359
* Used to accelerate scrolling.
362
xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec *dstRects,
365
xp_copy_window((xp_window_id) wid, (xp_window_id) wid,
366
dstNrects, dstRects, dx, dy);
370
static RootlessFrameProcsRec xprRootlessProcs = {
392
* Initialize XPR implementation
395
xprInit(ScreenPtr pScreen)
397
RootlessInit(pScreen, &xprRootlessProcs);
399
rootless_CopyBytes_threshold = xp_copy_bytes_threshold;
400
rootless_FillBytes_threshold = xp_fill_bytes_threshold;
401
rootless_CompositePixels_threshold = xp_composite_area_threshold;
402
rootless_CopyWindow_threshold = xp_scroll_area_threshold;
404
no_configure_window = FALSE;
411
* Given the id of a physical window, try to find the top-level (or root)
412
* X window that it represents.
415
xprGetXWindow(xp_window_id wid)
417
RootlessWindowRec *winRec;
419
if (window_hash == NULL)
422
winRec = x_hash_table_lookup(window_hash, (void *) wid, NULL);
424
return winRec != NULL ? winRec->win : NULL;
429
* The windowNumber is an AppKit window number. Returns TRUE if xpr is
430
* displaying a window with that number.
433
xprIsX11Window(void *nsWindow, int windowNumber)
438
if (window_hash == NULL)
441
/* need to lock, since this function can be called by any thread */
443
pthread_mutex_lock(&window_hash_mutex);
445
if (xp_lookup_native_window(windowNumber, &wid))
446
ret = xprGetXWindow(wid) != NULL;
450
pthread_mutex_unlock(&window_hash_mutex);
458
* Hide or unhide all top level windows. This is called for application hide/
459
* unhide events if the window manager is not Apple-WM aware. Xplugin windows
460
* do not hide or unhide themselves.
463
xprHideWindows(Bool hide)
466
WindowPtr pRoot, pWin;
468
for (screen = 0; screen < screenInfo.numScreens; screen++) {
469
pRoot = WindowTable[screenInfo.screens[screen]->myNum];
470
RootlessFrameID prevWid = NULL;
472
for (pWin = pRoot->firstChild; pWin; pWin = pWin->nextSib) {
473
RootlessWindowRec *winRec = WINREC(pWin);
475
if (winRec != NULL) {
477
xprUnmapFrame(winRec->wid);
481
xprRestackFrame(winRec->wid, prevWid);
482
prevWid = winRec->wid;
486
box.x2 = winRec->width;
487
box.y2 = winRec->height;
489
xprDamageRects(winRec->wid, 1, &box, 0, 0);
490
RootlessQueueRedisplay(screenInfo.screens[screen]);