ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_x.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/video_x.cpp (file contents):
Revision 1.27 by cebix, 2000-11-02T14:45:16Z vs.
Revision 1.31 by cebix, 2000-11-30T16:09:03Z

# Line 122 | Line 122 | static Colormap cmap[2];                                                       // Two co
122   static XColor black, white;
123   static unsigned long black_pixel, white_pixel;
124   static int eventmask;
125 < static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | FocusChangeMask | ExposureMask;
126 < static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
125 > static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask | StructureNotifyMask;
126 > static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask;
127 > static Atom WM_DELETE_WINDOW = (Atom)0;
128  
129   static XColor palette[256];                                                     // Color palette for 8-bit mode
130   static bool palette_changed = false;                            // Flag: Palette changed, redraw thread must set new colors
131   #ifdef HAVE_PTHREADS
132   static pthread_mutex_t palette_lock = PTHREAD_MUTEX_INITIALIZER;        // Mutex to protect palette
133 + #define LOCK_PALETTE pthread_mutex_lock(&palette_lock)
134 + #define UNLOCK_PALETTE pthread_mutex_unlock(&palette_lock)
135 + #else
136 + #define LOCK_PALETTE
137 + #define UNLOCK_PALETTE
138   #endif
139  
140   // Variables for window mode
# Line 149 | Line 155 | static Window suspend_win;                                                     // "Sus
155   static void *fb_save = NULL;                                            // Saved frame buffer for suspend
156   #ifdef HAVE_PTHREADS
157   static pthread_mutex_t frame_buffer_lock = PTHREAD_MUTEX_INITIALIZER;   // Mutex to protect frame buffer
158 + #define LOCK_FRAME_BUFFER pthread_mutex_lock(&frame_buffer_lock);
159 + #define UNLOCK_FRAME_BUFFER pthread_mutex_unlock(&frame_buffer_lock);
160 + #else
161 + #define LOCK_FRAME_BUFFER
162 + #define UNLOCK_FRAME_BUFFER
163   #endif
164  
165   // Variables for fbdev DGA mode
# Line 168 | Line 179 | static const bool use_vosf = false;
179   #endif
180  
181   #ifdef ENABLE_VOSF
182 < static uint8 * the_host_buffer;                                         // Host frame buffer in VOSF mode
182 > // Variables for Video on SEGV support (taken from the Win32 port)
183 > static uint8 *the_host_buffer;                                          // Host frame buffer in VOSF mode
184   static uint32 the_buffer_size;                                          // Size of allocated the_buffer
173 #endif
185  
175 #ifdef ENABLE_VOSF
176 // Variables for Video on SEGV support (taken from the Win32 port)
186   struct ScreenPageInfo {
187      int top, bottom;                    // Mapping between this virtual page and Mac scanlines
188   };
# Line 215 | Line 224 | static bool Screen_fault_handler_init();
224   static struct sigaction vosf_sa;
225  
226   #ifdef HAVE_PTHREADS
227 < static pthread_mutex_t Screen_draw_lock = PTHREAD_MUTEX_INITIALIZER;    // Mutex to protect frame buffer (dirtyPages in fact)
227 > static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER;   // Mutex to protect frame buffer (dirtyPages in fact)
228 > #define LOCK_VOSF pthread_mutex_lock(&vosf_lock);
229 > #define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock);
230 > #else
231 > #define LOCK_VOSF
232 > #define UNLOCK_VOSF
233   #endif
234  
235   static int log_base_2(uint32 x)
# Line 237 | Line 251 | static void (*video_refresh)(void);
251  
252   // Prototypes
253   static void *redraw_func(void *arg);
254 < static int event2keycode(XKeyEvent *ev);
254 > static int event2keycode(XKeyEvent &ev);
255  
256  
257   // From main_unix.cpp
# Line 307 | Line 321 | void set_video_monitor(int width, int he
321          VideoMonitor.bytes_per_row = bytes_per_row;
322   }
323  
324 + // Set window name and class
325 + static void set_window_name(Window w, int name)
326 + {
327 +        const char *str = GetString(name);
328 +        XStoreName(x_display, w, str);
329 +        XSetIconName(x_display, w, str);
330 +
331 +        XClassHint *hints;
332 +        hints = XAllocClassHint();
333 +        if (hints) {
334 +                hints->res_name = "BasiliskII";
335 +                hints->res_class = "BasiliskII";
336 +                XSetClassHint(x_display, w, hints);
337 +                XFree((char *)hints);
338 +        }
339 + }
340 +
341 + // Set window input focus flag
342 + static void set_window_focus(Window w)
343 + {
344 +        XWMHints *hints = XAllocWMHints();
345 +        if (hints) {
346 +                hints->input = True;
347 +                hints->initial_state = NormalState;
348 +                hints->flags = InputHint | StateHint;
349 +                XSetWMHints(x_display, w, hints);
350 +                XFree((char *)hints);
351 +        }
352 + }
353 +
354 + // Set WM_DELETE_WINDOW protocol on window (preventing it from being destroyed by the WM when clicking on the "close" widget)
355 + static void set_window_delete_protocol(Window w)
356 + {
357 +        WM_DELETE_WINDOW = XInternAtom(x_display, "WM_DELETE_WINDOW", false);
358 +        XSetWMProtocols(x_display, w, &WM_DELETE_WINDOW, 1);
359 + }
360 +
361 + // Wait until window is mapped/unmapped
362 + void wait_mapped(Window w)
363 + {
364 +        XEvent e;
365 +        do {
366 +                XMaskEvent(x_display, StructureNotifyMask, &e);
367 +        } while ((e.type != MapNotify) || (e.xmap.event != w));
368 + }
369 +
370 + void wait_unmapped(Window w)
371 + {
372 +        XEvent e;
373 +        do {
374 +                XMaskEvent(x_display, StructureNotifyMask, &e);
375 +        } while ((e.type != UnmapNotify) || (e.xmap.event != w));
376 + }
377 +
378   // Trap SHM errors
379   static bool shm_error = false;
380   static int (*old_error_handler)(Display *, XErrorEvent *);
# Line 336 | Line 404 | static bool init_window(int width, int h
404          XSetWindowAttributes wattr;
405          wattr.event_mask = eventmask = win_eventmask;
406          wattr.background_pixel = black_pixel;
407 <        wattr.border_pixel = black_pixel;
340 <        wattr.backing_store = NotUseful;
341 <        wattr.save_under = false;
342 <        wattr.backing_planes = xdepth;
407 >        wattr.colormap = cmap[0];
408  
344        XSync(x_display, false);
409          the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
410 <                InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel |
411 <                CWBackingStore | CWBackingPlanes, &wattr);
410 >                InputOutput, vis, CWEventMask | CWBackPixel | (depth == 8 ? CWColormap : 0), &wattr);
411 >
412 >        // Set window name/class
413 >        set_window_name(the_win, STR_WINDOW_TITLE);
414  
415          // Indicate that we want keyboard input
416 <        {
417 <                XWMHints *hints = XAllocWMHints();
418 <                if (hints) {
419 <                        hints->input = True;
354 <                        hints->flags = InputHint;
355 <                        XSetWMHints(x_display, the_win, hints);
356 <                        XFree((char *)hints);
357 <                }
358 <        }
416 >        set_window_focus(the_win);
417 >
418 >        // Set delete protocol property
419 >        set_window_delete_protocol(the_win);
420  
421          // Make window unresizable
422          {
# Line 371 | Line 432 | static bool init_window(int width, int h
432                  }
433          }
434          
374        // Set window title
375        {
376                XTextProperty title_prop;
377                const char *title = GetString(STR_WINDOW_TITLE);
378                XStringListToTextProperty((char **)&title, 1, &title_prop);
379                XSetWMName(x_display, the_win, &title_prop);
380                XFree(title_prop.value);
381        }
382
383        // Set window class
384        {
385                XClassHint *hints;
386                hints = XAllocClassHint();
387                if (hints) {
388                        hints->res_name = "BasiliskII";
389                        hints->res_class = "BasiliskII";
390                        XSetClassHint(x_display, the_win, hints);
391                        XFree((char *)hints);
392                }
393        }
394
435          // Show window
436 <        XSync(x_display, false);
437 <        XMapRaised(x_display, the_win);
398 <        XFlush(x_display);
399 <
400 <        // Set colormap
401 <        if (depth == 8)
402 <                XSetWindowColormap(x_display, the_win, cmap[0]);
436 >        XMapWindow(x_display, the_win);
437 >        wait_mapped(the_win);
438  
439          // Try to create and attach SHM image
440          have_shm = false;
# Line 483 | Line 518 | static bool init_window(int width, int h
518          // Set VideoMonitor
519          bool native_byte_order;
520   #ifdef WORDS_BIGENDIAN
521 <        native_byte_order = (img->bitmap_bit_order == MSBFirst);
521 >        native_byte_order = (XImageByteOrder(x_display) == MSBFirst);
522   #else
523 <        native_byte_order = (img->bitmap_bit_order == LSBFirst);
523 >        native_byte_order = (XImageByteOrder(x_display) == LSBFirst);
524   #endif
525   #ifdef ENABLE_VOSF
526          do_update_framebuffer = GET_FBCOPY_FUNC(depth, native_byte_order, DISPLAY_WINDOW);
# Line 572 | Line 607 | static bool init_fbdev_dga(char *in_fb_n
607          
608          // Create window
609          XSetWindowAttributes wattr;
610 <        wattr.override_redirect = True;
611 <        wattr.backing_store             = NotUseful;
612 <        wattr.background_pixel  = white_pixel;
613 <        wattr.border_pixel              = black_pixel;
579 <        wattr.event_mask                = eventmask = dga_eventmask;
610 >        wattr.event_mask = eventmask = dga_eventmask;
611 >        wattr.background_pixel = white_pixel;
612 >        wattr.override_redirect = True;
613 >        wattr.colormap = cmap[0];
614          
581        XSync(x_display, false);
615          the_win = XCreateWindow(x_display, rootwin,
616                  0, 0, width, height,
617                  0, xdepth, InputOutput, vis,
618 <                CWEventMask|CWBackPixel|CWBorderPixel|CWOverrideRedirect|CWBackingStore,
618 >                CWEventMask | CWBackPixel | CWOverrideRedirect | (depth == 8 ? CWColormap : 0),
619                  &wattr);
620 <        XSync(x_display, false);
620 >
621 >        // Set window name/class
622 >        set_window_name(the_win, STR_WINDOW_TITLE);
623 >
624 >        // Indicate that we want keyboard input
625 >        set_window_focus(the_win);
626 >
627 >        // Show window
628          XMapRaised(x_display, the_win);
629 <        XSync(x_display, false);
629 >        wait_mapped(the_win);
630          
631          // Grab mouse and keyboard
632          XGrabKeyboard(x_display, the_win, True,
# Line 595 | Line 635 | static bool init_fbdev_dga(char *in_fb_n
635                  PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
636                  GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime);
637          
598        // Set colormap
599        if (depth == 8)
600                XSetWindowColormap(x_display, the_win, cmap[0]);
601        
638          // Set VideoMonitor
639          int bytes_per_row = width;
640          switch (depth) {
# Line 678 | Line 714 | static bool init_xf86_dga(int width, int
714                  }
715                  XF86VidModeSwitchToMode(x_display, screen, x_video_modes[best]);
716                  XF86VidModeSetViewPort(x_display, screen, 0, 0);
717 +                XSync(x_display, false);
718          }
719   #endif
720  
721          // Create window
722          XSetWindowAttributes wattr;
723          wattr.event_mask = eventmask = dga_eventmask;
687        wattr.border_pixel = black_pixel;
724          wattr.override_redirect = True;
725  
690        XSync(x_display, false);
726          the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth,
727 <                InputOutput, vis, CWEventMask | CWBorderPixel | CWOverrideRedirect, &wattr);
728 <        XSync(x_display, false);
729 <        XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE));
727 >                InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr);
728 >
729 >        // Set window name/class
730 >        set_window_name(the_win, STR_WINDOW_TITLE);
731 >
732 >        // Indicate that we want keyboard input
733 >        set_window_focus(the_win);
734 >
735 >        // Show window
736          XMapRaised(x_display, the_win);
737 <        XSync(x_display, false);
737 >        wait_mapped(the_win);
738  
739          // Establish direct screen connection
740          XMoveResizeWindow(x_display, the_win, 0, 0, width, height);
# Line 712 | Line 753 | static bool init_xf86_dga(int width, int
753                  XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]);
754                  XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
755          }
756 +        XSync(x_display, false);
757  
758          // Set VideoMonitor
759          int bytes_per_row = (v_width + 7) & ~7;
# Line 1050 | Line 1092 | bool VideoInit(bool classic)
1092                          break;
1093          }
1094  
1053 #ifdef HAVE_PTHREADS
1095          // Lock down frame buffer
1096 <        pthread_mutex_lock(&frame_buffer_lock);
1056 < #endif
1096 >        LOCK_FRAME_BUFFER;
1097  
1098   #if !REAL_ADDRESSING && !DIRECT_ADDRESSING
1099          // Set variables for UAE memory mapping
# Line 1118 | Line 1158 | void VideoExit(void)
1158          }
1159   #endif
1160  
1121 #ifdef HAVE_PTHREADS
1161          // Unlock frame buffer
1162 <        pthread_mutex_unlock(&frame_buffer_lock);
1124 < #endif
1162 >        UNLOCK_FRAME_BUFFER;
1163  
1164          // Close window and server connection
1165          if (x_display != NULL) {
# Line 1224 | Line 1262 | void VideoInterrupt(void)
1262          if (emerg_quit)
1263                  QuitEmulator();
1264  
1227 #ifdef HAVE_PTHREADS
1265          // Temporarily give up frame buffer lock (this is the point where
1266          // we are suspended when the user presses Ctrl-Tab)
1267 <        pthread_mutex_unlock(&frame_buffer_lock);
1268 <        pthread_mutex_lock(&frame_buffer_lock);
1232 < #endif
1267 >        UNLOCK_FRAME_BUFFER;
1268 >        LOCK_FRAME_BUFFER;
1269   }
1270  
1271  
# Line 1239 | Line 1275 | void VideoInterrupt(void)
1275  
1276   void video_set_palette(uint8 *pal)
1277   {
1278 < #ifdef HAVE_PTHREADS
1243 <        pthread_mutex_lock(&palette_lock);
1244 < #endif
1278 >        LOCK_PALETTE;
1279  
1280          // Convert colors to XColor array
1281          for (int i=0; i<256; i++) {
# Line 1255 | Line 1289 | void video_set_palette(uint8 *pal)
1289          // Tell redraw thread to change palette
1290          palette_changed = true;
1291  
1292 < #ifdef HAVE_PTHREADS
1259 <        pthread_mutex_unlock(&palette_lock);
1260 < #endif
1292 >        UNLOCK_PALETTE;
1293   }
1294  
1295  
# Line 1273 | Line 1305 | static void suspend_emul(void)
1305                  ADBKeyUp(0x36);
1306                  ctrl_down = false;
1307  
1276 #ifdef HAVE_PTHREADS
1308                  // Lock frame buffer (this will stop the MacOS thread)
1309 <                pthread_mutex_lock(&frame_buffer_lock);
1279 < #endif
1309 >                LOCK_FRAME_BUFFER;
1310  
1311                  // Save frame buffer
1312                  fb_save = malloc(VideoMonitor.y * VideoMonitor.bytes_per_row);
# Line 1290 | Line 1320 | static void suspend_emul(void)
1320                  XUngrabPointer(x_display, CurrentTime);
1321                  XUngrabKeyboard(x_display, CurrentTime);
1322                  XUnmapWindow(x_display, the_win);
1323 <                XSync(x_display, false);
1323 >                wait_unmapped(the_win);
1324  
1325                  // Open "suspend" window
1326                  XSetWindowAttributes wattr;
1327                  wattr.event_mask = KeyPressMask;
1328                  wattr.background_pixel = black_pixel;
1299                wattr.border_pixel = black_pixel;
1300                wattr.backing_store = Always;
1301                wattr.backing_planes = xdepth;
1302                wattr.colormap = DefaultColormap(x_display, screen);
1329                  
1304                XSync(x_display, false);
1330                  suspend_win = XCreateWindow(x_display, rootwin, 0, 0, 512, 1, 0, xdepth,
1331 <                        InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel |
1332 <                        CWBackingStore | CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr);
1333 <                XSync(x_display, false);
1334 <                XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE));
1310 <                XMapRaised(x_display, suspend_win);
1311 <                XSync(x_display, false);
1331 >                        InputOutput, vis, CWEventMask | CWBackPixel, &wattr);
1332 >                set_window_name(suspend_win, STR_SUSPEND_WINDOW_TITLE);
1333 >                set_window_focus(suspend_win);
1334 >                XMapWindow(x_display, suspend_win);
1335                  emul_suspended = true;
1336          }
1337   }
# Line 1321 | Line 1344 | static void resume_emul(void)
1344  
1345          // Reopen full screen display
1346          XMapRaised(x_display, the_win);
1347 +        wait_mapped(the_win);
1348          XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0);
1325        XSync(x_display, false);
1349          XGrabKeyboard(x_display, rootwin, 1, GrabModeAsync, GrabModeAsync, CurrentTime);
1350          XGrabPointer(x_display, rootwin, 1, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
1351   #ifdef ENABLE_XF86_DGA
# Line 1336 | Line 1359 | static void resume_emul(void)
1359          // not necessary.
1360   #ifdef ENABLE_VOSF
1361          if (use_vosf) {
1362 < #ifdef HAVE_PTHREADS
1340 <                pthread_mutex_lock(&Screen_draw_lock);
1341 < #endif
1362 >                LOCK_VOSF;
1363                  PFLAG_SET_ALL;
1364 < #ifdef HAVE_PTHREADS
1344 <                pthread_mutex_unlock(&Screen_draw_lock);
1345 < #endif
1364 >                UNLOCK_VOSF;
1365                  memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1366          }
1367   #endif
# Line 1363 | Line 1382 | static void resume_emul(void)
1382                  XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
1383   #endif
1384  
1366 #ifdef HAVE_PTHREADS
1385          // Unlock frame buffer (and continue MacOS thread)
1386 <        pthread_mutex_unlock(&frame_buffer_lock);
1386 >        UNLOCK_FRAME_BUFFER;
1387          emul_suspended = false;
1370 #endif
1388   }
1389   #endif
1390  
# Line 1521 | Line 1538 | static int kc_decode(KeySym ks)
1538          return -1;
1539   }
1540  
1541 < static int event2keycode(XKeyEvent *ev)
1541 > static int event2keycode(XKeyEvent &ev)
1542   {
1543          KeySym ks;
1544          int as;
1545          int i = 0;
1546  
1547          do {
1548 <                ks = XLookupKeysym(ev, i++);
1548 >                ks = XLookupKeysym(&ev, i++);
1549                  as = kc_decode(ks);
1550                  if (as != -1)
1551                          return as;
# Line 1544 | Line 1561 | static int event2keycode(XKeyEvent *ev)
1561  
1562   static void handle_events(void)
1563   {
1564 <        XEvent event;
1565 <        for (;;) {
1566 <                if (!XCheckMaskEvent(x_display, eventmask, &event))
1550 <                        break;
1564 >        while (XPending(x_display)) {
1565 >                XEvent event;
1566 >                XNextEvent(x_display, &event);
1567  
1568                  switch (event.type) {
1569                          // Mouse button
1570                          case ButtonPress: {
1571 <                                unsigned int button = ((XButtonEvent *)&event)->button;
1571 >                                unsigned int button = event.xbutton.button;
1572                                  if (button < 4)
1573                                          ADBMouseDown(button - 1);
1574                                  else if (button < 6) {  // Wheel mouse
# Line 1571 | Line 1587 | static void handle_events(void)
1587                                  break;
1588                          }
1589                          case ButtonRelease: {
1590 <                                unsigned int button = ((XButtonEvent *)&event)->button;
1590 >                                unsigned int button = event.xbutton.button;
1591                                  if (button < 4)
1592                                          ADBMouseUp(button - 1);
1593                                  break;
# Line 1579 | Line 1595 | static void handle_events(void)
1595  
1596                          // Mouse moved
1597                          case EnterNotify:
1582                                ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y);
1583                                break;
1598                          case MotionNotify:
1599 <                                ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y);
1599 >                                ADBMouseMoved(event.xmotion.x, event.xmotion.y);
1600                                  break;
1601  
1602                          // Keyboard
1603                          case KeyPress: {
1604                                  int code;
1605                                  if (use_keycodes) {
1606 <                                        event2keycode((XKeyEvent *)&event);     // This is called to process the hotkeys
1607 <                                        code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff];
1606 >                                        event2keycode(event.xkey);      // This is called to process the hotkeys
1607 >                                        code = keycode_table[event.xkey.keycode & 0xff];
1608                                  } else
1609 <                                        code = event2keycode((XKeyEvent *)&event);
1609 >                                        code = event2keycode(event.xkey);
1610                                  if (code != -1) {
1611                                          if (!emul_suspended) {
1612                                                  if (code == 0x39) {     // Caps Lock pressed
# Line 1619 | Line 1633 | static void handle_events(void)
1633                          case KeyRelease: {
1634                                  int code;
1635                                  if (use_keycodes) {
1636 <                                        event2keycode((XKeyEvent *)&event);     // This is called to process the hotkeys
1637 <                                        code = keycode_table[((XKeyEvent *)&event)->keycode & 0xff];
1636 >                                        event2keycode(event.xkey);      // This is called to process the hotkeys
1637 >                                        code = keycode_table[event.xkey.keycode & 0xff];
1638                                  } else
1639 <                                        code = event2keycode((XKeyEvent *)&event);
1639 >                                        code = event2keycode(event.xkey);
1640                                  if (code != -1 && code != 0x39) {       // Don't propagate Caps Lock releases
1641                                          ADBKeyUp(code);
1642                                          if (code == 0x36)
# Line 1636 | Line 1650 | static void handle_events(void)
1650                                  if (display_type == DISPLAY_WINDOW) {
1651   #ifdef ENABLE_VOSF
1652                                          if (use_vosf) {                 // VOSF refresh
1653 < #ifdef HAVE_PTHREADS
1640 <                                                pthread_mutex_lock(&Screen_draw_lock);
1641 < #endif
1653 >                                                LOCK_VOSF;
1654                                                  PFLAG_SET_ALL;
1655 < #ifdef HAVE_PTHREADS
1644 <                                                pthread_mutex_unlock(&Screen_draw_lock);
1645 < #endif
1655 >                                                UNLOCK_VOSF;
1656                                                  memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y);
1657                                          }
1658                                          else
# Line 1658 | Line 1668 | static void handle_events(void)
1668                                  }
1669                                  break;
1670  
1671 <                        case FocusIn:
1672 <                        case FocusOut:
1671 >                        // Window "close" widget clicked
1672 >                        case ClientMessage:
1673 >                                if (event.xclient.format == 32 && event.xclient.data.l[0] == WM_DELETE_WINDOW) {
1674 >                                        ADBKeyDown(0x7f);       // Power key
1675 >                                        ADBKeyUp(0x7f);
1676 >                                }
1677                                  break;
1678                  }
1679          }
# Line 1917 | Line 1931 | static inline void possibly_quit_dga_mod
1931  
1932   static inline void handle_palette_changes(int depth, int display_type)
1933   {
1934 < #ifdef HAVE_PTHREADS
1935 <        pthread_mutex_lock(&palette_lock);
1922 < #endif
1934 >        LOCK_PALETTE;
1935 >
1936          if (palette_changed) {
1937                  palette_changed = false;
1938                  if (depth == 8) {
1939                          XStoreColors(x_display, cmap[0], palette, 256);
1940                          XStoreColors(x_display, cmap[1], palette, 256);
1941 +                        XSync(x_display, false);
1942                                  
1943   #ifdef ENABLE_XF86_DGA
1944                          if (display_type == DISPLAY_DGA) {
# Line 1934 | Line 1948 | static inline void handle_palette_change
1948   #endif
1949                  }
1950          }
1951 < #ifdef HAVE_PTHREADS
1952 <        pthread_mutex_unlock(&palette_lock);
1939 < #endif
1951 >
1952 >        UNLOCK_PALETTE;
1953   }
1954  
1955   static void video_refresh_dga(void)
# Line 1968 | Line 1981 | static void video_refresh_dga_vosf(void)
1981          static int tick_counter = 0;
1982          if (++tick_counter >= frame_skip) {
1983                  tick_counter = 0;
1984 < #ifdef HAVE_PTHREADS
1972 <                pthread_mutex_lock(&Screen_draw_lock);
1973 < #endif
1984 >                LOCK_VOSF;
1985                  update_display_dga_vosf();
1986 < #ifdef HAVE_PTHREADS
1976 <                pthread_mutex_unlock(&Screen_draw_lock);
1977 < #endif
1986 >                UNLOCK_VOSF;
1987          }
1988   }
1989   #endif
# Line 1994 | Line 2003 | static void video_refresh_window_vosf(vo
2003          static int tick_counter = 0;
2004          if (++tick_counter >= frame_skip) {
2005                  tick_counter = 0;
2006 < #ifdef HAVE_PTHREADS
1998 <                pthread_mutex_lock(&Screen_draw_lock);
1999 < #endif
2006 >                LOCK_VOSF;
2007                  update_display_window_vosf();
2008 < #ifdef HAVE_PTHREADS
2002 <                pthread_mutex_unlock(&Screen_draw_lock);
2003 < #endif
2008 >                UNLOCK_VOSF;
2009          }
2010   }
2011   #endif // def ENABLE_VOSF
# Line 2070 | Line 2075 | void VideoRefresh(void)
2075          video_refresh();
2076   }
2077  
2073 #if 0
2074 void VideoRefresh(void)
2075 {
2076 #if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA)
2077        // Quit DGA mode if requested
2078        if (quit_full_screen) {
2079                quit_full_screen = false;
2080                if (display_type == DISPLAY_DGA) {
2081 #ifdef ENABLE_XF86_DGA
2082                        XF86DGADirectVideo(x_display, screen, 0);
2083 #endif
2084                        XUngrabPointer(x_display, CurrentTime);
2085                        XUngrabKeyboard(x_display, CurrentTime);
2086                        XUnmapWindow(x_display, the_win);
2087                        XSync(x_display, false);
2088                }
2089        }
2090 #endif
2091
2092        // Handle X events
2093        handle_events();
2094
2095        // Handle palette changes
2096 #ifdef HAVE_PTHREADS
2097        pthread_mutex_lock(&palette_lock);
2098 #endif
2099        if (palette_changed) {
2100                palette_changed = false;
2101                if (depth == 8) {
2102                        XStoreColors(x_display, cmap[0], palette, 256);
2103                        XStoreColors(x_display, cmap[1], palette, 256);
2104                                
2105 #ifdef ENABLE_XF86_DGA
2106                        if (display_type == DISPLAY_DGA) {
2107                                current_dga_cmap ^= 1;
2108                                XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]);
2109                        }
2110 #endif
2111                }
2112        }
2113 #ifdef HAVE_PTHREADS
2114        pthread_mutex_unlock(&palette_lock);
2115 #endif
2116
2117        // In window mode, update display
2118        static int tick_counter = 0;
2119        if (display_type == DISPLAY_WINDOW) {
2120                tick_counter++;
2121                if (frame_skip == 0)
2122                        update_display_dynamic(tick_counter);
2123                else if (tick_counter >= frame_skip) {
2124                        tick_counter = 0;
2125                        update_display_static();
2126                }
2127        }
2128 }
2129 #endif
2130
2078   #ifdef HAVE_PTHREADS
2079   static void *redraw_func(void *arg)
2080   {
# Line 2135 | Line 2082 | static void *redraw_func(void *arg)
2082          int64 ticks = 0;
2083          uint64 next = GetTicks_usec();
2084          while (!redraw_thread_cancel) {
2138 //              VideoRefresh();
2085                  video_refresh();
2086                  next += 16667;
2087                  int64 delay = next - GetTicks_usec();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines