Changeset 93

Show
Ignore:
Timestamp:
09/15/07 01:06:09 (2 years ago)
Author:
mike
Message:

[fix] remove crashed/stray guests from doServer (#15)
[fix] Q Control: StopPC Icon is a forcequit if task is not responding or doServer is not responding (#15)
[fix] Fullscreen: alt-tabing back to Q brings you back to FS Guest (#32)
[fix] Fullscreen: switching animation always vertical
[fix] Fullscreen: honor aspect ratio, only factors of 1/1.25/1.5/1.75/2.0/3.0/4.0... (#18)
[fix] doServer: added missing dealloc
[fix] quartz: panther compiling
[fix] quartz: small drawspeed improvements
[fix] backport bgr support for bigendians (andreasf) (#14)
[new] Q Control: EditPC can be used (read only) when guest is running (#23)
[new] Q Control: commandline as tooltips of guests (#23)
[new] Q icon

Location:
trunk
Files:
1 added
1 removed
16 modified

Legend:

Unmodified
Added
Removed
  • trunk/build_i386.sh

    r86 r93  
    3535patch -p0 -u < ../../q/patches/q_host-cocoa_02.diff 
    3636 
    37 #qemu hotfix for qcow2 
     37#qemu cvs backport for qcow2 
    3838patch -p0 -u < ../../q/patches/qemu-0.9.0-qcow2.diff 
     39 
     40#qemu cvs backport rgb support for bigendian 
     41patch -p1 -u < ../../q/patches/qemu-0.9.0-big_endian_display4.diff 
    3942 
    4043#qemu gcc4 patches 
     
    5053 
    5154patch -p1 -u < ../../q/patches/qemu-0.8.0-osx-bugfix.patch 
    52  
    53 #qemu rgb support for intel 
    54 cd hw 
    55 patch -p0 -u < ../../../q/patches/q_vga.c_02.diff 
    56 cd .. 
    5755 
    5856#qemu add 2nd Bootdevice 
  • trunk/build_ppc.sh

    r86 r93  
    3737patch -p0 -u < ../../q/patches/q_host-cocoa_02.diff 
    3838 
    39 #qemu hotfix for qcow2 
     39#qemu cvs backport for qcow2 
    4040patch -p0 -u < ../../q/patches/qemu-0.9.0-qcow2.diff 
    4141 
    42 #qemu rgb support for intel 
    43 cd hw 
    44 #patch -p0 -u < ../../../q/patches/q_vga.c_02.diff 
    45 cd .. 
     42#qemu cvs backport rgb support for bigendian 
     43patch -p1 -u < ../../q/patches/qemu-0.9.0-big_endian_display4.diff 
    4644 
    4745#qemu add 2nd Bootdevice 
  • trunk/changelog.txt

    r90 r93  
    1 Q-0.9.0d90 
     1Q-0.9.0d93 
     2[fix] remove crashed/stray guests from doServer (#15) 
     3[fix] Q Control: StopPC Icon is a forcequit if task is not responding or doServer is not responding (#15) 
     4[fix] Fullscreen: alt-tabing back to Q brings you back to FS Guest (#32) 
     5[fix] Fullscreen: switching animation always vertical 
     6[fix] Fullscreen: honor aspect ratio, only factors of 1/1.25/1.5/1.75/2.0/3.0/4.0... (#18) 
     7[fix] doServer: added missing dealloc 
     8[fix] quartz: panther compiling 
     9[fix] quartz: small drawspeed improvements 
     10[fix] backport bgr support for bigendians (andreasf) (#14) 
     11[new] Q Control: EditPC can be used (read only) when guest is running (#23) 
     12[new] Q Control: commandline as tooltips of guests (#23) 
     13[new] Q icon 
     14 
     15Q-0.9.0d92 
    216[fix] ARM emulation on Q GUI breaks (Chocobo) (#17) 
    317[fix] Editing a PC inserts incorrect spaces into argument (andreasf) (#13) 
    418[fix] Starting guest can display screenshot of previous session (andreasf) (#28) 
    519[fix] Edit PC window title inconsistent (andreasf) (#26) 
     20 
     21Q-0.9.0d91 
     22branch Q-0.9.0a89 
    623 
    724Q-0.9.0d89 
  • trunk/host-cocoa/cocoaQemu.m

    r90 r93  
    33 *  
    44 * Copyright (c) 2005 - 2007 Pierre d'Herbemont 
    5  *                                                      Mike Kronenberg 
    6  *                                                      many code/inspiration from SDL 1.2 code (LGPL) 
     5 *                          Mike Kronenberg 
     6 *                          many code/inspiration from SDL 1.2 code (LGPL) 
    77 *  
    88 * Permission is hereby granted, free of charge, to any person obtaining a copy 
     
    4949/* 
    5050 ------------------------------------------------------ 
    51         Headers 
    52          
     51    Headers 
     52     
    5353 ------------------------------------------------------ 
    5454*/ 
    5555/* 
    5656 ------------------------------------------------------ 
    57         QemuCocoa Video Driver 
     57    QemuCocoa Video Driver 
    5858 ------------------------------------------------------ 
    5959*/ 
     
    6666/* 
    6767 ------------------------------------------------------ 
    68         QemuCocoa CD-ROM Driver 
     68    QemuCocoa CD-ROM Driver 
    6969 ------------------------------------------------------ 
    7070*/ 
     
    7676/* 
    7777 ------------------------------------------------------ 
    78         Implementations 
    79          
     78    Implementations 
     79     
    8080 ------------------------------------------------------ 
    8181*/ 
    8282/* 
    8383 ------------------------------------------------------ 
    84         cocoaQemu 
     84    cocoaQemu 
    8585 ------------------------------------------------------ 
    8686*/ 
     
    8989-(id) init 
    9090{ 
    91 //      NSLog(@"cocoaQemu: init"); 
    92  
    93         if ((self = [super init])) { 
    94                 /* set allowed filetypes */ 
    95                 fileTypes = [[NSArray arrayWithObjects:@"qcow2", @"qcow", @"raw", @"cow", @"vmdk", @"cloop", @"img", @"iso", @"dsk", @"dmg", @"cdr", @"toast", @"flp", @"fs", nil] retain]; 
    96  
    97                 /* pc */ 
    98                 pcName = [@"" retain]; 
    99                 pcWindowName = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"] retain]; 
    100                 pcPath = [[@"~/Documents/QEMU/temp.qvm" stringByExpandingTildeInPath] retain]; 
    101                 pcTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector( liveThumbnail ) userInfo:nil repeats:YES]; 
    102                 [self liveThumbnail]; 
    103                 pcDialogs = YES; 
    104                 pc = self; 
    105  
    106                 /* set openGL as default */ 
    107                 pcOpenGLView = true; 
    108  
    109                 /* setup progressWindow */ 
    110                 progressWindow = [[cocoaQemuProgressWindow alloc] init]; 
    111  
    112                 /* setup Q distributed object Client */ 
    113                 qdoserver = [[NSConnection rootProxyForConnectionWithRegisteredName:@"qdoserver" host:nil] retain]; 
    114                 [qdoserver setProtocolForProxy:@protocol(cocoaControlDOServerProto)]; 
    115                  
    116                 /* Pasteboard *//* 
    117                 bios_dir = [[NSString stringWithFormat:@"%@/qemu", [[NSBundle mainBundle] resourcePath]] cString]; 
    118                 kbd_layout = init_keyboard_layout("de-ch"); 
    119 */               
    120                 return self; 
    121         } 
    122         return nil; 
     91//  NSLog(@"cocoaQemu: init"); 
     92 
     93    if ((self = [super init])) { 
     94        /* set allowed filetypes */ 
     95        fileTypes = [[NSArray arrayWithObjects:@"qcow2", @"qcow", @"raw", @"cow", @"vmdk", @"cloop", @"img", @"iso", @"dsk", @"dmg", @"cdr", @"toast", @"flp", @"fs", nil] retain]; 
     96 
     97        /* pc */ 
     98        pcName = [@"" retain]; 
     99        pcWindowName = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"] retain]; 
     100        pcPath = [[@"~/Documents/QEMU/temp.qvm" stringByExpandingTildeInPath] retain]; 
     101        pcTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector( liveThumbnail ) userInfo:nil repeats:YES]; 
     102        [self liveThumbnail]; 
     103        pcDialogs = YES; 
     104        pc = self; 
     105 
     106        /* set openGL as default */ 
     107        pcOpenGLView = true; 
     108 
     109        /* setup progressWindow */ 
     110        progressWindow = [[cocoaQemuProgressWindow alloc] init]; 
     111 
     112        /* setup Q distributed object Client */ 
     113        qdoserver = [[NSConnection rootProxyForConnectionWithRegisteredName:@"qdoserver" host:nil] retain]; 
     114        [qdoserver setProtocolForProxy:@protocol(cocoaControlDOServerProto)]; 
     115 
     116        /* Pasteboard *//* 
     117        bios_dir = [[NSString stringWithFormat:@"%@/qemu", [[NSBundle mainBundle] resourcePath]] cString]; 
     118        kbd_layout = init_keyboard_layout("de-ch"); 
     119*/       
     120        return self; 
     121    } 
     122    return nil; 
    123123} 
    124124 
    125125- (void) dealloc 
    126126{ 
    127 //      NSLog(@"cocoaQemu: dealloc"); 
    128  
    129         [super dealloc]; 
     127//  NSLog(@"cocoaQemu: dealloc"); 
     128 
     129    [super dealloc]; 
    130130} 
    131131 
     
    133133- (BOOL) guestOrderFrontRegardless 
    134134{ 
    135 //      NSLog(@"cocoaQemu: guestOrderFrontRegardless"); 
    136  
    137         [pcWindow orderFrontRegardless]; 
    138         return true; 
     135//  NSLog(@"cocoaQemu: guestOrderFrontRegardless"); 
     136 
     137    [pcWindow orderFrontRegardless]; 
     138    return true; 
    139139} 
    140140 
    141141- (int) guestWindowLevel 
    142142{ 
    143 //      NSLog(@"cocoaQemu: guestWindowLevel"); 
    144  
    145         return [pcWindow level]; 
     143//  NSLog(@"cocoaQemu: guestWindowLevel"); 
     144 
     145    return [pcWindow level]; 
    146146} 
    147147 
    148148- (int) guestWindowNumber 
    149149{ 
    150 //      NSLog(@"cocoaQemu: guestWindowNumber"); 
    151  
    152         return [pcWindow windowNumber]; 
     150//  NSLog(@"cocoaQemu: guestWindowNumber"); 
     151 
     152    return [pcWindow windowNumber]; 
    153153} 
    154154 
    155155- (BOOL) guestOrderWindow:(NSWindowOrderingMode)place relativeTo:(int)otherWindowNumber 
    156156{ 
    157 //      NSLog(@"cocoaQemu: guestOrderWindow"); 
    158  
    159         [pcWindow orderWindow:place relativeTo:otherWindowNumber]; 
    160         return true; 
     157//  NSLog(@"cocoaQemu: guestOrderWindow"); 
     158 
     159    [pcWindow orderWindow:place relativeTo:otherWindowNumber]; 
     160    return true; 
    161161} 
    162162 
    163163- (BOOL) guestHide; 
    164164{ 
    165 //      NSLog(@"cocoaQemu: guestHide"); 
    166  
    167         [NSApp hide:self]; 
    168         return true; 
     165//  NSLog(@"cocoaQemu: guestHide"); 
     166 
     167    [NSApp hide:self]; 
     168    return true; 
    169169} 
    170170 
    171171- (BOOL) guestUnhide; 
    172172{ 
    173 //      NSLog(@"cocoaQemu: guestUnhide"); 
    174  
    175         [NSApp unhide:self]; 
    176         return true; 
     173//  NSLog(@"cocoaQemu: guestUnhide"); 
     174 
     175    [NSApp unhide:self]; 
     176    return true; 
    177177} 
    178178 
    179179- (BOOL) guestPause; 
    180180{ 
    181 //      NSLog(@"cocoaQemu: guestPause"); 
    182  
    183         [self pausePlay:self]; 
    184         return true; 
     181//  NSLog(@"cocoaQemu: guestPause"); 
     182 
     183    [self pausePlay:self]; 
     184    return true; 
    185185} 
    186186 
    187187- (BOOL) guestStop; 
    188188{ 
    189 //      NSLog(@"cocoaQemu: guestStop"); 
    190  
    191         [self shutdownPC]; 
    192         return true; 
     189//  NSLog(@"cocoaQemu: guestStop"); 
     190 
     191    [self shutdownPC]; 
     192    return true; 
    193193} 
    194194 
     
    196196- (NSString *) pcName 
    197197{ 
    198 //      NSLog(@"cocoaQemu: pcName"); 
    199  
    200         return pcName; 
     198//  NSLog(@"cocoaQemu: pcName"); 
     199 
     200    return pcName; 
    201201} 
    202202 
    203203- (NSString *) pcWindowName 
    204204{ 
    205 //      NSLog(@"cocoaQemu: pcWindowName"); 
    206  
    207         return pcWindowName; 
     205//  NSLog(@"cocoaQemu: pcWindowName"); 
     206 
     207    return pcWindowName; 
    208208} 
    209209 
    210210-(NSString *) smbPath 
    211211{ 
    212 //      NSLog(@"cocoaQemu: smbPath"); 
    213  
    214         return smbPath; 
     212//  NSLog(@"cocoaQemu: smbPath"); 
     213 
     214    return smbPath; 
    215215} 
    216216 
    217217- (id) qdoserver 
    218218{ 
    219 //      NSLog(@"cocoaQemu: qdoserver"); 
     219//  NSLog(@"cocoaQemu: qdoserver"); 
    220220 
    221221    return qdoserver; 
     
    224224- (BOOL) fullscreen 
    225225{ 
    226 //      NSLog(@"cocoaQemu: fullscreen"); 
    227  
    228         return fullscreen; 
     226//  NSLog(@"cocoaQemu: fullscreen"); 
     227 
     228    return fullscreen; 
    229229} 
    230230 
    231231- (void) setFullscreen:(BOOL)val 
    232232{ 
    233 //      NSLog(@"cocoaQemu: setFullscreen"); 
    234  
    235         fullscreen = val; 
     233//  NSLog(@"cocoaQemu: setFullscreen"); 
     234 
     235    fullscreen = val; 
    236236} 
    237237 
     
    259259- (BOOL) grab 
    260260{ 
    261 //      NSLog(@"cocoaQemu: grab"); 
    262  
    263         return grab; 
     261//  NSLog(@"cocoaQemu: grab"); 
     262 
     263    return grab; 
    264264} 
    265265 
    266266- (BOOL) absolute_enabled 
    267267{ 
    268 //      NSLog(@"cocoaQemu: absolute_enabled"); 
    269  
    270         return absolute_enabled; 
     268//  NSLog(@"cocoaQemu: absolute_enabled"); 
     269 
     270    return absolute_enabled; 
    271271} 
    272272 
    273273- (BOOL) tablet_enabled 
    274274{ 
    275 //      NSLog(@"cocoaQemu: tablet_enabled"); 
    276  
    277         return tablet_enabled; 
     275//  NSLog(@"cocoaQemu: tablet_enabled"); 
     276 
     277    return tablet_enabled; 
    278278} 
    279279 
    280280- (BOOL) wMStopWhenInactive 
    281281{ 
    282 //      NSLog(@"cocoaQemu: wMStopWhenInactive"); 
    283  
    284         return WMStopWhenInactive; 
     282//  NSLog(@"cocoaQemu: wMStopWhenInactive"); 
     283 
     284    return WMStopWhenInactive; 
    285285} 
    286286 
    287287- (BOOL) wMPaused 
    288288{ 
    289 //      NSLog(@"cocoaQemu: wMPaused"); 
    290  
    291         return vm_running; 
     289//  NSLog(@"cocoaQemu: wMPaused"); 
     290 
     291    return vm_running; 
    292292} 
    293293 
    294294- (BOOL) wMPausedByUser 
    295295{ 
    296 //      NSLog(@"cocoaQemu: wMPausedByUser"); 
    297  
    298         return wMPausedByUser; 
     296//  NSLog(@"cocoaQemu: wMPausedByUser"); 
     297 
     298    return wMPausedByUser; 
    299299} 
    300300 
    301301- (void) setGrab:(BOOL)val 
    302302{ 
    303 //      NSLog(@"cocoaQemu: setGrab"); 
    304  
    305         grab = val; 
     303//  NSLog(@"cocoaQemu: setGrab"); 
     304 
     305    grab = val; 
    306306} 
    307307 
    308308- (void) setAbsolute_enabled:(BOOL)val 
    309309{ 
    310 //      NSLog(@"cocoaQemu: setAbsolute_enabled"); 
    311  
    312         absolute_enabled = val; 
     310//  NSLog(@"cocoaQemu: setAbsolute_enabled"); 
     311 
     312    absolute_enabled = val; 
    313313} 
    314314 
    315315- (void) setTablet_enabled:(BOOL)val 
    316316{ 
    317 //      NSLog(@"cocoaQemu: setTablet_enabled"); 
    318  
    319         tablet_enabled = val; 
     317//  NSLog(@"cocoaQemu: setTablet_enabled"); 
     318 
     319    tablet_enabled = val; 
    320320} 
    321321 
    322322- (void) grabMouse 
    323323{ 
    324 //      NSLog(@"cocoaQemu: grabMouse"); 
    325  
    326         if (!grab) { 
    327                 grab = YES; 
    328                 [pcWindow setTitle: [NSString stringWithFormat: NSLocalizedStringFromTable(@"grabMouse:title", @"Localizable", @"cocoaQemu"), pcWindowName, pcName]]; 
    329                 [NSCursor hide]; 
    330                 CGAssociateMouseAndMouseCursorPosition ( FALSE ); 
    331         } 
     324//  NSLog(@"cocoaQemu: grabMouse"); 
     325 
     326    if (!grab) { 
     327        grab = YES; 
     328        [pcWindow setTitle: [NSString stringWithFormat: NSLocalizedStringFromTable(@"grabMouse:title", @"Localizable", @"cocoaQemu"), pcWindowName, pcName]]; 
     329        [NSCursor hide]; 
     330        CGAssociateMouseAndMouseCursorPosition ( FALSE ); 
     331    } 
    332332} 
    333333 
    334334- (void) ungrabMouse 
    335335{ 
    336 //      NSLog(@"cocoaQemu: ungrabMouse"); 
    337  
    338         if (grab) { 
    339                 grab = NO; 
    340                 [pcWindow setTitle: [NSString stringWithFormat:@"%@ - %@", pcWindowName, pcName]]; 
    341                 [NSCursor unhide]; 
    342                 CGAssociateMouseAndMouseCursorPosition ( TRUE ); 
    343         } 
     336//  NSLog(@"cocoaQemu: ungrabMouse"); 
     337 
     338    if (grab) { 
     339        grab = NO; 
     340        [pcWindow setTitle: [NSString stringWithFormat:@"%@ - %@", pcWindowName, pcName]]; 
     341        [NSCursor unhide]; 
     342        CGAssociateMouseAndMouseCursorPosition ( TRUE ); 
     343    } 
    344344} 
    345345 
    346346- (int) modifierAtIndex:(int)index 
    347347{ 
    348 //      NSLog(@"cocoaQemu: modifierAtIndex"); 
    349  
    350         return modifiers_state[index]; 
     348//  NSLog(@"cocoaQemu: modifierAtIndex"); 
     349 
     350    return modifiers_state[index]; 
    351351} 
    352352 
    353353- (void) setModifierAtIndex:(int)index to:(int)value 
    354354{ 
    355 //      NSLog(@"cocoaQemu: setModifierAtIndex"); 
    356  
    357         modifiers_state[index] = value; 
     355//  NSLog(@"cocoaQemu: setModifierAtIndex"); 
     356 
     357    modifiers_state[index] = value; 
    358358} 
    359359 
    360360- (void) resetModifiers 
    361361{ 
    362 //      NSLog(@"cocoaQemu: resetModifiers"); 
    363  
    364         int i; 
    365         for(i = 0; i < 256; i++) { 
    366                 if (modifiers_state[i]) { 
    367                         if (i & 0x80) 
    368                                 kbd_put_keycode(0xe0); 
    369                         kbd_put_keycode(i | 0x80); 
    370                         modifiers_state[i] = 0; 
    371                 } 
    372         } 
     362//  NSLog(@"cocoaQemu: resetModifiers"); 
     363 
     364    int i; 
     365    for(i = 0; i < 256; i++) { 
     366        if (modifiers_state[i]) { 
     367            if (i & 0x80) 
     368                kbd_put_keycode(0xe0); 
     369            kbd_put_keycode(i | 0x80); 
     370            modifiers_state[i] = 0; 
     371        } 
     372    } 
    373373} 
    374374 
    375375- (id) pcWindow 
    376376{ 
    377 //      NSLog(@"cocoaQemu: pcWindow"); 
    378  
    379         return pcWindow; 
     377//  NSLog(@"cocoaQemu: pcWindow"); 
     378 
     379    return pcWindow; 
    380380} 
    381381 
    382382- (id) contentView 
    383383{ 
    384 //      NSLog(@"cocoaQemu: contentView"); 
    385  
    386         return contentView; 
     384//  NSLog(@"cocoaQemu: contentView"); 
     385 
     386    return contentView; 
    387387} 
    388388 
    389389- (void) liveThumbnail 
    390390{ 
    391 //      NSLog(@"cocoaQemu: liveThumbnail <%@>", pcPath); 
    392  
    393         if (![pcName isEqual:@""]) { 
    394                 /* create liveThumbnail */ 
    395                 NSBitmapImageRep *bitmapImageRep = [NSBitmapImageRep imageRepWithData: [[contentView screenshot:NSMakeSize(100,75)] TIFFRepresentation]]; 
    396                 NSData *data = [bitmapImageRep representationUsingType: NSPNGFileType properties: nil]; 
    397                 [data writeToFile: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath] atomically: YES]; 
    398         } 
     391//  NSLog(@"cocoaQemu: liveThumbnail <%@>", pcPath); 
     392 
     393    if (![pcName isEqual:@""]) { 
     394        /* create liveThumbnail */ 
     395        NSBitmapImageRep *bitmapImageRep = [NSBitmapImageRep imageRepWithData: [[contentView screenshot:NSMakeSize(100,75)] TIFFRepresentation]]; 
     396        NSData *data = [bitmapImageRep representationUsingType: NSPNGFileType properties: nil]; 
     397        [data writeToFile: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath] atomically: YES]; 
     398    } 
    399399} 
    400400 
    401401- (void) stopVM 
    402402{ 
    403 //      NSLog(@"cocoaQemu: stopVM"); 
    404  
    405         if (vm_running) 
    406                 vm_stop(0); 
    407                 [pcWindow display]; 
     403//  NSLog(@"cocoaQemu: stopVM"); 
     404 
     405    if (vm_running) 
     406        vm_stop(0); 
     407    [pcWindow display]; 
    408408} 
    409409 
    410410- (void) startVM 
    411411{ 
    412 //      NSLog(@"cocoaQemu: startVM"); 
    413  
    414         if (!vm_running) 
    415                 vm_start(); 
    416                 [pcWindow display]; 
     412//  NSLog(@"cocoaQemu: startVM"); 
     413 
     414    if (!vm_running) 
     415        vm_start(); 
     416    [pcWindow display]; 
    417417} 
    418418 
    419419- (void) saveVM 
    420420{ 
    421 //      NSLog(@"cocoaQemu: saveVM"); 
    422  
    423         /* show progressWindow */ 
    424         [progressWindow showProgressWindow:pcWindow text: NSLocalizedStringFromTable(@"saveVM:text", @"Localizable", @"cocoaQemu") name:pcName]; 
    425          
    426         /* stop VM */ 
    427         vm_stop(0); 
    428          
    429         /* generate Preview */ 
    430         NSBitmapImageRep *bitmapImageRep = [NSBitmapImageRep imageRepWithData: [[contentView screenshot:NSMakeSize(100,75)] TIFFRepresentation]]; 
    431         NSData *data = [bitmapImageRep representationUsingType: NSPNGFileType properties: nil]; 
    432         [data writeToFile: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath] atomically: YES]; 
    433  
    434         /* save VM */ 
    435 //      qemu_savevm( [[NSString stringWithFormat: @"%@/saved.vm", pcPath] cString]); 
    436         do_savevm([@"kju" cString]); 
    437          
    438         /* hide progressWindow */ 
    439         [progressWindow hideProgressWindow]; 
     421//  NSLog(@"cocoaQemu: saveVM"); 
     422 
     423    /* show progressWindow */ 
     424    [progressWindow showProgressWindow:pcWindow text: NSLocalizedStringFromTable(@"saveVM:text", @"Localizable", @"cocoaQemu") name:pcName]; 
     425 
     426    /* stop VM */ 
     427    vm_stop(0); 
     428 
     429    /* generate Preview */ 
     430    NSBitmapImageRep *bitmapImageRep = [NSBitmapImageRep imageRepWithData: [[contentView screenshot:NSMakeSize(100,75)] TIFFRepresentation]]; 
     431    NSData *data = [bitmapImageRep representationUsingType: NSPNGFileType properties: nil]; 
     432    [data writeToFile: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath] atomically: YES]; 
     433 
     434    /* save VM */ 
     435    do_savevm([@"kju" cString]); 
     436 
     437    /* hide progressWindow */ 
     438    [progressWindow hideProgressWindow]; 
    440439} 
    441440 
    442441- (void) closeProgressWindow 
    443442{ 
    444 //      NSLog(@"cocoaQemu: closeProgressWindow"); 
    445          
    446         if (vm_running) { 
    447                 [progressWindowTimer invalidate]; 
    448                 [progressWindow hideProgressWindow]; 
    449                  
    450         } 
     443//  NSLog(@"cocoaQemu: closeProgressWindow"); 
     444     
     445    if (vm_running) { 
     446        [progressWindowTimer invalidate]; 
     447        [progressWindow hideProgressWindow]; 
     448         
     449    } 
    451450} 
    452451 
     
    454453- (void) startPCWithArgs:(id)arguments 
    455454{ 
    456 //      NSLog(@"cocoaQemu: startPCWithArgs"); 
    457  
    458         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    459          
    460         /* overrun defaults for bios_dir, so we can run qemu everywhere */ 
    461         bios_dir = [[NSString stringWithFormat:@"%@/qemu", [[NSBundle mainBundle] resourcePath]] cString]; 
    462  
    463         /* setup QEMU Window */ 
    464         pcWindow = [[cocoaQemuWindow  alloc] initWithSender:self]; 
    465         if ([arguments containsObject:@"-cocoaquickdraw"]) { 
    466                 contentView = [[[cocoaQemuQuickDrawView alloc] initWithFrame:NSMakeRect(0,0,640,400) sender:self] autorelease]; 
    467         } else if ([arguments containsObject:@"-cocoaquartz"]) { 
    468                 contentView = [[[cocoaQemuQuartzView alloc] initWithFrame:NSMakeRect(0,0,640,400) sender:self] autorelease]; 
    469         } else { 
    470                 contentView = [[[cocoaQemuOpenGLView alloc] initWithFrame:NSMakeRect(0,0,640,400) sender:self] autorelease]; 
    471         } 
    472          
    473         [contentView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; 
    474          
    475         /* scrollview */ 
    476 /*      NSScrollView * scrollView = [[NSScrollView alloc] init]; 
    477         [scrollView setHasVerticalScroller:TRUE]; 
    478         [scrollView setHasHorizontalScroller:TRUE]; 
    479         [scrollView setAutohidesScrollers:FALSE]; 
    480         [scrollView setScrollsDynamically:TRUE]; // 
    481         [scrollView setBorderType:NSLineBorder]; 
    482         [scrollView setDocumentView:contentView]; 
    483         [pcWindow setContentView:scrollView];*/ 
    484  
    485          
    486         [pcWindow setContentView:contentView]; 
    487         [pcWindow setMyContentView:contentView]; 
    488  
    489         /* filter cocoa arguments */ 
    490         int i; 
    491         int i2 = 0; 
    492         char **argv2 = (char**)malloc( sizeof(char*)*[arguments count] ); 
    493  
    494         for (i = 0; i < [arguments count]; i++) { 
    495 //              NSLog(@"Arguments: %@", [arguments objectAtIndex:i]); 
    496                  
    497                 if ( [[arguments objectAtIndex:i] isEqual:@"-cocoaquickdraw"] ) { 
    498                         pcOpenGLView = false; 
    499                 } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoaquartz"] ) { 
    500                         pcOpenGLView = false; 
    501                 } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoaname"] ) { 
    502                         i++; 
    503                         pcName = [arguments objectAtIndex:i]; 
    504                 } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoawindowname"] ) { 
    505                         i++; 
    506                         pcWindowName = [arguments objectAtIndex:i]; 
    507                 } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoapath"] ) { 
    508                         i++; 
    509                         pcPath = [arguments objectAtIndex:i]; 
    510                 } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoalivethumbnail"] ) { 
    511                 } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoanodialogs"] ) { 
    512                         pcDialogs = NO; 
    513                         NSLog(@"pcDialogs: %d\n", pcDialogs); 
    514                 } else if ( [[arguments objectAtIndex:i] isEqual:@"-wmstopwheninactive"] ) { 
    515                         WMStopWhenInactive = true; 
    516                 } else if ( [[arguments objectAtIndex:i] isEqual:@"-full-screen"] ) { 
    517                         fullscreen = [contentView toggleFullScreen]; 
    518                 } else if ( [[arguments objectAtIndex:i] isEqual:@"-cdrom"] ) { 
    519                         if ( [[arguments objectAtIndex:i+1] isEqual:@"/dev/cdrom"] ) { 
    520                                 kern_return_t kernResult; 
    521                                 io_iterator_t mediaIterator; 
    522                                 char bsdPath[MAXPATHLEN]; 
    523                                  
    524                                 kernResult = FindEjectableCDMedia( &mediaIterator ); 
    525                                 kernResult = GetBSDPath( mediaIterator, bsdPath, sizeof( bsdPath ) ); 
    526                                  
    527                                 if ( bsdPath[0] == '\0' ) { 
    528                                         i++; 
    529                                 } else { 
    530                                         asprintf(&argv2[i2], "%s", [[arguments objectAtIndex:i] cString]); 
    531                                         i2++; 
    532                                         i++; 
    533                                         asprintf(&argv2[i2], "%s", [[arguments objectAtIndex:i] cString]); 
    534                                         i2++; 
    535                                 } 
    536                                  
    537                                 if ( mediaIterator ) 
    538                                         IOObjectRelease( mediaIterator ); 
    539                         } else { 
    540                                 asprintf(&argv2[i2], "%s", [[arguments objectAtIndex:i] cString]); 
    541                                 i2++; 
    542                                 i++; 
    543                                 asprintf(&argv2[i2], "%s", [[arguments objectAtIndex:i] cString]); 
    544                                 i2++; 
    545                         } 
    546                 } else { 
    547                         if ([[arguments objectAtIndex:i] isEqual:@"-smb"]) 
    548                                 smbPath = [[NSString alloc] initWithString:[arguments objectAtIndex:i + 1]]; 
    549                          
    550                         if ([[arguments objectAtIndex:i] isEqual:@"-hda"]) 
     455//  NSLog(@"cocoaQemu: startPCWithArgs"); 
     456 
     457    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
     458 
     459    /* overrun defaults for bios_dir, so we can run qemu everywhere */ 
     460    bios_dir = [[NSString stringWithFormat:@"%@/qemu", [[NSBundle mainBundle] resourcePath]] cString]; 
     461 
     462    /* setup QEMU Window */ 
     463    pcWindow = [[cocoaQemuWindow  alloc] initWithSender:self]; 
     464    if ([arguments containsObject:@"-cocoaquickdraw"]) { 
     465        contentView = [[[cocoaQemuQuickDrawView alloc] initWithFrame:NSMakeRect(0,0,640,400) sender:self] autorelease]; 
     466    } else if ([arguments containsObject:@"-cocoaquartz"]) { 
     467        contentView = [[[cocoaQemuQuartzView alloc] initWithFrame:NSMakeRect(0,0,640,400) sender:self] autorelease]; 
     468    } else { 
     469        contentView = [[[cocoaQemuOpenGLView alloc] initWithFrame:NSMakeRect(0,0,640,400) sender:self] autorelease]; 
     470    } 
     471    [contentView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; 
     472 
     473    /* scrollview */ 
     474/*  NSScrollView * scrollView = [[NSScrollView alloc] init]; 
     475    [scrollView setHasVerticalScroller:TRUE]; 
     476    [scrollView setHasHorizontalScroller:TRUE]; 
     477    [scrollView setAutohidesScrollers:FALSE]; 
     478    [scrollView setScrollsDynamically:TRUE]; // 
     479    [scrollView setBorderType:NSLineBorder]; 
     480    [scrollView setDocumentView:contentView]; 
     481    [pcWindow setContentView:scrollView];*/ 
     482 
     483     
     484    [pcWindow setContentView:contentView]; 
     485    [pcWindow setMyContentView:contentView]; 
     486 
     487    /* filter cocoa arguments */ 
     488    int i; 
     489    int i2 = 0; 
     490    char **argv2 = (char**)malloc( sizeof(char*)*[arguments count] ); 
     491 
     492    for (i = 0; i < [arguments count]; i++) { 
     493//      NSLog(@"Arguments: %@", [arguments objectAtIndex:i]); 
     494         
     495        if ( [[arguments objectAtIndex:i] isEqual:@"-cocoaquickdraw"] ) { 
     496            pcOpenGLView = false; 
     497        } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoaquartz"] ) { 
     498            pcOpenGLView = false; 
     499        } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoaname"] ) { 
     500            i++; 
     501            pcName = [arguments objectAtIndex:i]; 
     502        } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoawindowname"] ) { 
     503            i++; 
     504            pcWindowName = [arguments objectAtIndex:i]; 
     505        } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoapath"] ) { 
     506            i++; 
     507            pcPath = [arguments objectAtIndex:i]; 
     508        } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoalivethumbnail"] ) { 
     509        } else if ( [[arguments objectAtIndex:i] isEqual:@"-cocoanodialogs"] ) { 
     510            pcDialogs = NO; 
     511            NSLog(@"pcDialogs: %d\n", pcDialogs); 
     512        } else if ( [[arguments objectAtIndex:i] isEqual:@"-wmstopwheninactive"] ) { 
     513            WMStopWhenInactive = true; 
     514        } else if ( [[arguments objectAtIndex:i] isEqual:@"-full-screen"] ) { 
     515            fullscreen = [contentView toggleFullScreen]; 
     516        } else if ( [[arguments objectAtIndex:i] isEqual:@"-cdrom"] ) { 
     517            if ( [[arguments objectAtIndex:i+1] isEqual:@"/dev/cdrom"] ) { 
     518                kern_return_t kernResult; 
     519                io_iterator_t mediaIterator; 
     520                char bsdPath[MAXPATHLEN]; 
     521                 
     522                kernResult = FindEjectableCDMedia( &mediaIterator ); 
     523                kernResult = GetBSDPath( mediaIterator, bsdPath, sizeof( bsdPath ) ); 
     524                 
     525                if ( bsdPath[0] == '\0' ) { 
     526                    i++; 
     527                } else { 
     528                    asprintf(&argv2[i2], "%s", [[arguments objectAtIndex:i] cString]); 
     529                    i2++; 
     530                    i++; 
     531                    asprintf(&argv2[i2], "%s", [[arguments objectAtIndex:i] cString]); 
     532                    i2++; 
     533                } 
     534                 
     535                if ( mediaIterator ) 
     536                    IOObjectRelease( mediaIterator ); 
     537            } else { 
     538                asprintf(&argv2[i2], "%s", [[arguments objectAtIndex:i] cString]); 
     539                i2++; 
     540                i++; 
     541                asprintf(&argv2[i2], "%s", [[arguments objectAtIndex:i] cString]); 
     542                i2++; 
     543            } 
     544        } else { 
     545            if ([[arguments objectAtIndex:i] isEqual:@"-smb"]) 
     546                smbPath = [[NSString alloc] initWithString:[arguments objectAtIndex:i + 1]]; 
     547             
     548            if ([[arguments objectAtIndex:i] isEqual:@"-hda"]) 
    551549                if ([[arguments objectAtIndex:i+1] rangeOfString:@"qcow2"].length > 0) 
    552550                    WMSupportsSnapshots = TRUE; 
    553                         asprintf(&argv2[i2], "%s", [[arguments objectAtIndex:i] cString]); 
    554                         i2++; 
    555                 } 
    556         } 
    557          
    558 //      for (i = 0; i < i2; i++) 
    559 //              NSLog(@"Argv :%s\n", argv2[i]); 
    560          
    561         /* set window- and frameAutosaveName */ 
    562         [pcWindow setFrameAutosaveName: [NSString stringWithFormat:@"%@ - %@",pcWindowName, pcName]]; 
    563         [pcWindow setTitle: [NSString stringWithFormat:@"%@ - %@",pcWindowName, pcName]]; 
    564          
    565         /* show progressWindow */ 
    566         [progressWindow showProgressWindow:pcWindow text: NSLocalizedStringFromTable(@"startPCWithArgs:text", @"Localizable", @"cocoaQemu") name:pcName]; 
    567          
    568         /* register with Q distributed objects server */ 
    569         if (![qdoserver guestRegister: self withName:pcName]) { 
    570                 [qdoserver release]; 
    571                 qdoserver = nil; 
    572                 NSLog(@"KO"); 
    573         } 
    574                  
    575         /* update status */ 
    576         pcStatus = @"running"; 
    577          
    578         /* hide progressWindow */ 
    579         progressWindowTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector( closeProgressWindow ) userInfo:nil repeats:YES]; 
    580          
    581         /* launch VM, QEMU is up and running here */ 
    582         qemu_main(i2, argv2); 
    583          
    584         /* remove pcWindow */ 
    585         [pcWindow close]; 
    586          
    587         [pool release]; 
    588          
    589         /* unregister with Q distributed objects server */ 
    590         if (![qdoserver guestUnregisterWithName:pcName]) { 
    591                 NSLog(@"KO"); 
    592         } 
    593         [qdoserver release]; 
    594         qdoserver = nil; 
    595          
    596         /* saved: return 2, so qemu-control knows */ 
    597         if ([pcStatus isEqual:@"saved"]) { 
    598                 exit(2); 
    599         } else { 
    600                 [NSApp terminate:self]; 
    601         } 
     551            asprintf(&argv2[i2], "%s", [[arguments objectAtIndex:i] cString]); 
     552            i2++; 
     553        } 
     554    } 
     555     
     556//  for (i = 0; i < i2; i++) 
     557//      NSLog(@"Argv :%s\n", argv2[i]); 
     558 
     559    /* set window- and frameAutosaveName */ 
     560    [pcWindow setFrameAutosaveName: [NSString stringWithFormat:@"%@ - %@",pcWindowName, pcName]]; 
     561    [pcWindow setTitle: [NSString stringWithFormat:@"%@ - %@",pcWindowName, pcName]]; 
     562 
     563    /* show progressWindow */ 
     564    [progressWindow showProgressWindow:pcWindow text: NSLocalizedStringFromTable(@"startPCWithArgs:text", @"Localizable", @"cocoaQemu") name:pcName]; 
     565 
     566    /* register with Q distributed objects server */ 
     567    if (![qdoserver guestRegister: self withName:pcName]) { 
     568        [qdoserver release]; 
     569        qdoserver = nil; 
     570        NSLog(@"KO"); 
     571    } 
     572 
     573    /* update status */ 
     574    pcStatus = @"running"; 
     575 
     576    /* hide progressWindow */ 
     577    progressWindowTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector( closeProgressWindow ) userInfo:nil repeats:YES]; 
     578 
     579    /* launch VM, QEMU is up and running here */ 
     580    qemu_main(i2, argv2); 
     581 
     582    /* remove pcWindow */ 
     583    [pcWindow close]; 
     584 
     585    [pool release]; 
     586 
     587    /* unregister with Q distributed objects server */ 
     588    if (![qdoserver guestUnregisterWithName:pcName]) { 
     589        NSLog(@"KO"); 
     590    } 
     591    [qdoserver release]; 
     592    qdoserver = nil; 
     593 
     594    /* saved: return 2, so qemu-control knows */ 
     595    if ([pcStatus isEqual:@"saved"]) { 
     596        exit(2); 
     597    } else { 
     598        [NSApp terminate:self]; 
     599    } 
    602600} 
    603601 
    604602- (void) changeFda:(id)sender 
    605603{ 
    606 //      NSLog(@"cocoaQemu: changeFda"); 
    607  
    608                 NSOpenPanel *op = [[NSOpenPanel alloc] init]; 
    609                 [op setPrompt: NSLocalizedStringFromTable(@"changeFda:prompt", @"Localizable", @"cocoaQemu")]; 
    610                 [op setMessage: NSLocalizedStringFromTable(@"changeFda:message", @"Localizable", @"cocoaQemu")]; 
    611                 [op beginSheetForDirectory:nil 
    612                 file:nil 
    613                 types:fileTypes 
    614                 modalForWindow:pcWindow 
    615                 modalDelegate:self 
    616                 didEndSelector:@selector(changeDeviceSheetDidEnd:returnCode:contextInfo:) 
    617                 contextInfo:@"fda"]; 
     604//  NSLog(@"cocoaQemu: changeFda"); 
     605 
     606        NSOpenPanel *op = [[NSOpenPanel alloc] init]; 
     607        [op setPrompt: NSLocalizedStringFromTable(@"changeFda:prompt", @"Localizable", @"cocoaQemu")]; 
     608        [op setMessage: NSLocalizedStringFromTable(@"changeFda:message", @"Localizable", @"cocoaQemu")]; 
     609        [op beginSheetForDirectory:nil 
     610        file:nil 
     611        types:fileTypes 
     612        modalForWindow:pcWindow 
     613        modalDelegate:self 
     614        didEndSelector:@selector(changeDeviceSheetDidEnd:returnCode:contextInfo:) 
     615        contextInfo:@"fda"]; 
    618616} 
    619617 
    620618- (void) changeFdb:(id)sender 
    621619{ 
    622 //      NSLog(@"cocoaQemu: changeFdb"); 
    623  
    624         NSOpenPanel *op = [[NSOpenPanel alloc] init]; 
    625                 [op setPrompt: NSLocalizedStringFromTable(@"changeFdb:prompt", @"Localizable", @"cocoaQemu")]; 
    626                 [op setMessage: NSLocalizedStringFromTable(@"changeFdb:message", @"Localizable", @"cocoaQemu")]; 
    627                 [op beginSheetForDirectory:nil 
    628                 file:nil 
    629                 types:fileTypes 
    630                 modalForWindow:pcWindow 
    631                 modalDelegate:self 
    632                 didEndSelector:@selector(changeDeviceSheetDidEnd:returnCode:contextInfo:) 
    633                 contextInfo:@"fdb"]; 
     620//  NSLog(@"cocoaQemu: changeFdb"); 
     621 
     622    NSOpenPanel *op = [[NSOpenPanel alloc] init]; 
     623        [op setPrompt: NSLocalizedStringFromTable(@"changeFdb:prompt", @"Localizable", @"cocoaQemu")]; 
     624        [op setMessage: NSLocalizedStringFromTable(@"changeFdb:message", @"Localizable", @"cocoaQemu")]; 
     625        [op beginSheetForDirectory:nil 
     626        file:nil 
     627        types:fileTypes 
     628        modalForWindow:pcWindow 
     629        modalDelegate:self 
     630        didEndSelector:@selector(changeDeviceSheetDidEnd:returnCode:contextInfo:) 
     631        contextInfo:@"fdb"]; 
    634632} 
    635633 
    636634- (void) changeCdrom:(id)sender 
    637635{ 
    638 //      NSLog(@"cocoaQemu: changeCdrom"); 
    639  
    640         NSOpenPanel *op = [[NSOpenPanel alloc] init]; 
    641                 [op setPrompt: NSLocalizedStringFromTable(@"changeCdrom:prompt", @"Localizable", @"cocoaQemu")]; 
    642                 [op setMessage: NSLocalizedStringFromTable(@"changeCdrom:message", @"Localizable", @"cocoaQemu")]; 
    643                 [op beginSheetForDirectory:nil 
    644                 file:nil 
    645                 types:fileTypes 
    646                 modalForWindow:pcWindow 
    647                 modalDelegate:self 
    648                 didEndSelector:@selector(changeDeviceSheetDidEnd:returnCode:contextInfo:) 
    649                 contextInfo:@"cdrom"]; 
     636//  NSLog(@"cocoaQemu: changeCdrom"); 
     637 
     638    NSOpenPanel *op = [[NSOpenPanel alloc] init]; 
     639        [op setPrompt: NSLocalizedStringFromTable(@"changeCdrom:prompt", @"Localizable", @"cocoaQemu")]; 
     640        [op setMessage: NSLocalizedStringFromTable(@"changeCdrom:message", @"Localizable", @"cocoaQemu")]; 
     641        [op beginSheetForDirectory:nil 
     642        file:nil 
     643        types:fileTypes 
     644        modalForWindow:pcWindow 
     645        modalDelegate:self 
     646        didEndSelector:@selector(changeDeviceSheetDidEnd:returnCode:contextInfo:) 
     647        contextInfo:@"cdrom"]; 
    650648} 
    651649 
    652650- (void)changeDeviceSheetDidEnd: (NSOpenPanel *)sheet 
    653         returnCode:(int)returnCode 
    654         contextInfo:(NSString *)contextInfo 
    655 { 
    656 //      NSLog(@"cocoaQemu: changeDeviceSheetDidEnd"); 
    657  
    658         if(returnCode == NSOKButton) 
    659                 [self changeDeviceImage:[contextInfo cString] filename:[[sheet filename] cString] withForce:1]; 
     651    returnCode:(int)returnCode 
     652    contextInfo:(NSString *)contextInfo 
     653{ 
     654//  NSLog(@"cocoaQemu: changeDeviceSheetDidEnd"); 
     655 
     656    if(returnCode == NSOKButton) 
     657        [self changeDeviceImage:[contextInfo cString] filename:[[sheet filename] cString] withForce:1]; 
    660658} 
    661659 
    662660- (void) useCdrom: (id)sender 
    663661{ 
    664 //      NSLog(@"cocoaQemu: useCdrom"); 
    665  
    666         [self changeDeviceImage:[@"cdrom" cString] filename:[@"/dev/cdrom" cString] withForce:1]; 
     662//  NSLog(@"cocoaQemu: useCdrom"); 
     663 
     664    [self changeDeviceImage:[@"cdrom" cString] filename:[@"/dev/cdrom" cString] withForce:1]; 
    667665} 
    668666 
    669667- (void) ejectFda: (id)sender 
    670668{ 
    671 //      NSLog(@"cocoaQemu: ejectFda"); 
    672  
    673                 [self ejectImage:[@"fda" cString] withForce:1]; 
     669//  NSLog(@"cocoaQemu: ejectFda"); 
     670 
     671        [self ejectImage:[@"fda" cString] withForce:1]; 
    674672} 
    675673 
    676674- (void) ejectFdb: (id)sender 
    677675{ 
    678 //      NSLog(@"cocoaQemu: ejectFdb"); 
    679  
    680                 [self ejectImage:[@"fdb" cString] withForce:1]; 
     676//  NSLog(@"cocoaQemu: ejectFdb"); 
     677 
     678        [self ejectImage:[@"fdb" cString] withForce:1]; 
    681679} 
    682680 
    683681- (void) ejectCdrom: (id)sender 
    684682{ 
    685 //      NSLog(@"cocoaQemu: ejectCdrom"); 
    686  
    687                 [self ejectImage:[@"cdrom" cString] withForce:1]; 
     683//  NSLog(@"cocoaQemu: ejectCdrom"); 
     684 
     685        [self ejectImage:[@"cdrom" cString] withForce:1]; 
    688686} 
    689687 
    690688/* copied and adapted from monitor.c */ 
    691689- (int) ejectDevice: (BlockDriverState *) bs 
    692         withForce: (int) force 
    693 { 
    694         if (bdrv_is_inserted(bs)) { 
    695                 if (!force) { 
    696                         if (!bdrv_is_removable(bs)) { 
    697                                 printf("device is not removable\n"); 
    698                                 return -1; 
    699                         } 
    700                         if (bdrv_is_locked(bs)) { 
    701                                 printf("device is locked\n"); 
    702                                 return -1; 
    703                         } 
    704                 } 
    705                 bdrv_close(bs); 
    706         } 
    707         return 0; 
     690    withForce: (int) force 
     691{ 
     692    if (bdrv_is_inserted(bs)) { 
     693        if (!force) { 
     694            if (!bdrv_is_removable(bs)) { 
     695                printf("device is not removable\n"); 
     696                return -1; 
     697            } 
     698            if (bdrv_is_locked(bs)) { 
     699                printf("device is locked\n"); 
     700                return -1; 
     701            } 
     702        } 
     703        bdrv_close(bs); 
     704    } 
     705    return 0; 
    708706} 
    709707 
    710708- (void) ejectImage:(const char *) filename 
    711         withForce: (int) force 
    712 { 
    713         BlockDriverState *bs; 
    714  
    715         bs = bdrv_find(filename); 
    716         if (!bs) { 
    717                 printf("device not found\n"); 
    718                 return; 
    719         } 
    720         [self ejectDevice:bs withForce:force]; 
     709    withForce: (int) force 
     710{ 
     711    BlockDriverState *bs; 
     712 
     713    bs = bdrv_find(filename); 
     714    if (!bs) { 
     715        printf("device not found\n"); 
     716        return; 
     717    } 
     718    [self ejectDevice:bs withForce:force]; 
    721719} 
    722720 
    723721- (void) changeDeviceImage: (const char *) device 
    724         filename: (const char *) filename 
    725         withForce: (int) force 
    726 { 
    727         BlockDriverState *bs; 
    728         int i; 
    729         char password[256]; 
    730  
    731         bs = bdrv_find(device); 
    732         if (!bs) { 
    733                 printf("device not found\n"); 
    734                 return; 
    735         } 
    736         if ([self ejectDevice:bs withForce:force] < 0) 
    737                 return; 
    738         bdrv_open(bs, filename, 0); 
    739         if (bdrv_is_encrypted(bs)) { 
    740                 printf("%s is encrypted.\n", device); 
    741                 for(i = 0; i < 3; i++) { 
    742                         monitor_readline("Password: ", 1, password, sizeof(password)); 
    743                         if (bdrv_set_key(bs, password) == 0) 
    744                                 break; 
    745                         printf("invalid password\n"); 
    746                 } 
    747         } 
     722    filename: (const char *) filename 
     723    withForce: (int) force 
     724{ 
     725    BlockDriverState *bs; 
     726    int i; 
     727    char password[256]; 
     728 
     729    bs = bdrv_find(device); 
     730    if (!bs) { 
     731        printf("device not found\n"); 
     732        return; 
     733    } 
     734    if ([self ejectDevice:bs withForce:force] < 0) 
     735        return; 
     736    bdrv_open(bs, filename, 0); 
     737    if (bdrv_is_encrypted(bs)) { 
     738        printf("%s is encrypted.\n", device); 
     739        for(i = 0; i < 3; i++) { 
     740            monitor_readline("Password: ", 1, password, sizeof(password)); 
     741            if (bdrv_set_key(bs, password) == 0) 
     742                break; 
     743            printf("invalid password\n"); 
     744        } 
     745    } 
    748746} 
    749747 
    750748- (void) pausePlay: (id)sender 
    751749{ 
    752 //      NSLog(@"cocoaQemu: pausePlay"); 
    753  
    754         if (vm_running) { 
    755                 [self stopVM]; 
    756                 wMPausedByUser = TRUE; 
    757         } else { 
    758                 [self startVM]; 
    759                 wMPausedByUser = FALSE; 
    760         } 
     750//  NSLog(@"cocoaQemu: pausePlay"); 
     751 
     752    if (vm_running) { 
     753        [self stopVM]; 
     754        wMPausedByUser = TRUE; 
     755    } else { 
     756        [self startVM]; 
     757        wMPausedByUser = FALSE; 
     758    } 
    761759} 
    762760 
    763761- (void) ctrlAltDel: (id)sender 
    764762{ 
    765 //      NSLog(@"cocoaQemu: ctrlAltDel"); 
    766  
    767         /* press keys */ 
    768         if (56 & 0x80) /* ctrl */ 
    769                 kbd_put_keycode(0xe0); 
    770         kbd_put_keycode(56 & 0x7f); 
    771         if (29 & 0x80) /* alt */ 
    772                 kbd_put_keycode(0xe0); 
    773         kbd_put_keycode(29 & 0x7f); 
    774         if (211 & 0x80) /* del */ 
    775                 kbd_put_keycode(0xe0); 
    776         kbd_put_keycode(211 & 0x7f); 
    777          
    778         /* release keys */ 
    779         if (56 & 0x80) /* ctrl */ 
    780                 kbd_put_keycode(0xe0); 
    781         kbd_put_keycode(56 | 0x80); 
    782         if (29 & 0x80) /* alt */ 
    783                 kbd_put_keycode(0xe0); 
    784         kbd_put_keycode(29 | 0x80); 
    785         if (211 & 0x80) /* del */ 
    786                 kbd_put_keycode(0xe0); 
    787         kbd_put_keycode(211 | 0x80); 
     763//  NSLog(@"cocoaQemu: ctrlAltDel"); 
     764 
     765    /* press keys */ 
     766    if (56 & 0x80) /* ctrl */ 
     767        kbd_put_keycode(0xe0); 
     768    kbd_put_keycode(56 & 0x7f); 
     769    if (29 & 0x80) /* alt */ 
     770        kbd_put_keycode(0xe0); 
     771    kbd_put_keycode(29 & 0x7f); 
     772    if (211 & 0x80) /* del */ 
     773        kbd_put_keycode(0xe0); 
     774    kbd_put_keycode(211 & 0x7f); 
     775     
     776    /* release keys */ 
     777    if (56 & 0x80) /* ctrl */ 
     778        kbd_put_keycode(0xe0); 
     779    kbd_put_keycode(56 | 0x80); 
     780    if (29 & 0x80) /* alt */ 
     781        kbd_put_keycode(0xe0); 
     782    kbd_put_keycode(29 | 0x80); 
     783    if (211 & 0x80) /* del */ 
     784        kbd_put_keycode(0xe0); 
     785    kbd_put_keycode(211 | 0x80); 
    788786} 
    789787 
    790788- (void) shutdownPC 
    791789{ 
    792 //      NSLog(@"cocoaQemu: shutdownPC"); 
     790//  NSLog(@"cocoaQemu: shutdownPC"); 
    793791 
    794792    /* exit fullscreen */ 
     
    796794        [pc setFullscreen:[[pc contentView] toggleFullScreen]]; 
    797795 
    798         if (!pcDialogs) { 
    799                 pcStatus = @"shutdown"; 
    800                 qemu_system_shutdown_request(); 
    801         } else if ( !WMSupportsSnapshots ) { 
    802                 NSAlert *alert = [NSAlert alertWithMessageText: NSLocalizedStringFromTable(@"shutdownPC:text:1", @"Localizable", @"cocoaQemu") 
    803                         defaultButton: NSLocalizedStringFromTable(@"shutdownPC:defaultButton:1", @"Localizable", @"cocoaQemu") 
    804                         alternateButton: NSLocalizedStringFromTable(@"shutdownPC:alternateButton:1", @"Localizable", @"cocoaQemu") 
    805                         otherButton:@"" 
    806                         informativeTextWithFormat: NSLocalizedStringFromTable(@"shutdownPC:informativeTextWithFormat:1", @"Localizable", @"cocoaQemu")]; 
    807                 [alert beginSheetModalForWindow:pcWindow 
    808                         modalDelegate:self 
    809                         didEndSelector:@selector(shutdownPC2SheetDidEnd:returnCode:contextInfo:) 
    810                         contextInfo:nil]; 
    811         } else { 
    812                 NSAlert *alert = [NSAlert alertWithMessageText: NSLocalizedStringFromTable(@"shutdownPC:text:2", @"Localizable", @"cocoaQemu") 
    813                         defaultButton: NSLocalizedStringFromTable(@"shutdownPC:defaultButton:2", @"Localizable", @"cocoaQemu") 
    814                         alternateButton: NSLocalizedStringFromTable(@"shutdownPC:alternateButton:2", @"Localizable", @"cocoaQemu") 
    815                         otherButton: NSLocalizedStringFromTable(@"shutdownPC:otherButton:2", @"Localizable", @"cocoaQemu") 
    816                         informativeTextWithFormat: NSLocalizedStringFromTable(@"shutdownPC:informativeTextWithFormat:2", @"Localizable", @"cocoaQemu")]; 
    817                 [alert beginSheetModalForWindow:pcWindow 
    818                         modalDelegate:self 
    819                         didEndSelector:@selector(shutdownPCSheetDidEnd:returnCode:contextInfo:) 
    820                         contextInfo:nil]; 
    821         } 
     796    if (!pcDialogs) { 
     797        pcStatus = @"shutdown"; 
     798        qemu_system_shutdown_request(); 
     799    } else if ( !WMSupportsSnapshots ) { 
     800        NSAlert *alert = [NSAlert alertWithMessageText: NSLocalizedStringFromTable(@"shutdownPC:text:1", @"Localizable", @"cocoaQemu") 
     801            defaultButton: NSLocalizedStringFromTable(@"shutdownPC:defaultButton:1", @"Localizable", @"cocoaQemu") 
     802            alternateButton: NSLocalizedStringFromTable(@"shutdownPC:alternateButton:1", @"Localizable", @"cocoaQemu") 
     803            otherButton:@"" 
     804            informativeTextWithFormat: NSLocalizedStringFromTable(@"shutdownPC:informativeTextWithFormat:1", @"Localizable", @"cocoaQemu")]; 
     805        [alert beginSheetModalForWindow:pcWindow 
     806            modalDelegate:self 
     807            didEndSelector:@selector(shutdownPC2SheetDidEnd:returnCode:contextInfo:) 
     808            contextInfo:nil]; 
     809    } else { 
     810        NSAlert *alert = [NSAlert alertWithMessageText: NSLocalizedStringFromTable(@"shutdownPC:text:2", @"Localizable", @"cocoaQemu") 
     811            defaultButton: NSLocalizedStringFromTable(@"shutdownPC:defaultButton:2", @"Localizable", @"cocoaQemu") 
     812            alternateButton: NSLocalizedStringFromTable(@"shutdownPC:alternateButton:2", @"Localizable", @"cocoaQemu") 
     813            otherButton: NSLocalizedStringFromTable(@"shutdownPC:otherButton:2", @"Localizable", @"cocoaQemu") 
     814            informativeTextWithFormat: NSLocalizedStringFromTable(@"shutdownPC:informativeTextWithFormat:2", @"Localizable", @"cocoaQemu")]; 
     815        [alert beginSheetModalForWindow:pcWindow 
     816            modalDelegate:self 
     817            didEndSelector:@selector(shutdownPCSheetDidEnd:returnCode:contextInfo:) 
     818            contextInfo:nil]; 
     819    } 
    822820} 
    823821 
    824822- (void) shutdownPCSheetDidEnd: (NSWindow *)sheet 
    825         returnCode: (int)returnCode 
    826         contextInfo: (void *)contextInfo 
    827 { 
    828 //      NSLog(@"cocoaQemu: shutdownPCSheetDidEnd"); 
    829  
    830         [[sheet window] orderOut:self]; 
    831         if (returnCode == NSAlertDefaultReturn) 
    832         { 
    833                 [self saveVM]; 
    834                 pcStatus = @"saved"; 
    835                 qemu_system_shutdown_request(); 
    836                 vm_start(); 
    837         } 
    838         else if (returnCode == NSAlertOtherReturn) 
    839         { 
    840                 pcStatus = @"shutdown"; 
    841                 if([[NSFileManager defaultManager] fileExistsAtPath: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath]]) [[NSFileManager defaultManager] removeFileAtPath: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath] handler: nil]; 
    842                 qemu_system_shutdown_request(); 
    843                 vm_start(); 
    844         } 
     823    returnCode: (int)returnCode 
     824    contextInfo: (void *)contextInfo 
     825{ 
     826//  NSLog(@"cocoaQemu: shutdownPCSheetDidEnd"); 
     827 
     828    [[sheet window] orderOut:self]; 
     829    if (returnCode == NSAlertDefaultReturn) { 
     830        [self saveVM]; 
     831        pcStatus = @"saved"; 
     832        qemu_system_shutdown_request(); 
     833        vm_start(); 
     834    } else if (returnCode == NSAlertOtherReturn) { 
     835        pcStatus = @"shutdown"; 
     836        if([[NSFileManager defaultManager] fileExistsAtPath: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath]]) [[NSFileManager defaultManager] removeFileAtPath: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath] handler: nil]; 
     837        qemu_system_shutdown_request(); 
     838        vm_start(); 
     839    } 
    845840} 
    846841 
    847842- (void) shutdownPC2SheetDidEnd: (NSWindow *)sheet 
    848         returnCode: (int)returnCode 
    849         contextInfo: (void *)contextInfo 
    850 { 
    851 //      NSLog(@"cocoaQemu: shutdownPC2SheetDidEnd"); 
    852  
    853         [[sheet window] orderOut:self]; 
    854         if (returnCode == NSAlertDefaultReturn) 
    855         { 
    856         } 
    857         else 
    858         { 
    859                 if ( [pcStatus isEqual: @"running"] ) 
    860                         pcStatus = @"shutdown"; 
    861                         if([[NSFileManager defaultManager] fileExistsAtPath: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath]]) [[NSFileManager defaultManager] removeFileAtPath: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath] handler: nil]; 
    862                 qemu_system_shutdown_request(); 
    863                 vm_start(); 
    864         } 
     843    returnCode: (int)returnCode 
     844    contextInfo: (void *)contextInfo 
     845{ 
     846//  NSLog(@"cocoaQemu: shutdownPC2SheetDidEnd"); 
     847 
     848    [[sheet window] orderOut:self]; 
     849    if (returnCode == NSAlertDefaultReturn) { 
     850    } else { 
     851        if ( [pcStatus isEqual: @"running"] ) 
     852            pcStatus = @"shutdown"; 
     853            if([[NSFileManager defaultManager] fileExistsAtPath: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath]]) [[NSFileManager defaultManager] removeFileAtPath: [NSString stringWithFormat: @"%@/thumbnail.png", pcPath] handler: nil]; 
     854        qemu_system_shutdown_request(); 
     855        vm_start(); 
     856    } 
    865857} 
    866858 
    867859- (void) resetPC 
    868860{ 
    869 //      NSLog(@"cocoaQemu: resetPC"); 
    870  
    871         qemu_system_reset_request(); 
     861//  NSLog(@"cocoaQemu: resetPC"); 
     862 
     863    qemu_system_reset_request(); 
    872864} 
    873865 
    874866- (void) screenshot 
    875867{ 
    876 //      NSLog(@"screenshot: resetPC"); 
    877  
    878         /* generate Screenshot */        
    879         NSBitmapImageRep *bitmapImageRep = [NSBitmapImageRep imageRepWithData: [[contentView screenshot:[contentView frame].size] TIFFRepresentation]]; 
    880         NSData *data = [bitmapImageRep representationUsingType: NSPNGFileType properties: nil]; 
    881          
    882         /* save it to the desktop */ 
    883         NSFileManager *fileManager = [NSFileManager defaultManager]; 
    884         int i = 1; 
    885         while ([fileManager fileExistsAtPath:[NSString stringWithFormat:@"%@/Q Screenshot %D.png", [@"~/Desktop" stringByExpandingTildeInPath], i]]) 
    886                 i++; 
    887  
    888         [data writeToFile: [NSString stringWithFormat:@"%@/Q Screenshot %D.png", [@"~/Desktop" stringByExpandingTildeInPath], i] atomically: YES]; 
     868//  NSLog(@"screenshot: resetPC"); 
     869 
     870    /* generate Screenshot */    
     871    NSBitmapImageRep *bitmapImageRep = [NSBitmapImageRep imageRepWithData: [[contentView screenshot:[contentView frame].size] TIFFRepresentation]]; 
     872    NSData *data = [bitmapImageRep representationUsingType: NSPNGFileType properties: nil]; 
     873     
     874    /* save it to the desktop */ 
     875    NSFileManager *fileManager = [NSFileManager defaultManager]; 
     876    int i = 1; 
     877    while ([fileManager fileExistsAtPath:[NSString stringWithFormat:@"%@/Q Screenshot %D.png", [@"~/Desktop" stringByExpandingTildeInPath], i]]) 
     878        i++; 
     879 
     880    [data writeToFile: [NSString stringWithFormat:@"%@/Q Screenshot %D.png", [@"~/Desktop" stringByExpandingTildeInPath], i] atomically: YES]; 
    889881} 
    890882@end 
     
    894886/* 
    895887 ------------------------------------------------------ 
    896         keymap conversion 
     888    keymap conversion 
    897889 ------------------------------------------------------ 
    898890*/ 
     
    900892int keymap[] = 
    901893{ 
    902 //      SdlI            macI    macH    SdlH    104xtH  104xtC  sdl 
    903         30,             //      0               0x00    0x1e                    A               QZ_a 
    904         31,             //      1               0x01    0x1f                    S               QZ_s 
    905         32,             //      2               0x02    0x20                    D               QZ_d 
    906         33,             //      3               0x03    0x21                    F               QZ_f 
    907         35,             //      4               0x04    0x23                    H               QZ_h 
    908         34,             //      5               0x05    0x22                    G               QZ_g 
    909         44,             //      6               0x06    0x2c                    Z               QZ_z 
    910         45,             //      7               0x07    0x2d                    X               QZ_x 
    911         46,             //      8               0x08    0x2e                    C               QZ_c 
    912         47,             //      9               0x09    0x2f                    V               QZ_v 
    913         0,              //      10              0x0A    Undefined 
    914         48,             //      11              0x0B    0x30                    B               QZ_b 
    915         16,             //      12              0x0C    0x10                    Q               QZ_q 
    916         17,             //      13              0x0D    0x11                    W               QZ_w 
    917         18,             //      14              0x0E    0x12                    E               QZ_e 
    918         19,             //      15              0x0F    0x13                    R               QZ_r 
    919         21,             //      16              0x10    0x15                    Y               QZ_y 
    920         20,             //      17              0x11    0x14                    T               QZ_t 
    921         2,              //      18              0x12    0x02                    1               QZ_1 
    922         3,              //      19              0x13    0x03                    2               QZ_2 
    923         4,              //      20              0x14    0x04                    3               QZ_3 
    924         5,              //      21              0x15    0x05                    4               QZ_4 
    925         7,              //      22              0x16    0x07                    6               QZ_6 
    926         6,              //      23              0x17    0x06                    5               QZ_5 
    927         13,             //      24              0x18    0x0d                    =               QZ_EQUALS 
    928         10,             //      25              0x19    0x0a                    9               QZ_9 
    929         8,              //      26              0x1A    0x08                    7               QZ_7 
    930         12,             //      27              0x1B    0x0c                    -               QZ_MINUS 
    931         9,              //      28              0x1C    0x09                    8               QZ_8 
    932         11,             //      29              0x1D    0x0b                    0               QZ_0 
    933         27,             //      30              0x1E    0x1b                    ]               QZ_RIGHTBRACKET 
    934         24,             //      31              0x1F    0x18                    O               QZ_o 
    935         22,             //      32              0x20    0x16                    U               QZ_u 
    936         26,             //      33              0x21    0x1a                    [               QZ_LEFTBRACKET 
    937         23,             //      34              0x22    0x17                    I               QZ_i 
    938         25,             //      35              0x23    0x19                    P               QZ_p 
    939         28,             //      36              0x24    0x1c                    ENTER   QZ_RETURN 
    940         38,             //      37              0x25    0x26                    L               QZ_l 
    941         36,             //      38              0x26    0x24                    J               QZ_j 
    942         40,             //      39              0x27    0x28                    '               QZ_QUOTE 
    943         37,             //      40              0x28    0x25                    K               QZ_k 
    944         39,             //      41              0x29    0x27                    ;               QZ_SEMICOLON 
    945         43,             //      42              0x2A    0x2b                    \               QZ_BACKSLASH 
    946         51,             //      43              0x2B    0x33                    ,               QZ_COMMA 
    947         53,             //      44              0x2C    0x35                    /               QZ_SLASH 
    948         49,             //      45              0x2D    0x31                    N               QZ_n 
    949         50,             //      46              0x2E    0x32                    M               QZ_m 
    950         52,             //      47              0x2F    0x34                    .               QZ_PERIOD 
    951         15,             //      48              0x30    0x0f                    TAB             QZ_TAB 
    952         57,             //      49              0x31    0x39                    SPACE   QZ_SPACE 
    953         41,             //      50              0x32    0x29                    `               QZ_BACKQUOTE 
    954         14,             //      51              0x33    0x0e                    BKSP    QZ_BACKSPACE 
    955         0,              //      52              0x34    Undefined 
    956         1,              //      53              0x35    0x01                    ESC             QZ_ESCAPE 
    957         0,              //      54              0x36                                                    QZ_RMETA 
    958         0,              //      55              0x37                                                    QZ_LMETA 
    959         42,             //      56              0x38    0x2a                    L SHFT  QZ_LSHIFT 
    960         58,             //      57              0x39    0x3a                    CAPS    QZ_CAPSLOCK 
    961         56,             //      58              0x3A    0x38                    L ALT   QZ_LALT 
    962         29,             //      59              0x3B    0x1d                    L CTRL  QZ_LCTRL 
    963         54,             //      60              0x3C    0x36                    R SHFT  QZ_RSHIFT 
    964         184,    //      61              0x3D    0xb8    E0,38   R ALT   QZ_RALT 
    965         157,    //      62              0x3E    0x9d    E0,1D   R CTRL  QZ_RCTRL 
    966         0,              //      63              0x3F    Undefined 
    967         0,              //      64              0x40    Undefined 
    968         0,              //      65              0x41    Undefined 
    969         0,              //      66              0x42    Undefined 
    970         55,     //      67              0x43    0x37                    KP *    QZ_KP_MULTIPLY 
    971         0,              //      68              0x44    Undefined 
    972         78,             //      69              0x45    0x4e                    KP +    QZ_KP_PLUS 
    973         0,              //      70              0x46    Undefined 
    974         69,             //      71              0x47    0x45                    NUM             QZ_NUMLOCK 
    975         0,              //      72              0x48    Undefined 
    976         0,              //      73              0x49    Undefined 
    977         0,              //      74              0x4A    Undefined 
    978         181,    //      75              0x4B    0xb5    E0,35   KP /    QZ_KP_DIVIDE 
    979         152,    //      76              0x4C    0x9c    E0,1C   KP EN   QZ_KP_ENTER 
    980         0,              //      77              0x4D    undefined 
    981         74,             //      78              0x4E    0x4a                    KP -    QZ_KP_MINUS 
    982         0,              //      79              0x4F    Undefined 
    983         0,              //      80              0x50    Undefined 
    984         0,              //      81              0x51                                                    QZ_KP_EQUALS 
    985         82,             //      82              0x52    0x52                    KP 0    QZ_KP0 
    986         79,             //      83              0x53    0x4f                    KP 1    QZ_KP1 
    987         80,             //      84              0x54    0x50                    KP 2    QZ_KP2 
    988         81,             //      85              0x55    0x51                    KP 3    QZ_KP3 
    989         75,             //      86              0x56    0x4b                    KP 4    QZ_KP4 
    990         76,             //      87              0x57    0x4c                    KP 5    QZ_KP5 
    991         77,             //      88              0x58    0x4d                    KP 6    QZ_KP6 
    992         71,             //      89              0x59    0x47                    KP 7    QZ_KP7 
    993         0,              //      90              0x5A    Undefined 
    994         72,             //      91              0x5B    0x48                    KP 8    QZ_KP8 
    995         73,             //      92              0x5C    0x49                    KP 9    QZ_KP9 
    996         125,    //  93    0x5D    Backslash (NIP) 
    997         115,    //  94    0x5E    Underline (NIP) 
    998         0,              //      95              0x5F    Undefined 
    999         63,             //      96              0x60    0x3f                    F5              QZ_F5 
    1000         64,             //      97              0x61    0x40                    F6              QZ_F6 
    1001         65,             //      98              0x62    0x41                    F7              QZ_F7 
    1002         61,             //      99              0x63    0x3d                    F3              QZ_F3 
    1003         66,             //      100             0x64    0x42                    F8              QZ_F8 
    1004         67,             //      101             0x65    0x43                    F9              QZ_F9 
    1005         0,              //      102             0x66    Undefined 
    1006         87,             //      103             0x67    0x57                    F11             QZ_F11 
    1007         0,              //      104             0x68    Undefined 
    1008         183,    //      105             0x69    0xb7                    QZ_PRINT 
    1009         0,              //      106             0x6A    Undefined 
    1010         70,             //      107             0x6B    0x46                    SCROLL  QZ_SCROLLOCK 
    1011         0,              //      108             0x6C    Undefined 
    1012         68,             //      109             0x6D    0x44                    F10             QZ_F10 
    1013         0,              //      110             0x6E    Undefined 
    1014         88,     //      111             0x6F    0x58                    F12             QZ_F12 
    1015         0,              //      112             0x70    Undefined 
    1016         110,    //      113             0x71    0x0                                             QZ_PAUSE 
    1017         210,    //      114             0x72    0xd2    E0,52   INSERT  QZ_INSERT 
    1018         199,    //      115             0x73    0xc7    E0,47   HOME    QZ_HOME 
    1019         201,    //      116             0x74    0xc9    E0,49   PG UP   QZ_PAGEUP 
    1020         211,    //      117             0x75    0xd3    E0,53   DELETE  QZ_DELETE 
    1021         62,             //      118             0x76    0x3e                    F4              QZ_F4 
    1022         207,    //      119             0x77    0xcf    E0,4f   END             QZ_END 
    1023         60,             //      120             0x78    0x3c                    F2              QZ_F2 
    1024         209,    //      121             0x79    0xd1    E0,51   PG DN   QZ_PAGEDOWN 
    1025         59,             //      122             0x7A    0x3b                    F1              QZ_F1 
    1026         203,    //      123             0x7B    0xcb    e0,4B   L ARROW QZ_LEFT 
    1027         205,    //      124             0x7C    0xcd    e0,4D   R ARROW QZ_RIGHT 
    1028         208,    //      125             0x7D    0xd0    E0,50   D ARROW QZ_DOWN 
    1029         200,    //      126             0x7E    0xc8    E0,48   U ARROW QZ_UP 
    1030 /* completed according to http: //www.libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/quartz/SDL_QuartzKeys.h?rev=1.6&content-type=text/x-cvsweb-markup */ 
     894//  SdlI        macI    macH    SdlH    104xtH  104xtC  sdl 
     895    30,     //  0       0x00    0x1e            A       QZ_a 
     896    31,     //  1       0x01    0x1f            S       QZ_s 
     897    32,     //  2       0x02    0x20            D       QZ_d 
     898    33,     //  3       0x03    0x21            F       QZ_f 
     899    35,     //  4       0x04    0x23            H       QZ_h 
     900    34,     //  5       0x05    0x22            G       QZ_g 
     901    44,     //  6       0x06    0x2c            Z       QZ_z 
     902    45,     //  7       0x07    0x2d            X       QZ_x 
     903    46,     //  8       0x08    0x2e            C       QZ_c 
     904    47,     //  9       0x09    0x2f            V       QZ_v 
     905    0,      //  10      0x0A    Undefined 
     906    48,     //  11      0x0B    0x30            B       QZ_b 
     907    16,     //  12      0x0C    0x10            Q       QZ_q 
     908    17,     //  13      0x0D    0x11            W       QZ_w 
     909    18,     //  14      0x0E    0x12            E       QZ_e 
     910    19,     //  15      0x0F    0x13            R       QZ_r 
     911    21,     //  16      0x10    0x15            Y       QZ_y 
     912    20,     //  17      0x11    0x14            T       QZ_t 
     913    2,      //  18      0x12    0x02            1       QZ_1 
     914    3,      //  19      0x13    0x03            2       QZ_2 
     915    4,      //  20      0x14    0x04            3       QZ_3 
     916    5,      //  21      0x15    0x05            4       QZ_4 
     917    7,      //  22      0x16    0x07            6       QZ_6 
     918    6,      //  23      0x17    0x06            5       QZ_5 
     919    13,     //  24      0x18    0x0d            =       QZ_EQUALS 
     920    10,     //  25      0x19    0x0a            9       QZ_9 
     921    8,      //  26      0x1A    0x08            7       QZ_7 
     922    12,     //  27      0x1B    0x0c            -       QZ_MINUS 
     923    9,      //  28      0x1C    0x09            8       QZ_8 
     924    11,     //  29      0x1D    0x0b            0       QZ_0 
     925    27,     //  30      0x1E    0x1b            ]       QZ_RIGHTBRACKET 
     926    24,     //  31      0x1F    0x18            O       QZ_o 
     927    22,     //  32      0x20    0x16            U       QZ_u 
     928    26,     //  33      0x21    0x1a            [       QZ_LEFTBRACKET 
     929    23,     //  34      0x22    0x17            I       QZ_i 
     930    25,     //  35      0x23    0x19            P       QZ_p 
     931    28,     //  36      0x24    0x1c            ENTER   QZ_RETURN 
     932    38,     //  37      0x25    0x26            L       QZ_l 
     933    36,     //  38      0x26    0x24            J       QZ_j 
     934    40,     //  39      0x27    0x28            '       QZ_QUOTE 
     935    37,     //  40      0x28    0x25            K       QZ_k 
     936    39,     //  41      0x29    0x27            ;       QZ_SEMICOLON 
     937    43,     //  42      0x2A    0x2b            \       QZ_BACKSLASH 
     938    51,     //  43      0x2B    0x33            ,       QZ_COMMA 
     939    53,     //  44      0x2C    0x35            /       QZ_SLASH 
     940    49,     //  45      0x2D    0x31            N       QZ_n 
     941    50,     //  46      0x2E    0x32            M       QZ_m 
     942    52,     //  47      0x2F    0x34            .       QZ_PERIOD 
     943    15,     //  48      0x30    0x0f            TAB     QZ_TAB 
     944    57,     //  49      0x31    0x39            SPACE   QZ_SPACE 
     945    41,     //  50      0x32    0x29            `       QZ_BACKQUOTE 
     946    14,     //  51      0x33    0x0e            BKSP    QZ_BACKSPACE 
     947    0,      //  52      0x34    Undefined 
     948    1,      //  53      0x35    0x01            ESC     QZ_ESCAPE 
     949    0,      //  54      0x36                            QZ_RMETA 
     950    0,      //  55      0x37                            QZ_LMETA 
     951    42,     //  56      0x38    0x2a            L SHFT  QZ_LSHIFT 
     952    58,     //  57      0x39    0x3a            CAPS    QZ_CAPSLOCK 
     953    56,     //  58      0x3A    0x38            L ALT   QZ_LALT 
     954    29,     //  59      0x3B    0x1d            L CTRL  QZ_LCTRL 
     955    54,     //  60      0x3C    0x36            R SHFT  QZ_RSHIFT 
     956    184,    //  61      0x3D    0xb8    E0,38   R ALT   QZ_RALT 
     957    157,    //  62      0x3E    0x9d    E0,1D   R CTRL  QZ_RCTRL 
     958    0,      //  63      0x3F    Undefined 
     959    0,      //  64      0x40    Undefined 
     960    0,      //  65      0x41    Undefined 
     961    0,      //  66      0x42    Undefined 
     962    55,     //  67      0x43    0x37            KP *    QZ_KP_MULTIPLY 
     963    0,      //  68      0x44    Undefined 
     964    78,     //  69      0x45    0x4e            KP +    QZ_KP_PLUS 
     965    0,      //  70      0x46    Undefined 
     966    69,     //  71      0x47    0x45            NUM     QZ_NUMLOCK 
     967    0,      //  72      0x48    Undefined 
     968    0,      //  73      0x49    Undefined 
     969    0,      //  74      0x4A    Undefined 
     970    181,    //  75      0x4B    0xb5    E0,35   KP /    QZ_KP_DIVIDE 
     971    152,    //  76      0x4C    0x9c    E0,1C   KP EN   QZ_KP_ENTER 
     972    0,      //  77      0x4D    undefined 
     973    74,     //  78      0x4E    0x4a            KP -    QZ_KP_MINUS 
     974    0,      //  79      0x4F    Undefined 
     975    0,      //  80      0x50    Undefined 
     976    0,      //  81      0x51                            QZ_KP_EQUALS 
     977    82,     //  82      0x52    0x52            KP 0    QZ_KP0 
     978    79,     //  83      0x53    0x4f            KP 1    QZ_KP1 
     979    80,     //  84      0x54    0x50            KP 2    QZ_KP2 
     980    81,     //  85      0x55    0x51            KP 3    QZ_KP3 
     981    75,     //  86      0x56    0x4b            KP 4    QZ_KP4 
     982    76,     //  87      0x57    0x4c            KP 5    QZ_KP5 
     983    77,     //  88      0x58    0x4d            KP 6    QZ_KP6 
     984    71,     //  89      0x59    0x47            KP 7    QZ_KP7 
     985    0,      //  90      0x5A    Undefined 
     986    72,     //  91      0x5B    0x48            KP 8    QZ_KP8 
     987    73,     //  92      0x5C    0x49            KP 9    QZ_KP9 
     988    125,    //  93    0x5D    Backslash (NIP) 
     989    115,    //  94    0x5E    Underline (NIP) 
     990    0,      //  95      0x5F    Undefined 
     991    63,     //  96      0x60    0x3f            F5      QZ_F5 
     992    64,     //  97      0x61    0x40            F6      QZ_F6 
     993    65,     //  98      0x62    0x41            F7      QZ_F7 
     994    61,     //  99      0x63    0x3d            F3      QZ_F3 
     995    66,     //  100     0x64    0x42            F8      QZ_F8 
     996    67,     //  101     0x65    0x43            F9      QZ_F9 
     997    0,      //  102     0x66    Undefined 
     998    87,     //  103     0x67    0x57            F11     QZ_F11 
     999    0,      //  104     0x68    Undefined 
     1000    183,    //  105     0x69    0xb7            QZ_PRINT 
     1001    0,      //  106     0x6A    Undefined 
     1002    70,     //  107     0x6B    0x46            SCROLL  QZ_SCROLLOCK 
     1003    0,      //  108     0x6C    Undefined 
     1004    68,     //  109     0x6D    0x44            F10     QZ_F10 
     1005    0,      //  110     0x6E    Undefined 
     1006    88,     //  111     0x6F    0x58            F12     QZ_F12 
     1007    0,      //  112     0x70    Undefined 
     1008    110,    //  113     0x71    0x0                     QZ_PAUSE 
     1009    210,    //  114     0x72    0xd2    E0,52   INSERT  QZ_INSERT 
     1010    199,    //  115     0x73    0xc7    E0,47   HOME    QZ_HOME 
     1011    201,    //  116     0x74    0xc9    E0,49   PG UP   QZ_PAGEUP 
     1012    211,    //  117     0x75    0xd3    E0,53   DELETE  QZ_DELETE 
     1013    62,     //  118     0x76    0x3e            F4      QZ_F4 
     1014    207,    //  119     0x77    0xcf    E0,4f   END     QZ_END 
     1015    60,     //  120     0x78    0x3c            F2      QZ_F2 
     1016    209,    //  121     0x79    0xd1    E0,51   PG DN   QZ_PAGEDOWN 
     1017    59,     //  122     0x7A    0x3b            F1      QZ_F1 
     1018    203,    //  123     0x7B    0xcb    e0,4B   L ARROW QZ_LEFT 
     1019    205,    //  124     0x7C    0xcd    e0,4D   R ARROW QZ_RIGHT 
     1020    208,    //  125     0x7D    0xd0    E0,50   D ARROW QZ_DOWN 
     1021    200,    //  126     0x7E    0xc8    E0,48   U ARROW QZ_UP 
     1022/* completed according to http: //www.libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/quartz/SDL_QuartzKeys.h?rev=1.6&content-type=text/x-cvsweb-markup */ 
    10311023   
    1032 /* Aditional 104 Key XP-Keyboard Scancodes from http:   //www.computer-engineering.org/ps2keyboard/scancodes1.html */ 
     1024/* Aditional 104 Key XP-Keyboard Scancodes from http:   //www.computer-engineering.org/ps2keyboard/scancodes1.html */ 
    10331025/* 
    1034         219,    //                      0xdb                    e0,5b   L GUI    
    1035         220,    //                      0xdc                    e0,5c   R GUI    
    1036         221,    //                      0xdd                    e0,5d   APPS     
    1037                         //                              E0,2A,E0,37                     PRNT SCRN        
    1038                         //                              E1,1D,45,E1,9D,C5       PAUSE    
    1039         83,             //                      0x53    0x53                    KP .     
    1040 // ACPI Scan Codes                                                               
    1041         222,    //                      0xde                    E0, 5E  Power    
    1042         223,    //                      0xdf                    E0, 5F  Sleep    
    1043         227,    //                      0xe3                    E0, 63  Wake     
    1044 // Windows Multimedia Scan Codes                                                                 
    1045         153,    //                      0x99                    E0, 19  Next Track       
    1046         144,    //                      0x90                    E0, 10  Previous Track   
    1047         164,    //                      0xa4                    E0, 24  Stop     
    1048         162,    //                      0xa2                    E0, 22  Play/Pause       
    1049         160,    //                      0xa0                    E0, 20  Mute     
    1050         176,    //                      0xb0                    E0, 30  Volume Up        
    1051         174,    //                      0xae                    E0, 2E  Volume Down  
    1052         237,    //                      0xed                    E0, 6D  Media Select     
    1053         236,    //                      0xec                    E0, 6C  E-Mail   
    1054         161,    //                      0xa1                    E0, 21  Calculator       
    1055         235,    //                      0xeb                    E0, 6B  My Computer  
    1056         229,    //                      0xe5                    E0, 65  WWW Search       
    1057         178,    //                      0xb2                    E0, 32  WWW Home         
    1058         234,    //                      0xea                    E0, 6A  WWW Back         
    1059         233,    //                      0xe9                    E0, 69  WWW Forward  
    1060         232,    //                      0xe8                    E0, 68  WWW Stop         
    1061         231,    //                      0xe7                    E0, 67  WWW Refresh  
    1062         230             //                      0xe6                    E0, 66  WWW Favorites    
     1026    219,    //          0xdb            e0,5b   L GUI    
     1027    220,    //          0xdc            e0,5c   R GUI    
     1028    221,    //          0xdd            e0,5d   APPS     
     1029            //              E0,2A,E0,37         PRNT SCRN    
     1030            //              E1,1D,45,E1,9D,C5   PAUSE    
     1031    83,     //          0x53    0x53            KP .     
     1032// ACPI Scan Codes                               
     1033    222,    //          0xde            E0, 5E  Power    
     1034    223,    //          0xdf            E0, 5F  Sleep    
     1035    227,    //          0xe3            E0, 63  Wake     
     1036// Windows Multimedia Scan Codes                                 
     1037    153,    //          0x99            E0, 19  Next Track   
     1038    144,    //          0x90            E0, 10  Previous Track   
     1039    164,    //          0xa4            E0, 24  Stop     
     1040    162,    //          0xa2            E0, 22  Play/Pause   
     1041    160,    //          0xa0            E0, 20  Mute     
     1042    176,    //          0xb0            E0, 30  Volume Up    
     1043    174,    //          0xae            E0, 2E  Volume Down  
     1044    237,    //          0xed            E0, 6D  Media Select     
     1045    236,    //          0xec            E0, 6C  E-Mail   
     1046    161,    //          0xa1            E0, 21  Calculator   
     1047    235,    //          0xeb            E0, 6B  My Computer  
     1048    229,    //          0xe5            E0, 65  WWW Search   
     1049    178,    //          0xb2            E0, 32  WWW Home     
     1050    234,    //          0xea            E0, 6A  WWW Back     
     1051    233,    //          0xe9            E0, 69  WWW Forward  
     1052    232,    //          0xe8            E0, 68  WWW Stop     
     1053    231,    //          0xe7            E0, 67  WWW Refresh  
     1054    230     //          0xe6            E0, 66  WWW Favorites    
    10631055*/ 
    10641056}; 
     
    10661058int cocoa_keycode_to_qemu(int keycode) 
    10671059{ 
    1068         if((sizeof(keymap)/sizeof(int)) <= keycode) 
    1069         { 
    1070                 printf("(cocoa) warning unknow keycode 0x%x\n", keycode); 
    1071                 return 0; 
    1072         } 
    1073         return keymap[keycode]; 
     1060    if((sizeof(keymap)/sizeof(int)) <= keycode) 
     1061    { 
     1062        printf("(cocoa) warning unknow keycode 0x%x\n", keycode); 
     1063        return 0; 
     1064    } 
     1065    return keymap[keycode]; 
    10741066} 
    10751067 
     
    10781070/* 
    10791071 ------------------------------------------------------ 
    1080         Qemu Video Driver 
    1081          
     1072    Qemu Video Driver 
     1073 
    10821074 ------------------------------------------------------ 
    10831075*/ 
    10841076void cocoa_update(DisplayState *ds, int x, int y, int w, int h) 
    10851077{ 
    1086 //      NSLog(@"cocoa: update"); 
     1078//  NSLog(@"cocoa: update"); 
    10871079 
    10881080    if ([[[pc contentView] class] isEqual:[cocoaQemuQuartzView class]]) { 
     1081 
    10891082        /* new selective drawing code (draws only dirty rectangles) */ 
    1090         float dx; 
    1091         float dy; 
    1092          
    1093         dx = [[pc contentView] frame].size.width / (float)ds->width; 
    1094         dy = [[pc contentView] frame].size.height / (float)ds->height; 
    1095          
    10961083        [[pc contentView] setNeedsDisplayInRect:NSMakeRect( 
    1097             x * dx, 
    1098             [[pc contentView] frame].size.height - (h + y) * dy, 
    1099             w * dx, 
    1100             h * dy 
    1101         )];     
     1084            x * [[pc contentView] cdx], 
     1085            [[pc contentView] frame].size.height - (h + y) * [[pc contentView] cdy], 
     1086            w * [[pc contentView] cdx], 
     1087            h * [[pc contentView] cdy] 
     1088        )]; 
     1089 
    11021090    } else { 
    1103      
     1091 
    11041092        /* old drawing code (draws everything) */ 
    11051093        [[pc contentView] drawContent:ds]; 
     
    11101098void cocoa_resize(DisplayState *ds, int w, int h) 
    11111099{ 
    1112 //      NSLog(@"cocoa: resize\n"); 
    1113  
    1114         [[pc contentView] resizeContent:ds width:w height:h]; 
     1100//  NSLog(@"cocoa: resize\n"); 
     1101 
     1102    [[pc contentView] resizeContent:ds width:w height:h]; 
    11151103} 
    11161104 
    11171105void cocoa_refresh(DisplayState *ds) 
    11181106{ 
    1119 //      NSLog(@"cocoa: refresh\n"); 
    1120  
    1121         if (kbd_mouse_is_absolute()) { 
    1122                 if (![pc absolute_enabled]) { 
    1123                         if ([pc grab]) { 
    1124                                 [pc ungrabMouse]; 
    1125                         } 
    1126                 } 
    1127                 [pc setAbsolute_enabled:1]; 
    1128         } 
    1129  
    1130         NSEvent *event; 
    1131         do { 
    1132                 event = [ NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[ NSDate distantPast ] 
    1133                                                 inMode: NSDefaultRunLoopMode dequeue:YES ]; 
    1134                 if (event != nil) { 
    1135                         switch ([event type]) 
    1136                         { 
    1137                                                  
    1138                                 case NSFlagsChanged: 
    1139                                         { 
    1140                                                 int keycode = cocoa_keycode_to_qemu([event keyCode]); 
    1141                                                 [pc setModifierAtIndex:keycode to: ([pc modifierAtIndex:keycode] == 0) ? 1 : 0]; 
    1142                                                  
    1143                                                 if ( [pc modifierAtIndex:keycode] ) { /* Keydown */ 
    1144                                                         if (keycode & 0x80) 
    1145                                                                 kbd_put_keycode(0xe0); 
    1146                                                         kbd_put_keycode(keycode & 0x7f); 
    1147                                                 } else { /* Keyup */ 
    1148                                                         if (keycode & 0x80) 
    1149                                                                 kbd_put_keycode(0xe0); 
    1150                                                         kbd_put_keycode(keycode | 0x80); 
    1151                                                 } 
    1152                                                  
    1153                                                 /* emulate caps lock and num lock keyup */ 
    1154                                                 if ((keycode == 58) || (keycode == 69)) 
    1155                                                 { 
    1156                                                         [pc setModifierAtIndex:keycode to:0]; 
    1157                                                         if (keycode & 0x80) 
    1158                                                                 kbd_put_keycode(0xe0); 
    1159                                                         kbd_put_keycode(keycode | 0x80); 
    1160                                                 } 
    1161                                                          
    1162                                                 /* release Mouse grab when pressing ctrl+alt */ 
    1163                                                 if ((![pc fullscreen]) && ([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) 
    1164                                                         [pc ungrabMouse]; 
    1165                                         } 
    1166                                         break; 
    1167                                          
    1168                                 case NSKeyDown: 
    1169                                         { 
    1170                                                 int keycode = cocoa_keycode_to_qemu([event keyCode]);                            
    1171                                                  
    1172                                                 /* handle command Key Combos */ 
    1173                                                 if ([event modifierFlags] & NSCommandKeyMask) { 
    1174                                                         switch ([event keyCode]) { 
    1175                                                          
    1176                                                                 /* toggle fullscreen */ 
    1177                                                                 case 3: /* f key */ 
    1178                                                                     // show hint to exit fullscreen, fast os switch, toolbar 
    1179                                                                         if(![pc fullscreen]) { 
    1180                                                                         #if kju_debug 
    1181                                                                            NSLog(@"init FSController"); 
    1182                                                                     #endif 
    1183                                                                         NSBeginAlertSheet(NSLocalizedStringFromTable(@"cocoa_refresh:showFullscreen:standardAlert", @"Localizable", @"cocoaQemu"),NSLocalizedStringFromTable(@"cocoa_refresh:showFullscreen:defaultButton", @"Localizable", @"cocoaQemu"),nil,nil,[pc pcWindow],pc,@selector(showFullscreenAlertSheetDidEnd:returnCode:contextInfo:),nil,nil,NSLocalizedStringFromTable(@"cocoa_refresh:showFullscreen:informativeText", @"Localizable", @"cocoaQemu")); 
    1184                                                                            [pc setFullscreenController:[[FSController alloc] initWithSender:pc]]; 
    1185                                                                     } else { 
    1186                                                                     #if kju_debug 
    1187                                                                         NSLog(@"release FSController"); 
    1188                                                                     #endif 
    1189                                                                         [pc setFullscreen:[[pc contentView] toggleFullScreen]]; 
    1190                                                                         [[pc fullscreenController] release]; 
    1191                                                                     } 
    1192                                                                         return; 
    1193  
    1194 //                                                              /* paste text in Host Clipboard to Guest */ 
    1195 //                                                              case 9: /* v key */ 
    1196 //                                                              { 
    1197 //                                                                      NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; 
    1198 //                                                                      NSString *string = [NSString stringWithString:[pasteboard stringForType:NSStringPboardType]]; 
    1199 //                                                                      if (string) { 
    1200 //                                                                              NSLog(@"PASTE: %@", string); 
    1201 //                                                                              int ii; 
    1202 //                                                                              int maxChars = 24; 
    1203 //                                                                              if ([string length] < maxChars) 
    1204 //                                                                                      maxChars = [string length]; 
    1205 //                                                                              for (ii=0; ii<maxChars; ii++) { 
    1206 //                                                                                      /* keycode */ 
    1207 //                                                                                      keycode = keysym2scancode(kbd_layout, [string characterAtIndex:ii]); 
     1107//  NSLog(@"cocoa: refresh\n"); 
     1108 
     1109    if (kbd_mouse_is_absolute()) { 
     1110        if (![pc absolute_enabled]) { 
     1111            if ([pc grab]) { 
     1112                [pc ungrabMouse]; 
     1113            } 
     1114        } 
     1115        [pc setAbsolute_enabled:1]; 
     1116    } 
     1117 
     1118    NSEvent *event; 
     1119    do { 
     1120        event = [ NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[ NSDate distantPast ] 
     1121                        inMode: NSDefaultRunLoopMode dequeue:YES ]; 
     1122        if (event != nil) { 
     1123            switch ([event type]) 
     1124            { 
     1125 
     1126                case NSFlagsChanged: 
     1127                    { 
     1128                        int keycode = cocoa_keycode_to_qemu([event keyCode]); 
     1129                        [pc setModifierAtIndex:keycode to: ([pc modifierAtIndex:keycode] == 0) ? 1 : 0]; 
     1130 
     1131                        if ( [pc modifierAtIndex:keycode] ) { /* Keydown */ 
     1132                            if (keycode & 0x80) 
     1133                                kbd_put_keycode(0xe0); 
     1134                            kbd_put_keycode(keycode & 0x7f); 
     1135                        } else { /* Keyup */ 
     1136                            if (keycode & 0x80) 
     1137                                kbd_put_keycode(0xe0); 
     1138                            kbd_put_keycode(keycode | 0x80); 
     1139                        } 
     1140 
     1141                        /* emulate caps lock and num lock keyup */ 
     1142                        if ((keycode == 58) || (keycode == 69)) 
     1143                        { 
     1144                            [pc setModifierAtIndex:keycode to:0]; 
     1145                            if (keycode & 0x80) 
     1146                                kbd_put_keycode(0xe0); 
     1147                            kbd_put_keycode(keycode | 0x80); 
     1148                        } 
     1149 
     1150                        /* release Mouse grab when pressing ctrl+alt */ 
     1151                        if ((![pc fullscreen]) && ([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) 
     1152                            [pc ungrabMouse]; 
     1153                    } 
     1154                    break; 
     1155                     
     1156                case NSKeyDown: 
     1157                    { 
     1158                        int keycode = cocoa_keycode_to_qemu([event keyCode]);                
     1159                         
     1160                        /* handle command Key Combos */ 
     1161                        if ([event modifierFlags] & NSCommandKeyMask) { 
     1162                            switch ([event keyCode]) { 
     1163 
     1164                                /* toggle fullscreen */ 
     1165                                case 3: /* f key */ 
     1166                                    // show hint to exit fullscreen, fast os switch, toolbar 
     1167                                    if(![pc fullscreen]) { 
     1168                                    #if kju_debug 
     1169                                       NSLog(@"init FSController"); 
     1170                                    #endif 
     1171                                        NSBeginAlertSheet(NSLocalizedStringFromTable(@"cocoa_refresh:showFullscreen:standardAlert", @"Localizable", @"cocoaQemu"),NSLocalizedStringFromTable(@"cocoa_refresh:showFullscreen:defaultButton", @"Localizable", @"cocoaQemu"),nil,nil,[pc pcWindow],pc,@selector(showFullscreenAlertSheetDidEnd:returnCode:contextInfo:),nil,nil,NSLocalizedStringFromTable(@"cocoa_refresh:showFullscreen:informativeText", @"Localizable", @"cocoaQemu")); 
     1172                                       [pc setFullscreenController:[[FSController alloc] initWithSender:pc]]; 
     1173                                    } else { 
     1174                                    #if kju_debug 
     1175                                        NSLog(@"release FSController"); 
     1176                                    #endif 
     1177                                        [pc setFullscreen:[[pc contentView] toggleFullScreen]]; 
     1178                                        [[pc fullscreenController] release]; 
     1179                                    } 
     1180                                    return; 
     1181 
     1182//                              /* paste text in Host Clipboard to Guest */ 
     1183//                              case 9: /* v key */ 
     1184//                              { 
     1185//                                  NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; 
     1186//                                  NSString *string = [NSString stringWithString:[pasteboard stringForType:NSStringPboardType]]; 
     1187//                                  if (string) { 
     1188//                                      NSLog(@"PASTE: %@", string); 
     1189//                                      int ii; 
     1190//                                      int maxChars = 24; 
     1191//                                      if ([string length] < maxChars) 
     1192//                                          maxChars = [string length]; 
     1193//                                      for (ii=0; ii<maxChars; ii++) { 
     1194//                                          /* keycode */ 
     1195//                                          keycode = keysym2scancode(kbd_layout, [string characterAtIndex:ii]); 
    12081196// 
    1209 //                                                                                      if (keycode!=0) { 
    1210 //                                                                                              /* key down events */ 
    1211 //                                                                                              if (keycode & 0x80) 
    1212 //                                                                                                      kbd_put_keycode(0xe0); 
    1213 //                                                                                              kbd_put_keycode(keycode & 0x7f); 
    1214 //                                                                                       
    1215 //                                                                                              /* key up events */ 
    1216 //                                                                                              if (keycode & 0x80) 
    1217 //                                                                                                      kbd_put_keycode(0xe0); 
    1218 //                                                                                              kbd_put_keycode(keycode | 0x80); 
    1219 //                                                                                      } 
    1220 //                                                                              } 
    1221 //                                                                              [string release]; 
    1222 //                                                                      } 
    1223 //                                                                      return; 
    1224 //                                                              } 
    1225  
    1226                                                                 /* quit */ 
    1227                                                                 case 12: /* q key */ 
    1228                                                                         /* switch to windowed View */ 
    1229                                                                         if ([pc fullscreen]) { 
    1230                                                                                 [pc setFullscreen:[[pc contentView] toggleFullScreen]]; 
    1231                                                                                 [[pc fullscreenController] release]; 
    1232                                                                     } 
    1233                                                                         [[pc pcWindow] performClose:nil]; 
    1234                                                                         return; 
    1235  
    1236                                                                 /* minimize Window */ 
    1237                                                                 case 46: /* m key */ 
    1238                                                                         if ([pc fullscreen]) 
    1239                                                                                 [pc setFullscreen:[[pc contentView] toggleFullScreen]]; 
    1240                                                                         [[pc pcWindow] miniaturize:nil]; 
    1241                                                                         return; 
    1242                                                                          
    1243 //                                                              /* app switch *//* does not work, as dock is ogging command-tab */ 
    1244 //                                                              case 48: /* tab key */ 
    1245 //                                                                      if ([pc fullscreen]) 
    1246 //                                                                              [pc setFullscreen:[[pc contentView] toggleFullScreen]]; 
    1247 //                                                                      return; 
    1248                                                                          
    1249                                                                 /* window switch */ 
    1250                                                                 case 50: /* backquote key */ 
    1251                                                                     if ([event modifierFlags] & NSShiftKeyMask) { /* previous Window */ 
     1197//                                          if (keycode!=0) { 
     1198//                                              /* key down events */ 
     1199//                                              if (keycode & 0x80) 
     1200//                                                  kbd_put_keycode(0xe0); 
     1201//                                              kbd_put_keycode(keycode & 0x7f); 
     1202//                                           
     1203//                                              /* key up events */ 
     1204//                                              if (keycode & 0x80) 
     1205//                                                  kbd_put_keycode(0xe0); 
     1206//                                              kbd_put_keycode(keycode | 0x80); 
     1207//                                          } 
     1208//                                      } 
     1209//                                      [string release]; 
     1210//                                  } 
     1211//                                  return; 
     1212//                              } 
     1213 
     1214                                /* quit */ 
     1215                                case 12: /* q key */ 
     1216                                    /* switch to windowed View */ 
     1217                                    if ([pc fullscreen]) { 
     1218                                        [pc setFullscreen:[[pc contentView] toggleFullScreen]]; 
     1219                                        [[pc fullscreenController] release]; 
     1220                                    } 
     1221                                    [[pc pcWindow] performClose:nil]; 
     1222                                    return; 
     1223 
     1224                                /* minimize Window */ 
     1225                                case 46: /* m key */ 
     1226                                    if ([pc fullscreen]) 
     1227                                        [pc setFullscreen:[[pc contentView] toggleFullScreen]]; 
     1228                                    [[pc pcWindow] miniaturize:nil]; 
     1229                                    return; 
     1230 
     1231//                              /* app switch *//* does not work, as dock is ogging command-tab */ 
     1232//                              case 48: /* tab key */ 
     1233//                                  if ([pc fullscreen]) 
     1234//                                      [pc setFullscreen:[[pc contentView] toggleFullScreen]]; 
     1235//                                  return; 
     1236 
     1237                                /* window switch */ 
     1238                                case 50: /* backquote key */ 
     1239                                    if ([event modifierFlags] & NSShiftKeyMask) { /* previous Window */ 
    12521240                                        if ([[pc qdoserver] guestSwitch:[pc pcName] fullscreen:[pc fullscreen] previousGuestName:nil]) 
    12531241                                            return; 
     
    12601248                                            break; 
    12611249                                    } 
     1250 
    12621251                                /* fullscreen toolbar */ 
    12631252                                case 11: /* B-key */ 
     
    12681257                                        break; 
    12691258                                    } 
    1270                                                         } 
    1271                                                 } 
    1272                                                  
    1273                                                 /* handle control + alt Key Combos */ 
    1274                                                 if (([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) { 
    1275                                                         switch (keycode) { 
    1276                                                                 /* toggle Monitor */ 
    1277                                                                 case 0x02 ... 0x0a: /* '1' to '9' keys */ 
    1278                                                                     { 
     1259 
     1260                            } 
     1261                        } 
     1262 
     1263                        /* handle control + alt Key Combos */ 
     1264                        if (([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) { 
     1265                            switch (keycode) { 
     1266                                /* toggle Monitor */ 
     1267                                case 0x02 ... 0x0a: /* '1' to '9' keys */ 
     1268                                    { 
    12791269                                        /* setup transition */ 
    12801270                                        CGSConnection cid = _CGSDefaultConnection(); 
    12811271                                        int transitionHandle = -1; 
    12821272                                        CGSTransitionSpec transitionSpecifications; 
    1283                                          
     1273 
    12841274                                        transitionSpecifications.type = 9; //transition; 
    12851275                                        if (keycode - 0x02 == 0) 
     
    12891279                                        transitionSpecifications.wid = [[pc pcWindow] windowNumber]; //wid 
    12901280                                        transitionSpecifications.backColour = 0; //background color 
    1291              
     1281 
    12921282                                        /* freeze desktop: OSStatus CGSNewTransition(const CGSConnection cid, const CGSTransitionSpec* transitionSpecifications, int *transitionHandle) */ 
    12931283                                        CGSNewTransition(cid, &transitionSpecifications, &transitionHandle); 
    1294                              
     1284 
    12951285                                        /* change monitor */ 
    12961286                                        console_select(keycode - 0x02); 
    12971287                                        vga_hw_update(); 
    1298                                          
     1288 
    12991289                                        /* wait */ 
    13001290                                        usleep(10000); 
    1301                                          
     1291 
    13021292                                        /* run transition: OSStatus CGSInvokeTransition(const CGSConnection cid, int transitionHandle, float duration) */ 
    13031293                                        CGSInvokeTransition(cid, transitionHandle, 1.0); 
    1304                                          
     1294 
    13051295                                        break; 
    13061296                                    } 
    1307 //                                                                      console_select(keycode - 0x02); 
    1308 //                                                                      break; 
    1309                                                                 /* toggle Fullscreen */ 
    1310                                                                 case 0x21: /* 'f' key */ 
    1311                                                                     // show hint to exit fullscreen, fast os switch, toolbar 
    1312                                                                     if(![pc fullscreen]) { 
    1313                                                                         NSBeginAlertSheet(NSLocalizedStringFromTable(@"cocoa_refresh:showFullscreen:standardAlert", @"Localizable", @"cocoaQemu"),NSLocalizedStringFromTable(@"cocoa_refresh:showFullscreen:defaultButton", @"Localizable", @"cocoaQemu"),nil,nil,[pc pcWindow],pc,@selector(showFullscreenAlertSheetDidEnd:returnCode:contextInfo:),nil,nil,NSLocalizedStringFromTable(@"cocoa_refresh:showFullscreen:informativeText", @"Localizable", @"cocoaQemu")); 
    1314                                                                     } else { 
    1315                                                                         [pc setFullscreen:[[pc contentView] toggleFullScreen]]; 
    1316                                                                     } 
    1317                                                                         break; 
    1318                                                         } 
    1319                                                 } else { 
    1320                                                         /* handle standard key events */ 
    1321                                                         if (is_graphic_console()) { 
    1322                                                                 if (keycode & 0x80) //check bit for e0 in front 
    1323                                                                         kbd_put_keycode(0xe0); 
    1324                                                                 kbd_put_keycode(keycode & 0x7f); //remove e0 bit in front 
    1325                                                         /* handle monitor key events */ 
    1326                                                         } else { 
    1327                                                                 switch([event keyCode]) { 
    1328                                                                         case 123: 
    1329                                                                                 kbd_put_keysym(QEMU_KEY_LEFT); 
    1330                                                                                 break; 
    1331                                                                         case 124: 
    1332                                                                                 kbd_put_keysym(QEMU_KEY_RIGHT); 
    1333                                                                                 break; 
    1334                                                                         case 125: 
    1335                                                                                 kbd_put_keysym(QEMU_KEY_DOWN); 
    1336                                                                                 break; 
    1337                                                                         case 126: 
    1338                                                                                 kbd_put_keysym(QEMU_KEY_UP); 
    1339                                                                                 break; 
    1340                                                                         default: 
    1341                                                                         { 
    1342                                                                                 NSString *ks = [event characters]; 
    1343                                                                                 if ([ks length] > 0) 
    1344                                                                                         kbd_put_keysym([ks characterAtIndex:0]); 
    1345                                                                         } 
    1346                                                                 } 
    1347                                                         } 
    1348                                                 } 
    1349                                         } 
    1350                                         break; 
    1351                                                  
    1352                                 case NSKeyUp: 
    1353                                         { 
    1354                                                 int keycode = cocoa_keycode_to_qemu([event keyCode]); 
    1355                                                 if (is_graphic_console()) { 
    1356                                                         if (keycode & 0x80) 
    1357                                                                 kbd_put_keycode(0xe0); 
    1358                                                         kbd_put_keycode(keycode | 0x80); //add 128 to signal release of key 
    1359                                                 } 
    1360                                         } 
    1361                                         break; 
    1362                                          
    1363                                 case NSMouseMoved: 
    1364                                         if ([pc absolute_enabled]) { 
    1365                                                 NSPoint p = [event locationInWindow]; 
    1366                                                 if (p.x < 0 || p.x > ds->width || p.y < 0 || p.y > ds->height || ![[pc pcWindow] isKeyWindow]) { 
    1367                                                         if ([pc tablet_enabled]) 
    1368                                                                 [NSCursor unhide]; 
    1369                                                         [pc setTablet_enabled:0]; 
    1370                                                 } else { 
    1371                                                         if (![pc tablet_enabled]) 
    1372                                                                 [NSCursor hide]; 
    1373                                                         [pc setTablet_enabled:1]; 
    1374                                                         int dx = p.x * 0x7FFF / ds->width; 
    1375                                                         int dy = (ds->height - p.y) * 0x7FFF / ds->height; 
    1376                                                         int dz = [event deltaZ]; 
    1377                                                         int buttons = 0; 
    1378                                                         kbd_mouse_event(dx, dy, dz, buttons); 
    1379                                                 } 
    1380                                         } else if ([pc grab]) { 
    1381                                                 int dx = [event deltaX]; 
    1382                                                 int dy = [event deltaY]; 
    1383                                                 int dz = [event deltaZ]; 
    1384                                                 int buttons = 0; 
    1385                                                 kbd_mouse_event(dx, dy, dz, buttons); 
    1386                                         } 
    1387                                         break; 
    1388                                                  
    1389                                 case NSLeftMouseDown: 
    1390                                         if ([pc grab]||[pc tablet_enabled]) { 
    1391                                                 int buttons = 0; 
    1392                                                  
    1393                                                 /* leftclick+command simulates rightclick */ 
    1394                                     &nbs