xserver-multidpi/hw/xquartz/X11Controller.m
Jeremy Huddleston 5324557c7b XQuartz: Source formatting cleanup
indent butchered Objective-C formatting.  This patch was created by:

1) Reverting the indent changes in hw/xquartz
2) Editing X11Application.m and chaning some #ifdef logic to work
   with uncrustify
3) Hand edited some (c) notifications
4) Opened all XQuartz sources in XCode and re-indented (^I)
5) Ran uncrustify with this configuration
   (as close to the indent rules as I could get):

tok_split_gte=false
utf8_byte=true
utf8_force=true
indent_cmt_with_tabs=false
indent_align_string=false
indent_braces=false
indent_braces_no_func=false
indent_braces_no_class=false
indent_braces_no_struct=false
indent_brace_parent=false
indent_namespace=false
indent_extern=false
indent_class=false
indent_class_colon=false
indent_else_if=false
indent_var_def_cont=false
indent_func_call_param=false
indent_func_def_param=false
indent_func_proto_param=false
indent_func_class_param=false
indent_func_ctor_var_param=false
indent_template_param=false
indent_func_param_double=false
indent_relative_single_line_comments=false
indent_col1_comment=false
indent_access_spec_body=false
indent_paren_nl=false
indent_comma_paren=false
indent_bool_paren=false
indent_first_bool_expr=false
indent_square_nl=false
indent_preserve_sql=false
indent_align_assign=true
sp_balance_nested_parens=false
align_keep_tabs=false
align_with_tabs=false
align_on_tabstop=false
align_number_left=false
align_func_params=false
align_same_func_call_params=false
align_var_def_colon=true
align_var_def_attribute=true
align_var_def_inline=true
align_right_cmt_mix=false
align_on_operator=false
align_mix_var_proto=false
align_single_line_func=false
align_single_line_brace=false
align_nl_cont=false
align_left_shift=true
align_oc_decl_colon=true
nl_collapse_empty_body=true
nl_assign_leave_one_liners=true
nl_class_leave_one_liners=true
nl_enum_leave_one_liners=true
nl_getset_leave_one_liners=true
nl_func_leave_one_liners=true
nl_if_leave_one_liners=true
nl_multi_line_cond=false
nl_multi_line_define=false
nl_before_case=true
nl_after_case=true
nl_after_return=false
nl_after_semicolon=true
nl_after_brace_open=true
nl_after_brace_open_cmt=false
nl_after_vbrace_open=false
nl_after_vbrace_open_empty=false
nl_after_brace_close=false
nl_after_vbrace_close=false
nl_define_macro=false
nl_squeeze_ifdef=false
nl_ds_struct_enum_cmt=false
nl_ds_struct_enum_close_brace=false
nl_create_if_one_liner=false
nl_create_for_one_liner=false
nl_create_while_one_liner=false
ls_for_split_full=false
ls_func_split_full=false
nl_after_multiline_comment=false
eat_blanks_after_open_brace=false
eat_blanks_before_close_brace=false
mod_full_brace_if_chain=false
mod_pawn_semicolon=false
mod_full_paren_if_bool=false
mod_remove_extra_semicolon=false
mod_sort_import=false
mod_sort_using=false
mod_sort_include=false
mod_move_case_break=false
mod_remove_empty_return=false
cmt_indent_multi=true
cmt_c_group=false
cmt_c_nl_start=false
cmt_c_nl_end=false
cmt_cpp_group=false
cmt_cpp_nl_start=false
cmt_cpp_nl_end=false
cmt_cpp_to_c=false
cmt_star_cont=false
cmt_multi_check_last=true
cmt_insert_before_preproc=false
pp_indent_at_level=false
pp_region_indent_code=false
pp_if_indent_code=false
pp_define_at_level=false
indent_columns=4
indent_brace=0
indent_switch_case=0
align_struct_init_span=2
align_pp_define_gap=0
align_pp_define_span=2
align_oc_msg_colon_span=16
nl_end_of_file_min=1
nl_func_var_def_blk=0
code_width=78
nl_max=2
newlines=auto
indent_with_tabs=0
sp_arith=force
sp_assign=force
sp_assign_default=force
sp_before_assign=force
sp_after_assign=force
sp_enum_assign=force
sp_enum_before_assign=force
sp_enum_after_assign=force
sp_pp_stringify=add
sp_bool=force
sp_compare=force
sp_inside_paren=remove
sp_paren_paren=remove
sp_paren_brace=force
sp_before_ptr_star=ignore
sp_before_unnamed_ptr_star=force
sp_before_byref=force
sp_before_unnamed_byref=force
sp_after_byref=remove
sp_after_type=force
sp_before_sparen=force
sp_inside_sparen=remove
sp_inside_sparen_close=remove
sp_after_sparen=force
sp_sparen_brace=force
sp_special_semi=force
sp_before_semi=remove
sp_after_semi=force
sp_after_semi_for=force
sp_after_semi_for_empty=remove
sp_before_square=remove
sp_inside_square=remove
sp_after_comma=force
sp_before_comma=remove
sp_paren_comma=force
sp_before_ellipsis=force
sp_after_class_colon=force
sp_before_class_colon=force
sp_before_case_colon=remove
sp_after_cast=remove
sp_inside_paren_cast=remove
sp_sizeof_paren=remove
sp_inside_braces_enum=force
sp_inside_braces_struct=force
sp_inside_braces=force
sp_inside_braces_empty=remove
sp_func_proto_paren=remove
sp_func_def_paren=remove
sp_inside_fparens=remove
sp_inside_fparen=remove
sp_square_fparen=remove
sp_fparen_brace=force
sp_func_call_paren=remove
sp_func_call_paren_empty=remove
sp_return_paren=force
sp_attribute_paren=remove
sp_defined_paren=remove
sp_macro=force
sp_macro_func=force
sp_else_brace=force
sp_brace_else=force
sp_brace_typedef=force
sp_not=remove
sp_inv=remove
nl_start_of_file=remove
nl_end_of_file=force
nl_assign_square=remove
nl_after_square_assign=remove
nl_fcall_brace=remove
nl_enum_brace=remove
nl_struct_brace=remove
nl_union_brace=remove
nl_if_brace=remove
nl_brace_else=force
nl_elseif_brace=remove
nl_else_brace=remove
nl_else_if=remove
nl_for_brace=remove
nl_do_brace=remove
nl_brace_while=remove
nl_switch_brace=remove
nl_case_colon_brace=force
nl_func_type_name=force
nl_func_type_name_class=force
nl_func_proto_type_name=force
nl_func_paren=remove
nl_func_def_paren=remove
nl_func_decl_start=remove
nl_func_def_start=remove
nl_func_decl_args=remove
nl_func_decl_end=remove
nl_func_def_end=remove
nl_func_decl_end_single=remove
nl_func_def_end_single=remove
nl_func_decl_empty=remove
nl_func_def_empty=remove
nl_fdef_brace=force
nl_return_expr=remove
nl_before_if=ignore
nl_after_if=ignore
nl_before_for=ignore
nl_after_for=ignore
nl_before_while=ignore
nl_after_while=ignore
nl_before_switch=ignore
nl_after_switch=ignore
nl_before_do=ignore
nl_after_do=ignore
pp_space=remove

Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
2012-03-24 01:07:06 -07:00

930 lines
27 KiB
Objective-C

/* X11Controller.m -- connect the IB ui, also the NSApp delegate
*
* Copyright (c) 2002-2012 Apple Inc. All rights reserved.
*
* 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.
*/
#include "sanitizedCarbon.h"
#include <AvailabilityMacros.h>
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include "quartzCommon.h"
#import "X11Controller.h"
#import "X11Application.h"
#include "opaque.h"
#include "darwin.h"
#include "darwinEvents.h"
#include "quartz.h"
#include "quartzKeyboard.h"
#include <X11/extensions/applewmconst.h>
#include "applewmExt.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
@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];
}
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(apps_table_done:)
name: NSWindowWillCloseNotification
object: [apps_table window]];
// Setup data about our Windows menu
if (window_separator) {
[[window_separator menu] removeItem:window_separator];
window_separator = nil;
}
windows_menu_start = [[X11App windowsMenu] numberOfItems];
}
- (void) item_selected:sender
{
[NSApp activateIgnoringOtherApps:YES];
DarwinSendDDXEvent(kXquartzControllerNotify, 2,
AppleWMWindowMenuItem, [sender tag]);
}
- (void) remove_window_menu
{
NSMenu *menu;
int count, i;
/* Work backwards so we don't mess up the indices */
menu = [X11App windowsMenu];
count = [menu numberOfItems];
for (i = count - 1; i >= windows_menu_start; i--)
[menu removeItemAtIndex:i];
count = [dock_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;
menu = [X11App windowsMenu];
first = windows_menu_start + 1;
count = [list count];
// Push a Separator
if (count) {
[menu addItem:[NSMenuItem separatorItem]];
}
for (i = 0; i < count; i++) {
NSString *name, *shortcut;
name = [[list objectAtIndex:i] objectAtIndex:0];
shortcut = [[list objectAtIndex:i] objectAtIndex:1];
if (windowItemModMask == 0 || windowItemModMask == -1)
shortcut = @"";
item =
(NSMenuItem *)[menu addItemWithTitle:name action:
@selector
(item_selected:) keyEquivalent:shortcut];
[item setKeyEquivalentModifierMask:(NSUInteger)windowItemModMask];
[item setTarget:self];
[item setTag:i];
[item setEnabled:YES];
item = (NSMenuItem *)[dock_menu insertItemWithTitle:name
action:@selector
(item_selected:) keyEquivalent:shortcut
atIndex:i];
[item setKeyEquivalentModifierMask:(NSUInteger)windowItemModMask];
[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];
DarwinSendDDXEvent(kXquartzControllerNotify, 1,
AppleWMWindowMenuNotify);
}
- (void) set_window_menu_check:(NSNumber *)nn
{
NSMenu *menu;
NSMenuItem *item;
int first, count;
int n = [nn intValue];
menu = [X11App windowsMenu];
first = windows_menu_start + 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];
}
#ifdef XQUARTZ_SPARKLE
- (void) setup_sparkle
{
if (check_for_updates_item)
return; // already did it...
NSMenu *menu = [x11_about_item menu];
check_for_updates_item =
[menu insertItemWithTitle:NSLocalizedString(
@"Check for X11 Updates...",
@"Check for X11 Updates...")
action:@selector (
checkForUpdates:)
keyEquivalent:@""
atIndex:1];
[check_for_updates_item setTarget:[SUUpdater sharedUpdater]];
[check_for_updates_item setEnabled:YES];
// Set X11Controller as the delegate for the updater.
[[SUUpdater sharedUpdater] setDelegate:self];
}
// Sent immediately before installing the specified update.
- (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)
update
{
//[self set_can_quit:YES];
}
#endif
- (void) launch_client:(NSString *)filename
{
int child1, child2 = 0;
int status;
const char *newargv[4];
char buf[128];
char *s;
newargv[0] =
[X11App prefs_get_string:@PREFS_LOGIN_SHELL default:"/bin/sh"];
newargv[1] = "-c";
newargv[2] = [filename UTF8String];
newargv[3] = NULL;
s = getenv("DISPLAY");
if (s == NULL || s[0] == 0) {
snprintf(buf, sizeof(buf), ":%s", display);
setenv("DISPLAY", buf, TRUE);
}
/* 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;
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);
execvp(newargv[0], (char * *const)newargv);
_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;
NSMutableArray *oldapps = nil;
if (table_apps != nil)
oldapps = table_apps;
table_apps = [[NSMutableArray alloc] initWithCapacity:1];
if (apps != nil)
[table_apps addObjectsFromArray:apps];
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 selectRowIndexes:[NSIndexSet indexSetWithIndex:0]
byExtendingSelection:NO];
[[apps_table window] makeKeyAndOrderFront:sender];
[apps_table reloadData];
if (oldapps != nil)
[oldapps release];
}
- (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 selectRowIndexes:[NSIndexSet indexSetWithIndex: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 selectRowIndexes:[NSIndexSet indexSetWithIndex: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 selectRowIndexes:[NSIndexSet indexSetWithIndex:row]
byExtendingSelection:NO];
}
- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
{
if (table_apps == nil) return 0;
return [table_apps count];
}
- (id) tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)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:(NSInteger)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])
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMHideWindow);
else
NSBeep(); /* FIXME: something here */
}
- (IBAction)bring_to_front:sender
{
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMBringAllToFront);
}
- (IBAction)close_window:sender
{
if ([X11App x_active])
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMCloseWindow);
else
[[NSApp keyWindow] performClose:sender];
}
- (IBAction)minimize_window:sender
{
if ([X11App x_active])
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMMinimizeWindow);
else
[[NSApp keyWindow] performMiniaturize:sender];
}
- (IBAction)zoom_window:sender
{
if ([X11App x_active])
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMZoomWindow);
else
[[NSApp keyWindow] performZoom:sender];
}
- (IBAction) next_window:sender
{
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMNextWindow);
}
- (IBAction) previous_window:sender
{
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMPreviousWindow);
}
- (IBAction) enable_fullscreen_changed:sender
{
XQuartzRootlessDefault = ![enable_fullscreen intValue];
[enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault];
[enable_fullscreen_menu_text setTextColor:XQuartzRootlessDefault ?[
NSColor disabledControlTextColor] : [NSColor controlTextColor]];
DarwinSendDDXEvent(kXquartzSetRootless, 1, XQuartzRootlessDefault);
[NSApp prefs_set_boolean:@PREFS_ROOTLESS value:XQuartzRootlessDefault];
[NSApp prefs_synchronize];
}
- (IBAction) toggle_fullscreen:sender
{
DarwinSendDDXEvent(kXquartzToggleFullscreen, 0);
}
- (void) set_can_quit:(OSX_BOOL)state
{
can_quit = state;
}
- (IBAction)prefs_changed:sender
{
if (!sender)
return;
if (sender == fake_buttons) {
darwinFakeButtons = [fake_buttons intValue];
[NSApp prefs_set_boolean:@PREFS_FAKEBUTTONS value:darwinFakeButtons];
}
else if (sender == enable_keyequivs) {
XQuartzEnableKeyEquivalents = [enable_keyequivs intValue];
[NSApp prefs_set_boolean:@PREFS_KEYEQUIVS value:
XQuartzEnableKeyEquivalents];
}
else if (sender == sync_keymap) {
darwinSyncKeymap = [sync_keymap intValue];
[NSApp prefs_set_boolean:@PREFS_SYNC_KEYMAP value:darwinSyncKeymap];
}
else if (sender == enable_fullscreen_menu) {
XQuartzFullscreenMenu = [enable_fullscreen_menu intValue];
[NSApp prefs_set_boolean:@PREFS_FULLSCREEN_MENU value:
XQuartzFullscreenMenu];
}
else if (sender == option_sends_alt) {
BOOL prev_opt_sends_alt = XQuartzOptionSendsAlt;
XQuartzOptionSendsAlt = [option_sends_alt intValue];
[NSApp prefs_set_boolean:@PREFS_OPTION_SENDS_ALT value:
XQuartzOptionSendsAlt];
if (prev_opt_sends_alt != XQuartzOptionSendsAlt)
QuartsResyncKeymap(TRUE);
}
else if (sender == click_through) {
[NSApp prefs_set_boolean:@PREFS_CLICK_THROUGH value:[click_through
intValue]];
}
else if (sender == focus_follows_mouse) {
[NSApp prefs_set_boolean:@PREFS_FFM value:[focus_follows_mouse
intValue]];
}
else if (sender == focus_on_new_window) {
[NSApp prefs_set_boolean:@PREFS_FOCUS_ON_NEW_WINDOW value:[
focus_on_new_window intValue]];
}
else if (sender == enable_auth) {
[NSApp prefs_set_boolean:@PREFS_NO_AUTH value:![enable_auth intValue]
];
}
else if (sender == enable_tcp) {
[NSApp prefs_set_boolean:@PREFS_NO_TCP value:![enable_tcp intValue]];
}
else if (sender == depth) {
[NSApp prefs_set_integer:@PREFS_DEPTH value:[depth selectedTag]];
}
else if (sender == sync_pasteboard) {
BOOL pbproxy_active = [sync_pasteboard intValue];
[NSApp prefs_set_boolean:@PREFS_SYNC_PB value:pbproxy_active];
[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]];
}
else if (sender == sync_pasteboard_to_clipboard) {
[NSApp prefs_set_boolean:@PREFS_SYNC_PB_TO_CLIPBOARD value:[
sync_pasteboard_to_clipboard intValue]];
}
else if (sender == sync_pasteboard_to_primary) {
[NSApp prefs_set_boolean:@PREFS_SYNC_PB_TO_PRIMARY value:[
sync_pasteboard_to_primary intValue]];
}
else if (sender == sync_clipboard_to_pasteboard) {
[NSApp prefs_set_boolean:@PREFS_SYNC_CLIPBOARD_TO_PB value:[
sync_clipboard_to_pasteboard intValue]];
}
else if (sender == sync_primary_immediately) {
[NSApp prefs_set_boolean:@PREFS_SYNC_PRIMARY_ON_SELECT value:[
sync_primary_immediately intValue]];
}
else if (sender == scroll_in_device_direction) {
XQuartzScrollInDeviceDirection =
[scroll_in_device_direction intValue];
[NSApp prefs_set_boolean:@PREFS_SCROLL_IN_DEV_DIRECTION value:
XQuartzScrollInDeviceDirection];
}
[NSApp prefs_synchronize];
DarwinSendDDXEvent(kXquartzReloadPreferences, 0);
}
- (IBAction) prefs_show:sender
{
BOOL pbproxy_active =
[NSApp prefs_get_boolean:@PREFS_SYNC_PB default:YES];
// Remove preferences from the GUI which are not supported
// TODO: Change 1117 to NSAppKitVersionNumber10_7 when it is defined
if (scroll_in_device_direction && NSAppKitVersionNumber < 1117) {
[scroll_in_device_direction removeFromSuperview];
scroll_in_device_direction = nil;
}
else {
[scroll_in_device_direction setIntValue:
XQuartzScrollInDeviceDirection];
}
[fake_buttons setIntValue:darwinFakeButtons];
[enable_keyequivs setIntValue:XQuartzEnableKeyEquivalents];
[sync_keymap setIntValue:darwinSyncKeymap];
[option_sends_alt setIntValue:XQuartzOptionSendsAlt];
[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]]];
[sync_pasteboard setIntValue:pbproxy_active];
[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]];
[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]];
[enable_fullscreen setIntValue:!XQuartzRootlessDefault];
[enable_fullscreen_menu setIntValue:XQuartzFullscreenMenu];
[enable_fullscreen_menu setEnabled:!XQuartzRootlessDefault];
[enable_fullscreen_menu_text setTextColor:XQuartzRootlessDefault ?[
NSColor disabledControlTextColor] : [NSColor controlTextColor]];
[prefs_panel makeKeyAndOrderFront:sender];
}
- (IBAction) quit:sender
{
DarwinSendDDXEvent(kXquartzQuit, 0);
}
- (IBAction) x11_help:sender
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
AHLookupAnchor((CFStringRef)NSLocalizedString(@"Mac Help",
no comment),
CFSTR("mchlp2276"));
#else
AHLookupAnchor(CFSTR("com.apple.machelp"), CFSTR("mchlp2276"));
#endif
}
- (OSX_BOOL) validateMenuItem:(NSMenuItem *)item
{
NSMenu *menu = [item menu];
if (item == toggle_fullscreen_item)
return !XQuartzIsRootless;
else if (menu == [X11App windowsMenu] || menu == dock_menu
|| (menu == [x11_about_item menu] && [item tag] == 42))
return (AppleWMSelectedEvents() & AppleWMControllerNotifyMask) != 0;
else
return TRUE;
}
- (void) applicationDidHide:(NSNotification *)notify
{
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMHideAll);
/* Toggle off fullscreen mode to leave our non-default video
* mode and hide our guard window.
*/
if (!XQuartzIsRootless && XQuartzFullscreenVisible) {
DarwinSendDDXEvent(kXquartzToggleFullscreen, 0);
}
}
- (void) applicationDidUnhide:(NSNotification *)notify
{
DarwinSendDDXEvent(kXquartzControllerNotify, 1, AppleWMShowAll);
}
- (NSApplicationTerminateReply) applicationShouldTerminate:sender
{
NSString *msg;
NSString *title;
if (can_quit ||
[X11App prefs_get_boolean:@PREFS_NO_QUIT_ALERT default:NO])
return NSTerminateNow;
/* Make sure we're frontmost. */
[NSApp activateIgnoringOtherApps:YES];
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..
*/
return (NSRunAlertPanel(title, msg, NSLocalizedString(@"Quit", @""),
NSLocalizedString(@"Cancel", @""), nil)
== NSAlertDefaultReturn) ? NSTerminateNow : NSTerminateCancel;
}
- (void) applicationWillTerminate:(NSNotification *)aNotification
{
unsigned remain;
[X11App prefs_synchronize];
/* shutdown the X server, it will exit () for us. */
DarwinSendDDXEvent(kXquartzQuit, 0);
/* In case it doesn't, exit anyway after a while. */
remain = 10000000;
while ((remain = usleep(remain)) > 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;
}
- (OSX_BOOL) application:(NSApplication *)app openFile:(NSString *)filename
{
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;
}
@end
void
X11ControllerMain(int argc, char **argv, char **envp)
{
X11ApplicationMain(argc, argv, envp);
}