- Timestamp:
- Jan 21, 2022 4:19:23 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/x11/VBoxClient/display-helper-generic.cpp
r93380 r93400 40 40 #include <X11/Xlibint.h> 41 41 42 /* A log prefix which is specific for this source file. */43 #define VBCL_HLP_LOG_PREFIX "display-helper-generic "44 45 42 /** Name of Display Change Monitor thread. */ 46 43 #define VBCL_HLP_DCM_THREAD_NAME "dcm-task" 47 44 48 45 /** Display Change Monitor thread. */ 49 static RTTHREAD vbclHlpGenericDcmThread = NIL_RTTHREAD;46 static RTTHREAD g_vbclHlpGenericDcmThread = NIL_RTTHREAD; 50 47 51 48 /** Global flag which is triggered when service requested to shutdown. */ … … 166 163 static void vbcl_hlp_generic_process_display_change_event(Display *pDisplay) 167 164 { 168 int iCount, idxDisplay = 0; 165 int iCount; 166 uint32_t idxDisplay = 0; 169 167 XRRMonitorInfo *pMonitorsInfo = XRRGetMonitors(pDisplay, DefaultRootWindow(pDisplay), true, &iCount); 170 if (pMonitorsInfo && iCount && iCount < VBOX_DRMIPC_MONITORS_MAX)168 if (pMonitorsInfo && iCount > 0 && iCount < VBOX_DRMIPC_MONITORS_MAX) 171 169 { 172 170 int rc; … … 182 180 if (RT_FAILURE(rc)) 183 181 { 184 VBClLogError( VBCL_HLP_LOG_PREFIX"unable to fill monitors info list, rc=%Rrc\n", rc);182 VBClLogError("unable to fill monitors info list, rc=%Rrc\n", rc); 185 183 break; 186 184 } … … 192 190 char *pszMonitorName = XGetAtomName(pDisplay, pIter->pMonitorInfo->name); 193 191 194 VBClLogVerbose(1, VBCL_HLP_LOG_PREFIX"reporting monitor %s offset: (%d, %d)\n",192 VBClLogVerbose(1, "reporting monitor %s offset: (%d, %d)\n", 195 193 pszMonitorName, pIter->pMonitorInfo->x, pIter->pMonitorInfo->y); 196 194 … … 208 206 if (g_pfnDisplayOffsetChangeCb) 209 207 { 210 rc = g_pfnDisplayOffsetChangeCb(i Count, aDisplayOffsets);208 rc = g_pfnDisplayOffsetChangeCb(idxDisplay, aDisplayOffsets); 211 209 if (RT_FAILURE(rc)) 212 VBClLogError( VBCL_HLP_LOG_PREFIX"unable to notify subscriber about monitors info change, rc=%Rrc\n", rc);210 VBClLogError("unable to notify subscriber about monitors info change, rc=%Rrc\n", rc); 213 211 } 214 212 } 215 213 else 216 VBClLogError( VBCL_HLP_LOG_PREFIX"cannot get monitors info\n");214 VBClLogError("cannot get monitors info\n"); 217 215 } 218 216 … … 269 267 else 270 268 { 271 VBClLogError( VBCL_HLP_LOG_PREFIX"dcm monitor cannot find XRandr 1.3+ extension\n");269 VBClLogError("dcm monitor cannot find XRandr 1.3+ extension\n"); 272 270 rc = VERR_NOT_AVAILABLE; 273 271 } … … 277 275 else 278 276 { 279 VBClLogError( VBCL_HLP_LOG_PREFIX"dcm monitor cannot open X Display\n");277 VBClLogError("dcm monitor cannot open X Display\n"); 280 278 rc = VERR_NOT_AVAILABLE; 281 279 } … … 286 284 } 287 285 288 RTDECL(int)vbcl_hlp_generic_start_display_change_monitor()286 static void vbcl_hlp_generic_start_display_change_monitor() 289 287 { 290 288 int rc; … … 294 292 { 295 293 /* Start thread which will monitor display change events. */ 296 rc = RTThreadCreate(& vbclHlpGenericDcmThread, vbcl_hlp_generic_display_change_event_monitor_worker, (void *)NULL, 0,294 rc = RTThreadCreate(&g_vbclHlpGenericDcmThread, vbcl_hlp_generic_display_change_event_monitor_worker, (void *)NULL, 0, 297 295 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, VBCL_HLP_DCM_THREAD_NAME); 298 296 if (RT_SUCCESS(rc)) 299 297 { 300 rc = RTThreadUserWait( vbclHlpGenericDcmThread, RT_MS_5SEC);298 rc = RTThreadUserWait(g_vbclHlpGenericDcmThread, RT_MS_5SEC); 301 299 } 302 300 else 303 vbclHlpGenericDcmThread = NIL_RTTHREAD;304 305 VBClLogInfo( VBCL_HLP_LOG_PREFIX"attempt to start display change monitor thread, rc=%Rrc\n", rc);301 g_vbclHlpGenericDcmThread = NIL_RTTHREAD; 302 303 VBClLogInfo("attempt to start display change monitor thread, rc=%Rrc\n", rc); 306 304 307 305 } 308 306 else 309 VBClLogInfo(VBCL_HLP_LOG_PREFIX "libXrandr not available, will not monitor display change events, rc=%Rrc\n", rc); 310 311 return rc; 307 VBClLogInfo("libXrandr not available, will not monitor display change events, rc=%Rrc\n", rc); 312 308 } 313 309 … … 331 327 { 332 328 XRRSetOutputPrimary(pDisplay, DefaultRootWindow(pDisplay), pScreenResources->outputs[idDisplay]); 333 VBClLogInfo( VBCL_HLP_LOG_PREFIX"display %u has been set as primary\n", idDisplay);329 VBClLogInfo("display %u has been set as primary\n", idDisplay); 334 330 rc = VINF_SUCCESS; 335 331 } 336 332 else 337 VBClLogError( VBCL_HLP_LOG_PREFIX"cannot set display %u as primary: index out of range\n", idDisplay);333 VBClLogError("cannot set display %u as primary: index out of range\n", idDisplay); 338 334 339 335 XRRFreeScreenResources(pScreenResources); 340 336 } 341 337 else 342 VBClLogError( VBCL_HLP_LOG_PREFIX"cannot set display %u as primary: libXrandr can not get screen resources\n", idDisplay);338 VBClLogError("cannot set display %u as primary: libXrandr can not get screen resources\n", idDisplay); 343 339 344 340 XCloseDisplay(pDisplay); 345 341 } 346 342 else 347 VBClLogError( VBCL_HLP_LOG_PREFIX"cannot set display %u as primary: cannot connect to X11\n", idDisplay);343 VBClLogError("cannot set display %u as primary: cannot connect to X11\n", idDisplay); 348 344 349 345 return rc; … … 368 364 ASMAtomicWriteBool(&g_fShutdown, false); 369 365 370 /* Attempt to start display change events monitor. Ignore rc, 371 * error will be printed inside function anyway. */ 372 (void)vbcl_hlp_generic_start_display_change_monitor(); 366 /* Attempt to start display change events monitor. */ 367 vbcl_hlp_generic_start_display_change_monitor(); 373 368 374 369 /* Always return positive status for generic (fallback, last resort) helper. */ … … 383 378 int rc = VINF_SUCCESS; 384 379 385 if ( vbclHlpGenericDcmThread != NIL_RTTHREAD)380 if (g_vbclHlpGenericDcmThread != NIL_RTTHREAD) 386 381 { 387 382 /* Signal thread we are going to shutdown. */ … … 389 384 390 385 /* Wait for thread to terminate gracefully. */ 391 rc = RTThreadWait( vbclHlpGenericDcmThread, RT_MS_5SEC, NULL);386 rc = RTThreadWait(g_vbclHlpGenericDcmThread, RT_MS_5SEC, NULL); 392 387 } 393 388
Note:
See TracChangeset
for help on using the changeset viewer.