2007-02-27 02:06:53 +01:00
|
|
|
/* X11Controller.m -- connect the IB ui, also the NSApp delegate
|
|
|
|
|
2008-04-01 07:55:24 +02:00
|
|
|
Copyright (c) 2002-2008 Apple Inc. All rights reserved.
|
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"
|
2008-11-21 19:53:39 +01:00
|
|
|
#include <AvailabilityMacros.h>
|
2008-04-19 05:06:17 +02:00
|
|
|
|
2007-11-29 11:19:22 +01:00
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2007-11-22 09:35:09 +01:00
|
|
|
#include "quartzCommon.h"
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
#import "X11Controller.h"
|
|
|
|
#import "X11Application.h"
|
|
|
|
|
|
|
|
#include "opaque.h"
|
2008-04-19 05:06:17 +02:00
|
|
|
#include "darwin.h"
|
2008-05-02 03:02:59 +02:00
|
|
|
#include "darwinEvents.h"
|
2008-04-19 05:06:17 +02:00
|
|
|
#include "quartz.h"
|
|
|
|
#define _APPLEWM_SERVER_
|
|
|
|
#include "X11/extensions/applewm.h"
|
|
|
|
#include "applewmExt.h"
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2008-11-25 10:30:03 +01:00
|
|
|
BOOL xquartz_resetenv_display = NO;
|
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
@implementation X11Controller
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
|
|
|
X11Application *xapp = NSApp;
|
|
|
|
NSArray *array;
|
|
|
|
|
|
|
|
/* Point X11Application at ourself. */
|
|
|
|
[xapp set_controller:self];
|
|
|
|
|
|
|
|
array = [xapp prefs_get_array:@PREFS_APPSMENU];
|
|
|
|
if (array != nil)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
/* convert from [TITLE1 COMMAND1 TITLE2 COMMAND2 ...]
|
|
|
|
to [[TITLE1 COMMAND1] [TITLE2 COMMAND2] ...] format. */
|
|
|
|
|
|
|
|
count = [array count];
|
|
|
|
if (count > 0
|
|
|
|
&& ![[array objectAtIndex:0] isKindOfClass:[NSArray class]])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
NSMutableArray *copy, *sub;
|
|
|
|
|
|
|
|
copy = [NSMutableArray arrayWithCapacity:(count / 2)];
|
|
|
|
|
|
|
|
for (i = 0; i < count / 2; i++)
|
|
|
|
{
|
|
|
|
sub = [[NSMutableArray alloc] initWithCapacity:3];
|
|
|
|
[sub addObject:[array objectAtIndex:i*2]];
|
|
|
|
[sub addObject:[array objectAtIndex:i*2+1]];
|
|
|
|
[sub addObject:@""];
|
|
|
|
[copy addObject:sub];
|
|
|
|
[sub release];
|
|
|
|
}
|
|
|
|
|
|
|
|
array = copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self set_apps_menu:array];
|
|
|
|
}
|
2008-09-03 12:54:42 +02:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver: self
|
|
|
|
selector: @selector(apps_table_done:)
|
|
|
|
name: NSWindowWillCloseNotification
|
|
|
|
object: [apps_table window]];
|
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) item_selected:sender
|
|
|
|
{
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
|
|
|
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzControllerNotify, 2,
|
2007-02-27 02:06:53 +01:00
|
|
|
AppleWMWindowMenuItem, [sender tag]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) remove_window_menu
|
|
|
|
{
|
|
|
|
NSMenu *menu;
|
|
|
|
int first, count, i;
|
|
|
|
|
|
|
|
/* Work backwards so we don't mess up the indices */
|
|
|
|
menu = [window_separator menu];
|
|
|
|
first = [menu indexOfItem:window_separator] + 1;
|
|
|
|
count = [menu numberOfItems];
|
|
|
|
for (i = count - 1; i >= first; i--)
|
|
|
|
[menu removeItemAtIndex:i];
|
|
|
|
|
|
|
|
menu = [dock_window_separator menu];
|
|
|
|
count = [menu indexOfItem:dock_window_separator];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
[dock_menu removeItemAtIndex:0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) install_window_menu:(NSArray *)list
|
|
|
|
{
|
|
|
|
NSMenu *menu;
|
|
|
|
NSMenuItem *item;
|
|
|
|
int first, count, i;
|
2008-08-20 18:21:44 +02:00
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
menu = [window_separator menu];
|
|
|
|
first = [menu indexOfItem:window_separator] + 1;
|
|
|
|
count = [list count];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
NSString *name, *shortcut;
|
|
|
|
|
|
|
|
name = [[list objectAtIndex:i] objectAtIndex:0];
|
|
|
|
shortcut = [[list objectAtIndex:i] objectAtIndex:1];
|
2008-08-20 18:50:54 +02:00
|
|
|
|
|
|
|
if(windowItemModMask == 0 || windowItemModMask == -1)
|
|
|
|
shortcut = @"";
|
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
item = (NSMenuItem *) [menu addItemWithTitle:name action:@selector
|
|
|
|
(item_selected:) keyEquivalent:shortcut];
|
2008-11-21 19:53:39 +01:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
|
2008-08-20 18:21:44 +02:00
|
|
|
[item setKeyEquivalentModifierMask:(NSUInteger) windowItemModMask];
|
2008-11-21 19:53:39 +01:00
|
|
|
#else
|
|
|
|
[item setKeyEquivalentModifierMask:windowItemModMask];
|
|
|
|
#endif
|
2007-02-27 02:06:53 +01:00
|
|
|
[item setTarget:self];
|
|
|
|
[item setTag:i];
|
|
|
|
[item setEnabled:YES];
|
2008-08-20 18:21:44 +02:00
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
item = (NSMenuItem *) [dock_menu insertItemWithTitle:name
|
|
|
|
action:@selector
|
|
|
|
(item_selected:) keyEquivalent:shortcut
|
|
|
|
atIndex:i];
|
2008-11-21 19:53:39 +01:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
|
2008-08-20 18:21:44 +02:00
|
|
|
[item setKeyEquivalentModifierMask:(NSUInteger) windowItemModMask];
|
2008-11-21 19:53:39 +01:00
|
|
|
#else
|
|
|
|
[item setKeyEquivalentModifierMask:windowItemModMask];
|
|
|
|
#endif
|
2007-02-27 02:06:53 +01:00
|
|
|
[item setTarget:self];
|
|
|
|
[item setTag:i];
|
|
|
|
[item setEnabled:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (checked_window_item >= 0 && checked_window_item < count)
|
|
|
|
{
|
|
|
|
item = (NSMenuItem *) [menu itemAtIndex:first + checked_window_item];
|
|
|
|
[item setState:NSOnState];
|
|
|
|
item = (NSMenuItem *) [dock_menu itemAtIndex:checked_window_item];
|
|
|
|
[item setState:NSOnState];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) remove_apps_menu
|
|
|
|
{
|
|
|
|
NSMenu *menu;
|
|
|
|
NSMenuItem *item;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (apps == nil || apps_separator == nil) return;
|
|
|
|
|
|
|
|
menu = [apps_separator menu];
|
|
|
|
|
|
|
|
if (menu != nil)
|
|
|
|
{
|
|
|
|
for (i = [menu numberOfItems] - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
item = (NSMenuItem *) [menu itemAtIndex:i];
|
|
|
|
if ([item tag] != 0)
|
|
|
|
[menu removeItemAtIndex:i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dock_apps_menu != nil)
|
|
|
|
{
|
|
|
|
for (i = [dock_apps_menu numberOfItems] - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
item = (NSMenuItem *) [dock_apps_menu itemAtIndex:i];
|
|
|
|
if ([item tag] != 0)
|
|
|
|
[dock_apps_menu removeItemAtIndex:i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[apps release];
|
|
|
|
apps = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) prepend_apps_item:(NSArray *)list index:(int)i menu:(NSMenu *)menu
|
|
|
|
{
|
|
|
|
NSString *title, *shortcut = @"";
|
|
|
|
NSArray *group;
|
|
|
|
NSMenuItem *item;
|
|
|
|
|
|
|
|
group = [list objectAtIndex:i];
|
|
|
|
title = [group objectAtIndex:0];
|
|
|
|
if ([group count] >= 3)
|
|
|
|
shortcut = [group objectAtIndex:2];
|
|
|
|
|
|
|
|
if ([title length] != 0)
|
|
|
|
{
|
|
|
|
item = (NSMenuItem *) [menu insertItemWithTitle:title
|
|
|
|
action:@selector (app_selected:)
|
|
|
|
keyEquivalent:shortcut atIndex:0];
|
|
|
|
[item setTarget:self];
|
|
|
|
[item setEnabled:YES];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item = (NSMenuItem *) [NSMenuItem separatorItem];
|
|
|
|
[menu insertItem:item atIndex:0];
|
|
|
|
}
|
|
|
|
|
|
|
|
[item setTag:i+1]; /* can't be zero, so add one */
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) install_apps_menu:(NSArray *)list
|
|
|
|
{
|
|
|
|
NSMenu *menu;
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
count = [list count];
|
|
|
|
|
|
|
|
if (count == 0 || apps_separator == nil) return;
|
|
|
|
|
|
|
|
menu = [apps_separator menu];
|
|
|
|
|
|
|
|
for (i = count - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (menu != nil)
|
|
|
|
[self prepend_apps_item:list index:i menu:menu];
|
|
|
|
if (dock_apps_menu != nil)
|
|
|
|
[self prepend_apps_item:list index:i menu:dock_apps_menu];
|
|
|
|
}
|
|
|
|
|
|
|
|
apps = [list retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) set_window_menu:(NSArray *)list
|
|
|
|
{
|
|
|
|
[self remove_window_menu];
|
|
|
|
[self install_window_menu:list];
|
|
|
|
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzControllerNotify, 1,
|
2007-02-27 02:06:53 +01:00
|
|
|
AppleWMWindowMenuNotify);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) set_window_menu_check:(NSNumber *)nn
|
|
|
|
{
|
|
|
|
NSMenu *menu;
|
|
|
|
NSMenuItem *item;
|
|
|
|
int first, count;
|
|
|
|
int n = [nn intValue];
|
|
|
|
|
|
|
|
menu = [window_separator menu];
|
|
|
|
first = [menu indexOfItem:window_separator] + 1;
|
|
|
|
count = [menu numberOfItems] - first;
|
|
|
|
|
|
|
|
if (checked_window_item >= 0 && checked_window_item < count)
|
|
|
|
{
|
|
|
|
item = (NSMenuItem *) [menu itemAtIndex:first + checked_window_item];
|
|
|
|
[item setState:NSOffState];
|
|
|
|
item = (NSMenuItem *) [dock_menu itemAtIndex:checked_window_item];
|
|
|
|
[item setState:NSOffState];
|
|
|
|
}
|
|
|
|
if (n >= 0 && n < count)
|
|
|
|
{
|
|
|
|
item = (NSMenuItem *) [menu itemAtIndex:first + n];
|
|
|
|
[item setState:NSOnState];
|
|
|
|
item = (NSMenuItem *) [dock_menu itemAtIndex:n];
|
|
|
|
[item setState:NSOnState];
|
|
|
|
}
|
|
|
|
checked_window_item = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) set_apps_menu:(NSArray *)list
|
|
|
|
{
|
|
|
|
[self remove_apps_menu];
|
|
|
|
[self install_apps_menu:list];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) launch_client:(NSString *)filename
|
|
|
|
{
|
|
|
|
const char *command = [filename UTF8String];
|
2007-11-04 14:13:19 +01:00
|
|
|
const char *argv[7];
|
2007-02-27 02:06:53 +01:00
|
|
|
int child1, child2 = 0;
|
|
|
|
int status;
|
|
|
|
|
2007-09-21 01:50:49 +02:00
|
|
|
argv[0] = "/usr/bin/login";
|
|
|
|
argv[1] = "-fp";
|
|
|
|
argv[2] = getlogin();
|
2008-01-13 06:24:34 +01:00
|
|
|
argv[3] = [X11App prefs_get_string:@PREFS_LOGIN_SHELL default:"/bin/sh"];
|
2007-11-04 14:13:19 +01:00
|
|
|
argv[4] = "-c";
|
|
|
|
argv[5] = command;
|
|
|
|
argv[6] = NULL;
|
2007-09-21 01:50:49 +02:00
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
/* Do the fork-twice trick to avoid having to reap zombies */
|
|
|
|
|
|
|
|
child1 = fork();
|
|
|
|
|
|
|
|
switch (child1) {
|
|
|
|
case -1: /* error */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0: /* child1 */
|
|
|
|
child2 = fork();
|
|
|
|
|
|
|
|
switch (child2) {
|
|
|
|
int max_files, i;
|
|
|
|
char buf[1024], *temp;
|
|
|
|
|
|
|
|
case -1: /* error */
|
|
|
|
_exit(1);
|
|
|
|
|
|
|
|
case 0: /* child2 */
|
|
|
|
/* close all open files except for standard streams */
|
|
|
|
max_files = sysconf(_SC_OPEN_MAX);
|
|
|
|
for (i = 3; i < max_files; i++) close(i);
|
|
|
|
|
|
|
|
/* ensure stdin is on /dev/null */
|
|
|
|
close(0);
|
|
|
|
open("/dev/null", O_RDONLY);
|
|
|
|
|
|
|
|
/* Setup environment */
|
|
|
|
temp = getenv("DISPLAY");
|
2008-11-25 20:25:58 +01:00
|
|
|
if (xquartz_resetenv_display || temp == NULL || temp[0] == 0) {
|
2007-12-20 22:17:30 +01:00
|
|
|
snprintf(buf, sizeof(buf), ":%s", display);
|
2007-02-27 02:06:53 +01:00
|
|
|
setenv("DISPLAY", buf, TRUE);
|
|
|
|
}
|
2008-11-28 10:45:37 +01:00
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
execvp(argv[0], (char **const) argv);
|
|
|
|
|
|
|
|
_exit(2);
|
|
|
|
|
|
|
|
default: /* parent (child1) */
|
|
|
|
_exit(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* parent */
|
|
|
|
waitpid(child1, &status, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) app_selected:sender
|
|
|
|
{
|
|
|
|
int tag;
|
|
|
|
NSString *item;
|
|
|
|
|
|
|
|
tag = [sender tag] - 1;
|
|
|
|
if (apps == nil || tag < 0 || tag >= [apps count])
|
|
|
|
return;
|
|
|
|
|
|
|
|
item = [[apps objectAtIndex:tag] objectAtIndex:1];
|
|
|
|
|
|
|
|
[self launch_client:item];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) apps_table_show:sender
|
|
|
|
{
|
|
|
|
NSArray *columns;
|
2008-08-31 01:13:58 +02:00
|
|
|
NSMutableArray *oldapps = nil;
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2008-08-31 01:13:58 +02:00
|
|
|
if (table_apps != nil)
|
|
|
|
oldapps = table_apps;
|
|
|
|
|
|
|
|
table_apps = [[NSMutableArray alloc] initWithCapacity:1];
|
|
|
|
if(apps != nil)
|
|
|
|
[table_apps addObjectsFromArray:apps];
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
columns = [apps_table tableColumns];
|
|
|
|
[[columns objectAtIndex:0] setIdentifier:@"0"];
|
|
|
|
[[columns objectAtIndex:1] setIdentifier:@"1"];
|
|
|
|
[[columns objectAtIndex:2] setIdentifier:@"2"];
|
|
|
|
|
|
|
|
[apps_table setDataSource:self];
|
|
|
|
[apps_table selectRow:0 byExtendingSelection:NO];
|
|
|
|
|
|
|
|
[[apps_table window] makeKeyAndOrderFront:sender];
|
|
|
|
[apps_table reloadData];
|
2008-08-31 01:13:58 +02:00
|
|
|
if(oldapps != nil)
|
|
|
|
[oldapps release];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) apps_table_done:sender
|
|
|
|
{
|
|
|
|
[apps_table deselectAll:sender]; /* flush edits? */
|
|
|
|
|
|
|
|
[self remove_apps_menu];
|
|
|
|
[self install_apps_menu:table_apps];
|
|
|
|
|
|
|
|
[NSApp prefs_set_array:@PREFS_APPSMENU value:table_apps];
|
|
|
|
[NSApp prefs_synchronize];
|
|
|
|
|
|
|
|
[[apps_table window] orderOut:sender];
|
|
|
|
|
|
|
|
[table_apps release];
|
|
|
|
table_apps = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) apps_table_new:sender
|
|
|
|
{
|
|
|
|
NSMutableArray *item;
|
|
|
|
|
|
|
|
int row = [apps_table selectedRow], i;
|
|
|
|
|
|
|
|
if (row < 0) row = 0;
|
|
|
|
else row = row + 1;
|
|
|
|
|
|
|
|
i = row;
|
|
|
|
if (i > [table_apps count])
|
|
|
|
return; /* avoid exceptions */
|
|
|
|
|
|
|
|
[apps_table deselectAll:sender];
|
|
|
|
|
|
|
|
item = [[NSMutableArray alloc] initWithCapacity:3];
|
|
|
|
[item addObject:@""];
|
|
|
|
[item addObject:@""];
|
|
|
|
[item addObject:@""];
|
|
|
|
|
|
|
|
[table_apps insertObject:item atIndex:i];
|
|
|
|
[item release];
|
|
|
|
|
|
|
|
[apps_table reloadData];
|
|
|
|
[apps_table selectRow:row byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) apps_table_duplicate:sender
|
|
|
|
{
|
|
|
|
int row = [apps_table selectedRow], i;
|
|
|
|
NSObject *item;
|
|
|
|
|
|
|
|
if (row < 0) {
|
|
|
|
[self apps_table_new:sender];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = row;
|
|
|
|
if (i > [table_apps count] - 1) return; /* avoid exceptions */
|
|
|
|
|
|
|
|
[apps_table deselectAll:sender];
|
|
|
|
|
|
|
|
item = [[table_apps objectAtIndex:i] mutableCopy];
|
|
|
|
[table_apps insertObject:item atIndex:i];
|
|
|
|
[item release];
|
|
|
|
|
|
|
|
[apps_table reloadData];
|
|
|
|
[apps_table selectRow:row+1 byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) apps_table_delete:sender
|
|
|
|
{
|
|
|
|
int row = [apps_table selectedRow];
|
|
|
|
|
|
|
|
if (row >= 0)
|
|
|
|
{
|
|
|
|
int i = row;
|
|
|
|
|
|
|
|
if (i > [table_apps count] - 1) return; /* avoid exceptions */
|
|
|
|
|
|
|
|
[apps_table deselectAll:sender];
|
|
|
|
|
|
|
|
[table_apps removeObjectAtIndex:i];
|
|
|
|
}
|
|
|
|
|
|
|
|
[apps_table reloadData];
|
|
|
|
|
|
|
|
row = MIN (row, [table_apps count] - 1);
|
|
|
|
if (row >= 0)
|
|
|
|
[apps_table selectRow:row byExtendingSelection:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) numberOfRowsInTableView:(NSTableView *)tableView
|
|
|
|
{
|
|
|
|
if (table_apps == nil) return 0;
|
|
|
|
|
|
|
|
return [table_apps count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) tableView:(NSTableView *)tableView
|
|
|
|
objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
|
|
|
|
{
|
|
|
|
NSArray *item;
|
|
|
|
int col;
|
|
|
|
|
|
|
|
if (table_apps == nil) return nil;
|
|
|
|
|
|
|
|
col = [[tableColumn identifier] intValue];
|
|
|
|
|
|
|
|
item = [table_apps objectAtIndex:row];
|
|
|
|
if ([item count] > col)
|
|
|
|
return [item objectAtIndex:col];
|
|
|
|
else
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableView:(NSTableView *)tableView setObjectValue:(id)object
|
|
|
|
forTableColumn:(NSTableColumn *)tableColumn row:(int)row
|
|
|
|
{
|
|
|
|
NSMutableArray *item;
|
|
|
|
int col;
|
|
|
|
|
|
|
|
if (table_apps == nil) return;
|
|
|
|
|
|
|
|
col = [[tableColumn identifier] intValue];
|
|
|
|
|
|
|
|
item = [table_apps objectAtIndex:row];
|
|
|
|
[item replaceObjectAtIndex:col withObject:object];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) hide_window:sender
|
|
|
|
{
|
|
|
|
if ([X11App x_active])
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMHideWindow);
|
2007-02-27 02:06:53 +01:00
|
|
|
else
|
|
|
|
NSBeep (); /* FIXME: something here */
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)bring_to_front:sender
|
|
|
|
{
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMBringAllToFront);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)close_window:sender
|
|
|
|
{
|
|
|
|
if ([X11App x_active])
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMCloseWindow);
|
2007-02-27 02:06:53 +01:00
|
|
|
else
|
|
|
|
[[NSApp keyWindow] performClose:sender];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)minimize_window:sender
|
|
|
|
{
|
|
|
|
if ([X11App x_active])
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMMinimizeWindow);
|
2007-02-27 02:06:53 +01:00
|
|
|
else
|
|
|
|
[[NSApp keyWindow] performMiniaturize:sender];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)zoom_window:sender
|
|
|
|
{
|
|
|
|
if ([X11App x_active])
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMZoomWindow);
|
2007-02-27 02:06:53 +01:00
|
|
|
else
|
|
|
|
[[NSApp keyWindow] performZoom:sender];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) next_window:sender
|
|
|
|
{
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMNextWindow);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) previous_window:sender
|
|
|
|
{
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMPreviousWindow);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2008-11-01 04:03:34 +01:00
|
|
|
- (IBAction) enable_fullscreen_changed:sender {
|
|
|
|
int value = ![enable_fullscreen intValue];
|
2008-10-09 03:39:41 +02:00
|
|
|
|
2008-11-01 04:03:34 +01:00
|
|
|
[enable_fullscreen_menu setEnabled:!value];
|
|
|
|
|
|
|
|
DarwinSendDDXEvent(kXquartzSetRootless, 1, value);
|
|
|
|
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_ROOTLESS value:value];
|
|
|
|
[NSApp prefs_synchronize];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) toggle_fullscreen:sender
|
|
|
|
{
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzToggleFullscreen, 0);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2008-04-19 05:25:38 +02:00
|
|
|
- (void) set_can_quit:(OSX_BOOL)state
|
2007-02-27 02:06:53 +01:00
|
|
|
{
|
|
|
|
can_quit = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)prefs_changed:sender
|
|
|
|
{
|
2008-03-22 03:11:59 +01:00
|
|
|
darwinFakeButtons = [fake_buttons intValue];
|
|
|
|
quartzUseSysBeep = [use_sysbeep intValue];
|
|
|
|
X11EnableKeyEquivalents = [enable_keyequivs intValue];
|
|
|
|
darwinSyncKeymap = [sync_keymap intValue];
|
2008-11-01 04:03:34 +01:00
|
|
|
quartzFullscreenMenu = [enable_fullscreen_menu intValue];
|
2008-09-22 02:40:35 +02:00
|
|
|
|
2008-03-22 03:11:59 +01:00
|
|
|
/* after adding prefs here, also add to [X11Application read_defaults]
|
2008-09-22 02:40:35 +02:00
|
|
|
and prefs_show */
|
2008-11-01 04:03:34 +01:00
|
|
|
|
2008-03-22 03:11:59 +01:00
|
|
|
[NSApp prefs_set_boolean:@PREFS_FAKEBUTTONS value:darwinFakeButtons];
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_SYSBEEP value:quartzUseSysBeep];
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_KEYEQUIVS value:X11EnableKeyEquivalents];
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_SYNC_KEYMAP value:darwinSyncKeymap];
|
2008-11-01 04:03:34 +01:00
|
|
|
[NSApp prefs_set_boolean:@PREFS_FULLSCREEN_MENU value:quartzFullscreenMenu];
|
2008-03-22 03:11:59 +01:00
|
|
|
[NSApp prefs_set_boolean:@PREFS_CLICK_THROUGH value:[click_through intValue]];
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_FFM value:[focus_follows_mouse intValue]];
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_FOCUS_ON_NEW_WINDOW value:[focus_on_new_window intValue]];
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_NO_AUTH value:![enable_auth intValue]];
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_NO_TCP value:![enable_tcp intValue]];
|
|
|
|
[NSApp prefs_set_integer:@PREFS_DEPTH value:[depth selectedTag]];
|
2008-09-22 02:40:35 +02:00
|
|
|
|
2008-10-03 20:12:49 +02:00
|
|
|
BOOL pbproxy_active = [sync_pasteboard intValue];
|
2008-11-01 04:03:34 +01:00
|
|
|
|
2008-10-03 20:12:49 +02:00
|
|
|
[NSApp prefs_set_boolean:@PREFS_SYNC_PB value:pbproxy_active];
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_SYNC_PB_TO_CLIPBOARD value:[sync_pasteboard_to_clipboard intValue]];
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_SYNC_PB_TO_PRIMARY value:[sync_pasteboard_to_primary intValue]];
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_SYNC_CLIPBOARD_TO_PB value:[sync_clipboard_to_pasteboard intValue]];
|
|
|
|
[NSApp prefs_set_boolean:@PREFS_SYNC_PRIMARY_ON_SELECT value:[sync_primary_immediately intValue]];
|
2008-11-01 04:03:34 +01:00
|
|
|
|
2008-03-22 03:11:59 +01:00
|
|
|
[NSApp prefs_synchronize];
|
2008-10-03 20:12:49 +02:00
|
|
|
|
|
|
|
[sync_pasteboard_to_clipboard setEnabled:pbproxy_active];
|
|
|
|
[sync_pasteboard_to_primary setEnabled:pbproxy_active];
|
|
|
|
[sync_clipboard_to_pasteboard setEnabled:pbproxy_active];
|
|
|
|
[sync_primary_immediately setEnabled:pbproxy_active];
|
|
|
|
|
|
|
|
// setEnabled doesn't do this...
|
|
|
|
[sync_text1 setTextColor:pbproxy_active ? [NSColor controlTextColor] : [NSColor disabledControlTextColor]];
|
|
|
|
[sync_text2 setTextColor:pbproxy_active ? [NSColor controlTextColor] : [NSColor disabledControlTextColor]];
|
|
|
|
|
|
|
|
DarwinSendDDXEvent(kXquartzReloadPreferences, 0);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) prefs_show:sender
|
|
|
|
{
|
2008-10-03 20:12:49 +02:00
|
|
|
BOOL pbproxy_active = [NSApp prefs_get_boolean:@PREFS_SYNC_PB default:YES];
|
|
|
|
|
2008-03-22 03:31:31 +01:00
|
|
|
[fake_buttons setIntValue:darwinFakeButtons];
|
|
|
|
[use_sysbeep setIntValue:quartzUseSysBeep];
|
|
|
|
[enable_keyequivs setIntValue:X11EnableKeyEquivalents];
|
|
|
|
[sync_keymap setIntValue:darwinSyncKeymap];
|
|
|
|
[click_through setIntValue:[NSApp prefs_get_boolean:@PREFS_CLICK_THROUGH default:NO]];
|
|
|
|
[focus_follows_mouse setIntValue:[NSApp prefs_get_boolean:@PREFS_FFM default:NO]];
|
|
|
|
[focus_on_new_window setIntValue:[NSApp prefs_get_boolean:@PREFS_FOCUS_ON_NEW_WINDOW default:YES]];
|
|
|
|
|
|
|
|
[enable_auth setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_AUTH default:NO]];
|
|
|
|
[enable_tcp setIntValue:![NSApp prefs_get_boolean:@PREFS_NO_TCP default:NO]];
|
|
|
|
|
|
|
|
[depth selectItemAtIndex:[depth indexOfItemWithTag:[NSApp prefs_get_integer:@PREFS_DEPTH default:-1]]];
|
2008-10-03 20:12:49 +02:00
|
|
|
|
2008-09-22 02:40:35 +02:00
|
|
|
[sync_pasteboard setIntValue:pbproxy_active];
|
2008-10-03 20:12:49 +02:00
|
|
|
[sync_pasteboard_to_clipboard setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_PB_TO_CLIPBOARD default:YES]];
|
|
|
|
[sync_pasteboard_to_primary setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_PB_TO_PRIMARY default:YES]];
|
|
|
|
[sync_clipboard_to_pasteboard setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_CLIPBOARD_TO_PB default:YES]];
|
|
|
|
[sync_primary_immediately setIntValue:[NSApp prefs_get_boolean:@PREFS_SYNC_PRIMARY_ON_SELECT default:NO]];
|
2008-09-22 02:40:35 +02:00
|
|
|
|
|
|
|
[sync_pasteboard_to_clipboard setEnabled:pbproxy_active];
|
|
|
|
[sync_pasteboard_to_primary setEnabled:pbproxy_active];
|
|
|
|
[sync_clipboard_to_pasteboard setEnabled:pbproxy_active];
|
|
|
|
[sync_primary_immediately setEnabled:pbproxy_active];
|
|
|
|
|
2008-09-19 22:15:07 +02:00
|
|
|
// setEnabled doesn't do this...
|
|
|
|
[sync_text1 setTextColor:pbproxy_active ? [NSColor controlTextColor] : [NSColor disabledControlTextColor]];
|
|
|
|
[sync_text2 setTextColor:pbproxy_active ? [NSColor controlTextColor] : [NSColor disabledControlTextColor]];
|
2008-03-22 03:31:31 +01:00
|
|
|
|
2008-11-01 04:03:34 +01:00
|
|
|
[enable_fullscreen setIntValue:!quartzEnableRootless];
|
|
|
|
[enable_fullscreen_menu setEnabled:!quartzEnableRootless];
|
|
|
|
[enable_fullscreen_menu setIntValue:quartzFullscreenMenu];
|
|
|
|
|
2008-03-22 03:31:31 +01:00
|
|
|
[prefs_panel makeKeyAndOrderFront:sender];
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) quit:sender
|
|
|
|
{
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzQuit, 0);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) x11_help:sender
|
|
|
|
{
|
2007-09-21 01:50:49 +02:00
|
|
|
AHLookupAnchor ((CFStringRef)NSLocalizedString(@"Mac Help", no comment), CFSTR ("mchlp2276"));
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2008-04-19 05:25:38 +02:00
|
|
|
- (OSX_BOOL) validateMenuItem:(NSMenuItem *)item
|
2007-02-27 02:06:53 +01:00
|
|
|
{
|
|
|
|
NSMenu *menu = [item menu];
|
2008-09-22 02:40:35 +02:00
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
if (item == toggle_fullscreen_item)
|
|
|
|
return !quartzEnableRootless;
|
2008-09-22 02:40:35 +02:00
|
|
|
else if (item == copy_menu_item) // For some reason, this isn't working...
|
|
|
|
return NO;
|
2007-02-27 02:06:53 +01:00
|
|
|
else if (menu == [window_separator menu] || menu == dock_menu
|
|
|
|
|| (menu == [x11_about_item menu] && [item tag] == 42))
|
|
|
|
return (AppleWMSelectedEvents () & AppleWMControllerNotifyMask) != 0;
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) applicationDidHide:(NSNotification *)notify
|
|
|
|
{
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMHideAll);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) applicationDidUnhide:(NSNotification *)notify
|
|
|
|
{
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMShowAll);
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
2008-04-21 07:18:45 +02:00
|
|
|
- (NSApplicationTerminateReply) applicationShouldTerminate:sender {
|
|
|
|
NSString *msg;
|
|
|
|
NSString *title;
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2008-04-21 07:18:45 +02:00
|
|
|
if (can_quit || [X11App prefs_get_boolean:@PREFS_NO_QUIT_ALERT default:NO])
|
|
|
|
return NSTerminateNow;
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2008-04-21 07:18:45 +02:00
|
|
|
/* Make sure we're frontmost. */
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2008-04-21 07:18:45 +02:00
|
|
|
title = NSLocalizedString(@"Do you really want to quit X11?", @"Dialog title when quitting");
|
|
|
|
msg = NSLocalizedString(@"Any open X11 applications will stop immediately, and you will lose any unsaved changes.", @"Dialog when quitting");
|
|
|
|
|
|
|
|
/* FIXME: safe to run the alert in here? Or should we return Later
|
|
|
|
* and then run the alert on a timer? It seems to work here, so..
|
|
|
|
*/
|
2007-02-27 02:06:53 +01:00
|
|
|
|
2008-04-21 07:18:45 +02:00
|
|
|
return (NSRunAlertPanel (title, msg, NSLocalizedString (@"Quit", @""),
|
|
|
|
NSLocalizedString (@"Cancel", @""), nil)
|
|
|
|
== NSAlertDefaultReturn) ? NSTerminateNow : NSTerminateCancel;
|
2007-02-27 02:06:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) applicationWillTerminate:(NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
[X11App prefs_synchronize];
|
|
|
|
|
|
|
|
/* shutdown the X server, it will exit () for us. */
|
2008-04-01 07:55:24 +02:00
|
|
|
DarwinSendDDXEvent(kXquartzQuit, 0);
|
2007-02-27 02:06:53 +01:00
|
|
|
|
|
|
|
/* In case it doesn't, exit anyway after a while. */
|
|
|
|
while (sleep (10) != 0) ;
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) server_ready
|
|
|
|
{
|
|
|
|
x_list *node;
|
|
|
|
|
|
|
|
finished_launching = YES;
|
|
|
|
|
|
|
|
for (node = pending_apps; node != NULL; node = node->next)
|
|
|
|
{
|
|
|
|
NSString *filename = node->data;
|
|
|
|
[self launch_client:filename];
|
|
|
|
[filename release];
|
|
|
|
}
|
|
|
|
|
|
|
|
x_list_free (pending_apps);
|
|
|
|
pending_apps = NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-19 05:25:38 +02:00
|
|
|
- (OSX_BOOL) application:(NSApplication *)app openFile:(NSString *)filename
|
2007-02-27 02:06:53 +01:00
|
|
|
{
|
2008-04-12 02:49:51 +02:00
|
|
|
const char *name = [filename UTF8String];
|
|
|
|
|
|
|
|
if (finished_launching)
|
|
|
|
[self launch_client:filename];
|
|
|
|
else if (name[0] != ':') /* ignore display names */
|
|
|
|
pending_apps = x_list_prepend (pending_apps, [filename retain]);
|
|
|
|
|
|
|
|
/* FIXME: report failures. */
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-02-27 02:06:53 +01:00
|
|
|
@end
|
2007-12-21 00:46:40 +01:00
|
|
|
|
2008-04-28 20:47:49 +02:00
|
|
|
void X11ControllerMain(int argc, char **argv, char **envp) {
|
|
|
|
X11ApplicationMain (argc, argv, envp);
|
2007-12-21 00:46:40 +01:00
|
|
|
}
|