--- BasiliskII/src/Unix/video_x.cpp 2000/10/11 17:55:06 1.24 +++ BasiliskII/src/Unix/video_x.cpp 2000/11/03 12:23:49 1.28 @@ -53,7 +53,6 @@ #endif #ifdef ENABLE_VOSF -# include // log() # include # include # include @@ -123,7 +122,7 @@ static Colormap cmap[2]; // Two co static XColor black, white; static unsigned long black_pixel, white_pixel; static int eventmask; -static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | ExposureMask; +static const int win_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | FocusChangeMask | ExposureMask; static const int dga_eventmask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; static XColor palette[256]; // Color palette for 8-bit mode @@ -219,6 +218,17 @@ static struct sigaction vosf_sa; static pthread_mutex_t Screen_draw_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) #endif +static int log_base_2(uint32 x) +{ + uint32 mask = 0x80000000; + int l = 31; + while (l >= 0 && (x & mask) == 0) { + mask >>= 1; + l--; + } + return l; +} + #endif // VideoRefresh function @@ -326,38 +336,60 @@ static bool init_window(int width, int h XSetWindowAttributes wattr; wattr.event_mask = eventmask = win_eventmask; wattr.background_pixel = black_pixel; - wattr.border_pixel = black_pixel; - wattr.backing_store = NotUseful; - wattr.save_under = false; - wattr.backing_planes = xdepth; XSync(x_display, false); the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, - InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | - CWBackingStore | CWBackingPlanes, &wattr); - XSync(x_display, false); - XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); - XMapRaised(x_display, the_win); - XSync(x_display, false); + InputOutput, vis, CWEventMask | CWBackPixel, &wattr); - // Set colormap - if (depth == 8) { - XSetWindowColormap(x_display, the_win, cmap[0]); - XSetWMColormapWindows(x_display, the_win, &the_win, 1); + // Indicate that we want keyboard input + { + XWMHints *hints = XAllocWMHints(); + if (hints) { + hints->input = True; + hints->flags = InputHint; + XSetWMHints(x_display, the_win, hints); + XFree((char *)hints); + } } // Make window unresizable - XSizeHints *hints; - if ((hints = XAllocSizeHints()) != NULL) { - hints->min_width = width; - hints->max_width = width; - hints->min_height = height; - hints->max_height = height; - hints->flags = PMinSize | PMaxSize; - XSetWMNormalHints(x_display, the_win, hints); - XFree((char *)hints); + { + XSizeHints *hints = XAllocSizeHints(); + if (hints) { + hints->min_width = width; + hints->max_width = width; + hints->min_height = height; + hints->max_height = height; + hints->flags = PMinSize | PMaxSize; + XSetWMNormalHints(x_display, the_win, hints); + XFree((char *)hints); + } } + // 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 + XSync(x_display, false); + XMapRaised(x_display, the_win); + XFlush(x_display); + + // Set colormap + if (depth == 8) + XSetWindowColormap(x_display, the_win, cmap[0]); + // Try to create and attach SHM image have_shm = false; if (depth != 1 && local_X11 && XShmQueryExtension(x_display)) { @@ -529,17 +561,15 @@ static bool init_fbdev_dga(char *in_fb_n // Create window XSetWindowAttributes wattr; - wattr.override_redirect = True; - wattr.backing_store = NotUseful; - wattr.background_pixel = white_pixel; - wattr.border_pixel = black_pixel; wattr.event_mask = eventmask = dga_eventmask; + wattr.background_pixel = white_pixel; + wattr.override_redirect = True; XSync(x_display, false); the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, InputOutput, vis, - CWEventMask|CWBackPixel|CWBorderPixel|CWOverrideRedirect|CWBackingStore, + CWEventMask | CWBackPixel | CWOverrideRedirect, &wattr); XSync(x_display, false); XMapRaised(x_display, the_win); @@ -553,10 +583,8 @@ static bool init_fbdev_dga(char *in_fb_n GrabModeAsync, GrabModeAsync, the_win, None, CurrentTime); // Set colormap - if (depth == 8) { + if (depth == 8) XSetWindowColormap(x_display, the_win, cmap[0]); - XSetWMColormapWindows(x_display, the_win, &the_win, 1); - } // Set VideoMonitor int bytes_per_row = width; @@ -643,12 +671,11 @@ static bool init_xf86_dga(int width, int // Create window XSetWindowAttributes wattr; wattr.event_mask = eventmask = dga_eventmask; - wattr.border_pixel = black_pixel; wattr.override_redirect = True; XSync(x_display, false); the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, - InputOutput, vis, CWEventMask | CWBorderPixel | CWOverrideRedirect, &wattr); + InputOutput, vis, CWEventMask | CWOverrideRedirect, &wattr); XSync(x_display, false); XStoreName(x_display, the_win, GetString(STR_WINDOW_TITLE)); XMapRaised(x_display, the_win); @@ -669,7 +696,6 @@ static bool init_xf86_dga(int width, int // Set colormap if (depth == 8) { XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); - XSetWMColormapWindows(x_display, the_win, &the_win, 1); XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); } @@ -804,7 +830,7 @@ bool VideoInitBuffer() mainBuffer.pageSize = page_size; mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; - mainBuffer.pageBits = int( log(mainBuffer.pageSize) / log(2.0) ); + mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); if (mainBuffer.dirtyPages != 0) free(mainBuffer.dirtyPages); @@ -1199,7 +1225,7 @@ void VideoInterrupt(void) void video_set_palette(uint8 *pal) { -#ifdef HAVE_PTHREDS +#ifdef HAVE_PTHREADS pthread_mutex_lock(&palette_lock); #endif @@ -1256,15 +1282,14 @@ static void suspend_emul(void) XSetWindowAttributes wattr; wattr.event_mask = KeyPressMask; wattr.background_pixel = black_pixel; - wattr.border_pixel = black_pixel; - wattr.backing_store = Always; + 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, - InputOutput, vis, CWEventMask | CWBackPixel | CWBorderPixel | - CWBackingStore | CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr); + InputOutput, vis, CWEventMask | CWBackPixel | CWBackingStore | + CWBackingPlanes | (xdepth == 8 ? CWColormap : 0), &wattr); XSync(x_display, false); XStoreName(x_display, suspend_win, GetString(STR_SUSPEND_WINDOW_TITLE)); XMapRaised(x_display, suspend_win); @@ -1617,6 +1642,10 @@ static void handle_events(void) memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); } break; + + case FocusIn: + case FocusOut: + break; } } } @@ -1766,12 +1795,12 @@ static void update_display_static(void) for (i=(VideoMonitor.x>>3); i>(x2>>3); i--) { p--; p2--; if (*p != *p2) { - x2 = i << 3; + x2 = (i << 3) + 7; break; } } } - wide = x2 - x1; + wide = x2 - x1 + 1; // Update copy of the_buffer if (high && wide) {