OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tk8.6.12 / unix / tkUnix.c
1 /*
2  * tkUnix.c --
3  *
4  *      This file contains procedures that are UNIX/X-specific, and will
5  *      probably have to be written differently for Windows or Macintosh
6  *      platforms.
7  *
8  * Copyright (c) 1995 Sun Microsystems, Inc.
9  *
10  * See the file "license.terms" for information on usage and redistribution of
11  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
12  */
13
14 #include "tkInt.h"
15 #ifdef HAVE_XSS
16 #   include <X11/extensions/scrnsaver.h>
17 #   ifdef __APPLE__
18 /* Support for weak-linked libXss. */
19 #       define HaveXSSLibrary() (&XScreenSaverQueryInfo != NULL)
20 #   else
21 /* Other platforms always link libXss. */
22 #       define HaveXSSLibrary() (1)
23 #   endif
24 #endif
25 \f
26 /*
27  *----------------------------------------------------------------------
28  *
29  * TkGetServerInfo --
30  *
31  *      Given a window, this procedure returns information about the window
32  *      server for that window. This procedure provides the guts of the "winfo
33  *      server" command.
34  *
35  * Results:
36  *      Sets the interpreter result.
37  *
38  * Side effects:
39  *      None.
40  *
41  *----------------------------------------------------------------------
42  */
43
44 void
45 TkGetServerInfo(
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. */
50 {
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))));
56 }
57 \f
58 /*
59  *----------------------------------------------------------------------
60  *
61  * TkGetDefaultScreenName --
62  *
63  *      Returns the name of the screen that Tk should use during
64  *      initialization.
65  *
66  * Results:
67  *      Returns the argument or a string that should not be freed by the
68  *      caller.
69  *
70  * Side effects:
71  *      None.
72  *
73  *----------------------------------------------------------------------
74  */
75
76 const char *
77 TkGetDefaultScreenName(
78     Tcl_Interp *interp,         /* Interp used to find environment
79                                  * variables. */
80     const char *screenName)     /* Screen name from command line, or NULL. */
81 {
82     if ((screenName == NULL) || (screenName[0] == '\0')) {
83         screenName = Tcl_GetVar2(interp, "env", "DISPLAY", TCL_GLOBAL_ONLY);
84     }
85     return screenName;
86 }
87 \f
88 /*
89  *----------------------------------------------------------------------
90  *
91  * Tk_UpdatePointer --
92  *
93  *      Unused function in UNIX
94  *
95  * Results:
96  *      None.
97  *
98  * Side effects:
99  *      None.
100  *
101  *----------------------------------------------------------------------
102  */
103
104 void
105 Tk_UpdatePointer(
106     Tk_Window tkwin,            /* Window to which pointer event is reported.
107                                  * May be NULL. */
108     int x, int y,               /* Pointer location in root coords. */
109     int state)                  /* Modifier state mask. */
110 {
111   /*
112    * This function intentionally left blank
113    */
114 }
115 \f
116 /*
117  *----------------------------------------------------------------------
118  *
119  * TkpBuildRegionFromAlphaData --
120  *
121  *      Set up a rectangle of the given region based on the supplied alpha
122  *      data.
123  *
124  * Results:
125  *      None
126  *
127  * Side effects:
128  *      The region is updated, with extra pixels added to it.
129  *
130  *----------------------------------------------------------------------
131  */
132
133 void
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
143                                  * the next line. */
144 {
145     unsigned char *lineDataPtr;
146     unsigned int x1, y1, end;
147     XRectangle rect;
148
149     for (y1 = 0; y1 < height; y1++) {
150         lineDataPtr = dataPtr;
151         for (x1 = 0; x1 < width; x1 = end) {
152             /*
153              * Search for first non-transparent pixel.
154              */
155
156             while ((x1 < width) && !*lineDataPtr) {
157                 x1++;
158                 lineDataPtr += pixelStride;
159             }
160             end = x1;
161
162             /*
163              * Search for first transparent pixel.
164              */
165
166             while ((end < width) && *lineDataPtr) {
167                 end++;
168                 lineDataPtr += pixelStride;
169             }
170             if (end > x1) {
171                 rect.x = x + x1;
172                 rect.y = y + y1;
173                 rect.width = end - x1;
174                 rect.height = 1;
175                 TkUnionRectWithRegion(&rect, region, region);
176             }
177         }
178         dataPtr += lineStride;
179     }
180 }
181 \f
182 /*
183  *----------------------------------------------------------------------
184  *
185  * Tk_GetUserInactiveTime --
186  *
187  *      Return the number of milliseconds the user was inactive.
188  *
189  * Results:
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
193  *      implementation.
194  *
195  * Side effects:
196  *      None.
197  *----------------------------------------------------------------------
198  */
199
200 long
201 Tk_GetUserInactiveTime(
202  #ifdef HAVE_XSS
203    Display *dpy)                /* The display for which to query the inactive
204                                  * time. */
205 #else
206   TCL_UNUSED(Display *))
207 #endif /* HAVE_XSS */
208 {
209     long inactiveTime = -1;
210 #ifdef HAVE_XSS
211     int eventBase, errorBase, major, minor;
212
213     /*
214      * Calling XScreenSaverQueryVersion seems to be needed to prevent a crash
215      * on some buggy versions of XFree86.
216      */
217
218     if (HaveXSSLibrary()
219             && XScreenSaverQueryExtension(dpy, &eventBase, &errorBase)
220             && XScreenSaverQueryVersion(dpy, &major, &minor)) {
221         XScreenSaverInfo *info = XScreenSaverAllocInfo();
222
223         if (info == NULL) {
224             /*
225              * We are out of memory.
226              */
227
228             Tcl_Panic("Out of memory: XScreenSaverAllocInfo failed in Tk_GetUserInactiveTime");
229         }
230         if (XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info)) {
231             inactiveTime = info->idle;
232         }
233         XFree(info);
234     }
235 #endif /* HAVE_XSS */
236     return inactiveTime;
237 }
238
239 /*
240  *----------------------------------------------------------------------
241  *
242  * Tk_ResetUserInactiveTime --
243  *
244  *      Reset the user inactivity timer
245  *
246  * Results:
247  *      none
248  *
249  * Side effects:
250  *      The user inactivity timer of the underlaying windowing system is reset
251  *      to zero.
252  *
253  *----------------------------------------------------------------------
254  */
255
256 void
257 Tk_ResetUserInactiveTime(
258     Display *dpy)
259 {
260     XResetScreenSaver(dpy);
261 }
262 \f
263 /*
264  * Local Variables:
265  * mode: c
266  * c-basic-offset: 4
267  * fill-column: 78
268  * End:
269  */