~ubuntu-branches/debian/lenny/italc/lenny

« back to all changes in this revision

Viewing changes to ica/x11/x11vnc/macosx.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-06-17 13:46:54 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080617134654-cl0gi4u524cv1ici
Tags: 1:1.0.9~rc3-1
* Package new upstream version
  - upstream ported the code to qt4.4 (Closes: #481974)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -- macosx.c -- */
 
2
 
 
3
#include "rfb/rfbconfig.h"
 
4
#if (defined(__MACH__) && defined(__APPLE__) && defined(LIBVNCSERVER_HAVE_MACOSX_NATIVE_DISPLAY))
 
5
 
 
6
#define DOMAC 1
 
7
 
 
8
#else
 
9
 
 
10
#define DOMAC 0
 
11
 
 
12
#endif
 
13
 
 
14
#include "x11vnc.h"
 
15
#include "cleanup.h"
 
16
#include "scan.h"
 
17
#include "screen.h"
 
18
#include "pointer.h"
 
19
#include "allowed_input_t.h"
 
20
#include "keyboard.h"
 
21
#include "cursor.h"
 
22
#include "connections.h"
 
23
#include "macosxCG.h"
 
24
#include "macosxCGP.h"
 
25
#include "macosxCGS.h"
 
26
 
 
27
void macosx_log(char *);
 
28
char *macosx_console_guess(char *str, int *fd);
 
29
void macosx_key_command(rfbBool down, rfbKeySym keysym, rfbClientPtr client);
 
30
void macosx_pointer_command(int mask, int x, int y, rfbClientPtr client);
 
31
char *macosx_get_fb_addr(void);
 
32
int macosx_get_cursor(void);
 
33
int macosx_get_cursor_pos(int *, int *);
 
34
void macosx_send_sel(char *, int);
 
35
void macosx_set_sel(char *, int);
 
36
int macosx_valid_window(Window, XWindowAttributes*);
 
37
 
 
38
Status macosx_xquerytree(Window w, Window *root_return, Window *parent_return,
 
39
    Window **children_return, unsigned int *nchildren_return);
 
40
int macosx_get_wm_frame_pos(int *px, int *py, int *x, int *y, int *w, int *h,
 
41
    Window *frame, Window *win);
 
42
 
 
43
void macosx_add_mapnotify(Window win, int level, int map);
 
44
void macosx_add_create(Window win, int level);
 
45
void macosx_add_destroy(Window win, int level);
 
46
void macosx_add_visnotify(Window win, int level, int obscured);
 
47
int macosx_checkevent(XEvent *ev);
 
48
 
 
49
void macosx_log(char *str) {
 
50
        rfbLog(str);
 
51
}
 
52
 
 
53
#if (! DOMAC)
 
54
 
 
55
void macosx_event_loop(void) {
 
56
        return;
 
57
}
 
58
char *macosx_console_guess(char *str, int *fd) {
 
59
        if (!str || !fd) {}
 
60
        return NULL;
 
61
}
 
62
void macosx_key_command(rfbBool down, rfbKeySym keysym, rfbClientPtr client) {
 
63
        if (!down || !keysym || !client) {}
 
64
        return;
 
65
}
 
66
void macosx_pointer_command(int mask, int x, int y, rfbClientPtr client) {
 
67
        if (!mask || !x || !y || !client) {}
 
68
        return;
 
69
}
 
70
char *macosx_get_fb_addr(void) {
 
71
        return NULL;
 
72
}
 
73
int macosx_get_cursor(void) {
 
74
        return 0;
 
75
}
 
76
int macosx_get_cursor_pos(int *x, int *y) {
 
77
        if (!x || !y) {}
 
78
        return 0;
 
79
}
 
80
void macosx_send_sel(char * str, int len) {
 
81
        if (!str || !len) {}
 
82
        return;
 
83
}
 
84
void macosx_set_sel(char * str, int len) {
 
85
        if (!str || !len) {}
 
86
        return;
 
87
}
 
88
int macosx_valid_window(Window w, XWindowAttributes* a) {
 
89
        if (!w || !a) {}
 
90
        return 0;
 
91
}
 
92
Status macosx_xquerytree(Window w, Window *root_return, Window *parent_return,
 
93
    Window **children_return, unsigned int *nchildren_return) {
 
94
        if (!w || !root_return || !parent_return || !children_return || !nchildren_return) {}
 
95
        return (Status) 0;
 
96
}
 
97
void macosx_add_mapnotify(Window win, int level, int map) {
 
98
        if (!win || !level || !map) {}
 
99
        return;
 
100
}
 
101
void macosx_add_create(Window win, int level) {
 
102
        if (!win || !level) {}
 
103
        return;
 
104
}
 
105
void macosx_add_destroy(Window win, int level) {
 
106
        if (!win || !level) {}
 
107
        return;
 
108
}
 
109
void macosx_add_visnotify(Window win, int level, int obscured) {
 
110
        if (!win || !level || !obscured) {}
 
111
        return;
 
112
}
 
113
 
 
114
int macosx_checkevent(XEvent *ev) {
 
115
        if (!ev) {}
 
116
        return 0;
 
117
}
 
118
 
 
119
 
 
120
int dragum(void) {return 1;}
 
121
 
 
122
#else 
 
123
 
 
124
void macosx_event_loop(void) {
 
125
        macosxCG_event_loop();
 
126
}
 
127
 
 
128
char *macosx_get_fb_addr(void) {
 
129
        macosxCG_init();
 
130
        return macosxCG_get_fb_addr();
 
131
}
 
132
 
 
133
char *macosx_console_guess(char *str, int *fd) {
 
134
        char *q, *in = strdup(str);
 
135
        char *atparms = NULL, *file = NULL;
 
136
 
 
137
        macosxCG_init();
 
138
 
 
139
        if (strstr(in, "console") != in) {
 
140
                rfbLog("console_guess: unrecognized console/fb format: %s\n", str);
 
141
                free(in);
 
142
                return NULL;
 
143
        }
 
144
 
 
145
        *fd = -1;
 
146
 
 
147
        q = strrchr(in, '@');
 
148
        if (q) {
 
149
                atparms = strdup(q+1);
 
150
                *q = '\0';
 
151
        }
 
152
        q = strrchr(in, ':');
 
153
        if (q) {
 
154
                file = strdup(q+1);
 
155
                *q = '\0';
 
156
        }
 
157
        if (! file || file[0] == '\0')  {
 
158
                file = strdup("/dev/null");
 
159
        }
 
160
        rfbLog("console_guess: file is %s\n", file);
 
161
 
 
162
        if (! pipeinput_str) {
 
163
                pipeinput_str = strdup("MACOSX");
 
164
                initialize_pipeinput();
 
165
        }
 
166
 
 
167
        if (! atparms) {
 
168
                int w, h, b, bps, dep;
 
169
                unsigned long rm = 0, gm = 0, bm = 0;
 
170
 
 
171
                w = macosxCG_CGDisplayPixelsWide();
 
172
                h = macosxCG_CGDisplayPixelsHigh();
 
173
                b = macosxCG_CGDisplayBitsPerPixel();
 
174
 
 
175
                bps = macosxCG_CGDisplayBitsPerSample();
 
176
                dep = macosxCG_CGDisplaySamplesPerPixel() * bps;
 
177
 
 
178
                rm = (1 << bps) - 1;
 
179
                gm = (1 << bps) - 1;
 
180
                bm = (1 << bps) - 1;
 
181
                rm = rm << 2 * bps;
 
182
                gm = gm << 1 * bps;
 
183
                bm = bm << 0 * bps;
 
184
 
 
185
                if (b == 8 && rm == 0xff && gm == 0xff && bm == 0xff) {
 
186
                        /* I don't believe it... */
 
187
                        rm = 0x07;
 
188
                        gm = 0x38;
 
189
                        bm = 0xc0;
 
190
                }
 
191
                
 
192
                /* @66666x66666x32:0xffffffff:... */
 
193
                atparms = (char *) malloc(200);
 
194
                sprintf(atparms, "%dx%dx%d:%lx/%lx/%lx",
 
195
                    w, h, b, rm, gm, bm);
 
196
        }
 
197
        if (atparms) {
 
198
                int gw, gh, gb;
 
199
                if (sscanf(atparms, "%dx%dx%d", &gw, &gh, &gb) == 3)  {
 
200
                        fb_x = gw;      
 
201
                        fb_y = gh;      
 
202
                        fb_b = gb;      
 
203
                }
 
204
        }
 
205
        if (! atparms) {
 
206
                rfbLog("console_guess: could not get @ parameters.\n");
 
207
                return NULL;
 
208
        }
 
209
 
 
210
        q = (char *) malloc(strlen("map:macosx:") + strlen(file) + 1 + strlen(atparms) + 1);
 
211
        sprintf(q, "map:macosx:%s@%s", file, atparms);
 
212
        return q;
 
213
}
 
214
 
 
215
Window macosx_click_frame = None;
 
216
 
 
217
void macosx_pointer_command(int mask, int x, int y, rfbClientPtr client) {
 
218
        allowed_input_t input;
 
219
        static int last_mask = 0;
 
220
        int rc;
 
221
 
 
222
        if (0) fprintf(stderr, "macosx_pointer_command: %d %d - %d\n", x, y, mask);
 
223
 
 
224
        if (mask >= 0) {
 
225
                got_pointer_calls++;
 
226
        }
 
227
 
 
228
        if (view_only) {
 
229
                return;
 
230
        }
 
231
 
 
232
        get_allowed_input(client, &input);
 
233
 
 
234
        if (! input.motion || ! input.button) {
 
235
                /* XXX fix me with last_x, last_y, etc. */
 
236
                return;
 
237
        }
 
238
 
 
239
        if (mask >= 0) {
 
240
                got_user_input++;
 
241
                got_pointer_input++;
 
242
                last_pointer_client = client;
 
243
                last_pointer_time = time(NULL);
 
244
        }
 
245
        if (last_mask != mask) {
 
246
                if (0) fprintf(stderr, "about to inject mask change %d -> %d: %.4f\n", last_mask, mask, dnowx());
 
247
                if (mask) {
 
248
                        int px, py, x, y, w, h;
 
249
                        macosx_click_frame = None;
 
250
                        if (!macosx_get_wm_frame_pos(&px, &py, &x, &y, &w, &h, &macosx_click_frame, NULL)) {
 
251
                                macosx_click_frame = None;
 
252
                        }
 
253
                }
 
254
        }
 
255
 
 
256
        macosxCG_pointer_inject(mask, x, y);
 
257
 
 
258
        if (cursor_x != x || cursor_y != y) {
 
259
                last_pointer_motion_time = dnow();
 
260
        }
 
261
 
 
262
        cursor_x = x;
 
263
        cursor_y = y;
 
264
 
 
265
        if (last_mask != mask) {
 
266
                last_pointer_click_time = dnow();
 
267
                if (ncache > 0) {
 
268
                        /* XXX Y */
 
269
                        int i;
 
270
if (0) fprintf(stderr, "about to get all windows:           %.4f\n", dnowx());
 
271
                        for (i=0; i < 2; i++) {
 
272
                                macosxCGS_get_all_windows();
 
273
                                fprintf(stderr, "!");
 
274
                                if (macosx_checkevent(NULL)) {
 
275
                                        break;
 
276
                                }
 
277
                        }
 
278
if (0) fprintf(stderr, "\ndone:                               %.4f\n", dnowx());
 
279
                }
 
280
        }
 
281
        last_mask = mask;
 
282
 
 
283
        /* record the x, y position for the rfb screen as well. */
 
284
        cursor_position(x, y);
 
285
 
 
286
        /* change the cursor shape if necessary */
 
287
        rc = set_cursor(x, y, get_which_cursor());
 
288
        cursor_changes += rc;
 
289
 
 
290
        last_event = last_input = last_pointer_input = time(NULL);
 
291
}
 
292
 
 
293
void init_key_table(void) {
 
294
        macosxCG_init_key_table();
 
295
}
 
296
 
 
297
void macosx_key_command(rfbBool down, rfbKeySym keysym, rfbClientPtr client) {
 
298
        allowed_input_t input;
 
299
        if (debug_keyboard) fprintf(stderr, "macosx_key_command: %d %s\n", (int) keysym, down ? "down" : "up");
 
300
 
 
301
        if (view_only) {
 
302
                return;
 
303
        }
 
304
        get_allowed_input(client, &input);
 
305
        if (! input.keystroke) {
 
306
                return;
 
307
        }
 
308
 
 
309
        init_key_table();
 
310
        macosxCG_key_inject((int) down, (unsigned int) keysym);
 
311
}
 
312
 
 
313
extern void macosxGCS_poll_pb(void);
 
314
 
 
315
int macosx_get_cursor_pos(int *x, int *y) {
 
316
        macosxCG_get_cursor_pos(x, y);
 
317
        if (nofb) {
 
318
                /* good time to poll the pasteboard */
 
319
                macosxGCS_poll_pb();
 
320
        }
 
321
        return 1;
 
322
}
 
323
 
 
324
static char *cuttext = NULL;
 
325
static int cutlen = 0;
 
326
 
 
327
void macosx_send_sel(char *str, int len) {
 
328
        if (screen && all_clients_initialized()) {
 
329
                if (cuttext) {
 
330
                        int n = cutlen;
 
331
                        if (len < n) {
 
332
                                n = len;
 
333
                        }
 
334
                        if (!memcmp(str, cuttext, (size_t) n)) {
 
335
                                /* the same text we set pasteboard to ... */
 
336
                                return;
 
337
                        }
 
338
                }
 
339
                if (debug_sel) {
 
340
                        rfbLog("macosx_send_sel: %d\n", len);
 
341
                }
 
342
                rfbSendServerCutText(screen, str, len);
 
343
        }
 
344
}
 
345
 
 
346
void macosx_set_sel(char *str, int len) {
 
347
        if (screen && all_clients_initialized()) {
 
348
                if (cutlen <= len) {
 
349
                        if (cuttext) {
 
350
                                free(cuttext);
 
351
                        }
 
352
                        cutlen = 2*(len+1);
 
353
                        cuttext = (char *) calloc(cutlen, 1);
 
354
                }
 
355
                memcpy(cuttext, str, (size_t) len);
 
356
                cuttext[len] = '\0';
 
357
                if (debug_sel) {
 
358
                        rfbLog("macosx_set_sel: %d\n", len);
 
359
                }
 
360
                macosxGCS_set_pasteboard(str, len);
 
361
        }
 
362
}
 
363
 
 
364
int macosx_get_cursor(void) {
 
365
        return macosxCG_get_cursor();
 
366
}
 
367
 
 
368
typedef struct evdat {
 
369
        int win;
 
370
        int map;
 
371
        int level;
 
372
        int vis;
 
373
        int type;
 
374
} evdat_t;
 
375
 
 
376
#define MAX_EVENTS 1024
 
377
evdat_t mac_events[MAX_EVENTS];
 
378
int mac_events_ptr = 0;
 
379
int mac_events_last = 0;
 
380
 
 
381
void macosx_add_mapnotify(Window win, int level, int map) {
 
382
        int i = mac_events_last++;
 
383
        mac_events[i].win = win;
 
384
        mac_events[i].level = level;
 
385
 
 
386
        if (map) {
 
387
                mac_events[i].type = MapNotify;
 
388
        } else {
 
389
                mac_events[i].type = UnmapNotify;
 
390
        }
 
391
        mac_events[i].map = map;
 
392
        mac_events[i].vis = -1;
 
393
 
 
394
        mac_events_last = mac_events_last % MAX_EVENTS;
 
395
 
 
396
        return;
 
397
}
 
398
 
 
399
void macosx_add_create(Window win, int level) {
 
400
        int i = mac_events_last++;
 
401
        mac_events[i].win = win;
 
402
        mac_events[i].level = level;
 
403
 
 
404
        mac_events[i].type = CreateNotify;
 
405
        mac_events[i].map = -1;
 
406
        mac_events[i].vis = -1;
 
407
 
 
408
        mac_events_last = mac_events_last % MAX_EVENTS;
 
409
 
 
410
        return;
 
411
}
 
412
 
 
413
void macosx_add_destroy(Window win, int level) {
 
414
        int i = mac_events_last++;
 
415
        mac_events[i].win = win;
 
416
        mac_events[i].level = level;
 
417
 
 
418
        mac_events[i].type = DestroyNotify;
 
419
        mac_events[i].map = -1;
 
420
        mac_events[i].vis = -1;
 
421
 
 
422
        mac_events_last = mac_events_last % MAX_EVENTS;
 
423
 
 
424
        return;
 
425
}
 
426
 
 
427
void macosx_add_visnotify(Window win, int level, int obscured) {
 
428
        int i = mac_events_last++;
 
429
        mac_events[i].win = win;
 
430
        mac_events[i].level = level;
 
431
 
 
432
        mac_events[i].type = VisibilityNotify;
 
433
        mac_events[i].map = -1;
 
434
 
 
435
        mac_events[i].vis = 1;
 
436
        if (obscured == 0) {
 
437
                mac_events[i].vis = VisibilityUnobscured;
 
438
        } else if (obscured == 1) {
 
439
                mac_events[i].vis = VisibilityPartiallyObscured;
 
440
        } else if (obscured == 2) {
 
441
                mac_events[i].vis = VisibilityFullyObscured;    /* NI */
 
442
        }
 
443
 
 
444
        mac_events_last = mac_events_last % MAX_EVENTS;
 
445
 
 
446
        return;
 
447
}
 
448
 
 
449
int macosx_checkevent(XEvent *ev) {
 
450
        int i = mac_events_ptr;
 
451
 
 
452
        if (mac_events_ptr == mac_events_last) {
 
453
                return 0;
 
454
        }
 
455
        if (ev == NULL) {
 
456
                return mac_events[i].type;
 
457
        }
 
458
 
 
459
        ev->xany.window = mac_events[i].win;
 
460
 
 
461
        if (mac_events[i].type == CreateNotify) {
 
462
                ev->type = CreateNotify;
 
463
                ev->xany.window = rootwin;
 
464
                ev->xcreatewindow.window = mac_events[i].win;
 
465
        } else if (mac_events[i].type == DestroyNotify) {
 
466
                ev->type = DestroyNotify;
 
467
                ev->xdestroywindow.window = mac_events[i].win;
 
468
        } else if (mac_events[i].type == VisibilityNotify) {
 
469
                ev->type = VisibilityNotify;
 
470
                ev->xvisibility.state = mac_events[i].vis;
 
471
        } else if (mac_events[i].type == MapNotify) {
 
472
                ev->type = MapNotify;
 
473
        } else if (mac_events[i].type == UnmapNotify) {
 
474
                ev->type = UnmapNotify;
 
475
        } else {
 
476
                fprintf(stderr, "unknown macosx_checkevent: %d\n", mac_events[i].type);
 
477
        }
 
478
        mac_events_ptr++;
 
479
        mac_events_ptr = mac_events_ptr % MAX_EVENTS;
 
480
 
 
481
        return mac_events[i].type;
 
482
}
 
483
 
 
484
typedef struct windat {
 
485
        int win;
 
486
        int x, y;
 
487
        int width, height;
 
488
        int level;
 
489
        int mapped;
 
490
        int clipped;
 
491
        int ncache_only;
 
492
} windat_t;
 
493
 
 
494
extern int macwinmax; 
 
495
extern windat_t macwins[]; 
 
496
 
 
497
int macosx_get_wm_frame_pos(int *px, int *py, int *x, int *y, int *w, int *h,
 
498
    Window *frame, Window *win) {
 
499
        static int last_idx = -1;
 
500
        int x1, x2, y1, y2;
 
501
        int idx = -1, k;
 
502
        macosxCGS_get_all_windows();
 
503
        macosxCG_get_cursor_pos(px, py);
 
504
 
 
505
        for (k = 0; k<macwinmax; k++) {
 
506
                if (! macwins[k].mapped) {
 
507
                        continue;
 
508
                }
 
509
                x1 = macwins[k].x;
 
510
                x2 = macwins[k].x + macwins[k].width;
 
511
                y1 = macwins[k].y;
 
512
                y2 = macwins[k].y + macwins[k].height;
 
513
if (debug_wireframe) fprintf(stderr, "%d/%d:    %d %d %d  - %d %d %d\n", k, macwins[k].win, x1, *px, x2, y1, *py, y2);
 
514
                if (x1 <= *px && *px < x2) {
 
515
                        if (y1 <= *py && *py < y2) {
 
516
                                idx = k;
 
517
                                break;
 
518
                        }
 
519
                }
 
520
        }
 
521
        if (idx < 0) {
 
522
                return 0;
 
523
        }
 
524
 
 
525
        *x = macwins[idx].x;
 
526
        *y = macwins[idx].y;
 
527
        *w = macwins[idx].width;
 
528
        *h = macwins[idx].height;
 
529
        *frame = (Window) macwins[idx].win;
 
530
        if (win != NULL) {
 
531
                *win = *frame;
 
532
        }
 
533
 
 
534
        last_idx = idx;
 
535
 
 
536
        return 1;
 
537
}
 
538
 
 
539
int macosx_valid_window(Window w, XWindowAttributes* a) {
 
540
        static int last_idx = -1;
 
541
        int win = (int) w;
 
542
        int i, k, idx = -1;
 
543
 
 
544
        if (last_idx >= 0 && last_idx < macwinmax) {
 
545
                if (macwins[last_idx].win == win) {
 
546
                        idx = last_idx;
 
547
                }
 
548
        }
 
549
 
 
550
        if (idx < 0) {
 
551
                idx = macosxCGS_get_qlook(w);
 
552
                if (idx >= 0 && idx < macwinmax) {
 
553
                        if (macwins[idx].win != win) {
 
554
                                idx = -1;
 
555
                        }
 
556
                } else {
 
557
                        idx = -1;
 
558
                }
 
559
        }
 
560
 
 
561
        if (idx < 0) {
 
562
                for (i = 0; i<macwinmax; i++) {
 
563
                        k = i;
 
564
                        if (i == -1)  {
 
565
                                if (last_idx >= 0 && last_idx < macwinmax) {
 
566
                                        k = last_idx;
 
567
                                } else {
 
568
                                        last_idx = -1;
 
569
                                        continue;
 
570
                                }
 
571
                        }
 
572
                        if (macwins[k].win == win) {
 
573
                                idx = k;
 
574
                                break;
 
575
                        }
 
576
                }
 
577
        }
 
578
        if (idx < 0) {
 
579
                return 0;
 
580
        }
 
581
 
 
582
        a->x = macwins[idx].x;
 
583
        a->y = macwins[idx].y;
 
584
        a->width  = macwins[idx].width;
 
585
        a->height = macwins[idx].height;
 
586
        a->depth = depth;
 
587
        a->border_width = 0;
 
588
        a->backing_store = 0;
 
589
        if (macwins[idx].mapped) {
 
590
                a->map_state = IsViewable;
 
591
        } else {
 
592
                a->map_state = IsUnmapped;
 
593
        }
 
594
 
 
595
        last_idx = idx;
 
596
        
 
597
        return 1;
 
598
}
 
599
 
 
600
#define QTMAX 2048
 
601
static Window cret[QTMAX];
 
602
 
 
603
extern int CGS_levelmax;
 
604
extern int CGS_levels[];
 
605
 
 
606
Status macosx_xquerytree(Window w, Window *root_return, Window *parent_return,
 
607
    Window **children_return, unsigned int *nchildren_return) {
 
608
 
 
609
        int i, n, k;
 
610
 
 
611
        *root_return = (Window) 0;
 
612
        *parent_return = (Window) 0;
 
613
        if (!w) {}
 
614
 
 
615
        macosxCGS_get_all_windows();
 
616
 
 
617
        n = 0;
 
618
        for (k = CGS_levelmax - 1; k >= 0; k--) {
 
619
                for (i = macwinmax - 1; i >= 0; i--) {
 
620
                        if (n >= QTMAX) break;
 
621
                        if (macwins[i].level == CGS_levels[k]) {
 
622
if (0) fprintf(stderr, "k=%d i=%d n=%d\n", k, i, n);
 
623
                                cret[n++] = (Window) macwins[i].win;
 
624
                        }
 
625
                }
 
626
        }
 
627
        *children_return = cret;
 
628
        *nchildren_return = (unsigned int) macwinmax;
 
629
 
 
630
        return (Status) 1;
 
631
}
 
632
 
 
633
int macosx_check_offscreen(int win) {
 
634
        sraRegionPtr r0, r1;
 
635
        int x1, y1, x2, y2;
 
636
        int ret;
 
637
        int i = macosxCGS_find_index(win);
 
638
 
 
639
        if (i < 0) {
 
640
                return 0;
 
641
        }
 
642
 
 
643
        x1 = macwins[i].x;
 
644
        y1 = macwins[i].y;
 
645
        x2 = macwins[i].x + macwins[i].width;
 
646
        y2 = macwins[i].y + macwins[i].height;
 
647
 
 
648
        r0 = sraRgnCreateRect(0, 0, dpy_x, dpy_y);
 
649
        r1 = sraRgnCreateRect(x1, y1, x2, y2);
 
650
 
 
651
        if (sraRgnAnd(r1, r0)) {
 
652
                ret = 0;
 
653
        } else {
 
654
                ret = 1;
 
655
        }
 
656
        sraRgnDestroy(r0);
 
657
        sraRgnDestroy(r1);
 
658
 
 
659
        return ret;
 
660
}
 
661
 
 
662
int macosx_check_clipped(int win, int *list, int n) {
 
663
        sraRegionPtr r0, r1, r2;
 
664
        int x1, y1, x2, y2;
 
665
        int ret = 0;
 
666
        int k, j, i = macosxCGS_find_index(win);
 
667
 
 
668
        if (i < 0) {
 
669
                return 0;
 
670
        }
 
671
 
 
672
        x1 = macwins[i].x;
 
673
        y1 = macwins[i].y;
 
674
        x2 = macwins[i].x + macwins[i].width;
 
675
        y2 = macwins[i].y + macwins[i].height;
 
676
 
 
677
        r0 = sraRgnCreateRect(0, 0, dpy_x, dpy_y);
 
678
        r1 = sraRgnCreateRect(x1, y1, x2, y2);
 
679
        sraRgnAnd(r1, r0);
 
680
 
 
681
        for (k = 0; k < n; k++) {
 
682
                j = macosxCGS_find_index(list[k]);      /* XXX slow? */
 
683
                if (j < 0) {
 
684
                        continue;
 
685
                }
 
686
                x1 = macwins[j].x;
 
687
                y1 = macwins[j].y;
 
688
                x2 = macwins[j].x + macwins[j].width;
 
689
                y2 = macwins[j].y + macwins[j].height;
 
690
                r2 = sraRgnCreateRect(x1, y1, x2, y2);
 
691
                if (sraRgnAnd(r2, r1)) {
 
692
                        ret = 1;
 
693
                        sraRgnDestroy(r2);
 
694
                        break;
 
695
                }
 
696
                sraRgnDestroy(r2);
 
697
        }
 
698
        sraRgnDestroy(r0);
 
699
        sraRgnDestroy(r1);
 
700
 
 
701
        return ret;
 
702
}
 
703
 
 
704
 
 
705
#endif  /* LIBVNCSERVER_HAVE_MACOSX_NATIVE_DISPLAY */
 
706