bool Window::configInitAGLFullscreen() { AGLContext context = getAGLContext(); if( !context ) { sendError( ERROR_AGLWINDOW_NO_CONTEXT ); return false; } Global::enterCarbon(); aglEnable( context, AGL_FS_CAPTURE_SINGLE ); const PixelViewport& pvp = getPixelViewport(); if( !aglSetFullScreen( context, pvp.w, pvp.h, 0, 0 )) LBWARN << "aglSetFullScreen to " << pvp << " failed: " << aglError() << std::endl; // Do focus hell ProcessSerialNumber selfProcess = { 0, kCurrentProcess }; SetFrontProcess( &selfProcess ); Global::leaveCarbon(); setPixelViewport( pvp ); if( getIAttribute( WindowSettings::IATTR_HINT_DRAWABLE ) != OFF ) initEventHandler(); return true; }
void Window::setCarbonWindow( WindowRef window ) { LBVERB << "set Carbon window " << window << std::endl; if( _impl->carbonWindow == window ) return; if( _impl->carbonWindow ) exitEventHandler(); _impl->carbonWindow = window; if( !window ) return; if( getIAttribute( WindowSettings::IATTR_HINT_DRAWABLE ) == OFF ) return; initEventHandler(); Rect rect; Global::enterCarbon(); if( GetWindowBounds( window, kWindowContentRgn, &rect ) == noErr ) { PixelViewport pvp( rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top ); if( getIAttribute( WindowSettings::IATTR_HINT_DECORATION ) != OFF ) pvp.y -= EQ_AGL_MENUBARHEIGHT; setPixelViewport( pvp ); } Global::leaveCarbon(); }
//---------------------------------------------------------------------------- // case MSG_LOADER_DATA_AVAILABLE: int8_t resmanager_loader_data_handler(dvm_state_t* dvm_st, Message *msg) { MsgParam* params = ( MsgParam * )( msg->data ); uint8_t id = params->byte; codemem_t cm = params->word; DvmState *ds; DEBUG("RESOURCE_MANAGER: Data received. ID - %d.\n", id); ds = mem_allocate(dvm_st, id); if( ds == NULL ) { // XXX may want to set a timer for retry return -ENOMEM; } ds->context.which = id; sys_codemem_read(cm, &(ds->context.moduleID), sizeof(ds->context.moduleID), offsetof(DvmScript, moduleID)); DEBUG("RESOURCE_MANAGER: Event - module = %d, offset = %ld \n", ds->context.moduleID, offsetof(DvmScript, moduleID)); sys_codemem_read(cm, &(ds->context.type), sizeof(ds->context.type), offsetof(DvmScript, eventType)); DEBUG("RESOURCE_MANAGER: Event - event type = %d, offset = %ld \n", ds->context.type, offsetof(DvmScript, eventType)); sys_codemem_read(cm, &(ds->context.dataSize), sizeof(ds->context.dataSize), offsetof(DvmScript, length)); ds->context.dataSize = ehtons(ds->context.dataSize); DEBUG("RESOURCE_MANAGER: Length of script = %d, offset = %ld \n", ds->context.dataSize, offsetof(DvmScript, length)); sys_codemem_read(cm, &(ds->context.libraryMask), sizeof(ds->context.libraryMask), offsetof(DvmScript, libraryMask)); DEBUG("RESOURCE_MANAGER: Library Mask = 0x%x, offset = %ld \n", ds->context.libraryMask, offsetof(DvmScript, libraryMask)); ds->cm = cm; initEventHandler(dvm_st, ds, id); return SOS_OK; }
int EventManager::RegisterTimeHandler(EventHandler* handler, timeval* timeout, void ** pTimerID) { if ( timeout == NULL ) return -1; initEventHandler(handler); EventData* ed = static_cast<EventData*>(handler->Context()); TimerData * pTimerData = new TimerData; if ( pTimerData == NULL ) return -1; pTimerData->argv[0] = handler; pTimerData->argv[1] = pTimerData; evtimer_set(&pTimerData->timer, __TimeEventCallBack, &pTimerData->argv); event_base_set(_eventBase, &pTimerData->timer); if ( evtimer_add(&pTimerData->timer, timeout) != 0 ) { delete pTimerData; return -1; } ed->timers.push_back(pTimerData); if ( pTimerID ) { *pTimerID = pTimerData; } return 0; }
void Window::setXDrawable( XID drawable ) { if( _xDrawable == drawable ) return; if( _xDrawable ) exitEventHandler(); _xDrawable = drawable; if( !drawable ) return; initEventHandler(); // query pixel viewport of window EQASSERT( _xDisplay ); switch( getIAttribute( eq::Window::IATTR_HINT_DRAWABLE )) { case PBUFFER: { unsigned width = 0; unsigned height = 0; glXQueryDrawable( _xDisplay, drawable, GLX_WIDTH, &width ); glXQueryDrawable( _xDisplay, drawable, GLX_HEIGHT, &height ); getWindow()->setPixelViewport( PixelViewport( 0, 0, int32_t( width ), int32_t( height ))); break; } case WINDOW: { XWindowAttributes wa; XGetWindowAttributes( _xDisplay, drawable, &wa ); // position is relative to parent: translate to absolute coords ::Window root, parent, *children; unsigned nChildren; XQueryTree( _xDisplay, drawable, &root, &parent, &children, &nChildren ); if( children != 0 ) XFree( children ); int x,y; ::Window childReturn; XTranslateCoordinates( _xDisplay, parent, root, wa.x, wa.y, &x, &y, &childReturn ); getWindow()->setPixelViewport( PixelViewport( x, y, wa.width, wa.height )); break; } default: EQUNIMPLEMENTED; case FBO: EQASSERT( getWindow()->getPixelViewport().hasArea( )); } }
/* This function is called when new value should be measured. The function returns the new value. */ UINT Update(UINT id) { if (!CoInitialized || !InstanceCreated) { // Check if the iTunes window has appeared if (FindWindow(L"iTunesApp", L"iTunes") || FindWindow(L"iTunes", L"iTunes")) { if (!iTunesAboutToPromptUserToQuit && SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, nullptr, CLSCTX_LOCAL_SERVER))) { InstanceCreated = true; initEventHandler(); } else { LSLog(LOG_ERROR, nullptr, L"iTunesPlugin.dll: Unable to create instance"); return 0; } } else { iTunesAboutToPromptUserToQuit = false; return 0; } } CCommandIdMap::const_iterator it = CommandIdMap.find(id); COMMAND_TYPE command = (it != CommandIdMap.end()) ? it->second : COMMAND_COUNT; switch (command) { case COMMAND_GETSOUNDVOLUME: // value: 0 ~ 100 { long volume; iTunes->get_SoundVolume(&volume); return volume; } case COMMAND_GETPLAYERPOSITIONPERCENT: // value: 0 ~ 100 { long pos; iTunes->get_PlayerPosition(&pos); if (!updateCurrentTrack()) return 0; long duration; CurrentTrack->get_Duration(&duration); return duration ? pos * 100 / duration : 0; } case COMMAND_GETPLAYERPOSITION: // value: seconds { long pos; iTunes->get_PlayerPosition(&pos); return pos; } } return 0; }
/* This function is called when the measure is initialized. The function must return the maximum value that can be measured. The return value can also be 0, which means that Rainmeter will track the maximum value automatically. The parameters for this function are: instance The instance of this DLL iniFile The name of the ini-file (usually Rainmeter.ini) section The name of the section in the ini-file for this measure id The identifier for the measure. This is used to identify the measures that use the same plugin. */ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) { if (!CoInitialized) { ::CoInitialize(nullptr); wcsncpy(BaseDir, iniFile, MAX_PATH); BaseDir[MAX_PATH - 1] = 0; wchar_t* lastBackslash = wcsrchr(BaseDir, L'\\'); if (lastBackslash) lastBackslash[1] = 0; CoInitialized = true; } if (CoInitialized && !InstanceCreated && (FindWindow(L"iTunesApp", L"iTunes") || FindWindow(L"iTunes", L"iTunes"))) { if (SUCCEEDED(iTunes.CreateInstance(CLSID_iTunesApp, nullptr, CLSCTX_LOCAL_SERVER))) { InstanceCreated = true; initEventHandler(); } else { LSLog(LOG_ERROR, nullptr, L"iTunesPlugin.dll: Unable to create instance"); } } const wchar_t* type = ReadConfigString(section, L"Command", L""); for (int i = 0; i < COMMAND_COUNT; i++) { if (CommandName[i] && type && _wcsicmp(CommandName[i], type) == 0) { CommandIdMap[id] = (COMMAND_TYPE)i; if (COMMAND_GETCURRENTTRACK_ARTWORK == (COMMAND_TYPE)i) { const wchar_t* defaultArtwork = ReadConfigString(section, L"DefaultArtwork", L""); wcscpy(DefaultTrackArtworkPath, defaultArtwork); } } } return 0; }
int EventManager::RegisterHandler(int mask, EventHandler* handler, timeval* timeout) { initEventHandler(handler); EventData* ed = static_cast<EventData*>(handler->Context()); assert(ed!=NULL); short events = 0; if (mask & ReadMask) { events |= EV_READ; if (timeout) events |= EV_TIMEOUT; if (mask & PersistMask) events |= EV_PERSIST; event_del(&ed->readev); event_set(&ed->readev, handler->GetEventObject().GetObject(), events, __EventCallBack, handler); event_base_set(_eventBase, &ed->readev); if (event_add(&ed->readev, timeout) != 0) { return -1; } } events = 0; if (mask & WriteMask) { events |= EV_WRITE; if (timeout) events |= EV_TIMEOUT; if (mask & PersistMask) events |= EV_PERSIST; event_del(&ed->writeev); event_set(&ed->writeev, handler->GetEventObject().GetObject(), events, __EventCallBack, handler); event_base_set(_eventBase, &ed->writeev); if (event_add(&ed->writeev, timeout) != 0) { return -1; } } return 0; }
void Window::setXDrawable( XID drawable ) { LBASSERT( _impl->xDisplay ); if( _impl->xDrawable == drawable ) return; if( _impl->xDrawable ) exitEventHandler(); _impl->xDrawable = drawable; if( !drawable ) return; const int32_t drawableType = getIAttribute( IATTR_HINT_DRAWABLE ); if( drawableType != OFF ) initEventHandler(); // query pixel viewport of window switch( drawableType ) { case PBUFFER: { unsigned width = 0; unsigned height = 0; glXQueryDrawable( _impl->xDisplay, drawable, GLX_WIDTH, &width ); glXQueryDrawable( _impl->xDisplay, drawable, GLX_HEIGHT, &height ); setPixelViewport( PixelViewport( 0, 0, int32_t( width ), int32_t( height ))); break; } case WINDOW: case AUTO: case UNDEFINED: { XWindowAttributes wa; XGetWindowAttributes( _impl->xDisplay, drawable, &wa ); // position is relative to parent: translate to absolute coords ::Window root, parent, *children; unsigned nChildren; XQueryTree( _impl->xDisplay, drawable, &root, &parent, &children, &nChildren ); if( children != 0 ) XFree( children ); int x,y; ::Window childReturn; XTranslateCoordinates( _impl->xDisplay, parent, root, wa.x, wa.y, &x, &y, &childReturn ); setPixelViewport( PixelViewport( x, y, wa.width, wa.height )); break; } default: LBERROR << "Unknown drawable type " << drawableType << std::endl; LBUNIMPLEMENTED; case OFF: case FBO: LBASSERT( getPixelViewport().hasArea( )); } }