| @@ -41,7 +41,7 @@ Memimage *gscreen; · 40 unmodified lines |
| 41 | | 41 | |
| 42 | static int readybit; | 42 | static int readybit; |
| 43 | static Rendez rend; | 43 | static Rendez rend; |
| 44 | static int triedscreen; | 44 | static int triedscreen; |
| 45 | | 45 | |
| 46 | /// | 46 | /// |
| 47 | // menu | 47 | // menu |
| @@ -64,6 +64,12 @@ static CGRect bounds; · 16 unmodified lines |
| 64 | static PasteboardRef appleclip; | 64 | static PasteboardRef appleclip; |
| 65 | static _Rect winRect; | 65 | static _Rect winRect; |
| 66 | | 66 | |
| | 67 | static Boolean altPressed = false; |
| | 68 | static Boolean button2 = false; |
| | 69 | static Boolean button3 = false; |
| | 70 | |
| | 71 | static Boolean needflush = false; |
| | 72 | |
| 67 | | 73 | |
| 68 | static int | 74 | static int |
| 69 | isready(void*a) | 75 | isready(void*a) |
| @@ -73,7 +79,11 @@ isready(void*a) · 3 unmodified lines |
| 73 | | 79 | |
| 74 | CGContextRef QuartzContext; | 80 | CGContextRef QuartzContext; |
| 75 | | 81 | |
| | 82 | static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); |
| | 83 | static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); |
| | 84 | |
| 76 | static void winproc(void *a); | 85 | static void winproc(void *a); |
| | 86 | static void flushproc(void *a); |
| 77 | | 87 | |
| 78 | void | 88 | void |
| 79 | screeninit(void) | 89 | screeninit(void) |
| @@ -108,12 +118,10 @@ screeninit(void) · 28 unmodified lines |
| 108 | dataProviderRef, 0, 0, kCGRenderingIntentDefault); | 118 | dataProviderRef, 0, 0, kCGRenderingIntentDefault); |
| 109 | | 119 | |
| 110 | kproc("osxscreen", winproc, nil, 0); | 120 | kproc("osxscreen", winproc, nil, 0); |
| | 121 | kproc("osxflush", flushproc, nil, 0); |
| 111 | Sleep(&rend, isready, nil); | 122 | Sleep(&rend, isready, nil); |
| 112 | } | 123 | } |
| 113 | | 124 | |
| 114 | static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); | | |
| 115 | static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); | | |
| 116 | | | |
| 117 | void | 125 | void |
| 118 | window_resized(void) | 126 | window_resized(void) |
| 119 | { | 127 | { |
| @@ -122,6 +130,21 @@ window_resized(void) · 2 unmodified lines |
| 122 | bounds = CGRectMake(0, 0, winRect.right-winRect.left, winRect.bottom - winRect.top); | 130 | bounds = CGRectMake(0, 0, winRect.right-winRect.left, winRect.bottom - winRect.top); |
| 123 | } | 131 | } |
| 124 | | 132 | |
| | 133 | static void |
| | 134 | flushproc(void *a) |
| | 135 | { |
| | 136 | for(;;) { |
| | 137 | if(needflush) { |
| | 138 | drawqlock(); |
| | 139 | QDBeginCGContext(GetWindowPort(theWindow), &context); |
| | 140 | CGContextFlush(context); |
| | 141 | QDEndCGContext(GetWindowPort(theWindow), &context); |
| | 142 | needflush = false; |
| | 143 | drawqunlock(); |
| | 144 | } |
| | 145 | usleep(33333); |
| | 146 | } |
| | 147 | } |
| 125 | | 148 | |
| 126 | static void | 149 | static void |
| 127 | winproc(void *a) | 150 | winproc(void *a) |
| @@ -208,7 +231,6 @@ winproc(void *a) · 80 unmodified lines |
| 208 | ShowMenuBar(); | 231 | ShowMenuBar(); |
| 209 | window_resized(); | 232 | window_resized(); |
| 210 | SelectWindow(theWindow); | 233 | SelectWindow(theWindow); |
| 211 | // terminit(); | | |
| 212 | // Run the event loop | 234 | // Run the event loop |
| 213 | readybit = 1; | 235 | readybit = 1; |
| 214 | Wakeup(&rend); | 236 | Wakeup(&rend); |
| @@ -273,7 +295,6 @@ convert_key(UInt32 key, UInt32 charcode) · 58 unmodified lines |
| 273 | void | 295 | void |
| 274 | sendbuttons(int b, int x, int y) | 296 | sendbuttons(int b, int x, int y) |
| 275 | { | 297 | { |
| 276 | /* TO DO: add special keyboard characters as mouse buttons */ | | |
| 277 | mousetrack(b, x, y, 0); | 298 | mousetrack(b, x, y, 0); |
| 278 | } | 299 | } |
| 279 | | 300 | |
| @@ -306,7 +327,9 @@ full_screen(void) · 26 unmodified lines |
| 306 | BeginFullScreen(&fullScreenRestore, 0, 0, 0, &theWindow, 0, 0); | 327 | BeginFullScreen(&fullScreenRestore, 0, 0, 0, &theWindow, 0, 0); |
| 307 | amFullScreen = 1; | 328 | amFullScreen = 1; |
| 308 | window_resized(); | 329 | window_resized(); |
| 309 | Rectangle rect = { { 0, 0 }, { bounds.size.width, bounds.size.height} }; | 330 | Rectangle rect = { { 0, 0 }, |
| | 331 | { bounds.size.width, |
| | 332 | bounds.size.height} }; |
| 310 | drawqlock(); | 333 | drawqlock(); |
| 311 | flushmemscreen(rect); | 334 | flushmemscreen(rect); |
| 312 | drawqunlock(); | 335 | drawqunlock(); |
| @@ -320,6 +343,10 @@ MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *us · 7 unmodified lines |
| 320 | result = CallNextEventHandler(nextHandler, event); | 343 | result = CallNextEventHandler(nextHandler, event); |
| 321 | UInt32 class = GetEventClass (event); | 344 | UInt32 class = GetEventClass (event); |
| 322 | UInt32 kind = GetEventKind (event); | 345 | UInt32 kind = GetEventKind (event); |
| | 346 | static uint32_t mousebuttons = 0; // bitmask of buttons currently down |
| | 347 | static uint32_t mouseX = 0; |
| | 348 | static uint32_t mouseY = 0; |
| | 349 | |
| 323 | if(class == kEventClassKeyboard) { | 350 | if(class == kEventClassKeyboard) { |
| 324 | char macCharCodes; | 351 | char macCharCodes; |
| 325 | UInt32 macKeyCode; | 352 | UInt32 macKeyCode; |
| @@ -331,24 +358,69 @@ MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *us · 5 unmodified lines |
| 331 | sizeof(macKeyCode), NULL, &macKeyCode); | 358 | sizeof(macKeyCode), NULL, &macKeyCode); |
| 332 | GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, | 359 | GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, |
| 333 | sizeof(macKeyModifiers), NULL, &macKeyModifiers); | 360 | sizeof(macKeyModifiers), NULL, &macKeyModifiers); |
| 334 | switch(kind) { | 361 | switch(kind) { |
| 335 | case kEventRawKeyModifiersChanged: | 362 | case kEventRawKeyModifiersChanged: |
| 336 | if (macKeyModifiers == 0x1800) leave_full_screen(); | 363 | if (macKeyModifiers == (controlKey | optionKey)) leave_full_screen(); |
| 337 | break; | 364 | |
| 338 | case kEventRawKeyDown: | 365 | switch(macKeyModifiers & (optionKey | cmdKey)) { |
| 339 | case kEventRawKeyRepeat: { | 366 | case (optionKey | cmdKey): |
| 340 | if(macKeyModifiers != 256) { | 367 | /* due to chording we need to handle the case when both |
| 341 | if (kind == kEventRawKeyRepeat || kind == kEventRawKeyDown) { | 368 | * modifier keys are pressed at the same time. |
| 342 | int key = convert_key(macKeyCode, macCharCodes); | 369 | * currently it's only 2-3 snarf and the 3-2 noop |
| 343 | if(key != -1) | 370 | */ |
| 344 | gkbdputc(gkbdq, key); | 371 | altPressed = true; |
| 345 | if(0 && key != -1)fprint(2, "[%C]", key); | 372 | if(mousebuttons & 1 || mousebuttons & 2 || mousebuttons & 4) { |
| | 373 | mousebuttons |= 2; /* set button 2 */ |
| | 374 | mousebuttons |= 4; /* set button 3 */ |
| | 375 | button2 = true; |
| | 376 | button3 = true; |
| | 377 | sendbuttons(mousebuttons, mouseX, mouseY); |
| | 378 | } |
| | 379 | break; |
| | 380 | case optionKey: |
| | 381 | altPressed = true; |
| | 382 | if(mousebuttons & 1 || mousebuttons & 4) { |
| | 383 | mousebuttons |= 2; /* set button 2 */ |
| | 384 | button2 = true; |
| | 385 | sendbuttons(mousebuttons, mouseX, mouseY); |
| 346 | } | 386 | } |
| | 387 | break; |
| | 388 | case cmdKey: |
| | 389 | if(mousebuttons & 1 || mousebuttons & 2) { |
| | 390 | mousebuttons |= 4; /* set button 3 */ |
| | 391 | button3 = true; |
| | 392 | sendbuttons(mousebuttons, mouseX, mouseY); |
| | 393 | } |
| | 394 | break; |
| | 395 | case 0: |
| | 396 | default: |
| | 397 | if(button2 || button3) { |
| | 398 | if(button2) { |
| | 399 | mousebuttons &= ~2; /* clear button 2 */ |
| | 400 | button2 = false; |
| | 401 | altPressed = false; |
| | 402 | } |
| | 403 | if(button3) { |
| | 404 | mousebuttons &= ~4; /* clear button 3 */ |
| | 405 | button3 = false; |
| | 406 | } |
| | 407 | sendbuttons(mousebuttons, mouseX, mouseY); |
| | 408 | } |
| | 409 | if(altPressed) { |
| | 410 | gkbdputc(gkbdq, Kalt); |
| | 411 | altPressed = false; |
| | 412 | } |
| | 413 | break; |
| 347 | } | 414 | } |
| 348 | else | 415 | break; |
| | 416 | case kEventRawKeyDown: |
| | 417 | case kEventRawKeyRepeat: |
| | 418 | if(macKeyModifiers != cmdKey) { |
| | 419 | int key = convert_key(macKeyCode, macCharCodes); |
| | 420 | if (key != -1) gkbdputc(gkbdq, key); |
| | 421 | } else |
| 349 | result = eventNotHandledErr; | 422 | result = eventNotHandledErr; |
| 350 | break; | 423 | break; |
| 351 | } | | |
| 352 | default: | 424 | default: |
| 353 | break; | 425 | break; |
| 354 | } | 426 | } |
| @@ -359,35 +431,45 @@ if(0 && key != -1)fprint(2, "[%C]", key); · 4 unmodified lines |
| 359 | GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, | 431 | GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, |
| 360 | 0, sizeof mousePos, 0, &mousePos); | 432 | 0, sizeof mousePos, 0, &mousePos); |
| 361 | | 433 | |
| 362 | static uint32_t mousebuttons = 0; // bitmask of buttons currently down | 434 | switch(kind) { |
| 363 | | 435 | case kEventMouseWheelMoved: |
| 364 | switch (kind) { | 436 | { |
| 365 | case kEventMouseWheelMoved: { | 437 | int32_t wheeldelta; |
| 366 | int32_t wheeldelta; | 438 | GetEventParameter(event,kEventParamMouseWheelDelta,typeSInt32, |
| 367 | GetEventParameter(event,kEventParamMouseWheelDelta,typeLongInteger, | 439 | 0,sizeof(wheeldelta), 0, &wheeldelta); |
| 368 | 0,sizeof(EventMouseButton), 0, &wheeldelta); | 440 | mouseX = mousePos.h - winRect.left; |
| 369 | sendbuttons((int16_t)wheeldelta>0 ? 8 : 16, | 441 | mouseY = mousePos.v - winRect.top; |
| 370 | mousePos.h - winRect.left, | 442 | sendbuttons(wheeldelta>0 ? 8 : 16, mouseX, mouseY); |
| 371 | mousePos.v - winRect.top); | | |
| 372 | break; | 443 | break; |
| 373 | } | 444 | } |
| 374 | case kEventMouseUp: | 445 | case kEventMouseUp: |
| 375 | case kEventMouseDown: { | 446 | case kEventMouseDown: |
| | 447 | { |
| 376 | uint32_t buttons; | 448 | uint32_t buttons; |
| 377 | GetEventParameter(event, kEventParamMouseChord, | 449 | uint32_t modifiers; |
| 378 | typeUInt32, 0, sizeof buttons, 0, &buttons); | 450 | GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, |
| 379 | mousebuttons = (buttons & 1) | 451 | 0, sizeof(modifiers), 0, &modifiers); |
| 380 | | ((buttons & 2)<<1) | 452 | GetEventParameter(event, kEventParamMouseChord, typeUInt32, |
| 381 | | ((buttons & 4)>>1); | 453 | 0, sizeof buttons, 0, &buttons); |
| | 454 | /* simulate other buttons via alt/apple key. like x11 */ |
| | 455 | if(modifiers & optionKey) { |
| | 456 | mousebuttons = ((buttons & 1) ? 2 : 0); |
| | 457 | altPressed = false; |
| | 458 | } else if(modifiers & cmdKey) |
| | 459 | mousebuttons = ((buttons & 1) ? 4 : 0); |
| | 460 | else |
| | 461 | mousebuttons = (buttons & 1); |
| | 462 | |
| | 463 | mousebuttons |= ((buttons & 2)<<1); |
| | 464 | mousebuttons |= ((buttons & 4)>>1); |
| | 465 | |
| 382 | } /* Fallthrough */ | 466 | } /* Fallthrough */ |
| 383 | case kEventMouseMoved: | 467 | case kEventMouseMoved: |
| 384 | case kEventMouseDragged: { | 468 | case kEventMouseDragged: |
| 385 | sendbuttons(mousebuttons, | 469 | mouseX = mousePos.h - winRect.left; |
| 386 | mousePos.h - winRect.left, | 470 | mouseY = mousePos.v - winRect.top; |
| 387 | mousePos.v - winRect.top); | 471 | sendbuttons(mousebuttons, mouseX, mouseY); |
| 388 | } | 472 | break; |
| 389 | break; | | |
| 390 | | | |
| 391 | default: | 473 | default: |
| 392 | result = eventNotHandledErr; | 474 | result = eventNotHandledErr; |
| 393 | break; | 475 | break; |
| @@ -396,6 +478,7 @@ if(0 && key != -1)fprint(2, "[%C]", key); · 2 unmodified lines |
| 396 | return result; | 478 | return result; |
| 397 | } | 479 | } |
| 398 | | 480 | |
| | 481 | |
| 399 | //default window command handler (from menus) | 482 | //default window command handler (from menus) |
| 400 | static OSStatus | 483 | static OSStatus |
| 401 | MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) | 484 | MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) |
| @@ -406,12 +489,12 @@ MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void * · 4 unmodified lines |
| 406 | | 489 | |
| 407 | result = CallNextEventHandler(nextHandler, event); | 490 | result = CallNextEventHandler(nextHandler, event); |
| 408 | | 491 | |
| 409 | if(class == kEventClassCommand){ | 492 | if(class == kEventClassCommand) { |
| 410 | HICommand theHICommand; | 493 | HICommand theHICommand; |
| 411 | GetEventParameter(event, kEventParamDirectObject, typeHICommand, | 494 | GetEventParameter(event, kEventParamDirectObject, typeHICommand, |
| 412 | NULL, sizeof(HICommand), NULL, &theHICommand); | 495 | NULL, sizeof(HICommand), NULL, &theHICommand); |
| 413 | | 496 | |
| 414 | switch(theHICommand.commandID){ | 497 | switch(theHICommand.commandID) { |
| 415 | case kHICommandQuit: | 498 | case kHICommandQuit: |
| 416 | cleanexit(0); | 499 | cleanexit(0); |
| 417 | break; | 500 | break; |
| @@ -424,7 +507,7 @@ MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void * · 6 unmodified lines |
| 424 | result = eventNotHandledErr; | 507 | result = eventNotHandledErr; |
| 425 | break; | 508 | break; |
| 426 | } | 509 | } |
| 427 | } else if(class == kEventClassWindow){ | 510 | } else if(class == kEventClassWindow) { |
| 428 | WindowRef window; | 511 | WindowRef window; |
| 429 | _Rect rectPort = {0,0,0,0}; | 512 | _Rect rectPort = {0,0,0,0}; |
| 430 | | 513 | |
| @@ -434,7 +517,7 @@ MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void * · 3 unmodified lines |
| 434 | if(window) | 517 | if(window) |
| 435 | GetPortBounds(GetWindowPort(window), &rectPort); | 518 | GetPortBounds(GetWindowPort(window), &rectPort); |
| 436 | | 519 | |
| 437 | switch (kind){ | 520 | switch(kind) { |
| 438 | case kEventWindowClosed: | 521 | case kEventWindowClosed: |
| 439 | theWindow = NULL; | 522 | theWindow = NULL; |
| 440 | cleanexit(0); // only one window | 523 | cleanexit(0); // only one window |
| @@ -485,15 +568,16 @@ flushmemscreen(Rectangle r) · 44 unmodified lines |
| 485 | // Drawing the sub-image is relative to the window. | 568 | // Drawing the sub-image is relative to the window. |
| 486 | rbounds.origin.y = winRect.bottom - winRect.top - r.min.y - rbounds.size.height; | 569 | rbounds.origin.y = winRect.bottom - winRect.top - r.min.y - rbounds.size.height; |
| 487 | CGContextDrawImage(context, rbounds, subimg); | 570 | CGContextDrawImage(context, rbounds, subimg); |
| 488 | CGContextFlush(context); | | |
| 489 | CGImageRelease(subimg); | 571 | CGImageRelease(subimg); |
| 490 | QDEndCGContext(GetWindowPort(theWindow), &context); | 572 | QDEndCGContext(GetWindowPort(theWindow), &context); |
| | 573 | |
| | 574 | needflush = true; |
| 491 | } | 575 | } |
| 492 | | 576 | |
| 493 | uchar* | 577 | uchar* |
| 494 | attachscreen(Rectangle *r, ulong *chan, int *depth, int *width, int *softscreen) | 578 | attachscreen(Rectangle *r, ulong *chan, int *depth, int *width, int *softscreen) |
| 495 | { | 579 | { |
| 496 | if(!triedscreen){ | 580 | if(!triedscreen) { |
| 497 | triedscreen = 1; | 581 | triedscreen = 1; |
| 498 | screeninit(); /* TO DO: call this elsewhere? */ | 582 | screeninit(); /* TO DO: call this elsewhere? */ |
| 499 | } | 583 | } |
| @@ -527,7 +611,6 @@ enum{ · 27 unmodified lines |
| 527 | SnarfSize= 100*1024 | 611 | SnarfSize= 100*1024 |
| 528 | }; | 612 | }; |
| 529 | | 613 | |
| 530 | | | |
| 531 | static char snarf[3*SnarfSize+1]; | 614 | static char snarf[3*SnarfSize+1]; |
| 532 | static Rune rsnarf[SnarfSize+1]; | 615 | static Rune rsnarf[SnarfSize+1]; |
| 533 | | 616 | |