formatting cleanup for X11Application.m (no code changes)

(cherry picked from commit eb083d3f68f459d90417558da1ed00729b749950)
This commit is contained in:
Ben Byer 2008-03-31 23:31:25 -07:00 committed by Jeremy Huddleston
parent e9e2d88436
commit 15b0084f1a

View File

@ -166,171 +166,170 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
static TSMDocumentID x11_document; static TSMDocumentID x11_document;
DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active) DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active)
if (state) { if (state) {
DarwinSendDDXEvent(kXquartzActivate, 0); DarwinSendDDXEvent(kXquartzActivate, 0);
if (!_x_active) { if (!_x_active) {
if (x11_document == 0 && darwinKeymapFile == NULL) { if (x11_document == 0 && darwinKeymapFile == NULL) {
OSType types[1]; OSType types[1];
types[0] = kUnicodeDocument; types[0] = kUnicodeDocument;
NewTSMDocument (1, types, &x11_document, 0); NewTSMDocument (1, types, &x11_document, 0);
} }
if (x11_document != 0) ActivateTSMDocument (x11_document); if (x11_document != 0) ActivateTSMDocument (x11_document);
} }
} else { } else {
DarwinSendDDXEvent(kXquartzDeactivate, 0); DarwinSendDDXEvent(kXquartzDeactivate, 0);
if (_x_active && x11_document != 0) if (_x_active && x11_document != 0)
DeactivateTSMDocument (x11_document); DeactivateTSMDocument (x11_document);
} }
_x_active = state; _x_active = state;
} }
- (void) became_key:(NSWindow *)win { - (void) became_key:(NSWindow *)win {
[self activateX:NO]; [self activateX:NO];
} }
- (void) sendEvent:(NSEvent *)e { - (void) sendEvent:(NSEvent *)e {
NSEventType type; NSEventType type;
BOOL for_appkit, for_x; BOOL for_appkit, for_x;
type = [e type];
/* By default pass down the responder chain and to X. */
for_appkit = YES;
for_x = YES;
type = [e type]; switch (type) {
case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown:
/* By default pass down the responder chain and to X. */ case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp:
for_appkit = YES; if ([e window] != nil) {
for_x = YES; /* Pointer event has an (AppKit) window. Probably something for the kit. */
for_x = NO;
switch (type) { if (_x_active) [self activateX:NO];
case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown: } else if ([self modalWindow] == nil) {
case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: /* Must be an X window. Tell appkit it doesn't have focus. */
if ([e window] != nil) { WindowPtr pWin = xprGetXWindowFromAppKit([e windowNumber]);
/* Pointer event has an (AppKit) window. Probably something for the kit. */ if (pWin) RootlessReorderWindow(pWin);
for_x = NO; for_appkit = NO;
if (_x_active) [self activateX:NO];
} else if ([self modalWindow] == nil) { if ([self isActive]) {
/* Must be an X window. Tell appkit it doesn't have focus. */ [self deactivate];
WindowPtr pWin = xprGetXWindowFromAppKit([e windowNumber]); if (!_x_active && quartzProcs->IsX11Window([e window],
if (pWin) RootlessReorderWindow(pWin); [e windowNumber]))
for_appkit = NO; [self activateX:YES];
}
if ([self isActive]) { }
[self deactivate]; break;
if (!_x_active && quartzProcs->IsX11Window([e window], case NSKeyDown: case NSKeyUp:
[e windowNumber])) if (_x_active) {
[self activateX:YES]; static int swallow_up;
}
} /* No kit window is focused, so send it to X. */
break; for_appkit = NO;
if (type == NSKeyDown) {
case NSKeyDown: case NSKeyUp: /* Before that though, see if there are any global
if (_x_active) { shortcuts bound to it. */
static int swallow_up;
if (X11EnableKeyEquivalents
/* No kit window is focused, so send it to X. */ && [[self mainMenu] performKeyEquivalent:e]) {
for_appkit = NO; swallow_up = [e keyCode];
if (type == NSKeyDown) { for_x = NO;
/* Before that though, see if there are any global } else if (!quartzEnableRootless
shortcuts bound to it. */ && ([e modifierFlags] & ALL_KEY_MASKS)
== (NSCommandKeyMask | NSAlternateKeyMask)
if (X11EnableKeyEquivalents && ([e keyCode] == 0 /*a*/
&& [[self mainMenu] performKeyEquivalent:e]) { || [e keyCode] == 53 /*Esc*/)) {
swallow_up = [e keyCode]; swallow_up = 0;
for_x = NO; for_x = NO;
} else if (!quartzEnableRootless
&& ([e modifierFlags] & ALL_KEY_MASKS)
== (NSCommandKeyMask | NSAlternateKeyMask)
&& ([e keyCode] == 0 /*a*/
|| [e keyCode] == 53 /*Esc*/)) {
swallow_up = 0;
for_x = NO;
#ifdef DARWIN_DDX_MISSING #ifdef DARWIN_DDX_MISSING
DarwinSendDDXEvent(kXquartzToggleFullscreen, 0); DarwinSendDDXEvent(kXquartzToggleFullscreen, 0);
#endif #endif
}
} else {
/* If we saw a key equivalent on the down, don't pass
the up through to X. */
if (swallow_up != 0 && [e keyCode] == swallow_up) {
swallow_up = 0;
for_x = NO;
}
}
} else for_x = NO;
break;
case NSFlagsChanged:
/* For the l33t X users who remap modifier keys to normal keysyms. */
if (!_x_active) for_x = NO;
break;
case NSAppKitDefined:
switch ([e subtype]) {
case NSApplicationActivatedEventType:
for_x = NO;
if ([self modalWindow] == nil) {
for_appkit = NO;
/* FIXME: hack to avoid having to pass the event to appkit,
which would cause it to raise one of its windows. */
_appFlags._active = YES;
[self activateX:YES];
if ([e data2] & 0x10) X11ApplicationSetFrontProcess();
}
break;
case 18: /* ApplicationDidReactivate */
if (quartzHasRoot) for_appkit = NO;
break;
case NSApplicationDeactivatedEventType:
for_x = NO;
[self activateX:NO];
break;
}
break;
default: break; /* for gcc */
} }
} else {
/* If we saw a key equivalent on the down, don't pass if (for_appkit) [super sendEvent:e];
the up through to X. */
if (for_x) send_nsevent (type, e);
if (swallow_up != 0 && [e keyCode] == swallow_up) {
swallow_up = 0;
for_x = NO;
}
}
} else for_x = NO;
break;
case NSFlagsChanged:
/* For the l33t X users who remap modifier keys to normal keysyms. */
if (!_x_active) for_x = NO;
break;
case NSAppKitDefined:
switch ([e subtype]) {
case NSApplicationActivatedEventType:
for_x = NO;
if ([self modalWindow] == nil) {
for_appkit = NO;
/* FIXME: hack to avoid having to pass the event to appkit,
which would cause it to raise one of its windows. */
_appFlags._active = YES;
[self activateX:YES];
if ([e data2] & 0x10) X11ApplicationSetFrontProcess();
}
break;
case 18: /* ApplicationDidReactivate */
if (quartzHasRoot) for_appkit = NO;
break;
case NSApplicationDeactivatedEventType:
for_x = NO;
[self activateX:NO];
break;
}
break;
default: break; /* for gcc */
}
if (for_appkit) [super sendEvent:e];
if (for_x) send_nsevent (type, e);
} }
- (void) set_window_menu:(NSArray *)list { - (void) set_window_menu:(NSArray *)list {
[_controller set_window_menu:list]; [_controller set_window_menu:list];
} }
- (void) set_window_menu_check:(NSNumber *)n { - (void) set_window_menu_check:(NSNumber *)n {
[_controller set_window_menu_check:n]; [_controller set_window_menu_check:n];
} }
- (void) set_apps_menu:(NSArray *)list { - (void) set_apps_menu:(NSArray *)list {
[_controller set_apps_menu:list]; [_controller set_apps_menu:list];
} }
- (void) set_front_process:unused { - (void) set_front_process:unused {
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
if ([self modalWindow] == nil) if ([self modalWindow] == nil)
[self activateX:YES]; [self activateX:YES];
} }
- (void) set_can_quit:(NSNumber *)state { - (void) set_can_quit:(NSNumber *)state {
[_controller set_can_quit:[state boolValue]]; [_controller set_can_quit:[state boolValue]];
} }
- (void) server_ready:unused { - (void) server_ready:unused {
[_controller server_ready]; [_controller server_ready];
} }
- (void) show_hide_menubar:(NSNumber *)state { - (void) show_hide_menubar:(NSNumber *)state {
if ([state boolValue]) ShowMenuBar (); if ([state boolValue]) ShowMenuBar ();
else HideMenuBar (); else HideMenuBar ();
} }
@ -348,57 +347,57 @@ static void cfrelease (CFAllocatorRef a, const void *b) {
} }
static CFMutableArrayRef nsarray_to_cfarray (NSArray *in) { static CFMutableArrayRef nsarray_to_cfarray (NSArray *in) {
CFMutableArrayRef out; CFMutableArrayRef out;
CFArrayCallBacks cb; CFArrayCallBacks cb;
NSObject *ns; NSObject *ns;
const CFTypeRef *cf; const CFTypeRef *cf;
int i, count; int i, count;
memset (&cb, 0, sizeof (cb)); memset (&cb, 0, sizeof (cb));
cb.version = 0; cb.version = 0;
cb.retain = cfretain; cb.retain = cfretain;
cb.release = cfrelease; cb.release = cfrelease;
count = [in count]; count = [in count];
out = CFArrayCreateMutable (NULL, count, &cb); out = CFArrayCreateMutable (NULL, count, &cb);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
ns = [in objectAtIndex:i]; ns = [in objectAtIndex:i];
if ([ns isKindOfClass:[NSArray class]]) if ([ns isKindOfClass:[NSArray class]])
cf = (CFTypeRef) nsarray_to_cfarray ((NSArray *) ns); cf = (CFTypeRef) nsarray_to_cfarray ((NSArray *) ns);
else else
cf = CFRetain ((CFTypeRef) ns); cf = CFRetain ((CFTypeRef) ns);
CFArrayAppendValue (out, cf); CFArrayAppendValue (out, cf);
CFRelease (cf); CFRelease (cf);
} }
return out; return out;
} }
static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) { static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) {
NSMutableArray *out; NSMutableArray *out;
const CFTypeRef *cf; const CFTypeRef *cf;
NSObject *ns; NSObject *ns;
int i, count; int i, count;
count = CFArrayGetCount (in); count = CFArrayGetCount (in);
out = [[NSMutableArray alloc] initWithCapacity:count]; out = [[NSMutableArray alloc] initWithCapacity:count];
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
cf = CFArrayGetValueAtIndex (in, i); cf = CFArrayGetValueAtIndex (in, i);
if (CFGetTypeID (cf) == CFArrayGetTypeID ()) if (CFGetTypeID (cf) == CFArrayGetTypeID ())
ns = cfarray_to_nsarray ((CFArrayRef) cf); ns = cfarray_to_nsarray ((CFArrayRef) cf);
else else
ns = [(id)cf retain]; ns = [(id)cf retain];
[out addObject:ns]; [out addObject:ns];
[ns release]; [ns release];
} }
return out; return out;
} }
- (CFPropertyListRef) prefs_get:(NSString *)key { - (CFPropertyListRef) prefs_get:(NSString *)key {
@ -855,86 +854,68 @@ convert_flags (unsigned int nsflags) {
return xflags; return xflags;
} }
// This code should probably be merged with that in XDarwin's XServer.m - BB
static void send_nsevent (NSEventType type, NSEvent *e) { static void send_nsevent (NSEventType type, NSEvent *e) {
// static unsigned int button_state = 0; NSRect screen;
NSRect screen; NSPoint location;
NSPoint location; NSWindow *window;
NSWindow *window; int pointer_x, pointer_y, ev_button, ev_type;
int pointer_x, pointer_y, ev_button, ev_type; float pressure, tilt_x, tilt_y;
float pressure, tilt_x, tilt_y;
/* convert location to global top-left coordinates */
location = [e locationInWindow];
window = [e window];
screen = [[[NSScreen screens] objectAtIndex:0] frame];
// int num_events=0, i=0, state;
// xEvent xe;
/* convert location to global top-left coordinates */
location = [e locationInWindow];
window = [e window];
screen = [[[NSScreen screens] objectAtIndex:0] frame];
if (window != nil) { if (window != nil) {
NSRect frame = [window frame]; NSRect frame = [window frame];
pointer_x = location.x + frame.origin.x; pointer_x = location.x + frame.origin.x;
pointer_y = (((screen.origin.y + screen.size.height) pointer_y = (((screen.origin.y + screen.size.height)
- location.y) - frame.origin.y); - location.y) - frame.origin.y);
} else { } else {
pointer_x = location.x; pointer_x = location.x;
pointer_y = (screen.origin.y + screen.size.height) - location.y; pointer_y = (screen.origin.y + screen.size.height) - location.y;
}
pointer_y -= aquaMenuBarHeight;
// state = convert_flags ([e modifierFlags]);
pressure = 0; // for tablets
tilt_x = 0;
tilt_y = 0;
switch (type) {
case NSLeftMouseDown: ev_button=1; ev_type=ButtonPress; goto handle_mouse;
case NSOtherMouseDown: ev_button=2; ev_type=ButtonPress; goto handle_mouse;
case NSRightMouseDown: ev_button=3; ev_type=ButtonPress; goto handle_mouse;
case NSLeftMouseUp: ev_button=1; ev_type=ButtonRelease; goto handle_mouse;
case NSOtherMouseUp: ev_button=2; ev_type=ButtonRelease; goto handle_mouse;
case NSRightMouseUp: ev_button=3; ev_type=ButtonRelease; goto handle_mouse;
case NSLeftMouseDragged: ev_button=1; ev_type=MotionNotify; goto handle_mouse;
case NSOtherMouseDragged: ev_button=2; ev_type=MotionNotify; goto handle_mouse;
case NSRightMouseDragged: ev_button=3; ev_type=MotionNotify; goto handle_mouse;
case NSTabletPoint:
pressure = [e pressure];
tilt_x = [e tilt].x;
tilt_y = [e tilt].y; // fall through
case NSMouseMoved: ev_button=0; ev_type=MotionNotify; goto handle_mouse;
handle_mouse:
/* I'm not sure the below code is necessary or useful (-bb)
if(ev_type==ButtonPress) {
if (!quartzProcs->IsX11Window([e window], [e windowNumber])) {
fprintf(stderr, "Dropping event because it's not a window\n");
break;
} }
button_state |= (1 << ev_button);
DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y);
} else if (ev_type==ButtonRelease && (button_state & (1 << ev_button)) == 0) break;
*/
// if ([e subtype] == NSTabletPointEventSubtype) pressure = [e pressure]; pointer_y -= aquaMenuBarHeight;
DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y,
pressure, tilt_x, tilt_y);
break;
case NSScrollWheel:
DarwinSendScrollEvents([e deltaY], pointer_x, pointer_y,
pressure, tilt_x, tilt_y);
break;
case NSKeyDown: // do we need to translate these keyCodes?
case NSKeyUp:
DarwinSendKeyboardEvents((type == NSKeyDown)?KeyPress:KeyRelease, [e keyCode]);
break;
case NSFlagsChanged: pressure = 0; // for tablets
DarwinUpdateModKeys([e modifierFlags]); tilt_x = 0;
break; tilt_y = 0;
default: break; /* for gcc */
} switch (type) {
case NSLeftMouseDown: ev_button=1; ev_type=ButtonPress; goto handle_mouse;
case NSOtherMouseDown: ev_button=2; ev_type=ButtonPress; goto handle_mouse;
case NSRightMouseDown: ev_button=3; ev_type=ButtonPress; goto handle_mouse;
case NSLeftMouseUp: ev_button=1; ev_type=ButtonRelease; goto handle_mouse;
case NSOtherMouseUp: ev_button=2; ev_type=ButtonRelease; goto handle_mouse;
case NSRightMouseUp: ev_button=3; ev_type=ButtonRelease; goto handle_mouse;
case NSLeftMouseDragged: ev_button=1; ev_type=MotionNotify; goto handle_mouse;
case NSOtherMouseDragged: ev_button=2; ev_type=MotionNotify; goto handle_mouse;
case NSRightMouseDragged: ev_button=3; ev_type=MotionNotify; goto handle_mouse;
case NSTabletPoint:
pressure = [e pressure];
tilt_x = [e tilt].x;
tilt_y = [e tilt].y; // fall through
case NSMouseMoved: ev_button=0; ev_type=MotionNotify; goto handle_mouse;
handle_mouse:
// if ([e subtype] == NSTabletPointEventSubtype) pressure = [e pressure];
DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y,
pressure, tilt_x, tilt_y);
break;
case NSScrollWheel:
DarwinSendScrollEvents([e deltaY], pointer_x, pointer_y,
pressure, tilt_x, tilt_y);
break;
case NSKeyDown: case NSKeyUp:
DarwinSendKeyboardEvents((type == NSKeyDown)?KeyPress:KeyRelease, [e keyCode]);
break;
case NSFlagsChanged:
DarwinUpdateModKeys([e modifierFlags]);
break;
default: break; /* for gcc */
}
} }