#include <config.h>
#include <stdio.h>
#include "lisp.h"
+#include "frame.h"
#include "blockinput.h"
#include "w32term.h"
#include "windowsx.h"
CRITICAL_SECTION critsect;
extern HANDLE keyboard_handle;
-HANDLE hEvent = NULL;
+HANDLE input_available = NULL;
void
init_crit ()
{
InitializeCriticalSection (&critsect);
- keyboard_handle = hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
-}
-void
-enter_crit ()
-{
- EnterCriticalSection (&critsect);
+ /* For safety, input_available should only be reset by get_next_msg
+ when the input queue is empty, so make it a manual reset event. */
+ keyboard_handle = input_available = CreateEvent (NULL, TRUE, FALSE, NULL);
}
void
-leave_crit ()
+delete_crit ()
{
- LeaveCriticalSection (&critsect);
+ DeleteCriticalSection (&critsect);
+
+ if (input_available)
+ {
+ CloseHandle (input_available);
+ input_available = NULL;
+ }
}
-void
-delete_crit ()
+void
+select_palette (FRAME_PTR f, HDC hdc)
{
- DeleteCriticalSection (&critsect);
- if (hEvent)
+ if (!NILP (Vwin32_enable_palette))
+ f->output_data.win32->old_palette =
+ SelectPalette (hdc, one_win32_display_info.palette, FALSE);
+ else
+ f->output_data.win32->old_palette = NULL;
+
+ if (RealizePalette (hdc))
+ {
+ Lisp_Object frame, framelist;
+ FOR_EACH_FRAME (framelist, frame)
{
- CloseHandle (hEvent);
- hEvent = NULL;
+ SET_FRAME_GARBAGED (XFRAME (frame));
}
+ }
+}
+
+void
+deselect_palette (FRAME_PTR f, HDC hdc)
+{
+ if (f->output_data.win32->old_palette)
+ SelectPalette (hdc, f->output_data.win32->old_palette, FALSE);
+}
+
+/* Get a DC for frame and select palette for drawing; force an update of
+ all frames if palette's mapping changes. */
+HDC
+get_frame_dc (FRAME_PTR f)
+{
+ HDC hdc;
+
+ enter_crit ();
+
+ hdc = GetDC (f->output_data.win32->window_desc);
+ select_palette (f, hdc);
+
+ return hdc;
+}
+
+int
+release_frame_dc (FRAME_PTR f, HDC hdc)
+{
+ int ret;
+
+ deselect_palette (f, hdc);
+ ret = ReleaseDC (f->output_data.win32->window_desc, hdc);
+
+ leave_crit ();
+
+ return ret;
}
typedef struct int_msg
while (!nQueue && bWait)
{
leave_crit ();
- WaitForSingleObject (hEvent, INFINITE);
+ WaitForSingleObject (input_available, INFINITE);
enter_crit ();
}
bRet = TRUE;
}
+
+ if (nQueue == 0)
+ ResetEvent (input_available);
leave_crit ();
{
int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
- if (!lpNew) return (FALSE);
+ if (!lpNew)
+ return (FALSE);
bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
lpNew->lpNext = NULL;
else
{
lpHead = lpNew;
- SetEvent (hEvent);
}
lpTail = lpNew;
+ SetEvent (input_available);
leave_crit ();