summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixEvent.c
diff options
context:
space:
mode:
authorstanton <stanton>1999-04-16 01:51:06 (GMT)
committerstanton <stanton>1999-04-16 01:51:06 (GMT)
commit03656f44f81469f459031fa3a4a7b09c8bc77712 (patch)
tree31378e81bd58f8c726fc552d6b30cbf3ca07497b /unix/tkUnixEvent.c
parent404fc236f34304df53b7e44bc7971d786b87d453 (diff)
downloadtk-03656f44f81469f459031fa3a4a7b09c8bc77712.zip
tk-03656f44f81469f459031fa3a4a7b09c8bc77712.tar.gz
tk-03656f44f81469f459031fa3a4a7b09c8bc77712.tar.bz2
* Merged 8.1 branch into the main trunk
Diffstat (limited to 'unix/tkUnixEvent.c')
-rw-r--r--unix/tkUnixEvent.c112
1 files changed, 67 insertions, 45 deletions
diff --git a/unix/tkUnixEvent.c b/unix/tkUnixEvent.c
index 12e58f4..4353154 100644
--- a/unix/tkUnixEvent.c
+++ b/unix/tkUnixEvent.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkUnixEvent.c,v 1.2 1998/09/14 18:23:56 stanton Exp $
+ * RCS: @(#) $Id: tkUnixEvent.c,v 1.3 1999/04/16 01:51:46 stanton Exp $
*/
#include "tkInt.h"
@@ -17,10 +17,14 @@
#include <signal.h>
/*
- * The following static indicates whether this module has been initialized.
+ * The following static indicates whether this module has been initialized
+ * in the current thread.
*/
-static int initialized = 0;
+typedef struct ThreadSpecificData {
+ int initialized;
+} ThreadSpecificData;
+static Tcl_ThreadDataKey dataKey;
/*
* Prototypes for procedures that are referenced only in this file:
@@ -34,6 +38,8 @@ static void DisplayFileProc _ANSI_ARGS_((ClientData clientData,
int flags));
static void DisplaySetupProc _ANSI_ARGS_((ClientData clientData,
int flags));
+static void TransferXEventsToTcl _ANSI_ARGS_((Display *display));
+
/*
*----------------------------------------------------------------------
@@ -55,8 +61,11 @@ static void DisplaySetupProc _ANSI_ARGS_((ClientData clientData,
void
TkCreateXEventSource()
{
- if (!initialized) {
- initialized = 1;
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+
+ if (!tsdPtr->initialized) {
+ tsdPtr->initialized = 1;
Tcl_CreateEventSource(DisplaySetupProc, DisplayCheckProc, NULL);
Tcl_CreateExitHandler(DisplayExitHandler, NULL);
}
@@ -83,8 +92,11 @@ static void
DisplayExitHandler(clientData)
ClientData clientData; /* Not used. */
{
+ ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
+
Tcl_DeleteEventSource(DisplaySetupProc, DisplayCheckProc, NULL);
- initialized = 0;
+ tsdPtr->initialized = 0;
}
/*
@@ -185,7 +197,7 @@ DisplaySetupProc(clientData, flags)
return;
}
- for (dispPtr = tkDisplayList; dispPtr != NULL;
+ for (dispPtr = TkGetDisplayList(); dispPtr != NULL;
dispPtr = dispPtr->nextPtr) {
/*
@@ -196,7 +208,7 @@ DisplaySetupProc(clientData, flags)
*/
XFlush(dispPtr->display);
- if (XQLength(dispPtr->display) > 0) {
+ if (QLength(dispPtr->display) > 0) {
Tcl_SetMaxBlockTime(&blockTime);
}
}
@@ -205,6 +217,43 @@ DisplaySetupProc(clientData, flags)
/*
*----------------------------------------------------------------------
*
+ * TransferXEventsToTcl
+ *
+ * Transfer events from the X event queue to the Tk event queue.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Moves queued X events onto the Tcl event queue.
+ *
+ *----------------------------------------------------------------------
+ */
+
+
+static void
+TransferXEventsToTcl(display)
+ Display *display;
+{
+ int numFound;
+ XEvent event;
+
+ numFound = QLength(display);
+
+ /*
+ * Transfer events from the X event queue to the Tk event queue.
+ */
+
+ while (numFound > 0) {
+ XNextEvent(display, &event);
+ Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
+ numFound--;
+ }
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* DisplayCheckProc --
*
* This procedure checks for events sitting in the X event
@@ -225,29 +274,19 @@ DisplayCheckProc(clientData, flags)
int flags;
{
TkDisplay *dispPtr;
- XEvent event;
- int numFound;
if (!(flags & TCL_WINDOW_EVENTS)) {
return;
}
- for (dispPtr = tkDisplayList; dispPtr != NULL;
+ for (dispPtr = TkGetDisplayList(); dispPtr != NULL;
dispPtr = dispPtr->nextPtr) {
XFlush(dispPtr->display);
- numFound = XQLength(dispPtr->display);
-
- /*
- * Transfer events from the X event queue to the Tk event queue.
- */
-
- while (numFound > 0) {
- XNextEvent(dispPtr->display, &event);
- Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
- numFound--;
- }
+ TransferXEventsToTcl(dispPtr->display);
}
}
+
+
/*
*----------------------------------------------------------------------
@@ -273,7 +312,6 @@ DisplayFileProc(clientData, flags)
{
TkDisplay *dispPtr = (TkDisplay *) clientData;
Display *display = dispPtr->display;
- XEvent event;
int numFound;
XFlush(display);
@@ -311,15 +349,7 @@ DisplayFileProc(clientData, flags)
(void) signal(SIGPIPE, oldHandler);
}
- /*
- * Transfer events from the X event queue to the Tk event queue.
- */
-
- while (numFound > 0) {
- XNextEvent(display, &event);
- Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
- numFound--;
- }
+ TransferXEventsToTcl(display);
}
/*
@@ -394,10 +424,10 @@ TkUnixDoOneXEvent(timePtr)
*/
memset((VOID *) readMask, 0, MASK_SIZE*sizeof(fd_mask));
- for (dispPtr = tkDisplayList; dispPtr != NULL;
+ for (dispPtr = TkGetDisplayList(); dispPtr != NULL;
dispPtr = dispPtr->nextPtr) {
XFlush(dispPtr->display);
- if (XQLength(dispPtr->display) > 0) {
+ if (QLength(dispPtr->display) > 0) {
blockTime.tv_sec = 0;
blockTime.tv_usec = 0;
}
@@ -425,12 +455,12 @@ TkUnixDoOneXEvent(timePtr)
* Process any new events on the display connections.
*/
- for (dispPtr = tkDisplayList; dispPtr != NULL;
+ for (dispPtr = TkGetDisplayList(); dispPtr != NULL;
dispPtr = dispPtr->nextPtr) {
fd = ConnectionNumber(dispPtr->display);
index = fd/(NBBY*sizeof(fd_mask));
bit = 1 << (fd%(NBBY*sizeof(fd_mask)));
- if ((readMask[index] & bit) || (XQLength(dispPtr->display) > 0)) {
+ if ((readMask[index] & bit) || (QLength(dispPtr->display) > 0)) {
DisplayFileProc((ClientData)dispPtr, TCL_READABLE);
}
}
@@ -480,19 +510,11 @@ void
TkpSync(display)
Display *display; /* Display to sync. */
{
- int numFound = 0;
- XEvent event;
-
XSync(display, False);
/*
* Transfer events from the X event queue to the Tk event queue.
*/
+ TransferXEventsToTcl(display);
- numFound = XQLength(display);
- while (numFound > 0) {
- XNextEvent(display, &event);
- Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
- numFound--;
- }
}