| 18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 |
*/ |
*/ |
| 20 |
|
|
| 21 |
|
#include "sysdeps.h" |
| 22 |
|
|
| 23 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
| 24 |
#include <X11/Xutil.h> |
#include <X11/Xutil.h> |
| 25 |
#include <X11/keysym.h> |
#include <X11/keysym.h> |
| 26 |
#include <X11/extensions/XShm.h> |
#include <X11/extensions/XShm.h> |
| 27 |
#include <sys/ipc.h> |
#include <sys/ipc.h> |
| 28 |
#include <sys/shm.h> |
#include <sys/shm.h> |
| 29 |
|
#include <errno.h> |
| 30 |
|
|
| 31 |
|
#ifdef HAVE_PTHREADS |
| 32 |
#include <pthread.h> |
#include <pthread.h> |
| 33 |
|
#endif |
| 34 |
|
|
| 35 |
|
#ifdef ENABLE_XF86_DGA |
| 36 |
|
#include <X11/extensions/xf86dga.h> |
| 37 |
|
#endif |
| 38 |
|
|
| 39 |
|
#ifdef ENABLE_XF86_VIDMODE |
| 40 |
|
# include <X11/extensions/xf86vmode.h> |
| 41 |
|
#endif |
| 42 |
|
|
|
#include "sysdeps.h" |
|
| 43 |
#include "main.h" |
#include "main.h" |
| 44 |
#include "adb.h" |
#include "adb.h" |
| 45 |
#include "prefs.h" |
#include "prefs.h" |
| 51 |
#define DEBUG 0 |
#define DEBUG 0 |
| 52 |
#include "debug.h" |
#include "debug.h" |
| 53 |
|
|
|
#ifdef ENABLE_XF86_DGA |
|
|
#include <X11/extensions/xf86dga.h> |
|
|
#endif |
|
|
|
|
|
#ifdef ENABLE_XF86_VIDMODE |
|
|
#include <X11/extensions/xf86vmode.h> |
|
|
#endif |
|
| 54 |
|
|
| 55 |
|
// Constants |
| 56 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
| 57 |
|
|
| 58 |
// Global variables |
// Global variables |
| 59 |
static int32 frame_skip; |
static int32 frame_skip; |
| 82 |
static bool emul_suspended = false; // Flag: emulator suspended |
static bool emul_suspended = false; // Flag: emulator suspended |
| 83 |
static Window suspend_win; // "Suspend" window |
static Window suspend_win; // "Suspend" window |
| 84 |
static void *fb_save = NULL; // Saved frame buffer for suspend |
static void *fb_save = NULL; // Saved frame buffer for suspend |
| 85 |
|
static bool use_keycodes = false; // Flag: Use keycodes rather than keysyms |
| 86 |
|
static int keycode_table[256]; // X keycode -> Mac keycode translation table |
| 87 |
|
|
| 88 |
// X11 variables |
// X11 variables |
| 89 |
static int screen; // Screen number |
static int screen; // Screen number |
| 544 |
* Initialization |
* Initialization |
| 545 |
*/ |
*/ |
| 546 |
|
|
| 547 |
|
// Init keycode translation table |
| 548 |
|
static void keycode_init(void) |
| 549 |
|
{ |
| 550 |
|
bool use_kc = PrefsFindBool("keycodes"); |
| 551 |
|
if (use_kc) { |
| 552 |
|
|
| 553 |
|
// Get keycode file path from preferences |
| 554 |
|
const char *kc_path = PrefsFindString("keycodefile"); |
| 555 |
|
|
| 556 |
|
// Open keycode table |
| 557 |
|
FILE *f = fopen(kc_path ? kc_path : KEYCODE_FILE_NAME, "r"); |
| 558 |
|
if (f == NULL) { |
| 559 |
|
char str[256]; |
| 560 |
|
sprintf(str, GetString(STR_KEYCODE_FILE_WARN), kc_path ? kc_path : KEYCODE_FILE_NAME, strerror(errno)); |
| 561 |
|
WarningAlert(str); |
| 562 |
|
return; |
| 563 |
|
} |
| 564 |
|
|
| 565 |
|
// Default translation table |
| 566 |
|
for (int i=0; i<256; i++) |
| 567 |
|
keycode_table[i] = -1; |
| 568 |
|
|
| 569 |
|
// Search for server vendor string, then read keycodes |
| 570 |
|
const char *vendor = ServerVendor(x_display); |
| 571 |
|
bool vendor_found = false; |
| 572 |
|
char line[256]; |
| 573 |
|
while (fgets(line, 255, f)) { |
| 574 |
|
// Read line |
| 575 |
|
int len = strlen(line); |
| 576 |
|
if (len == 0) |
| 577 |
|
continue; |
| 578 |
|
line[len-1] = 0; |
| 579 |
|
|
| 580 |
|
// Comments begin with "#" or ";" |
| 581 |
|
if (line[0] == '#' || line[0] == ';' || line[0] == 0) |
| 582 |
|
continue; |
| 583 |
|
|
| 584 |
|
if (vendor_found) { |
| 585 |
|
// Read keycode |
| 586 |
|
int x_code, mac_code; |
| 587 |
|
if (sscanf(line, "%d %d", &x_code, &mac_code) == 2) |
| 588 |
|
keycode_table[x_code & 0xff] = mac_code; |
| 589 |
|
else |
| 590 |
|
break; |
| 591 |
|
} else { |
| 592 |
|
// Search for vendor string |
| 593 |
|
if (strstr(vendor, line) == vendor) |
| 594 |
|
vendor_found = true; |
| 595 |
|
} |
| 596 |
|
} |
| 597 |
|
|
| 598 |
|
// Keycode file completely read |
| 599 |
|
fclose(f); |
| 600 |
|
use_keycodes = vendor_found; |
| 601 |
|
|
| 602 |
|
// Vendor not found? Then display warning |
| 603 |
|
if (!vendor_found) { |
| 604 |
|
char str[256]; |
| 605 |
|
sprintf(str, GetString(STR_KEYCODE_VENDOR_WARN), vendor, kc_path ? kc_path : KEYCODE_FILE_NAME); |
| 606 |
|
WarningAlert(str); |
| 607 |
|
return; |
| 608 |
|
} |
| 609 |
|
} |
| 610 |
|
} |
| 611 |
|
|
| 612 |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, long apple_mode, long apple_id, int type) |
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, long apple_mode, long apple_id, int type) |
| 613 |
{ |
{ |
| 614 |
if (allow & test) { |
if (allow & test) { |
| 682 |
local_X11 = (strncmp(XDisplayName(x_display_name), ":", 1) == 0) |
local_X11 = (strncmp(XDisplayName(x_display_name), ":", 1) == 0) |
| 683 |
|| (strncmp(XDisplayName(x_display_name), "unix:", 5) == 0); |
|| (strncmp(XDisplayName(x_display_name), "unix:", 5) == 0); |
| 684 |
|
|
| 685 |
|
// Init keycode translation |
| 686 |
|
keycode_init(); |
| 687 |
|
|
| 688 |
// Init variables |
// Init variables |
| 689 |
private_data = NULL; |
private_data = NULL; |
| 690 |
cur_mode = 0; // Window 640x480 |
cur_mode = 0; // Window 640x480 |
| 1156 |
return -1; |
return -1; |
| 1157 |
} |
} |
| 1158 |
|
|
| 1159 |
static int event2keycode(XKeyEvent *ev) |
static int event2keycode(XKeyEvent &ev) |
| 1160 |
{ |
{ |
| 1161 |
KeySym ks; |
KeySym ks; |
| 1162 |
int as; |
int as; |
| 1163 |
int i = 0; |
int i = 0; |
| 1164 |
|
|
| 1165 |
do { |
do { |
| 1166 |
ks = XLookupKeysym(ev, i++); |
ks = XLookupKeysym(&ev, i++); |
| 1167 |
as = kc_decode(ks); |
as = kc_decode(ks); |
| 1168 |
if (as != -1) |
if (as != -1) |
| 1169 |
return as; |
return as; |
| 1206 |
|
|
| 1207 |
// Keyboard |
// Keyboard |
| 1208 |
case KeyPress: { |
case KeyPress: { |
| 1209 |
int code; |
int code = event2keycode(event.xkey); |
| 1210 |
if ((code = event2keycode((XKeyEvent *)&event)) != -1) { |
if (use_keycodes && code != -1) |
| 1211 |
|
code = keycode_table[event.xkey.keycode & 0xff]; |
| 1212 |
|
if (code != -1) { |
| 1213 |
if (!emul_suspended) { |
if (!emul_suspended) { |
| 1214 |
ADBKeyDown(code); |
ADBKeyDown(code); |
| 1215 |
if (code == 0x36) |
if (code == 0x36) |
| 1222 |
break; |
break; |
| 1223 |
} |
} |
| 1224 |
case KeyRelease: { |
case KeyRelease: { |
| 1225 |
int code; |
int code = event2keycode(event.xkey); |
| 1226 |
if ((code = event2keycode((XKeyEvent *)&event)) != -1) { |
if (use_keycodes && code != 1) |
| 1227 |
|
code = keycode_table[event.xkey.keycode & 0xff]; |
| 1228 |
|
if (code != -1) { |
| 1229 |
ADBKeyUp(code); |
ADBKeyUp(code); |
| 1230 |
if (code == 0x36) |
if (code == 0x36) |
| 1231 |
ctrl_down = false; |
ctrl_down = false; |