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

« back to all changes in this revision

Viewing changes to ica/x11/x11vnc/macosxCGS.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
/* -- macosxCGS.c -- */
 
2
 
 
3
/*
 
4
 * We need to keep this separate from nearly everything else, e.g. rfb.h
 
5
 * and the other stuff, otherwise it does not work properly, mouse drags
 
6
 * will not work!!
 
7
 */
 
8
void macosxCGS_unused(void) {}
 
9
 
 
10
#if (defined(__MACH__) && defined(__APPLE__))
 
11
 
 
12
#include <ApplicationServices/ApplicationServices.h>
 
13
#include <Cocoa/Cocoa.h>
 
14
#include <Carbon/Carbon.h>
 
15
 
 
16
extern CGDirectDisplayID displayID;
 
17
 
 
18
void macosxCGS_get_all_windows(void);
 
19
int macosxCGS_get_qlook(int);
 
20
void macosxGCS_set_pasteboard(char *str, int len);
 
21
 
 
22
typedef CGError       CGSError;
 
23
typedef long          CGSWindowCount;
 
24
typedef void *        CGSConnectionID;
 
25
typedef int           CGSWindowID;
 
26
typedef CGSWindowID*  CGSWindowIDList;
 
27
typedef CGWindowLevel CGSWindowLevel;
 
28
typedef NSRect        CGSRect;
 
29
 
 
30
extern CGSConnectionID _CGSDefaultConnection ();
 
31
 
 
32
extern CGSError CGSGetOnScreenWindowList (CGSConnectionID cid,
 
33
    CGSConnectionID owner, CGSWindowCount listCapacity,
 
34
    CGSWindowIDList list, CGSWindowCount *listCount);
 
35
 
 
36
extern CGSError CGSGetWindowList (CGSConnectionID cid,
 
37
    CGSConnectionID owner, CGSWindowCount listCapacity,
 
38
    CGSWindowIDList list, CGSWindowCount *listCount);
 
39
 
 
40
extern CGSError CGSGetScreenRectForWindow (CGSConnectionID cid,
 
41
    CGSWindowID wid, CGSRect *rect);
 
42
 
 
43
extern CGWindowLevel CGSGetWindowLevel (CGSConnectionID cid,
 
44
    CGSWindowID wid, CGSWindowLevel *level);
 
45
 
 
46
typedef enum _CGSWindowOrderingMode {
 
47
    kCGSOrderAbove                =  1, /* Window is ordered above target. */
 
48
    kCGSOrderBelow                = -1, /* Window is ordered below target. */
 
49
    kCGSOrderOut                  =  0  /* Window is removed from the on-screen window list. */
 
50
} CGSWindowOrderingMode;
 
51
 
 
52
extern OSStatus CGSOrderWindow(const CGSConnectionID cid,
 
53
    const CGSWindowID wid, CGSWindowOrderingMode place, CGSWindowID relativeToWindowID);
 
54
 
 
55
static CGSConnectionID cid = NULL;
 
56
 
 
57
extern void macosx_log(char *);
 
58
 
 
59
int macwinmax = 0; 
 
60
typedef struct windat {
 
61
        int win;
 
62
        int x, y;
 
63
        int width, height;
 
64
        int level;
 
65
        int mapped;
 
66
        int clipped;
 
67
        int ncache_only;
 
68
} windat_t;
 
69
 
 
70
extern int ncache;
 
71
 
 
72
#define MAXWINDAT 4096
 
73
windat_t macwins[MAXWINDAT]; 
 
74
static CGSWindowID _wins_all[MAXWINDAT]; 
 
75
static CGSWindowID _wins_mapped[MAXWINDAT]; 
 
76
static CGSWindowCount _wins_all_cnt, _wins_mapped_cnt; 
 
77
static int _wins_int[MAXWINDAT]; 
 
78
 
 
79
#define WINHISTNUM 32768
 
80
#define WINHISTMAX 4
 
81
char whist[WINHISTMAX][WINHISTNUM];
 
82
int whist_idx = -1;
 
83
int qlook[WINHISTNUM];
 
84
 
 
85
char is_exist     = 0x1;
 
86
char is_mapped    = 0x2;
 
87
char is_clipped   = 0x4;
 
88
char is_offscreen = 0x8;
 
89
 
 
90
extern double dnow(void);
 
91
extern double dnowx(void);
 
92
 
 
93
extern int dpy_x, dpy_y;
 
94
extern int macosx_icon_anim_time;
 
95
 
 
96
extern void macosx_add_mapnotify(int, int, int);
 
97
extern void macosx_add_create(int, int);
 
98
extern void macosx_add_destroy(int, int);
 
99
extern void macosx_add_visnotify(int, int, int);
 
100
 
 
101
int CGS_levelmax;
 
102
int CGS_levels[16];
 
103
 
 
104
int macosxCGS_get_qlook(int w) {
 
105
        if (w >= WINHISTNUM) {
 
106
                return -1;
 
107
        }
 
108
        return qlook[w];
 
109
}
 
110
 
 
111
int macosxCGS_find_index(int w) {
 
112
        static int last_index = -1;
 
113
        int idx;
 
114
 
 
115
        if (last_index >= 0) {
 
116
                if (macwins[last_index].win == w) {
 
117
                        return last_index;
 
118
                }
 
119
        }
 
120
 
 
121
        idx = macosxCGS_get_qlook(w);
 
122
        if (idx >= 0) {
 
123
                if (macwins[idx].win == w) {
 
124
                        last_index = idx;
 
125
                        return idx;
 
126
                }
 
127
        }
 
128
 
 
129
        for (idx=0; idx < macwinmax; idx++) {
 
130
                if (macwins[idx].win == w) {
 
131
                        last_index = idx;
 
132
                        return idx;
 
133
                }
 
134
        }
 
135
        return -1;
 
136
}
 
137
 
 
138
#if 0
 
139
extern void usleep(unsigned long usec);
 
140
#else
 
141
extern int usleep(useconds_t usec);
 
142
#endif
 
143
 
 
144
int macosxCGS_follow_animation_win(int win, int idx, int grow) {
 
145
        double t = dnow();
 
146
        int diffs = 0;
 
147
        int x, y, w, h;
 
148
        int xp = -1, yp = -1, wp = -1, hp = -1;
 
149
        CGSRect rect;
 
150
        CGSError err; 
 
151
 
 
152
        int reps = 0;
 
153
 
 
154
        if (cid == NULL) {
 
155
                cid = _CGSDefaultConnection();
 
156
                if (cid == NULL) {
 
157
                        return 0;
 
158
                }
 
159
        }
 
160
 
 
161
        if (idx < 0) {
 
162
                idx = macosxCGS_find_index(win); 
 
163
        }
 
164
        if (idx < 0) {
 
165
                return 0;
 
166
        }
 
167
 
 
168
        while (dnow() < t + 0.001 * macosx_icon_anim_time)  {
 
169
                err = CGSGetScreenRectForWindow(cid, win, &rect);
 
170
                if (err != 0) {
 
171
                        break;
 
172
                }
 
173
                x = (int) rect.origin.x;
 
174
                y = (int) rect.origin.y;
 
175
                w = (int) rect.size.width;
 
176
                h = (int) rect.size.height;
 
177
 
 
178
                if (grow) {
 
179
                        macwins[idx].x      = x;
 
180
                        macwins[idx].y      = y;
 
181
                        macwins[idx].width  = w;
 
182
                        macwins[idx].height = h;
 
183
                }
 
184
        
 
185
                if (0) fprintf(stderr, " chase: %03dx%03d+%03d+%03d  %d\n", w, h, x, y, win);
 
186
                if (x == xp && y == yp && w == wp && h == hp)  {
 
187
                        reps++;
 
188
                        if (reps >= 2) {
 
189
                                break;
 
190
                        }
 
191
                } else {
 
192
                        diffs++;
 
193
                        reps = 0;
 
194
                }
 
195
                xp = x;
 
196
                yp = y;
 
197
                wp = w;
 
198
                hp = h;
 
199
                usleep(50 * 1000);
 
200
        }
 
201
        if (diffs >= 2) {
 
202
                return 1;
 
203
        } else {
 
204
                return 0;
 
205
        }
 
206
}
 
207
 
 
208
extern int macosx_check_clipped(int win, int *list, int n);
 
209
extern int macosx_check_offscreen(int win);
 
210
 
 
211
static int check_clipped(int win) {
 
212
        int i, n = 0, win2;
 
213
        for (i = 0; i < (int) _wins_mapped_cnt; i++) {
 
214
                win2 = (int) _wins_mapped[i];
 
215
                if (win2 == win) {
 
216
                        break;
 
217
                }
 
218
                _wins_int[n++] = win2;
 
219
        }
 
220
        return macosx_check_clipped(win, _wins_int, n);
 
221
}
 
222
 
 
223
static int check_offscreen(int win) {
 
224
        return macosx_check_offscreen(win);
 
225
}
 
226
 
 
227
extern int macosx_ncache_macmenu;
 
228
 
 
229
 
 
230
void macosxCGS_get_all_windows(void) {
 
231
        static double last = 0.0;
 
232
        static int totcnt = 0;
 
233
        double dt = 0.0, now = dnow();
 
234
        int i, db = 0, whist_prv = 0, maxwin = 0, whist_skip = 0;
 
235
        CGSWindowCount cap = (CGSWindowCount) MAXWINDAT;
 
236
        CGSError err; 
 
237
 
 
238
        CGS_levelmax = 0;
 
239
        CGS_levels[CGS_levelmax++] = (int) kCGDraggingWindowLevel;      /* 500 ? */
 
240
        if (0) CGS_levels[CGS_levelmax++] = (int) kCGHelpWindowLevel;           /* 102 ? */
 
241
        if (macosx_ncache_macmenu) CGS_levels[CGS_levelmax++] = (int) kCGPopUpMenuWindowLevel;  /* 101 pulldown menu */
 
242
        CGS_levels[CGS_levelmax++] = (int) kCGMainMenuWindowLevelKey;   /*  24 ? */
 
243
        CGS_levels[CGS_levelmax++] = (int) kCGModalPanelWindowLevel;    /*   8 open dialog box */
 
244
        CGS_levels[CGS_levelmax++] = (int) kCGFloatingWindowLevel;      /*   3 ? */
 
245
        CGS_levels[CGS_levelmax++] = (int) kCGNormalWindowLevel;        /*   0 regular window */
 
246
 
 
247
        if (cid == NULL) {
 
248
                cid = _CGSDefaultConnection();
 
249
                if (cid == NULL) {
 
250
                        return;
 
251
                }
 
252
        }
 
253
 
 
254
        if (dt > 0.0 && now < last + dt) {
 
255
                return;
 
256
        }
 
257
 
 
258
        last = now;
 
259
 
 
260
        macwinmax = 0; 
 
261
 
 
262
        totcnt++;
 
263
 
 
264
        if (ncache > 0) {
 
265
                whist_prv = whist_idx++;
 
266
                if (whist_prv < 0) {
 
267
                        whist_skip = 1;
 
268
                        whist_prv = 0;
 
269
                }
 
270
                whist_idx = whist_idx % WINHISTMAX;
 
271
                for (i=0; i < WINHISTNUM; i++) {
 
272
                        whist[whist_idx][i] = 0;
 
273
                        qlook[i] = -1;
 
274
                }
 
275
        }
 
276
 
 
277
        err = CGSGetWindowList(cid, NULL, cap, _wins_all, &_wins_all_cnt);
 
278
 
 
279
if (db) fprintf(stderr, "cnt: %d err: %d\n", (int) _wins_all_cnt, err);
 
280
 
 
281
        if (err != 0) {
 
282
                return;
 
283
        }
 
284
        
 
285
        for (i=0; i < (int) _wins_all_cnt; i++) {
 
286
                CGSRect rect;
 
287
                CGSWindowLevel level;
 
288
                int j, keepit = 0;
 
289
                err = CGSGetScreenRectForWindow(cid, _wins_all[i], &rect);
 
290
                if (err != 0) {
 
291
                        continue;
 
292
                }
 
293
                if (rect.origin.x == 0 && rect.origin.y == 0) {
 
294
                        if (rect.size.width == dpy_x) {
 
295
                                if (rect.size.height == dpy_y) {
 
296
                                        continue;
 
297
                                }
 
298
                        }
 
299
                }
 
300
                err = CGSGetWindowLevel(cid, _wins_all[i], &level);
 
301
                if (err != 0) {
 
302
                        continue;
 
303
                }
 
304
                for (j=0; j<CGS_levelmax; j++) {
 
305
                        if ((int) level == CGS_levels[j]) {
 
306
                                keepit = 1;
 
307
                                break;
 
308
                        }
 
309
                }
 
310
                if (! keepit) {
 
311
                        continue;
 
312
                }
 
313
 
 
314
                macwins[macwinmax].level  = (int) level;
 
315
                macwins[macwinmax].win    = (int) _wins_all[i];
 
316
                macwins[macwinmax].x      = (int) rect.origin.x;
 
317
                macwins[macwinmax].y      = (int) rect.origin.y;
 
318
                macwins[macwinmax].width  = (int) rect.size.width;
 
319
                macwins[macwinmax].height = (int) rect.size.height;
 
320
                macwins[macwinmax].mapped = 0;
 
321
                macwins[macwinmax].clipped = 0;
 
322
                macwins[macwinmax].ncache_only = 0;
 
323
                if (level == kCGPopUpMenuWindowLevel) {
 
324
                        macwins[macwinmax].ncache_only = 1;
 
325
                }
 
326
 
 
327
if (0 || db) fprintf(stderr, "i=%03d ID: %06d  x: %03d  y: %03d  w: %03d h: %03d level: %d\n", i, _wins_all[i],
 
328
    (int) rect.origin.x, (int) rect.origin.y,(int) rect.size.width, (int) rect.size.height, (int) level);
 
329
 
 
330
                if (macwins[macwinmax].win < WINHISTNUM) {
 
331
                        qlook[macwins[macwinmax].win] = macwinmax;
 
332
                        if (macwins[macwinmax].win > maxwin) {
 
333
                                maxwin = macwins[macwinmax].win;
 
334
                        }
 
335
                }
 
336
 
 
337
                macwinmax++;
 
338
        }
 
339
 
 
340
        err = CGSGetOnScreenWindowList(cid, NULL, cap, _wins_mapped, &_wins_mapped_cnt);
 
341
 
 
342
if (db) fprintf(stderr, "cnt: %d err: %d\n", (int) _wins_mapped_cnt, err);
 
343
 
 
344
        if (err != 0) {
 
345
                return;
 
346
        }
 
347
        
 
348
        for (i=0; i < (int) _wins_mapped_cnt; i++) {
 
349
                int j, idx = -1;
 
350
                int win = (int) _wins_mapped[i];
 
351
 
 
352
                if (0 <= win && win < WINHISTNUM) {
 
353
                        j = qlook[win];
 
354
                        if (j >= 0 && macwins[j].win == win) {
 
355
                                idx = j; 
 
356
                        }
 
357
                }
 
358
                if (idx < 0) {
 
359
                        for (j=0; j < macwinmax; j++) {
 
360
                                if (macwins[j].win == win) {
 
361
                                        idx = j; 
 
362
                                        break;
 
363
                                }
 
364
                        }
 
365
                }
 
366
                if (idx >= 0) {
 
367
                        macwins[idx].mapped = 1;
 
368
                }
 
369
        }
 
370
 
 
371
        if (ncache > 0) {
 
372
                int nv= 0, NBMAX = 64;
 
373
                int nv_win[64];
 
374
                int nv_lvl[64];
 
375
                int nv_vis[64];
 
376
 
 
377
                for (i=0; i < macwinmax; i++) {
 
378
                        int win = macwins[i].win;
 
379
                        char prev, curr;
 
380
 
 
381
                        if (win >= WINHISTNUM) {
 
382
                                continue;
 
383
                        }
 
384
 
 
385
                        whist[whist_idx][win] |= is_exist;
 
386
                        if (macwins[i].mapped) {
 
387
                                whist[whist_idx][win] |= is_mapped;
 
388
                                if (check_clipped(win)) {
 
389
                                        whist[whist_idx][win] |= is_clipped;
 
390
                                        macwins[i].clipped = 1;
 
391
                                }
 
392
                                if (check_offscreen(win)) {
 
393
                                        whist[whist_idx][win] |= is_offscreen;
 
394
                                }
 
395
                        } else {
 
396
                                whist[whist_idx][win] |= is_offscreen;
 
397
                        }
 
398
 
 
399
                        curr = whist[whist_idx][win];
 
400
                        prev = whist[whist_prv][win];
 
401
 
 
402
                        if (whist_skip) {
 
403
                                ;
 
404
                        } else if ( !(prev & is_mapped) && (curr & is_mapped)) {
 
405
                                /* MapNotify */
 
406
                                if (0) fprintf(stderr, "MapNotify:   %d/%d  %d               %.4f tot=%d\n", prev, curr, win, dnowx(), totcnt); 
 
407
                                macosx_add_mapnotify(win, macwins[i].level, 1);
 
408
                                if (0) macosxCGS_follow_animation_win(win, i, 1);
 
409
 
 
410
                        } else if ( !(curr & is_mapped) && (prev & is_mapped)) {
 
411
                                /* UnmapNotify */
 
412
                                if (0) fprintf(stderr, "UnmapNotify: %d/%d  %d               %.4f A tot=%d\n", prev, curr, win, dnowx(), totcnt); 
 
413
                                macosx_add_mapnotify(win, macwins[i].level, 0);
 
414
                        } else if ( !(prev & is_exist) && (curr & is_exist)) {
 
415
                                /* CreateNotify */
 
416
                                if (0) fprintf(stderr, "CreateNotify:%d/%d  %d               %.4f whist: %d/%d 0x%x tot=%d\n", prev, curr, win, dnowx(), whist_prv, whist_idx, win, totcnt); 
 
417
                                macosx_add_create(win, macwins[i].level);
 
418
                                if (curr & is_mapped) {
 
419
                                        if (0) fprintf(stderr, "MapNotify:   %d/%d  %d               %.4f tot=%d\n", prev, curr, win, dnowx(), totcnt); 
 
420
                                        macosx_add_mapnotify(win, macwins[i].level, 1);
 
421
                                }
 
422
                        }
 
423
                        if (whist_skip) {
 
424
                                ;
 
425
                        } else if (nv >= NBMAX) {
 
426
                                ;
 
427
                        } else if (!(curr & is_mapped)) {
 
428
                                ;
 
429
                        } else if (!(prev & is_mapped)) {
 
430
                                if (1) {
 
431
                                        ;
 
432
                                } else if (curr & is_clipped) {
 
433
                                        if (0) fprintf(stderr, "VisibNotify: %d/%d  %d               OBS tot=%d\n", prev, curr, win, totcnt); 
 
434
                                        nv_win[nv] = win;
 
435
                                        nv_lvl[nv] = macwins[i].level;
 
436
                                        nv_vis[nv++] = 1;
 
437
                                } else {
 
438
                                        if (0) fprintf(stderr, "VisibNotify: %d/%d  %d               UNOBS tot=%d\n", prev, curr, win, totcnt); 
 
439
                                        nv_win[nv] = win;
 
440
                                        nv_lvl[nv] = macwins[i].level;
 
441
                                        nv_vis[nv++] = 0;
 
442
                                }
 
443
                        } else {
 
444
                                if        ( !(prev & is_clipped) &&  (curr & is_clipped) ) {
 
445
                                        if (0) fprintf(stderr, "VisibNotify: %d/%d  %d               OBS tot=%d\n", prev, curr, win, totcnt); 
 
446
                                        nv_win[nv] = win;
 
447
                                        nv_lvl[nv] = macwins[i].level;
 
448
                                        nv_vis[nv++] = 1;
 
449
                                } else if (  (prev & is_clipped) && !(curr & is_clipped) ) {
 
450
                                        if (0) fprintf(stderr, "VisibNotify: %d/%d  %d               UNOBS tot=%d\n", prev, curr, win, totcnt); 
 
451
                                        nv_win[nv] = win;
 
452
                                        nv_lvl[nv] = macwins[i].level;
 
453
                                        nv_vis[nv++] = 0;
 
454
                                }
 
455
                        }
 
456
                }
 
457
                for (i=0; i < maxwin; i++) {
 
458
                        char prev, curr;
 
459
                        int win = i;
 
460
                        int q = qlook[i];
 
461
                        int lvl = 0;
 
462
 
 
463
                        if (whist_skip) {
 
464
                                break;
 
465
                        }
 
466
 
 
467
                        if (q >= 0) {
 
468
                                lvl = macwins[q].level; 
 
469
                        }
 
470
                        curr = whist[whist_idx][win];
 
471
                        prev = whist[whist_prv][win];
 
472
                        if (!(curr & is_exist) && (prev & is_exist)) {
 
473
                                if (prev & is_mapped) {
 
474
                                        if (0) fprintf(stderr, "UnmapNotify: %d/%d  %d               %.4f B tot=%d\n", prev, curr, win, dnowx(), totcnt); 
 
475
                                        macosx_add_mapnotify(win, lvl, 0);
 
476
                                }
 
477
                                /* DestroyNotify */
 
478
                                if (0) fprintf(stderr, "DestroNotify:%d/%d  %d               %.4f tot=%d\n", prev, curr, win, dnowx(), totcnt); 
 
479
                                macosx_add_destroy(win, lvl);
 
480
                        }
 
481
                }
 
482
                if (nv) {
 
483
                        int k;
 
484
                        for (k = 0; k < nv; k++) {
 
485
                                macosx_add_visnotify(nv_win[k], nv_lvl[k], nv_vis[k]);
 
486
                        }
 
487
                }
 
488
        }
 
489
}
 
490
 
 
491
#if 1
 
492
NSLock *pblock = nil;
 
493
NSString *pbstr = nil;
 
494
NSString *cuttext = nil;
 
495
 
 
496
int pbcnt = -1;
 
497
NSStringEncoding pbenc = NSWindowsCP1252StringEncoding;
 
498
 
 
499
void macosxGCS_initpb(void) {
 
500
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
501
        pblock = [[NSLock alloc] init];
 
502
        if (![NSPasteboard generalPasteboard]) {
 
503
                macosx_log("macosxGCS_initpb: **PASTEBOARD INACCESSIBLE**.\n");
 
504
                macosx_log("macosxGCS_initpb: Clipboard exchange will NOT work.\n");
 
505
                macosx_log("macosxGCS_initpb: Start x11vnc *inside* Aqua for Clipboard.\n");
 
506
                pbcnt = 0;
 
507
                pbstr = [[NSString alloc] initWithString:@"\e<PASTEBOARD INACCESSIBLE>\e"]; 
 
508
        }
 
509
        [pool release];
 
510
}
 
511
 
 
512
void macosxGCS_set_pasteboard(char *str, int len) {
 
513
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
514
        if (pbcnt != 0) {
 
515
                [pblock lock];
 
516
                [cuttext release];
 
517
                cuttext = [[NSString alloc] initWithData:[NSData dataWithBytes:str length:len] encoding: pbenc];
 
518
                if ([[NSPasteboard generalPasteboard] declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]) {
 
519
                        NS_DURING
 
520
                                [[NSPasteboard generalPasteboard] setString:cuttext forType:NSStringPboardType];
 
521
                        NS_HANDLER
 
522
                                fprintf(stderr, "macosxGCS_set_pasteboard: problem writing to pasteboard\n");
 
523
                        NS_ENDHANDLER
 
524
                } else {
 
525
                        fprintf(stderr, "macosxGCS_set_pasteboard: problem writing to pasteboard\n");
 
526
                }
 
527
                [cuttext release];
 
528
                cuttext = nil;
 
529
                [pblock unlock];
 
530
        }
 
531
        [pool release];
 
532
}
 
533
 
 
534
extern void macosx_send_sel(char *, int);
 
535
 
 
536
void macosxGCS_poll_pb(void) {
 
537
 
 
538
        static double dlast = 0.0;
 
539
        double now = dnow();
 
540
 
 
541
        if (now < dlast + 0.2) {
 
542
                return;
 
543
        }
 
544
        dlast = now;
 
545
 
 
546
   {
 
547
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
548
        [pblock lock];
 
549
        if (pbcnt != [[NSPasteboard generalPasteboard] changeCount]) {
 
550
                pbcnt = [[NSPasteboard generalPasteboard] changeCount];
 
551
                [pbstr release];
 
552
                pbstr = nil;
 
553
                if ([[NSPasteboard generalPasteboard] availableTypeFromArray:[NSArray arrayWithObject:NSStringPboardType]]) {
 
554
                        pbstr = [[[NSPasteboard generalPasteboard] stringForType:NSStringPboardType] copy];
 
555
                        if (pbstr) {
 
556
                                NSData *str = [pbstr dataUsingEncoding:pbenc allowLossyConversion:YES];
 
557
                                if ([str length]) {
 
558
                                        macosx_send_sel((char *) [str bytes], [str length]);
 
559
                                }
 
560
                        }
 
561
                }
 
562
        }
 
563
        [pblock unlock];
 
564
        [pool release];
 
565
   }
 
566
}
 
567
#endif
 
568
 
 
569
#endif  /* __APPLE__ */
 
570