Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xfree86 / os-support / solaris / sun_VTsw.c
CommitLineData
a09e091a
JB
1/*
2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#ifdef HAVE_XORG_CONFIG_H
25#include <xorg-config.h>
26#endif
27
28#include <X11/X.h>
29
30#include "xf86.h"
31#include "xf86Priv.h"
32#include "xf86_OSlib.h"
33
34#include <door.h>
35#include <sys/vtdaemon.h>
36
37/*
38 * Handle the VT-switching interface for Solaris/OpenSolaris
39 */
40
41static int xf86VTPruneDoor = 0;
42
43void
44xf86VTRelease(int sig)
45{
46 if (xf86Info.vtPendingNum == -1) {
47 xf86VTPruneDoor = 1;
48 xf86Info.vtRequestsPending = TRUE;
49 return;
50 }
51
52 ioctl(xf86Info.consoleFd, VT_RELDISP, 1);
53 xf86Info.vtPendingNum = -1;
54
55 return;
56}
57
58void
59xf86VTAcquire(int sig)
60{
61 xf86Info.vtRequestsPending = TRUE;
62 return;
63}
64
65Bool
66xf86VTSwitchPending(void)
67{
68 return xf86Info.vtRequestsPending ? TRUE : FALSE;
69}
70
71Bool
72xf86VTSwitchAway(void)
73{
74 int door_fd;
75 vt_cmd_arg_t vt_door_arg;
76 door_arg_t door_arg;
77
78 xf86Info.vtRequestsPending = FALSE;
79
80 if (xf86VTPruneDoor) {
81 xf86VTPruneDoor = 0;
82 ioctl(xf86Info.consoleFd, VT_RELDISP, 1);
83 return TRUE;
84 }
85
86 vt_door_arg.vt_ev = VT_EV_HOTKEYS;
87 vt_door_arg.vt_num = xf86Info.vtPendingNum;
88 door_arg.data_ptr = (char *) &vt_door_arg;
89 door_arg.data_size = sizeof(vt_cmd_arg_t);
90 door_arg.rbuf = NULL;
91 door_arg.rsize = 0;
92 door_arg.desc_ptr = NULL;
93 door_arg.desc_num = 0;
94
95 if ((door_fd = open(VT_DAEMON_DOOR_FILE, O_RDONLY)) < 0)
96 return FALSE;
97
98 if (door_call(door_fd, &door_arg) != 0) {
99 close(door_fd);
100 return FALSE;
101 }
102
103 close(door_fd);
104 return TRUE;
105}
106
107Bool
108xf86VTSwitchTo(void)
109{
110 xf86Info.vtRequestsPending = FALSE;
111 if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) {
112 return FALSE;
113 }
114 else {
115 return TRUE;
116 }
117}
118
119Bool
120xf86VTActivate(int vtno)
121{
122 struct vt_stat state;
123
124 if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &state) < 0)
125 return FALSE;
126
127 if ((state.v_state & (1 << vtno)) == 0)
128 return FALSE;
129
130 xf86Info.vtRequestsPending = TRUE;
131 xf86Info.vtPendingNum = vtno;
132
133 return TRUE;
134}