- clicking on the "close" widget of the MacOS display window rings the bell

but doesn't actually close the window to prevent Basilisk II from being
  accidentally killed without a proper shutdown of MacOS
- replaced many #ifdef HAVE_PTHREADS constructs with LOCK/UNLOCK macros
- minor cleanups
This commit is contained in:
cebix 2000-11-03 18:21:43 +00:00
parent 3e6bb33b15
commit 3a777718bd
2 changed files with 160 additions and 205 deletions

View File

@ -249,14 +249,10 @@ static inline void do_handle_screen_fault(uintptr addr)
const int page = (addr - mainBuffer.memStart) >> mainBuffer.pageBits; const int page = (addr - mainBuffer.memStart) >> mainBuffer.pageBits;
caddr_t page_ad = (caddr_t)(addr & ~(mainBuffer.pageSize - 1)); caddr_t page_ad = (caddr_t)(addr & ~(mainBuffer.pageSize - 1));
#ifdef HAVE_PTHREADS LOCK_VOSF;
pthread_mutex_lock(&Screen_draw_lock);
#endif
PFLAG_SET(page); PFLAG_SET(page);
mprotect(page_ad, mainBuffer.pageSize, PROT_READ | PROT_WRITE); mprotect(page_ad, mainBuffer.pageSize, PROT_READ | PROT_WRITE);
#ifdef HAVE_PTHREADS UNLOCK_VOSF;
pthread_mutex_unlock(&Screen_draw_lock);
#endif
} }
#if defined(HAVE_SIGINFO_T) #if defined(HAVE_SIGINFO_T)

View File

@ -122,13 +122,19 @@ static Colormap cmap[2]; // Two colormaps (DGA) for 8-bit mode
static XColor black, white; static XColor black, white;
static unsigned long black_pixel, white_pixel; static unsigned long black_pixel, white_pixel;
static int eventmask; static int eventmask;
static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | FocusChangeMask | ExposureMask; static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask;
static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask;
static Atom WM_DELETE_WINDOW = (Atom)0;
static XColor palette[256]; // Color palette for 8-bit mode static XColor palette[256]; // Color palette for 8-bit mode
static bool palette_changed = false; // Flag: Palette changed, redraw thread must set new colors static bool palette_changed = false; // Flag: Palette changed, redraw thread must set new colors
#ifdef HAVE_PTHREADS #ifdef HAVE_PTHREADS
static pthread_mutex_t palette_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect palette static pthread_mutex_t palette_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect palette
#define LOCK_PALETTE pthread_mutex_lock(&palette_lock)
#define UNLOCK_PALETTE pthread_mutex_unlock(&palette_lock)
#else
#define LOCK_PALETTE
#define UNLOCK_PALETTE
#endif #endif
// Variables for window mode // Variables for window mode
@ -149,6 +155,11 @@ static Window suspend_win; // "Suspend" window
static void *fb_save = NULL; // Saved frame buffer for suspend static void *fb_save = NULL; // Saved frame buffer for suspend
#ifdef HAVE_PTHREADS #ifdef HAVE_PTHREADS
static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer
#define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock);
#define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock);
#else
#define LOCK_FRAME_BUFFER
#define UNLOCK_FRAME_BUFFER
#endif #endif
// Variables for fbdev DGA mode // Variables for fbdev DGA mode
@ -167,13 +178,11 @@ static bool use_vosf = true; // Flag: VOSF enabled
static const bool use_vosf = false; // Flag: VOSF enabled static const bool use_vosf = false; // Flag: VOSF enabled
#endif #endif
#ifdef ENABLE_VOSF
static uint8 * the_host_buffer; // Host frame buffer in VOSF mode
static uint32 the_buffer_size; // Size of allocated the_buffer
#endif
#ifdef ENABLE_VOSF #ifdef ENABLE_VOSF
// Variables for Video on SEGV support (taken from the Win32 port) // Variables for Video on SEGV support (taken from the Win32 port)
static uint8 *the_host_buffer; // Host frame buffer in VOSF mode
static uint32 the_buffer_size; // Size of allocated the_buffer
struct ScreenPageInfo { struct ScreenPageInfo {
int top, bottom; // Mapping between this virtual page and Mac scanlines int top, bottom; // Mapping between this virtual page and Mac scanlines
}; };
@ -215,7 +224,12 @@ static bool Screen_fault_handler_init();
static struct sigaction vosf_sa; static struct sigaction vosf_sa;
#ifdef HAVE_PTHREADS #ifdef HAVE_PTHREADS
static pthread_mutex_t Screen_draw_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact)
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock);
#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock);
#else
#define LOCK_VOSF
#define UNLOCK_VOSF
#endif #endif
static int log_base_2(uint32 x) static int log_base_2(uint32 x)
@ -237,7 +251,7 @@ static void (*video_refresh)(void);
// Prototypes // Prototypes
static void *redraw_func(void *arg); static void *redraw_func(void *arg);
static int event2keycode(XKeyEvent *ev); static int event2keycode(XKeyEvent &ev);
// From main_unix.cpp // From main_unix.cpp
@ -307,6 +321,60 @@ void set_video_monitor(int width, int height, int bytes_per_row, bool native_byt
VideoMonitor.bytes_per_row = bytes_per_row; VideoMonitor.bytes_per_row = bytes_per_row;
} }
// Set window name and class
static void set_window_name(Window w, int name)
{
const char *str = GetString(name);
XStoreName(x_display, w, str);
XSetIconName(x_display, w, str);
XClassHint *hints;
hints = XAllocClassHint();
if (hints) {
hints->res_name = "BasiliskII";
hints->res_class = "BasiliskII";
XSetClassHint(x_display, w, hints);
XFree((char *)hints);
}
}
// Set window input focus flag
static void set_window_focus(Window w)
{
XWMHints *hints = XAllocWMHints();
if (hints) {
hints->input = True;
hints->initial_state = NormalState;
hints->flags = InputHint | StateHint;
XSetWMHints(x_display, w, hints);
XFree((char *)hints);
}
}
// Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget)
static void set_window_delete_protocol(Window w)
{
WM_DELETE_WINDOW = XInternAtom(x_display, "WM_DELETE_WINDOW", false);
XSetWMProtocols(x_display, w, &WM_DELETE_WINDOW, 1);
}
// Wait until window is mapped/unmapped
void wait_mapped(Window w)
{
XEvent e;
do {
XMaskEvent(x_display, StructureNotifyMask, &e);
} while ((e.type != MapNotify) || (e.xmap.event != w));
}
void wait_unmapped(Window w)
{
XEvent e;
do {
XMaskEvent(x_display, StructureNotifyMask, &e);
} while ((e.type != UnmapNotify) || (e.xmap.event != w));
}
// Trap SHM errors // Trap SHM errors
static bool shm_error = false; static bool shm_error = false;
static int (*old_error_handler)(Display *, XErrorEvent *); static int (*old_error_handler)(Display *, XErrorEvent *);
@ -336,21 +404,19 @@ static bool init_window(int width, int height)
XSetWindowAttributes wattr; XSetWindowAttributes wattr;
wattr.event_mask = eventmask = win_eventmask; wattr.event_mask = eventmask = win_eventmask;
wattr.background_pixel = black_pixel; wattr.background_pixel = black_pixel;
wattr.colormap = cmap[0];
XSync(x_display, false);
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
InputOutput, vis, CWEventMask | CWBackPixel, &wattr); InputOutput, vis, CWEventMask | CWBackPixel | (depth == 8 ? CWColormap : 0), &wattr);
// Set window name/class
set_window_name(the_win, STR_WINDOW_TITLE);
// Indicate that we want keyboard input // Indicate that we want keyboard input
{ set_window_focus(the_win);
XWMHints *hints = XAllocWMHints();
if (hints) { // Set delete protocol property
hints->input = True; set_window_delete_protocol(the_win);
hints->flags = InputHint;
XSetWMHints(x_display, the_win, hints);
XFree((char *)hints);
}
}
// Make window unresizable // Make window unresizable
{ {
@ -366,29 +432,9 @@ static bool init_window(int width, int height)
} }
} }
// Set window title
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE));
// Set window class
{
XClassHint *hints;
hints = XAllocClassHint();
if (hints) {
hints->res_name = "BasiliskII";
hints->res_class = "BasiliskII";
XSetClassHint(x_display, the_win, hints);
XFree((char *)hints);
}
}
// Show window // Show window
XSync(x_display, false); XMapWindow(x_display, the_win);
XMapRaised(x_display, the_win); wait_mapped(the_win);
XFlush(x_display);
// Set colormap
if (depth == 8)
XSetWindowColormap(x_display, the_win, cmap[0]);
// Try to create and attach SHM image // Try to create and attach SHM image
have_shm = false; have_shm = false;
@ -561,19 +607,26 @@ static bool init_fbdev_dga(char *in_fb_name)
// Create window // Create window
XSetWindowAttributes wattr; XSetWindowAttributes wattr;
wattr.event_mask = eventmask = dga_eventmask; wattr.event_mask = eventmask = dga_eventmask;
wattr.background_pixel = white_pixel; wattr.background_pixel = white_pixel;
wattr.override_redirect = True; wattr.override_redirect = True;
wattr.colormap = cmap[0];
XSync(x_display, false);
the_win = XCreateWindow(x_display, rootwin, the_win = XCreateWindow(x_display, rootwin,
0, 0, width, height, 0, 0, width, height,
0, xdepth, InputOutput, vis, 0, xdepth, InputOutput, vis,
CWEventMask | CWBackPixel | CWOverrideRedirect, CWEventMask | CWBackPixel | CWOverrideRedirect | (depth == 8 ? CWColormap : 0),
&wattr); &wattr);
XSync(x_display, false);
// Set window name/class
set_window_name(the_win, STR_WINDOW_TITLE);
// Indicate that we want keyboard input
set_window_focus(the_win);
// Show window
XMapRaised(x_display, the_win); XMapRaised(x_display, the_win);
XSync(x_display, false); wait_mapped(the_win);
// Grab mouse and keyboard // Grab mouse and keyboard
XGrabKeyboard(x_display, the_win, True, XGrabKeyboard(x_display, the_win, True,
@ -582,10 +635,6 @@ static bool init_fbdev_dga(char *in_fb_name)
PointerMotionMask | ButtonPressMask | ButtonReleaseMask, PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime); GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime);
// Set colormap
if (depth == 8)
XSetWindowColormap(x_display, the_win, cmap[0]);
// Set VideoMonitor // Set VideoMonitor
int bytes_per_row = width; int bytes_per_row = width;
switch (depth) { switch (depth) {
@ -665,6 +714,7 @@ static bool init_xf86_dga(int width, int height)
} }
XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]); XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]);
XF86VidModeSetViewPort(x_display, screen, 0, 0); XF86VidModeSetViewPort(x_display, screen, 0, 0);
XSync(x_display, false);
} }
#endif #endif
@ -673,13 +723,18 @@ static bool init_xf86_dga(int width, int height)
wattr.event_mask = eventmask = dga_eventmask; wattr.event_mask = eventmask = dga_eventmask;
wattr.override_redirect = True; wattr.override_redirect = True;
XSync(x_display, false);
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr); InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr);
XSync(x_display, false);
XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); // Set window name/class
set_window_name(the_win, STR_WINDOW_TITLE);
// Indicate that we want keyboard input
set_window_focus(the_win);
// Show window
XMapRaised(x_display, the_win); XMapRaised(x_display, the_win);
XSync(x_display, false); wait_mapped(the_win);
// Establish direct screen connection // Establish direct screen connection
XMoveResizeWindow(x_display, the_win, 0, 0, width, height); XMoveResizeWindow(x_display, the_win, 0, 0, width, height);
@ -698,6 +753,7 @@ static bool init_xf86_dga(int width, int height)
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]);
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
} }
XSync(x_display, false);
// Set VideoMonitor // Set VideoMonitor
int bytes_per_row = (v_width + 7) & ~7; int bytes_per_row = (v_width + 7) & ~7;
@ -1036,10 +1092,8 @@ bool VideoInit(bool classic)
break; break;
} }
#ifdef HAVE_PTHREADS
// Lock down frame buffer // Lock down frame buffer
pthread_mutex_lock(&frame_buffer_lock); LOCK_FRAME_BUFFER;
#endif
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING #if !REAL_ADDRESSING && !DIRECT_ADDRESSING
// Set variables for UAE memory mapping // Set variables for UAE memory mapping
@ -1104,10 +1158,8 @@ void VideoExit(void)
} }
#endif #endif
#ifdef HAVE_PTHREADS
// Unlock frame buffer // Unlock frame buffer
pthread_mutex_unlock(&frame_buffer_lock); UNLOCK_FRAME_BUFFER;
#endif
// Close window and server connection // Close window and server connection
if (x_display != NULL) { if (x_display != NULL) {
@ -1210,12 +1262,10 @@ void VideoInterrupt(void)
if (emerg_quit) if (emerg_quit)
QuitEmulator(); QuitEmulator();
#ifdef HAVE_PTHREADS
// Temporarily give up frame buffer lock (this is the point where // Temporarily give up frame buffer lock (this is the point where
// we are suspended when the user presses Ctrl-Tab) // we are suspended when the user presses Ctrl-Tab)
pthread_mutex_unlock(&frame_buffer_lock); UNLOCK_FRAME_BUFFER;
pthread_mutex_lock(&frame_buffer_lock); LOCK_FRAME_BUFFER;
#endif
} }
@ -1225,9 +1275,7 @@ void VideoInterrupt(void)
void video_set_palette(uint8 *pal) void video_set_palette(uint8 *pal)
{ {
#ifdef HAVE_PTHREADS LOCK_PALETTE;
pthread_mutex_lock(&palette_lock);
#endif
// Convert colors to XColor array // Convert colors to XColor array
for (int i=0; i<256; i++) { for (int i=0; i<256; i++) {
@ -1241,9 +1289,7 @@ void video_set_palette(uint8 *pal)
// Tell redraw thread to change palette // Tell redraw thread to change palette
palette_changed = true; palette_changed = true;
#ifdef HAVE_PTHREADS UNLOCK_PALETTE;
pthread_mutex_unlock(&palette_lock);
#endif
} }
@ -1259,10 +1305,8 @@ static void suspend_emul(void)
ADBKeyUp(0x36); ADBKeyUp(0x36);
ctrl_down = false; ctrl_down = false;
#ifdef HAVE_PTHREADS
// Lock frame buffer (this will stop the MacOS thread) // Lock frame buffer (this will stop the MacOS thread)
pthread_mutex_lock(&frame_buffer_lock); LOCK_FRAME_BUFFER;
#endif
// Save frame buffer // Save frame buffer
fb_save = malloc(VideoMonitor.y * VideoMonitor.bytes_per_row); fb_save = malloc(VideoMonitor.y * VideoMonitor.bytes_per_row);
@ -1276,24 +1320,18 @@ static void suspend_emul(void)
XUngrabPointer(x_display, CurrentTime); XUngrabPointer(x_display, CurrentTime);
XUngrabKeyboard(x_display, CurrentTime); XUngrabKeyboard(x_display, CurrentTime);
XUnmapWindow(x_display, the_win); XUnmapWindow(x_display, the_win);
XSync(x_display, false); wait_unmapped(the_win);
// Open "suspend" window // Open "suspend" window
XSetWindowAttributes wattr; XSetWindowAttributes wattr;
wattr.event_mask = KeyPressMask; wattr.event_mask = KeyPressMask;
wattr.background_pixel = black_pixel; wattr.background_pixel = black_pixel;
wattr.backing_store = WhenMapped;
wattr.backing_planes = xdepth;
wattr.colormap = DefaultColormap(x_display, screen);
XSync(x_display, false);
suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth, suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth,
InputOutput, vis, CWEventMask | CWBackPixel | CWBackingStore | InputOutput, vis, CWEventMask | CWBackPixel, &wattr);
CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr); set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE);
XSync(x_display, false); set_window_focus(suspend_win);
XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE)); XMapWindow(x_display, suspend_win);
XMapRaised(x_display, suspend_win);
XSync(x_display, false);
emul_suspended = true; emul_suspended = true;
} }
} }
@ -1306,8 +1344,8 @@ static void resume_emul(void)
// Reopen full screen display // Reopen full screen display
XMapRaised(x_display, the_win); XMapRaised(x_display, the_win);
wait_mapped(the_win);
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0);
XSync(x_display, false);
XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime);
XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
#ifdef ENABLE_XF86_DGA #ifdef ENABLE_XF86_DGA
@ -1321,13 +1359,9 @@ static void resume_emul(void)
// not necessary. // not necessary.
#ifdef ENABLE_VOSF #ifdef ENABLE_VOSF
if (use_vosf) { if (use_vosf) {
#ifdef HAVE_PTHREADS LOCK_VOSF;
pthread_mutex_lock(&Screen_draw_lock);
#endif
PFLAG_SET_ALL; PFLAG_SET_ALL;
#ifdef HAVE_PTHREADS UNLOCK_VOSF;
pthread_mutex_unlock(&Screen_draw_lock);
#endif
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
} }
#endif #endif
@ -1348,11 +1382,9 @@ static void resume_emul(void)
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
#endif #endif
#ifdef HAVE_PTHREADS
// Unlock frame buffer (and continue MacOS thread) // Unlock frame buffer (and continue MacOS thread)
pthread_mutex_unlock(&frame_buffer_lock); UNLOCK_FRAME_BUFFER;
emul_suspended = false; emul_suspended = false;
#endif
} }
#endif #endif
@ -1506,14 +1538,14 @@ static int kc_decode(KeySym ks)
return -1; return -1;
} }
static int event2keycode(XKeyEvent *ev) static int event2keycode(XKeyEvent &ev)
{ {
KeySym ks; KeySym ks;
int as; int as;
int i = 0; int i = 0;
do { do {
ks = XLookupKeysym(ev, i++); ks = XLookupKeysym(&ev, i++);
as = kc_decode(ks); as = kc_decode(ks);
if (as != -1) if (as != -1)
return as; return as;
@ -1529,15 +1561,14 @@ static int event2keycode(XKeyEvent *ev)
static void handle_events(void) static void handle_events(void)
{ {
XEvent event; while (XPending(x_display)) {
for (;;) { XEvent event;
if (!XCheckMaskEvent(x_display, eventmask, &event)) XNextEvent(x_display, &event);
break;
switch (event.type) { switch (event.type) {
// Mouse button // Mouse button
case ButtonPress: { case ButtonPress: {
unsigned int button = ((XButtonEvent *)&event)->button; unsigned int button = event.xbutton.button;
if (button < 4) if (button < 4)
ADBMouseDown(button - 1); ADBMouseDown(button - 1);
else if (button < 6) { // Wheel mouse else if (button < 6) { // Wheel mouse
@ -1556,7 +1587,7 @@ static void handle_events(void)
break; break;
} }
case ButtonRelease: { case ButtonRelease: {
unsigned int button = ((XButtonEvent *)&event)->button; unsigned int button = event.xbutton.button;
if (button < 4) if (button < 4)
ADBMouseUp(button - 1); ADBMouseUp(button - 1);
break; break;
@ -1564,20 +1595,18 @@ static void handle_events(void)
// Mouse moved // Mouse moved
case EnterNotify: case EnterNotify:
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y);
break;
case MotionNotify: case MotionNotify:
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); ADBMouseMoved(event.xmotion.x, event.xmotion.y);
break; break;
// Keyboard // Keyboard
case KeyPress: { case KeyPress: {
int code; int code;
if (use_keycodes) { if (use_keycodes) {
event2keycode((XKeyEvent *)&event); // This is called to process the hotkeys event2keycode(event.xkey); // This is called to process the hotkeys
code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff]; code = keycode_table[event.xkey.keycode & 0xff];
} else } else
code = event2keycode((XKeyEvent *)&event); code = event2keycode(event.xkey);
if (code != -1) { if (code != -1) {
if (!emul_suspended) { if (!emul_suspended) {
if (code == 0x39) { // Caps Lock pressed if (code == 0x39) { // Caps Lock pressed
@ -1604,10 +1633,10 @@ static void handle_events(void)
case KeyRelease: { case KeyRelease: {
int code; int code;
if (use_keycodes) { if (use_keycodes) {
event2keycode((XKeyEvent *)&event); // This is called to process the hotkeys event2keycode(event.xkey); // This is called to process the hotkeys
code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff]; code = keycode_table[event.xkey.keycode & 0xff];
} else } else
code = event2keycode((XKeyEvent *)&event); code = event2keycode(event.xkey);
if (code != -1 && code != 0x39) { // Don't propagate Caps Lock releases if (code != -1 && code != 0x39) { // Don't propagate Caps Lock releases
ADBKeyUp(code); ADBKeyUp(code);
if (code == 0x36) if (code == 0x36)
@ -1621,13 +1650,9 @@ static void handle_events(void)
if (display_type == DISPLAY_WINDOW) { if (display_type == DISPLAY_WINDOW) {
#ifdef ENABLE_VOSF #ifdef ENABLE_VOSF
if (use_vosf) { // VOSF refresh if (use_vosf) { // VOSF refresh
#ifdef HAVE_PTHREADS LOCK_VOSF;
pthread_mutex_lock(&Screen_draw_lock);
#endif
PFLAG_SET_ALL; PFLAG_SET_ALL;
#ifdef HAVE_PTHREADS UNLOCK_VOSF;
pthread_mutex_unlock(&Screen_draw_lock);
#endif
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
} }
else else
@ -1643,8 +1668,10 @@ static void handle_events(void)
} }
break; break;
case FocusIn: // Window "close" widget clicked
case FocusOut: case ClientMessage:
if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW)
XBell(x_display, 0);
break; break;
} }
} }
@ -1902,14 +1929,14 @@ static inline void possibly_quit_dga_mode()
static inline void handle_palette_changes(int depth, int display_type) static inline void handle_palette_changes(int depth, int display_type)
{ {
#ifdef HAVE_PTHREADS LOCK_PALETTE;
pthread_mutex_lock(&palette_lock);
#endif
if (palette_changed) { if (palette_changed) {
palette_changed = false; palette_changed = false;
if (depth == 8) { if (depth == 8) {
XStoreColors(x_display, cmap[0], palette, 256); XStoreColors(x_display, cmap[0], palette, 256);
XStoreColors(x_display, cmap[1], palette, 256); XStoreColors(x_display, cmap[1], palette, 256);
XSync(x_display, false);
#ifdef ENABLE_XF86_DGA #ifdef ENABLE_XF86_DGA
if (display_type == DISPLAY_DGA) { if (display_type == DISPLAY_DGA) {
@ -1919,9 +1946,8 @@ static inline void handle_palette_changes(int depth, int display_type)
#endif #endif
} }
} }
#ifdef HAVE_PTHREADS
pthread_mutex_unlock(&palette_lock); UNLOCK_PALETTE;
#endif
} }
static void video_refresh_dga(void) static void video_refresh_dga(void)
@ -1953,13 +1979,9 @@ static void video_refresh_dga_vosf(void)
static int tick_counter = 0; static int tick_counter = 0;
if (++tick_counter >= frame_skip) { if (++tick_counter >= frame_skip) {
tick_counter = 0; tick_counter = 0;
#ifdef HAVE_PTHREADS LOCK_VOSF;
pthread_mutex_lock(&Screen_draw_lock);
#endif
update_display_dga_vosf(); update_display_dga_vosf();
#ifdef HAVE_PTHREADS UNLOCK_VOSF;
pthread_mutex_unlock(&Screen_draw_lock);
#endif
} }
} }
#endif #endif
@ -1979,13 +2001,9 @@ static void video_refresh_window_vosf(void)
static int tick_counter = 0; static int tick_counter = 0;
if (++tick_counter >= frame_skip) { if (++tick_counter >= frame_skip) {
tick_counter = 0; tick_counter = 0;
#ifdef HAVE_PTHREADS LOCK_VOSF;
pthread_mutex_lock(&Screen_draw_lock);
#endif
update_display_window_vosf(); update_display_window_vosf();
#ifdef HAVE_PTHREADS UNLOCK_VOSF;
pthread_mutex_unlock(&Screen_draw_lock);
#endif
} }
} }
#endif // def ENABLE_VOSF #endif // def ENABLE_VOSF
@ -2055,64 +2073,6 @@ void VideoRefresh(void)
video_refresh(); video_refresh();
} }
#if 0
void VideoRefresh(void)
{
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA)
// Quit DGA mode if requested
if (quit_full_screen) {
quit_full_screen = false;
if (display_type == DISPLAY_DGA) {
#ifdef ENABLE_XF86_DGA
XF86DGADirectVideo(x_display, screen, 0);
#endif
XUngrabPointer(x_display, CurrentTime);
XUngrabKeyboard(x_display, CurrentTime);
XUnmapWindow(x_display, the_win);
XSync(x_display, false);
}
}
#endif
// Handle X events
handle_events();
// Handle palette changes
#ifdef HAVE_PTHREADS
pthread_mutex_lock(&palette_lock);
#endif
if (palette_changed) {
palette_changed = false;
if (depth == 8) {
XStoreColors(x_display, cmap[0], palette, 256);
XStoreColors(x_display, cmap[1], palette, 256);
#ifdef ENABLE_XF86_DGA
if (display_type == DISPLAY_DGA) {
current_dga_cmap ^= 1;
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
}
#endif
}
}
#ifdef HAVE_PTHREADS
pthread_mutex_unlock(&palette_lock);
#endif
// In window mode, update display
static int tick_counter = 0;
if (display_type == DISPLAY_WINDOW) {
tick_counter++;
if (frame_skip == 0)
update_display_dynamic(tick_counter);
else if (tick_counter >= frame_skip) {
tick_counter = 0;
update_display_static();
}
}
}
#endif
#ifdef HAVE_PTHREADS #ifdef HAVE_PTHREADS
static void *redraw_func(void *arg) static void *redraw_func(void *arg)
{ {
@ -2120,7 +2080,6 @@ static void *redraw_func(void *arg)
int64 ticks = 0; int64 ticks = 0;
uint64 next = GetTicks_usec(); uint64 next = GetTicks_usec();
while (!redraw_thread_cancel) { while (!redraw_thread_cancel) {
// VideoRefresh();
video_refresh(); video_refresh();
next += 16667; next += 16667;
int64 delay = next - GetTicks_usec(); int64 delay = next - GetTicks_usec();