diff options
Diffstat (limited to 'xorg-server/hw/xfree86/common/xf86PM.c')
-rw-r--r-- | xorg-server/hw/xfree86/common/xf86PM.c | 223 |
1 files changed, 127 insertions, 96 deletions
diff --git a/xorg-server/hw/xfree86/common/xf86PM.c b/xorg-server/hw/xfree86/common/xf86PM.c index 47e0297d6..f69fffa0e 100644 --- a/xorg-server/hw/xfree86/common/xf86PM.c +++ b/xorg-server/hw/xfree86/common/xf86PM.c @@ -35,60 +35,90 @@ #include "xf86Xinput.h" #include "xf86_OSproc.h" -int (*xf86PMGetEventFromOs)(int fd,pmEvent *events,int num) = NULL; -pmWait (*xf86PMConfirmEventToOs)(int fd,pmEvent event) = NULL; +int (*xf86PMGetEventFromOs) (int fd, pmEvent * events, int num) = NULL; +pmWait (*xf86PMConfirmEventToOs) (int fd, pmEvent event) = NULL; static Bool suspended = FALSE; static int eventName(pmEvent event, const char **str) { - switch(event) { - case XF86_APM_SYS_STANDBY: *str="System Standby Request"; return 0; - case XF86_APM_SYS_SUSPEND: *str="System Suspend Request"; return 0; - case XF86_APM_CRITICAL_SUSPEND: *str="Critical Suspend"; return 0; - case XF86_APM_USER_STANDBY: *str="User System Standby Request"; return 0; - case XF86_APM_USER_SUSPEND: *str="User System Suspend Request"; return 0; - case XF86_APM_STANDBY_RESUME: *str="System Standby Resume"; return 0; - case XF86_APM_NORMAL_RESUME: *str="Normal Resume System"; return 0; - case XF86_APM_CRITICAL_RESUME: *str="Critical Resume System"; return 0; - case XF86_APM_LOW_BATTERY: *str="Battery Low"; return 3; - case XF86_APM_POWER_STATUS_CHANGE: *str="Power Status Change";return 3; - case XF86_APM_UPDATE_TIME: *str="Update Time";return 3; - case XF86_APM_CAPABILITY_CHANGED: *str="Capability Changed"; return 3; - case XF86_APM_STANDBY_FAILED: *str="Standby Request Failed"; return 0; - case XF86_APM_SUSPEND_FAILED: *str="Suspend Request Failed"; return 0; - default: *str="Unknown Event"; return 0; + switch (event) { + case XF86_APM_SYS_STANDBY: + *str = "System Standby Request"; + return 0; + case XF86_APM_SYS_SUSPEND: + *str = "System Suspend Request"; + return 0; + case XF86_APM_CRITICAL_SUSPEND: + *str = "Critical Suspend"; + return 0; + case XF86_APM_USER_STANDBY: + *str = "User System Standby Request"; + return 0; + case XF86_APM_USER_SUSPEND: + *str = "User System Suspend Request"; + return 0; + case XF86_APM_STANDBY_RESUME: + *str = "System Standby Resume"; + return 0; + case XF86_APM_NORMAL_RESUME: + *str = "Normal Resume System"; + return 0; + case XF86_APM_CRITICAL_RESUME: + *str = "Critical Resume System"; + return 0; + case XF86_APM_LOW_BATTERY: + *str = "Battery Low"; + return 3; + case XF86_APM_POWER_STATUS_CHANGE: + *str = "Power Status Change"; + return 3; + case XF86_APM_UPDATE_TIME: + *str = "Update Time"; + return 3; + case XF86_APM_CAPABILITY_CHANGED: + *str = "Capability Changed"; + return 3; + case XF86_APM_STANDBY_FAILED: + *str = "Standby Request Failed"; + return 0; + case XF86_APM_SUSPEND_FAILED: + *str = "Suspend Request Failed"; + return 0; + default: + *str = "Unknown Event"; + return 0; } } static int sigio_blocked_for_suspend; static void -suspend (pmEvent event, Bool undo) +suspend(pmEvent event, Bool undo) { int i; InputInfoPtr pInfo; for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess) (i, FALSE); + if (xf86Screens[i]->EnableDisableFBAccess) + (*xf86Screens[i]->EnableDisableFBAccess) (i, FALSE); } pInfo = xf86InputDevs; while (pInfo) { - DisableDevice(pInfo->dev, TRUE); - pInfo = pInfo->next; + DisableDevice(pInfo->dev, TRUE); + pInfo = pInfo->next; } sigio_blocked_for_suspend = xf86BlockSIGIO(); for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->PMEvent) - xf86Screens[i]->PMEvent(i,event,undo); - else { - xf86Screens[i]->LeaveVT(i, 0); - xf86Screens[i]->vtSema = FALSE; - } + if (xf86Screens[i]->PMEvent) + xf86Screens[i]->PMEvent(i, event, undo); + else { + xf86Screens[i]->LeaveVT(i, 0); + xf86Screens[i]->vtSema = FALSE; + } } - xf86AccessLeave(); + xf86AccessLeave(); } @@ -100,23 +130,23 @@ resume(pmEvent event, Bool undo) xf86AccessEnter(); for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->PMEvent) - xf86Screens[i]->PMEvent(i,event,undo); - else { - xf86Screens[i]->vtSema = TRUE; - xf86Screens[i]->EnterVT(i, 0); - } + if (xf86Screens[i]->PMEvent) + xf86Screens[i]->PMEvent(i, event, undo); + else { + xf86Screens[i]->vtSema = TRUE; + xf86Screens[i]->EnterVT(i, 0); + } } xf86UnblockSIGIO(sigio_blocked_for_suspend); for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE); + if (xf86Screens[i]->EnableDisableFBAccess) + (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE); } dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); pInfo = xf86InputDevs; while (pInfo) { - EnableDevice(pInfo->dev, TRUE); - pInfo = pInfo->next; + EnableDevice(pInfo->dev, TRUE); + pInfo = pInfo->next; } } @@ -124,43 +154,44 @@ static void DoApmEvent(pmEvent event, Bool undo) { int i, was_blocked; - - switch(event) { + + switch (event) { #if 0 case XF86_APM_SYS_STANDBY: case XF86_APM_USER_STANDBY: #endif case XF86_APM_SYS_SUSPEND: - case XF86_APM_CRITICAL_SUSPEND: /*do we want to delay a critical suspend?*/ + case XF86_APM_CRITICAL_SUSPEND: /*do we want to delay a critical suspend? */ case XF86_APM_USER_SUSPEND: - /* should we do this ? */ - if (!undo && !suspended) { - suspend(event,undo); - suspended = TRUE; - } else if (undo && suspended) { - resume(event,undo); - suspended = FALSE; - } - break; + /* should we do this ? */ + if (!undo && !suspended) { + suspend(event, undo); + suspended = TRUE; + } + else if (undo && suspended) { + resume(event, undo); + suspended = FALSE; + } + break; #if 0 case XF86_APM_STANDBY_RESUME: #endif case XF86_APM_NORMAL_RESUME: case XF86_APM_CRITICAL_RESUME: - if (suspended) { - resume(event,undo); - suspended = FALSE; - } - break; + if (suspended) { + resume(event, undo); + suspended = FALSE; + } + break; default: - was_blocked = xf86BlockSIGIO(); - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->PMEvent) { - xf86Screens[i]->PMEvent(i,event,undo); - } - } - xf86UnblockSIGIO(was_blocked); - break; + was_blocked = xf86BlockSIGIO(); + for (i = 0; i < xf86NumScreens; i++) { + if (xf86Screens[i]->PMEvent) { + xf86Screens[i]->PMEvent(i, event, undo); + } + } + xf86UnblockSIGIO(was_blocked); + break; } } @@ -170,39 +201,39 @@ void xf86HandlePMEvents(int fd, pointer data) { pmEvent events[MAX_NO_EVENTS]; - int i,n; + int i, n; Bool wait = FALSE; if (!xf86PMGetEventFromOs) - return; - - if ((n = xf86PMGetEventFromOs(fd,events,MAX_NO_EVENTS))) { - do { - for (i = 0; i < n; i++) { - const char *str = NULL; - int verb = eventName(events[i],&str); - - xf86MsgVerb(X_INFO,verb,"PM Event received: %s\n",str); - DoApmEvent(events[i],FALSE); - switch (xf86PMConfirmEventToOs(fd,events[i])) { - case PM_WAIT: - wait = TRUE; - break; - case PM_CONTINUE: - wait = FALSE; - break; - case PM_FAILED: - DoApmEvent(events[i],TRUE); - wait = FALSE; - break; - default: - break; - } - } - if (wait) - n = xf86PMGetEventFromOs(fd,events,MAX_NO_EVENTS); - else - break; - } while (1); + return; + + if ((n = xf86PMGetEventFromOs(fd, events, MAX_NO_EVENTS))) { + do { + for (i = 0; i < n; i++) { + const char *str = NULL; + int verb = eventName(events[i], &str); + + xf86MsgVerb(X_INFO, verb, "PM Event received: %s\n", str); + DoApmEvent(events[i], FALSE); + switch (xf86PMConfirmEventToOs(fd, events[i])) { + case PM_WAIT: + wait = TRUE; + break; + case PM_CONTINUE: + wait = FALSE; + break; + case PM_FAILED: + DoApmEvent(events[i], TRUE); + wait = FALSE; + break; + default: + break; + } + } + if (wait) + n = xf86PMGetEventFromOs(fd, events, MAX_NO_EVENTS); + else + break; + } while (1); } } |