Changeset 20931
- Timestamp:
- 11/18/07 13:16:42 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
juggler/trunk/modules/gadgeteer/gadget/Devices/KeyboardMouseDevice/InputWindowXWin.cpp
r20930 r20931 54 54 bool InputWindowXWin::config(jccl::ConfigElementPtr e) 55 55 { 56 unsigned required_definition_ver(1);57 58 if ( e->getVersion() < required_definition_ver)56 const unsigned required_definition_ver(1); 57 58 if ( e->getVersion() < required_definition_ver ) 59 59 { 60 60 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) … … 102 102 << std::endl << vprDEBUG_FLUSH; 103 103 104 if ( NULL == disp_sys_elt.get())104 if ( NULL == disp_sys_elt.get() ) 105 105 { 106 106 vprDEBUG(vprDBG_ERROR, vprDBG_CONFIG_LVL) … … 139 139 } 140 140 141 if ((mXDisplayString.empty()) || (strcmp(mXDisplayString.c_str(), neg_one_STRING) == 0)) // Use display env 142 { 141 if ( mXDisplayString.empty() || 142 strcmp(mXDisplayString.c_str(), neg_one_STRING) == 0 ) 143 { 144 // Use the value of the DISPLAY environment variable. 143 145 const std::string DISPLAY_str("DISPLAY"); 144 146 vpr::System::getenv(DISPLAY_str, mXDisplayString); 145 147 } 148 146 149 return true; 147 150 } … … 149 152 bool InputWindowXWin::startSampling() 150 153 { 151 if ( mThread != NULL)152 { 153 vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)154 << clrOutNORM(clrRED, "ERROR")155 << ": gadget::InputWindowXWin: startSampling called, when already sampling.\n"156 << vprDEBUG_FLUSH;154 if ( NULL != mThread ) 155 { 156 vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL) 157 << clrOutNORM(clrRED, "ERROR") 158 << ": [gadget::InputWindowXWin::startSampling] " 159 << "Called when already sampling.\n" << vprDEBUG_FLUSH; 157 160 vprASSERT(false); 158 161 } … … 184 187 { 185 188 // If there is a thread for us and we actually own the window 186 if ( mThread != NULL)189 if ( NULL != mThread ) 187 190 { 188 191 mExitFlag = true; … … 206 209 void InputWindowXWin::controlLoop() 207 210 { 208 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)209 << " gadget::InputWindowXWin::controlLoop:Thread started.\n"211 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL) 212 << "[gadget::InputWindowXWin::controlLoop()] Thread started.\n" 210 213 << vprDEBUG_FLUSH; 211 214 212 while ( NULL == vpr::Thread::self())215 while ( NULL == vpr::Thread::self() ) 213 216 { 214 217 vpr::System::usleep(50); 215 vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)216 << " gadget::InputWindowXWin: Waiting for (thread::self() != NULL)\n"217 << vprDEBUG_FLUSH;218 vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL) 219 << "[gadget::InputWindowXWin::controlLoop()] " 220 << "Waiting for (thread::self() != NULL)\n" << vprDEBUG_FLUSH; 218 221 } 219 222 mThread = (vpr::Thread*) vpr::Thread::self(); … … 228 231 XSync(mXDisplay, 0); 229 232 230 // If we have initial locked, then we need to lock the system 231 if ( mLockState == Lock_LockKey) // Means that we are in the initially locked state232 { 233 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)234 << " gadget::InputWindowXWin::controlLoop: Mouse set to initial lock. Locking it now.\n"235 << vprDEBUG_FLUSH;236 lockMouse( NULL); // Lock the mouse233 // If we have initial locked, then we need to lock the system. 234 if ( mLockState == Lock_LockKey ) 235 { 236 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL) 237 << "[gadget::InputWindowXWin::controlLoop()] " 238 << "Mouse set to initial lock. Locking it now.\n" << vprDEBUG_FLUSH; 239 lockMouse(NULL); // Lock the mouse 237 240 } 238 241 239 242 // Loop on updating 240 while ( !mExitFlag)243 while ( ! mExitFlag ) 241 244 { 242 245 sample(); 243 long usleep_time(1); // to be set... 244 245 usleep_time = mSleepTimeMS*1000; 246 247 vpr::System::usleep(usleep_time); 246 vpr::System::usleep(mSleepTimeMS * 1000); 248 247 } 249 248 … … 259 258 XCloseDisplay((::Display*) mXDisplay); 260 259 } 261 262 260 263 261 /*****************************************************************/ … … 269 267 bool InputWindowXWin::openLocalWindow() 270 268 { 271 int i;272 273 269 mXDisplay = XOpenDisplay(mXDisplayString.c_str()); // Open display on given XDisplay 274 if ( NULL == mXDisplay)270 if ( NULL == mXDisplay ) 275 271 { 276 272 vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL) … … 279 275 << "Failed to open display '" << mXDisplayString << "'" << std::endl 280 276 << vprDEBUG_FLUSH; 281 return 0;277 return false; 282 278 } 283 279 284 280 mScreen = DefaultScreen(mXDisplay); 285 281 286 XVisualInfo v Template, *vis_infos;287 long vMask = VisualScreenMask;288 vTemplate.screen = mScreen;289 int nVisuals; 290 291 vis_infos = XGetVisualInfo(mXDisplay, vMask, &vTemplate, &nVisuals);282 XVisualInfo vi_template; 283 vi_template.screen = mScreen; 284 int num_visuals(0); 285 286 XVisualInfo* vis_infos = XGetVisualInfo(mXDisplay, VisualScreenMask, 287 &vi_template, &num_visuals); 292 288 293 289 // Verify that we got at least one visual from XGetVisualInfo(3). 294 if ( vis_infos != NULL && n Visuals >= 1 )290 if ( vis_infos != NULL && num_visuals >= 1 ) 295 291 { 296 292 XVisualInfo* p_visinfo; 293 int i; 297 294 298 295 // Try to find a visual with color depth of at least 8 bits. Having 299 296 // such a visual ensures that the input windows at least have a 300 297 // black background. 301 for ( i = 0, p_visinfo = vis_infos; i < n Visuals; i++, p_visinfo++)298 for ( i = 0, p_visinfo = vis_infos; i < num_visuals; ++i, ++p_visinfo ) 302 299 { 303 300 if ( p_visinfo->depth >= 8 ) … … 310 307 // If we couldn't find a visual with at least 8-bit color, just use the 311 308 // first one in the list. 312 if ( i == n Visuals )309 if ( i == num_visuals ) 313 310 { 314 311 mVisual = vis_infos; … … 322 319 << ": [gadget::InputWindowXWin::openTheWindow()] find visual failed" 323 320 << std::endl << vprDEBUG_FLUSH; 324 return 0;321 return false; 325 322 } 326 323 … … 354 351 XFree(vis_infos); 355 352 356 return 1;353 return true; 357 354 } 358 355 … … 408 405 status = XStringListToTextProperty(&window_name, 1, &w_name); 409 406 410 if ( 0 == status)407 if ( 0 == status ) 411 408 { 412 409 vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL) … … 418 415 status = XStringListToTextProperty(&icon_name, 1, &i_name); 419 416 420 if ( 0 == status)417 if ( 0 == status ) 421 418 { 422 419 vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
