1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
|
/*
* tkMacOSXXStubs.c --
*
* This file contains most of the X calls called by Tk. Many of these
* calls are just stubs and either don't make sense on the Macintosh or
* their implamentation just doesn't do anything. Other calls will
* eventually be moved into other files.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright 2001-2009, Apple Inc.
* Copyright (c) 2005-2009 Daniel A. Steffen <das@users.sourceforge.net>
* Copyright 2014 Marc Culler.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tkMacOSXPrivate.h"
#include "tkMacOSXEvent.h"
#include <IOKit/IOKitLib.h>
#include <IOKit/hidsystem/IOHIDShared.h>
/*
* Because this file is still under major development Debugger statements are
* used through out this file. The define TCL_DEBUG will decide whether the
* debugger statements actually call the debugger or not.
*/
#ifndef TCL_DEBUG
# define Debugger()
#endif
#define ROOT_ID 10
CGFloat tkMacOSXZeroScreenHeight = 0;
CGFloat tkMacOSXZeroScreenTop = 0;
/*
* Declarations of static variables used in this file.
*/
static TkDisplay *gMacDisplay = NULL;
/* Macintosh display. */
static const char *macScreenName = ":0";
/* Default name of macintosh display. */
/*
* Forward declarations of procedures used in this file.
*/
static XID MacXIdAlloc(Display *display);
static int DefaultErrorHandler(Display *display,
XErrorEvent *err_evt);
/*
*----------------------------------------------------------------------
*
* TkMacOSXDisplayChanged --
*
* Called to set up initial screen info or when an event indicated
* display (screen) change.
*
* Results:
* None.
*
* Side effects:
* May change info regarding the screen.
*
*----------------------------------------------------------------------
*/
void
TkMacOSXDisplayChanged(
Display *display)
{
Screen *screen;
NSArray *nsScreens;
if (display == NULL || display->screens == NULL) {
return;
}
screen = display->screens;
nsScreens = [NSScreen screens];
if (nsScreens && [nsScreens count]) {
NSScreen *s = [nsScreens objectAtIndex:0];
NSRect bounds = [s frame], visible = [s visibleFrame];
NSRect maxBounds = NSZeroRect;
tkMacOSXZeroScreenHeight = bounds.size.height;
tkMacOSXZeroScreenTop = tkMacOSXZeroScreenHeight -
(visible.origin.y + visible.size.height);
screen->root_depth = NSBitsPerPixelFromDepth([s depth]);
screen->width = bounds.size.width;
screen->height = bounds.size.height;
screen->mwidth = (bounds.size.width * 254 + 360) / 720;
screen->mheight = (bounds.size.height * 254 + 360) / 720;
for (s in nsScreens) {
maxBounds = NSUnionRect(maxBounds, [s visibleFrame]);
}
*((NSRect *)screen->ext_data) = maxBounds;
}
}
/*
*----------------------------------------------------------------------
*
* TkpOpenDisplay --
*
* Create the Display structure and fill it with device specific
* information.
*
* Results:
* Returns a Display structure on success or NULL on failure.
*
* Side effects:
* Allocates a new Display structure.
*
*----------------------------------------------------------------------
*/
TkDisplay *
TkpOpenDisplay(
const char *display_name)
{
Display *display;
Screen *screen;
int fd = 0;
static NSRect maxBounds = {{0, 0}, {0, 0}};
static char vendor[25] = "";
NSArray *cgVers;
NSAutoreleasePool *pool = [NSAutoreleasePool new];
if (gMacDisplay != NULL) {
if (strcmp(gMacDisplay->display->display_name, display_name) == 0) {
return gMacDisplay;
} else {
return NULL;
}
}
display = ckalloc(sizeof(Display));
screen = ckalloc(sizeof(Screen));
bzero(display, sizeof(Display));
bzero(screen, sizeof(Screen));
display->resource_alloc = MacXIdAlloc;
display->request = 0;
display->qlen = 0;
display->fd = fd;
display->screens = screen;
display->nscreens = 1;
display->default_screen = 0;
display->display_name = (char *) macScreenName;
cgVers = [[[NSBundle bundleWithIdentifier:@"com.apple.CoreGraphics"]
objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
componentsSeparatedByString:@"."];
if ([cgVers count] >= 2) {
display->proto_major_version = [[cgVers objectAtIndex:1] integerValue];
}
if ([cgVers count] >= 3) {
display->proto_minor_version = [[cgVers objectAtIndex:2] integerValue];
}
if (!vendor[0]) {
snprintf(vendor, sizeof(vendor), "Apple AppKit %g",
NSAppKitVersionNumber);
}
display->vendor = vendor;
{
int major, minor, patch;
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1080
Gestalt(gestaltSystemVersionMajor, (SInt32*)&major);
Gestalt(gestaltSystemVersionMinor, (SInt32*)&minor);
Gestalt(gestaltSystemVersionBugFix, (SInt32*)&patch);
#else
NSOperatingSystemVersion systemVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
major = systemVersion.majorVersion;
minor = systemVersion.minorVersion;
patch = systemVersion.patchVersion;
#endif
display->release = major << 16 | minor << 8 | patch;
}
/*
* These screen bits never change
*/
screen->root = ROOT_ID;
screen->display = display;
screen->black_pixel = 0x00000000 | PIXEL_MAGIC << 24;
screen->white_pixel = 0x00FFFFFF | PIXEL_MAGIC << 24;
screen->ext_data = (XExtData *) &maxBounds;
screen->root_visual = ckalloc(sizeof(Visual));
screen->root_visual->visualid = 0;
screen->root_visual->class = TrueColor;
screen->root_visual->alpha_mask = 0xFF000000;
screen->root_visual->red_mask = 0x00FF0000;
screen->root_visual->green_mask = 0x0000FF00;
screen->root_visual->blue_mask = 0x000000FF;
screen->root_visual->bits_per_rgb = 24;
screen->root_visual->map_entries = 256;
/*
* Initialize screen bits that may change
*/
TkMacOSXDisplayChanged(display);
gMacDisplay = ckalloc(sizeof(TkDisplay));
/*
* This is the quickest way to make sure that all the *Init flags get
* properly initialized
*/
bzero(gMacDisplay, sizeof(TkDisplay));
gMacDisplay->display = display;
[pool drain];
return gMacDisplay;
}
/*
*----------------------------------------------------------------------
*
* TkpCloseDisplay --
*
* Deallocates a display structure created by TkpOpenDisplay.
*
* Results:
* None.
*
* Side effects:
* Frees memory.
*
*----------------------------------------------------------------------
*/
void
TkpCloseDisplay(
TkDisplay *displayPtr)
{
Display *display = displayPtr->display;
if (gMacDisplay != displayPtr) {
Tcl_Panic("TkpCloseDisplay: tried to call TkpCloseDisplay on bad display");
}
gMacDisplay = NULL;
if (display->screens != NULL) {
if (display->screens->root_visual != NULL) {
ckfree(display->screens->root_visual);
}
ckfree(display->screens);
}
ckfree(display);
}
/*
*----------------------------------------------------------------------
*
* TkClipCleanup --
*
* This procedure is called to cleanup resources associated with claiming
* clipboard ownership and for receiving selection get results. This
* function is called in tkWindow.c. This has to be called by the display
* cleanup function because we still need the access display elements.
*
* Results:
* None.
*
* Side effects:
* Resources are freed - the clipboard may no longer be used.
*
*----------------------------------------------------------------------
*/
void
TkClipCleanup(
TkDisplay *dispPtr) /* display associated with clipboard */
{
/*
* Make sure that the local scrap is transfered to the global scrap if
* needed.
*/
[NSApp tkProvidePasteboard:dispPtr];
if (dispPtr->clipWindow != NULL) {
Tk_DeleteSelHandler(dispPtr->clipWindow, dispPtr->clipboardAtom,
dispPtr->applicationAtom);
Tk_DeleteSelHandler(dispPtr->clipWindow, dispPtr->clipboardAtom,
dispPtr->windowAtom);
Tk_DestroyWindow(dispPtr->clipWindow);
Tcl_Release(dispPtr->clipWindow);
dispPtr->clipWindow = NULL;
}
}
/*
*----------------------------------------------------------------------
*
* MacXIdAlloc --
*
* This procedure is invoked by Xlib as the resource allocator for a
* display.
*
* Results:
* The return value is an X resource identifier that isn't currently in
* use.
*
* Side effects:
* The identifier is removed from the stack of free identifiers, if it
* was previously on the stack.
*
*----------------------------------------------------------------------
*/
static XID
MacXIdAlloc(
Display *display) /* Display for which to allocate. */
{
static long int cur_id = 100;
/*
* Some special XIds are reserved
* - this is why we start at 100
*/
return ++cur_id;
}
/*
*----------------------------------------------------------------------
*
* DefaultErrorHandler --
*
* This procedure is the default X error handler. Tk uses it's own error
* handler so this call should never be called.
*
* Results:
* None.
*
* Side effects:
* This function will call panic and exit.
*
*----------------------------------------------------------------------
*/
static int
DefaultErrorHandler(
Display* display,
XErrorEvent* err_evt)
{
/*
* This call should never be called. Tk replaces it with its own error
* handler.
*/
Tcl_Panic("Warning hit bogus error handler!");
return 0;
}
char *
XGetAtomName(
Display * display,
Atom atom)
{
display->request++;
return NULL;
}
XErrorHandler
XSetErrorHandler(
XErrorHandler handler)
{
return DefaultErrorHandler;
}
Window
XRootWindow(
Display *display,
int screen_number)
{
display->request++;
return ROOT_ID;
}
int
XGetGeometry(
Display *display,
Drawable d,
Window *root_return,
int *x_return,
int *y_return,
unsigned int *width_return,
unsigned int *height_return,
unsigned int *border_width_return,
unsigned int *depth_return)
{
TkWindow *winPtr = ((MacDrawable *) d)->winPtr;
display->request++;
*root_return = ROOT_ID;
if (winPtr) {
*x_return = Tk_X(winPtr);
*y_return = Tk_Y(winPtr);
*width_return = Tk_Width(winPtr);
*height_return = Tk_Height(winPtr);
*border_width_return = winPtr->changes.border_width;
*depth_return = Tk_Depth(winPtr);
} else {
CGSize size = ((MacDrawable *) d)->size;
*x_return = 0;
*y_return = 0;
*width_return = size.width;
*height_return = size.height;
*border_width_return = 0;
*depth_return = 32;
}
return 1;
}
void
XChangeProperty(
Display* display,
Window w,
Atom property,
Atom type,
int format,
int mode,
_Xconst unsigned char* data,
int nelements)
{
Debugger();
}
void
XSelectInput(
Display* display,
Window w,
long event_mask)
{
Debugger();
}
int
XBell(
Display* display,
int percent)
{
NSBeep();
return Success;
}
#if 0
void
XSetWMNormalHints(
Display* display,
Window w,
XSizeHints* hints)
{
/*
* Do nothing. Shouldn't even be called.
*/
}
XSizeHints *
XAllocSizeHints(void)
{
/*
* Always return NULL. Tk code checks to see if NULL is returned & does
* nothing if it is.
*/
return NULL;
}
#endif
GContext
XGContextFromGC(
GC gc)
{
/*
* TODO: currently a no-op
*/
return 0;
}
Status
XSendEvent(
Display* display,
Window w,
Bool propagate,
long event_mask,
XEvent* event_send)
{
Debugger();
return 0;
}
void
XClearWindow(
Display* display,
Window w)
{
}
/*
int
XDrawPoint(
Display* display,
Drawable d,
GC gc,
int x,
int y)
{
}
int
XDrawPoints(
Display* display,
Drawable d,
GC gc,
XPoint* points,
int npoints,
int mode)
{
}
*/
int
XWarpPointer(
Display* display,
Window src_w,
Window dest_w,
int src_x,
int src_y,
unsigned int src_width,
unsigned int src_height,
int dest_x,
int dest_y)
{
return Success;
}
void
XQueryColor(
Display* display,
Colormap colormap,
XColor* def_in_out)
{
unsigned long p;
unsigned char r, g, b;
XColor *d = def_in_out;
p = d->pixel;
r = (p & 0x00FF0000) >> 16;
g = (p & 0x0000FF00) >> 8;
b = (p & 0x000000FF);
d->red = (r << 8) | r;
d->green = (g << 8) | g;
d->blue = (b << 8) | b;
d->flags = DoRed|DoGreen|DoBlue;
d->pad = 0;
}
void
XQueryColors(
Display* display,
Colormap colormap,
XColor* defs_in_out,
int ncolors)
{
int i;
unsigned long p;
unsigned char r, g, b;
XColor *d = defs_in_out;
for (i = 0; i < ncolors; i++, d++) {
p = d->pixel;
r = (p & 0x00FF0000) >> 16;
g = (p & 0x0000FF00) >> 8;
b = (p & 0x000000FF);
d->red = (r << 8) | r;
d->green = (g << 8) | g;
d->blue = (b << 8) | b;
d->flags = DoRed|DoGreen|DoBlue;
d->pad = 0;
}
}
int
XQueryTree(display, w, root_return, parent_return, children_return,
nchildren_return)
Display* display;
Window w;
Window* root_return;
Window* parent_return;
Window** children_return;
unsigned int* nchildren_return;
{
return 0;
}
int
XGetWindowProperty(
Display *display,
Window w,
Atom property,
long long_offset,
long long_length,
Bool delete,
Atom req_type,
Atom *actual_type_return,
int *actual_format_return,
unsigned long *nitems_return,
unsigned long *bytes_after_return,
unsigned char ** prop_return)
{
display->request++;
*actual_type_return = None;
*actual_format_return = *bytes_after_return = 0;
*nitems_return = 0;
return 0;
}
void
XRefreshKeyboardMapping(
XMappingEvent *x)
{
/* used by tkXEvent.c */
Debugger();
}
void
XSetIconName(
Display* display,
Window w,
const char *icon_name)
{
/*
* This is a no-op, no icon name for Macs.
*/
display->request++;
}
void
XForceScreenSaver(
Display* display,
int mode)
{
/*
* This function is just a no-op. It is defined to reset the screen saver.
* However, there is no real way to do this on a Mac. Let me know if there
* is!
*/
display->request++;
}
void
Tk_FreeXId(
Display *display,
XID xid)
{
/* no-op function needed for stubs implementation. */
}
int
XSync(
Display *display,
Bool flag)
{
TkMacOSXFlushWindows();
display->request++;
return 0;
}
#if 0
int
XSetClipRectangles(
Display *d,
GC gc,
int clip_x_origin,
int clip_y_origin,
XRectangle* rectangles,
int n,
int ordering)
{
TkRegion clipRgn = TkCreateRegion();
while (n--) {
XRectangle rect = *rectangles;
rect.x += clip_x_origin;
rect.y += clip_y_origin;
TkUnionRectWithRegion(&rect, clipRgn, clipRgn);
rectangles++;
}
TkSetRegion(d, gc, clipRgn);
TkDestroyRegion(clipRgn);
return 1;
}
#endif
/*
*----------------------------------------------------------------------
*
* TkGetServerInfo --
*
* Given a window, this procedure returns information about the window
* server for that window. This procedure provides the guts of the "winfo
* server" command.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
TkGetServerInfo(
Tcl_Interp *interp, /* The server information is returned in this
* interpreter's result. */
Tk_Window tkwin) /* Token for window; this selects a particular
* display and server. */
{
char buffer[5 + TCL_INTEGER_SPACE * 2];
char buffer2[11 + TCL_INTEGER_SPACE];
snprintf(buffer, sizeof(buffer), "CG%d.%d ",
ProtocolVersion(Tk_Display(tkwin)),
ProtocolRevision(Tk_Display(tkwin)));
snprintf(buffer2, sizeof(buffer2), " Mac OS X %x",
VendorRelease(Tk_Display(tkwin)));
Tcl_AppendResult(interp, buffer, ServerVendor(Tk_Display(tkwin)),
buffer2, NULL);
}
/*
*----------------------------------------------------------------------
*
* XChangeWindowAttributes, XSetWindowBackground,
* XSetWindowBackgroundPixmap, XSetWindowBorder, XSetWindowBorderPixmap,
* XSetWindowBorderWidth, XSetWindowColormap
*
* These functions are all no-ops. They all have equivalent Tk calls that
* should always be used instead.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void
XChangeWindowAttributes(
Display *display,
Window w,
unsigned long value_mask,
XSetWindowAttributes *attributes)
{
}
void
XSetWindowBackground(
Display *display,
Window window,
unsigned long value)
{
}
void
XSetWindowBackgroundPixmap(
Display *display,
Window w,
Pixmap background_pixmap)
{
}
void
XSetWindowBorder(
Display *display,
Window w,
unsigned long border_pixel)
{
}
void
XSetWindowBorderPixmap(
Display *display,
Window w,
Pixmap border_pixmap)
{
}
void
XSetWindowBorderWidth(
Display *display,
Window w,
unsigned int width)
{
}
void
XSetWindowColormap(
Display *display,
Window w,
Colormap colormap)
{
Debugger();
}
Status
XStringListToTextProperty(
char **list,
int count,
XTextProperty *text_prop_return)
{
Debugger();
return (Status) 0;
}
void
XSetWMClientMachine(
Display *display,
Window w,
XTextProperty *text_prop)
{
Debugger();
}
XIC
XCreateIC(void)
{
Debugger();
return (XIC) 0;
}
/*
*----------------------------------------------------------------------
*
* TkGetDefaultScreenName --
*
* Returns the name of the screen that Tk should use during
* initialization.
*
* Results:
* Returns a statically allocated string.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
const char *
TkGetDefaultScreenName(
Tcl_Interp *interp, /* Not used. */
const char *screenName) /* If NULL, use default string. */
{
#if 0
if ((screenName == NULL) || (screenName[0] == '\0')) {
screenName = macScreenName;
}
return screenName;
#endif
return macScreenName;
}
/*
*----------------------------------------------------------------------
*
* Tk_GetUserInactiveTime --
*
* Return the number of milliseconds the user was inactive.
*
* Results:
* The number of milliseconds the user has been inactive, or -1 if
* querying the inactive time is not supported.
*
* Side effects:
* None.
*----------------------------------------------------------------------
*/
long
Tk_GetUserInactiveTime(
Display *dpy)
{
io_registry_entry_t regEntry;
CFMutableDictionaryRef props = NULL;
CFTypeRef timeObj;
long ret = -1l;
uint64_t time;
IOReturn result;
regEntry = IOServiceGetMatchingService(kIOMasterPortDefault,
IOServiceMatching("IOHIDSystem"));
if (regEntry == 0) {
return -1l;
}
result = IORegistryEntryCreateCFProperties(regEntry, &props,
kCFAllocatorDefault, 0);
IOObjectRelease(regEntry);
if (result != KERN_SUCCESS || props == NULL) {
return -1l;
}
timeObj = CFDictionaryGetValue(props, CFSTR("HIDIdleTime"));
if (timeObj) {
CFTypeID type = CFGetTypeID(timeObj);
if (type == CFDataGetTypeID()) { /* Jaguar */
CFDataGetBytes((CFDataRef) timeObj,
CFRangeMake(0, sizeof(time)), (UInt8 *) &time);
/* Convert nanoseconds to milliseconds. */
/* ret /= kMillisecondScale; */
ret = (long) (time/kMillisecondScale);
} else if (type == CFNumberGetTypeID()) { /* Panther+ */
CFNumberGetValue((CFNumberRef)timeObj,
kCFNumberSInt64Type, &time);
/* Convert nanoseconds to milliseconds. */
/* ret /= kMillisecondScale; */
ret = (long) (time/kMillisecondScale);
} else {
ret = -1l;
}
}
/* Cleanup */
CFRelease(props);
return ret;
}
/*
*----------------------------------------------------------------------
*
* Tk_ResetUserInactiveTime --
*
* Reset the user inactivity timer
*
* Results:
* none
*
* Side effects:
* The user inactivity timer of the underlaying windowing system is reset
* to zero.
*
*----------------------------------------------------------------------
*/
void
Tk_ResetUserInactiveTime(
Display *dpy)
{
IOGPoint loc = {0, 0};
kern_return_t kr;
NXEvent nullEvent = {NX_NULLEVENT, {0, 0}, 0, -1, 0};
enum { kNULLEventPostThrottle = 10 };
static io_connect_t io_connection = MACH_PORT_NULL;
if (io_connection == MACH_PORT_NULL) {
io_service_t service = IOServiceGetMatchingService(
kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass));
if (service == MACH_PORT_NULL) {
return;
}
kr = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType,
&io_connection);
IOObjectRelease(service);
if (kr != KERN_SUCCESS) {
return;
}
}
kr = IOHIDPostEvent(io_connection, NX_NULLEVENT, loc, &nullEvent.data,
FALSE, 0, FALSE);
}
/*
* Local Variables:
* mode: objc
* c-basic-offset: 4
* fill-column: 79
* coding: utf-8
* End:
*/
|