TDE base libraries and programs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lockprocess.cc 85KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789
  1. //===========================================================================
  2. //
  3. // This file is part of the KDE project
  4. //
  5. // Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
  6. // Copyright (c) 2003 Oswald Buddenhagen <ossi@kde.org>
  7. // Copyright (c) 2010-2013 Timothy Pearson <kb9vqf@pearsoncomputing.net>
  8. //
  9. //kdesktop keeps running and checks user inactivity
  10. //when it should show screensaver (and maybe lock the session),
  11. //it starts kdesktop_lock, who does all the locking and who
  12. //actually starts the screensaver
  13. //It's done this way to prevent screen unlocking when kdesktop
  14. //crashes (e.g. because it's set to multiple wallpapers and
  15. //some image will be corrupted).
  16. #define protected public
  17. #include <tqwidget.h>
  18. #undef protected
  19. #include <config.h>
  20. #include <execinfo.h>
  21. #include "lockprocess.h"
  22. #include "lockdlg.h"
  23. #include "infodlg.h"
  24. #include "querydlg.h"
  25. #include "sakdlg.h"
  26. #include "securedlg.h"
  27. #include "autologout.h"
  28. #include "kdesktopsettings.h"
  29. #include <dmctl.h>
  30. #include <dcopref.h>
  31. #include <kstandarddirs.h>
  32. #include <tdeapplication.h>
  33. #include <kservicegroup.h>
  34. #include <kdebug.h>
  35. #include <tdemessagebox.h>
  36. #include <tdeglobalsettings.h>
  37. #include <tdelocale.h>
  38. #include <klibloader.h>
  39. #include <kpushbutton.h>
  40. #include <kstdguiitem.h>
  41. #include <kpixmapeffect.h>
  42. #include <kpixmap.h>
  43. #include <twin.h>
  44. #include <twinmodule.h>
  45. #include <kdialog.h>
  46. #include <tqframe.h>
  47. #include <tqlabel.h>
  48. #include <tqlayout.h>
  49. #include <tqcursor.h>
  50. #include <tqtimer.h>
  51. #include <tqfile.h>
  52. #include <tqsocketnotifier.h>
  53. #include <tqvaluevector.h>
  54. #include <tqtooltip.h>
  55. #include <tqimage.h>
  56. #include <tqregexp.h>
  57. #include <tqpainter.h>
  58. #include <tqeventloop.h>
  59. #include <tqdatetime.h>
  60. #include <stdlib.h>
  61. #include <assert.h>
  62. #include <signal.h>
  63. #ifdef HAVE_SETPRIORITY
  64. #include <sys/time.h>
  65. #include <sys/resource.h>
  66. #endif
  67. #include <stdio.h>
  68. #include <sys/stat.h>
  69. #include <unistd.h>
  70. #include <errno.h>
  71. #include <ctype.h>
  72. #include <sys/types.h>
  73. #include <fcntl.h>
  74. #include <kcrash.h>
  75. #include <linux/stat.h>
  76. #include <X11/Xlib.h>
  77. #include <X11/Xutil.h>
  78. #include <X11/keysym.h>
  79. #include <X11/Xatom.h>
  80. #include <X11/Intrinsic.h>
  81. #ifdef HAVE_DPMS
  82. extern "C" {
  83. #include <X11/Xmd.h>
  84. #ifndef Bool
  85. #define Bool BOOL
  86. #endif
  87. #include <X11/extensions/dpms.h>
  88. #ifndef HAVE_DPMSINFO_PROTO
  89. Status DPMSInfo ( Display *, CARD16 *, BOOL * );
  90. #endif
  91. }
  92. #endif
  93. #ifdef HAVE_XF86MISC
  94. #include <X11/extensions/xf86misc.h>
  95. #endif
  96. #ifdef HAVE_GLXCHOOSEVISUAL
  97. #include <GL/glx.h>
  98. #endif
  99. #define LOCK_GRACE_DEFAULT 5000
  100. #define AUTOLOGOUT_DEFAULT 600
  101. #define DESKTOP_WALLPAPER_OBTAIN_TIMEOUT_MS 3000
  102. // Setting this define is INSECURE
  103. // Use it for debugging purposes ONLY
  104. // #define KEEP_MOUSE_UNGRABBED 1
  105. // These lines are taken on 10/2009 from X.org (X11/XF86keysym.h), defining some special multimedia keys
  106. #define XF86XK_AudioMute 0x1008FF12
  107. #define XF86XK_AudioRaiseVolume 0x1008FF13
  108. #define XF86XK_AudioLowerVolume 0x1008FF11
  109. #define XF86XK_Display 0x1008FF59
  110. #define DPMS_MONITOR_BLANKED(x) ((x == DPMSModeStandby) || (x == DPMSModeSuspend) || (x == DPMSModeOff))
  111. static Window gVRoot = 0;
  112. static Window gVRootData = 0;
  113. static Atom gXA_VROOT;
  114. static Atom gXA_SCREENSAVER_VERSION;
  115. void print_trace()
  116. {
  117. #ifdef WITH_KDESKTOP_LOCK_BACKTRACE
  118. void *array[10];
  119. size_t size;
  120. char **strings;
  121. size_t i;
  122. size = backtrace (array, 10);
  123. strings = backtrace_symbols (array, size);
  124. printf ("[kdesktop_lock] Obtained %zd stack frames.\n", size);
  125. for (i = 0; i < size; i++) {
  126. printf ("[kdesktop_lock] %s\n", strings[i]);
  127. }
  128. free (strings);
  129. #endif
  130. }
  131. static void segv_handler(int)
  132. {
  133. printf("[kdesktop_lock] WARNING: A fatal exception was encountered. Trapping and ignoring it so as not to compromise desktop security...\n");
  134. print_trace();
  135. sleep(1);
  136. }
  137. extern Atom tqt_wm_state;
  138. extern bool trinity_desktop_lock_use_system_modal_dialogs;
  139. extern bool trinity_desktop_lock_delay_screensaver_start;
  140. extern bool trinity_desktop_lock_use_sak;
  141. extern bool trinity_desktop_lock_hide_active_windows;
  142. extern bool trinity_desktop_lock_forced;
  143. extern bool argb_visual;
  144. extern TQXLibWindowList trinity_desktop_lock_hidden_window_list;
  145. bool trinity_desktop_lock_autohide_lockdlg = TRUE;
  146. bool trinity_desktop_lock_closing_windows = FALSE;
  147. bool trinity_desktop_lock_in_sec_dlg = FALSE;
  148. bool trinity_desktop_hack_active = FALSE;
  149. #define ENABLE_CONTINUOUS_LOCKDLG_DISPLAY \
  150. if (!mForceContinualLockDisplayTimer->isActive()) mForceContinualLockDisplayTimer->start(100, FALSE); \
  151. trinity_desktop_lock_autohide_lockdlg = FALSE; \
  152. mHackDelayStartupTimer->stop();
  153. #define DISABLE_CONTINUOUS_LOCKDLG_DISPLAY \
  154. mForceContinualLockDisplayTimer->stop(); \
  155. trinity_desktop_lock_autohide_lockdlg = TRUE; \
  156. mHackDelayStartupTimer->stop();
  157. //===========================================================================
  158. //
  159. // Screen saver handling process. Handles screensaver window,
  160. // starting screensaver hacks, and password entry.
  161. //
  162. LockProcess::LockProcess()
  163. : TQWidget(0L, "saver window", ((WFlags)(WStyle_StaysOnTop|WStyle_Customize|WStyle_NoBorder))),
  164. mOpenGLVisual(0),
  165. mParent(0),
  166. mShowLockDateTime(false),
  167. mSuspended(false),
  168. mVisibility(false),
  169. mRestoreXF86Lock(false),
  170. mForbidden(false),
  171. mAutoLogout(false),
  172. resizeTimer(NULL),
  173. hackResumeTimer(NULL),
  174. mVkbdProcess(NULL),
  175. mKWinModule(NULL),
  176. mPipeOpen(false),
  177. mPipeOpen_out(false),
  178. mInfoMessageDisplayed(false),
  179. mDialogControlLock(false),
  180. mForceReject(false),
  181. currentDialog(NULL),
  182. mEnsureScreenHiddenTimer(NULL),
  183. mForceContinualLockDisplayTimer(NULL),
  184. mEnsureVRootWindowSecurityTimer(NULL),
  185. mHackDelayStartupTimer(NULL),
  186. mHackDelayStartupTimeout(0),
  187. mHackStartupEnabled(true),
  188. mOverrideHackStartupEnabled(false),
  189. mResizingDesktopLock(false),
  190. m_rootPixmap(NULL),
  191. mBackingStartupDelayTimer(0),
  192. m_startupStatusDialog(NULL),
  193. m_mouseDown(0),
  194. m_mousePrevX(0),
  195. m_mousePrevY(0),
  196. m_dialogPrevX(0),
  197. m_dialogPrevY(0),
  198. m_maskWidget(NULL)
  199. {
  200. #ifdef KEEP_MOUSE_UNGRABBED
  201. setNFlags(WX11DisableMove|WX11DisableClose|WX11DisableShade|WX11DisableMinimize|WX11DisableMaximize);
  202. #endif
  203. setupSignals();
  204. // Signal that we want to be transparent to the desktop, not to windows behind us...
  205. Atom kde_wm_transparent_to_desktop;
  206. kde_wm_transparent_to_desktop = XInternAtom(tqt_xdisplay(), "_KDE_TRANSPARENT_TO_DESKTOP", False);
  207. XChangeProperty(tqt_xdisplay(), winId(), kde_wm_transparent_to_desktop, XA_INTEGER, 32, PropModeReplace, (unsigned char *) "TRUE", 1L);
  208. kapp->installX11EventFilter(this);
  209. mForceContinualLockDisplayTimer = new TQTimer( this );
  210. mHackDelayStartupTimer = new TQTimer( this );
  211. mEnsureVRootWindowSecurityTimer = new TQTimer( this );
  212. if (!argb_visual) {
  213. // Try to get the root pixmap
  214. if (!m_rootPixmap) m_rootPixmap = new KRootPixmap(this);
  215. connect(m_rootPixmap, TQT_SIGNAL(backgroundUpdated(const TQPixmap &)), this, TQT_SLOT(slotPaintBackground(const TQPixmap &)));
  216. m_rootPixmap->setCustomPainting(true);
  217. m_rootPixmap->start();
  218. }
  219. // Get root window attributes
  220. XWindowAttributes rootAttr;
  221. XGetWindowAttributes(tqt_xdisplay(), RootWindow(tqt_xdisplay(), tqt_xscreen()), &rootAttr);
  222. { // trigger creation of QToolTipManager, it does XSelectInput() on the root window
  223. TQWidget w;
  224. TQToolTip::add( &w, "foo" );
  225. }
  226. XSelectInput( tqt_xdisplay(), tqt_xrootwin(), SubstructureNotifyMask | rootAttr.your_event_mask );
  227. // Add non-TDE path
  228. TDEGlobal::dirs()->addResourceType("scrsav",
  229. TDEGlobal::dirs()->kde_default("apps") +
  230. "System/ScreenSavers/");
  231. // Add KDE specific screensaver path
  232. TQString relPath="System/ScreenSavers/";
  233. KServiceGroup::Ptr servGroup = KServiceGroup::baseGroup( "screensavers");
  234. if (servGroup)
  235. {
  236. relPath=servGroup->relPath();
  237. kdDebug(1204) << "relPath=" << relPath << endl;
  238. }
  239. TDEGlobal::dirs()->addResourceType("scrsav",
  240. TDEGlobal::dirs()->kde_default("apps") +
  241. relPath);
  242. // virtual root property
  243. gXA_VROOT = XInternAtom (tqt_xdisplay(), "__SWM_VROOT", False);
  244. gXA_SCREENSAVER_VERSION = XInternAtom (tqt_xdisplay(), "_SCREENSAVER_VERSION", False);
  245. TQStringList dmopt =
  246. TQStringList::split(TQChar(','),
  247. TQString::fromLatin1( ::getenv( "XDM_MANAGED" )));
  248. for (TQStringList::ConstIterator it = dmopt.begin(); it != dmopt.end(); ++it)
  249. if ((*it).startsWith("method="))
  250. mMethod = (*it).mid(7);
  251. #ifdef KEEP_MOUSE_UNGRABBED
  252. setEnabled(false);
  253. #endif
  254. greetPlugin.library = 0;
  255. TDECrash::setCrashHandler(segv_handler);
  256. }
  257. //---------------------------------------------------------------------------
  258. //
  259. // Destructor - usual cleanups.
  260. //
  261. LockProcess::~LockProcess()
  262. {
  263. mControlPipeHandlerThread->terminate();
  264. mControlPipeHandlerThread->wait();
  265. delete mControlPipeHandler;
  266. // delete mControlPipeHandlerThread;
  267. if (resizeTimer != NULL) {
  268. resizeTimer->stop();
  269. delete resizeTimer;
  270. }
  271. if (hackResumeTimer != NULL) {
  272. hackResumeTimer->stop();
  273. delete hackResumeTimer;
  274. }
  275. if (mEnsureScreenHiddenTimer != NULL) {
  276. mEnsureScreenHiddenTimer->stop();
  277. delete mEnsureScreenHiddenTimer;
  278. }
  279. if (mForceContinualLockDisplayTimer != NULL) {
  280. mForceContinualLockDisplayTimer->stop();
  281. delete mForceContinualLockDisplayTimer;
  282. }
  283. if (mHackDelayStartupTimer != NULL) {
  284. mHackDelayStartupTimer->stop();
  285. delete mHackDelayStartupTimer;
  286. }
  287. if (mEnsureVRootWindowSecurityTimer != NULL) {
  288. mEnsureVRootWindowSecurityTimer->stop();
  289. delete mEnsureVRootWindowSecurityTimer;
  290. }
  291. if (greetPlugin.library) {
  292. if (greetPlugin.info->done)
  293. greetPlugin.info->done();
  294. greetPlugin.library->unload();
  295. }
  296. if (m_rootPixmap) {
  297. m_rootPixmap->stop();
  298. delete m_rootPixmap;
  299. }
  300. mPipeOpen = false;
  301. mPipeOpen_out = false;
  302. }
  303. //---------------------------------------------------------------------------
  304. //
  305. // Initialization for startup
  306. // This is where instance settings should be set--all objects should have already been created in the constructor above
  307. //
  308. void LockProcess::init(bool child, bool useBlankOnly)
  309. {
  310. // Get root window size
  311. XWindowAttributes rootAttr;
  312. XGetWindowAttributes(tqt_xdisplay(), RootWindow(tqt_xdisplay(), tqt_xscreen()), &rootAttr);
  313. mRootWidth = rootAttr.width;
  314. mRootHeight = rootAttr.height;
  315. // Connect all signals
  316. connect( mForceContinualLockDisplayTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(displayLockDialogIfNeeded()) );
  317. connect( mHackDelayStartupTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(closeDialogAndStartHack()) );
  318. connect( mEnsureVRootWindowSecurityTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(repaintRootWindowIfNeeded()) );
  319. connect(tqApp, TQT_SIGNAL(mouseInteraction(XEvent *)), TQT_SLOT(slotMouseActivity(XEvent *)));
  320. connect(&mHackProc, TQT_SIGNAL(processExited(TDEProcess *)), TQT_SLOT(hackExited(TDEProcess *)));
  321. connect(&mSuspendTimer, TQT_SIGNAL(timeout()), TQT_SLOT(suspend()));
  322. #ifdef HAVE_DPMS
  323. //if the user decided that the screensaver should run independent from
  324. //dpms, we shouldn't check for it, aleXXX
  325. if (KDesktopSettings::dpmsDependent()) {
  326. BOOL on;
  327. CARD16 state;
  328. if (DPMSInfo(tqt_xdisplay(), &state, &on)) {
  329. if (on) {
  330. connect(&mCheckDPMS, TQT_SIGNAL(timeout()), TQT_SLOT(checkDPMSActive()));
  331. // we can save CPU if we stop it as quickly as possible
  332. // but we waste CPU if we check too often -> so take 10s
  333. mCheckDPMS.start(10000);
  334. }
  335. }
  336. }
  337. #endif
  338. #if (TQT_VERSION-0 >= 0x030200) // XRANDR support
  339. connect( kapp->desktop(), TQT_SIGNAL( resized( int )), TQT_SLOT( desktopResized()));
  340. #endif
  341. if (!trinity_desktop_lock_use_system_modal_dialogs) {
  342. setWFlags((WFlags)WX11BypassWM);
  343. }
  344. child_saver = child;
  345. mUseBlankOnly = useBlankOnly;
  346. mShowLockDateTime = KDesktopSettings::showLockDateTime();
  347. mlockDateTime = TQDateTime::currentDateTime();
  348. mHackDelayStartupTimeout = trinity_desktop_lock_delay_screensaver_start?KDesktopSettings::timeout()*1000:10*1000;
  349. mHackStartupEnabled = trinity_desktop_lock_use_system_modal_dialogs?KDesktopSettings::screenSaverEnabled():true;
  350. configure();
  351. mControlPipeHandlerThread = new TQEventLoopThread();
  352. mControlPipeHandler = new ControlPipeHandlerObject();
  353. mControlPipeHandler->mParent = this;
  354. mControlPipeHandler->moveToThread(mControlPipeHandlerThread);
  355. TQObject::connect(mControlPipeHandler, SIGNAL(processCommand(TQString)), this, SLOT(processInputPipeCommand(TQString)));
  356. TQTimer::singleShot(0, mControlPipeHandler, SLOT(run()));
  357. mControlPipeHandlerThread->start();
  358. }
  359. static int signal_pipe[2];
  360. static void sigterm_handler(int)
  361. {
  362. if (!trinity_desktop_lock_in_sec_dlg) {
  363. // Exit uncleanly
  364. exit(1);
  365. }
  366. }
  367. static void sighup_handler(int)
  368. {
  369. char tmp = 'H';
  370. if (::write( signal_pipe[1], &tmp, 1) == -1) {
  371. // Error handler to shut up gcc warnings
  372. }
  373. }
  374. bool LockProcess::closeCurrentWindow()
  375. {
  376. trinity_desktop_lock_closing_windows = TRUE;
  377. if (currentDialog != NULL) {
  378. mForceReject = true;
  379. if (dynamic_cast<SAKDlg*>(currentDialog)) {
  380. dynamic_cast<SAKDlg*>(currentDialog)->closeDialogForced();
  381. }
  382. else if (dynamic_cast<SecureDlg*>(currentDialog)) {
  383. dynamic_cast<SecureDlg*>(currentDialog)->closeDialogForced();
  384. }
  385. else {
  386. currentDialog->close();
  387. }
  388. }
  389. if( mDialogs.isEmpty() ) {
  390. trinity_desktop_lock_closing_windows = FALSE;
  391. mForceReject = false;
  392. return false;
  393. }
  394. else {
  395. trinity_desktop_lock_closing_windows = TRUE;
  396. return true;
  397. }
  398. }
  399. void LockProcess::timerEvent(TQTimerEvent *ev)
  400. {
  401. if (mAutoLogout && ev->timerId() == mAutoLogoutTimerId)
  402. {
  403. killTimer(mAutoLogoutTimerId);
  404. AutoLogout autologout(this);
  405. execDialog(&autologout);
  406. }
  407. }
  408. void LockProcess::resizeEvent(TQResizeEvent *)
  409. {
  410. //
  411. }
  412. void LockProcess::setupSignals()
  413. {
  414. struct sigaction act;
  415. // ignore SIGINT
  416. act.sa_handler=SIG_IGN;
  417. sigemptyset(&(act.sa_mask));
  418. sigaddset(&(act.sa_mask), SIGINT);
  419. act.sa_flags = 0;
  420. sigaction(SIGINT, &act, 0L);
  421. // ignore SIGQUIT
  422. act.sa_handler=SIG_IGN;
  423. sigemptyset(&(act.sa_mask));
  424. sigaddset(&(act.sa_mask), SIGQUIT);
  425. act.sa_flags = 0;
  426. sigaction(SIGQUIT, &act, 0L);
  427. // exit uncleanly on SIGTERM
  428. act.sa_handler= sigterm_handler;
  429. sigemptyset(&(act.sa_mask));
  430. sigaddset(&(act.sa_mask), SIGTERM);
  431. act.sa_flags = 0;
  432. sigaction(SIGTERM, &act, 0L);
  433. // SIGHUP forces lock
  434. act.sa_handler= sighup_handler;
  435. sigemptyset(&(act.sa_mask));
  436. sigaddset(&(act.sa_mask), SIGHUP);
  437. act.sa_flags = 0;
  438. sigaction(SIGHUP, &act, 0L);
  439. if (pipe(signal_pipe) == -1) {
  440. // Error handler to shut up gcc warnings
  441. }
  442. TQSocketNotifier* notif = new TQSocketNotifier(signal_pipe[0], TQSocketNotifier::Read, TQT_TQOBJECT(this) );
  443. connect( notif, TQT_SIGNAL(activated(int)), TQT_SLOT(signalPipeSignal()));
  444. }
  445. void LockProcess::signalPipeSignal()
  446. {
  447. char tmp;
  448. if (::read( signal_pipe[0], &tmp, 1) == -1) {
  449. // Error handler to shut up gcc warnings
  450. }
  451. if( tmp == 'T' )
  452. quitSaver();
  453. else if( tmp == 'H' ) {
  454. if( !mLocked )
  455. startLock();
  456. }
  457. }
  458. //---------------------------------------------------------------------------
  459. bool LockProcess::lock()
  460. {
  461. #ifdef USE_SECURING_DESKTOP_NOTIFICATION
  462. m_startupStatusDialog = new KSMModalDialog(this);
  463. m_startupStatusDialog->setStatusMessage(i18n("Securing desktop session").append("..."));
  464. m_startupStatusDialog->show();
  465. m_startupStatusDialog->setActiveWindow();
  466. tqApp->processEvents();
  467. #endif
  468. if (startSaver()) {
  469. // In case of a forced lock we don't react to events during
  470. // the dead-time to give the screensaver some time to activate.
  471. // That way we don't accidentally show the password dialog before
  472. // the screensaver kicks in because the user moved the mouse after
  473. // selecting "lock screen", that looks really untidy.
  474. mBusy = true;
  475. if (startLock())
  476. {
  477. TQTimer::singleShot(1000, this, TQT_SLOT(slotDeadTimePassed()));
  478. return true;
  479. }
  480. stopSaver();
  481. mBusy = false;
  482. }
  483. return false;
  484. }
  485. //---------------------------------------------------------------------------
  486. void LockProcess::slotDeadTimePassed()
  487. {
  488. mBusy = false;
  489. }
  490. //---------------------------------------------------------------------------
  491. bool LockProcess::defaultSave()
  492. {
  493. mLocked = false;
  494. mOverrideHackStartupEnabled = true;
  495. if (startSaver()) {
  496. if (mLockGrace >= 0)
  497. TQTimer::singleShot(mLockGrace, this, TQT_SLOT(startLock()));
  498. return true;
  499. }
  500. return false;
  501. }
  502. //---------------------------------------------------------------------------
  503. bool LockProcess::dontLock()
  504. {
  505. mLocked = false;
  506. return startSaver();
  507. }
  508. //---------------------------------------------------------------------------
  509. void LockProcess::quitSaver()
  510. {
  511. DISABLE_CONTINUOUS_LOCKDLG_DISPLAY
  512. if (closeCurrentWindow()) {
  513. TQTimer::singleShot( 0, this, SLOT(quitSaver()) );
  514. return;
  515. }
  516. stopSaver();
  517. kapp->quit();
  518. }
  519. //---------------------------------------------------------------------------
  520. void LockProcess::startSecureDialog()
  521. {
  522. if ((backingPixmap.isNull()) && (mBackingStartupDelayTimer < 100)) {
  523. TQTimer::singleShot(10, this, TQT_SLOT(startSecureDialog()));
  524. mBackingStartupDelayTimer++;
  525. return;
  526. }
  527. setGeometry(0, 0, mRootWidth, mRootHeight);
  528. int ret;
  529. SecureDlg inDlg( this );
  530. inDlg.setRetInt(&ret);
  531. mBusy = true;
  532. execDialog( &inDlg );
  533. mBusy = false;
  534. bool forcecontdisp = mForceContinualLockDisplayTimer->isActive();
  535. if (forcecontdisp) {
  536. DISABLE_CONTINUOUS_LOCKDLG_DISPLAY
  537. }
  538. trinity_desktop_lock_in_sec_dlg = false;
  539. if (ret == 0) {
  540. trinity_desktop_lock_closing_windows = 1;
  541. kapp->quit();
  542. }
  543. if (ret == 1) {
  544. // In case of a forced lock we don't react to events during
  545. // the dead-time to give the screensaver some time to activate.
  546. // That way we don't accidentally show the password dialog before
  547. // the screensaver kicks in because the user moved the mouse after
  548. // selecting "lock screen", that looks really untidy.
  549. mBusy = true;
  550. trinity_desktop_lock_forced = true;
  551. // Make sure the cursor is not showing busy status
  552. setCursor( tqarrowCursor );
  553. if (startLock())
  554. {
  555. if (trinity_desktop_lock_delay_screensaver_start) {
  556. mBusy = false;
  557. }
  558. else {
  559. TQTimer::singleShot(1000, this, TQT_SLOT(slotDeadTimePassed()));
  560. }
  561. if (trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced && trinity_desktop_lock_use_system_modal_dialogs) {
  562. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  563. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  564. }
  565. else {
  566. if (mHackStartupEnabled == true) {
  567. startHack();
  568. }
  569. else {
  570. if (trinity_desktop_lock_use_system_modal_dialogs == true) {
  571. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  572. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  573. }
  574. else {
  575. startHack();
  576. }
  577. }
  578. }
  579. return;
  580. }
  581. stopSaver();
  582. mBusy = false;
  583. return;
  584. }
  585. if (ret == 2) {
  586. trinity_desktop_lock_closing_windows = 1;
  587. if (system("ksysguard &") == -1) {
  588. // Error handler to shut up gcc warnings
  589. }
  590. kapp->quit();
  591. }
  592. if (ret == 3) {
  593. trinity_desktop_lock_closing_windows = 1;
  594. DCOPRef("ksmserver","ksmserver").send("logout", (int)TDEApplication::ShutdownConfirmYes, (int)TDEApplication::ShutdownTypeNone, (int)TDEApplication::ShutdownModeInteractive);
  595. kapp->quit();
  596. }
  597. // FIXME
  598. // Handle remaining case (switch user)
  599. if (forcecontdisp) {
  600. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  601. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  602. }
  603. stopSaver();
  604. }
  605. bool LockProcess::runSecureDialog()
  606. {
  607. #ifdef USE_SECURING_DESKTOP_NOTIFICATION
  608. m_startupStatusDialog = new KSMModalDialog(this);
  609. m_startupStatusDialog->setStatusMessage(i18n("Securing desktop session").append("..."));
  610. m_startupStatusDialog->show();
  611. m_startupStatusDialog->setActiveWindow();
  612. tqApp->processEvents();
  613. #endif
  614. trinity_desktop_lock_in_sec_dlg = true;
  615. if (startSaver()) {
  616. mBackingStartupDelayTimer = 0;
  617. TQTimer::singleShot(0, this, TQT_SLOT(startSecureDialog()));
  618. return true;
  619. }
  620. else {
  621. return false;
  622. }
  623. }
  624. //---------------------------------------------------------------------------
  625. //
  626. // Read and apply configuration.
  627. //
  628. void LockProcess::configure()
  629. {
  630. // the configuration is stored in kdesktop's config file
  631. if( KDesktopSettings::lock() )
  632. {
  633. mLockGrace = KDesktopSettings::lockGrace();
  634. if (mLockGrace < 0)
  635. mLockGrace = 0;
  636. else if (mLockGrace > 300000)
  637. mLockGrace = 300000; // 5 minutes, keep the value sane
  638. }
  639. else
  640. mLockGrace = -1;
  641. if ( KDesktopSettings::autoLogout() )
  642. {
  643. mAutoLogout = true;
  644. mAutoLogoutTimeout = KDesktopSettings::autoLogoutTimeout();
  645. mAutoLogoutTimerId = startTimer(mAutoLogoutTimeout * 1000); // in milliseconds
  646. }
  647. mPriority = KDesktopSettings::priority();
  648. if (mPriority < 0) mPriority = 0;
  649. if (mPriority > 19) mPriority = 19;
  650. mSaver = KDesktopSettings::saver();
  651. if (mSaver.isEmpty() || mUseBlankOnly) {
  652. mSaver = "KBlankscreen.desktop";
  653. }
  654. if (!trinity_desktop_lock_use_system_modal_dialogs) {
  655. if (KDesktopSettings::screenSaverEnabled() == false) {
  656. mSaver = "";
  657. mSaverExec = "";
  658. }
  659. }
  660. readSaver();
  661. mPlugins = KDesktopSettings::pluginsUnlock();
  662. if (mPlugins.isEmpty()) {
  663. mPlugins = TQStringList("classic");
  664. }
  665. mPluginOptions = KDesktopSettings::pluginOptions();
  666. }
  667. //---------------------------------------------------------------------------
  668. //
  669. // Read the command line needed to run the screensaver given a .desktop file.
  670. //
  671. void LockProcess::readSaver()
  672. {
  673. if (!mSaver.isEmpty())
  674. {
  675. TQString file = locate("scrsav", mSaver);
  676. bool opengl = kapp->authorize("opengl_screensavers");
  677. bool manipulatescreen = kapp->authorize("manipulatescreen_screensavers");
  678. KDesktopFile config(file, true);
  679. if (config.readEntry("X-TDE-Type").utf8() != 0)
  680. {
  681. TQString saverType = config.readEntry("X-TDE-Type").utf8();
  682. TQStringList saverTypes = TQStringList::split(";", saverType);
  683. for (uint i = 0; i < saverTypes.count(); i++)
  684. {
  685. if ((saverTypes[i] == "ManipulateScreen") && !manipulatescreen)
  686. {
  687. kdDebug(1204) << "Screensaver is type ManipulateScreen and ManipulateScreen is forbidden" << endl;
  688. mForbidden = true;
  689. }
  690. if ((saverTypes[i] == "OpenGL") && !opengl)
  691. {
  692. kdDebug(1204) << "Screensaver is type OpenGL and OpenGL is forbidden" << endl;
  693. mForbidden = true;
  694. }
  695. if (saverTypes[i] == "OpenGL")
  696. {
  697. mOpenGLVisual = true;
  698. }
  699. }
  700. }
  701. kdDebug(1204) << "mForbidden: " << (mForbidden ? "true" : "false") << endl;
  702. if (trinity_desktop_lock_use_system_modal_dialogs) {
  703. if (config.hasActionGroup("InWindow"))
  704. {
  705. config.setActionGroup("InWindow");
  706. mSaverExec = config.readPathEntry("Exec");
  707. }
  708. }
  709. else {
  710. if (config.hasActionGroup("Root"))
  711. {
  712. config.setActionGroup("Root");
  713. mSaverExec = config.readPathEntry("Exec");
  714. }
  715. }
  716. }
  717. }
  718. //---------------------------------------------------------------------------
  719. //
  720. // Create a window to draw our screen saver on.
  721. //
  722. void LockProcess::createSaverWindow()
  723. {
  724. Visual* visual = CopyFromParent;
  725. XSetWindowAttributes attrs;
  726. int flags = trinity_desktop_lock_use_system_modal_dialogs?0:CWOverrideRedirect;
  727. #ifdef HAVE_GLXCHOOSEVISUAL
  728. if( mOpenGLVisual )
  729. {
  730. static int attribs[][ 15 ] =
  731. {
  732. #define R GLX_RED_SIZE
  733. #define G GLX_GREEN_SIZE
  734. #define B GLX_BLUE_SIZE
  735. { GLX_RGBA, R, 8, G, 8, B, 8, GLX_DEPTH_SIZE, 8, GLX_DOUBLEBUFFER, GLX_STENCIL_SIZE, 1, None },
  736. { GLX_RGBA, R, 4, G, 4, B, 4, GLX_DEPTH_SIZE, 4, GLX_DOUBLEBUFFER, GLX_STENCIL_SIZE, 1, None },
  737. { GLX_RGBA, R, 8, G, 8, B, 8, GLX_DEPTH_SIZE, 8, GLX_DOUBLEBUFFER, None },
  738. { GLX_RGBA, R, 4, G, 4, B, 4, GLX_DEPTH_SIZE, 4, GLX_DOUBLEBUFFER, None },
  739. { GLX_RGBA, R, 8, G, 8, B, 8, GLX_DEPTH_SIZE, 8, GLX_STENCIL_SIZE, 1, None },
  740. { GLX_RGBA, R, 4, G, 4, B, 4, GLX_DEPTH_SIZE, 4, GLX_STENCIL_SIZE, 1, None },
  741. { GLX_RGBA, R, 8, G, 8, B, 8, GLX_DEPTH_SIZE, 8, None },
  742. { GLX_RGBA, R, 4, G, 4, B, 4, GLX_DEPTH_SIZE, 4, None },
  743. { GLX_RGBA, GLX_DEPTH_SIZE, 8, GLX_DOUBLEBUFFER, GLX_STENCIL_SIZE, 1, None },
  744. { GLX_RGBA, GLX_DEPTH_SIZE, 8, GLX_DOUBLEBUFFER, None },
  745. { GLX_RGBA, GLX_DEPTH_SIZE, 8, GLX_STENCIL_SIZE, 1, None },
  746. { GLX_RGBA, GLX_DEPTH_SIZE, 8, None }
  747. #undef R
  748. #undef G
  749. #undef B
  750. };
  751. for( unsigned int i = 0;
  752. i < sizeof( attribs ) / sizeof( attribs[ 0 ] );
  753. ++i )
  754. {
  755. if( XVisualInfo* info = glXChooseVisual( x11Display(), x11Screen(), attribs[ i ] ))
  756. {
  757. visual = info->visual;
  758. static Colormap colormap = 0;
  759. if( colormap != 0 )
  760. XFreeColormap( x11Display(), colormap );
  761. colormap = XCreateColormap( x11Display(), RootWindow( x11Display(), x11Screen()), visual, AllocNone );
  762. attrs.colormap = colormap;
  763. flags |= CWColormap;
  764. XFree( info );
  765. break;
  766. }
  767. }
  768. }
  769. #endif
  770. attrs.override_redirect = 1;
  771. hide();
  772. if (argb_visual) {
  773. attrs.background_pixel = 0;
  774. attrs.border_pixel = 0;
  775. flags |= CWBackPixel;
  776. flags |= CWBorderPixel;
  777. if (!(flags & CWColormap)) {
  778. XVisualInfo vinfo;
  779. if (!XMatchVisualInfo( x11Display(), x11Screen(), 32, TrueColor, &vinfo )) {
  780. printf("[ERROR] Unable to locate matching X11 Visual; this application will not function correctly!\n");
  781. }
  782. else {
  783. visual = vinfo.visual;
  784. attrs.colormap = XCreateColormap( x11Display(), RootWindow( x11Display(), x11Screen()), visual, AllocNone );
  785. flags |= CWColormap;
  786. }
  787. }
  788. }
  789. Window w = XCreateWindow( x11Display(), RootWindow( x11Display(), x11Screen()), x(), y(), width(), height(), 0, x11Depth(), InputOutput, visual, flags, &attrs );
  790. create( w );
  791. // Some xscreensaver hacks check for this property
  792. const char *version = "KDE 2.0";
  793. XChangeProperty (tqt_xdisplay(), winId(),
  794. gXA_SCREENSAVER_VERSION, XA_STRING, 8, PropModeReplace,
  795. (unsigned char *) version, strlen(version));
  796. XSetWindowAttributes attr;
  797. attr.event_mask = KeyPressMask | ButtonPressMask | PointerMotionMask | VisibilityChangeMask | ExposureMask;
  798. XChangeWindowAttributes(tqt_xdisplay(), winId(), CWEventMask, &attr);
  799. // Signal that we want to be transparent to the desktop, not to windows behind us...
  800. Atom kde_wm_transparent_to_desktop;
  801. kde_wm_transparent_to_desktop = XInternAtom(tqt_xdisplay(), "_KDE_TRANSPARENT_TO_DESKTOP", False);
  802. XChangeProperty(tqt_xdisplay(), w, kde_wm_transparent_to_desktop, XA_INTEGER, 32, PropModeReplace, (unsigned char *) "TRUE", 1L);
  803. // erase();
  804. // set NoBackground so that the saver can capture the current
  805. // screen state if necessary
  806. // this is a security risk and has been deactivated--welcome to the 21st century folks!
  807. // setBackgroundMode(TQWidget::NoBackground);
  808. setGeometry(0, 0, mRootWidth, mRootHeight);
  809. // HACK
  810. // Hide all tooltips and notification windows
  811. {
  812. Window rootWindow = RootWindow(x11Display(), x11Screen());
  813. Window parent;
  814. Window* children = NULL;
  815. unsigned int noOfChildren = 0;
  816. XWindowAttributes childAttr;
  817. Window childTransient;
  818. if (XQueryTree(x11Display(), rootWindow, &rootWindow, &parent, &children, &noOfChildren) && noOfChildren>0 ) {
  819. for (unsigned int i=0; i<noOfChildren; i++) {
  820. if (XGetWindowAttributes(x11Display(), children[i], &childAttr) && XGetTransientForHint(x11Display(), children[i], &childTransient)) {
  821. if ((childAttr.map_state == IsViewable) && (childAttr.override_redirect) && (childTransient)) {
  822. if (!trinity_desktop_lock_hidden_window_list.contains(children[i])) {
  823. trinity_desktop_lock_hidden_window_list.append(children[i]);
  824. }
  825. XLowerWindow(x11Display(), children[i]);
  826. XFlush(x11Display());
  827. }
  828. }
  829. }
  830. }
  831. }
  832. kdDebug(1204) << "Saver window Id: " << winId() << endl;
  833. }
  834. void LockProcess::desktopResized()
  835. {
  836. // Get root window size
  837. XWindowAttributes rootAttr;
  838. XGetWindowAttributes(tqt_xdisplay(), RootWindow(tqt_xdisplay(), tqt_xscreen()), &rootAttr);
  839. if ((rootAttr.width == mRootWidth) && (rootAttr.height == mRootHeight)) {
  840. return;
  841. }
  842. mRootWidth = rootAttr.width;
  843. mRootHeight = rootAttr.height;
  844. mBusy = true;
  845. mHackDelayStartupTimer->stop();
  846. stopHack();
  847. DISABLE_CONTINUOUS_LOCKDLG_DISPLAY
  848. mResizingDesktopLock = true;
  849. backingPixmap = TQPixmap();
  850. if (trinity_desktop_lock_use_system_modal_dialogs) {
  851. // Temporarily hide the entire screen with a new override redirect window
  852. if (m_maskWidget) {
  853. m_maskWidget->setGeometry(0, 0, mRootWidth, mRootHeight);
  854. }
  855. else {
  856. int flags = CWOverrideRedirect;
  857. Visual* visual = CopyFromParent;
  858. XSetWindowAttributes attrs;
  859. attrs.override_redirect = 1;
  860. Window maskWindow = XCreateWindow(x11Display(), RootWindow( x11Display(), x11Screen()), 0, 0, mRootWidth, mRootHeight, 0, x11Depth(), InputOutput, visual, flags, &attrs);
  861. m_maskWidget = new TQWidget();
  862. m_maskWidget->create(maskWindow);
  863. m_maskWidget->setBackgroundColor(TQt::black);
  864. m_maskWidget->erase();
  865. m_maskWidget->show();
  866. }
  867. XSync(tqt_xdisplay(), False);
  868. if (mEnsureScreenHiddenTimer) {
  869. mEnsureScreenHiddenTimer->stop();
  870. }
  871. else {
  872. mEnsureScreenHiddenTimer = new TQTimer( this );
  873. connect( mEnsureScreenHiddenTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotForcePaintBackground()) );
  874. }
  875. mEnsureScreenHiddenTimer->start(DESKTOP_WALLPAPER_OBTAIN_TIMEOUT_MS, true);
  876. }
  877. // Resize the background widget
  878. setGeometry(0, 0, mRootWidth, mRootHeight);
  879. XSync(tqt_xdisplay(), False);
  880. // Black out the background widget to hide ugly resize tiling artifacts
  881. if (argb_visual) {
  882. setTransparentBackgroundARGB();
  883. }
  884. else {
  885. setBackgroundColor(black);
  886. }
  887. erase();
  888. // This slot needs to be able to execute very rapidly so as to prevent the user's desktop from ever
  889. // being displayed, so we finish the hack restarting/display prettying operations in a separate timed slot
  890. if (resizeTimer == NULL) {
  891. resizeTimer = new TQTimer( this );
  892. connect( resizeTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(doDesktopResizeFinish()) );
  893. }
  894. resizeTimer->start( 100, TRUE ); // 100 millisecond single shot timer; should allow display switching operations to finish before hack is started
  895. }
  896. void LockProcess::doDesktopResizeFinish()
  897. {
  898. while (mDialogControlLock == true) {
  899. usleep(100000);
  900. }
  901. mDialogControlLock = true;
  902. if (closeCurrentWindow()) {
  903. TQTimer::singleShot( 0, this, SLOT(doDesktopResizeFinish()) );
  904. mDialogControlLock = false;
  905. return;
  906. }
  907. mDialogControlLock = false;
  908. // Restart the hack as the window size is now different
  909. if (trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_use_system_modal_dialogs) {
  910. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  911. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  912. }
  913. else {
  914. if (mHackStartupEnabled == true) {
  915. startHack();
  916. }
  917. else {
  918. if (trinity_desktop_lock_use_system_modal_dialogs == true) {
  919. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  920. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  921. }
  922. else {
  923. startHack();
  924. }
  925. }
  926. }
  927. mResizingDesktopLock = false;
  928. mBusy = false;
  929. }
  930. //---------------------------------------------------------------------------
  931. //
  932. // Hide the screensaver window
  933. //
  934. void LockProcess::hideSaverWindow()
  935. {
  936. hide();
  937. lower();
  938. removeVRoot(winId());
  939. XDeleteProperty(tqt_xdisplay(), winId(), gXA_SCREENSAVER_VERSION);
  940. if ( gVRoot ) {
  941. unsigned long vroot_data[1] = { gVRootData };
  942. XChangeProperty(tqt_xdisplay(), gVRoot, gXA_VROOT, XA_WINDOW, 32,
  943. PropModeReplace, (unsigned char *)vroot_data, 1);
  944. gVRoot = 0;
  945. }
  946. XSync(tqt_xdisplay(), False);
  947. }
  948. //---------------------------------------------------------------------------
  949. static int ignoreXError(Display *, XErrorEvent *)
  950. {
  951. return 0;
  952. }
  953. //---------------------------------------------------------------------------
  954. //
  955. // Save the current virtual root window
  956. //
  957. void LockProcess::saveVRoot()
  958. {
  959. Window rootReturn, parentReturn, *children;
  960. unsigned int numChildren;
  961. Window root = RootWindowOfScreen(ScreenOfDisplay(tqt_xdisplay(), tqt_xscreen()));
  962. gVRoot = 0;
  963. gVRootData = 0;
  964. int (*oldHandler)(Display *, XErrorEvent *);
  965. oldHandler = XSetErrorHandler(ignoreXError);
  966. if (XQueryTree(tqt_xdisplay(), root, &rootReturn, &parentReturn,
  967. &children, &numChildren))
  968. {
  969. for (unsigned int i = 0; i < numChildren; i++)
  970. {
  971. Atom actual_type;
  972. int actual_format;
  973. unsigned long nitems, bytesafter;
  974. unsigned char *newRoot = 0;
  975. if ((XGetWindowProperty(tqt_xdisplay(), children[i], gXA_VROOT, 0, 1,
  976. False, XA_WINDOW, &actual_type, &actual_format, &nitems, &bytesafter,
  977. &newRoot) == Success) && newRoot)
  978. {
  979. gVRoot = children[i];
  980. Window *dummy = (Window*)newRoot;
  981. gVRootData = *dummy;
  982. XFree ((char*) newRoot);
  983. break;
  984. }
  985. }
  986. if (children)
  987. {
  988. XFree((char *)children);
  989. }
  990. }
  991. XSetErrorHandler(oldHandler);
  992. }
  993. //---------------------------------------------------------------------------
  994. //
  995. // Set the virtual root property
  996. //
  997. void LockProcess::setVRoot(Window win, Window vr)
  998. {
  999. if (gVRoot) {
  1000. removeVRoot(gVRoot);
  1001. }
  1002. unsigned long rw = RootWindowOfScreen(ScreenOfDisplay(tqt_xdisplay(), tqt_xscreen()));
  1003. unsigned long vroot_data[1] = { vr };
  1004. Window rootReturn;
  1005. Window parentReturn;
  1006. Window *children = NULL;
  1007. unsigned int numChildren;
  1008. Window top = win;
  1009. while (1) {
  1010. if (XQueryTree(tqt_xdisplay(), top, &rootReturn, &parentReturn, &children, &numChildren) == 0) {
  1011. printf("[WARNING] XQueryTree() failed!\n"); fflush(stdout);
  1012. break;
  1013. }
  1014. if (children) {
  1015. XFree((char *)children);
  1016. }
  1017. if (parentReturn == rw) {
  1018. break;
  1019. }
  1020. else {
  1021. top = parentReturn;
  1022. }
  1023. }
  1024. XChangeProperty(tqt_xdisplay(), top, gXA_VROOT, XA_WINDOW, 32, PropModeReplace, (unsigned char *)vroot_data, 1);
  1025. }
  1026. //---------------------------------------------------------------------------
  1027. //
  1028. // Remove the virtual root property
  1029. //
  1030. void LockProcess::removeVRoot(Window win)
  1031. {
  1032. XDeleteProperty (tqt_xdisplay(), win, gXA_VROOT);
  1033. }
  1034. //---------------------------------------------------------------------------
  1035. //
  1036. // Grab the keyboard. Returns true on success
  1037. //
  1038. bool LockProcess::grabKeyboard()
  1039. {
  1040. int rv = XGrabKeyboard( tqt_xdisplay(), TQApplication::desktop()->winId(),
  1041. True, GrabModeAsync, GrabModeAsync, CurrentTime );
  1042. return (rv == GrabSuccess);
  1043. }
  1044. #define GRABEVENTS ButtonPressMask | ButtonReleaseMask | PointerMotionMask | \
  1045. EnterWindowMask | LeaveWindowMask
  1046. //---------------------------------------------------------------------------
  1047. //
  1048. // Grab the mouse. Returns true on success
  1049. //
  1050. bool LockProcess::grabMouse()
  1051. {
  1052. HANDLE cursorHandle;
  1053. if (trinity_desktop_hack_active) {
  1054. cursorHandle = TQCursor(tqblankCursor).handle();
  1055. }
  1056. else {
  1057. cursorHandle = TQCursor(tqbusyCursor).handle();
  1058. }
  1059. int rv = XGrabPointer( tqt_xdisplay(), TQApplication::desktop()->winId(),
  1060. True, GRABEVENTS, GrabModeAsync, GrabModeAsync, None,
  1061. cursorHandle, CurrentTime );
  1062. return (rv == GrabSuccess);
  1063. }
  1064. //---------------------------------------------------------------------------
  1065. //
  1066. // Grab keyboard and mouse. Returns true on success.
  1067. //
  1068. bool LockProcess::grabInput()
  1069. {
  1070. XSync(tqt_xdisplay(), False);
  1071. if (!grabKeyboard())
  1072. {
  1073. usleep(100000);
  1074. if (!grabKeyboard())
  1075. {
  1076. return false;
  1077. }
  1078. }
  1079. #ifndef KEEP_MOUSE_UNGRABBED
  1080. if (!grabMouse())
  1081. {
  1082. usleep(100000);
  1083. if (!grabMouse())
  1084. {
  1085. XUngrabKeyboard(tqt_xdisplay(), CurrentTime);
  1086. return false;
  1087. }
  1088. }
  1089. #endif
  1090. lockXF86();
  1091. return true;
  1092. }
  1093. //---------------------------------------------------------------------------
  1094. //
  1095. // Release mouse an keyboard grab.
  1096. //
  1097. void LockProcess::ungrabInput()
  1098. {
  1099. XUngrabKeyboard(tqt_xdisplay(), CurrentTime);
  1100. XUngrabPointer(tqt_xdisplay(), CurrentTime);
  1101. unlockXF86();
  1102. }
  1103. //---------------------------------------------------------------------------
  1104. //
  1105. // Set a fully transparent ARGB background image.
  1106. //
  1107. void LockProcess::setTransparentBackgroundARGB()
  1108. {
  1109. // eliminate nasty flicker on first show
  1110. TQImage m_grayImage = TQImage( TQApplication::desktop()->width(), TQApplication::desktop()->height(), 32 );
  1111. m_grayImage = m_grayImage.convertDepth(32);
  1112. m_grayImage.setAlphaBuffer(false);
  1113. m_grayImage.fill(0); // Set the alpha buffer to 0 (fully transparent)
  1114. m_grayImage.setAlphaBuffer(true);
  1115. TQPixmap m_root;
  1116. m_root.resize(mRootWidth, mRootHeight);
  1117. TQPainter p;
  1118. p.begin( &m_root );
  1119. m_grayImage.setAlphaBuffer(false);
  1120. p.drawImage( 0, 0, m_grayImage );
  1121. p.end();
  1122. setBackgroundPixmap( m_root );
  1123. }
  1124. //---------------------------------------------------------------------------
  1125. //
  1126. // Start the screen saver.
  1127. //
  1128. bool LockProcess::startSaver()
  1129. {
  1130. if (!child_saver && !grabInput())
  1131. {
  1132. kdWarning(1204) << "LockProcess::startSaver() grabInput() failed!!!!" << endl;
  1133. return false;
  1134. }
  1135. mBusy = false;
  1136. // eliminate nasty flicker on first show
  1137. setTransparentBackgroundARGB();
  1138. saveVRoot();
  1139. if (mParent) {
  1140. TQSocketNotifier *notifier = new TQSocketNotifier(mParent, TQSocketNotifier::Read, TQT_TQOBJECT(this), "notifier");
  1141. connect(notifier, TQT_SIGNAL( activated (int)), TQT_SLOT( quitSaver()));
  1142. }
  1143. createSaverWindow();
  1144. move(0, 0);
  1145. show();
  1146. raise();
  1147. XSync(tqt_xdisplay(), False);
  1148. setVRoot( winId(), winId() );
  1149. if (!trinity_desktop_lock_hide_active_windows) {
  1150. if (m_rootPixmap) m_rootPixmap->stop();
  1151. TQPixmap rootWinSnapShot = TQPixmap::grabWindow(TQApplication::desktop()->winId());
  1152. slotPaintBackground(rootWinSnapShot);
  1153. }
  1154. if (((!(trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced)) && (!trinity_desktop_lock_in_sec_dlg)) && (mHackStartupEnabled || mOverrideHackStartupEnabled)) {
  1155. if (argb_visual) {
  1156. setTransparentBackgroundARGB();
  1157. }
  1158. else {
  1159. if (backingPixmap.isNull()) {
  1160. setBackgroundColor(black);
  1161. }
  1162. else {
  1163. setBackgroundPixmap(backingPixmap);
  1164. }
  1165. }
  1166. setGeometry(0, 0, mRootWidth, mRootHeight);
  1167. erase();
  1168. }
  1169. if (trinity_desktop_lock_in_sec_dlg == FALSE) {
  1170. if (trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced && trinity_desktop_lock_use_system_modal_dialogs) {
  1171. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  1172. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  1173. }
  1174. else {
  1175. if (mHackStartupEnabled || mOverrideHackStartupEnabled) {
  1176. mOverrideHackStartupEnabled = false;
  1177. startHack();
  1178. }
  1179. else {
  1180. if (trinity_desktop_lock_use_system_modal_dialogs == true) {
  1181. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  1182. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  1183. }
  1184. else {
  1185. startHack();
  1186. }
  1187. }
  1188. }
  1189. }
  1190. return true;
  1191. }
  1192. //---------------------------------------------------------------------------
  1193. //
  1194. // Stop the screen saver.
  1195. //
  1196. void LockProcess::stopSaver()
  1197. {
  1198. kdDebug(1204) << "LockProcess: stopping saver" << endl;
  1199. mHackProc.kill(SIGCONT);
  1200. stopHack();
  1201. mSuspended = false;
  1202. hideSaverWindow();
  1203. mVisibility = false;
  1204. if (!child_saver) {
  1205. if (mLocked)
  1206. DM().setLock( false );
  1207. ungrabInput();
  1208. const char *out = "GOAWAY!";
  1209. for (TQValueList<int>::ConstIterator it = child_sockets.begin(); it != child_sockets.end(); ++it)
  1210. if (write(*it, out, sizeof(out)) == -1) {
  1211. // Error handler to shut up gcc warnings
  1212. }
  1213. }
  1214. }
  1215. // private static
  1216. TQVariant LockProcess::getConf(void *ctx, const char *key, const TQVariant &dflt)
  1217. {
  1218. LockProcess *that = (LockProcess *)ctx;
  1219. TQString fkey = TQString::fromLatin1( key ) + '=';
  1220. for (TQStringList::ConstIterator it = that->mPluginOptions.begin();
  1221. it != that->mPluginOptions.end(); ++it)
  1222. if ((*it).startsWith( fkey ))
  1223. return (*it).mid( fkey.length() );
  1224. return dflt;
  1225. }
  1226. void LockProcess::cantLock( const TQString &txt)
  1227. {
  1228. msgBox( TQMessageBox::Critical, i18n("Will not lock the session, as unlocking would be impossible:\n") + txt );
  1229. }
  1230. #if 0 // placeholders for later
  1231. i18n("Cannot start <i>kcheckpass</i>.");
  1232. i18n("<i>kcheckpass</i> is unable to operate. Possibly it is not SetUID root.");
  1233. #endif
  1234. //---------------------------------------------------------------------------
  1235. //
  1236. // Make the screen saver password protected.
  1237. //
  1238. bool LockProcess::startLock()
  1239. {
  1240. for (TQStringList::ConstIterator it = mPlugins.begin(); it != mPlugins.end(); ++it) {
  1241. GreeterPluginHandle plugin;
  1242. TQString path = KLibLoader::self()->findLibrary(
  1243. ((*it)[0] == '/' ? *it : "kgreet_" + *it ).latin1() );
  1244. if (path.isEmpty()) {
  1245. kdWarning(1204) << "GreeterPlugin " << *it << " does not exist" << endl;
  1246. continue;
  1247. }
  1248. if (!(plugin.library = KLibLoader::self()->library( path.latin1() ))) {
  1249. kdWarning(1204) << "Cannot load GreeterPlugin " << *it << " (" << path << ")" << endl;
  1250. continue;
  1251. }
  1252. if (!plugin.library->hasSymbol( "kgreeterplugin_info" )) {
  1253. kdWarning(1204) << "GreeterPlugin " << *it << " (" << path << ") is no valid greet widget plugin" << endl;
  1254. plugin.library->unload();
  1255. continue;
  1256. }
  1257. plugin.info = (kgreeterplugin_info*)plugin.library->symbol( "kgreeterplugin_info" );
  1258. if (plugin.info->method && !mMethod.isEmpty() && mMethod != plugin.info->method) {
  1259. kdDebug(1204) << "GreeterPlugin " << *it << " (" << path << ") serves " << plugin.info->method << ", not " << mMethod << endl;
  1260. plugin.library->unload();
  1261. continue;
  1262. }
  1263. if (!plugin.info->init( mMethod, getConf, this )) {
  1264. kdDebug(1204) << "GreeterPlugin " << *it << " (" << path << ") refuses to serve " << mMethod << endl;
  1265. plugin.library->unload();
  1266. continue;
  1267. }
  1268. kdDebug(1204) << "GreeterPlugin " << *it << " (" << plugin.info->method << ", " << plugin.info->name << ") loaded" << endl;
  1269. greetPlugin = plugin;
  1270. mLocked = true;
  1271. DM().setLock( true );
  1272. return true;
  1273. }
  1274. cantLock( i18n("No appropriate greeter plugin configured.") );
  1275. return false;
  1276. }
  1277. //---------------------------------------------------------------------------
  1278. //
  1279. void LockProcess::closeDialogAndStartHack()
  1280. {
  1281. #ifdef HAVE_DPMS
  1282. if (KDesktopSettings::dpmsDependent()) {
  1283. BOOL on;
  1284. CARD16 state;
  1285. if (DPMSInfo(tqt_xdisplay(), &state, &on)) {
  1286. //kdDebug() << "checkDPMSActive " << on << " " << state << endl;
  1287. if (DPMS_MONITOR_BLANKED(state)) {
  1288. // Make sure saver will attempt to start again after DPMS wakeup
  1289. // This is related to Bug 1475
  1290. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  1291. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  1292. // Should not start saver here, because the DPMS check method below would turn it right back off!
  1293. // This is related to Bug 1475
  1294. return;
  1295. }
  1296. }
  1297. }
  1298. #endif
  1299. // Close any active dialogs
  1300. DISABLE_CONTINUOUS_LOCKDLG_DISPLAY
  1301. mSuspended = true;
  1302. if (closeCurrentWindow()) {
  1303. TQTimer::singleShot( 0, this, SLOT(closeDialogAndStartHack()) );
  1304. }
  1305. else {
  1306. resume(true);
  1307. }
  1308. }
  1309. void LockProcess::repaintRootWindowIfNeeded()
  1310. {
  1311. if (trinity_desktop_lock_use_system_modal_dialogs) {
  1312. if (!mHackProc.isRunning()) {
  1313. if (argb_visual) {
  1314. setTransparentBackgroundARGB();
  1315. erase();
  1316. }
  1317. else {
  1318. if (backingPixmap.isNull()) {
  1319. setBackgroundColor(black);
  1320. setGeometry(0, 0, mRootWidth, mRootHeight);
  1321. erase();
  1322. }
  1323. else {
  1324. bitBlt(this, 0, 0, &backingPixmap);
  1325. }
  1326. }
  1327. }
  1328. if (currentDialog == NULL) {
  1329. raise();
  1330. }
  1331. }
  1332. }
  1333. bool LockProcess::startHack()
  1334. {
  1335. trinity_desktop_hack_active = TRUE;
  1336. setCursor( tqblankCursor );
  1337. XChangeActivePointerGrab( tqt_xdisplay(), GRABEVENTS, TQCursor(tqblankCursor).handle(), CurrentTime);
  1338. if ((mEnsureVRootWindowSecurityTimer) && (!mEnsureVRootWindowSecurityTimer->isActive())) mEnsureVRootWindowSecurityTimer->start(250, FALSE);
  1339. if (currentDialog || (!mDialogs.isEmpty()))
  1340. {
  1341. // no resuming with dialog visible or when not visible
  1342. if (argb_visual) {
  1343. setTransparentBackgroundARGB();
  1344. }
  1345. else {
  1346. if (backingPixmap.isNull()) {
  1347. setBackgroundColor(black);
  1348. }
  1349. else {
  1350. setBackgroundPixmap(backingPixmap);
  1351. }
  1352. }
  1353. setGeometry(0, 0, mRootWidth, mRootHeight);
  1354. erase();
  1355. return false;
  1356. }
  1357. if (mSaverExec.isEmpty())
  1358. {
  1359. return false;
  1360. }
  1361. if (mHackProc.isRunning())
  1362. {
  1363. stopHack();
  1364. }
  1365. mHackProc.clearArguments();
  1366. TQTextStream ts(&mSaverExec, IO_ReadOnly);
  1367. TQString word;
  1368. ts >> word;
  1369. TQString path = TDEStandardDirs::findExe(word);
  1370. if (!path.isEmpty())
  1371. {
  1372. mHackProc << path;
  1373. kdDebug(1204) << "Starting hack: " << path << endl;
  1374. while (!ts.atEnd())
  1375. {
  1376. ts >> word;
  1377. if (word == "%w")
  1378. {
  1379. word = word.setNum(winId());
  1380. }
  1381. mHackProc << word;
  1382. }
  1383. if (!mForbidden)
  1384. {
  1385. if (trinity_desktop_lock_use_system_modal_dialogs) {
  1386. // Make sure we have a nice clean display to start with!
  1387. if (argb_visual) {
  1388. setTransparentBackgroundARGB();
  1389. }
  1390. else {
  1391. if (backingPixmap.isNull()) {
  1392. setBackgroundColor(black);
  1393. }
  1394. else {
  1395. setBackgroundPixmap(backingPixmap);
  1396. }
  1397. }
  1398. setGeometry(0, 0, mRootWidth, mRootHeight);
  1399. erase();
  1400. mSuspended = false;
  1401. }
  1402. if (mHackProc.start() == true)
  1403. {
  1404. #ifdef HAVE_SETPRIORITY
  1405. setpriority(PRIO_PROCESS, mHackProc.pid(), mPriority);
  1406. #endif
  1407. //bitBlt(this, 0, 0, &mOriginal);
  1408. DISABLE_CONTINUOUS_LOCKDLG_DISPLAY
  1409. if (trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced) {
  1410. // Close any active dialogs
  1411. if (closeCurrentWindow()) {
  1412. TQTimer::singleShot( 0, this, SLOT(closeCurrentWindow()) );
  1413. }
  1414. }
  1415. if (m_startupStatusDialog) { m_startupStatusDialog->closeSMDialog(); m_startupStatusDialog=NULL; }
  1416. return true;
  1417. }
  1418. }
  1419. else
  1420. // we aren't allowed to start the specified screensaver either because it didn't run for some reason
  1421. // according to the kiosk restrictions forbid it
  1422. {
  1423. usleep(100);
  1424. TQApplication::syncX();
  1425. if (!trinity_desktop_lock_use_system_modal_dialogs) {
  1426. if (argb_visual) {
  1427. setTransparentBackgroundARGB();
  1428. }
  1429. else {
  1430. if (backingPixmap.isNull()) {
  1431. setBackgroundColor(black);
  1432. }
  1433. else {
  1434. setBackgroundPixmap(backingPixmap);
  1435. }
  1436. }
  1437. }
  1438. if (argb_visual) {
  1439. setTransparentBackgroundARGB();
  1440. erase();
  1441. }
  1442. else {
  1443. if (backingPixmap.isNull()) {
  1444. setGeometry(0, 0, mRootWidth, mRootHeight);
  1445. erase();
  1446. }
  1447. else {
  1448. bitBlt(this, 0, 0, &backingPixmap);
  1449. }
  1450. }
  1451. if (trinity_desktop_lock_use_system_modal_dialogs) {
  1452. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  1453. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  1454. }
  1455. }
  1456. }
  1457. if (m_startupStatusDialog) { m_startupStatusDialog->closeSMDialog(); m_startupStatusDialog=NULL; }
  1458. return false;
  1459. }
  1460. //---------------------------------------------------------------------------
  1461. //
  1462. void LockProcess::stopHack()
  1463. {
  1464. if (mHackProc.isRunning())
  1465. {
  1466. mHackProc.kill();
  1467. if (!mHackProc.wait(10))
  1468. {
  1469. mHackProc.kill(SIGKILL);
  1470. }
  1471. }
  1472. setCursor( tqarrowCursor );
  1473. trinity_desktop_hack_active = FALSE;
  1474. }
  1475. //---------------------------------------------------------------------------
  1476. //
  1477. void LockProcess::hackExited(TDEProcess *)
  1478. {
  1479. // Hack exited while we're supposed to be saving the screen.
  1480. // Make sure the saver window is black.
  1481. trinity_desktop_hack_active = FALSE;
  1482. usleep(100);
  1483. TQApplication::syncX();
  1484. if (!trinity_desktop_lock_use_system_modal_dialogs) {
  1485. if (argb_visual) {
  1486. setTransparentBackgroundARGB();
  1487. }
  1488. else {
  1489. if (backingPixmap.isNull()) {
  1490. setBackgroundColor(black);
  1491. }
  1492. else {
  1493. setBackgroundPixmap(backingPixmap);
  1494. }
  1495. }
  1496. }
  1497. if (argb_visual) {
  1498. setTransparentBackgroundARGB();
  1499. }
  1500. else {
  1501. if (backingPixmap.isNull()) {
  1502. setGeometry(0, 0, mRootWidth, mRootHeight);
  1503. erase();
  1504. }
  1505. else {
  1506. bitBlt(this, 0, 0, &backingPixmap);
  1507. }
  1508. }
  1509. if (!mSuspended) {
  1510. if (trinity_desktop_lock_use_system_modal_dialogs) {
  1511. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  1512. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  1513. }
  1514. }
  1515. }
  1516. void LockProcess::displayLockDialogIfNeeded()
  1517. {
  1518. if (m_startupStatusDialog) {
  1519. m_startupStatusDialog->closeSMDialog(); m_startupStatusDialog=NULL;
  1520. }
  1521. if (!trinity_desktop_lock_in_sec_dlg) {
  1522. if (trinity_desktop_lock_use_system_modal_dialogs) {
  1523. if (!mBusy) {
  1524. mBusy = true;
  1525. if (mLocked) {
  1526. if (checkPass()) {
  1527. trinity_desktop_lock_closing_windows = true;
  1528. stopSaver();
  1529. kapp->quit();
  1530. }
  1531. }
  1532. mBusy = false;
  1533. }
  1534. }
  1535. }
  1536. }
  1537. void LockProcess::suspend()
  1538. {
  1539. if(!mSuspended)
  1540. {
  1541. if (trinity_desktop_lock_use_system_modal_dialogs) {
  1542. mSuspended = true;
  1543. stopHack();
  1544. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  1545. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  1546. }
  1547. else {
  1548. TQString hackStatus;
  1549. mHackProc.kill(SIGSTOP);
  1550. mSuspended = true;
  1551. #if 0
  1552. // wait for the stop signal to take effect
  1553. while (hackStatus != "T") {
  1554. char hackstat[8192];
  1555. FILE *fp = fopen(TQString("/proc/%1/stat").arg(mHackProc.pid()).ascii(),"r");
  1556. if (fp != NULL) {
  1557. fgets (hackstat, 8192, fp);
  1558. fclose (fp);
  1559. }
  1560. hackstat[8191] = 0;
  1561. hackStatus = hackstat;
  1562. hackStatus = hackStatus.remove(TQRegExp("(*) ", TRUE, TRUE));
  1563. TQStringList hackStatusList = TQStringList::split(" ", hackStatus);
  1564. hackStatus = (*(hackStatusList.at(1)));
  1565. }
  1566. #endif
  1567. TQApplication::syncX();
  1568. usleep(100000); // Allow certain bad graphics drivers (*cough* fglrx *cough*) time to actually sync up the display
  1569. }
  1570. TQApplication::syncX();
  1571. mSavedScreen = TQPixmap::grabWindow( winId());
  1572. }
  1573. }
  1574. void LockProcess::resume( bool force )
  1575. {
  1576. if (trinity_desktop_lock_use_sak && (mHackDelayStartupTimer->isActive() || !mHackStartupEnabled)) {
  1577. return;
  1578. }
  1579. if( !force && (!mDialogs.isEmpty() || !mVisibility )) {
  1580. // no resuming with dialog visible or when not visible
  1581. if (trinity_desktop_lock_use_system_modal_dialogs) {
  1582. if (argb_visual) {
  1583. setTransparentBackgroundARGB();
  1584. }
  1585. else {
  1586. if (backingPixmap.isNull()) {
  1587. setBackgroundColor(black);
  1588. }
  1589. else {
  1590. setBackgroundPixmap(backingPixmap);
  1591. }
  1592. }
  1593. setGeometry(0, 0, mRootWidth, mRootHeight);
  1594. erase();
  1595. }
  1596. else {
  1597. setGeometry(0, 0, mRootWidth, mRootHeight);
  1598. }
  1599. return;
  1600. }
  1601. if ((mSuspended) && (mHackProc.isRunning()))
  1602. {
  1603. XForceScreenSaver(tqt_xdisplay(), ScreenSaverReset );
  1604. bitBlt( this, 0, 0, &mSavedScreen );
  1605. TQApplication::syncX();
  1606. mHackProc.kill(SIGCONT);
  1607. mSuspended = false;
  1608. }
  1609. else if (mSuspended && trinity_desktop_lock_use_system_modal_dialogs) {
  1610. startHack();
  1611. }
  1612. }
  1613. //---------------------------------------------------------------------------
  1614. //
  1615. // Show the password dialog
  1616. // This is called only in the master process
  1617. //
  1618. bool LockProcess::checkPass()
  1619. {
  1620. if (!mDialogs.isEmpty()) {
  1621. // Another dialog is already shown
  1622. // Abort!
  1623. return 0;
  1624. }
  1625. if (mInfoMessageDisplayed == false) {
  1626. if (mAutoLogout) {
  1627. killTimer(mAutoLogoutTimerId);
  1628. }
  1629. // Make sure we never launch the SAK or login dialog if windows are being closed down
  1630. // Otherwise we can get stuck in an irrecoverable state where any attempt to show the login screen is instantly aborted
  1631. if (trinity_desktop_lock_closing_windows) {
  1632. return 0;
  1633. }
  1634. if (trinity_desktop_lock_use_sak) {
  1635. // Verify SAK operational status
  1636. TDEProcess* checkSAKProcess = new TDEProcess;
  1637. *checkSAKProcess << "tdmtsak" << "check";
  1638. checkSAKProcess->start(TDEProcess::Block, TDEProcess::NoCommunication);
  1639. int retcode = checkSAKProcess->exitStatus();
  1640. delete checkSAKProcess;
  1641. if (retcode != 0) {
  1642. trinity_desktop_lock_use_sak = false;
  1643. }
  1644. }
  1645. if (trinity_desktop_lock_use_sak) {
  1646. // Wait for SAK press before continuing...
  1647. SAKDlg inDlg( this );
  1648. execDialog( &inDlg );
  1649. if (trinity_desktop_lock_closing_windows) {
  1650. return 0;
  1651. }
  1652. }
  1653. showVkbd();
  1654. PasswordDlg passDlg( this, &greetPlugin, (mShowLockDateTime)?mlockDateTime:TQDateTime());
  1655. int ret = execDialog( &passDlg );
  1656. hideVkbd();
  1657. if (mForceReject == true) {
  1658. ret = TQDialog::Rejected;
  1659. }
  1660. mForceReject = false;
  1661. XWindowAttributes rootAttr;
  1662. XGetWindowAttributes(tqt_xdisplay(), RootWindow(tqt_xdisplay(),
  1663. tqt_xscreen()), &rootAttr);
  1664. if(( rootAttr.your_event_mask & SubstructureNotifyMask ) == 0 )
  1665. {
  1666. kdWarning() << "ERROR: Something removed SubstructureNotifyMask from the root window!!!" << endl;
  1667. XSelectInput( tqt_xdisplay(), tqt_xrootwin(),
  1668. SubstructureNotifyMask | rootAttr.your_event_mask );
  1669. }
  1670. return ret == TQDialog::Accepted;
  1671. }
  1672. else {
  1673. return 0;
  1674. }
  1675. }
  1676. static void fakeFocusIn( WId window )
  1677. {
  1678. // We have keyboard grab, so this application will
  1679. // get keyboard events even without having focus.
  1680. // Fake FocusIn to make Qt realize it has the active
  1681. // window, so that it will correctly show cursor in the dialog.
  1682. XEvent ev;
  1683. memset(&ev, 0, sizeof(ev));
  1684. ev.xfocus.display = tqt_xdisplay();
  1685. ev.xfocus.type = FocusIn;
  1686. ev.xfocus.window = window;
  1687. ev.xfocus.mode = NotifyNormal;
  1688. ev.xfocus.detail = NotifyAncestor;
  1689. XSendEvent( tqt_xdisplay(), window, False, NoEventMask, &ev );
  1690. }
  1691. void LockProcess::resumeUnforced()
  1692. {
  1693. resume( false );
  1694. }
  1695. int LockProcess::execDialog( TQDialog *dlg )
  1696. {
  1697. currentDialog=dlg;
  1698. dlg->adjustSize();
  1699. TQRect rect = dlg->geometry();
  1700. rect.moveCenter(TDEGlobalSettings::desktopGeometry(TQCursor::pos()).center());
  1701. dlg->move( rect.topLeft() );
  1702. if (mDialogs.isEmpty())
  1703. {
  1704. suspend();
  1705. XChangeActivePointerGrab( tqt_xdisplay(), GRABEVENTS,
  1706. TQCursor(tqarrowCursor).handle(), CurrentTime);
  1707. }
  1708. mDialogs.prepend( dlg );
  1709. fakeFocusIn( dlg->winId());
  1710. if (trinity_desktop_lock_use_system_modal_dialogs) {
  1711. if (backingPixmap.isNull()) {
  1712. setGeometry(0, 0, mRootWidth, mRootHeight);
  1713. erase();
  1714. }
  1715. else {
  1716. bitBlt(this, 0, 0, &backingPixmap);
  1717. }
  1718. }
  1719. // dlg->exec may generate BadMatch errors, so make sure they are silently ignored
  1720. int (*oldHandler)(Display *, XErrorEvent *);
  1721. oldHandler = XSetErrorHandler(ignoreXError);
  1722. int rt = dlg->exec();
  1723. XSetErrorHandler(oldHandler);
  1724. while (mDialogControlLock == true) usleep(100000);
  1725. currentDialog = NULL;
  1726. mDialogs.remove( dlg );
  1727. if( mDialogs.isEmpty() ) {
  1728. HANDLE cursorHandle;
  1729. if (trinity_desktop_hack_active) {
  1730. cursorHandle = TQCursor(tqblankCursor).handle();
  1731. }
  1732. else {
  1733. cursorHandle = TQCursor(tqbusyCursor).handle();
  1734. }
  1735. XChangeActivePointerGrab( tqt_xdisplay(), GRABEVENTS,
  1736. cursorHandle, CurrentTime);
  1737. if (trinity_desktop_lock_use_system_modal_dialogs) {
  1738. // Slight delay before screensaver resume to allow the dialog window to fully disappear
  1739. if (hackResumeTimer == NULL) {
  1740. hackResumeTimer = new TQTimer( this );
  1741. connect( hackResumeTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(resumeUnforced()) );
  1742. }
  1743. if (mResizingDesktopLock == false) {
  1744. hackResumeTimer->start( 10, TRUE );
  1745. }
  1746. }
  1747. else {
  1748. resume( false );
  1749. }
  1750. } else {
  1751. fakeFocusIn( mDialogs.first()->winId());
  1752. currentDialog = dynamic_cast<TQDialog*>(mDialogs.first());
  1753. }
  1754. return rt;
  1755. }
  1756. void LockProcess::slotForcePaintBackground()
  1757. {
  1758. TQPixmap blankPixmap(mRootWidth, mRootHeight);
  1759. blankPixmap.fill(Qt::black);
  1760. slotPaintBackground(blankPixmap);
  1761. printf("[WARNING] Unable to obtain desktop wallpaper in a timely manner. High system load or possibly a TDE bug!\n"); fflush(stdout);
  1762. }
  1763. void LockProcess::slotPaintBackground(const TQPixmap &rpm)
  1764. {
  1765. if (argb_visual) {
  1766. if (mEnsureScreenHiddenTimer) {
  1767. mEnsureScreenHiddenTimer->stop();
  1768. }
  1769. return;
  1770. }
  1771. if (mEnsureScreenHiddenTimer) {
  1772. mEnsureScreenHiddenTimer->stop();
  1773. }
  1774. else {
  1775. mEnsureScreenHiddenTimer = new TQTimer( this );
  1776. connect( mEnsureScreenHiddenTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotForcePaintBackground()) );
  1777. }
  1778. // Only remove the mask widget once the resize is 100% complete!
  1779. if (m_maskWidget) {
  1780. delete m_maskWidget;
  1781. m_maskWidget = NULL;
  1782. XSync(tqt_xdisplay(), False);
  1783. }
  1784. TQPixmap pm = rpm;
  1785. if (TQPaintDevice::x11AppDepth() == 32) {
  1786. // Remove the alpha components from the image
  1787. TQImage correctedImage = pm.convertToImage();
  1788. correctedImage = correctedImage.convertDepth(32);
  1789. correctedImage.setAlphaBuffer(true);
  1790. int w = correctedImage.width();
  1791. int h = correctedImage.height();
  1792. for (int y = 0; y < h; ++y) {
  1793. TQRgb *ls = (TQRgb *)correctedImage.scanLine( y );
  1794. for (int x = 0; x < w; ++x) {
  1795. TQRgb l = ls[x];
  1796. int r = int( tqRed( l ) );
  1797. int g = int( tqGreen( l ) );
  1798. int b = int( tqBlue( l ) );
  1799. int a = int( 255 );
  1800. ls[x] = tqRgba( r, g, b, a );
  1801. }
  1802. }
  1803. pm.convertFromImage(correctedImage);
  1804. }
  1805. backingPixmap = pm;
  1806. if ((trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced) || (!mHackStartupEnabled)) {
  1807. setBackgroundPixmap(backingPixmap);
  1808. setGeometry(0, 0, mRootWidth, mRootHeight);
  1809. erase();
  1810. }
  1811. }
  1812. void LockProcess::preparePopup()
  1813. {
  1814. TQWidget *dlg = (TQWidget *)sender();
  1815. mDialogs.prepend( dlg );
  1816. fakeFocusIn( dlg->winId() );
  1817. }
  1818. void LockProcess::cleanupPopup()
  1819. {
  1820. TQWidget *dlg = (TQWidget *)sender();
  1821. mDialogs.remove( dlg );
  1822. if ( mDialogs.isEmpty() ) {
  1823. fakeFocusIn( mDialogs.first()->winId() );
  1824. }
  1825. }
  1826. void LockProcess::doFunctionKeyBroadcast() {
  1827. // Provide a clean, pretty display switch by hiding the password dialog here
  1828. // This does NOT work with the SAK or system modal dialogs!
  1829. if ((!trinity_desktop_lock_use_system_modal_dialogs) && (!trinity_desktop_lock_use_sak)) {
  1830. mBusy=true;
  1831. TQTimer::singleShot(1000, this, TQT_SLOT(slotDeadTimePassed()));
  1832. if (mkeyCode == XKeysymToKeycode(tqt_xdisplay(), XF86XK_Display)) {
  1833. while (mDialogControlLock == true) usleep(100000);
  1834. mDialogControlLock = true;
  1835. currentDialog->close(); // DO NOT use closeCurrentWindow() here!
  1836. mDialogControlLock = false;
  1837. }
  1838. }
  1839. DCOPRef ref( "*", "MainApplication-Interface");
  1840. ref.send("sendFakeKey", DCOPArg(mkeyCode , "unsigned int"));
  1841. }
  1842. //---------------------------------------------------------------------------
  1843. //
  1844. // X11 Event.
  1845. //
  1846. bool LockProcess::x11Event(XEvent *event)
  1847. {
  1848. // Allow certain very specific keypresses through
  1849. // Key: Reason:
  1850. // XF86Display You need to be able to see the screen when unlocking your computer
  1851. // XF86AudioMute Would be nice to be able to shut your computer up in an emergency while it is locked
  1852. // XF86AudioRaiseVolume Ditto
  1853. // XF86AudioLowerVolume Ditto
  1854. //if ((event->type == KeyPress) || (event->type == KeyRelease)) {
  1855. if (event->type == KeyPress) {
  1856. if ((event->xkey.keycode == XKeysymToKeycode(event->xkey.display, XF86XK_Display)) || \
  1857. (event->xkey.keycode == XKeysymToKeycode(event->xkey.display, XF86XK_AudioMute)) || \
  1858. (event->xkey.keycode == XKeysymToKeycode(event->xkey.display, XF86XK_AudioRaiseVolume)) || \
  1859. (event->xkey.keycode == XKeysymToKeycode(event->xkey.display, XF86XK_AudioLowerVolume))) {
  1860. mkeyCode = event->xkey.keycode;
  1861. TQTimer::singleShot( 100, this, TQT_SLOT(doFunctionKeyBroadcast()) );
  1862. return true;
  1863. }
  1864. }
  1865. switch (event->type)
  1866. {
  1867. case ButtonPress:
  1868. case MotionNotify:
  1869. case ButtonRelease:
  1870. if( forwardVkbdEvent( event ))
  1871. return true; // filter out
  1872. // fall through
  1873. case KeyPress:
  1874. if ((mHackDelayStartupTimer) && (mHackDelayStartupTimer->isActive())) {
  1875. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  1876. }
  1877. if (mBusy || !mDialogs.isEmpty())
  1878. break;
  1879. mBusy = true;
  1880. if (trinity_desktop_lock_delay_screensaver_start) {
  1881. if (mLocked) {
  1882. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  1883. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  1884. }
  1885. if ((!mLocked) && (!trinity_desktop_lock_in_sec_dlg))
  1886. {
  1887. stopSaver();
  1888. kapp->quit();
  1889. }
  1890. if (mAutoLogout) // we need to restart the auto logout countdown
  1891. {
  1892. killTimer(mAutoLogoutTimerId);
  1893. mAutoLogoutTimerId = startTimer(mAutoLogoutTimeout);
  1894. }
  1895. }
  1896. else {
  1897. if (!mLocked || checkPass())
  1898. {
  1899. trinity_desktop_lock_closing_windows = true;
  1900. stopSaver();
  1901. kapp->quit();
  1902. }
  1903. else if (mAutoLogout) // we need to restart the auto logout countdown
  1904. {
  1905. killTimer(mAutoLogoutTimerId);
  1906. mAutoLogoutTimerId = startTimer(mAutoLogoutTimeout);
  1907. }
  1908. }
  1909. mBusy = false;
  1910. return true;
  1911. case VisibilityNotify:
  1912. if( event->xvisibility.window == winId())
  1913. { // mVisibility == false means the screensaver is not visible at all
  1914. // e.g. when switched to text console
  1915. mVisibility = !(event->xvisibility.state == VisibilityFullyObscured);
  1916. if(!mVisibility) {
  1917. mSuspendTimer.start(2000, true);
  1918. }
  1919. else
  1920. {
  1921. mSuspendTimer.stop();
  1922. if (mResizingDesktopLock == false) {
  1923. if (trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced && trinity_desktop_lock_use_system_modal_dialogs) {
  1924. // Do nothing
  1925. }
  1926. else {
  1927. if (mHackStartupEnabled == true) {
  1928. resume( false );
  1929. }
  1930. else {
  1931. if (trinity_desktop_lock_use_system_modal_dialogs == true) {
  1932. ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
  1933. if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
  1934. }
  1935. else {
  1936. resume( false );
  1937. }
  1938. }
  1939. }
  1940. }
  1941. }
  1942. if (event->xvisibility.state != VisibilityUnobscured) {
  1943. stayOnTop();
  1944. }
  1945. }
  1946. break;
  1947. case ConfigureNotify: // from SubstructureNotifyMask on the root window
  1948. if(event->xconfigure.event == tqt_xrootwin()) {
  1949. stayOnTop();
  1950. }
  1951. for( TQValueList< VkbdWindow >::Iterator it = mVkbdWindows.begin();
  1952. it != mVkbdWindows.end();
  1953. ++it ) {
  1954. if( (*it).id == event->xconfigure.window ) {
  1955. (*it).rect = TQRect( event->xconfigure.x, event->xconfigure.y,
  1956. event->xconfigure.width, event->xconfigure.height );
  1957. break;
  1958. }
  1959. }
  1960. break;
  1961. case MapNotify: // from SubstructureNotifyMask on the root window
  1962. windowAdded( event->xmap.window, false );
  1963. if( event->xmap.event == tqt_xrootwin())
  1964. stayOnTop();
  1965. break;
  1966. case DestroyNotify:
  1967. for( TQValueList< VkbdWindow >::Iterator it = mVkbdWindows.begin();
  1968. it != mVkbdWindows.end();
  1969. ++it )
  1970. if( (*it).id == event->xdestroywindow.window ) {
  1971. mVkbdWindows.remove( it );
  1972. break;
  1973. }
  1974. break;
  1975. }
  1976. // We have grab with the grab window being the root window.
  1977. // This results in key events being sent to the root window,
  1978. // but they should be sent to the dialog if it's visible.
  1979. // It could be solved by setFocus() call, but that would mess
  1980. // the focus after this process exits.
  1981. // Qt seems to be quite hard to persuade to redirect the event,
  1982. // so let's simply dupe it with correct destination window,
  1983. // and ignore the original one.
  1984. if(!mDialogs.isEmpty() && ( event->type == KeyPress || event->type == KeyRelease)
  1985. && event->xkey.window != mDialogs.first()->winId())
  1986. {
  1987. XEvent ev2 = *event;
  1988. ev2.xkey.window = ev2.xkey.subwindow = mDialogs.first()->winId();
  1989. tqApp->x11ProcessEvent( &ev2 );
  1990. return true;
  1991. }
  1992. return false;
  1993. }
  1994. void LockProcess::stayOnTop()
  1995. {
  1996. if(!mDialogs.isEmpty() || !mVkbdWindows.isEmpty())
  1997. {
  1998. // this restacking is written in a way so that
  1999. // if the stacking positions actually don't change,
  2000. // all restacking operations will be no-op,
  2001. // and no ConfigureNotify will be generated,
  2002. // thus avoiding possible infinite loops
  2003. if( !mVkbdWindows.isEmpty())
  2004. XRaiseWindow( tqt_xdisplay(), mVkbdWindows.first().id );
  2005. else
  2006. XRaiseWindow( tqt_xdisplay(), mDialogs.first()->winId()); // raise topmost
  2007. // and stack others below it
  2008. Window* stack = new Window[ mDialogs.count() + mVkbdWindows.count() + 1 ];
  2009. int count = 0;
  2010. for( TQValueList< VkbdWindow >::ConstIterator it = mVkbdWindows.begin();
  2011. it != mVkbdWindows.end();
  2012. ++it )
  2013. stack[ count++ ] = (*it).id;
  2014. for( TQValueList< TQWidget* >::ConstIterator it = mDialogs.begin();
  2015. it != mDialogs.end();
  2016. ++it )
  2017. stack[ count++ ] = (*it)->winId();
  2018. stack[ count++ ] = winId();
  2019. XRestackWindows( x11Display(), stack, count );
  2020. delete[] stack;
  2021. }
  2022. else
  2023. XRaiseWindow(tqt_xdisplay(), winId());
  2024. }
  2025. void LockProcess::checkDPMSActive()
  2026. {
  2027. #ifdef HAVE_DPMS
  2028. if (KDesktopSettings::dpmsDependent()) {
  2029. BOOL on;
  2030. CARD16 state;
  2031. if (DPMSInfo(tqt_xdisplay(), &state, &on)) {
  2032. //kdDebug() << "checkDPMSActive " << on << " " << state << endl;
  2033. if (DPMS_MONITOR_BLANKED(state)) {
  2034. suspend();
  2035. }
  2036. else if (mSuspended) {
  2037. if (mResizingDesktopLock == false) {
  2038. resume( true );
  2039. }
  2040. }
  2041. }
  2042. }
  2043. #endif
  2044. }
  2045. #if defined(HAVE_XF86MISC) && defined(HAVE_XF86MISCSETGRABKEYSSTATE)
  2046. // see http://cvsweb.xfree86.org/cvsweb/xc/programs/Xserver/hw/xfree86/common/xf86Events.c#rev3.113
  2047. // This allows enabling the "Allow{Deactivate/Closedown}Grabs" options in XF86Config,
  2048. // and kdesktop_lock will still lock the session.
  2049. static enum { Unknown, Yes, No } can_do_xf86_lock = Unknown;
  2050. void LockProcess::lockXF86()
  2051. {
  2052. if( can_do_xf86_lock == Unknown )
  2053. {
  2054. int major, minor;
  2055. if( XF86MiscQueryVersion( tqt_xdisplay(), &major, &minor )
  2056. && major >= 0 && minor >= 5 )
  2057. can_do_xf86_lock = Yes;
  2058. else
  2059. can_do_xf86_lock = No;
  2060. }
  2061. if( can_do_xf86_lock != Yes )
  2062. return;
  2063. if( mRestoreXF86Lock )
  2064. return;
  2065. if( XF86MiscSetGrabKeysState( tqt_xdisplay(), False ) != MiscExtGrabStateSuccess )
  2066. return;
  2067. // success
  2068. mRestoreXF86Lock = true;
  2069. }
  2070. void LockProcess::unlockXF86()
  2071. {
  2072. if( can_do_xf86_lock != Yes )
  2073. return;
  2074. if( !mRestoreXF86Lock )
  2075. return;
  2076. XF86MiscSetGrabKeysState( tqt_xdisplay(), True );
  2077. mRestoreXF86Lock = false;
  2078. }
  2079. #else
  2080. void LockProcess::lockXF86()
  2081. {
  2082. }
  2083. void LockProcess::unlockXF86()
  2084. {
  2085. }
  2086. #endif
  2087. void LockProcess::msgBox( TQMessageBox::Icon type, const TQString &txt )
  2088. {
  2089. TQDialog box( 0, "messagebox", true, (trinity_desktop_lock_use_system_modal_dialogs?((WFlags)WStyle_StaysOnTop):((WFlags)WX11BypassWM)) );
  2090. if (trinity_desktop_lock_use_system_modal_dialogs) {
  2091. // Signal that we do not want any window controls to be shown at all
  2092. Atom kde_wm_system_modal_notification;
  2093. kde_wm_system_modal_notification = XInternAtom(tqt_xdisplay(), "_KDE_WM_MODAL_SYS_NOTIFICATION", False);
  2094. XChangeProperty(tqt_xdisplay(), box.winId(), kde_wm_system_modal_notification, XA_INTEGER, 32, PropModeReplace, (unsigned char *) "TRUE", 1L);
  2095. }
  2096. box.setCaption(i18n("Authentication Subsystem Notice"));
  2097. TQFrame *winFrame = new TQFrame( &box );
  2098. if (trinity_desktop_lock_use_system_modal_dialogs)
  2099. winFrame->setFrameStyle( TQFrame::NoFrame );
  2100. else
  2101. winFrame->setFrameStyle( TQFrame::WinPanel | TQFrame::Raised );
  2102. winFrame->setLineWidth( 2 );
  2103. TQLabel *label1 = new TQLabel( winFrame );
  2104. label1->setPixmap( TQMessageBox::standardIcon( type ) );
  2105. TQLabel *label2 = new TQLabel( txt, winFrame );
  2106. KPushButton *button = new KPushButton( KStdGuiItem::ok(), winFrame );
  2107. button->setDefault( true );
  2108. button->setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Preferred ) );
  2109. connect( button, TQT_SIGNAL( clicked() ), &box, TQT_SLOT( accept() ) );
  2110. TQVBoxLayout *vbox = new TQVBoxLayout( &box );
  2111. vbox->addWidget( winFrame );
  2112. TQGridLayout *grid = new TQGridLayout( winFrame, 2, 2, 10 );
  2113. grid->addWidget( label1, 0, 0, Qt::AlignCenter );
  2114. grid->addWidget( label2, 0, 1, Qt::AlignCenter );
  2115. grid->addMultiCellWidget( button, 1,1, 0,1, Qt::AlignCenter );
  2116. execDialog( &box );
  2117. }
  2118. static int run_vkbd = -1;
  2119. void LockProcess::showVkbd()
  2120. {
  2121. if( run_vkbd == - 1 ) {
  2122. int status = system( "hal-find-by-property --key system.formfactor.subtype --string tabletpc" );
  2123. // status = 0; // enable for testing
  2124. run_vkbd = ( WIFEXITED( status ) && WEXITSTATUS( status ) == 0
  2125. && !TDEStandardDirs::findExe( "xvkbd" ).isEmpty()) ? 1 : 0;
  2126. }
  2127. if( run_vkbd ) {
  2128. mVkbdWindows.clear();
  2129. mVkbdLastEventWindow = None;
  2130. mKWinModule = new KWinModule( NULL, KWinModule::INFO_WINDOWS );
  2131. connect( mKWinModule, TQT_SIGNAL( windowAdded( WId )), TQT_SLOT( windowAdded( WId )));
  2132. mVkbdProcess = new TDEProcess;
  2133. *mVkbdProcess << "xvkbd" << "-compact" << "-geometry" << "-0-0" << "-xdm";
  2134. mVkbdProcess->start();
  2135. }
  2136. }
  2137. void LockProcess::hideVkbd()
  2138. {
  2139. if( mVkbdProcess != NULL ) {
  2140. mVkbdProcess->kill();
  2141. delete mVkbdProcess;
  2142. mVkbdProcess = NULL;
  2143. delete mKWinModule;
  2144. mKWinModule = NULL;
  2145. mVkbdWindows.clear();
  2146. }
  2147. }
  2148. void LockProcess::windowAdded( WId w )
  2149. {
  2150. windowAdded( w, true );
  2151. }
  2152. void LockProcess::windowAdded( WId w, bool managed )
  2153. {
  2154. // KWin::windowInfo may generate BadWindow errors, so make sure they are silently ignored
  2155. int (*oldHandler)(Display *, XErrorEvent *);
  2156. oldHandler = XSetErrorHandler(ignoreXError);
  2157. KWin::WindowInfo info = KWin::windowInfo( w, 0, NET::WM2WindowClass );
  2158. XSetErrorHandler(oldHandler);
  2159. if( info.windowClassClass().lower() != "xvkbd" )
  2160. return;
  2161. // Unmanaged windows (i.e. popups) don't currently work anyway, since they
  2162. // don't have WM_CLASS set anyway. I could perhaps try tricks with X id
  2163. // ranges if really needed.
  2164. if( managed ) {
  2165. // withdraw the window, wait for it to be withdrawn, reparent it directly
  2166. // to root at the right position
  2167. XWithdrawWindow( tqt_xdisplay(), w, tqt_xscreen());
  2168. for(;;) {
  2169. Atom type;
  2170. int format;
  2171. unsigned long length, after;
  2172. unsigned char *data;
  2173. int r = XGetWindowProperty( tqt_xdisplay(), w, tqt_wm_state, 0, 2,
  2174. false, AnyPropertyType, &type, &format,
  2175. &length, &after, &data );
  2176. bool withdrawn = true;
  2177. if ( r == Success && data && format == 32 ) {
  2178. TQ_UINT32 *wstate = (TQ_UINT32*)data;
  2179. withdrawn = (*wstate == WithdrawnState );
  2180. XFree( (char *)data );
  2181. }
  2182. if( withdrawn )
  2183. break;
  2184. }
  2185. }
  2186. XSelectInput( tqt_xdisplay(), w, StructureNotifyMask );
  2187. XWindowAttributes attr_geom;
  2188. if( !XGetWindowAttributes( tqt_xdisplay(), w, &attr_geom ))
  2189. return;
  2190. int x = XDisplayWidth( tqt_xdisplay(), tqt_xscreen()) - attr_geom.width;
  2191. int y = XDisplayHeight( tqt_xdisplay(), tqt_xscreen()) - attr_geom.height;
  2192. if( managed ) {
  2193. XSetWindowAttributes attr;
  2194. if (!trinity_desktop_lock_use_system_modal_dialogs) {
  2195. attr.override_redirect = True;
  2196. XChangeWindowAttributes( tqt_xdisplay(), w, CWOverrideRedirect, &attr );
  2197. }
  2198. XReparentWindow( tqt_xdisplay(), w, tqt_xrootwin(), x, y );
  2199. XMapWindow( tqt_xdisplay(), w );
  2200. }
  2201. VkbdWindow data;
  2202. data.id = w;
  2203. data.rect = TQRect( x, y, attr_geom.width, attr_geom.height );
  2204. mVkbdWindows.prepend( data );
  2205. }
  2206. bool LockProcess::forwardVkbdEvent( XEvent* event )
  2207. {
  2208. if( mVkbdProcess == NULL )
  2209. return false;
  2210. TQPoint pos;
  2211. Time time;
  2212. switch( event->type )
  2213. {
  2214. case ButtonPress:
  2215. case ButtonRelease:
  2216. pos = TQPoint( event->xbutton.x, event->xbutton.y );
  2217. time = event->xbutton.time;
  2218. break;
  2219. case MotionNotify:
  2220. pos = TQPoint( event->xmotion.x, event->xmotion.y );
  2221. time = event->xmotion.time;
  2222. break;
  2223. default:
  2224. return false;
  2225. }
  2226. // vkbd windows are kept topmost, so just find the first one in the position
  2227. for( TQValueList< VkbdWindow >::ConstIterator it = mVkbdWindows.begin();
  2228. it != mVkbdWindows.end();
  2229. ++it ) {
  2230. if( TQT_TQRECT_OBJECT((*it).rect).contains( pos )) {
  2231. // Find the subwindow where the event should actually go.
  2232. // Not exactly cheap in the number of X roundtrips but oh well.
  2233. Window window = (*it).id;
  2234. Window root, child;
  2235. int root_x, root_y, x, y;
  2236. unsigned int mask;
  2237. for(;;) {
  2238. if( !XQueryPointer( tqt_xdisplay(), window, &root, &child, &root_x, &root_y, &x, &y, &mask ))
  2239. return false;
  2240. if( child == None )
  2241. break;
  2242. window = child;
  2243. }
  2244. switch( event->type )
  2245. {
  2246. case ButtonPress:
  2247. case ButtonRelease:
  2248. event->xbutton.x = x;
  2249. event->xbutton.y = y;
  2250. event->xbutton.subwindow = None;
  2251. break;
  2252. case MotionNotify:
  2253. event->xmotion.x = x;
  2254. event->xmotion.y = y;
  2255. event->xmotion.subwindow = None;
  2256. break;
  2257. }
  2258. event->xany.window = window;
  2259. sendVkbdFocusInOut( window, time );
  2260. XSendEvent( tqt_xdisplay(), window, False, 0, event );
  2261. return true;
  2262. }
  2263. }
  2264. sendVkbdFocusInOut( None, time );
  2265. return false;
  2266. }
  2267. // Fake EnterNotify/LeaveNotify events as the mouse moves. They're not sent by X
  2268. // because of the grab and having them makes xvkbd highlight the buttons (but
  2269. // not needed otherwise it seems).
  2270. void LockProcess::sendVkbdFocusInOut( WId window, Time t )
  2271. {
  2272. if( mVkbdLastEventWindow == window )
  2273. return;
  2274. if( mVkbdLastEventWindow != None ) {
  2275. XEvent e;
  2276. e.xcrossing.type = LeaveNotify;
  2277. e.xcrossing.display = tqt_xdisplay();
  2278. e.xcrossing.window = mVkbdLastEventWindow;
  2279. e.xcrossing.root = tqt_xrootwin();
  2280. e.xcrossing.subwindow = None;
  2281. e.xcrossing.time = t;
  2282. e.xcrossing.x = 0;
  2283. e.xcrossing.y = 0;
  2284. e.xcrossing.x_root = -1;
  2285. e.xcrossing.y_root = -1;
  2286. e.xcrossing.mode = NotifyNormal;
  2287. e.xcrossing.detail = NotifyAncestor;
  2288. e.xcrossing.same_screen = True;
  2289. e.xcrossing.focus = False;
  2290. e.xcrossing.state = 0;
  2291. XSendEvent( tqt_xdisplay(), mVkbdLastEventWindow, False, 0, &e );
  2292. }
  2293. mVkbdLastEventWindow = window;
  2294. if( mVkbdLastEventWindow != None ) {
  2295. XEvent e;
  2296. e.xcrossing.type = EnterNotify;
  2297. e.xcrossing.display = tqt_xdisplay();
  2298. e.xcrossing.window = mVkbdLastEventWindow;
  2299. e.xcrossing.root = tqt_xrootwin();
  2300. e.xcrossing.subwindow = None;
  2301. e.xcrossing.time = t;
  2302. e.xcrossing.x = 0;
  2303. e.xcrossing.y = 0;
  2304. e.xcrossing.x_root = 0;
  2305. e.xcrossing.y_root = 0;
  2306. e.xcrossing.mode = NotifyNormal;
  2307. e.xcrossing.detail = NotifyAncestor;
  2308. e.xcrossing.same_screen = True;
  2309. e.xcrossing.focus = False;
  2310. e.xcrossing.state = 0;
  2311. XSendEvent( tqt_xdisplay(), mVkbdLastEventWindow, False, 0, &e );
  2312. }
  2313. }
  2314. void LockProcess::slotMouseActivity(XEvent *event)
  2315. {
  2316. bool inFrame = 0;
  2317. bool inDialog = 0;
  2318. XButtonEvent *be = (XButtonEvent *) event;
  2319. XMotionEvent *me = (XMotionEvent *) event;
  2320. if ((event->type == ButtonPress) && (!mDialogs.isEmpty())) {
  2321. // Get geometry including window frame/titlebar
  2322. TQRect fgeom = mDialogs.first()->frameGeometry();
  2323. TQRect wgeom = mDialogs.first()->geometry();
  2324. if (((be->x_root > fgeom.x()) && (be->y_root > fgeom.y())) && ((be->x_root < (fgeom.x()+fgeom.width())) && (be->y_root < (fgeom.y()+fgeom.height())))) {
  2325. inFrame = 1;
  2326. }
  2327. if (((be->x_root > wgeom.x()) && (be->y_root > wgeom.y())) && ((be->x_root < (wgeom.x()+wgeom.width())) && (be->y_root < (wgeom.y()+wgeom.height())))) {
  2328. inDialog = 1;
  2329. }
  2330. // Clicked inside dialog; set focus
  2331. if (inFrame == TRUE) {
  2332. WId window = mDialogs.first()->winId();
  2333. XSetInputFocus(tqt_xdisplay(), window, RevertToParent, CurrentTime);
  2334. fakeFocusIn(window);
  2335. // Why this needs to be repeated I have no idea...
  2336. XSetInputFocus(tqt_xdisplay(), window, RevertToParent, CurrentTime);
  2337. fakeFocusIn(window);
  2338. }
  2339. // Clicked inside window handle (or border); drag window
  2340. if ((inFrame == TRUE) && (inDialog == FALSE)) {
  2341. TQPoint oldPoint = mDialogs.first()->pos();
  2342. m_mouseDown = 1;
  2343. m_dialogPrevX = oldPoint.x();
  2344. m_dialogPrevY = oldPoint.y();
  2345. m_mousePrevX = be->x_root;
  2346. m_mousePrevY = be->y_root;
  2347. XChangeActivePointerGrab( tqt_xdisplay(), GRABEVENTS, TQCursor(tqsizeAllCursor).handle(), CurrentTime);
  2348. }
  2349. }
  2350. // Drag the window...
  2351. if (event->type == MotionNotify) {
  2352. if (m_mouseDown == TRUE) {
  2353. int deltaX = me->x_root - m_mousePrevX;
  2354. int deltaY = me->y_root - m_mousePrevY;
  2355. m_dialogPrevX = m_dialogPrevX + deltaX;
  2356. m_dialogPrevY = m_dialogPrevY + deltaY;
  2357. if (!mDialogs.isEmpty()) mDialogs.first()->move(m_dialogPrevX, m_dialogPrevY);
  2358. m_mousePrevX = me->x_root;
  2359. m_mousePrevY = me->y_root;
  2360. }
  2361. }
  2362. if (event->type == ButtonRelease) {
  2363. m_mouseDown = 0;
  2364. XChangeActivePointerGrab( tqt_xdisplay(), GRABEVENTS, TQCursor(tqarrowCursor).handle(), CurrentTime);
  2365. }
  2366. }
  2367. void LockProcess::processInputPipeCommand(TQString inputcommand) {
  2368. TQCString command(inputcommand.ascii());
  2369. TQString to_display;
  2370. const char * pin_entry;
  2371. if (command[0] == 'C') {
  2372. while (mDialogControlLock == true) usleep(100000);
  2373. mDialogControlLock = true;
  2374. if (mInfoMessageDisplayed || !trinity_desktop_lock_use_system_modal_dialogs) {
  2375. if (currentDialog != NULL) {
  2376. mForceReject = true;
  2377. closeCurrentWindow();
  2378. }
  2379. }
  2380. trinity_desktop_lock_closing_windows = false;
  2381. mInfoMessageDisplayed = false;
  2382. mDialogControlLock = false;
  2383. }
  2384. if (command[0] == 'T') {
  2385. to_display = command.data();
  2386. to_display = to_display.remove(0,1);
  2387. // Lock out password dialogs and close any active dialog
  2388. while (mDialogControlLock == true) usleep(100000);
  2389. mDialogControlLock = true;
  2390. if (mInfoMessageDisplayed || !trinity_desktop_lock_use_system_modal_dialogs) {
  2391. if (currentDialog != NULL) {
  2392. mForceReject = true;
  2393. closeCurrentWindow();
  2394. }
  2395. }
  2396. mInfoMessageDisplayed = true;
  2397. mDialogControlLock = false;
  2398. // Display info message dialog
  2399. InfoDlg inDlg( this );
  2400. inDlg.updateLabel(to_display);
  2401. inDlg.setUnlockIcon();
  2402. execDialog( &inDlg );
  2403. mForceReject = false;
  2404. trinity_desktop_lock_closing_windows = false;
  2405. return;
  2406. }
  2407. if ((command[0] == 'E') || (command[0] == 'W') || (command[0] == 'I') || (command[0] == 'K')) {
  2408. to_display = command.data();
  2409. to_display = to_display.remove(0,1);
  2410. // Lock out password dialogs and close any active dialog
  2411. while (mDialogControlLock == true) usleep(100000);
  2412. mDialogControlLock = true;
  2413. if (mInfoMessageDisplayed || !trinity_desktop_lock_use_system_modal_dialogs) {
  2414. if (currentDialog != NULL) {
  2415. mForceReject = true;
  2416. closeCurrentWindow();
  2417. }
  2418. }
  2419. mInfoMessageDisplayed = true;
  2420. mDialogControlLock = false;
  2421. // Display info message dialog
  2422. InfoDlg inDlg( this );
  2423. inDlg.updateLabel(to_display);
  2424. if (command[0] == 'K') inDlg.setKDEIcon();
  2425. if (command[0] == 'I') inDlg.setInfoIcon();
  2426. if (command[0] == 'W') inDlg.setWarningIcon();
  2427. if (command[0] == 'E') inDlg.setErrorIcon();
  2428. execDialog( &inDlg );
  2429. mForceReject = false;
  2430. trinity_desktop_lock_closing_windows = false;
  2431. return;
  2432. }
  2433. if (command[0] == 'Q') {
  2434. to_display = command.data();
  2435. to_display = to_display.remove(0,1);
  2436. // Lock out password dialogs and close any active dialog
  2437. while (mDialogControlLock == true) usleep(100000);
  2438. mDialogControlLock = true;
  2439. if (mInfoMessageDisplayed || !trinity_desktop_lock_use_system_modal_dialogs) {
  2440. if (currentDialog != NULL) {
  2441. mForceReject = true;
  2442. closeCurrentWindow();
  2443. }
  2444. }
  2445. mInfoMessageDisplayed = true;
  2446. mDialogControlLock = false;
  2447. // Display query dialog
  2448. QueryDlg qryDlg( this );
  2449. qryDlg.updateLabel(to_display);
  2450. qryDlg.setUnlockIcon();
  2451. mForceReject = false;
  2452. execDialog( &qryDlg );
  2453. if (mForceReject == false) {
  2454. pin_entry = qryDlg.getEntry();
  2455. mInfoMessageDisplayed=false;
  2456. if (mPipeOpen_out == true) {
  2457. if (write(mPipe_fd_out, pin_entry, strlen(pin_entry)+1) == -1) {
  2458. // Error handler to shut up gcc warnings
  2459. }
  2460. if (write(mPipe_fd_out, "\n\r", 3) == -1) {
  2461. // Error handler to shut up gcc warnings
  2462. }
  2463. }
  2464. }
  2465. mForceReject = false;
  2466. trinity_desktop_lock_closing_windows = false;
  2467. return;
  2468. }
  2469. }
  2470. //===========================================================================
  2471. //
  2472. // Control pipe handler
  2473. //
  2474. ControlPipeHandlerObject::ControlPipeHandlerObject() : TQObject() {
  2475. mParent = NULL;
  2476. }
  2477. ControlPipeHandlerObject::~ControlPipeHandlerObject() {
  2478. //
  2479. }
  2480. void ControlPipeHandlerObject::run(void) {
  2481. int display_number = atoi(TQString(XDisplayString(tqt_xdisplay())).replace(":","").ascii());
  2482. if (display_number < 0) {
  2483. printf("[kdesktop_lock] Warning: unable to create control socket. Interactive logon modules may not function properly.\n");
  2484. TQApplication::eventLoop()->exit(-1);
  2485. return;
  2486. }
  2487. char fifo_file[PATH_MAX];
  2488. char fifo_file_out[PATH_MAX];
  2489. snprintf(fifo_file, PATH_MAX, FIFO_FILE, display_number);
  2490. snprintf(fifo_file_out, PATH_MAX, FIFO_FILE_OUT, display_number);
  2491. /* Create the FIFOs if they do not exist */
  2492. umask(0);
  2493. mkdir(FIFO_DIR,0644);
  2494. mknod(fifo_file, S_IFIFO|0644, 0);
  2495. chmod(fifo_file, 0644);
  2496. mParent->mPipe_fd = open(fifo_file, O_RDONLY | O_NONBLOCK);
  2497. if (mParent->mPipe_fd > -1) {
  2498. mParent->mPipeOpen = true;
  2499. }
  2500. mknod(fifo_file_out, S_IFIFO|0600, 0);
  2501. chmod(fifo_file_out, 0600);
  2502. mParent->mPipe_fd_out = open(fifo_file_out, O_RDWR | O_NONBLOCK);
  2503. if (mParent->mPipe_fd_out > -1) {
  2504. mParent->mPipeOpen_out = true;
  2505. }
  2506. if (!mParent->mPipeOpen) {
  2507. printf("[kdesktop_lock] Warning: unable to create control socket '%s'. Interactive logon modules may not function properly.\n", fifo_file);
  2508. TQApplication::eventLoop()->exit(-1);
  2509. return;
  2510. }
  2511. int numread;
  2512. int retval;
  2513. fd_set rfds;
  2514. FD_ZERO(&rfds);
  2515. FD_SET(mParent->mPipe_fd, &rfds);
  2516. TQByteArray readbuf(128);
  2517. while (mParent->mPipeOpen) {
  2518. TQString inputcommand = "";
  2519. // Wait for mParent->mPipe_fd to receive input
  2520. retval = select(mParent->mPipe_fd + 1, &rfds, NULL, NULL, NULL);
  2521. if (retval < 0) {
  2522. // ERROR
  2523. }
  2524. else if (retval) {
  2525. // New data is available
  2526. readbuf[0]=' ';
  2527. numread = read(mParent->mPipe_fd, readbuf.data(), 128);
  2528. readbuf[numread] = 0;
  2529. if (numread > 0) {
  2530. inputcommand += readbuf;
  2531. emit processCommand(inputcommand);
  2532. }
  2533. }
  2534. }
  2535. TQApplication::eventLoop()->exit(0);
  2536. return;
  2537. }
  2538. #include "lockprocess.moc"