| 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 | #ifdef HAVE_XORG_CONFIG_H1 |
| 53 | #include <xorg-config.h> |
| 54 | #endif |
| 55 | |
| 56 | #include <X11/X.h> |
| 57 | #include <X11/Xpoll.h> |
| 58 | #include <X11/Xproto.h> |
| 59 | #include <X11/Xatom.h> |
| 60 | #include "misc.h" |
| 61 | #include "xf86.h" |
| 62 | #include "xf86Priv.h" |
| 63 | #define XF86_OS_PRIVS |
| 64 | #include "xf86_OSlib.h" |
| 65 | #include <X11/keysym.h> |
| 66 | |
| 67 | #ifdef XFreeXDGA1 |
| 68 | #include "dgaproc.h" |
| 69 | #endif |
| 70 | |
| 71 | #include <X11/extensions/XI.h> |
| 72 | #include <X11/extensions/XIproto.h> |
| 73 | #include "inputstr.h" |
| 74 | #include "xf86Xinput.h" |
| 75 | |
| 76 | #include "mi.h" |
| 77 | #include "mipointer.h" |
| 78 | |
| 79 | #include "xkbsrv.h" |
| 80 | #include "xkbstr.h" |
| 81 | |
| 82 | #ifdef DPMSExtension1 |
| 83 | #include <X11/extensions/dpmsconst.h> |
| 84 | #include "dpmsproc.h" |
| 85 | #endif |
| 86 | |
| 87 | #include "xf86platformBus.h" |
| 88 | #include "systemd-logind.h" |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | Bool VTSwitchEnabled = TRUE1; |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | extern fd_set EnabledDevices; |
| 105 | |
| 106 | #ifdef XF86PM |
| 107 | extern void (*xf86OSPMClose) (void); |
| 108 | #endif |
| 109 | |
| 110 | static void xf86VTSwitch(void); |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | typedef struct x_IHRec { |
| 117 | int fd; |
| 118 | InputHandlerProc ihproc; |
| 119 | void *data; |
| 120 | Bool enabled; |
| 121 | Bool is_input; |
| 122 | struct x_IHRec *next; |
| 123 | } IHRec, *IHPtr; |
| 124 | |
| 125 | static IHPtr InputHandlers = NULL((void*)0); |
| 126 | |
| 127 | Bool |
| 128 | LegalModifier(unsigned int key, DeviceIntPtr pDev) |
| 129 | { |
| 130 | return TRUE1; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | int |
| 139 | TimeSinceLastInputEvent(void) |
| 140 | { |
| 141 | if (xf86Info.lastEventTime == 0) { |
| 142 | xf86Info.lastEventTime = GetTimeInMillis(); |
| 143 | } |
| 144 | return GetTimeInMillis() - xf86Info.lastEventTime; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | void |
| 152 | SetTimeSinceLastInputEvent(void) |
| 153 | { |
| 154 | xf86Info.lastEventTime = GetTimeInMillis(); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | void |
| 164 | ProcessInputEvents(void) |
| 165 | { |
| 166 | int x, y; |
| 167 | |
| 168 | mieqProcessInputEvents(); |
| 169 | |
| 170 | |
| 171 | miPointerGetPosition(inputInfo.pointer, &x, &y); |
| 172 | |
| 173 | xf86SetViewport(xf86Info.currentScreen, x, y); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | void |
| 181 | xf86ProcessActionEvent(ActionEvent action, void *arg) |
| 182 | { |
| 183 | DebugF("ProcessActionEvent(%d,%p)\n", (int) action, arg); |
| 184 | switch (action) { |
| 185 | case ACTION_TERMINATE: |
| 186 | if (!xf86Info.dontZap) { |
| 187 | xf86Msg(X_INFO, "Server zapped. Shutting down.\n"); |
| 188 | #ifdef XFreeXDGA1 |
| 189 | DGAShutdown(); |
| 190 | #endif |
| 191 | GiveUp(0); |
| 192 | } |
| 193 | break; |
| 194 | case ACTION_NEXT_MODE: |
| 195 | if (!xf86Info.dontZoom) |
| 196 | xf86ZoomViewport(xf86Info.currentScreen, 1); |
| 197 | break; |
| 198 | case ACTION_PREV_MODE: |
| 199 | if (!xf86Info.dontZoom) |
| 200 | xf86ZoomViewport(xf86Info.currentScreen, -1); |
| 201 | break; |
| 202 | case ACTION_SWITCHSCREEN: |
| 203 | if (VTSwitchEnabled && !xf86Info.dontVTSwitch && arg) { |
| 204 | int vtno = *((int *) arg); |
| 205 | |
| 206 | if (vtno != xf86Info.vtno) { |
| 207 | if (!xf86VTActivate(vtno)) { |
| 208 | ErrorF("Failed to switch from vt%02d to vt%02d: %s\n", |
| 209 | xf86Info.vtno, vtno, strerror(errno(*__error()))); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | break; |
| 214 | case ACTION_SWITCHSCREEN_NEXT: |
| 215 | if (VTSwitchEnabled && !xf86Info.dontVTSwitch) { |
| 216 | if (!xf86VTActivate(xf86Info.vtno + 1)) { |
| 217 | |
| 218 | |
| 219 | |
| 220 | if (!xf86VTActivate(1)) { |
| 221 | ErrorF("Failed to switch from vt%02d to next vt: %s\n", |
| 222 | xf86Info.vtno, strerror(errno(*__error()))); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | break; |
| 227 | case ACTION_SWITCHSCREEN_PREV: |
| 228 | if (VTSwitchEnabled && !xf86Info.dontVTSwitch && xf86Info.vtno > 0) { |
| 229 | if (!xf86VTActivate(xf86Info.vtno - 1)) { |
| 230 | |
| 231 | ErrorF("Failed to switch from vt%02d to previous vt: %s\n", |
| 232 | xf86Info.vtno, strerror(errno(*__error()))); |
| 233 | } |
| 234 | } |
| 235 | break; |
| 236 | default: |
| 237 | break; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | void |
| 248 | xf86Wakeup(void *blockData, int err, void *pReadmask) |
| 249 | { |
| 250 | if (err >= 0) { |
| 251 | IHPtr ih, ih_tmp; |
| 252 | |
| 253 | nt_list_for_each_entry_safe(ih, ih_tmp, InputHandlers, next)for (ih = InputHandlers, ih_tmp = (ih) ? (ih)->next : ((void *)0); ih; ih = ih_tmp, ih_tmp = (ih_tmp) ? (ih_tmp)->next: ((void*)0)) { |
| 254 | if (ih->enabled && ih->fd >= 0 && ih->ihproc && |
| 255 | (FD_ISSET(ih->fd, ((fd_set *) pReadmask))__darwin_fd_isset((ih->fd), (((fd_set *) pReadmask))) != 0)) { |
| 256 | ih->ihproc(ih->fd, ih->data); |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | if (xf86VTSwitchPending()) |
| 262 | xf86VTSwitch(); |
| 263 | } |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | static void |
| 271 | xf86ReadInput(int fd, int ready, void *closure) |
| 272 | { |
| 273 | InputInfoPtr pInfo = closure; |
| 274 | |
| 275 | pInfo->read_input(pInfo); |
| 276 | } |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | void |
| 283 | xf86AddEnabledDevice(InputInfoPtr pInfo) |
| 284 | { |
| 285 | InputThreadRegisterDev(pInfo->fd, xf86ReadInput, pInfo); |
| 286 | } |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | void |
| 293 | xf86RemoveEnabledDevice(InputInfoPtr pInfo) |
| 294 | { |
| 295 | InputThreadUnregisterDev(pInfo->fd); |
| 296 | } |
| 297 | |
| 298 | static int *xf86SignalIntercept = NULL((void*)0); |
| 299 | |
| 300 | void |
| 301 | xf86InterceptSignals(int *signo) |
| 302 | { |
| 303 | if ((xf86SignalIntercept = signo)) |
| 304 | *signo = -1; |
| 305 | } |
| 306 | |
| 307 | static void (*xf86SigIllHandler) (void) = NULL((void*)0); |
| 308 | |
| 309 | void |
| 310 | xf86InterceptSigIll(void (*sigillhandler) (void)) |
| 311 | { |
| 312 | xf86SigIllHandler = sigillhandler; |
| 313 | } |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | int |
| 320 | xf86SigWrapper(int signo) |
| 321 | { |
| 322 | if ((signo == SIGILL4) && xf86SigIllHandler) { |
| 323 | (*xf86SigIllHandler) (); |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | if (xf86SignalIntercept && (*xf86SignalIntercept < 0)) { |
| 328 | *xf86SignalIntercept = signo; |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | xf86Info.caughtSignal = TRUE1; |
| 333 | return 1; |
| 334 | } |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | void |
| 341 | xf86PrintBacktrace(void) |
| 342 | { |
| 343 | xorg_backtrace(); |
| 344 | } |
| 345 | |
| 346 | static void |
| 347 | xf86ReleaseKeys(DeviceIntPtr pDev) |
| 348 | { |
| 349 | KeyClassPtr keyc; |
| 350 | int i; |
| 351 | |
| 352 | if (!pDev || !pDev->key) |
| 353 | return; |
| 354 | |
| 355 | keyc = pDev->key; |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | for (i = keyc->xkbInfo->desc->min_key_code; |
| 369 | i < keyc->xkbInfo->desc->max_key_code; i++) { |
| 370 | if (key_is_down(pDev, i, KEY_POSTED2)) { |
| 371 | input_lock(); |
| 372 | QueueKeyboardEvents(pDev, KeyRelease3, i); |
| 373 | input_unlock(); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | void |
| 379 | xf86DisableInputDeviceForVTSwitch(InputInfoPtr pInfo) |
| 380 | { |
| 381 | if (!pInfo->dev) |
| 382 | return; |
| 383 | |
| 384 | if (!pInfo->dev->enabled) |
| 385 | pInfo->flags |= XI86_DEVICE_DISABLED0x10; |
| 386 | |
| 387 | xf86ReleaseKeys(pInfo->dev); |
| 388 | ProcessInputEvents(); |
| 389 | DisableDevice(pInfo->dev, TRUE1); |
| 390 | } |
| 391 | |
| 392 | void |
| 393 | xf86EnableInputDeviceForVTSwitch(InputInfoPtr pInfo) |
| 394 | { |
| 395 | if (pInfo->dev && (pInfo->flags & XI86_DEVICE_DISABLED0x10) == 0) |
| 396 | EnableDevice(pInfo->dev, TRUE1); |
| 397 | pInfo->flags &= ~XI86_DEVICE_DISABLED0x10; |
| 398 | } |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | static void |
| 406 | xf86UpdateHasVTProperty(Bool hasVT) |
| 407 | { |
| 408 | Atom property_name; |
| 409 | int32_t value = hasVT ? 1 : 0; |
| 410 | int i; |
| 411 | |
| 412 | property_name = MakeAtom(HAS_VT_ATOM_NAME"XFree86_has_VT", sizeof(HAS_VT_ATOM_NAME"XFree86_has_VT") - 1, |
| 413 | FALSE0); |
| 414 | if (property_name == BAD_RESOURCE0xe0000000) |
| 415 | FatalError("Failed to retrieve \"HAS_VT\" atom\n"); |
| 416 | for (i = 0; i < xf86NumScreens; i++) { |
| 417 | dixChangeWindowProperty(serverClient, |
| 418 | xf86ScrnToScreen(xf86Screens[i])->root, |
| 419 | property_name, XA_INTEGER((Atom) 19), 32, |
| 420 | PropModeReplace0, 1, &value, TRUE1); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | void |
| 425 | xf86VTLeave(void) |
| 426 | { |
| 427 | int i; |
| 428 | InputInfoPtr pInfo; |
| 429 | IHPtr ih; |
| 430 | |
| 431 | DebugF("xf86VTSwitch: Leaving, xf86Exiting is %s\n", |
| 432 | BOOLTOSTRING((dispatchException & DE_TERMINATE) ? TRUE : FALSE)); |
| 433 | #ifdef DPMSExtension1 |
| 434 | if (DPMSPowerLevel != DPMSModeOn0) |
| 435 | DPMSSet(serverClient, DPMSModeOn0); |
| 436 | #endif |
| 437 | for (i = 0; i < xf86NumScreens; i++) { |
| 438 | if (!(dispatchException & DE_TERMINATE2)) |
| 439 | if (xf86Screens[i]->EnableDisableFBAccess) |
| 440 | (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], FALSE0); |
| 441 | } |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | for (ih = InputHandlers; ih; ih = ih->next) { |
| 448 | if (ih->is_input) |
| 449 | xf86DisableInputHandler(ih); |
| 450 | else |
| 451 | xf86DisableGeneralHandler(ih); |
| 452 | } |
| 453 | for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) |
| 454 | xf86DisableInputDeviceForVTSwitch(pInfo); |
| 455 | |
| 456 | input_lock(); |
| 457 | for (i = 0; i < xf86NumScreens; i++) |
| 458 | xf86Screens[i]->LeaveVT(xf86Screens[i]); |
| 459 | for (i = 0; i < xf86NumGPUScreens; i++) |
| 460 | xf86GPUScreens[i]->LeaveVT(xf86GPUScreens[i]); |
| 461 | |
| 462 | xf86AccessLeave(); |
| 463 | |
| 464 | if (!xf86VTSwitchAway()) |
| 465 | goto switch_failed; |
| 466 | |
| 467 | #ifdef XF86PM |
| 468 | if (xf86OSPMClose) |
| 469 | xf86OSPMClose(); |
| 470 | xf86OSPMClose = NULL((void*)0); |
| 471 | #endif |
| 472 | |
| 473 | for (i = 0; i < xf86NumScreens; i++) { |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | xf86Screens[i]->vtSema = FALSE0; |
| 479 | } |
| 480 | if (xorgHWAccess) |
| 481 | xf86DisableIO(); |
| 482 | |
| 483 | xf86UpdateHasVTProperty(FALSE0); |
| 484 | |
| 485 | return; |
| 486 | |
| 487 | switch_failed: |
| 488 | DebugF("xf86VTSwitch: Leave failed\n"); |
| 489 | xf86AccessEnter(); |
| 490 | for (i = 0; i < xf86NumScreens; i++) { |
| 491 | if (!xf86Screens[i]->EnterVT(xf86Screens[i])) |
| 492 | FatalError("EnterVT failed for screen %d\n", i); |
| 493 | } |
| 494 | for (i = 0; i < xf86NumGPUScreens; i++) { |
| 495 | if (!xf86GPUScreens[i]->EnterVT(xf86GPUScreens[i])) |
| 496 | FatalError("EnterVT failed for gpu screen %d\n", i); |
| 497 | } |
| 498 | if (!(dispatchException & DE_TERMINATE2)) { |
| 499 | for (i = 0; i < xf86NumScreens; i++) { |
| 500 | if (xf86Screens[i]->EnableDisableFBAccess) |
| 501 | (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], TRUE1); |
| 502 | } |
| 503 | } |
| 504 | dixSaveScreens(serverClient, SCREEN_SAVER_FORCER2, ScreenSaverReset0); |
| 505 | |
| 506 | for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) |
| 507 | xf86EnableInputDeviceForVTSwitch(pInfo); |
| 508 | for (ih = InputHandlers; ih; ih = ih->next) { |
| 509 | if (ih->is_input) |
| 510 | xf86EnableInputHandler(ih); |
| 511 | else |
| 512 | xf86EnableGeneralHandler(ih); |
| 513 | } |
| 514 | input_unlock(); |
| 515 | } |
| 516 | |
| 517 | void |
| 518 | xf86VTEnter(void) |
| 519 | { |
| 520 | int i; |
| 521 | InputInfoPtr pInfo; |
| 522 | IHPtr ih; |
| 523 | |
| 524 | DebugF("xf86VTSwitch: Entering\n"); |
| 525 | if (!xf86VTSwitchTo()) |
| 526 | return; |
| 527 | |
| 528 | #ifdef XF86PM |
| 529 | xf86OSPMClose = xf86OSPMOpen(); |
| 530 | #endif |
| 531 | |
| 532 | if (xorgHWAccess) |
| 533 | xf86EnableIO(); |
| 534 | xf86AccessEnter(); |
| 535 | for (i = 0; i < xf86NumScreens; i++) { |
| 536 | xf86Screens[i]->vtSema = TRUE1; |
| 537 | if (!xf86Screens[i]->EnterVT(xf86Screens[i])) |
| 538 | FatalError("EnterVT failed for screen %d\n", i); |
| 539 | } |
| 540 | for (i = 0; i < xf86NumGPUScreens; i++) { |
| 541 | xf86GPUScreens[i]->vtSema = TRUE1; |
| 542 | if (!xf86GPUScreens[i]->EnterVT(xf86GPUScreens[i])) |
| 543 | FatalError("EnterVT failed for gpu screen %d\n", i); |
| 544 | } |
| 545 | for (i = 0; i < xf86NumScreens; i++) { |
| 546 | if (xf86Screens[i]->EnableDisableFBAccess) |
| 547 | (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], TRUE1); |
| 548 | } |
| 549 | |
| 550 | |
| 551 | dixSaveScreens(serverClient, SCREEN_SAVER_FORCER2, ScreenSaverReset0); |
| 552 | |
| 553 | for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) { |
| 554 | |
| 555 | if (!(pInfo->flags & XI86_SERVER_FD0x20)) |
| 556 | xf86EnableInputDeviceForVTSwitch(pInfo); |
| 557 | } |
| 558 | |
| 559 | for (ih = InputHandlers; ih; ih = ih->next) { |
| 560 | if (ih->is_input) |
| 561 | xf86EnableInputHandler(ih); |
| 562 | else |
| 563 | xf86EnableGeneralHandler(ih); |
| 564 | } |
| 565 | #ifdef XSERVER_PLATFORM_BUS |
| 566 | |
| 567 | xf86platformVTProbe(); |
| 568 | #endif |
| 569 | |
| 570 | xf86UpdateHasVTProperty(TRUE1); |
| 571 | |
| 572 | input_unlock(); |
| 573 | } |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | static void |
| 580 | xf86VTSwitch(void) |
| 581 | { |
| 582 | DebugF("xf86VTSwitch()\n"); |
| 583 | |
| 584 | #ifdef XFreeXDGA1 |
| 585 | if (!DGAVTSwitch()) |
| 586 | return; |
| 587 | #endif |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | if (xf86VTOwner()) |
| 598 | xf86VTLeave(); |
| 599 | else if (!systemd_logind_controls_session()0) |
| 600 | xf86VTEnter(); |
| 601 | } |
| 602 | |
| 603 | |
| 604 | |
| 605 | static void * |
| 606 | addInputHandler(int fd, InputHandlerProc proc, void *data) |
| 607 | { |
| 608 | IHPtr ih; |
| 609 | |
| 610 | if (fd < 0 || !proc) |
| 611 | return NULL((void*)0); |
| 612 | |
| 613 | ih = calloc(sizeof(*ih), 1); |
| 614 | if (!ih) |
| 615 | return NULL((void*)0); |
| 616 | |
| 617 | ih->fd = fd; |
| 618 | ih->ihproc = proc; |
| 619 | ih->data = data; |
| 620 | ih->enabled = TRUE1; |
| 621 | |
| 622 | ih->next = InputHandlers; |
| 623 | InputHandlers = ih; |
| 624 | |
| 625 | return ih; |
| 626 | } |
| 627 | |
| 628 | void * |
| 629 | xf86AddInputHandler(int fd, InputHandlerProc proc, void *data) |
| 630 | { |
| 631 | IHPtr ih = addInputHandler(fd, proc, data); |
| 632 | |
| 633 | if (ih) { |
| 634 | AddEnabledDevice(fd); |
| 635 | ih->is_input = TRUE1; |
| 636 | } |
| 637 | return ih; |
| 638 | } |
| 639 | |
| 640 | void * |
| 641 | xf86AddGeneralHandler(int fd, InputHandlerProc proc, void *data) |
| 642 | { |
| 643 | IHPtr ih = addInputHandler(fd, proc, data); |
| 644 | |
| 645 | if (ih) |
| 646 | AddGeneralSocket(fd); |
| 647 | return ih; |
| 648 | } |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | InputHandlerProc |
| 656 | xf86SetConsoleHandler(InputHandlerProc proc, void *data) |
| 657 | { |
| 658 | static IHPtr handler = NULL((void*)0); |
| 659 | InputHandlerProc old_proc = NULL((void*)0); |
| 660 | |
| 661 | if (handler) { |
| 662 | old_proc = handler->ihproc; |
| 663 | xf86RemoveGeneralHandler(handler); |
| 664 | } |
| 665 | |
| 666 | handler = xf86AddGeneralHandler(xf86Info.consoleFd, proc, data); |
| 667 | |
| 668 | return old_proc; |
| 669 | } |
| 670 | |
| 671 | static void |
| 672 | removeInputHandler(IHPtr ih) |
| 673 | { |
| 674 | IHPtr p; |
| 675 | |
| 676 | if (ih == InputHandlers) |
| 5 | | Assuming 'ih' is not equal to 'InputHandlers' | |
|
| |
| 677 | InputHandlers = ih->next; |
| 678 | else { |
| 679 | p = InputHandlers; |
| |
| 680 | while (p && p->next != ih) |
| 8 | | Assuming pointer value is null | |
|
| 681 | p = p->next; |
| 682 | if (ih) |
| |
| 683 | p->next = ih->next; |
| 10 | | Access to field 'next' results in a dereference of a null pointer (loaded from variable 'p') |
|
| 684 | } |
| 685 | free(ih); |
| 686 | } |
| 687 | |
| 688 | int |
| 689 | xf86RemoveInputHandler(void *handler) |
| 690 | { |
| 691 | IHPtr ih; |
| 692 | int fd; |
| 693 | |
| 694 | if (!handler) |
| 695 | return -1; |
| 696 | |
| 697 | ih = handler; |
| 698 | fd = ih->fd; |
| 699 | |
| 700 | if (ih->fd >= 0) |
| 701 | RemoveEnabledDevice(ih->fd); |
| 702 | removeInputHandler(ih); |
| 703 | |
| 704 | return fd; |
| 705 | } |
| 706 | |
| 707 | int |
| 708 | xf86RemoveGeneralHandler(void *handler) |
| 709 | { |
| 710 | IHPtr ih; |
| 711 | int fd; |
| 712 | |
| 713 | if (!handler) |
| 1 | Assuming 'handler' is non-null | |
|
| |
| 714 | return -1; |
| 715 | |
| 716 | ih = handler; |
| 717 | fd = ih->fd; |
| 718 | |
| 719 | if (ih->fd >= 0) |
| |
| 720 | RemoveGeneralSocket(ih->fd); |
| 721 | removeInputHandler(ih); |
| 4 | | Calling 'removeInputHandler' | |
|
| 722 | |
| 723 | return fd; |
| 724 | } |
| 725 | |
| 726 | void |
| 727 | xf86DisableInputHandler(void *handler) |
| 728 | { |
| 729 | IHPtr ih; |
| 730 | |
| 731 | if (!handler) |
| 732 | return; |
| 733 | |
| 734 | ih = handler; |
| 735 | ih->enabled = FALSE0; |
| 736 | if (ih->fd >= 0) |
| 737 | RemoveEnabledDevice(ih->fd); |
| 738 | } |
| 739 | |
| 740 | void |
| 741 | xf86DisableGeneralHandler(void *handler) |
| 742 | { |
| 743 | IHPtr ih; |
| 744 | |
| 745 | if (!handler) |
| 746 | return; |
| 747 | |
| 748 | ih = handler; |
| 749 | ih->enabled = FALSE0; |
| 750 | if (ih->fd >= 0) |
| 751 | RemoveGeneralSocket(ih->fd); |
| 752 | } |
| 753 | |
| 754 | void |
| 755 | xf86EnableInputHandler(void *handler) |
| 756 | { |
| 757 | IHPtr ih; |
| 758 | |
| 759 | if (!handler) |
| 760 | return; |
| 761 | |
| 762 | ih = handler; |
| 763 | ih->enabled = TRUE1; |
| 764 | if (ih->fd >= 0) |
| 765 | AddEnabledDevice(ih->fd); |
| 766 | } |
| 767 | |
| 768 | void |
| 769 | xf86EnableGeneralHandler(void *handler) |
| 770 | { |
| 771 | IHPtr ih; |
| 772 | |
| 773 | if (!handler) |
| 774 | return; |
| 775 | |
| 776 | ih = handler; |
| 777 | ih->enabled = TRUE1; |
| 778 | if (ih->fd >= 0) |
| 779 | AddGeneralSocket(ih->fd); |
| 780 | } |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | Bool |
| 786 | xf86EnableVTSwitch(Bool new) |
| 787 | { |
| 788 | static Bool def = TRUE1; |
| 789 | Bool old; |
| 790 | |
| 791 | old = VTSwitchEnabled; |
| 792 | if (!new) { |
| 793 | |
| 794 | def = VTSwitchEnabled; |
| 795 | VTSwitchEnabled = FALSE0; |
| 796 | } |
| 797 | else { |
| 798 | |
| 799 | VTSwitchEnabled = def; |
| 800 | } |
| 801 | return old; |
| 802 | } |
| 803 | |
| 804 | void |
| 805 | DDXRingBell(int volume, int pitch, int duration) |
| 806 | { |
| 807 | xf86OSRingBell(volume, pitch, duration); |
| 808 | } |
| 809 | |
| 810 | Bool |
| 811 | xf86VTOwner(void) |
| 812 | { |
| 813 | |
| 814 | if (xf86NumScreens == 0) |
| 815 | return TRUE1; |
| 816 | return xf86Screens[0]->vtSema; |
| 817 | } |