| 63 |
static int16 mouse_wheel_mode; |
static int16 mouse_wheel_mode; |
| 64 |
static int16 mouse_wheel_lines; |
static int16 mouse_wheel_lines; |
| 65 |
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
| 66 |
|
static pthread_attr_t redraw_thread_attr; // Redraw thread attributes |
| 67 |
static pthread_t redraw_thread; // Redraw thread |
static pthread_t redraw_thread; // Redraw thread |
| 68 |
|
|
| 69 |
static bool local_X11; // Flag: X server running on local machine? |
static bool local_X11; // Flag: X server running on local machine? |
| 126 |
static uint32 the_buffer_size; // Size of allocated the_buffer |
static uint32 the_buffer_size; // Size of allocated the_buffer |
| 127 |
|
|
| 128 |
// Variables for DGA mode |
// Variables for DGA mode |
|
static char *dga_screen_base; |
|
|
static int dga_fb_width; |
|
| 129 |
static int current_dga_cmap; |
static int current_dga_cmap; |
| 130 |
|
|
| 131 |
#ifdef ENABLE_XF86_VIDMODE |
#ifdef ENABLE_XF86_VIDMODE |
| 348 |
} |
} |
| 349 |
|
|
| 350 |
// Wait until window is mapped/unmapped |
// Wait until window is mapped/unmapped |
| 351 |
void wait_mapped(Window w) |
static void wait_mapped(Window w) |
| 352 |
{ |
{ |
| 353 |
XEvent e; |
XEvent e; |
| 354 |
do { |
do { |
| 356 |
} while ((e.type != MapNotify) || (e.xmap.event != w)); |
} while ((e.type != MapNotify) || (e.xmap.event != w)); |
| 357 |
} |
} |
| 358 |
|
|
| 359 |
void wait_unmapped(Window w) |
static void wait_unmapped(Window w) |
| 360 |
{ |
{ |
| 361 |
XEvent e; |
XEvent e; |
| 362 |
do { |
do { |
| 521 |
// Set relative mouse mode |
// Set relative mouse mode |
| 522 |
ADBSetRelMouseMode(true); |
ADBSetRelMouseMode(true); |
| 523 |
|
|
| 524 |
|
// Create window |
| 525 |
|
XSetWindowAttributes wattr; |
| 526 |
|
wattr.event_mask = eventmask = dga_eventmask; |
| 527 |
|
wattr.override_redirect = True; |
| 528 |
|
wattr.colormap = (depth == 1 ? DefaultColormap(x_display, screen) : cmap[0]); |
| 529 |
|
the_win = XCreateWindow(x_display, rootwin, 0, 0, width, height, 0, xdepth, |
| 530 |
|
InputOutput, vis, CWEventMask | CWOverrideRedirect | |
| 531 |
|
(color_class == DirectColor ? CWColormap : 0), &wattr); |
| 532 |
|
|
| 533 |
|
// Show window |
| 534 |
|
XMapRaised(x_display, the_win); |
| 535 |
|
wait_mapped(the_win); |
| 536 |
|
|
| 537 |
#ifdef ENABLE_XF86_VIDMODE |
#ifdef ENABLE_XF86_VIDMODE |
| 538 |
// Switch to best mode |
// Switch to best mode |
| 539 |
if (has_vidmode) { |
if (has_vidmode) { |
| 550 |
#endif |
#endif |
| 551 |
|
|
| 552 |
// Establish direct screen connection |
// Establish direct screen connection |
| 553 |
|
XMoveResizeWindow(x_display, the_win, 0, 0, width, height); |
| 554 |
|
XWarpPointer(x_display, None, rootwin, 0, 0, 0, 0, 0, 0); |
| 555 |
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
XGrabKeyboard(x_display, rootwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); |
| 556 |
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
XGrabPointer(x_display, rootwin, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); |
| 557 |
|
|
| 558 |
|
int v_width, v_bank, v_size; |
| 559 |
|
XF86DGAGetVideo(x_display, screen, (char **)&the_buffer, &v_width, &v_bank, &v_size); |
| 560 |
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
XF86DGADirectVideo(x_display, screen, XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse); |
| 561 |
XF86DGASetViewPort(x_display, screen, 0, 0); |
XF86DGASetViewPort(x_display, screen, 0, 0); |
| 562 |
XF86DGASetVidPage(x_display, screen, 0); |
XF86DGASetVidPage(x_display, screen, 0); |
| 563 |
|
|
| 564 |
// Set colormap |
// Set colormap |
| 565 |
if (depth == 8) |
if (!IsDirectMode(get_current_mode())) { |
| 566 |
|
XSetWindowColormap(x_display, the_win, cmap[current_dga_cmap = 0]); |
| 567 |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
| 568 |
|
} |
| 569 |
|
XSync(x_display, false); |
| 570 |
|
|
| 571 |
// Set bytes per row |
// Init blitting routines |
| 572 |
int bytes_per_row = TrivialBytesPerRow((dga_fb_width + 7) & ~7, DepthModeForPixelDepth(depth)); |
int bytes_per_row = TrivialBytesPerRow((v_width + 7) & ~7, DepthModeForPixelDepth(depth)); |
|
|
|
| 573 |
#if ENABLE_VOSF |
#if ENABLE_VOSF |
| 574 |
bool native_byte_order; |
bool native_byte_order; |
| 575 |
#ifdef WORDS_BIGENDIAN |
#ifdef WORDS_BIGENDIAN |
| 588 |
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
| 589 |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
| 590 |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
| 591 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
| 592 |
} |
} |
| 593 |
#else |
#else |
| 594 |
use_vosf = false; |
use_vosf = false; |
|
the_buffer = dga_screen_base; |
|
| 595 |
#endif |
#endif |
| 596 |
#endif |
#endif |
|
screen_base = (uint32)the_buffer; |
|
| 597 |
|
|
| 598 |
|
// Set frame buffer base |
| 599 |
|
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
| 600 |
|
screen_base = (uint32)the_buffer; |
| 601 |
VModes[cur_mode].viRowBytes = bytes_per_row; |
VModes[cur_mode].viRowBytes = bytes_per_row; |
|
XSync(x_display, false); |
|
| 602 |
return true; |
return true; |
| 603 |
#else |
#else |
| 604 |
ErrorAlert("SheepShaver has been compiled with DGA support disabled."); |
ErrorAlert("SheepShaver has been compiled with DGA support disabled."); |
| 731 |
if (the_gc) |
if (the_gc) |
| 732 |
XFreeGC(x_display, the_gc); |
XFreeGC(x_display, the_gc); |
| 733 |
|
|
|
// Close window |
|
|
if (the_win) { |
|
|
XUnmapWindow(x_display, the_win); |
|
|
wait_unmapped(the_win); |
|
|
XDestroyWindow(x_display, the_win); |
|
|
} |
|
|
|
|
| 734 |
XFlush(x_display); |
XFlush(x_display); |
| 735 |
XSync(x_display, false); |
XSync(x_display, false); |
| 736 |
} |
} |
| 768 |
else if (display_type == DIS_WINDOW) |
else if (display_type == DIS_WINDOW) |
| 769 |
close_window(); |
close_window(); |
| 770 |
|
|
| 771 |
|
// Close window |
| 772 |
|
if (the_win) { |
| 773 |
|
XUnmapWindow(x_display, the_win); |
| 774 |
|
wait_unmapped(the_win); |
| 775 |
|
XDestroyWindow(x_display, the_win); |
| 776 |
|
} |
| 777 |
|
|
| 778 |
// Free colormaps |
// Free colormaps |
| 779 |
if (cmap[0]) { |
if (cmap[0]) { |
| 780 |
XFreeColormap(x_display, cmap[0]); |
XFreeColormap(x_display, cmap[0]); |
| 891 |
} |
} |
| 892 |
} |
} |
| 893 |
|
|
| 894 |
|
// Find Apple mode matching best specified dimensions |
| 895 |
|
static int find_apple_resolution(int xsize, int ysize) |
| 896 |
|
{ |
| 897 |
|
int apple_id; |
| 898 |
|
if (xsize < 800) |
| 899 |
|
apple_id = APPLE_640x480; |
| 900 |
|
else if (xsize < 1024) |
| 901 |
|
apple_id = APPLE_800x600; |
| 902 |
|
else if (xsize < 1152) |
| 903 |
|
apple_id = APPLE_1024x768; |
| 904 |
|
else if (xsize < 1280) { |
| 905 |
|
if (ysize < 900) |
| 906 |
|
apple_id = APPLE_1152x768; |
| 907 |
|
else |
| 908 |
|
apple_id = APPLE_1152x900; |
| 909 |
|
} |
| 910 |
|
else if (xsize < 1600) |
| 911 |
|
apple_id = APPLE_1280x1024; |
| 912 |
|
else |
| 913 |
|
apple_id = APPLE_1600x1200; |
| 914 |
|
return apple_id; |
| 915 |
|
} |
| 916 |
|
|
| 917 |
|
// Find mode in list of supported modes |
| 918 |
|
static int find_mode(int apple_mode, int apple_id, int type) |
| 919 |
|
{ |
| 920 |
|
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
| 921 |
|
if (p->viType == type && p->viAppleID == apple_id && p->viAppleMode == apple_mode) |
| 922 |
|
return p - VModes; |
| 923 |
|
} |
| 924 |
|
return -1; |
| 925 |
|
} |
| 926 |
|
|
| 927 |
// Add mode to list of supported modes |
// Add mode to list of supported modes |
| 928 |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) |
| 929 |
{ |
{ |
| 944 |
p->viXsize = 1024; |
p->viXsize = 1024; |
| 945 |
p->viYsize = 768; |
p->viYsize = 768; |
| 946 |
break; |
break; |
| 947 |
|
case APPLE_1152x768: |
| 948 |
|
p->viXsize = 1152; |
| 949 |
|
p->viYsize = 768; |
| 950 |
|
break; |
| 951 |
case APPLE_1152x900: |
case APPLE_1152x900: |
| 952 |
p->viXsize = 1152; |
p->viXsize = 1152; |
| 953 |
p->viYsize = 900; |
p->viYsize = 900; |
| 1094 |
add_mode(p, screen_modes, 2, default_mode, APPLE_800x600, DIS_SCREEN); |
add_mode(p, screen_modes, 2, default_mode, APPLE_800x600, DIS_SCREEN); |
| 1095 |
if (has_mode(1024, 768)) |
if (has_mode(1024, 768)) |
| 1096 |
add_mode(p, screen_modes, 4, default_mode, APPLE_1024x768, DIS_SCREEN); |
add_mode(p, screen_modes, 4, default_mode, APPLE_1024x768, DIS_SCREEN); |
| 1097 |
|
if (has_mode(1152, 768)) |
| 1098 |
|
add_mode(p, screen_modes, 64, default_mode, APPLE_1152x768, DIS_SCREEN); |
| 1099 |
if (has_mode(1152, 900)) |
if (has_mode(1152, 900)) |
| 1100 |
add_mode(p, screen_modes, 8, default_mode, APPLE_1152x900, DIS_SCREEN); |
add_mode(p, screen_modes, 8, default_mode, APPLE_1152x900, DIS_SCREEN); |
| 1101 |
if (has_mode(1280, 1024)) |
if (has_mode(1280, 1024)) |
| 1105 |
} else if (screen_modes) { |
} else if (screen_modes) { |
| 1106 |
int xsize = DisplayWidth(x_display, screen); |
int xsize = DisplayWidth(x_display, screen); |
| 1107 |
int ysize = DisplayHeight(x_display, screen); |
int ysize = DisplayHeight(x_display, screen); |
| 1108 |
int apple_id; |
int apple_id = find_apple_resolution(xsize, ysize); |
|
if (xsize < 800) |
|
|
apple_id = APPLE_640x480; |
|
|
else if (xsize < 1024) |
|
|
apple_id = APPLE_800x600; |
|
|
else if (xsize < 1152) |
|
|
apple_id = APPLE_1024x768; |
|
|
else if (xsize < 1280) |
|
|
apple_id = APPLE_1152x900; |
|
|
else if (xsize < 1600) |
|
|
apple_id = APPLE_1280x1024; |
|
|
else |
|
|
apple_id = APPLE_1600x1200; |
|
| 1109 |
p->viType = DIS_SCREEN; |
p->viType = DIS_SCREEN; |
| 1110 |
p->viRowBytes = 0; |
p->viRowBytes = 0; |
| 1111 |
p->viXsize = xsize; |
p->viXsize = xsize; |
| 1122 |
|
|
| 1123 |
// Find default mode (window 640x480) |
// Find default mode (window 640x480) |
| 1124 |
cur_mode = -1; |
cur_mode = -1; |
| 1125 |
for (p = VModes; p->viType != DIS_INVALID; p++) { |
if (has_dga && screen_modes) { |
| 1126 |
if (p->viType == DIS_WINDOW |
int screen_width = DisplayWidth(x_display, screen); |
| 1127 |
&& p->viAppleID == APPLE_W_640x480 |
int screen_height = DisplayHeight(x_display, screen); |
| 1128 |
&& p->viAppleMode == default_mode) { |
int apple_id = find_apple_resolution(screen_width, screen_height); |
| 1129 |
cur_mode = p - VModes; |
if (apple_id != -1) |
| 1130 |
break; |
cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); |
|
} |
|
| 1131 |
} |
} |
| 1132 |
|
if (cur_mode == -1) |
| 1133 |
|
cur_mode = find_mode(default_mode, APPLE_W_640x480, DIS_WINDOW); |
| 1134 |
assert(cur_mode != -1); |
assert(cur_mode != -1); |
| 1135 |
|
|
| 1136 |
#if DEBUG |
#if DEBUG |
| 1141 |
} |
} |
| 1142 |
#endif |
#endif |
| 1143 |
|
|
|
#ifdef ENABLE_XF86_DGA |
|
|
if (has_dga && screen_modes) { |
|
|
int v_bank, v_size; |
|
|
XF86DGAGetVideo(x_display, screen, &dga_screen_base, &dga_fb_width, &v_bank, &v_size); |
|
|
D(bug("DGA screen_base %p, v_width %d\n", dga_screen_base, dga_fb_width)); |
|
|
} |
|
|
#endif |
|
|
|
|
| 1144 |
// Open window/screen |
// Open window/screen |
| 1145 |
if (!open_display()) |
if (!open_display()) |
| 1146 |
return false; |
return false; |
| 1152 |
|
|
| 1153 |
// Start periodic thread |
// Start periodic thread |
| 1154 |
XSync(x_display, false); |
XSync(x_display, false); |
| 1155 |
redraw_thread_active = (pthread_create(&redraw_thread, NULL, redraw_func, NULL) == 0); |
Set_pthread_attr(&redraw_thread_attr, 0); |
| 1156 |
|
redraw_thread_active = (pthread_create(&redraw_thread, &redraw_thread_attr, redraw_func, NULL) == 0); |
| 1157 |
D(bug("Redraw thread installed (%ld)\n", redraw_thread)); |
D(bug("Redraw thread installed (%ld)\n", redraw_thread)); |
| 1158 |
return true; |
return true; |
| 1159 |
} |
} |
| 1516 |
break; |
break; |
| 1517 |
} |
} |
| 1518 |
|
|
| 1519 |
// Mouse moved |
// Mouse entered window |
| 1520 |
case EnterNotify: |
case EnterNotify: |
| 1521 |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
if (event.xcrossing.mode != NotifyGrab && event.xcrossing.mode != NotifyUngrab) |
| 1522 |
|
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
| 1523 |
break; |
break; |
| 1524 |
|
|
| 1525 |
|
// Mouse moved |
| 1526 |
case MotionNotify: |
case MotionNotify: |
| 1527 |
ADBMouseMoved(((XMotionEvent *)&event)->x, ((XMotionEvent *)&event)->y); |
ADBMouseMoved(event.xmotion.x, event.xmotion.y); |
| 1528 |
break; |
break; |
| 1529 |
|
|
| 1530 |
// Keyboard |
// Keyboard |
| 2043 |
XF86DGADirectVideo(x_display, screen, 0); |
XF86DGADirectVideo(x_display, screen, 0); |
| 2044 |
XUngrabPointer(x_display, CurrentTime); |
XUngrabPointer(x_display, CurrentTime); |
| 2045 |
XUngrabKeyboard(x_display, CurrentTime); |
XUngrabKeyboard(x_display, CurrentTime); |
| 2046 |
|
XUnmapWindow(x_display, the_win); |
| 2047 |
|
wait_unmapped(the_win); |
| 2048 |
|
XDestroyWindow(x_display, the_win); |
| 2049 |
#endif |
#endif |
| 2050 |
XSync(x_display, false); |
XSync(x_display, false); |
| 2051 |
XDisplayUnlock(); |
XDisplayUnlock(); |