2 * Copyright (c) 2000-2002 by The XFree86 Project, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Except as contained in this notice, the name of the copyright holder(s)
23 * and author(s) shall not be used in advertising or otherwise to promote
24 * the sale, use or other dealings in this Software without prior written
25 * authorization from the copyright holder(s) and author(s).
28 #ifdef HAVE_XORG_CONFIG_H
29 #include <xorg-config.h>
35 #include "xf86Xinput.h"
37 int (*xf86PMGetEventFromOs
)(int fd
,pmEvent
*events
,int num
) = NULL
;
38 pmWait (*xf86PMConfirmEventToOs
)(int fd
,pmEvent event
) = NULL
;
40 static Bool suspended
= FALSE
;
43 eventName(pmEvent event
, char **str
)
46 case XF86_APM_SYS_STANDBY
: *str
="System Standby Request"; return 0;
47 case XF86_APM_SYS_SUSPEND
: *str
="System Suspend Request"; return 0;
48 case XF86_APM_CRITICAL_SUSPEND
: *str
="Critical Suspend"; return 0;
49 case XF86_APM_USER_STANDBY
: *str
="User System Standby Request"; return 0;
50 case XF86_APM_USER_SUSPEND
: *str
="User System Suspend Request"; return 0;
51 case XF86_APM_STANDBY_RESUME
: *str
="System Standby Resume"; return 0;
52 case XF86_APM_NORMAL_RESUME
: *str
="Normal Resume System"; return 0;
53 case XF86_APM_CRITICAL_RESUME
: *str
="Critical Resume System"; return 0;
54 case XF86_APM_LOW_BATTERY
: *str
="Battery Low"; return 3;
55 case XF86_APM_POWER_STATUS_CHANGE
: *str
="Power Status Change";return 3;
56 case XF86_APM_UPDATE_TIME
: *str
="Update Time";return 3;
57 case XF86_APM_CAPABILITY_CHANGED
: *str
="Capability Changed"; return 3;
58 case XF86_APM_STANDBY_FAILED
: *str
="Standby Request Failed"; return 0;
59 case XF86_APM_SUSPEND_FAILED
: *str
="Suspend Request Failed"; return 0;
60 default: *str
="Unknown Event"; return 0;
65 suspend (pmEvent event
, Bool undo
)
72 for (i
= 0; i
< xf86NumScreens
; i
++) {
73 xf86EnableAccess(xf86Screens
[i
]);
74 if (xf86Screens
[i
]->EnableDisableFBAccess
)
75 (*xf86Screens
[i
]->EnableDisableFBAccess
) (i
, FALSE
);
77 pInfo
= xf86InputDevs
;
79 DisableDevice(pInfo
->dev
);
82 xf86EnterServerState(SETUP
);
83 for (i
= 0; i
< xf86NumScreens
; i
++) {
84 xf86EnableAccess(xf86Screens
[i
]);
85 if (xf86Screens
[i
]->PMEvent
)
86 xf86Screens
[i
]->PMEvent(i
,event
,undo
);
88 xf86Screens
[i
]->LeaveVT(i
, 0);
89 xf86Screens
[i
]->vtSema
= FALSE
;
93 xf86AccessLeaveState();
97 resume(pmEvent event
, Bool undo
)
103 xf86EnterServerState(SETUP
);
104 for (i
= 0; i
< xf86NumScreens
; i
++) {
105 xf86EnableAccess(xf86Screens
[i
]);
106 if (xf86Screens
[i
]->PMEvent
)
107 xf86Screens
[i
]->PMEvent(i
,event
,undo
);
109 xf86Screens
[i
]->vtSema
= TRUE
;
110 xf86Screens
[i
]->EnterVT(i
, 0);
113 xf86EnterServerState(OPERATING
);
114 for (i
= 0; i
< xf86NumScreens
; i
++) {
115 xf86EnableAccess(xf86Screens
[i
]);
116 if (xf86Screens
[i
]->EnableDisableFBAccess
)
117 (*xf86Screens
[i
]->EnableDisableFBAccess
) (i
, TRUE
);
119 SaveScreens(SCREEN_SAVER_FORCER
, ScreenSaverReset
);
120 pInfo
= xf86InputDevs
;
122 EnableDevice(pInfo
->dev
);
125 xf86inSuspend
= FALSE
;
129 DoApmEvent(pmEvent event
, Bool undo
)
132 * we leave that as a global function for now. I don't know if
133 * this might cause problems in the future. It is a global server
134 * variable therefore it needs to be in a server info structure
140 case XF86_APM_SYS_STANDBY
:
141 case XF86_APM_USER_STANDBY
:
143 case XF86_APM_SYS_SUSPEND
:
144 case XF86_APM_CRITICAL_SUSPEND
: /*do we want to delay a critical suspend?*/
145 case XF86_APM_USER_SUSPEND
:
146 /* should we do this ? */
147 if (!undo
&& !suspended
) {
150 } else if (undo
&& suspended
) {
156 case XF86_APM_STANDBY_RESUME
:
158 case XF86_APM_NORMAL_RESUME
:
159 case XF86_APM_CRITICAL_RESUME
:
166 for (i
= 0; i
< xf86NumScreens
; i
++) {
167 if (xf86Screens
[i
]->PMEvent
) {
168 if (!setup
) xf86EnterServerState(SETUP
);
170 xf86EnableAccess(xf86Screens
[i
]);
171 xf86Screens
[i
]->PMEvent(i
,event
,undo
);
174 if (setup
) xf86EnterServerState(OPERATING
);
179 #define MAX_NO_EVENTS 8
182 xf86HandlePMEvents(int fd
, pointer data
)
184 pmEvent events
[MAX_NO_EVENTS
];
188 if (!xf86PMGetEventFromOs
)
191 if ((n
= xf86PMGetEventFromOs(fd
,events
,MAX_NO_EVENTS
))) {
193 for (i
= 0; i
< n
; i
++) {
195 int verb
= eventName(events
[i
],&str
);
197 xf86MsgVerb(X_INFO
,verb
,"PM Event received: %s\n",str
);
198 DoApmEvent(events
[i
],FALSE
);
199 switch (xf86PMConfirmEventToOs(fd
,events
[i
])) {
207 DoApmEvent(events
[i
],TRUE
);
215 n
= xf86PMGetEventFromOs(fd
,events
,MAX_NO_EVENTS
);