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

Comparing SheepShaver/src/Unix/video_x.cpp (file contents):
Revision 1.5 by gbeauche, 2003-11-20T16:24:57Z vs.
Revision 1.6 by gbeauche, 2003-11-21T17:01:33Z

# Line 18 | Line 18
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  
21 + #include "sysdeps.h"
22 +
23   #include <X11/Xlib.h>
24   #include <X11/Xutil.h>
25   #include <X11/keysym.h>
26   #include <X11/extensions/XShm.h>
27   #include <sys/ipc.h>
28   #include <sys/shm.h>
29 < #include <pthread.h>
29 > #include <errno.h>
30 >
31 > #ifdef HAVE_PTHREADS
32 > # 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  
29 #include "sysdeps.h"
43   #include "main.h"
44   #include "adb.h"
45   #include "prefs.h"
# Line 38 | Line 51
51   #define DEBUG 0
52   #include "debug.h"
53  
41 #ifdef ENABLE_XF86_DGA
42 #include <X11/extensions/xf86dga.h>
43 #endif
44
45 #ifdef ENABLE_XF86_VIDMODE
46 #include <X11/extensions/xf86vmode.h>
47 #endif
54  
55 + // Constants
56 + const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes";
57  
58   // Global variables
59   static int32 frame_skip;
# Line 74 | Line 82 | static bool emerg_quit = false;                                // Fl
82   static bool emul_suspended = false;                     // Flag: emulator suspended
83   static Window suspend_win;                                      // "Suspend" window
84   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
89   static int screen;                                                      // Screen number
# Line 534 | Line 544 | static void close_display(void)
544   *  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)
613   {
614          if (allow & test) {
# Line 607 | Line 682 | bool VideoInit(void)
682          local_X11 = (strncmp(XDisplayName(x_display_name), ":", 1) == 0)
683                   || (strncmp(XDisplayName(x_display_name), "unix:", 5) == 0);
684      
685 +        // Init keycode translation
686 +        keycode_init();
687 +
688          // Init variables
689          private_data = NULL;
690          cur_mode = 0;   // Window 640x480
# Line 1078 | Line 1156 | static int kc_decode(KeySym ks)
1156          return -1;
1157   }
1158  
1159 < static int event2keycode(XKeyEvent *ev)
1159 > static int event2keycode(XKeyEvent &ev)
1160   {
1161          KeySym ks;
1162          int as;
1163          int i = 0;
1164  
1165          do {
1166 <                ks = XLookupKeysym(ev, i++);
1166 >                ks = XLookupKeysym(&ev, i++);
1167                  as = kc_decode(ks);
1168                  if (as != -1)
1169                          return as;
# Line 1128 | Line 1206 | static void handle_events(void)
1206  
1207                          // Keyboard
1208                          case KeyPress: {
1209 <                                int code;
1210 <                                if ((code = event2keycode((XKeyEvent *)&event)) != -1) {
1209 >                                int code = event2keycode(event.xkey);
1210 >                                if (use_keycodes && code != -1)
1211 >                                        code = keycode_table[event.xkey.keycode & 0xff];
1212 >                                if (code != -1) {
1213                                          if (!emul_suspended) {
1214                                                  ADBKeyDown(code);
1215                                                  if (code == 0x36)
# Line 1142 | Line 1222 | static void handle_events(void)
1222                                  break;
1223                          }
1224                          case KeyRelease: {
1225 <                                int code;
1226 <                                if ((code = event2keycode((XKeyEvent *)&event)) != -1) {
1225 >                                int code = event2keycode(event.xkey);
1226 >                                if (use_keycodes && code != 1)
1227 >                                        code = keycode_table[event.xkey.keycode & 0xff];
1228 >                                if (code != -1) {
1229                                          ADBKeyUp(code);
1230                                          if (code == 0x36)
1231                                                  ctrl_down = false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines