History

20070831-0047

Charles.Forsyth committed 19 years ago

Commit 46f72201 parent 5bf0cee2 files · +136 −51Browse files

Unified · Split

2 files
  1. CHANGES +2 −0
  2. emu/MacOSX/win.c +134 −51
CHANGES+2−0
@@ -1,3 +1,5 @@
1+20070901
2+ add andrey's changes to emu/MacOSX/win.c (used by emu/MacOSX/mkfile-a)
13 20070817
24 two old changes that weren't in the distribution...
35 libkeyring/rsaalg.c: previously failed to ensure the output key was the right length (really rsagen should do that)
emu/MacOSX/win.c+134−51
@@ -41,7 +41,7 @@ Memimage *gscreen; · 40 unmodified lines
4141
4242 static int readybit;
4343 static Rendez rend;
44−static int triedscreen;
44+static int triedscreen;
4545
4646 ///
4747 // menu
@@ -64,6 +64,12 @@ static CGRect bounds; · 16 unmodified lines
6464 static PasteboardRef appleclip;
6565 static _Rect winRect;
6666
67+static Boolean altPressed = false;
68+static Boolean button2 = false;
69+static Boolean button3 = false;
70+
71+static Boolean needflush = false;
72+
6773
6874 static int
6975 isready(void*a)
@@ -73,7 +79,11 @@ isready(void*a) · 3 unmodified lines
7379
7480 CGContextRef QuartzContext;
7581
82+static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
83+static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
84+
7685 static void winproc(void *a);
86+static void flushproc(void *a);
7787
7888 void
7989 screeninit(void)
@@ -108,12 +118,10 @@ screeninit(void) · 28 unmodified lines
108118 dataProviderRef, 0, 0, kCGRenderingIntentDefault);
109119
110120 kproc("osxscreen", winproc, nil, 0);
121+ kproc("osxflush", flushproc, nil, 0);
111122 Sleep(&rend, isready, nil);
112123 }
113124
114−static OSStatus MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
115−static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData);
116−
117125 void
118126 window_resized(void)
119127 {
@@ -122,6 +130,21 @@ window_resized(void) · 2 unmodified lines
122130 bounds = CGRectMake(0, 0, winRect.right-winRect.left, winRect.bottom - winRect.top);
123131 }
124132
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+}
125148
126149 static void
127150 winproc(void *a)
@@ -208,7 +231,6 @@ winproc(void *a) · 80 unmodified lines
208231 ShowMenuBar();
209232 window_resized();
210233 SelectWindow(theWindow);
211−// terminit();
212234 // Run the event loop
213235 readybit = 1;
214236 Wakeup(&rend);
@@ -273,7 +295,6 @@ convert_key(UInt32 key, UInt32 charcode) · 58 unmodified lines
273295 void
274296 sendbuttons(int b, int x, int y)
275297 {
276− /* TO DO: add special keyboard characters as mouse buttons */
277298 mousetrack(b, x, y, 0);
278299 }
279300
@@ -306,7 +327,9 @@ full_screen(void) · 26 unmodified lines
306327 BeginFullScreen(&fullScreenRestore, 0, 0, 0, &theWindow, 0, 0);
307328 amFullScreen = 1;
308329 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} };
310333 drawqlock();
311334 flushmemscreen(rect);
312335 drawqunlock();
@@ -320,6 +343,10 @@ MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *us · 7 unmodified lines
320343 result = CallNextEventHandler(nextHandler, event);
321344 UInt32 class = GetEventClass (event);
322345 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+
323350 if(class == kEventClassKeyboard) {
324351 char macCharCodes;
325352 UInt32 macKeyCode;
@@ -331,24 +358,69 @@ MainWindowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *us · 5 unmodified lines
331358 sizeof(macKeyCode), NULL, &macKeyCode);
332359 GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL,
333360 sizeof(macKeyModifiers), NULL, &macKeyModifiers);
334− switch(kind) {
361+ switch(kind) {
335362 case kEventRawKeyModifiersChanged:
336− if (macKeyModifiers == 0x1800) leave_full_screen();
337− break;
338− case kEventRawKeyDown:
339− case kEventRawKeyRepeat: {
340− if(macKeyModifiers != 256) {
341− if (kind == kEventRawKeyRepeat || kind == kEventRawKeyDown) {
342− int key = convert_key(macKeyCode, macCharCodes);
343− if(key != -1)
344− gkbdputc(gkbdq, key);
345−if(0 && key != -1)fprint(2, "[%C]", key);
363+ if (macKeyModifiers == (controlKey | optionKey)) leave_full_screen();
364+
365+ switch(macKeyModifiers & (optionKey | cmdKey)) {
366+ case (optionKey | cmdKey):
367+ /* due to chording we need to handle the case when both
368+ * modifier keys are pressed at the same time.
369+ * currently it's only 2-3 snarf and the 3-2 noop
370+ */
371+ altPressed = true;
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);
346386 }
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;
347414 }
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
349422 result = eventNotHandledErr;
350423 break;
351− }
352424 default:
353425 break;
354426 }
@@ -359,35 +431,45 @@ if(0 && key != -1)fprint(2, "[%C]", key); · 4 unmodified lines
359431 GetEventParameter(event, kEventParamMouseLocation, typeQDPoint,
360432 0, sizeof mousePos, 0, &mousePos);
361433
362− static uint32_t mousebuttons = 0; // bitmask of buttons currently down
363−
364− switch (kind) {
365− case kEventMouseWheelMoved: {
366− int32_t wheeldelta;
367− GetEventParameter(event,kEventParamMouseWheelDelta,typeLongInteger,
368− 0,sizeof(EventMouseButton), 0, &wheeldelta);
369− sendbuttons((int16_t)wheeldelta>0 ? 8 : 16,
370− mousePos.h - winRect.left,
371− mousePos.v - winRect.top);
434+ switch(kind) {
435+ case kEventMouseWheelMoved:
436+ {
437+ int32_t wheeldelta;
438+ GetEventParameter(event,kEventParamMouseWheelDelta,typeSInt32,
439+ 0,sizeof(wheeldelta), 0, &wheeldelta);
440+ mouseX = mousePos.h - winRect.left;
441+ mouseY = mousePos.v - winRect.top;
442+ sendbuttons(wheeldelta>0 ? 8 : 16, mouseX, mouseY);
372443 break;
373444 }
374445 case kEventMouseUp:
375− case kEventMouseDown: {
446+ case kEventMouseDown:
447+ {
376448 uint32_t buttons;
377− GetEventParameter(event, kEventParamMouseChord,
378− typeUInt32, 0, sizeof buttons, 0, &buttons);
379− mousebuttons = (buttons & 1)
380− | ((buttons & 2)<<1)
381− | ((buttons & 4)>>1);
449+ uint32_t modifiers;
450+ GetEventParameter(event, kEventParamKeyModifiers, typeUInt32,
451+ 0, sizeof(modifiers), 0, &modifiers);
452+ GetEventParameter(event, kEventParamMouseChord, typeUInt32,
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+
382466 } /* Fallthrough */
383467 case kEventMouseMoved:
384− case kEventMouseDragged: {
385− sendbuttons(mousebuttons,
386− mousePos.h - winRect.left,
387− mousePos.v - winRect.top);
388− }
389− break;
390−
468+ case kEventMouseDragged:
469+ mouseX = mousePos.h - winRect.left;
470+ mouseY = mousePos.v - winRect.top;
471+ sendbuttons(mousebuttons, mouseX, mouseY);
472+ break;
391473 default:
392474 result = eventNotHandledErr;
393475 break;
@@ -396,6 +478,7 @@ if(0 && key != -1)fprint(2, "[%C]", key); · 2 unmodified lines
396478 return result;
397479 }
398480
481+
399482 //default window command handler (from menus)
400483 static OSStatus
401484 MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData)
@@ -406,12 +489,12 @@ MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void * · 4 unmodified lines
406489
407490 result = CallNextEventHandler(nextHandler, event);
408491
409− if(class == kEventClassCommand){
492+ if(class == kEventClassCommand) {
410493 HICommand theHICommand;
411494 GetEventParameter(event, kEventParamDirectObject, typeHICommand,
412495 NULL, sizeof(HICommand), NULL, &theHICommand);
413496
414− switch(theHICommand.commandID){
497+ switch(theHICommand.commandID) {
415498 case kHICommandQuit:
416499 cleanexit(0);
417500 break;
@@ -424,7 +507,7 @@ MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void * · 6 unmodified lines
424507 result = eventNotHandledErr;
425508 break;
426509 }
427− } else if(class == kEventClassWindow){
510+ } else if(class == kEventClassWindow) {
428511 WindowRef window;
429512 _Rect rectPort = {0,0,0,0};
430513
@@ -434,7 +517,7 @@ MainWindowCommandHandler(EventHandlerCallRef nextHandler, EventRef event, void * · 3 unmodified lines
434517 if(window)
435518 GetPortBounds(GetWindowPort(window), &rectPort);
436519
437− switch (kind){
520+ switch(kind) {
438521 case kEventWindowClosed:
439522 theWindow = NULL;
440523 cleanexit(0); // only one window
@@ -485,15 +568,16 @@ flushmemscreen(Rectangle r) · 44 unmodified lines
485568 // Drawing the sub-image is relative to the window.
486569 rbounds.origin.y = winRect.bottom - winRect.top - r.min.y - rbounds.size.height;
487570 CGContextDrawImage(context, rbounds, subimg);
488− CGContextFlush(context);
489571 CGImageRelease(subimg);
490572 QDEndCGContext(GetWindowPort(theWindow), &context);
573+
574+ needflush = true;
491575 }
492576
493577 uchar*
494578 attachscreen(Rectangle *r, ulong *chan, int *depth, int *width, int *softscreen)
495−{
496− if(!triedscreen){
579+{
580+ if(!triedscreen) {
497581 triedscreen = 1;
498582 screeninit(); /* TO DO: call this elsewhere? */
499583 }
@@ -527,7 +611,6 @@ enum{ · 27 unmodified lines
527611 SnarfSize= 100*1024
528612 };
529613
530−
531614 static char snarf[3*SnarfSize+1];
532615 static Rune rsnarf[SnarfSize+1];
533616