4 * This file contains procedures that are UNIX/X-specific, and will
5 * probably have to be written differently for Windows or Macintosh
8 * Copyright (c) 1995 Sun Microsystems, Inc.
10 * See the file "license.terms" for information on usage and redistribution of
11 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 # include <X11/extensions/scrnsaver.h>
18 /* Support for weak-linked libXss. */
19 # define HaveXSSLibrary() (&XScreenSaverQueryInfo != NULL)
21 /* Other platforms always link libXss. */
22 # define HaveXSSLibrary() (1)
27 *----------------------------------------------------------------------
31 * Given a window, this procedure returns information about the window
32 * server for that window. This procedure provides the guts of the "winfo
36 * Sets the interpreter result.
41 *----------------------------------------------------------------------
46 Tcl_Interp *interp, /* The server information is returned in this
47 * interpreter's result. */
48 Tk_Window tkwin) /* Token for window; this selects a particular
49 * display and server. */
51 Tcl_SetObjResult(interp, Tcl_ObjPrintf("X%dR%d %s %d",
52 ProtocolVersion(Tk_Display(tkwin)),
53 ProtocolRevision(Tk_Display(tkwin)),
54 ServerVendor(Tk_Display(tkwin)),
55 VendorRelease(Tk_Display(tkwin))));
59 *----------------------------------------------------------------------
61 * TkGetDefaultScreenName --
63 * Returns the name of the screen that Tk should use during
67 * Returns the argument or a string that should not be freed by the
73 *----------------------------------------------------------------------
77 TkGetDefaultScreenName(
78 Tcl_Interp *interp, /* Interp used to find environment
80 const char *screenName) /* Screen name from command line, or NULL. */
82 if ((screenName == NULL) || (screenName[0] == '\0')) {
83 screenName = Tcl_GetVar2(interp, "env", "DISPLAY", TCL_GLOBAL_ONLY);
89 *----------------------------------------------------------------------
93 * Unused function in UNIX
101 *----------------------------------------------------------------------
106 Tk_Window tkwin, /* Window to which pointer event is reported.
108 int x, int y, /* Pointer location in root coords. */
109 int state) /* Modifier state mask. */
112 * This function intentionally left blank
117 *----------------------------------------------------------------------
119 * TkpBuildRegionFromAlphaData --
121 * Set up a rectangle of the given region based on the supplied alpha
128 * The region is updated, with extra pixels added to it.
130 *----------------------------------------------------------------------
134 TkpBuildRegionFromAlphaData(
135 TkRegion region, /* Region to be updated. */
136 unsigned x, unsigned y, /* Where in region to update. */
137 unsigned width, unsigned height,
138 /* Size of rectangle to update. */
139 unsigned char *dataPtr, /* Data to read from. */
140 unsigned pixelStride, /* Num bytes from one piece of alpha data to
141 * the next in the line. */
142 unsigned lineStride) /* Num bytes from one line of alpha data to
145 unsigned char *lineDataPtr;
146 unsigned int x1, y1, end;
149 for (y1 = 0; y1 < height; y1++) {
150 lineDataPtr = dataPtr;
151 for (x1 = 0; x1 < width; x1 = end) {
153 * Search for first non-transparent pixel.
156 while ((x1 < width) && !*lineDataPtr) {
158 lineDataPtr += pixelStride;
163 * Search for first transparent pixel.
166 while ((end < width) && *lineDataPtr) {
168 lineDataPtr += pixelStride;
173 rect.width = end - x1;
175 TkUnionRectWithRegion(&rect, region, region);
178 dataPtr += lineStride;
183 *----------------------------------------------------------------------
185 * Tk_GetUserInactiveTime --
187 * Return the number of milliseconds the user was inactive.
190 * The number of milliseconds since the user's latest interaction with
191 * the system on the given display, or -1 if the XScreenSaver extension
192 * is not supported by the client libraries or the X server
197 *----------------------------------------------------------------------
201 Tk_GetUserInactiveTime(
203 Display *dpy) /* The display for which to query the inactive
206 TCL_UNUSED(Display *))
207 #endif /* HAVE_XSS */
209 long inactiveTime = -1;
211 int eventBase, errorBase, major, minor;
214 * Calling XScreenSaverQueryVersion seems to be needed to prevent a crash
215 * on some buggy versions of XFree86.
219 && XScreenSaverQueryExtension(dpy, &eventBase, &errorBase)
220 && XScreenSaverQueryVersion(dpy, &major, &minor)) {
221 XScreenSaverInfo *info = XScreenSaverAllocInfo();
225 * We are out of memory.
228 Tcl_Panic("Out of memory: XScreenSaverAllocInfo failed in Tk_GetUserInactiveTime");
230 if (XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info)) {
231 inactiveTime = info->idle;
235 #endif /* HAVE_XSS */
240 *----------------------------------------------------------------------
242 * Tk_ResetUserInactiveTime --
244 * Reset the user inactivity timer
250 * The user inactivity timer of the underlaying windowing system is reset
253 *----------------------------------------------------------------------
257 Tk_ResetUserInactiveTime(
260 XResetScreenSaver(dpy);