#include "fontset.h"
#include "systime.h"
#include "termhooks.h"
+#include "atimer.h"
#ifdef HAVE_X_WINDOWS
Busy cursor
***********************************************************************/
-/* The implementation partly follows a patch from
- F.Pierresteguy@frcl.bull.fr dated 1994. */
+/* If non-null, an asynchronous timer that, when it expires, displays
+ a busy cursor on all frames. */
-/* Setting inhibit_busy_cursor to 2 inhibits busy-cursor display until
- the next X event is read and we enter XTread_socket again. Setting
- it to 1 inhibits busy-cursor display for direct commands. */
+static struct atimer *busy_cursor_atimer;
-int inhibit_busy_cursor;
+/* Non-zero means a busy cursor is currently shown. */
-/* Incremented with each call to x-display-busy-cursor.
- Decremented in x-undisplay-busy-cursor. */
+static int busy_cursor_shown_p;
-static int busy_count;
+/* Number of seconds to wait before displaying a busy cursor. */
+static Lisp_Object Vbusy_cursor_delay;
-DEFUN ("x-show-busy-cursor", Fx_show_busy_cursor,
- Sx_show_busy_cursor, 0, 0, 0,
- "Show a busy cursor, if not already shown.\n\
-Each call to this function must be matched by a call to\n\
-`x-hide-busy-cursor' to make the busy pointer disappear again.")
- ()
+/* Default number of seconds to wait before displaying a busy
+ cursor. */
+
+#define DEFAULT_BUSY_CURSOR_DELAY 1
+
+/* Function prototypes. */
+
+static void show_busy_cursor P_ ((struct atimer *));
+static void hide_busy_cursor P_ ((void));
+
+
+/* Cancel a currently active busy-cursor timer, and start a new one. */
+
+void
+start_busy_cursor ()
{
- ++busy_count;
- if (busy_count == 1)
+ EMACS_TIME delay;
+ int secs;
+
+ cancel_busy_cursor ();
+
+ if (INTEGERP (Vbusy_cursor_delay)
+ && XINT (Vbusy_cursor_delay) > 0)
+ secs = XFASTINT (Vbusy_cursor_delay);
+ else
+ secs = DEFAULT_BUSY_CURSOR_DELAY;
+
+ EMACS_SET_SECS_USECS (delay, secs, 0);
+ busy_cursor_atimer = start_atimer (ATIMER_RELATIVE, delay,
+ show_busy_cursor, NULL);
+}
+
+
+/* Cancel the busy cursor timer if active, hide a busy cursor if
+ shown. */
+
+void
+cancel_busy_cursor ()
+{
+ if (busy_cursor_atimer)
+ cancel_atimer (busy_cursor_atimer);
+ if (busy_cursor_shown_p)
+ hide_busy_cursor ();
+}
+
+
+/* Timer function of busy_cursor_atimer. TIMER is equal to
+ busy_cursor_atimer.
+
+ Display a busy cursor on all frames by mapping the frames'
+ busy_window. Set the busy_p flag in the frames' output_data.x
+ structure to indicate that a busy cursor is shown on the
+ frames. */
+
+static void
+show_busy_cursor (timer)
+ struct atimer *timer;
+{
+ /* The timer implementation will cancel this timer automatically
+ after this function has run. Set busy_cursor_atimer to null
+ so that we know the timer doesn't have to be canceled. */
+ busy_cursor_atimer = NULL;
+
+ if (!busy_cursor_shown_p)
{
Lisp_Object rest, frame;
-
+
+ BLOCK_INPUT;
+
FOR_EACH_FRAME (rest, frame)
if (FRAME_X_P (XFRAME (frame)))
{
struct frame *f = XFRAME (frame);
-
- BLOCK_INPUT;
+
f->output_data.x->busy_p = 1;
-
+
if (!f->output_data.x->busy_window)
{
unsigned long mask = CWCursor;
XSetWindowAttributes attrs;
-
+
attrs.cursor = f->output_data.x->busy_cursor;
-
+
f->output_data.x->busy_window
= XCreateWindow (FRAME_X_DISPLAY (f),
FRAME_OUTER_WINDOW (f),
CopyFromParent,
mask, &attrs);
}
-
+
XMapRaised (FRAME_X_DISPLAY (f), f->output_data.x->busy_window);
- UNBLOCK_INPUT;
+ XFlush (FRAME_X_DISPLAY (f));
}
- }
- return Qnil;
+ busy_cursor_shown_p = 1;
+ UNBLOCK_INPUT;
+ }
}
-DEFUN ("x-hide-busy-cursor", Fx_hide_busy_cursor,
- Sx_hide_busy_cursor, 0, 1, 0,
- "Hide a busy-cursor.\n\
-A busy-cursor will actually be undisplayed when a matching\n\
-`x-hide-busy-cursor' is called for each `x-show-busy-cursor'\n\
-issued. FORCE non-nil means hide the busy-cursor forcibly,\n\
-not counting calls.")
- (force)
- Lisp_Object force;
-{
- Lisp_Object rest, frame;
-
- if (busy_count == 0)
- return Qnil;
-
- if (!NILP (force) && busy_count != 0)
- busy_count = 1;
+/* Hide the busy cursor on all frames, if it is currently shown. */
- --busy_count;
- if (busy_count != 0)
- return Qnil;
-
- FOR_EACH_FRAME (rest, frame)
+static void
+hide_busy_cursor ()
+{
+ if (busy_cursor_shown_p)
{
- struct frame *f = XFRAME (frame);
-
- if (FRAME_X_P (f)
- /* Watch out for newly created frames. */
- && f->output_data.x->busy_window)
+ Lisp_Object rest, frame;
+
+ BLOCK_INPUT;
+ FOR_EACH_FRAME (rest, frame)
{
-
- BLOCK_INPUT;
- XUnmapWindow (FRAME_X_DISPLAY (f), f->output_data.x->busy_window);
- /* Sync here because XTread_socket looks at the busy_p flag
- that is reset to zero below. */
- XSync (FRAME_X_DISPLAY (f), False);
- UNBLOCK_INPUT;
- f->output_data.x->busy_p = 0;
+ struct frame *f = XFRAME (frame);
+
+ if (FRAME_X_P (f)
+ /* Watch out for newly created frames. */
+ && f->output_data.x->busy_window)
+ {
+ XUnmapWindow (FRAME_X_DISPLAY (f), f->output_data.x->busy_window);
+ /* Sync here because XTread_socket looks at the busy_p flag
+ that is reset to zero below. */
+ XSync (FRAME_X_DISPLAY (f), False);
+ f->output_data.x->busy_p = 0;
+ }
}
- }
- return Qnil;
+ busy_cursor_shown_p = 0;
+ UNBLOCK_INPUT;
+ }
}
"Non-zero means Emacs displays a busy cursor on window systems.");
display_busy_cursor_p = 1;
+ DEFVAR_LISP ("busy-cursor-delay", &Vbusy_cursor_delay,
+ "*Seconds to wait before displaying a busy-cursor.\n\
+Value must be an integer.");
+ Vbusy_cursor_delay = make_number (DEFAULT_BUSY_CURSOR_DELAY);
+
#if 0 /* This doesn't really do anything. */
DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape,
"The shape of the pointer when over the mode line.\n\
defsubr (&Slookup_image);
#endif
- /* Busy-cursor. */
- defsubr (&Sx_show_busy_cursor);
- defsubr (&Sx_hide_busy_cursor);
- busy_count = 0;
- inhibit_busy_cursor = 0;
+ busy_cursor_atimer = NULL;
+ busy_cursor_shown_p = 0;
defsubr (&Sx_show_tip);
defsubr (&Sx_hide_tip);