Ticket #29387: clutter-osx-flagschanged.patch

File clutter-osx-flagschanged.patch, 4.0 KB (added by craig+macports@…, 14 years ago)

Patch to clutter which generates "bare" modifier keypress events

  • clutter/osx/clutter-event-osx.c

    diff --git clutter/osx/clutter-event-osx.c clutter/osx/clutter-event-osx.c
    index 65876ed..1f329b4 100644
     
    115115   * to 'unicode_value'  Instead of <Shift>a or <Shift>3 you'd get <Shift>A
    116116   * and <Shift>#
    117117   */
     118
     119  if([self type] == NSFlagsChanged)
     120  {
     121      switch ([self keyCode]) {
     122          case 54: // Right Command
     123                return CLUTTER_KEY_Meta_R;
     124          case 55: // Left Command
     125                return CLUTTER_KEY_Meta_L;
     126          case 57: // Capslock
     127                return CLUTTER_KEY_Caps_Lock;
     128          case 56: // Left Shift
     129                return CLUTTER_KEY_Shift_L;
     130          case 60: // Right Shift
     131                return CLUTTER_KEY_Shift_R;
     132          case 58: // Left Alt
     133                return CLUTTER_KEY_Alt_L;
     134          case 61: // Right Alt
     135                return CLUTTER_KEY_Alt_R;
     136          case 59: // Left Ctrl
     137                return CLUTTER_KEY_Control_L;
     138          case 62: // Right Ctrl
     139                return CLUTTER_KEY_Control_R;
     140          case 63: // Function
     141                return CLUTTER_KEY_function;
     142      }
     143    return CLUTTER_KEY_VoidSymbol;
     144  }
     145
    118146  unichar c = [[self charactersIgnoringModifiers] characterAtIndex:0];
    119147
    120148  /* Latin-1 characters, 1:1 mapping - this ought to be reliable */
    clutter_event_osx_translate (NSEvent *nsevent, 
    366394      process_scroll_event (event, FALSE);
    367395      break;
    368396     
     397    case NSFlagsChanged:
     398      // FIXME: This logic fails if the user presses both Shift keys at once, for example:
     399      // we treat releasing one of them as keyDown.
     400      switch ([nsevent keyCode]) {
     401          case 54: // Right Command
     402          case 55: // Left Command
     403              if([nsevent modifierFlags] & NSCommandKeyMask) event->type = CLUTTER_KEY_PRESS;
     404              break;
     405 
     406          case 57: // Capslock
     407              if([nsevent modifierFlags] & NSAlphaShiftKeyMask) event->type = CLUTTER_KEY_PRESS;
     408              break;
     409 
     410          case 56: // Left Shift
     411          case 60: // Right Shift
     412              if([nsevent modifierFlags] & NSShiftKeyMask) event->type = CLUTTER_KEY_PRESS;
     413              break;
     414 
     415          case 58: // Left Alt
     416          case 61: // Right Alt
     417              if([nsevent modifierFlags] & NSAlternateKeyMask) event->type = CLUTTER_KEY_PRESS;
     418              break;
     419 
     420          case 59: // Left Ctrl
     421          case 62: // Right Ctrl
     422              if([nsevent modifierFlags] & NSControlKeyMask) event->type = CLUTTER_KEY_PRESS;
     423              break;
     424 
     425          case 63: // Function
     426              if([nsevent modifierFlags] & NSFunctionKeyMask) event->type = CLUTTER_KEY_PRESS;
     427              break;
     428      }
     429      /* fall through */
    369430    case NSKeyDown:
    370       event->type = CLUTTER_KEY_PRESS;
     431      if([nsevent type] == NSKeyDown) event->type = CLUTTER_KEY_PRESS;
    371432      /* fall through */
    372433    case NSKeyUp:
    373434      if (event->type != CLUTTER_KEY_PRESS)
    clutter_event_osx_translate (NSEvent *nsevent, 
    376437      event->key.hardware_keycode = [nsevent keyCode];
    377438      event->key.modifier_state = [nsevent clutterModifierState];
    378439      event->key.keyval = [nsevent clutterKeyVal];
    379       event->key.unicode_value = [[nsevent characters] characterAtIndex:0];
     440      event->key.unicode_value = [nsevent type] == NSFlagsChanged ? (gunichar)'\0' : [[nsevent characters] characterAtIndex:0];
    380441      clutter_event_set_device (event, manager_osx->core_keyboard);
    381442
    382443      CLUTTER_NOTE (EVENT, "key %d (%s) (%s) %s, keyval %d",
    383444                    [nsevent keyCode],
    384                     [[nsevent characters] UTF8String],
    385                     [[nsevent charactersIgnoringModifiers] UTF8String],
     445                    [nsevent type] == NSFlagsChanged ? "NULL" : [[nsevent characters] UTF8String],
     446                    [nsevent type] == NSFlagsChanged ? "NULL" : [[nsevent charactersIgnoringModifiers] UTF8String],
    386447                    event->type == CLUTTER_KEY_PRESS ? "press" : "release",
    387448                    event->key.keyval);
    388449      return TRUE;