2007-02-27 02:06:53 +01:00
|
|
|
/* X11Application.m -- subclass of NSApplication to multiplex events
|
|
|
|
|
2008-04-01 07:55:24 +02:00
|
|
|
Copyright (c) 2002-2008 Apple Inc.
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person
|
|
|
|
obtaining a copy of this software and associated documentation files
|
|
|
|
(the "Software"), to deal in the Software without restriction,
|
|
|
|
including without limitation the rights to use, copy, modify, merge,
|
|
|
|
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
|
|
|
|
HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name(s) of the above
|
|
|
|
copyright holders shall not be used in advertising or otherwise to
|
|
|
|
promote the sale, use or other dealings in this Software without
|
|
|
|
prior written authorization. */
|
2008-04-19 05:06:17 +02:00
|
|
|
|
|
|
|
#include "sanitizedCarbon.h"
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2007-11-29 11:19:22 +01:00
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2008-04-19 05:30:43 +02:00
|
|
|
#include "quartzCommon.h"
|
2008-04-27 04:21:05 +02:00
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
#import "X11Application.h"
|
|
|
|
|
2008-05-17 23:56:53 +02:00
|
|
|
#include "darwin.h"
|
|
|
|
#include "darwinEvents.h"
|
2008-09-25 07:51:03 +02:00
|
|
|
#include "quartzKeyboard.h"
|
2008-05-17 23:56:53 +02:00
|
|
|
#include "quartz.h"
|
|
|
|
#define _APPLEWM_SERVER_
|
|
|
|
#include "X11/extensions/applewm.h"
|
|
|
|
#include "micmap.h"
|
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
#include <mach/mach.h>
|
|
|
|
#include <unistd.h>
|
2008-11-17 00:35:17 +01:00
|
|
|
#include <AvailabilityMacros.h>
|
2008-04-27 04:21:05 +02:00
|
|
|
|
2008-08-27 04:13:56 +02:00
|
|
|
#include <Xplugin.h>
|
|
|
|
|
2008-11-16 04:52:34 +01:00
|
|
|
// pbproxy/pbproxy.h
|
|
|
|
extern BOOL xpbproxy_init (void);
|
|
|
|
|
2008-12-09 06:00:11 +01:00
|
|
|
#define DEFAULTS_FILE X11LIBDIR"/X11/xserver/Xquartz.plist"
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2008-04-30 08:59:26 +02:00
|
|
|
#ifndef XSERVER_VERSION
|
|
|
|
#define XSERVER_VERSION "?"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ProximityIn 0
|
|
|
|
#define ProximityOut 1
|
|
|
|
|
2008-12-30 04:54:12 +01:00
|
|
|
/* Stuck modifier / button state... force release when we context switch */
|
|
|
|
static NSEventType keyState[NUM_KEYCODES];
|
2009-01-11 23:49:39 +01:00
|
|
|
static int modifierFlagsMask;
|
2008-12-30 04:54:12 +01:00
|
|
|
|
2008-11-01 04:03:34 +01:00
|
|
|
int X11EnableKeyEquivalents = TRUE, quartzFullscreenMenu = FALSE;
|
2007-02-27 02:06:53 +01:00
|
|
|
int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
|
|
|
|
|
2008-11-28 21:59:09 +01:00
|
|
|
extern Bool noTestExtensions;
|
|
|
|
|
2008-11-16 04:45:49 +01:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
|
2008-09-25 07:51:03 +02:00
|
|
|
static TISInputSourceRef last_key_layout;
|
2008-11-16 04:45:49 +01:00
|
|
|
#else
|
|
|
|
static KeyboardLayoutRef last_key_layout;
|
|
|
|
#endif
|
2008-09-25 07:51:03 +02:00
|
|
|
|
2008-05-15 14:49:43 +02:00
|
|
|
extern int darwinFakeButtons;
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
X11Application *X11App;
|
|
|
|
|
2008-11-25 09:15:53 +01:00
|
|
|
CFStringRef app_prefs_domain_cfstr = NULL;
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
#define ALL_KEY_MASKS (NSShiftKeyMask | NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask)
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2008-08-20 19:37:17 +02:00
|
|
|
@interface X11Application (Private)
|
|
|
|
- (void) sendX11NSEvent:(NSEvent *)e;
|
|
|
|
@end
|
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
@implementation X11Application
|
|
|
|
|
|
|
|
typedef struct message_struct message;
|
|
|
|
struct message_struct {
|
|
|
|
mach_msg_header_t hdr;
|
|
|
|
SEL selector;
|
|
|
|
NSObject *arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
static mach_port_t _port;
|
|
|
|
|
|
|
|
/* Quartz mode initialization routine. This is often dynamically loaded
|
2007-12-20 22:17:30 +01:00
|
|
|
but is statically linked into this X server. */
|
|
|
|
Bool QuartzModeBundleInit(void);
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
static void init_ports (void) {
|
2007-02-27 02:06:53 +01:00
|
|
|
kern_return_t r;
|
|
|
|
NSPort *p;
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
if (_port != MACH_PORT_NULL) return;
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
r = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &_port);
|
2007-03-01 10:45:19 +01:00
|
|
|
if (r != KERN_SUCCESS) return;
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
p = [NSMachPort portWithMachPort:_port];
|
|
|
|
[p setDelegate:NSApp];
|
|
|
|
[p scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
static void message_kit_thread (SEL selector, NSObject *arg) {
|
2007-02-27 02:06:53 +01:00
|
|
|
message msg;
|
|
|
|
kern_return_t r;
|
|
|
|
|
|
|
|
msg.hdr.msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_MAKE_SEND, 0);
|
|
|
|
msg.hdr.msgh_size = sizeof (msg);
|
|
|
|
msg.hdr.msgh_remote_port = _port;
|
|
|
|
msg.hdr.msgh_local_port = MACH_PORT_NULL;
|
|
|
|
msg.hdr.msgh_reserved = 0;
|
|
|
|
msg.hdr.msgh_id = 0;
|
|
|
|
|
|
|
|
msg.selector = selector;
|
|
|
|
msg.arg = [arg retain];
|
|
|
|
|
|
|
|
r = mach_msg (&msg.hdr, MACH_SEND_MSG, msg.hdr.msgh_size,
|
2007-03-01 10:45:19 +01:00
|
|
|
0, MACH_PORT_NULL, 0, MACH_PORT_NULL);
|
2007-02-27 02:06:53 +01:00
|
|
|
if (r != KERN_SUCCESS)
|
2007-03-01 10:45:19 +01:00
|
|
|
ErrorF("%s: mach_msg failed: %x\n", __FUNCTION__, r);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) handleMachMessage:(void *)_msg {
|
2007-02-27 02:06:53 +01:00
|
|
|
message *msg = _msg;
|
|
|
|
|
|
|
|
[self performSelector:msg->selector withObject:msg->arg];
|
|
|
|
[msg->arg release];
|
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) set_controller:obj {
|
|
|
|
if (_controller == nil) _controller = [obj retain];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) dealloc {
|
|
|
|
if (_controller != nil) [_controller release];
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
if (_port != MACH_PORT_NULL)
|
|
|
|
mach_port_deallocate (mach_task_self (), _port);
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) orderFrontStandardAboutPanel: (id) sender {
|
2007-02-27 02:06:53 +01:00
|
|
|
NSMutableDictionary *dict;
|
|
|
|
NSDictionary *infoDict;
|
|
|
|
NSString *tem;
|
2008-05-12 22:36:35 +02:00
|
|
|
|
|
|
|
dict = [NSMutableDictionary dictionaryWithCapacity:3];
|
2007-02-27 02:06:53 +01:00
|
|
|
infoDict = [[NSBundle mainBundle] infoDictionary];
|
2008-05-12 22:36:35 +02:00
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
[dict setObject: NSLocalizedString (@"The X Window System", @"About panel")
|
2008-05-12 22:36:35 +02:00
|
|
|
forKey:@"ApplicationName"];
|
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
tem = [infoDict objectForKey:@"CFBundleShortVersionString"];
|
2008-05-12 22:36:35 +02:00
|
|
|
|
|
|
|
[dict setObject:[NSString stringWithFormat:@"XQuartz %@", tem]
|
|
|
|
forKey:@"ApplicationVersion"];
|
|
|
|
|
|
|
|
[dict setObject:[NSString stringWithFormat:@"xorg-server %s", XSERVER_VERSION]
|
|
|
|
forKey:@"Version"];
|
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
[self orderFrontStandardAboutPanelWithOptions: dict];
|
|
|
|
}
|
|
|
|
|
2008-04-19 05:25:38 +02:00
|
|
|
- (void) activateX:(OSX_BOOL)state {
|
2007-02-27 02:06:53 +01:00
|
|
|
/* Create a TSM document that supports full Unicode input, and
|
2008-12-30 04:54:12 +01:00
|
|
|
have it activated while X is active */
|
2007-02-27 02:06:53 +01:00
|
|
|
static TSMDocumentID x11_document;
|
2008-12-30 04:54:12 +01:00
|
|
|
size_t i;
|
|
|
|
DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active)
|
2007-03-01 10:45:19 +01:00
|
|
|
if (state) {
|
2008-12-30 04:54:12 +01:00
|
|
|
DarwinSendDDXEvent(kXquartzActivate, 0);
|
2008-04-01 08:31:25 +02:00
|
|
|
|
2008-12-30 04:54:12 +01:00
|
|
|
if (!_x_active) {
|
|
|
|
if (x11_document == 0) {
|
|
|
|
OSType types[1];
|
|
|
|
types[0] = kUnicodeDocument;
|
|
|
|
NewTSMDocument (1, types, &x11_document, 0);
|
|
|
|
}
|
2008-04-01 08:31:25 +02:00
|
|
|
|
2008-12-30 04:54:12 +01:00
|
|
|
if (x11_document != 0) ActivateTSMDocument (x11_document);
|
|
|
|
}
|
2007-03-01 10:45:19 +01:00
|
|
|
} else {
|
2008-04-01 08:31:25 +02:00
|
|
|
|
2009-01-11 23:49:39 +01:00
|
|
|
if(darwin_modifier_flags)
|
|
|
|
DarwinUpdateModKeys(0);
|
2008-12-30 04:54:12 +01:00
|
|
|
for(i=0; i < NUM_KEYCODES; i++) {
|
2008-12-31 20:57:49 +01:00
|
|
|
if(keyState[i] == NSKeyDown) {
|
2008-12-30 04:54:12 +01:00
|
|
|
DarwinSendKeyboardEvents(KeyRelease, i);
|
2008-12-31 20:57:49 +01:00
|
|
|
keyState[i] = NSKeyUp;
|
|
|
|
}
|
2008-12-30 04:54:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DarwinSendDDXEvent(kXquartzDeactivate, 0);
|
2008-04-01 08:31:25 +02:00
|
|
|
|
2008-12-30 04:54:12 +01:00
|
|
|
if (_x_active && x11_document != 0)
|
|
|
|
DeactivateTSMDocument (x11_document);
|
|
|
|
}
|
|
|
|
|
|
|
|
_x_active = state;
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) became_key:(NSWindow *)win {
|
2008-04-01 08:31:25 +02:00
|
|
|
[self activateX:NO];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) sendEvent:(NSEvent *)e {
|
2008-08-20 18:58:48 +02:00
|
|
|
OSX_BOOL for_appkit, for_x;
|
|
|
|
|
|
|
|
/* By default pass down the responder chain and to X. */
|
|
|
|
for_appkit = YES;
|
|
|
|
for_x = YES;
|
2008-08-19 11:02:11 +02:00
|
|
|
|
2008-08-20 18:58:48 +02:00
|
|
|
switch ([e type]) {
|
|
|
|
case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown:
|
|
|
|
case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp:
|
|
|
|
if ([e window] != nil) {
|
|
|
|
/* Pointer event has an (AppKit) window. Probably something for the kit. */
|
|
|
|
for_x = NO;
|
|
|
|
if (_x_active) [self activateX:NO];
|
|
|
|
} else if ([self modalWindow] == nil) {
|
|
|
|
/* Must be an X window. Tell appkit it doesn't have focus. */
|
|
|
|
for_appkit = NO;
|
|
|
|
|
|
|
|
if ([self isActive]) {
|
|
|
|
[self deactivate];
|
|
|
|
if (!_x_active && quartzProcs->IsX11Window([e window],
|
|
|
|
[e windowNumber]))
|
|
|
|
[self activateX:YES];
|
|
|
|
}
|
|
|
|
}
|
2008-11-13 21:45:35 +01:00
|
|
|
|
|
|
|
/* We want to force sending to appkit if we're over the menu bar */
|
|
|
|
if(!for_appkit) {
|
|
|
|
NSPoint NSlocation = [e locationInWindow];
|
|
|
|
NSWindow *window = [e window];
|
|
|
|
|
|
|
|
if (window != nil) {
|
|
|
|
NSRect frame = [window frame];
|
|
|
|
NSlocation.x += frame.origin.x;
|
|
|
|
NSlocation.y += frame.origin.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSRect NSframe = [[NSScreen mainScreen] frame];
|
|
|
|
NSRect NSvisibleFrame = [[NSScreen mainScreen] visibleFrame];
|
|
|
|
|
|
|
|
CGRect CGframe = CGRectMake(NSframe.origin.x, NSframe.origin.y,
|
|
|
|
NSframe.size.width, NSframe.size.height);
|
|
|
|
CGRect CGvisibleFrame = CGRectMake(NSvisibleFrame.origin.x,
|
|
|
|
NSvisibleFrame.origin.y,
|
|
|
|
NSvisibleFrame.size.width,
|
|
|
|
NSvisibleFrame.size.height);
|
|
|
|
CGPoint CGlocation = CGPointMake(NSlocation.x, NSlocation.y);
|
|
|
|
|
|
|
|
if(CGRectContainsPoint(CGframe, CGlocation) &&
|
|
|
|
!CGRectContainsPoint(CGvisibleFrame, CGlocation))
|
|
|
|
for_appkit = YES;
|
|
|
|
}
|
|
|
|
|
2008-08-20 18:58:48 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NSKeyDown: case NSKeyUp:
|
2008-08-27 04:13:56 +02:00
|
|
|
|
|
|
|
if(_x_active) {
|
2008-12-22 06:03:59 +01:00
|
|
|
static BOOL do_swallow = NO;
|
|
|
|
static int swallow_keycode;
|
2008-08-20 18:58:48 +02:00
|
|
|
|
2008-08-27 04:13:56 +02:00
|
|
|
if([e type] == NSKeyDown) {
|
2008-08-20 18:58:48 +02:00
|
|
|
/* Before that though, see if there are any global
|
2008-10-21 18:07:08 +02:00
|
|
|
* shortcuts bound to it. */
|
2008-08-27 04:13:56 +02:00
|
|
|
|
|
|
|
if(darwinAppKitModMask & [e modifierFlags]) {
|
|
|
|
/* Override to force sending to Appkit */
|
2008-12-22 06:03:59 +01:00
|
|
|
swallow_keycode = [e keyCode];
|
|
|
|
do_swallow = YES;
|
2008-08-20 18:58:48 +02:00
|
|
|
for_x = NO;
|
2008-08-27 06:11:35 +02:00
|
|
|
#if XPLUGIN_VERSION >= 1
|
2008-08-29 12:54:55 +02:00
|
|
|
} else if(X11EnableKeyEquivalents &&
|
2008-12-22 06:03:59 +01:00
|
|
|
xp_is_symbolic_hotkey_event([e eventRef])) {
|
|
|
|
swallow_keycode = [e keyCode];
|
|
|
|
do_swallow = YES;
|
2008-08-29 12:54:55 +02:00
|
|
|
for_x = NO;
|
|
|
|
#endif
|
|
|
|
} else if(X11EnableKeyEquivalents &&
|
2008-08-27 04:13:56 +02:00
|
|
|
[[self mainMenu] performKeyEquivalent:e]) {
|
2008-12-22 06:03:59 +01:00
|
|
|
swallow_keycode = [e keyCode];
|
|
|
|
do_swallow = YES;
|
2008-08-27 04:13:56 +02:00
|
|
|
for_appkit = NO;
|
2008-10-21 18:07:08 +02:00
|
|
|
for_x = NO;
|
|
|
|
} else if(!quartzEnableRootless
|
|
|
|
&& ([e modifierFlags] & ALL_KEY_MASKS) == (NSCommandKeyMask | NSAlternateKeyMask)
|
|
|
|
&& ([e keyCode] == 0 /*a*/ || [e keyCode] == 53 /*Esc*/)) {
|
|
|
|
/* We have this here to force processing fullscreen
|
|
|
|
* toggle even if X11EnableKeyEquivalents is disabled */
|
2008-12-22 06:03:59 +01:00
|
|
|
swallow_keycode = [e keyCode];
|
|
|
|
do_swallow = YES;
|
2008-08-27 04:13:56 +02:00
|
|
|
for_x = NO;
|
2008-10-21 18:07:08 +02:00
|
|
|
for_appkit = NO;
|
|
|
|
DarwinSendDDXEvent(kXquartzToggleFullscreen, 0);
|
2008-08-27 04:13:56 +02:00
|
|
|
} else {
|
|
|
|
/* No kit window is focused, so send it to X. */
|
|
|
|
for_appkit = NO;
|
2008-08-20 18:58:48 +02:00
|
|
|
}
|
2008-08-27 04:13:56 +02:00
|
|
|
} else { /* KeyUp */
|
2008-08-20 18:58:48 +02:00
|
|
|
/* If we saw a key equivalent on the down, don't pass
|
2008-10-21 18:07:08 +02:00
|
|
|
* the up through to X. */
|
2008-12-22 06:03:59 +01:00
|
|
|
if (do_swallow && [e keyCode] == swallow_keycode) {
|
|
|
|
do_swallow = NO;
|
2008-08-20 18:58:48 +02:00
|
|
|
for_x = NO;
|
|
|
|
}
|
|
|
|
}
|
2008-08-27 04:13:56 +02:00
|
|
|
} else { /* !_x_active */
|
2008-08-20 18:58:48 +02:00
|
|
|
for_x = NO;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSFlagsChanged:
|
|
|
|
/* Don't tell X11 about modifiers changing while it's not active */
|
|
|
|
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];
|
2008-10-23 20:37:13 +02:00
|
|
|
|
|
|
|
/* Get the Spaces preference for SwitchOnActivate */
|
|
|
|
(void)CFPreferencesAppSynchronize(CFSTR(".GlobalPreferences"));
|
|
|
|
BOOL switch_on_activate, ok;
|
|
|
|
switch_on_activate = CFPreferencesGetAppBooleanValue(CFSTR("AppleSpacesSwitchOnActivate"), CFSTR(".GlobalPreferences"), &ok);
|
|
|
|
if(!ok)
|
|
|
|
switch_on_activate = YES;
|
|
|
|
|
2008-10-23 20:41:22 +02:00
|
|
|
if ([e data2] & 0x10 && switch_on_activate) // 0x10 is set when we use cmd-tab or the dock icon
|
2008-08-20 18:58:48 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzBringAllToFront, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 18: /* ApplicationDidReactivate */
|
|
|
|
if (quartzHasRoot) for_appkit = NO;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSApplicationDeactivatedEventType:
|
|
|
|
for_x = NO;
|
|
|
|
[self activateX:NO];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break; /* for gcc */
|
2008-08-19 11:02:11 +02:00
|
|
|
}
|
2008-08-20 18:58:48 +02:00
|
|
|
|
|
|
|
if (for_appkit) [super sendEvent:e];
|
|
|
|
|
2008-08-20 19:37:17 +02:00
|
|
|
if (for_x) [self sendX11NSEvent:e];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) set_window_menu:(NSArray *)list {
|
2008-04-01 08:31:25 +02:00
|
|
|
[_controller set_window_menu:list];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) set_window_menu_check:(NSNumber *)n {
|
2008-04-01 08:31:25 +02:00
|
|
|
[_controller set_window_menu_check:n];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) set_apps_menu:(NSArray *)list {
|
2008-04-01 08:31:25 +02:00
|
|
|
[_controller set_apps_menu:list];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) set_front_process:unused {
|
2008-04-01 08:31:25 +02:00
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2008-03-29 01:02:02 +01:00
|
|
|
|
2008-04-01 08:31:25 +02:00
|
|
|
if ([self modalWindow] == nil)
|
|
|
|
[self activateX:YES];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) set_can_quit:(NSNumber *)state {
|
2008-04-01 08:31:25 +02:00
|
|
|
[_controller set_can_quit:[state boolValue]];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) server_ready:unused {
|
2008-04-01 08:31:25 +02:00
|
|
|
[_controller server_ready];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) show_hide_menubar:(NSNumber *)state {
|
2008-11-01 04:03:34 +01:00
|
|
|
/* Also shows/hides the dock */
|
|
|
|
if ([state boolValue])
|
|
|
|
SetSystemUIMode(kUIModeNormal, 0);
|
|
|
|
else
|
|
|
|
SetSystemUIMode(kUIModeAllHidden, quartzFullscreenMenu ? kUIOptionAutoShowMenuBar : 0); // kUIModeAllSuppressed or kUIOptionAutoShowMenuBar can be used to allow "mouse-activation"
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* user preferences */
|
|
|
|
|
|
|
|
/* Note that these functions only work for arrays whose elements
|
|
|
|
can be toll-free-bridged between NS and CF worlds. */
|
|
|
|
|
|
|
|
static const void *cfretain (CFAllocatorRef a, const void *b) {
|
|
|
|
return CFRetain (b);
|
|
|
|
}
|
2007-03-01 10:45:19 +01:00
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
static void cfrelease (CFAllocatorRef a, const void *b) {
|
|
|
|
CFRelease (b);
|
|
|
|
}
|
2007-03-01 10:45:19 +01:00
|
|
|
|
|
|
|
static CFMutableArrayRef nsarray_to_cfarray (NSArray *in) {
|
2008-04-01 08:31:25 +02:00
|
|
|
CFMutableArrayRef out;
|
|
|
|
CFArrayCallBacks cb;
|
|
|
|
NSObject *ns;
|
|
|
|
const CFTypeRef *cf;
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
memset (&cb, 0, sizeof (cb));
|
|
|
|
cb.version = 0;
|
|
|
|
cb.retain = cfretain;
|
|
|
|
cb.release = cfrelease;
|
|
|
|
|
|
|
|
count = [in count];
|
|
|
|
out = CFArrayCreateMutable (NULL, count, &cb);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
ns = [in objectAtIndex:i];
|
|
|
|
|
|
|
|
if ([ns isKindOfClass:[NSArray class]])
|
|
|
|
cf = (CFTypeRef) nsarray_to_cfarray ((NSArray *) ns);
|
|
|
|
else
|
|
|
|
cf = CFRetain ((CFTypeRef) ns);
|
|
|
|
|
|
|
|
CFArrayAppendValue (out, cf);
|
|
|
|
CFRelease (cf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
2007-03-01 10:45:19 +01:00
|
|
|
|
|
|
|
static NSMutableArray * cfarray_to_nsarray (CFArrayRef in) {
|
2008-04-01 08:31:25 +02:00
|
|
|
NSMutableArray *out;
|
|
|
|
const CFTypeRef *cf;
|
|
|
|
NSObject *ns;
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
count = CFArrayGetCount (in);
|
|
|
|
out = [[NSMutableArray alloc] initWithCapacity:count];
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
cf = CFArrayGetValueAtIndex (in, i);
|
|
|
|
|
|
|
|
if (CFGetTypeID (cf) == CFArrayGetTypeID ())
|
|
|
|
ns = cfarray_to_nsarray ((CFArrayRef) cf);
|
|
|
|
else
|
|
|
|
ns = [(id)cf retain];
|
|
|
|
|
|
|
|
[out addObject:ns];
|
|
|
|
[ns release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (CFPropertyListRef) prefs_get:(NSString *)key {
|
2007-02-27 02:06:53 +01:00
|
|
|
CFPropertyListRef value;
|
|
|
|
|
2008-11-25 09:15:53 +01:00
|
|
|
value = CFPreferencesCopyAppValue ((CFStringRef) key, app_prefs_domain_cfstr);
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
if (value == NULL) {
|
|
|
|
static CFDictionaryRef defaults;
|
|
|
|
|
|
|
|
if (defaults == NULL) {
|
|
|
|
CFStringRef error = NULL;
|
|
|
|
CFDataRef data;
|
|
|
|
CFURLRef url;
|
|
|
|
SInt32 error_code;
|
|
|
|
|
|
|
|
url = (CFURLCreateFromFileSystemRepresentation
|
|
|
|
(NULL, (unsigned char *)DEFAULTS_FILE, strlen (DEFAULTS_FILE), false));
|
|
|
|
if (CFURLCreateDataAndPropertiesFromResource (NULL, url, &data,
|
|
|
|
NULL, NULL, &error_code)) {
|
|
|
|
defaults = (CFPropertyListCreateFromXMLData
|
|
|
|
(NULL, data, kCFPropertyListMutableContainersAndLeaves, &error));
|
|
|
|
if (error != NULL) CFRelease (error);
|
|
|
|
CFRelease (data);
|
|
|
|
}
|
|
|
|
CFRelease (url);
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
if (defaults != NULL) {
|
|
|
|
NSMutableArray *apps, *elt;
|
|
|
|
int count, i;
|
|
|
|
NSString *name, *nname;
|
|
|
|
|
|
|
|
/* Localize the names in the default apps menu. */
|
|
|
|
|
|
|
|
apps = [(NSDictionary *)defaults objectForKey:@PREFS_APPSMENU];
|
|
|
|
if (apps != nil) {
|
|
|
|
count = [apps count];
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
elt = [apps objectAtIndex:i];
|
|
|
|
if (elt != nil && [elt isKindOfClass:[NSArray class]]) {
|
|
|
|
name = [elt objectAtIndex:0];
|
|
|
|
if (name != nil) {
|
|
|
|
nname = NSLocalizedString (name, nil);
|
|
|
|
if (nname != nil && nname != name)
|
|
|
|
[elt replaceObjectAtIndex:0 withObject:nname];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
2007-03-01 10:45:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
if (defaults != NULL) value = CFDictionaryGetValue (defaults, key);
|
|
|
|
if (value != NULL) CFRetain (value);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (int) prefs_get_integer:(NSString *)key default:(int)def {
|
|
|
|
CFPropertyListRef value;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
value = [self prefs_get:key];
|
|
|
|
|
|
|
|
if (value != NULL && CFGetTypeID (value) == CFNumberGetTypeID ())
|
|
|
|
CFNumberGetValue (value, kCFNumberIntType, &ret);
|
|
|
|
else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
|
|
|
|
ret = CFStringGetIntValue (value);
|
|
|
|
else
|
|
|
|
ret = def;
|
|
|
|
|
|
|
|
if (value != NULL) CFRelease (value);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (const char *) prefs_get_string:(NSString *)key default:(const char *)def {
|
|
|
|
CFPropertyListRef value;
|
|
|
|
const char *ret = NULL;
|
|
|
|
|
|
|
|
value = [self prefs_get:key];
|
|
|
|
|
|
|
|
if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ()) {
|
|
|
|
NSString *s = (NSString *) value;
|
|
|
|
|
|
|
|
ret = [s UTF8String];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value != NULL) CFRelease (value);
|
|
|
|
|
|
|
|
return ret != NULL ? ret : def;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) prefs_get_float:(NSString *)key default:(float)def {
|
|
|
|
CFPropertyListRef value;
|
|
|
|
float ret = def;
|
|
|
|
|
|
|
|
value = [self prefs_get:key];
|
|
|
|
|
|
|
|
if (value != NULL
|
|
|
|
&& CFGetTypeID (value) == CFNumberGetTypeID ()
|
2008-03-29 04:47:44 +01:00
|
|
|
&& CFNumberIsFloatType (value))
|
2007-03-01 10:45:19 +01:00
|
|
|
CFNumberGetValue (value, kCFNumberFloatType, &ret);
|
|
|
|
else if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ())
|
|
|
|
ret = CFStringGetDoubleValue (value);
|
|
|
|
|
|
|
|
if (value != NULL) CFRelease (value);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) prefs_get_boolean:(NSString *)key default:(int)def {
|
|
|
|
CFPropertyListRef value;
|
|
|
|
int ret = def;
|
|
|
|
|
|
|
|
value = [self prefs_get:key];
|
|
|
|
|
|
|
|
if (value != NULL) {
|
|
|
|
if (CFGetTypeID (value) == CFNumberGetTypeID ())
|
|
|
|
CFNumberGetValue (value, kCFNumberIntType, &ret);
|
|
|
|
else if (CFGetTypeID (value) == CFBooleanGetTypeID ())
|
|
|
|
ret = CFBooleanGetValue (value);
|
|
|
|
else if (CFGetTypeID (value) == CFStringGetTypeID ()) {
|
2007-11-22 04:51:14 +01:00
|
|
|
const char *tem = [(NSString *) value UTF8String];
|
2007-03-01 10:45:19 +01:00
|
|
|
if (strcasecmp (tem, "true") == 0 || strcasecmp (tem, "yes") == 0)
|
|
|
|
ret = YES;
|
|
|
|
else
|
|
|
|
ret = NO;
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
2007-03-01 10:45:19 +01:00
|
|
|
|
|
|
|
CFRelease (value);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) prefs_get_array:(NSString *)key {
|
|
|
|
NSArray *ret = nil;
|
|
|
|
CFPropertyListRef value;
|
|
|
|
|
|
|
|
value = [self prefs_get:key];
|
|
|
|
|
|
|
|
if (value != NULL) {
|
|
|
|
if (CFGetTypeID (value) == CFArrayGetTypeID ())
|
|
|
|
ret = [cfarray_to_nsarray (value) autorelease];
|
|
|
|
|
|
|
|
CFRelease (value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) prefs_set_integer:(NSString *)key value:(int)value {
|
2007-02-27 02:06:53 +01:00
|
|
|
CFNumberRef x;
|
|
|
|
|
|
|
|
x = CFNumberCreate (NULL, kCFNumberIntType, &value);
|
|
|
|
|
2008-11-25 09:15:53 +01:00
|
|
|
CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) x, app_prefs_domain_cfstr,
|
2007-03-01 10:45:19 +01:00
|
|
|
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
CFRelease (x);
|
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) prefs_set_float:(NSString *)key value:(float)value {
|
2007-02-27 02:06:53 +01:00
|
|
|
CFNumberRef x;
|
|
|
|
|
|
|
|
x = CFNumberCreate (NULL, kCFNumberFloatType, &value);
|
|
|
|
|
2008-11-25 09:15:53 +01:00
|
|
|
CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) x, app_prefs_domain_cfstr,
|
2007-03-01 10:45:19 +01:00
|
|
|
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
CFRelease (x);
|
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) prefs_set_boolean:(NSString *)key value:(int)value {
|
|
|
|
CFPreferencesSetValue ((CFStringRef) key,
|
2008-09-25 07:51:03 +02:00
|
|
|
(CFTypeRef) (value ? kCFBooleanTrue
|
2008-11-25 09:15:53 +01:00
|
|
|
: kCFBooleanFalse), app_prefs_domain_cfstr,
|
2007-03-01 10:45:19 +01:00
|
|
|
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) prefs_set_array:(NSString *)key value:(NSArray *)value {
|
|
|
|
CFArrayRef cfarray;
|
|
|
|
|
|
|
|
cfarray = nsarray_to_cfarray (value);
|
|
|
|
CFPreferencesSetValue ((CFStringRef) key,
|
|
|
|
(CFTypeRef) cfarray,
|
2008-11-25 09:15:53 +01:00
|
|
|
app_prefs_domain_cfstr,
|
2007-03-01 10:45:19 +01:00
|
|
|
kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
|
|
|
CFRelease (cfarray);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) prefs_set_string:(NSString *)key value:(NSString *)value {
|
|
|
|
CFPreferencesSetValue ((CFStringRef) key, (CFTypeRef) value,
|
2008-11-25 09:15:53 +01:00
|
|
|
app_prefs_domain_cfstr, kCFPreferencesCurrentUser,
|
2007-03-01 10:45:19 +01:00
|
|
|
kCFPreferencesAnyHost);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) prefs_synchronize {
|
2007-02-27 02:06:53 +01:00
|
|
|
CFPreferencesAppSynchronize (kCFPreferencesCurrentApplication);
|
|
|
|
}
|
|
|
|
|
2007-11-07 10:56:37 +01:00
|
|
|
- (void) read_defaults
|
|
|
|
{
|
2008-08-20 18:21:44 +02:00
|
|
|
NSString *nsstr;
|
2007-11-07 10:56:37 +01:00
|
|
|
const char *tem;
|
|
|
|
|
|
|
|
quartzUseSysBeep = [self prefs_get_boolean:@PREFS_SYSBEEP
|
2008-11-01 04:03:34 +01:00
|
|
|
default:quartzUseSysBeep];
|
2008-10-09 03:39:41 +02:00
|
|
|
quartzEnableRootless = [self prefs_get_boolean:@PREFS_ROOTLESS
|
2008-11-01 04:03:34 +01:00
|
|
|
default:quartzEnableRootless];
|
|
|
|
quartzFullscreenMenu = [self prefs_get_boolean:@PREFS_FULLSCREEN_MENU
|
|
|
|
default:quartzFullscreenMenu];
|
2007-11-07 10:56:37 +01:00
|
|
|
quartzFullscreenDisableHotkeys = ![self prefs_get_boolean:
|
2008-11-01 04:03:34 +01:00
|
|
|
@PREFS_FULLSCREEN_HOTKEYS default:!quartzFullscreenDisableHotkeys];
|
2007-11-07 10:56:37 +01:00
|
|
|
darwinFakeButtons = [self prefs_get_boolean:@PREFS_FAKEBUTTONS
|
2008-11-01 04:03:34 +01:00
|
|
|
default:darwinFakeButtons];
|
2007-11-07 10:56:37 +01:00
|
|
|
if (darwinFakeButtons) {
|
2008-08-19 11:02:11 +02:00
|
|
|
const char *fake2, *fake3;
|
|
|
|
|
|
|
|
fake2 = [self prefs_get_string:@PREFS_FAKE_BUTTON2 default:NULL];
|
|
|
|
fake3 = [self prefs_get_string:@PREFS_FAKE_BUTTON3 default:NULL];
|
|
|
|
|
2008-08-20 18:21:44 +02:00
|
|
|
if (fake2 != NULL) darwinFakeMouse2Mask = DarwinParseModifierList(fake2, TRUE);
|
|
|
|
if (fake3 != NULL) darwinFakeMouse3Mask = DarwinParseModifierList(fake3, TRUE);
|
2007-11-07 10:56:37 +01:00
|
|
|
}
|
2008-08-19 11:02:11 +02:00
|
|
|
|
|
|
|
tem = [self prefs_get_string:@PREFS_APPKIT_MODIFIERS default:NULL];
|
2008-08-20 18:21:44 +02:00
|
|
|
if (tem != NULL) darwinAppKitModMask = DarwinParseModifierList(tem, TRUE);
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2008-08-20 18:21:44 +02:00
|
|
|
tem = [self prefs_get_string:@PREFS_WINDOW_ITEM_MODIFIERS default:NULL];
|
|
|
|
if (tem != NULL) {
|
|
|
|
windowItemModMask = DarwinParseModifierList(tem, FALSE);
|
|
|
|
} else {
|
|
|
|
nsstr = NSLocalizedString (@"window item modifiers", @"window item modifiers");
|
|
|
|
if(nsstr != NULL) {
|
|
|
|
tem = [nsstr UTF8String];
|
|
|
|
if((tem != NULL) && strcmp(tem, "window item modifiers")) {
|
|
|
|
windowItemModMask = DarwinParseModifierList(tem, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-07 10:56:37 +01:00
|
|
|
X11EnableKeyEquivalents = [self prefs_get_boolean:@PREFS_KEYEQUIVS
|
2008-11-28 21:59:09 +01:00
|
|
|
default:X11EnableKeyEquivalents];
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2007-11-07 10:56:37 +01:00
|
|
|
darwinSyncKeymap = [self prefs_get_boolean:@PREFS_SYNC_KEYMAP
|
2008-11-28 21:59:09 +01:00
|
|
|
default:darwinSyncKeymap];
|
2008-09-06 02:32:16 +02:00
|
|
|
|
2007-11-07 10:56:37 +01:00
|
|
|
darwinDesiredDepth = [self prefs_get_integer:@PREFS_DEPTH
|
2008-11-28 21:59:09 +01:00
|
|
|
default:darwinDesiredDepth];
|
|
|
|
|
|
|
|
noTestExtensions = ![self prefs_get_boolean:@PREFS_TEST_EXTENSIONS
|
|
|
|
default:FALSE];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This will end up at the end of the responder chain. */
|
2007-03-01 10:45:19 +01:00
|
|
|
- (void) copy:sender {
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzPasteboardNotify, 1,
|
2007-03-01 10:45:19 +01:00
|
|
|
AppleWMCopyToPasteboard);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2008-04-19 05:25:38 +02:00
|
|
|
- (OSX_BOOL) x_active {
|
2007-02-27 02:06:53 +01:00
|
|
|
return _x_active;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
static NSArray *
|
|
|
|
array_with_strings_and_numbers (int nitems, const char **items,
|
2007-03-01 10:45:19 +01:00
|
|
|
const char *numbers) {
|
|
|
|
NSMutableArray *array, *subarray;
|
|
|
|
NSString *string, *number;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* (Can't autorelease on the X server thread) */
|
|
|
|
|
|
|
|
array = [[NSMutableArray alloc] initWithCapacity:nitems];
|
|
|
|
|
|
|
|
for (i = 0; i < nitems; i++) {
|
|
|
|
subarray = [[NSMutableArray alloc] initWithCapacity:2];
|
|
|
|
|
|
|
|
string = [[NSString alloc] initWithUTF8String:items[i]];
|
|
|
|
[subarray addObject:string];
|
|
|
|
[string release];
|
|
|
|
|
|
|
|
if (numbers[i] != 0) {
|
|
|
|
number = [[NSString alloc] initWithFormat:@"%d", numbers[i]];
|
|
|
|
[subarray addObject:number];
|
|
|
|
[number release];
|
|
|
|
} else
|
|
|
|
[subarray addObject:@""];
|
|
|
|
|
|
|
|
[array addObject:subarray];
|
|
|
|
[subarray release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11ApplicationSetWindowMenu (int nitems, const char **items,
|
|
|
|
const char *shortcuts) {
|
|
|
|
NSArray *array;
|
|
|
|
array = array_with_strings_and_numbers (nitems, items, shortcuts);
|
|
|
|
|
|
|
|
/* Send the array of strings over to the appkit thread */
|
|
|
|
|
|
|
|
message_kit_thread (@selector (set_window_menu:), array);
|
|
|
|
[array release];
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11ApplicationSetWindowMenuCheck (int idx) {
|
|
|
|
NSNumber *n;
|
|
|
|
|
|
|
|
n = [[NSNumber alloc] initWithInt:idx];
|
|
|
|
|
|
|
|
message_kit_thread (@selector (set_window_menu_check:), n);
|
|
|
|
|
|
|
|
[n release];
|
|
|
|
}
|
|
|
|
|
|
|
|
void X11ApplicationSetFrontProcess (void) {
|
2007-02-27 02:06:53 +01:00
|
|
|
message_kit_thread (@selector (set_front_process:), nil);
|
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
void X11ApplicationSetCanQuit (int state) {
|
2007-02-27 02:06:53 +01:00
|
|
|
NSNumber *n;
|
|
|
|
|
|
|
|
n = [[NSNumber alloc] initWithBool:state];
|
|
|
|
|
|
|
|
message_kit_thread (@selector (set_can_quit:), n);
|
|
|
|
|
|
|
|
[n release];
|
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
void X11ApplicationServerReady (void) {
|
2007-02-27 02:06:53 +01:00
|
|
|
message_kit_thread (@selector (server_ready:), nil);
|
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
void X11ApplicationShowHideMenubar (int state) {
|
2007-02-27 02:06:53 +01:00
|
|
|
NSNumber *n;
|
|
|
|
|
|
|
|
n = [[NSNumber alloc] initWithBool:state];
|
|
|
|
|
|
|
|
message_kit_thread (@selector (show_hide_menubar:), n);
|
|
|
|
|
|
|
|
[n release];
|
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
static void check_xinitrc (void) {
|
2007-02-27 02:06:53 +01:00
|
|
|
char *tem, buf[1024];
|
|
|
|
NSString *msg;
|
|
|
|
|
|
|
|
if ([X11App prefs_get_boolean:@PREFS_DONE_XINIT_CHECK default:NO])
|
|
|
|
return;
|
|
|
|
|
|
|
|
tem = getenv ("HOME");
|
2007-03-01 10:45:19 +01:00
|
|
|
if (tem == NULL) goto done;
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
snprintf (buf, sizeof (buf), "%s/.xinitrc", tem);
|
|
|
|
if (access (buf, F_OK) != 0)
|
|
|
|
goto done;
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
msg = NSLocalizedString (@"You have an existing ~/.xinitrc file.\n\n\
|
|
|
|
Windows displayed by X11 applications may not have titlebars, or may look \
|
|
|
|
different to windows displayed by native applications.\n\n\
|
|
|
|
Would you like to move aside the existing file and use the standard X11 \
|
2008-10-24 02:32:32 +02:00
|
|
|
environment the next time you start X11?", @"Startup xinitrc dialog");
|
|
|
|
|
|
|
|
if(NSAlertDefaultReturn == NSRunAlertPanel (nil, msg, NSLocalizedString (@"Yes", @""),
|
|
|
|
NSLocalizedString (@"No", @""), nil)) {
|
|
|
|
char buf2[1024];
|
|
|
|
int i = -1;
|
2007-03-01 10:45:19 +01:00
|
|
|
|
2008-10-24 02:32:32 +02:00
|
|
|
snprintf (buf2, sizeof (buf2), "%s.old", buf);
|
2007-03-01 10:45:19 +01:00
|
|
|
|
2008-10-24 02:32:32 +02:00
|
|
|
for(i = 1; access (buf2, F_OK) == 0; i++)
|
|
|
|
snprintf (buf2, sizeof (buf2), "%s.old.%d", buf, i);
|
|
|
|
|
|
|
|
rename (buf, buf2);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
done:
|
2007-02-27 02:06:53 +01:00
|
|
|
[X11App prefs_set_boolean:@PREFS_DONE_XINIT_CHECK value:YES];
|
|
|
|
[X11App prefs_synchronize];
|
|
|
|
}
|
|
|
|
|
2008-04-28 20:47:49 +02:00
|
|
|
void X11ApplicationMain (int argc, char **argv, char **envp) {
|
2007-12-20 22:17:30 +01:00
|
|
|
NSAutoreleasePool *pool;
|
2009-01-11 23:49:39 +01:00
|
|
|
int *p;
|
2007-12-20 22:17:30 +01:00
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
#ifdef DEBUG
|
2007-12-20 22:17:30 +01:00
|
|
|
while (access ("/tmp/x11-block", F_OK) == 0) sleep (1);
|
2007-02-27 02:06:53 +01:00
|
|
|
#endif
|
2007-11-07 12:56:44 +01:00
|
|
|
|
2007-12-20 22:17:30 +01:00
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
X11App = (X11Application *) [X11Application sharedApplication];
|
|
|
|
init_ports ();
|
2008-11-25 09:15:53 +01:00
|
|
|
|
|
|
|
app_prefs_domain_cfstr = (CFStringRef)[[NSBundle mainBundle] bundleIdentifier];
|
|
|
|
|
2007-12-20 22:17:30 +01:00
|
|
|
[NSApp read_defaults];
|
|
|
|
[NSBundle loadNibNamed:@"main" owner:NSApp];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:NSApp
|
2007-11-07 12:56:44 +01:00
|
|
|
selector:@selector (became_key:)
|
|
|
|
name:NSWindowDidBecomeKeyNotification object:nil];
|
2007-12-20 22:17:30 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The xpr Quartz mode is statically linked into this server.
|
|
|
|
* Initialize all the Quartz functions.
|
|
|
|
*/
|
|
|
|
QuartzModeBundleInit();
|
|
|
|
|
|
|
|
/* Calculate the height of the menubar so we can avoid it. */
|
|
|
|
aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) -
|
2007-11-07 12:56:44 +01:00
|
|
|
NSMaxY([[NSScreen mainScreen] visibleFrame]);
|
2007-12-20 22:17:30 +01:00
|
|
|
|
2008-09-25 07:51:03 +02:00
|
|
|
/* Set the key layout seed before we start the server */
|
2008-11-16 04:45:49 +01:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
|
|
|
|
last_key_layout = TISCopyCurrentKeyboardLayoutInputSource();
|
|
|
|
|
|
|
|
if(!last_key_layout)
|
2008-09-25 07:51:03 +02:00
|
|
|
fprintf(stderr, "X11ApplicationMain: Unable to determine TISCopyCurrentKeyboardLayoutInputSource() at startup.\n");
|
2008-11-16 04:45:49 +01:00
|
|
|
#else
|
|
|
|
KLGetCurrentKeyboardLayout(&last_key_layout);
|
|
|
|
if(!last_key_layout)
|
|
|
|
fprintf(stderr, "X11ApplicationMain: Unable to determine KLGetCurrentKeyboardLayout() at startup.\n");
|
|
|
|
#endif
|
2008-09-25 07:51:03 +02:00
|
|
|
|
|
|
|
memset(keyInfo.keyMap, 0, sizeof(keyInfo.keyMap));
|
|
|
|
if (!QuartzReadSystemKeymap(&keyInfo)) {
|
|
|
|
fprintf(stderr, "X11ApplicationMain: Could not build a valid keymap.\n");
|
|
|
|
}
|
|
|
|
|
2009-01-11 23:49:39 +01:00
|
|
|
for(p=darwin_modifier_mask_list, modifierFlagsMask=0; *p; p++) {
|
|
|
|
modifierFlagsMask |= *p;
|
|
|
|
}
|
|
|
|
|
2008-04-27 04:21:05 +02:00
|
|
|
/* Tell the server thread that it can proceed */
|
2008-04-28 20:47:49 +02:00
|
|
|
QuartzInitServer(argc, argv, envp);
|
2008-10-24 02:32:32 +02:00
|
|
|
|
|
|
|
/* This must be done after QuartzInitServer because it can result in
|
|
|
|
* an mieqEnqueue() - <rdar://problem/6300249>
|
|
|
|
*/
|
|
|
|
check_xinitrc();
|
2008-11-16 04:52:34 +01:00
|
|
|
|
|
|
|
if(!xpbproxy_init())
|
|
|
|
fprintf(stderr, "Error initializing xpbproxy\n");
|
2008-09-25 07:51:03 +02:00
|
|
|
|
2007-12-20 22:17:30 +01:00
|
|
|
[NSApp run];
|
|
|
|
/* not reached */
|
|
|
|
}
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2008-08-20 19:37:17 +02:00
|
|
|
@implementation X11Application (Private)
|
2008-08-20 18:56:06 +02:00
|
|
|
|
2008-12-30 04:38:31 +01:00
|
|
|
#ifdef NX_DEVICELCMDKEYMASK
|
|
|
|
/* This is to workaround a bug in the VNC server where we sometimes see the L
|
|
|
|
* modifier and sometimes see no "side"
|
|
|
|
*/
|
|
|
|
static inline int ensure_flag(int flags, int device_independent, int device_dependents, int device_dependent_default) {
|
|
|
|
if( (flags & device_independent) &&
|
|
|
|
!(flags & device_dependents))
|
|
|
|
flags |= device_dependent_default;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-08-20 19:37:17 +02:00
|
|
|
- (void) sendX11NSEvent:(NSEvent *)e {
|
2008-11-13 21:45:35 +01:00
|
|
|
NSRect screen;
|
|
|
|
NSPoint location;
|
|
|
|
NSWindow *window;
|
|
|
|
int ev_button, ev_type;
|
|
|
|
float pointer_x, pointer_y, pressure, tilt_x, tilt_y;
|
2008-09-30 07:26:20 +02:00
|
|
|
DeviceIntPtr pDev;
|
2008-12-30 04:38:31 +01:00
|
|
|
int modifierFlags;
|
2008-11-13 21:45:35 +01:00
|
|
|
|
2009-03-31 05:37:25 +02:00
|
|
|
static NSPoint lastpt;
|
|
|
|
|
2008-11-13 21:45:35 +01:00
|
|
|
/* convert location to be relative to top-left of primary display */
|
|
|
|
window = [e window];
|
|
|
|
|
2007-03-01 10:45:19 +01:00
|
|
|
if (window != nil) {
|
2008-11-13 21:45:35 +01:00
|
|
|
NSRect frame = [window frame];
|
2009-03-31 05:37:25 +02:00
|
|
|
location = [e locationInWindow];
|
|
|
|
location.x += frame.origin.x;
|
|
|
|
location.y += frame.origin.y;
|
|
|
|
lastpt = location;
|
2008-11-13 21:45:35 +01:00
|
|
|
} else {
|
2009-03-31 05:37:25 +02:00
|
|
|
location.x = lastpt.x + [e deltaX];
|
|
|
|
location.y = lastpt.y - [e deltaY];
|
|
|
|
lastpt = [NSEvent mouseLocation];
|
2008-11-13 21:45:35 +01:00
|
|
|
}
|
2009-03-31 05:37:25 +02:00
|
|
|
|
|
|
|
/* Convert coordinate system */
|
|
|
|
screen = [[[NSScreen screens] objectAtIndex:0] frame];
|
|
|
|
location.y = (screen.origin.y + screen.size.height) - location.y;
|
|
|
|
|
2008-09-30 17:46:08 +02:00
|
|
|
/* Setup our valuators. These will range from 0 to 1 */
|
2008-11-13 21:45:35 +01:00
|
|
|
pressure = 0;
|
|
|
|
tilt_x = 0;
|
|
|
|
tilt_y = 0;
|
2009-03-31 05:37:25 +02:00
|
|
|
pointer_x = location.x;
|
|
|
|
pointer_y = location.y;
|
|
|
|
|
2008-12-30 04:38:31 +01:00
|
|
|
modifierFlags = [e modifierFlags];
|
|
|
|
|
|
|
|
#ifdef NX_DEVICELCMDKEYMASK
|
|
|
|
/* This is to workaround a bug in the VNC server where we sometimes see the L
|
|
|
|
* modifier and sometimes see no "side"
|
|
|
|
*/
|
|
|
|
modifierFlags = ensure_flag(modifierFlags, NX_CONTROLMASK, NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK, NX_DEVICELCTLKEYMASK);
|
|
|
|
modifierFlags = ensure_flag(modifierFlags, NX_SHIFTMASK, NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK, NX_DEVICELSHIFTKEYMASK);
|
|
|
|
modifierFlags = ensure_flag(modifierFlags, NX_COMMANDMASK, NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK, NX_DEVICELCMDKEYMASK);
|
|
|
|
modifierFlags = ensure_flag(modifierFlags, NX_ALTERNATEMASK, NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK, NX_DEVICELALTKEYMASK);
|
|
|
|
#endif
|
|
|
|
|
2009-01-11 23:49:39 +01:00
|
|
|
modifierFlags &= modifierFlagsMask;
|
|
|
|
|
2008-08-20 18:56:06 +02:00
|
|
|
/* We don't receive modifier key events while out of focus, and 3button
|
|
|
|
* emulation mucks this up, so we need to check our modifier flag state
|
|
|
|
* on every event... ugg
|
|
|
|
*/
|
2008-12-30 04:38:31 +01:00
|
|
|
|
|
|
|
if(darwin_modifier_flags != modifierFlags)
|
|
|
|
DarwinUpdateModKeys(modifierFlags);
|
2008-09-25 07:51:03 +02:00
|
|
|
|
2008-08-20 18:58:48 +02:00
|
|
|
switch ([e type]) {
|
2008-08-22 10:11:33 +02:00
|
|
|
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 NSMouseMoved: ev_button=0; ev_type=MotionNotify; goto handle_mouse;
|
|
|
|
case NSTabletPoint: ev_button=0; ev_type=MotionNotify; goto handle_mouse;
|
2008-09-25 07:51:03 +02:00
|
|
|
|
2008-08-20 18:58:48 +02:00
|
|
|
handle_mouse:
|
2008-09-30 07:26:20 +02:00
|
|
|
pDev = darwinPointer;
|
2008-09-30 20:10:58 +02:00
|
|
|
|
2008-11-28 20:18:14 +01:00
|
|
|
/* NSTabletPoint can have no subtype */
|
|
|
|
if([e type] != NSTabletPoint &&
|
|
|
|
[e subtype] == NSTabletProximityEventSubtype) {
|
2008-09-03 18:11:25 +02:00
|
|
|
switch([e pointingDeviceType]) {
|
|
|
|
case NSEraserPointingDevice:
|
|
|
|
darwinTabletCurrent=darwinTabletEraser;
|
|
|
|
break;
|
|
|
|
case NSPenPointingDevice:
|
|
|
|
darwinTabletCurrent=darwinTabletStylus;
|
|
|
|
break;
|
|
|
|
case NSCursorPointingDevice:
|
|
|
|
case NSUnknownPointingDevice:
|
|
|
|
default:
|
|
|
|
darwinTabletCurrent=darwinTabletCursor;
|
|
|
|
break;
|
|
|
|
}
|
2008-09-25 07:51:03 +02:00
|
|
|
|
2008-09-30 20:10:58 +02:00
|
|
|
/* NSTabletProximityEventSubtype doesn't encode pressure ant tilt
|
|
|
|
* So we just pretend the motion was caused by the mouse. Hopefully
|
|
|
|
* we'll have a better solution for this in the future (like maybe
|
|
|
|
* NSTabletProximityEventSubtype will come from NSTabletPoint
|
|
|
|
* rather than NSMouseMoved.
|
|
|
|
pressure = [e pressure];
|
|
|
|
tilt_x = [e tilt].x;
|
|
|
|
tilt_y = [e tilt].y;
|
|
|
|
pDev = darwinTabletCurrent;
|
|
|
|
*/
|
|
|
|
|
2008-09-03 18:11:25 +02:00
|
|
|
DarwinSendProximityEvents([e isEnteringProximity]?ProximityIn:ProximityOut,
|
|
|
|
pointer_x, pointer_y);
|
2008-09-30 20:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([e type] == NSTabletPoint || [e subtype] == NSTabletPointEventSubtype) {
|
|
|
|
pressure = [e pressure];
|
|
|
|
tilt_x = [e tilt].x;
|
|
|
|
tilt_y = [e tilt].y;
|
2008-09-30 07:26:20 +02:00
|
|
|
|
|
|
|
pDev = darwinTabletCurrent;
|
2008-09-03 18:11:25 +02:00
|
|
|
}
|
2008-09-30 07:26:20 +02:00
|
|
|
|
2009-04-01 03:11:19 +02:00
|
|
|
if(!quartzServerVisible) {
|
|
|
|
#if 0
|
2009-02-25 03:54:16 +01:00
|
|
|
/* Seems this has somehow triggered 100% CPU usage while X11.app is in the
|
|
|
|
* background on some obscure HW configurations.
|
|
|
|
* http://xquartz.macosforge.org/trac/ticket/241
|
|
|
|
*/
|
2009-04-01 03:11:19 +02:00
|
|
|
//#if defined(XPLUGIN_VERSION) && XPLUGIN_VERSION > 0
|
2008-12-11 08:04:30 +01:00
|
|
|
/* Older libXplugin (Tiger/"Stock" Leopard) aren't thread safe, so we can't call xp_find_window from the Appkit thread */
|
2008-10-21 18:11:59 +02:00
|
|
|
xp_window_id wid;
|
2008-10-31 20:37:32 +01:00
|
|
|
|
2008-10-21 18:11:59 +02:00
|
|
|
/* Sigh. Need to check that we're really over one of
|
|
|
|
* our windows. (We need to receive pointer events while
|
2008-10-31 20:37:32 +01:00
|
|
|
* not in the foreground, but we don't want to receive them
|
|
|
|
* when another window is over us or we might show a tooltip)
|
2008-10-21 18:11:59 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
wid = 0;
|
|
|
|
|
2008-10-31 20:37:32 +01:00
|
|
|
if (xp_find_window(pointer_x, pointer_y, 0, &wid) == XP_Success &&
|
|
|
|
wid == 0)
|
2009-04-01 03:11:19 +02:00
|
|
|
#endif
|
2008-10-21 18:11:59 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-30 07:26:20 +02:00
|
|
|
DarwinSendPointerEvents(pDev, ev_type, ev_button, pointer_x, pointer_y,
|
2008-08-20 18:58:48 +02:00
|
|
|
pressure, tilt_x, tilt_y);
|
2008-09-25 07:51:03 +02:00
|
|
|
|
2008-08-20 18:58:48 +02:00
|
|
|
break;
|
2008-09-25 07:51:03 +02:00
|
|
|
|
2008-04-30 08:59:26 +02:00
|
|
|
case NSTabletProximity:
|
2008-09-04 17:55:22 +02:00
|
|
|
switch([e pointingDeviceType]) {
|
|
|
|
case NSEraserPointingDevice:
|
|
|
|
darwinTabletCurrent=darwinTabletEraser;
|
|
|
|
break;
|
|
|
|
case NSPenPointingDevice:
|
|
|
|
darwinTabletCurrent=darwinTabletStylus;
|
|
|
|
break;
|
|
|
|
case NSCursorPointingDevice:
|
|
|
|
case NSUnknownPointingDevice:
|
|
|
|
default:
|
|
|
|
darwinTabletCurrent=darwinTabletCursor;
|
|
|
|
break;
|
|
|
|
}
|
2008-09-25 07:51:03 +02:00
|
|
|
|
2008-04-30 08:59:26 +02:00
|
|
|
DarwinSendProximityEvents([e isEnteringProximity]?ProximityIn:ProximityOut,
|
2008-08-20 18:58:48 +02:00
|
|
|
pointer_x, pointer_y);
|
|
|
|
break;
|
2008-09-25 07:51:03 +02:00
|
|
|
|
2008-04-01 08:31:25 +02:00
|
|
|
case NSScrollWheel:
|
2008-04-17 11:21:11 +02:00
|
|
|
DarwinSendScrollEvents([e deltaX], [e deltaY], pointer_x, pointer_y,
|
2008-08-20 18:58:48 +02:00
|
|
|
pressure, tilt_x, tilt_y);
|
|
|
|
break;
|
2008-09-25 07:51:03 +02:00
|
|
|
|
|
|
|
case NSKeyDown: case NSKeyUp:
|
|
|
|
if(darwinSyncKeymap) {
|
2008-11-16 04:45:49 +01:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
|
2008-09-25 07:51:03 +02:00
|
|
|
TISInputSourceRef key_layout = TISCopyCurrentKeyboardLayoutInputSource();
|
|
|
|
TISInputSourceRef clear;
|
|
|
|
if (CFEqual(key_layout, last_key_layout)) {
|
|
|
|
CFRelease(key_layout);
|
|
|
|
} else {
|
|
|
|
/* Swap/free thread-safely */
|
|
|
|
clear = last_key_layout;
|
|
|
|
last_key_layout = key_layout;
|
|
|
|
CFRelease(clear);
|
2008-11-16 04:45:49 +01:00
|
|
|
#else
|
|
|
|
KeyboardLayoutRef key_layout;
|
|
|
|
KLGetCurrentKeyboardLayout(&key_layout);
|
|
|
|
if(key_layout != last_key_layout) {
|
|
|
|
last_key_layout = key_layout;
|
|
|
|
#endif
|
2008-09-25 07:51:03 +02:00
|
|
|
|
|
|
|
/* Update keyInfo */
|
|
|
|
pthread_mutex_lock(&keyInfo_mutex);
|
|
|
|
memset(keyInfo.keyMap, 0, sizeof(keyInfo.keyMap));
|
|
|
|
if (!QuartzReadSystemKeymap(&keyInfo)) {
|
|
|
|
fprintf(stderr, "sendX11NSEvent: Could not build a valid keymap.\n");
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&keyInfo_mutex);
|
|
|
|
|
|
|
|
/* Tell server thread to deal with new keyInfo */
|
|
|
|
DarwinSendDDXEvent(kXquartzReloadKeymap, 0);
|
|
|
|
}
|
|
|
|
}
|
2008-12-30 04:54:12 +01:00
|
|
|
|
|
|
|
/* Avoid stuck keys on context switch */
|
|
|
|
if(keyState[[e keyCode]] == [e type])
|
|
|
|
return;
|
|
|
|
keyState[[e keyCode]] = [e type];
|
|
|
|
|
2008-08-20 18:58:48 +02:00
|
|
|
DarwinSendKeyboardEvents(([e type] == NSKeyDown) ? KeyPress : KeyRelease, [e keyCode]);
|
|
|
|
break;
|
2008-09-25 07:51:03 +02:00
|
|
|
|
2008-08-20 18:56:06 +02:00
|
|
|
default: break; /* for gcc */
|
2008-04-01 08:31:25 +02:00
|
|
|
}
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
2008-08-20 19:37:17 +02:00
|
|
|
@end
|