File: xhacks

package info (click to toggle)
hibernate 1.94-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 492 kB
  • ctags: 53
  • sloc: sh: 1,203; makefile: 59
file content (117 lines) | stat: -rw-r--r-- 3,737 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# -*- sh -*-
# vim:ft=sh:ts=8:sw=4:noet

AddConfigHandler XHacksOptions
AddConfigHelp "SwitchToTextMode <boolean>" "If your X driver is unable to resume properly, you can try switching to a text console first by setting this to yes."
AddConfigHelp "UseDummyXServer <boolean>" "Some X drivers can be reinitialised by launching a dummy X server after resuming to restore the state of the graphics card. Set this to yes to do so."
AddConfigHelp "DummyXServerConfig <filename>" "When using a dummy X server, use /etc/X11/<filename> as its configuration."

XHacksSuspend() {
    if [ x"$XHACKS_LEAVE_X" = "x1" ] ; then
	local dest_vt
	if command -v fgconsole > /dev/null 2>&1 ; then
	    XHACKS_ORIGINAL_VT=`fgconsole`
	else
	    XHACKS_ORIGINAL_VT=1
	fi
	[ -z "$SWSUSPVT" ] && dest_vt=15 || dest_vt="$SWSUSPVT"
	vecho 3 "xhacks: changing console from $XHACKS_ORIGINAL_VT to $dest_vt"
	chvt $dest_vt || return 1
    fi
    return 0
}

XHacksResume() {
    if [ x"$XHACKS_NVIDIA" = "x1" ] ; then
	# Launch a dummy X server to reinitialise the graphics card
	PATH=$PATH:/usr/bin/X11:/usr/X11R6/bin
	if ! command -v X > /dev/null 2>&1 ; then
	    vecho 1 "X not in path. Not starting dummy X server."
	else
	    vecho 2 "Launching dummy X server."
	    unset XAUTHORITY   # Make sure we don't clobber the user's .Xauthority
	    if [ -f /etc/X11/$XHACKS_CONFIG ] ; then
	    	XHACKS_CONFIG="-config $XHACKS_CONFIG"
	    else
		XHACKS_CONFIG=""
	    fi
	    xinit /bin/true -- `command -v X` :9 $XHACKS_CONFIG -auth /dev/null -audit 0 -nolisten tcp > /dev/null 2>&1
	fi
    fi

    if [ -n "$XHACKS_ORIGINAL_VT" ] ; then
	vecho 3 "xhacks: changing console back to $XHACKS_ORIGINAL_VT"
	chvt $XHACKS_ORIGINAL_VT
    fi
}

# Hook1's called when using bootsplash and chvt needs to be performed earlier on
XHacksSuspendHook1() {
    if [ x"$USE_BOOTSPLASH" = "x1" ] || [ x"$USE_FBSPLASH" = "x1" ] || \
		[ -n "$SWSUSPVT" ] ; then
	XHACKS_EARLY_SWITCH=1
	XHacksSuspend
    fi
    return 0
}

XHacksResumeHook1() {
    [ -n "$XHACKS_EARLY_SWITCH" ] && XHacksResume
    return 0
}

# Hook2's called when not using bootsplash or redirecting output and chvt can
# wait a while.
XHacksSuspendHook2() {
    [ -z "$XHACKS_EARLY_SWITCH" ] && XHacksSuspend
    return 0
}

XHacksResumeHook2() {
    [ -z "$XHACKS_EARLY_SWITCH" ] && XHacksResume
    return 0
}

XHacksOptions() {
    case $1 in
	leavexbeforesuspend)
	    vecho 0 "The LeaveXBeforeSuspend option is deprecated and may disappear in"
	    vecho 0 "future releases.  Please use SwitchToTextMode instead."
	    BoolIsOn "$1" "$2" && XHACKS_LEAVE_X=1 || return 0
	    # only break from case statement if we need something done
	    ;;
	switchtotextmode)
	    BoolIsOn "$1" "$2" && XHACKS_LEAVE_X=1 || return 0
	    # only break from case statement if we need something done
	    ;;
	nvidiahack)
	    vecho 0 "The NvidiaHack option is deprecated and may disappear in"
	    vecho 0 "future releases.  Please use UseDummyXServer instead."
	    BoolIsOn "$1" "$2" && XHACKS_NVIDIA=1 || return 0
	    # only break from case statement if we need something done
	    ;;
	usedummyxserver)
	    BoolIsOn "$1" "$2" && XHACKS_NVIDIA=1 || return 0
	    # only break from case statement if we need something done
	    ;;
	dummyxserverconfig)
	    shift
	    XHACKS_CONFIG="$@"
	    ;;
	*)
	    return 1
    esac

    if [ -z "$XHACKS_HOOKED" ] ; then
	AddSuspendHook 11 XHacksSuspendHook1
	AddSuspendHook 95 XHacksSuspendHook2
	AddResumeHook 11 XHacksResumeHook1
	AddResumeHook 85 XHacksResumeHook2
	# The switch back has to occur after modules have been loaded in order
	# to allow for anything X might need (eg, psmouse)
	XHACKS_HOOKED=1
    fi
    return 0
}

# $Id: xhacks 1002 2006-06-05 05:41:18Z bernard $