Changeset View
Changeset View
Standalone View
Standalone View
x11locker.cpp
Show All 21 Lines | |||||
22 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 22 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
23 | *********************************************************************/ | 23 | *********************************************************************/ | ||
24 | #include "x11locker.h" | 24 | #include "x11locker.h" | ||
25 | #include "globalaccel.h" | 25 | #include "globalaccel.h" | ||
26 | #include "abstractlocker.h" | 26 | #include "abstractlocker.h" | ||
27 | // KDE | 27 | // KDE | ||
28 | // Qt | 28 | // Qt | ||
29 | #include <QApplication> | 29 | #include <QApplication> | ||
30 | #include <QDebug> | | |||
31 | #include <QDesktopWidget> | 30 | #include <QDesktopWidget> | ||
32 | #include <QX11Info> | 31 | #include <QX11Info> | ||
33 | // X11 | 32 | // X11 | ||
34 | #include <X11/Xatom.h> | 33 | #include <X11/Xatom.h> | ||
35 | #include <fixx11h.h> | 34 | #include <fixx11h.h> | ||
36 | #include <xcb/xcb.h> | 35 | #include <xcb/xcb.h> | ||
37 | 36 | | |||
37 | #include <kscreenlocker_logging.h> | ||||
38 | | ||||
38 | static Window gVRoot = 0; | 39 | static Window gVRoot = 0; | ||
39 | static Window gVRootData = 0; | 40 | static Window gVRootData = 0; | ||
40 | static Atom gXA_VROOT; | 41 | static Atom gXA_VROOT; | ||
41 | static Atom gXA_SCREENSAVER_VERSION; | 42 | static Atom gXA_SCREENSAVER_VERSION; | ||
42 | 43 | | |||
43 | namespace ScreenLocker | 44 | namespace ScreenLocker | ||
44 | { | 45 | { | ||
45 | 46 | | |||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 98 | { | |||
99 | 100 | | |||
100 | // Some xscreensaver hacks check for this property | 101 | // Some xscreensaver hacks check for this property | ||
101 | const char *version = "KDE 4.0"; | 102 | const char *version = "KDE 4.0"; | ||
102 | 103 | | |||
103 | XChangeProperty (QX11Info::display(), m_background->winId(), | 104 | XChangeProperty (QX11Info::display(), m_background->winId(), | ||
104 | gXA_SCREENSAVER_VERSION, XA_STRING, 8, PropModeReplace, | 105 | gXA_SCREENSAVER_VERSION, XA_STRING, 8, PropModeReplace, | ||
105 | (unsigned char *) version, strlen(version)); | 106 | (unsigned char *) version, strlen(version)); | ||
106 | 107 | | |||
107 | qDebug() << "Lock window Id: " << m_background->winId(); | 108 | qCDebug(KSCREENLOCKER) << "Lock window Id: " << m_background->winId(); | ||
108 | 109 | | |||
109 | m_background->setPosition(0, 0); | 110 | m_background->setPosition(0, 0); | ||
110 | XSync(QX11Info::display(), False); | 111 | XSync(QX11Info::display(), False); | ||
111 | 112 | | |||
112 | setVRoot( m_background->winId(), m_background->winId() ); | 113 | setVRoot( m_background->winId(), m_background->winId() ); | ||
113 | } | 114 | } | ||
114 | 115 | | |||
115 | //--------------------------------------------------------------------------- | 116 | //--------------------------------------------------------------------------- | ||
▲ Show 20 Lines • Show All 216 Lines • ▼ Show 20 Line(s) | 290 | case XCB_MOTION_NOTIFY: | |||
332 | break; | 333 | break; | ||
333 | case XCB_CONFIGURE_NOTIFY: { // from SubstructureNotifyMask on the root window | 334 | case XCB_CONFIGURE_NOTIFY: { // from SubstructureNotifyMask on the root window | ||
334 | xcb_configure_notify_event_t *xc = reinterpret_cast<xcb_configure_notify_event_t*>(event); | 335 | xcb_configure_notify_event_t *xc = reinterpret_cast<xcb_configure_notify_event_t*>(event); | ||
335 | if (xc->event == QX11Info::appRootWindow()) { | 336 | if (xc->event == QX11Info::appRootWindow()) { | ||
336 | int index = findWindowInfo( xc->window ); | 337 | int index = findWindowInfo( xc->window ); | ||
337 | if( index >= 0 ) { | 338 | if( index >= 0 ) { | ||
338 | int index2 = xc->above_sibling ? findWindowInfo( xc->above_sibling ) : 0; | 339 | int index2 = xc->above_sibling ? findWindowInfo( xc->above_sibling ) : 0; | ||
339 | if( index2 < 0 ) | 340 | if( index2 < 0 ) | ||
340 | qDebug() << "Unknown above for ConfigureNotify"; | 341 | qCDebug(KSCREENLOCKER) << "Unknown above for ConfigureNotify"; | ||
341 | else { // move just above the other window | 342 | else { // move just above the other window | ||
342 | if( index2 < index ) | 343 | if( index2 < index ) | ||
343 | ++index2; | 344 | ++index2; | ||
344 | m_windowInfo.move( index, index2 ); | 345 | m_windowInfo.move( index, index2 ); | ||
345 | } | 346 | } | ||
346 | } else | 347 | } else | ||
347 | qDebug() << "Unknown toplevel for ConfigureNotify"; | 348 | qCDebug(KSCREENLOCKER) << "Unknown toplevel for ConfigureNotify"; | ||
348 | //kDebug() << "ConfigureNotify:"; | 349 | //kDebug() << "ConfigureNotify:"; | ||
349 | //the stacking order changed, so let's change the stacking order again to what we want | 350 | //the stacking order changed, so let's change the stacking order again to what we want | ||
350 | stayOnTop(); | 351 | stayOnTop(); | ||
351 | ret = true; | 352 | ret = true; | ||
352 | } | 353 | } | ||
353 | break; | 354 | break; | ||
354 | } | 355 | } | ||
355 | case XCB_MAP_NOTIFY: { // from SubstructureNotifyMask on the root window | 356 | case XCB_MAP_NOTIFY: { // from SubstructureNotifyMask on the root window | ||
356 | xcb_map_notify_event_t *xm = reinterpret_cast<xcb_map_notify_event_t*>(event); | 357 | xcb_map_notify_event_t *xm = reinterpret_cast<xcb_map_notify_event_t*>(event); | ||
357 | if (xm->event == QX11Info::appRootWindow()) { | 358 | if (xm->event == QX11Info::appRootWindow()) { | ||
358 | qDebug() << "MapNotify:" << xm->window; | 359 | qCDebug(KSCREENLOCKER) << "MapNotify:" << xm->window; | ||
359 | int index = findWindowInfo( xm->window ); | 360 | int index = findWindowInfo( xm->window ); | ||
360 | if( index >= 0 ) | 361 | if( index >= 0 ) | ||
361 | m_windowInfo[ index ].viewable = true; | 362 | m_windowInfo[ index ].viewable = true; | ||
362 | else | 363 | else | ||
363 | qDebug() << "Unknown toplevel for MapNotify"; | 364 | qCDebug(KSCREENLOCKER) << "Unknown toplevel for MapNotify"; | ||
364 | if (m_allowedWindows.contains(xm->window)) { | 365 | if (m_allowedWindows.contains(xm->window)) { | ||
365 | if (m_lockWindows.contains(xm->window)) { | 366 | if (m_lockWindows.contains(xm->window)) { | ||
366 | qDebug() << "uhoh! duplicate!"; | 367 | qCDebug(KSCREENLOCKER) << "uhoh! duplicate!"; | ||
367 | } else { | 368 | } else { | ||
368 | if (!m_background->isVisible()) { | 369 | if (!m_background->isVisible()) { | ||
369 | // not yet shown and we have a lock window, so we show our own window | 370 | // not yet shown and we have a lock window, so we show our own window | ||
370 | m_background->show(); | 371 | m_background->show(); | ||
371 | } | 372 | } | ||
372 | m_lockWindows.prepend(xm->window); | 373 | m_lockWindows.prepend(xm->window); | ||
373 | fakeFocusIn(xm->window); | 374 | fakeFocusIn(xm->window); | ||
374 | } | 375 | } | ||
375 | } | 376 | } | ||
376 | if (xm->window == m_background->winId()) { | 377 | if (xm->window == m_background->winId()) { | ||
377 | m_background->update(); | 378 | m_background->update(); | ||
378 | emit lockWindowShown(); | 379 | emit lockWindowShown(); | ||
379 | return false; | 380 | return false; | ||
380 | } | 381 | } | ||
381 | stayOnTop(); | 382 | stayOnTop(); | ||
382 | ret = true; | 383 | ret = true; | ||
383 | } | 384 | } | ||
384 | break; | 385 | break; | ||
385 | } | 386 | } | ||
386 | case XCB_UNMAP_NOTIFY: { | 387 | case XCB_UNMAP_NOTIFY: { | ||
387 | xcb_unmap_notify_event_t *xu = reinterpret_cast<xcb_unmap_notify_event_t*>(event); | 388 | xcb_unmap_notify_event_t *xu = reinterpret_cast<xcb_unmap_notify_event_t*>(event); | ||
388 | if (xu->event == QX11Info::appRootWindow()) { | 389 | if (xu->event == QX11Info::appRootWindow()) { | ||
389 | qDebug() << "UnmapNotify:" << xu->window; | 390 | qCDebug(KSCREENLOCKER) << "UnmapNotify:" << xu->window; | ||
390 | int index = findWindowInfo( xu->window ); | 391 | int index = findWindowInfo( xu->window ); | ||
391 | if( index >= 0 ) | 392 | if( index >= 0 ) | ||
392 | m_windowInfo[ index ].viewable = false; | 393 | m_windowInfo[ index ].viewable = false; | ||
393 | else | 394 | else | ||
394 | qDebug() << "Unknown toplevel for MapNotify"; | 395 | qCDebug(KSCREENLOCKER) << "Unknown toplevel for MapNotify"; | ||
395 | m_lockWindows.removeAll(xu->window); | 396 | m_lockWindows.removeAll(xu->window); | ||
396 | if (m_focusedLockWindow == xu->event && !m_lockWindows.empty()) { | 397 | if (m_focusedLockWindow == xu->event && !m_lockWindows.empty()) { | ||
397 | // The currently focused window vanished, just focus the first one in the list | 398 | // The currently focused window vanished, just focus the first one in the list | ||
398 | fakeFocusIn(m_lockWindows[0]); | 399 | fakeFocusIn(m_lockWindows[0]); | ||
399 | } | 400 | } | ||
400 | ret = true; | 401 | ret = true; | ||
401 | } | 402 | } | ||
402 | break; | 403 | break; | ||
403 | } | 404 | } | ||
404 | case XCB_CREATE_NOTIFY: { | 405 | case XCB_CREATE_NOTIFY: { | ||
405 | xcb_create_notify_event_t *xc = reinterpret_cast<xcb_create_notify_event_t*>(event); | 406 | xcb_create_notify_event_t *xc = reinterpret_cast<xcb_create_notify_event_t*>(event); | ||
406 | if (xc->parent == QX11Info::appRootWindow()) { | 407 | if (xc->parent == QX11Info::appRootWindow()) { | ||
407 | qDebug() << "CreateNotify:" << xc->window; | 408 | qCDebug(KSCREENLOCKER) << "CreateNotify:" << xc->window; | ||
408 | int index = findWindowInfo( xc->window ); | 409 | int index = findWindowInfo( xc->window ); | ||
409 | if( index >= 0 ) | 410 | if( index >= 0 ) | ||
410 | qDebug() << "Already existing toplevel for CreateNotify"; | 411 | qCDebug(KSCREENLOCKER) << "Already existing toplevel for CreateNotify"; | ||
411 | else { | 412 | else { | ||
412 | WindowInfo info; | 413 | WindowInfo info; | ||
413 | info.window = xc->window; | 414 | info.window = xc->window; | ||
414 | info.viewable = false; | 415 | info.viewable = false; | ||
415 | m_windowInfo.append( info ); | 416 | m_windowInfo.append( info ); | ||
416 | } | 417 | } | ||
417 | ret = true; | 418 | ret = true; | ||
418 | } | 419 | } | ||
419 | break; | 420 | break; | ||
420 | } | 421 | } | ||
421 | case XCB_DESTROY_NOTIFY: { | 422 | case XCB_DESTROY_NOTIFY: { | ||
422 | xcb_destroy_notify_event_t *xd = reinterpret_cast<xcb_destroy_notify_event_t *>(event); | 423 | xcb_destroy_notify_event_t *xd = reinterpret_cast<xcb_destroy_notify_event_t *>(event); | ||
423 | if (xd->event == QX11Info::appRootWindow()) { | 424 | if (xd->event == QX11Info::appRootWindow()) { | ||
424 | int index = findWindowInfo( xd->window ); | 425 | int index = findWindowInfo( xd->window ); | ||
425 | if( index >= 0 ) | 426 | if( index >= 0 ) | ||
426 | m_windowInfo.removeAt( index ); | 427 | m_windowInfo.removeAt( index ); | ||
427 | else | 428 | else | ||
428 | qDebug() << "Unknown toplevel for DestroyNotify"; | 429 | qCDebug(KSCREENLOCKER) << "Unknown toplevel for DestroyNotify"; | ||
429 | ret = true; | 430 | ret = true; | ||
430 | } | 431 | } | ||
431 | break; | 432 | break; | ||
432 | } | 433 | } | ||
433 | case XCB_REPARENT_NOTIFY: { | 434 | case XCB_REPARENT_NOTIFY: { | ||
434 | xcb_reparent_notify_event_t *xr = reinterpret_cast<xcb_reparent_notify_event_t*>(event); | 435 | xcb_reparent_notify_event_t *xr = reinterpret_cast<xcb_reparent_notify_event_t*>(event); | ||
435 | if (xr->event == QX11Info::appRootWindow() && xr->parent != QX11Info::appRootWindow()) { | 436 | if (xr->event == QX11Info::appRootWindow() && xr->parent != QX11Info::appRootWindow()) { | ||
436 | int index = findWindowInfo( xr->window ); | 437 | int index = findWindowInfo( xr->window ); | ||
437 | if( index >= 0 ) | 438 | if( index >= 0 ) | ||
438 | m_windowInfo.removeAt( index ); | 439 | m_windowInfo.removeAt( index ); | ||
439 | else | 440 | else | ||
440 | qDebug() << "Unknown toplevel for ReparentNotify away"; | 441 | qCDebug(KSCREENLOCKER) << "Unknown toplevel for ReparentNotify away"; | ||
441 | } else if (xr->parent == QX11Info::appRootWindow()) { | 442 | } else if (xr->parent == QX11Info::appRootWindow()) { | ||
442 | int index = findWindowInfo( xr->window ); | 443 | int index = findWindowInfo( xr->window ); | ||
443 | if( index >= 0 ) | 444 | if( index >= 0 ) | ||
444 | qDebug() << "Already existing toplevel for ReparentNotify"; | 445 | qCDebug(KSCREENLOCKER) << "Already existing toplevel for ReparentNotify"; | ||
445 | else { | 446 | else { | ||
446 | WindowInfo info; | 447 | WindowInfo info; | ||
447 | info.window = xr->window; | 448 | info.window = xr->window; | ||
448 | info.viewable = false; | 449 | info.viewable = false; | ||
449 | m_windowInfo.append( info ); | 450 | m_windowInfo.append( info ); | ||
450 | } | 451 | } | ||
451 | } | 452 | } | ||
452 | break; | 453 | break; | ||
453 | } | 454 | } | ||
454 | case XCB_CIRCULATE_NOTIFY: { | 455 | case XCB_CIRCULATE_NOTIFY: { | ||
455 | xcb_circulate_notify_event_t *xc = reinterpret_cast<xcb_circulate_notify_event_t*>(event); | 456 | xcb_circulate_notify_event_t *xc = reinterpret_cast<xcb_circulate_notify_event_t*>(event); | ||
456 | if (xc->event == QX11Info::appRootWindow()) { | 457 | if (xc->event == QX11Info::appRootWindow()) { | ||
457 | int index = findWindowInfo( xc->window ); | 458 | int index = findWindowInfo( xc->window ); | ||
458 | if( index >= 0 ) { | 459 | if( index >= 0 ) { | ||
459 | m_windowInfo.move( index, xc->place == PlaceOnTop ? m_windowInfo.size() - 1 : 0 ); | 460 | m_windowInfo.move( index, xc->place == PlaceOnTop ? m_windowInfo.size() - 1 : 0 ); | ||
460 | } else | 461 | } else | ||
461 | qDebug() << "Unknown toplevel for CirculateNotify"; | 462 | qCDebug(KSCREENLOCKER) << "Unknown toplevel for CirculateNotify"; | ||
462 | } | 463 | } | ||
463 | break; | 464 | break; | ||
464 | } | 465 | } | ||
465 | } | 466 | } | ||
466 | return ret; | 467 | return ret; | ||
467 | } | 468 | } | ||
468 | 469 | | |||
469 | int X11Locker::findWindowInfo(Window w) | 470 | int X11Locker::findWindowInfo(Window w) | ||
Show All 38 Lines | |||||
508 | { | 509 | { | ||
509 | m_allowedWindows << window; | 510 | m_allowedWindows << window; | ||
510 | // test whether it's to show | 511 | // test whether it's to show | ||
511 | const int index = findWindowInfo( window ); | 512 | const int index = findWindowInfo( window ); | ||
512 | if (index == -1 || !m_windowInfo[ index ].viewable) { | 513 | if (index == -1 || !m_windowInfo[ index ].viewable) { | ||
513 | return; | 514 | return; | ||
514 | } | 515 | } | ||
515 | if (m_lockWindows.contains(window)) { | 516 | if (m_lockWindows.contains(window)) { | ||
516 | qDebug() << "uhoh! duplicate!"; | 517 | qCDebug(KSCREENLOCKER) << "uhoh! duplicate!"; | ||
517 | } else { | 518 | } else { | ||
518 | if (!m_background->isVisible()) { | 519 | if (!m_background->isVisible()) { | ||
519 | // not yet shown and we have a lock window, so we show our own window | 520 | // not yet shown and we have a lock window, so we show our own window | ||
520 | m_background->show(); | 521 | m_background->show(); | ||
521 | } | 522 | } | ||
522 | 523 | | |||
523 | if (m_lockWindows.empty()) { | 524 | if (m_lockWindows.empty()) { | ||
524 | // Make sure to focus the first window | 525 | // Make sure to focus the first window | ||
Show All 10 Lines |