open-src/app/dispswitch/sun-src/dispswitch.c
author X gate hg captive account <xhg@xserver.us.oracle.com>
Wed, 19 Aug 2015 13:48:41 -0700
changeset 1484 bc8922b8e1d2
parent 1459 f624eee89e0b
permissions -rw-r--r--
Added tag s11u3_30 for changeset 221e9d9cc9cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
     1
/* 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
     2
 * Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
     3
 * Copyright © 2002 Hewlett Packard Company, Inc.
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
     4
 * Copyright © 2006 Intel Corporation
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
     5
 *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
     6
 * Permission to use, copy, modify, distribute, and sell this software and its
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
     7
 * documentation for any purpose is hereby granted without fee, provided that
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
     8
 * the above copyright notice appear in all copies and that both that copyright
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
     9
 * notice and this permission notice appear in supporting documentation, and
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    10
 * that the name of the copyright holders not be used in advertising or
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    11
 * publicity pertaining to distribution of the software without specific,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    12
 * written prior permission.  The copyright holders make no representations
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    13
 * about the suitability of this software for any purpose.  It is provided "as
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    14
 * is" without express or implied warranty.
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    15
 *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    16
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    18
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    22
 * OF THIS SOFTWARE.
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    23
 *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    24
 */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    25
919
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    26
/*
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
    27
 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
919
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    28
 *
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    29
 * Permission is hereby granted, free of charge, to any person obtaining a
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    30
 * copy of this software and associated documentation files (the "Software"),
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    31
 * to deal in the Software without restriction, including without limitation
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    32
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    33
 * and/or sell copies of the Software, and to permit persons to whom the
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    34
 * Software is furnished to do so, subject to the following conditions:
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    35
 *
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    36
 * The above copyright notice and this permission notice (including the next
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    37
 * paragraph) shall be included in all copies or substantial portions of the
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    38
 * Software.
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    39
 *
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    40
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    41
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    42
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    43
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    44
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    45
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    46
 * DEALINGS IN THE SOFTWARE.
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    47
 */
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    48
425233ae7236 6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents: 765
diff changeset
    49
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    50
#include <stdio.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    51
#include <X11/Xlib.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    52
#include <X11/Xlibint.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    53
#include <X11/Xproto.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    54
#include <X11/extensions/Xrandr.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    55
#include <X11/Xos.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    56
#include <string.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    57
#include <stdlib.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    58
#include <stdarg.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    59
#include <fcntl.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    60
#include <signal.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    61
#include <sys/proc.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    62
#include <unistd.h>
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    63
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    64
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    65
static char	*program_name;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    66
static Display	*dpy = NULL;
765
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
    67
static Window	root, win;
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    68
static int	screen;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    69
static Bool	nosideview = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    70
static Bool	verbose = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    71
static Bool	testrun = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    72
static int	had_error = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    73
static XErrorHandler	prev_handler;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    74
static int	cur_keycode;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    75
static struct timeval	time_val;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    76
static Rotation	init_rotation;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    77
static int 	init_x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    78
static int 	init_y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    79
static Bool	use_init_pos = False;
1323
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
    80
static Bool	need_off_deferred = False;
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    81
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    82
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    83
usage(void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    84
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    85
    fprintf(stderr, "usage: %s [options]\n", program_name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    86
    fprintf(stderr, "  where options are:\n");
765
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
    87
    fprintf(stderr, "  -toggle or -t\n");
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
    88
    fprintf(stderr, "  -listen or -l\n");
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    89
    fprintf(stderr, "  -display <display> or -d <display>\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    90
    fprintf(stderr, "  -key <key> or -k <key>\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    91
    fprintf(stderr, "  -mod <modifier> or -m <modifier>\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    92
    fprintf(stderr, "  -help\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    93
    fprintf(stderr, "  -nosideview\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    94
    fprintf(stderr, "  -verbose or -v\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    95
    fprintf(stderr, "  -testrun\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    96
    exit(1);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    97
    /*NOTREACHED*/
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    98
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
    99
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   100
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   101
fatal (const char *format, ...)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   102
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   103
    va_list ap;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   104
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   105
    va_start (ap, format);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   106
    fprintf (stderr, "%s exiting: ", program_name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   107
    vfprintf (stderr, format, ap);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   108
    va_end (ap);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   109
    exit (1);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   110
    /*NOTREACHED*/
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   111
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   112
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   113
static int
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   114
cur_handler (
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   115
    Display *const err_display,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   116
    XErrorEvent *const err_event)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   117
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   118
    had_error = err_event -> error_code;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   119
    return (0);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   120
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   121
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   122
typedef enum _relation {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   123
    left_of, right_of, above, below, same_as,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   124
} relation_t;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   125
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   126
typedef enum _changes {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   127
    changes_none = 0,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   128
    changes_crtc = (1 << 0),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   129
    changes_mode = (1 << 1),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   130
    changes_relation = (1 << 2),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   131
    changes_position = (1 << 3),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   132
} changes_t;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   133
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   134
typedef enum _name_kind {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   135
    name_none = 0,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   136
    name_string = (1 << 0),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   137
    name_xid = (1 << 1),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   138
    name_index = (1 << 2),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   139
} name_kind_t;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   140
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   141
typedef struct {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   142
    name_kind_t	    kind;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   143
    char    	    *string;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   144
    XID	    	    xid;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   145
    int		    index;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   146
} name_t;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   147
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   148
typedef struct _crtc crtc_t;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   149
typedef struct _output	output_t;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   150
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   151
struct _crtc {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   152
    name_t	    crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   153
    XRRCrtcInfo	    *crtc_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   154
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   155
    XRRModeInfo	    *mode_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   156
    int		    x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   157
    int		    y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   158
    Rotation	    rotation;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   159
    output_t	    **outputs;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   160
    int		    noutput;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   161
};
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   162
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   163
struct _output {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   164
    struct _output  *next;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   165
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   166
    changes_t	    changes;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   167
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   168
    name_t	    output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   169
    XRROutputInfo   *output_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   170
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   171
    name_t	    crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   172
    crtc_t	    *crtc_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   173
    crtc_t	    *current_crtc_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   174
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   175
    name_t	    mode;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   176
    float	    refresh;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   177
    XRRModeInfo	    *mode_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   178
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   179
    name_t	    addmode;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   180
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   181
    relation_t	    relation;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   182
    struct _output  *relative_to;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   183
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   184
    int		    x, y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   185
    Rotation	    rotation;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   186
};
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   187
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   188
static output_t	*outputs = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   189
static output_t	**outputs_tail = &outputs;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   190
static crtc_t	*crtcs = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   191
static int	num_crtcs;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   192
static XRRScreenResources  *res = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   193
static int	fb_width = 0, fb_height = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   194
static int	fb_width_mm = 0, fb_height_mm = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   195
static float	dpi = 0.0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   196
static Bool	dryrun = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   197
static int	minWidth, maxWidth, minHeight, maxHeight;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   198
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   199
#define 	MAX_OUTPUT	3
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   200
#define 	MAX_MODIFIERS	10
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   201
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   202
typedef struct _con_output  con_output_t;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   203
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   204
struct _con_output {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   205
    output_t		*output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   206
    XRRModeInfo		**smodes;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   207
    int			nsmodes;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   208
    Bool		on;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   209
};
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   210
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   211
typedef struct _mod_key_table  mod_key_table_t;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   212
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   213
struct _mod_key_table {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   214
    char		*modname;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   215
    unsigned int	mod;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   216
};
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   217
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   218
static	con_output_t	con_outputs[MAX_OUTPUT];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   219
static	con_output_t	dis_con_outputs[MAX_OUTPUT];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   220
static	XRRModeInfo	*start_mode[MAX_OUTPUT];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   221
static  XRRModeInfo	*new_mode[MAX_OUTPUT];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   222
static	int 	start = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   223
static	int	ncon;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   224
static	int	dis_ncon;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   225
static  Bool	do_not_switch = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   226
static  Bool	did_init = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   227
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   228
static mod_key_table_t	mod_key_table [MAX_MODIFIERS] = {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   229
	{"none",	0},
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   230
	{"shift", 	ShiftMask},
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   231
	{"lock", 	LockMask},
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   232
	{"control",	ControlMask},
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   233
	{"mod1", 	Mod1Mask},
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   234
	{"mod2", 	Mod2Mask},
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   235
	{"mod3", 	Mod3Mask},
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   236
	{"mod4", 	Mod4Mask},
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   237
	{"mod5", 	Mod5Mask},
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   238
	{"any", 	AnyModifier}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   239
};
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   240
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   241
static int
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   242
mode_height (XRRModeInfo *mode_info, Rotation rotation)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   243
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   244
    switch (rotation & 0xf) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   245
    case RR_Rotate_0:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   246
    case RR_Rotate_180:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   247
	return mode_info->height;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   248
    case RR_Rotate_90:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   249
    case RR_Rotate_270:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   250
	return mode_info->width;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   251
    default:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   252
	return 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   253
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   254
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   255
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   256
static int
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   257
mode_width (XRRModeInfo *mode_info, Rotation rotation)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   258
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   259
    switch (rotation & 0xf) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   260
    case RR_Rotate_0:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   261
    case RR_Rotate_180:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   262
	return mode_info->width;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   263
    case RR_Rotate_90:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   264
    case RR_Rotate_270:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   265
	return mode_info->height;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   266
    default:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   267
	return 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   268
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   269
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   270
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   271
/* v refresh frequency in Hz */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   272
static float
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   273
mode_refresh (XRRModeInfo *mode_info)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   274
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   275
    float rate;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   276
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   277
    if (mode_info->hTotal && mode_info->vTotal)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   278
	rate = ((float) mode_info->dotClock / 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   279
		((float) mode_info->hTotal * (float) mode_info->vTotal));
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   280
    else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   281
    	rate = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   282
    return rate;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   283
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   284
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   285
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   286
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   287
init_name (name_t *name)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   288
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   289
    name->kind = name_none;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   290
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   291
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   292
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   293
set_name_string (name_t *name, char *string)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   294
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   295
    name->kind |= name_string;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   296
    name->string = string;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   297
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   298
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   299
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   300
set_name_xid (name_t *name, XID xid)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   301
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   302
    name->kind |= name_xid;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   303
    name->xid = xid;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   304
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   305
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   306
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   307
set_name_index (name_t *name, int index)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   308
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   309
    name->kind |= name_index;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   310
    name->index = index;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   311
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   312
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   313
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   314
set_name_all (name_t *name, name_t *old)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   315
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   316
    if (old->kind & name_xid)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   317
	name->xid = old->xid;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   318
    if (old->kind & name_string)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   319
	name->string = old->string;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   320
    if (old->kind & name_index)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   321
	name->index = old->index;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   322
    name->kind |= old->kind;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   323
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   324
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   325
static output_t *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   326
add_output (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   327
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   328
    output_t *output = calloc (1, sizeof (output_t));
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   329
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   330
    if (!output)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   331
	fatal ("out of memory");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   332
    output->next = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   333
    *outputs_tail = output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   334
    outputs_tail = &output->next;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   335
    return output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   336
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   337
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   338
static output_t *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   339
find_output (name_t *name)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   340
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   341
    output_t *output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   342
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   343
    for (output = outputs; output; output = output->next)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   344
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   345
	name_kind_t common = name->kind & output->output.kind;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   346
	
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   347
	if ((common & name_xid) && name->xid == output->output.xid)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   348
	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   349
	if ((common & name_string) && !strcmp (name->string, output->output.string))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   350
	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   351
	if ((common & name_index) && name->index == output->output.index)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   352
	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   353
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   354
    return output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   355
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   356
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   357
static output_t *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   358
find_output_by_xid (RROutput output)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   359
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   360
    name_t  output_name;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   361
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   362
    init_name (&output_name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   363
    set_name_xid (&output_name, output);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   364
    return find_output (&output_name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   365
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   366
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   367
static crtc_t *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   368
find_crtc (name_t *name)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   369
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   370
    int	    c;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   371
    crtc_t  *crtc = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   372
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   373
    for (c = 0; c < num_crtcs; c++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   374
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   375
	name_kind_t common;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   376
	
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   377
	crtc = &crtcs[c];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   378
	common = name->kind & crtc->crtc.kind;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   379
	
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   380
	if ((common & name_xid) && name->xid == crtc->crtc.xid)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   381
	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   382
	if ((common & name_string) && !strcmp (name->string, crtc->crtc.string))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   383
	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   384
	if ((common & name_index) && name->index == crtc->crtc.index)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   385
	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   386
	crtc = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   387
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   388
    return crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   389
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   390
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   391
static crtc_t *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   392
find_crtc_by_xid (RRCrtc crtc)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   393
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   394
    name_t  crtc_name;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   395
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   396
    init_name (&crtc_name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   397
    set_name_xid (&crtc_name, crtc);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   398
    return find_crtc (&crtc_name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   399
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   400
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   401
static XRRModeInfo *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   402
find_mode (name_t *name)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   403
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   404
    int		m;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   405
    XRRModeInfo	*best = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   406
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   407
    for (m = 0; m < res->nmode; m++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   408
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   409
	XRRModeInfo *mode = &res->modes[m];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   410
	if ((name->kind & name_xid) && name->xid == mode->id)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   411
	{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   412
	    best = mode;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   413
	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   414
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   415
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   416
    return best;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   417
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   418
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   419
static XRRModeInfo *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   420
find_mode_by_xid (RRMode mode)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   421
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   422
    name_t  mode_name;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   423
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   424
    init_name (&mode_name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   425
    set_name_xid (&mode_name, mode);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   426
    return find_mode (&mode_name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   427
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   428
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   429
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   430
set_output_info (output_t *output, RROutput xid, XRROutputInfo *output_info)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   431
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   432
    crtc_t  *crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   433
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   434
    /* sanity check output info */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   435
    if (output_info->connection != RR_Disconnected && !output_info->nmode)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   436
	fatal ("Output %s is not disconnected but has no modes\n",
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   437
	       output_info->name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   438
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   439
    /* set output name and info */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   440
    if (!(output->output.kind & name_xid))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   441
	set_name_xid (&output->output, xid);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   442
    if (!(output->output.kind & name_string))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   443
	set_name_string (&output->output, output_info->name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   444
    output->output_info = output_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   445
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   446
    crtc = find_crtc_by_xid (output->output_info->crtc);    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   447
    /* set position */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   448
    if (crtc && crtc->crtc_info) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   449
	output->x = crtc->crtc_info->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   450
	output->y = crtc->crtc_info->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   451
    } 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   452
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   453
    /* set rotation */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   454
    output->rotation &= ~0xf;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   455
    if (crtc && crtc->crtc_info)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   456
	output->rotation |= (crtc->crtc_info->rotation & 0xf);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   457
    else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   458
	output->rotation = RR_Rotate_0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   459
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   460
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   461
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   462
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   463
get_crtcs (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   464
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   465
    int		c;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   466
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   467
    num_crtcs = res->ncrtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   468
    if (crtcs)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   469
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   470
	for (c = 0; c < res->ncrtc; c++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   471
	{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   472
	    if (crtcs[c].crtc_info)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   473
		XRRFreeCrtcInfo (crtcs[c].crtc_info);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   474
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   475
	free (crtcs);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   476
	crtcs = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   477
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   478
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   479
    crtcs = calloc (num_crtcs, sizeof (crtc_t));
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   480
    if (!crtcs) fatal ("out of memory");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   481
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   482
    for (c = 0; c < res->ncrtc; c++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   483
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   484
	XRRCrtcInfo *crtc_info = XRRGetCrtcInfo (dpy, res, res->crtcs[c]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   485
	set_name_xid (&crtcs[c].crtc, res->crtcs[c]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   486
	set_name_index (&crtcs[c].crtc, c);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   487
	if (!crtc_info) fatal ("could not get crtc 0x%x information", res->crtcs[c]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   488
	crtcs[c].crtc_info = crtc_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   489
	if (crtc_info->mode == None)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   490
	{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   491
	    crtcs[c].mode_info = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   492
	    crtcs[c].x = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   493
	    crtcs[c].y = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   494
	    crtcs[c].rotation = RR_Rotate_0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   495
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   496
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   497
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   498
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   499
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   500
crtc_add_output (crtc_t *crtc, output_t *output)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   501
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   502
    if (crtc->outputs)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   503
	crtc->outputs = realloc (crtc->outputs, (crtc->noutput + 1) * sizeof (output_t *));
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   504
    else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   505
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   506
	crtc->outputs = calloc (1, sizeof (output_t *));
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   507
	crtc->x = output->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   508
	crtc->y = output->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   509
	crtc->rotation = output->rotation;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   510
	crtc->mode_info = output->mode_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   511
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   512
    if (!crtc->outputs) fatal ("out of memory");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   513
    crtc->outputs[crtc->noutput++] = output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   514
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   515
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   516
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   517
set_crtcs (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   518
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   519
    output_t	*output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   520
    int		i;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   521
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   522
    for (i = 0; i < ncon; i++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   523
	output = con_outputs[i].output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   524
	if (!output->mode_info) continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   525
	    if (output->crtc_info)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   526
		crtc_add_output (output->crtc_info, output);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   527
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   528
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   529
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   530
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   531
reset_crtcs_for_outputs (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   532
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   533
    output_t    *output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   534
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   535
    for (output = outputs; output; output = output->next)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   536
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   537
        if ((output->crtc_info) && (output->crtc_info->outputs)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   538
            free (output->crtc_info->outputs);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   539
            output->crtc_info = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   540
        }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   541
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   542
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   543
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   544
static Status
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   545
crtc_disable (crtc_t *crtc)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   546
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   547
    if (verbose)
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
   548
    	fprintf (stderr, "crtc %d (0x%lx) : disable\n", crtc->crtc.index, crtc->crtc.xid);
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   549
	
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   550
    if (dryrun)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   551
	return RRSetConfigSuccess;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   552
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   553
    return XRRSetCrtcConfig (dpy, res, crtc->crtc.xid, CurrentTime,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   554
			     0, 0, None, RR_Rotate_0, NULL, 0);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   555
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   556
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   557
static Status
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   558
crtc_revert (crtc_t *crtc)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   559
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   560
    XRRCrtcInfo	*crtc_info = crtc->crtc_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   561
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   562
    if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   563
    	fprintf (stderr, "crtc %d: revert\n", crtc->crtc.index);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   564
	
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   565
    if (dryrun)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   566
	return RRSetConfigSuccess;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   567
    return XRRSetCrtcConfig (dpy, res, crtc->crtc.xid, CurrentTime,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   568
			    crtc_info->x, crtc_info->y,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   569
			    crtc_info->mode, crtc_info->rotation,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   570
			    crtc_info->outputs, crtc_info->noutput);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   571
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   572
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   573
static Status
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   574
crtc_apply (crtc_t *crtc)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   575
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   576
    RROutput	*rr_outputs;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   577
    int		o;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   578
    Status	s;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   579
    RRMode	mode = None;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   580
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   581
    if (!crtc->mode_info)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   582
	return RRSetConfigSuccess;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   583
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   584
    rr_outputs = calloc (crtc->noutput, sizeof (RROutput));
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   585
    if (!rr_outputs)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   586
	return BadAlloc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   587
    for (o = 0; o < crtc->noutput; o++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   588
	rr_outputs[o] = crtc->outputs[o]->output.xid;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   589
    mode = crtc->mode_info->id;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   590
    if (verbose) {
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
   591
	fprintf (stderr, "crtc %d (0x%lx) : %12s %6.1f +%d+%d", crtc->crtc.index,
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   592
		crtc->crtc.xid,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   593
		crtc->mode_info->name, mode_refresh (crtc->mode_info),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   594
		crtc->x, crtc->y);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   595
	for (o = 0; o < crtc->noutput; o++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   596
	    fprintf (stderr, " \"%s\"", crtc->outputs[o]->output.string);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   597
	    fprintf (stderr, "\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   598
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   599
    if (dryrun)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   600
	s = RRSetConfigSuccess;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   601
    else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   602
	s = XRRSetCrtcConfig (dpy, res, crtc->crtc.xid, CurrentTime,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   603
			      crtc->x, crtc->y, mode, crtc->rotation,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   604
			      rr_outputs, crtc->noutput);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   605
    free (rr_outputs);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   606
    return s;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   607
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   608
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   609
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   610
screen_revert (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   611
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   612
    if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   613
	fprintf (stderr, "screen %d: revert\n", screen);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   614
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   615
    if (dryrun)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   616
	return;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   617
    XRRSetScreenSize (dpy, root,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   618
		      DisplayWidth (dpy, screen),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   619
		      DisplayHeight (dpy, screen),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   620
		      DisplayWidthMM (dpy, screen),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   621
		      DisplayHeightMM (dpy, screen));
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   622
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   623
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   624
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   625
screen_apply (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   626
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   627
    /* comment it out because DisplayWidth() does not reflect the
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   628
       change of fb_width and fb_height previously set by
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   629
       XRRSetScreenSize()
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   630
    */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   631
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   632
    if (fb_width == DisplayWidth (dpy, screen) &&
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   633
	fb_height == DisplayHeight (dpy, screen) &&
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   634
	fb_width_mm == DisplayWidthMM (dpy, screen) &&
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   635
	fb_height_mm == DisplayHeightMM (dpy, screen))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   636
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   637
	return;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   638
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   639
    */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   640
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   641
    if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   642
	fprintf (stderr, "screen %d: %dx%d %dx%d mm %6.2fdpi\n", screen,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   643
		fb_width, fb_height, fb_width_mm, fb_height_mm, dpi);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   644
    if (dryrun)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   645
	return;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   646
    XRRSetScreenSize (dpy, root, fb_width, fb_height,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   647
		      fb_width_mm, fb_height_mm);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   648
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   649
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   650
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   651
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   652
revert (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   653
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   654
    int	c;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   655
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   656
    /* first disable all crtcs */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   657
    for (c = 0; c < res->ncrtc; c++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   658
	crtc_disable (&crtcs[c]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   659
    /* next reset screen size */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   660
    screen_revert ();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   661
    /* now restore all crtcs */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   662
    for (c = 0; c < res->ncrtc; c++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   663
	crtc_revert (&crtcs[c]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   664
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   665
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   666
/*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   667
 * uh-oh, something bad happened in the middle of changing
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   668
 * the configuration. Revert to the previous configuration
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   669
 * and bail
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   670
 */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   671
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   672
panic (Status s, crtc_t *crtc)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   673
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   674
    int	    c = crtc->crtc.index;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   675
    char    *message;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   676
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   677
    switch (s) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   678
    case RRSetConfigSuccess:		message = "succeeded";		    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   679
    case BadAlloc:			message = "out of memory";	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   680
    case RRSetConfigFailed:		message = "failed";		    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   681
    case RRSetConfigInvalidConfigTime:	message = "invalid config time";    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   682
    case RRSetConfigInvalidTime:	message = "invalid time";	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   683
    default:				message = "unknown failure";	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   684
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   685
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   686
    fprintf (stderr, "%s: Configure crtc %d %s\n", program_name, c, message);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   687
    revert ();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   688
    exit (1);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   689
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   690
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   691
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   692
apply (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   693
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   694
    Status  s;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   695
    int	    c;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   696
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   697
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   698
     * Turn off any crtcs which are to be disabled or which are
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   699
     * larger than the target size
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   700
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   701
    for (c = 0; c < res->ncrtc; c++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   702
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   703
	crtc_t	    *crtc = &crtcs[c];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   704
	XRRCrtcInfo *crtc_info = crtc->crtc_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   705
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   706
	/*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   707
	 * if this crtc is already disabled, skip it 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   708
	 * Note server sets crtc_info->mode (before change)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   709
	 */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   710
	if (crtc_info->mode == None) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   711
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   712
	
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   713
	/* 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   714
	 * If this crtc is to be left enabled, make
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   715
	 * sure the old size fits then new screen
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   716
	 * When crtc->mode_info is null, the crtc is to be
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   717
	 * disabled. Note set_crtcs () sets crtc->mode_info for
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   718
	 * new mode (to be changed to).
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   719
	 */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   720
	if (crtc->mode_info) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   721
	{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   722
	    XRRModeInfo	*old_mode = find_mode_by_xid (crtc_info->mode);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   723
	    int x, y, w, h;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   724
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   725
	    if (!old_mode) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   726
		panic (RRSetConfigFailed, crtc);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   727
	    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   728
	    /* old position and size information */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   729
	    x = crtc_info->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   730
	    y = crtc_info->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   731
	    w = mode_width (old_mode, crtc_info->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   732
	    h = mode_height (old_mode, crtc_info->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   733
	    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   734
	    /* if it fits, skip it */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   735
	    if (x + w <= fb_width && y + h <= fb_height) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   736
		continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   737
	}
1323
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
   738
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
   739
	if (need_off_deferred)
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
   740
	    /* Defer taking off */
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
   741
	    continue;
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
   742
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   743
	s = crtc_disable (crtc);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   744
	if (s != RRSetConfigSuccess)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   745
	    panic (s, crtc);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   746
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   747
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   748
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   749
     * Hold the server grabbed while messing with
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   750
     * the screen so that apps which notice the resize
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   751
     * event and ask for xinerama information from the server
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   752
     * receive up-to-date information
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   753
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   754
    XGrabServer (dpy);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   755
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   756
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   757
     * Set the screen size
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   758
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   759
    screen_apply ();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   760
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   761
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   762
     * Set crtcs
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   763
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   764
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   765
    for (c = 0; c < res->ncrtc; c++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   766
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   767
	crtc_t	*crtc = &crtcs[c];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   768
	
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   769
	s = crtc_apply (crtc);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   770
	if (s != RRSetConfigSuccess)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   771
	    panic (s, crtc);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   772
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   773
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   774
     * Release the server grab and let all clients
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   775
     * respond to the updated state
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   776
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   777
    XUngrabServer (dpy);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   778
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   779
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   780
/*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   781
 * Use current output state to complete the output list
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   782
 */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   783
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   784
get_outputs (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   785
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   786
    int		o;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   787
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   788
    for (o = 0; o < res->noutput; o++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   789
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   790
	XRROutputInfo	*output_info = XRRGetOutputInfo (dpy, res, res->outputs[o]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   791
	output_t	*output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   792
	name_t		output_name;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   793
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   794
	if (!output_info) fatal ("could not get output 0x%x information", res->outputs[o]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   795
	set_name_xid (&output_name, res->outputs[o]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   796
	set_name_index (&output_name, o);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   797
	set_name_string (&output_name, output_info->name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   798
	output = find_output (&output_name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   799
	if (!output)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   800
	{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   801
	    output = add_output ();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   802
	    set_name_all (&output->output, &output_name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   803
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   804
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   805
	set_output_info (output, res->outputs[o], output_info);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   806
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   807
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   808
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   809
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   810
/*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   811
 * Test whether 'crtc' can be used for 'output'
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   812
 */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   813
static Bool
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   814
check_crtc_for_output (crtc_t *crtc, output_t *output)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   815
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   816
    int		i;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   817
    int		l;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   818
    output_t    *other;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   819
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   820
    for (i = 0; i < ncon; i++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   821
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   822
	other = con_outputs[i].output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   823
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   824
	if (other == output)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   825
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   826
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   827
	if (other->mode_info == NULL)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   828
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   829
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   830
	if (other->crtc_info != crtc)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   831
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   832
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   833
	/* see if the output connected to the crtc can clone to this output */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   834
	for (l = 0; l < output->output_info->nclone; l++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   835
	    if (output->output_info->clones[l] == other->output.xid)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   836
		break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   837
	/* not on the list, can't clone */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   838
	if (l == output->output_info->nclone) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   839
	    return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   840
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   841
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   842
    if (crtc->noutput)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   843
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   844
	for (i = 0; i < crtc->noutput; i++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   845
	    /* Check if the output is to be turned on */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   846
	    if (crtc->outputs[i]->mode_info) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   847
		/* make sure the state matches */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   848
		if (crtc->mode_info != output->mode_info)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   849
	    	    return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   850
		if (crtc->x != output->x)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   851
	    	    return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   852
		if (crtc->y != output->y)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   853
	    	    return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   854
		if (crtc->rotation != output->rotation)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   855
	    	    return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   856
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   857
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   858
    return True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   859
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   860
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   861
static crtc_t *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   862
find_crtc_for_output (output_t *output)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   863
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   864
    int	    c;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   865
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   866
    for (c = 0; c < output->output_info->ncrtc; c++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   867
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   868
	crtc_t	    *crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   869
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   870
	crtc = find_crtc_by_xid (output->output_info->crtcs[c]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   871
	if (!crtc) fatal ("cannot find crtc 0x%x\n", output->output_info->crtcs[c]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   872
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   873
	if (check_crtc_for_output (crtc, output))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   874
	    return crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   875
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   876
    return NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   877
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   878
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   879
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   880
set_positions (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   881
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   882
    Bool	keep_going;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   883
    Bool	any_set;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   884
    int		min_x, min_y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   885
    int		i;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   886
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   887
    for (;;)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   888
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   889
	any_set = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   890
	keep_going = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   891
	for (i = 0; i < ncon; i++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   892
	{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   893
	    output_t    *output = con_outputs[i].output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   894
	    output_t    *relation;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   895
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   896
	    if (!(output->changes & changes_relation)) continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   897
	    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   898
	    if (output->mode_info == NULL) continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   899
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   900
	    relation = output->relative_to;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   901
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   902
	    if (relation->mode_info == NULL) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   903
	    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   904
		output->x = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   905
		output->y = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   906
		output->changes |= changes_position;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   907
		any_set = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   908
		continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   909
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   910
	    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   911
	     * Make sure the dependent object has been set in place
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   912
	     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   913
	    if ((relation->changes & changes_relation) && 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   914
		!(relation->changes & changes_position))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   915
	    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   916
		keep_going = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   917
		continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   918
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   919
	   
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   920
	    switch (output->relation) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   921
	    case left_of:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   922
		output->y = relation->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   923
		output->x = relation->x - mode_width (output->mode_info, output->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   924
		break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   925
	    case right_of:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   926
		output->y = relation->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   927
		output->x = relation->x + mode_width (relation->mode_info, relation->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   928
		break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   929
	    case above:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   930
		output->x = relation->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   931
		output->y = relation->y - mode_height (output->mode_info, output->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   932
		break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   933
	    case below:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   934
		output->x = relation->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   935
		output->y = relation->y + mode_height (relation->mode_info, relation->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   936
		break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   937
	    case same_as:
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   938
		output->x = relation->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   939
		output->y = relation->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   940
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   941
	    output->changes |= changes_position;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   942
	    relation->changes |= changes_position;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   943
	    any_set = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   944
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   945
	if (!keep_going)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   946
	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   947
	if (!any_set)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   948
	    fatal ("loop in relative position specifications\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   949
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   950
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   951
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   952
     * Now normalize positions so the upper left corner of all outputs is at 0,0
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   953
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   954
    min_x = 32768;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   955
    min_y = 32768;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   956
    for (i = 0; i < ncon; i++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   957
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   958
	output_t    *output = con_outputs[i].output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   959
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   960
	if (output->mode_info == NULL) continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   961
	
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   962
	if (output->x < min_x) min_x = output->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   963
	if (output->y < min_y) min_y = output->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   964
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   965
    if (min_x || min_y)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   966
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   967
	/* move all outputs */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   968
	for (i = 0; i < ncon; i++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   969
	{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   970
	    output_t    *output = con_outputs[i].output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   971
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   972
	    if (output->mode_info == NULL) continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   973
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   974
	    output->x -= min_x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   975
	    output->y -= min_y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   976
	    output->changes |= changes_position;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   977
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   978
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   979
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   980
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   981
static Bool
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   982
set_screen_size (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   983
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   984
    int	i;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   985
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   986
    fb_width = fb_height = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   987
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   988
    for (i = 0; i < ncon; i++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   989
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   990
    	output_t	*output = con_outputs[i].output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   991
	XRRModeInfo *mode_info = output->mode_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   992
	int	    x, y, w, h;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   993
	
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   994
	if (!mode_info) continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   995
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   996
	x = output->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   997
	y = output->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   998
	w = mode_width (mode_info, output->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
   999
	h = mode_height (mode_info, output->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1000
	if (x + w > fb_width) fb_width = x + w;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1001
	if (y + h > fb_height) fb_height = y + h;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1002
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1003
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1004
    if (fb_width > maxWidth || fb_height > maxHeight) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1005
	if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1006
            fprintf (stderr, "screen cannot be larger than %dx%d (desired size %dx%d)\n",
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1007
	       maxWidth, maxHeight, fb_width, fb_height);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1008
	return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1009
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1010
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1011
    if (fb_width < minWidth) fb_width = minWidth;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1012
    if (fb_height < minHeight) fb_height = minHeight;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1013
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1014
    return True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1015
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1016
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1017
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1018
disable_outputs (output_t *outputs)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1019
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1020
    while (outputs)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1021
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1022
	outputs->crtc_info = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1023
	outputs = outputs->next;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1024
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1025
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1026
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1027
/*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1028
 * find the best mapping from output to crtc available
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1029
 */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1030
static int
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1031
pick_crtcs_score (output_t *outputs)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1032
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1033
    output_t	*output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1034
    int		best_score;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1035
    int		my_score;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1036
    int		score;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1037
    crtc_t	*best_crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1038
    int		c;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1039
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1040
    if (!outputs)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1041
	return 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1042
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1043
    output = outputs;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1044
    outputs = outputs->next;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1045
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1046
     * Score with this output disabled
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1047
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1048
    output->crtc_info = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1049
    best_score = pick_crtcs_score (outputs);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1050
    if (output->mode_info == NULL)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1051
	return best_score;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1052
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1053
    best_crtc = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1054
    /* 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1055
     * Now score with this output any valid crtc
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1056
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1057
    for (c = 0; c < output->output_info->ncrtc; c++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1058
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1059
	crtc_t	    *crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1060
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1061
	crtc = find_crtc_by_xid (output->output_info->crtcs[c]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1062
	if (!crtc)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1063
	    fatal ("cannot find crtc 0x%x\n", output->output_info->crtcs[c]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1064
	
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1065
	/* reset crtc allocation for following outputs */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1066
	disable_outputs (outputs);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1067
	if (!check_crtc_for_output (crtc, output))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1068
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1069
	
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1070
	my_score = 1000;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1071
	/* slight preference for existing connections */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1072
	if (crtc == output->current_crtc_info)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1073
	    my_score++;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1074
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1075
	output->crtc_info = crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1076
	score = my_score + pick_crtcs_score (outputs);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1077
	if (score > best_score)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1078
	{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1079
	    best_crtc = crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1080
	    best_score = score;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1081
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1082
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1083
    if (output->crtc_info != best_crtc)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1084
	output->crtc_info = best_crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1085
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1086
     * Reset other outputs based on this one using the best crtc
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1087
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1088
    (void) pick_crtcs_score (outputs);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1089
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1090
    return best_score;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1091
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1092
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1093
/*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1094
 * Pick crtcs for any changing outputs that don't have one
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1095
 */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1096
static Bool
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1097
pick_crtcs (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1098
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1099
    output_t	*output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1100
    int i;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1101
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1102
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1103
     * First try to match up newly enabled outputs with spare crtcs
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1104
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1105
    for (i = 0; i < ncon; i++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1106
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1107
	output = con_outputs[i].output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1108
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1109
	if (output->mode_info)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1110
	{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1111
	    if (output->crtc_info)  {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1112
		if (output->crtc_info->crtc_info->noutput > 0 &&
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1113
		    (output->crtc_info->crtc_info->noutput > 1 ||
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1114
		     output != find_output_by_xid (output->crtc_info->crtc_info->outputs[0])))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1115
		    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1116
	    } else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1117
		output->crtc_info = find_crtc_for_output (output);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1118
		if (!output->crtc_info)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1119
		    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1120
		else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1121
		    if (verbose)
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1122
			fprintf(stderr, "picked crtc 0x%lx for output %d (%s)\n",
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1123
			    output->crtc_info->crtc.xid, i, output->output_info->name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1124
		}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1125
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1126
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1127
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1128
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1129
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1130
     * Everyone is happy
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1131
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1132
    if (i == ncon)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1133
	return True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1134
    /*
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1135
     * When the simple way fails, see if there is a way
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1136
     * to swap crtcs around and make things work
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1137
     */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1138
    for (output = outputs; output; output = output->next)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1139
	output->current_crtc_info = output->crtc_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1140
    pick_crtcs_score (outputs);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1141
    for (output = outputs; output; output = output->next)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1142
    {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1143
	if (output->mode_info && !output->crtc_info) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1144
	    if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1145
		fprintf (stderr, "cannot find crtc for output %s\n", 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1146
		    output->output.string);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1147
	    return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1148
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1149
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1150
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1151
    return True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1152
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1153
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1154
static Bool 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1155
probe_and_check_output_changes (void) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1156
    XRRScreenResources  *new_res = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1157
    int	 changed = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1158
    int  i;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1159
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1160
    new_res = XRRGetScreenResources (dpy, root);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1161
    if (!new_res)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1162
        fatal ("could not get screen resources");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1163
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1164
    if ((new_res->noutput != res->noutput) || (new_res->nmode != res->nmode) ||
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1165
	(new_res->ncrtc != res->ncrtc))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1166
	changed = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1167
    else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1168
	for (i = 0; i < new_res->noutput; i++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1169
	    if (new_res->outputs[i] != res->outputs[i]) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1170
		changed = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1171
		break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1172
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1173
	for (i = 0; i < new_res->nmode; i++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1174
	    if (new_res->modes[i].id != res->modes[i].id) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1175
		changed = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1176
		break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1177
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1178
	for (i = 0; i < new_res->ncrtc; i++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1179
	    crtc_t  *crtc = NULL;		/* old */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1180
	    XRRCrtcInfo *crtc_info = NULL;	/* new */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1181
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1182
	    crtc = find_crtc_by_xid (res->crtcs[i]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1183
	    crtc_info = XRRGetCrtcInfo (dpy, new_res, 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1184
		new_res->crtcs[i]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1185
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1186
	    if (!crtc || !crtc_info) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1187
	    	changed = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1188
	    	break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1189
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1190
	    if (!crtc->mode_info && !find_mode_by_xid (crtc_info->mode))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1191
		continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1192
    	    if ((crtc_info->x != crtc->x) || 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1193
	    	(crtc_info->y != crtc->y) ||
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1194
 	    	(find_mode_by_xid (crtc_info->mode) != crtc->mode_info) ||
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1195
	    	(crtc_info->rotation != crtc->rotation)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1196
	    	changed = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1197
	    	break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1198
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1199
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1200
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1201
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1202
    if (changed) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1203
	if (res)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1204
	    XRRFreeScreenResources(res);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1205
	res = new_res;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1206
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1207
	if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1208
	    fprintf(stderr, "probed: output status changed\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1209
	return True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1210
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1211
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1212
    if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1213
	fprintf(stderr, "probed: no output status change\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1214
    return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1215
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1216
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1217
static Bool 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1218
need_probe (void) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1219
    struct timeval	cur_time_val;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1220
    long long	cur, prev;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1221
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1222
    X_GETTIMEOFDAY(&cur_time_val);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1223
    cur = (long long) cur_time_val.tv_sec * 1000000 + cur_time_val.tv_usec;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1224
    prev =(long long) time_val.tv_sec * 1000000 + time_val.tv_usec;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1225
    if (((cur - prev) < 0) || ((cur - prev) > 5000000))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1226
	return True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1227
    else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1228
	return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1229
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1230
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1231
static int
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1232
mode_sort (const void *p1, void *p2)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1233
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1234
    XRRModeInfo *mi1 = * (XRRModeInfo **) p1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1235
    XRRModeInfo *mi2 = * (XRRModeInfo **) p2;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1236
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1237
    if ((mi1->width == mi2->width) && (mi1->height == mi2->height)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1238
	if (mode_refresh(mi1) && mode_refresh(mi2)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1239
	    if (mode_refresh(mi1) < mode_refresh(mi2))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1240
		return 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1241
	    if (mode_refresh(mi1) > mode_refresh(mi2))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1242
		return -1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1243
	} else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1244
            return 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1245
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1246
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1247
    if ((mi1->width == mi2->width) && (mi1->height < mi2->height))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1248
        return 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1249
    if ((mi1->width == mi2->width) && (mi1->height > mi2->height))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1250
        return -1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1251
    if (mi1->width < mi2->width)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1252
        return 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1253
    if (mi1->width > mi2->width)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1254
        return -1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1255
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1256
    return 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1257
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1258
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1259
static int
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1260
output_sort (const void *p1, const void *p2) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1261
    con_output_t co1 = * (con_output_t *) p1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1262
    con_output_t co2 = * (con_output_t *) p2;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1263
    int ncrtc1 = co1.output->output_info->ncrtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1264
    int ncrtc2 = co2.output->output_info->ncrtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1265
    char *name1 = co1.output->output_info->name;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1266
    char *name2 = co2.output->output_info->name;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1267
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1268
    if (ncrtc1 == ncrtc2)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1269
	return (strcmp(name1, name2));
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1270
    if (ncrtc1 <  ncrtc2)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1271
	return -1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1272
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1273
    return 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1274
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1275
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1276
static Bool 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1277
get_common_mode(con_output_t *c0, con_output_t *c1, int *m0, int *m1) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1278
    int		i, j;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1279
    int		i1 = -1, j1 = -1, i2 = -1, j2 = -1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1280
    int		x, y, w, h;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1281
    output_t    *output = c0->output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1282
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1283
    *m0 = -1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1284
    *m0 = -1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1285
    if (!c0 ||!c1 || !c0->smodes || !c1->smodes)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1286
	return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1287
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1288
    /* first try to find mode with common same size */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1289
    for (i = 0; i < c0->nsmodes; i ++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1290
	for (j = 0; j < c1->nsmodes; j ++) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1291
	    if ((c0->smodes[i]->width == c1->smodes[j]->width) && 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1292
		(c0->smodes[i]->height == c1->smodes[j]->height)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1293
		x = output->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1294
		y = output->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1295
		w = mode_width (c0->smodes[i], output->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1296
		h = mode_height (c0->smodes[i], output->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1297
		if ((x + w <=  maxWidth) && (y + h <= maxHeight)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1298
		    i1 = i; j1 = j;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1299
		    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1300
		}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1301
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1302
	if ((i1 != -1) && (j1 != -1))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1303
	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1304
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1305
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1306
    if ((i1 == -1) && (j1 == -1))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1307
	return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1308
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1309
    /* then try to find mode with common id for possible cloning */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1310
    for (i = 0; i < c0->nsmodes; i ++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1311
	for (j = 0; j < c1->nsmodes; j ++) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1312
	    if (c0->smodes[i] == c1->smodes[j]) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1313
		x = output->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1314
		y = output->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1315
		w = mode_width (c0->smodes[i], output->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1316
		h = mode_height (c0->smodes[i], output->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1317
		if ((x + w <=  maxWidth) && (y + h <= maxHeight)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1318
		    i2 = i; j2 = j;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1319
		    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1320
		}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1321
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1322
	if ((i2 != -1) && (j2 != -1))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1323
	    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1324
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1325
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1326
    if ((i2 == -1) && (j2 == -1)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1327
	*m0 = i1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1328
	*m1 = j1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1329
    } else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1330
	/* use common id if it is not smaller */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1331
	if ((mode_width (c0->smodes[i1], output->rotation) >
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1332
	    mode_width (c0->smodes[i2], output->rotation)) &&
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1333
	    (mode_height (c0->smodes[i1], output->rotation) >
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1334
	    mode_height (c0->smodes[i2], output->rotation))) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1335
	    *m0 = i1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1336
	    *m1 = j1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1337
	} else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1338
	    *m0 = i2;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1339
	    *m1 = j2;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1340
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1341
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1342
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1343
    return True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1344
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1345
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1346
static XRRModeInfo *
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1347
get_largest_mode (con_output_t *c, XRRModeInfo *start_mode) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1348
    int		i, found = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1349
    output_t	*output = c->output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1350
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1351
    for (i = 0; i < c->nsmodes; i++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1352
	XRRModeInfo *mode_info = c->smodes[i];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1353
	int 	x, y, w, h;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1354
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1355
	if (!found && (start_mode != mode_info)) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1356
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1357
	else 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1358
	    found = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1359
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1360
	if (mode_info) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1361
	    x = output->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1362
            y = output->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1363
            w = mode_width (mode_info, output->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1364
            h = mode_height (mode_info, output->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1365
	    if ((x + w <=  maxWidth) && (y + h <= maxHeight))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1366
		break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1367
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1368
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1369
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1370
    if (i < c->nsmodes)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1371
	return c->smodes[i];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1372
    else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1373
	fatal("cannot find mode");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1374
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1375
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1376
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1377
static Bool
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1378
valid_mode(con_output_t *con, XRRModeInfo *mode) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1379
    int i;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1380
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1381
    for (i = 0; i < con->nsmodes; i++)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1382
	if (con->smodes[i] == mode)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1383
	    return True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1384
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1385
    return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1386
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1387
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1388
static void
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1389
do_init (void) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1390
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1391
    int     	i, j;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1392
    output_t    *output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1393
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1394
    /* Initialize con_outputs array */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1395
    for (i = 0; i < MAX_OUTPUT; i++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1396
	con_outputs[i].output = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1397
	con_outputs[i].on = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1398
	start_mode[i] = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1399
	new_mode[i] = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1400
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1401
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1402
    ncon = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1403
    dis_ncon = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1404
    init_rotation = RR_Rotate_0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1405
    init_x = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1406
    init_y = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1407
    get_crtcs ();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1408
    get_outputs ();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1409
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1410
    for (output = outputs; output; output = output->next) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1411
	XRROutputInfo   *output_info = output->output_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1412
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1413
	if (output_info->connection == RR_Connected) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1414
	    con_outputs[ncon].output = output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1415
	    con_outputs[ncon].nsmodes = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1416
	    for (j = 0; j < output_info->nmode; j++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1417
		XRRModeInfo *rmode = find_mode_by_xid (output_info->modes[j]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1418
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1419
	 	con_outputs[ncon].smodes =
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1420
		    realloc(con_outputs[ncon].smodes, 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1421
		    (con_outputs[ncon].nsmodes + 1) * sizeof (XRRModeInfo *));
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1422
		con_outputs[ncon].smodes[j] = rmode;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1423
		con_outputs[ncon].nsmodes ++;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1424
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1425
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1426
	    /* Sort the modes */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1427
            qsort((void *) con_outputs[ncon].smodes, 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1428
		con_outputs[ncon].nsmodes, sizeof(XRRModeInfo *),
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1429
		(int (*) (const void *, const void *)) mode_sort);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1430
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1431
	    if (output_info->crtc) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1432
		crtc_t      *crtc;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1433
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1434
		con_outputs[ncon].on = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1435
		for (j = 0; j < output_info->ncrtc; j++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1436
		    if (output_info->crtcs[j] == output_info->crtc)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1437
                            break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1438
                    if (j == output_info->ncrtc) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1439
			if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1440
                            fatal ("crtc does not match for output\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1441
                    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1442
		}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1443
		/* set initial mode_info */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1444
		crtc = find_crtc_by_xid (output_info->crtc);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1445
		if (crtc)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1446
		    con_outputs[ncon].output->mode_info = 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1447
			find_mode_by_xid (crtc->crtc_info->mode);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1448
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1449
	    else 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1450
		con_outputs[ncon].on = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1451
	    ncon ++;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1452
	} else if (output_info->connection == RR_Disconnected) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1453
	    dis_con_outputs[dis_ncon].output = output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1454
	    dis_ncon ++;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1455
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1456
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1457
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1458
    qsort((void **) con_outputs, ncon,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1459
	sizeof(con_output_t), (int (*) (const void *, const void *)) output_sort);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1460
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1461
    if (verbose) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1462
	fprintf(stderr, "Total connected outputs = %d :\n", ncon);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1463
	for (j = 0; j < ncon; j++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1464
	    fprintf(stderr, "%d (%s): top mode = %s, rotation = %d, crtcs =", j,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1465
		con_outputs[j].output->output_info->name, 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1466
		con_outputs[j].smodes[0]->name,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1467
		con_outputs[j].output->rotation); 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1468
	    for (i = 0; i < con_outputs[j].output->output_info->ncrtc; i++)
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1469
		fprintf(stderr, " 0x%lx", con_outputs[j].output->output_info->crtcs[i]);
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1470
	    fprintf(stderr, ", using 0x%lx", con_outputs[j].output->output_info->crtc);
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1471
	    fprintf(stderr, "\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1472
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1473
	fprintf(stderr, "Total disconnected outputs = %d :\n", dis_ncon);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1474
	for (j = 0; j < dis_ncon; j++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1475
	    fprintf(stderr, "%d (%s) : number of crtcs %d =", j, 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1476
		dis_con_outputs[j].output->output_info->name, 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1477
		dis_con_outputs[j].output->output_info->ncrtc);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1478
	    for (i = 0; i < dis_con_outputs[j].output->output_info->ncrtc; i++)
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1479
		fprintf(stderr, " 0x%lx", dis_con_outputs[j].output->output_info->crtcs[i]);
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1480
	    fprintf(stderr, ", using 0x%lx", dis_con_outputs[j].output->output_info->crtc);
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1481
	    fprintf(stderr, "\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1482
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1483
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1484
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1485
    i = con_outputs[2].on * 4 + con_outputs[1].on * 2 + con_outputs[0].on;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1486
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1487
    if ((i == 1) || (i == 2) || (i == 4)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1488
	use_init_pos = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1489
	j = i >> 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1490
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1491
	/* remember position and mode info in single state */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1492
    	start_mode[j] = con_outputs[j].output->mode_info;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1493
	init_rotation = con_outputs[j].output->rotation;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1494
	init_x = con_outputs[j].output->x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1495
	init_y = con_outputs[j].output->y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1496
    } else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1497
	use_init_pos = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1498
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1499
    if ((ncon != 2) || (start < 3))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1500
	start = i;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1501
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1502
    if ((ncon < 1) || (ncon > 3)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1503
	if ((ncon < 1) && verbose)
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1504
	    fprintf (stderr, "warn: no connection\n");
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1505
	else if ((ncon > 3) && verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1506
	    fprintf (stderr, "warn: too many (more than 3) connections: %d: can't switch\n", ncon);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1507
	do_not_switch = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1508
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1509
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1510
    did_init = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1511
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1512
    return;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1513
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1514
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1515
static int 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1516
grab_key (Display *dpy, int keysym, unsigned int modifier, 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1517
    Window grab_window)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1518
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1519
    char    msg[256];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1520
    int keycode = XKeysymToKeycode(dpy, keysym);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1521
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1522
    if (keycode ==  NoSymbol)
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1523
	fatal ("grab_key: keycode not defined for keysym 0x%x\n", keysym);
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1524
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1525
    had_error = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1526
    prev_handler = XSetErrorHandler (cur_handler);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1527
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1528
    if (!testrun) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1529
    	XGrabKey(dpy, 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1530
	    keycode,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1531
	    modifier,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1532
	    root, True, GrabModeAsync, GrabModeAsync);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1533
    	XSync (dpy, False);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1534
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1535
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1536
    XSetErrorHandler (prev_handler);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1537
    if (had_error) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1538
	XGetErrorText (dpy, had_error, msg, sizeof (msg));
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1539
	fatal ("XGrabKey: %s\n", msg);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1540
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1541
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1542
    if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1543
	fprintf(stderr, "keycode to grab: %d\n", keycode);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1544
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1545
    return keycode;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1546
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1547
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1548
static Bool
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1549
do_switch (void)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1550
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1551
    int 	i, j;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1552
    int		single;
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1553
    int		save = -1;
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1554
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1555
    if (ncon <= 0)
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1556
	return True; 
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1557
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1558
    for (i = 0; i < ncon; i++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1559
	output_t	*output = con_outputs[i].output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1560
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1561
	new_mode[i] = NULL;
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1562
	output->relation = same_as;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1563
	output->relative_to = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1564
	if (use_init_pos) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1565
	    output->x = init_x;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1566
	    output->y = init_y;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1567
	    output->rotation = init_rotation;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1568
	} else { 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1569
	    output->x = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1570
	    output->y = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1571
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1572
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1573
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1574
    if (ncon == 2) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1575
	if (!nosideview) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1576
	    if (++start > 5)    start = 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1577
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1578
	else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1579
	    if (++start > 3)    start = 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1580
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1581
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1582
	if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1583
	    fprintf(stderr, "current state = %d\n", start);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1584
	if (start >= 3) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1585
	    int m0, m1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1586
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1587
    	    if (get_common_mode(&con_outputs[0], &con_outputs[1], &m0, &m1)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1588
		new_mode[0] = con_outputs[0].smodes[m0];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1589
                new_mode[1] = con_outputs[1].smodes[m1];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1590
	    } else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1591
		new_mode[0] = get_largest_mode (&con_outputs[0],
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1592
			con_outputs[0].smodes[0]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1593
		new_mode[1] = get_largest_mode (&con_outputs[1],
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1594
			con_outputs[1].smodes[0]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1595
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1596
	} else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1597
	    if (start_mode[start -1] && valid_mode(&con_outputs[start -1], 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1598
		start_mode[start -1]))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1599
		    new_mode[start -1] = start_mode[start -1]; 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1600
	    else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1601
	        if (con_outputs[start -1].smodes[0])
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1602
		    new_mode[start -1] = 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1603
			get_largest_mode (&con_outputs[start-1],
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1604
			con_outputs[start -1].smodes[0]); 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1605
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1606
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1607
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1608
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1609
    if (ncon == 3) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1610
	if (++start > 6)	start = 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1611
	if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1612
	    fprintf(stderr, "current state = %d\n", start);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1613
	if ((start == 1) || (start == 2) || (start == 4)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1614
	    single = 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1615
	    i = start >> 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1616
	    j = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1617
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1618
	else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1619
	    single = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1620
	    if (start > 4)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1621
		j = 2;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1622
	    else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1623
		j = 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1624
	    if (start > 5)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1625
		i = 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1626
	    else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1627
		i = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1628
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1629
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1630
	if (single) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1631
	    if (start_mode[i] && valid_mode(&con_outputs[i], start_mode[i]))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1632
		new_mode[i] = start_mode[i];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1633
	    else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1634
	        if (con_outputs[i].smodes[0])
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1635
		    new_mode[i] = get_largest_mode (&con_outputs[i], 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1636
			con_outputs[i].smodes[0]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1637
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1638
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1639
	else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1640
	    int m0, m1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1641
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1642
    	    if (get_common_mode(&con_outputs[i], &con_outputs[j], &m0, &m1)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1643
		new_mode[i] = con_outputs[i].smodes[m0];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1644
		new_mode[j] = con_outputs[j].smodes[m1];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1645
    	    } else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1646
		new_mode[i] = get_largest_mode (&con_outputs[i], 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1647
		    con_outputs[i].smodes[0]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1648
		new_mode[j] = get_largest_mode (&con_outputs[j],
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1649
		    con_outputs[j].smodes[0]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1650
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1651
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1652
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1653
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1654
    if (ncon == 1) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1655
	if (start_mode[0] && valid_mode(&con_outputs[0], start_mode[0]))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1656
	    new_mode[0] = start_mode[0]; 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1657
	else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1658
	    if (con_outputs[0].smodes[0])
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1659
		new_mode[0] = get_largest_mode (&con_outputs[0],
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1660
		    con_outputs[0].smodes[0]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1661
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1662
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1663
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1664
    /* Set mode */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1665
    for (i = 0; i < ncon; i++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1666
    	output_t	*output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1667
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1668
    	output = con_outputs[i].output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1669
	if (new_mode[i]) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1670
	    if ((!output->mode_info) || (output->mode_info != new_mode[i])) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1671
    		output->mode_info = new_mode[i];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1672
	        con_outputs[i].on = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1673
		if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1674
		    fprintf(stderr, "set output %d (%s) to mode %s rotation %d\n", i, 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1675
			con_outputs[i].output->output_info->name, 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1676
			con_outputs[i].output->mode_info->name,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1677
			con_outputs[i].output->rotation);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1678
    	    } 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1679
	} else if (con_outputs[i].on ) {
1323
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1680
	    if (!need_off_deferred) {
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1681
		output->mode_info = NULL;
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1682
		con_outputs[i].on = False;
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1683
		if (verbose)
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1684
		    fprintf(stderr, "turn off output %d (%s) \n", 
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1685
			i, con_outputs[i].output->output_info->name);
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1686
	    } else
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1687
		save = i;
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1688
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1689
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1690
  
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1691
    if ((ncon == 2) && (start >= 4)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1692
	if (start == 4) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1693
	    con_outputs[1].output->relative_to = con_outputs[0].output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1694
	    con_outputs[1].output->relation = right_of;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1695
	    con_outputs[1].output->changes = changes_relation;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1696
	    con_outputs[0].output->changes = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1697
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1698
	else if (start == 5) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1699
	    con_outputs[0].output->relative_to = con_outputs[1].output;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1700
	    con_outputs[0].output->relation = right_of;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1701
	    con_outputs[0].output->changes = changes_relation;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1702
	    con_outputs[1].output->changes = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1703
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1704
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1705
	set_positions();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1706
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1707
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1708
    if (!set_screen_size ()) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1709
	return False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1710
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1711
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1712
    /* reset crtcs before allocation */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1713
    reset_crtcs_for_outputs();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1714
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1715
    if (!did_init)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1716
	get_crtcs();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1717
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1718
    if (!pick_crtcs()) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1719
	if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1720
	    fprintf(stderr, "pick_crtcs failed\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1721
	return True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1722
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1723
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1724
    set_crtcs ();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1725
    apply();
1323
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1726
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1727
    if (need_off_deferred && (save != -1)) {
1323
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1728
	/* Now, take the deferred output off */
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1729
	output_t    *output;
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1730
	crtc_t      *crtc;
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1731
	Status      s;
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1732
	
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1733
	output = con_outputs[save].output;
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1734
	output->mode_info = NULL;
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1735
	con_outputs[save].on = False;
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1736
	if (verbose)
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1737
	    fprintf(stderr, "turn off output %d (%s) \n",
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1738
		save, con_outputs[save].output->output_info->name);
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1739
	
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1740
	crtc = output->crtc_info;
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1741
	s = crtc_disable (crtc);
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1742
	if (s != RRSetConfigSuccess)
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1743
	    panic (s, crtc);
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1744
    }
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1745
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1746
    XSync (dpy, False);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1747
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1748
    did_init = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1749
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1750
    return True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1751
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1752
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1753
765
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1754
static Bool 
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1755
do_toggle (void)
765
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1756
{
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1757
    Atom		atom;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1758
    XEvent		xev;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1759
    int			ret;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1760
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1761
    atom = XInternAtom (dpy, "DISPLAYSWITCH_DAEMON", True);
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1762
    if (!atom) {
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1763
	fprintf(stderr, "dispswitch daemon not running\n");
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1764
	return False;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1765
    }
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1766
	
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1767
    win = XGetSelectionOwner (dpy, atom);
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1768
    if (!win) {
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1769
	fprintf(stderr, "dispswitch: No owner of dispswitch daemon is found\n");
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1770
	return False;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1771
    }
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1772
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1773
    bzero (&xev, sizeof (XEvent));
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1774
    xev.xkey.type = KeyPress;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1775
    xev.xkey.send_event = True;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1776
    xev.xkey.display = dpy;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1777
    /* Any keycode */
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1778
    xev.xkey.keycode = 71;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1779
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1780
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1781
    /* 
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1782
     * Send another instance of dispswitch (a daemon) an event to
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1783
     * request a switch
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1784
     */
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1785
    ret = XSendEvent(dpy, win, False, KeyPressMask, &xev);
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1786
    XFlush(dpy);
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1787
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1788
    if (!ret)
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1789
	fprintf(stderr, "dispswitch: XSendEvent error\n");
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1790
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1791
    return (!ret);
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1792
}
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1793
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1794
int
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1795
main (int argc, char **argv) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1796
{
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1797
    char    *display_name = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1798
    int	    major, minor;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1799
    int	    i;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1800
    char    msg[256];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1801
    XEvent  ev;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1802
    unsigned int    modifier = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1803
    Bool    key_given = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1804
    Bool    mod_given = False;
765
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1805
    int	    keysym = 0, toggle = False, listen = False;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1806
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1807
    Atom    atom;
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1808
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1809
    program_name = argv[0];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1810
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1811
    for (i = 1; i < argc; i++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1812
	if (!strcmp ("-display", argv[i]) || !strcmp ("-d", argv[i])) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1813
	    if (++i>=argc) usage ();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1814
	    	display_name = argv[i];
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1815
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1816
        }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1817
	if (!strcmp ("-key", argv[i]) || !strcmp ("-k", argv[i])) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1818
	    if (++i>=argc) usage ();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1819
	    if ((keysym = XStringToKeysym(argv[i])) == NoSymbol) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1820
		fprintf(stderr, "invalid keysym: -key %s\n", argv[i]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1821
		usage();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1822
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1823
	    key_given = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1824
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1825
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1826
	if (!strcmp ("-mod", argv[i]) || !strcmp ("-m", argv[i])) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1827
	    int 	j;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1828
	    char 	*s, *p, *q;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1829
	    int		end = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1830
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1831
	    if (++i>=argc) usage ();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1832
	    s = strdup (argv[i]);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1833
	    if (!s) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1834
		if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1835
		    fprintf(stderr, "modifier failed, will use default modifier\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1836
	 	continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1837
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1838
	    while (*s == ' ') s++;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1839
	    p = s + strlen(s) - 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1840
	    while (*p == ' ') *p-- = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1841
	    q = s;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1842
	    for (; ;) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1843
	    	if (p = strchr(s, '+')) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1844
		    *p = ' ';
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1845
		    while ((p > s) && (*(p-1) == ' ')) p--;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1846
		    *p = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1847
		}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1848
		else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1849
		    end = 1;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1850
	        for (j = 0; j < MAX_MODIFIERS; j++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1851
	     	    if (!strcmp(mod_key_table[j].modname, s)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1852
			modifier |= mod_key_table[j].mod;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1853
			break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1854
		    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1855
		}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1856
	   	if (j == MAX_MODIFIERS) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1857
		    fprintf(stderr, "invalid modifier: -mod %s\n", q);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1858
	 	    usage();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1859
		}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1860
		if (end)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1861
		    break;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1862
		else {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1863
		    s = ++p;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1864
		    while (*s == ' ') s++;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1865
		}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1866
	    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1867
	    mod_given = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1868
	    free (q);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1869
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1870
        }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1871
	if (!strcmp ("-nosideview", argv[i])) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1872
	    nosideview = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1873
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1874
        }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1875
	if (!strcmp ("-verbose", argv[i]) || !strcmp ("-v", argv[i])) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1876
	    verbose = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1877
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1878
        }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1879
	if (!strcmp ("-testrun", argv[i])) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1880
	    testrun = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1881
	    verbose = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1882
	    continue;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1883
        }
765
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1884
	if (!strcmp ("-toggle", argv[i]) || !strcmp ("-t", argv[i])) {
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1885
	    toggle = True;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1886
	    continue;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1887
        }
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1888
	if (!strcmp ("-listen", argv[i]) || !strcmp ("-l", argv[i])) {
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1889
	    listen = True;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1890
	    continue;
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1891
        }
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1892
	usage();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1893
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1894
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1895
    dpy = XOpenDisplay (display_name);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1896
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1897
    if (dpy == NULL) 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1898
	fatal ("can't open display %s\n", XDisplayName(display_name));
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1899
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1900
    screen = DefaultScreen (dpy);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1901
    root = RootWindow (dpy, screen);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1902
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1903
    if (!XRRQueryVersion (dpy, &major, &minor))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1904
	fatal ("randr extension missing\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1905
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1906
    if ((major <= 1) &&  (major != 1 || minor < 2))
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1907
	fatal ("wrong randr version: %d.%d\n", major, minor);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1908
765
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1909
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1910
    if (toggle)
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1911
	exit (do_toggle());
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1912
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1913
    /* 
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1914
     * Create an atom, a trivial window, and make it selection owner. 
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1915
     * Ready to accept a client event request for switch
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1916
     */
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1917
    atom = XInternAtom(dpy, "DISPLAYSWITCH_DAEMON", False);
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1918
    if (!atom) {
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1919
	if (verbose)
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1920
	    fprintf(stderr, "cannot create Atom\n");
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1921
    }
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1922
    else {
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1923
	if (XGetSelectionOwner (dpy, atom)) {
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1924
	    if (verbose)
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1925
		fprintf(stderr, "dispswitch daemon is already running, quit\n");
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1926
	    exit (1);
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1927
	}
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1928
	win = XCreateSimpleWindow(dpy, root, 0, 0, 10, 10, 0, 10, 0);
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1929
	if (!win) {
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1930
	    if (verbose)
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1931
		fprintf(stderr, "cannot create window\n");
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1932
	}
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1933
	else {
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1934
	    XSetSelectionOwner(dpy, atom, win, CurrentTime);
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1935
	    if (XGetSelectionOwner(dpy, atom) != win) {
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1936
		if (verbose)
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1937
		    fprintf(stderr, "set selection owner failed\n");
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1938
	    } else
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1939
		XSelectInput(dpy, win, KeyPressMask);
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1940
	}
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1941
    }
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1942
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1943
    /* set default key and modifier if not given in command */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1944
    if (!key_given)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1945
	keysym  = XStringToKeysym ("F5");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1946
    if (!mod_given)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1947
	modifier = ShiftMask;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1948
765
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1949
    if (!listen)
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1950
	cur_keycode = grab_key (dpy, keysym, modifier, root);
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1951
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1952
    XRRGetScreenSizeRange (dpy, root, &minWidth, &minHeight,
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1953
                           &maxWidth, &maxHeight);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1954
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1955
    fb_width_mm = DisplayWidthMM (dpy, screen);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1956
    fb_height_mm = DisplayHeightMM (dpy, screen);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1957
    dpi = (25.4 * DisplayHeight (dpy, screen)) / DisplayHeightMM(dpy, screen);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1958
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1959
    res = XRRGetScreenResources (dpy, root);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1960
    if (!res)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1961
	fatal ("could not get screen resources\n");
1459
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1962
    if (res->ncrtc < 2)
f624eee89e0b 19477028 Toshiba laptop - external monitor cannot be enabled after booting
henryzh <henry.zhao@oracle.com>
parents: 1323
diff changeset
  1963
	fatal ("too few crtcs: %d\n", res->ncrtc);
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1964
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1965
    do_init();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1966
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1967
    X_GETTIMEOFDAY(&time_val);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1968
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1969
    for(;;)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1970
    {
1323
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1971
	need_off_deferred = False;
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  1972
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1973
	if (testrun) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1974
	    usleep(4000000);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1975
	    fprintf(stderr, "\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1976
	} else
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1977
	    XNextEvent(dpy, &ev);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1978
765
a3c7a0790719 6824603 ACPI hotkey X support
Henry Zhao <Henry.Zhao@Sun.COM>
parents: 649
diff changeset
  1979
	if (!listen && !testrun && (ev.type == MappingNotify) && 
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1980
	    ((ev.xmapping.request == MappingKeyboard) || 
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1981
	    (ev.xmapping.request == MappingModifier))) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1982
	    /* keyboard/modifier mapping changed */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1983
	    if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1984
		fprintf(stderr, "\nkeyboard/modifier mapping changed ...\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1985
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1986
	    XUngrabKey(dpy, cur_keycode, modifier, root);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1987
	    cur_keycode = grab_key (dpy, keysym, modifier, root);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1988
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1989
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1990
	if (testrun || (ev.type == KeyPress)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1991
	    if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1992
		fprintf(stderr, "\na key press event was grabbed ...\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1993
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1994
	    do_not_switch = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1995
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1996
	    if (testrun || need_probe()) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1997
	    /* Too long since last switch, need to check output changes */
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1998
		if (probe_and_check_output_changes ()) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  1999
		    output_t    *output, *next;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2000
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2001
		    output = outputs;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2002
		    while (output) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2003
			if (output->output_info)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2004
			    XRRFreeOutputInfo (output->output_info);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2005
			if (output->crtc_info && output->crtc_info->outputs) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2006
			    free(output->crtc_info->outputs);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2007
			    output->crtc_info->outputs = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2008
			}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2009
			next = output->next;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2010
			free(output);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2011
			output = next;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2012
		    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2013
		    outputs = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2014
		    outputs_tail = &outputs;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2015
		    for (i = 0; i < ncon; i++) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2016
			con_outputs[i].output = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2017
			con_outputs[i].on = False;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2018
			if (con_outputs[i].smodes) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2019
			    free(con_outputs[i].smodes);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2020
			    con_outputs[i].smodes = NULL;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2021
			}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2022
			con_outputs[i].nsmodes = 0;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2023
		    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2024
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2025
		    do_init();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2026
		} else if (ncon == 1)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2027
		    do_not_switch = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2028
	    } else if (ncon == 1)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2029
		do_not_switch = True;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2030
1323
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  2031
    	    if (!do_not_switch) {
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  2032
		if ((ncon == 2) && (start == 1))
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  2033
		    /* 
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  2034
		     * Workaround for intel based graphics: in switching from 
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  2035
		     * LVDS to VGA, off on LVDS needs to be deferred.
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  2036
		     */
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  2037
		    need_off_deferred = True;
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2038
	    	if (!do_switch()) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2039
		    if ((ncon == 2) && (start == 4)) {
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2040
			start = 5;
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2041
			if (verbose)
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2042
			    fprintf(stderr, "too small screen, skipping side view\n");
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2043
			(void) do_switch();
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2044
		    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2045
		}
1323
6a4457d03a89 15813986 SUNBT7196143 dispswitch: Failure switching from LVDS to VGA on intel graphics
henryzh <henry.zhao@oracle.com>
parents: 943
diff changeset
  2046
	    }
649
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2047
    
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2048
	    X_GETTIMEOFDAY(&time_val);
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2049
	}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2050
    }
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2051
}
f86993f8a87b 6809582 dispswitch should be moved to its own source directory
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
diff changeset
  2052