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"
36 #include "xf86_OSproc.h"
38 int (*xf86PMGetEventFromOs
) (int fd
, pmEvent
* events
, int num
) = NULL
;
39 pmWait (*xf86PMConfirmEventToOs
) (int fd
, pmEvent event
) = NULL
;
41 static Bool suspended
= FALSE
;
44 eventName(pmEvent event
, const char **str
)
47 case XF86_APM_SYS_STANDBY
:
48 *str
= "System Standby Request";
50 case XF86_APM_SYS_SUSPEND
:
51 *str
= "System Suspend Request";
53 case XF86_APM_CRITICAL_SUSPEND
:
54 *str
= "Critical Suspend";
56 case XF86_APM_USER_STANDBY
:
57 *str
= "User System Standby Request";
59 case XF86_APM_USER_SUSPEND
:
60 *str
= "User System Suspend Request";
62 case XF86_APM_STANDBY_RESUME
:
63 *str
= "System Standby Resume";
65 case XF86_APM_NORMAL_RESUME
:
66 *str
= "Normal Resume System";
68 case XF86_APM_CRITICAL_RESUME
:
69 *str
= "Critical Resume System";
71 case XF86_APM_LOW_BATTERY
:
74 case XF86_APM_POWER_STATUS_CHANGE
:
75 *str
= "Power Status Change";
77 case XF86_APM_UPDATE_TIME
:
80 case XF86_APM_CAPABILITY_CHANGED
:
81 *str
= "Capability Changed";
83 case XF86_APM_STANDBY_FAILED
:
84 *str
= "Standby Request Failed";
86 case XF86_APM_SUSPEND_FAILED
:
87 *str
= "Suspend Request Failed";
90 *str
= "Unknown Event";
96 suspend(pmEvent event
, Bool undo
)
101 for (i
= 0; i
< xf86NumScreens
; i
++) {
102 if (xf86Screens
[i
]->EnableDisableFBAccess
)
103 (*xf86Screens
[i
]->EnableDisableFBAccess
) (xf86Screens
[i
], FALSE
);
105 pInfo
= xf86InputDevs
;
107 DisableDevice(pInfo
->dev
, TRUE
);
111 for (i
= 0; i
< xf86NumScreens
; i
++) {
112 if (xf86Screens
[i
]->PMEvent
)
113 xf86Screens
[i
]->PMEvent(xf86Screens
[i
], event
, undo
);
115 xf86Screens
[i
]->LeaveVT(xf86Screens
[i
]);
116 xf86Screens
[i
]->vtSema
= FALSE
;
124 resume(pmEvent event
, Bool undo
)
130 for (i
= 0; i
< xf86NumScreens
; i
++) {
131 if (xf86Screens
[i
]->PMEvent
)
132 xf86Screens
[i
]->PMEvent(xf86Screens
[i
], event
, undo
);
134 xf86Screens
[i
]->vtSema
= TRUE
;
135 xf86Screens
[i
]->EnterVT(xf86Screens
[i
]);
139 for (i
= 0; i
< xf86NumScreens
; i
++) {
140 if (xf86Screens
[i
]->EnableDisableFBAccess
)
141 (*xf86Screens
[i
]->EnableDisableFBAccess
) (xf86Screens
[i
], TRUE
);
143 dixSaveScreens(serverClient
, SCREEN_SAVER_FORCER
, ScreenSaverReset
);
144 pInfo
= xf86InputDevs
;
146 EnableDevice(pInfo
->dev
, TRUE
);
152 DoApmEvent(pmEvent event
, Bool undo
)
158 case XF86_APM_SYS_STANDBY
:
159 case XF86_APM_USER_STANDBY
:
161 case XF86_APM_SYS_SUSPEND
:
162 case XF86_APM_CRITICAL_SUSPEND
: /*do we want to delay a critical suspend? */
163 case XF86_APM_USER_SUSPEND
:
164 /* should we do this ? */
165 if (!undo
&& !suspended
) {
166 suspend(event
, undo
);
169 else if (undo
&& suspended
) {
175 case XF86_APM_STANDBY_RESUME
:
177 case XF86_APM_NORMAL_RESUME
:
178 case XF86_APM_CRITICAL_RESUME
:
186 for (i
= 0; i
< xf86NumScreens
; i
++) {
187 if (xf86Screens
[i
]->PMEvent
) {
188 xf86Screens
[i
]->PMEvent(xf86Screens
[i
], event
, undo
);
196 #define MAX_NO_EVENTS 8
199 xf86HandlePMEvents(int fd
, pointer data
)
201 pmEvent events
[MAX_NO_EVENTS
];
205 if (!xf86PMGetEventFromOs
)
208 if ((n
= xf86PMGetEventFromOs(fd
, events
, MAX_NO_EVENTS
))) {
210 for (i
= 0; i
< n
; i
++) {
211 const char *str
= NULL
;
212 int verb
= eventName(events
[i
], &str
);
214 xf86MsgVerb(X_INFO
, verb
, "PM Event received: %s\n", str
);
215 DoApmEvent(events
[i
], FALSE
);
216 switch (xf86PMConfirmEventToOs(fd
, events
[i
])) {
224 DoApmEvent(events
[i
], TRUE
);
232 n
= xf86PMGetEventFromOs(fd
, events
, MAX_NO_EVENTS
);