OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_) : OBSQTDisplay (widget, Qt::Window | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint), source (source_), removedSignal (obs_source_get_signal_handler(source), "remove", OBSSourceRemoved, this) { setAttribute(Qt::WA_DeleteOnClose, true); installEventFilter(CreateShortcutFilter()); auto addDrawCallback = [this] () { obs_display_add_draw_callback(GetDisplay(), OBSRender, this); obs_display_set_background_color(GetDisplay(), 0x000000); }; connect(this, &OBSQTDisplay::DisplayCreated, addDrawCallback); bool hideCursor = config_get_bool(GetGlobalConfig(), "BasicWindow", "HideProjectorCursor"); if (hideCursor) { QPixmap empty(16, 16); empty.fill(Qt::transparent); setCursor(QCursor(empty)); } App()->IncrementSleepInhibition(); }
void OBSProjector::Init(int monitor, bool window, QString title) { QScreen *screen = QGuiApplication::screens()[monitor]; if (!window) setGeometry(screen->geometry()); bool alwaysOnTop = config_get_bool(GetGlobalConfig(), "BasicWindow", "ProjectorAlwaysOnTop"); if (alwaysOnTop && !window) SetAlwaysOnTop(this, true); if (window) setWindowTitle(title); show(); if (source) obs_source_inc_showing(source); if (!window) { QAction *action = new QAction(this); action->setShortcut(Qt::Key_Escape); addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(EscapeTriggered())); } savedMonitor = monitor; isWindow = window; }
int main(int argc, char** argv) { argc_main = argc; argv_main = argv; SplashColor paperColor; GooString* filename, *password; char* spwd; FILE* f = NULL; bookinfo* bi; char buf[1024]; int i; mkdir(CACHEDIR, 0777); chmod(CACHEDIR, 0777); spwd = GetDeviceKey(); if (setgid(102) != 0) fprintf(stderr, "warning: cannot set gid\n"); if (setuid(102) != 0) fprintf(stderr, "warning: cannot set uid\n"); if (spwd) { //fprintf(stderr, "password: %s\n", spwd); password = new GooString(spwd); } else { fprintf(stderr, "warning: cannot read password\n"); password = NULL; } OpenScreen(); signal(SIGFPE, sigfpe_handler); signal(SIGSEGV, sigsegv_handler); clock_left = GetThemeInt("panel.clockleft", 0); bmk_flag = GetResource("bmk_flag", NULL); if (argc < 2) { Message(ICON_WARNING, "PDF Viewer", "@Cant_open_file", 2000); return 0; } OriginalName = FileName = argv[1]; bi = GetBookInfo(FileName); if (bi->title) book_title = strdup(bi->title); // read config file globalParams = new GlobalParams(); globalParams->setEnableFreeType("yes"); globalParams->setAntialias((char*)(ivstate.antialiasing ? "yes" : "no")); globalParams->setVectorAntialias("no"); filename = new GooString(FileName); doc = new PDFDoc(filename, NULL, NULL); if (!doc->isOk()) { int err = doc->getErrorCode(); delete doc; if (err == 4) // encrypted file { filename = new GooString(FileName); doc = new PDFDoc(filename, NULL, password); if (!doc->isOk()) { delete doc; spwd = query_password(); password = new GooString(spwd); filename = new GooString(FileName); doc = new PDFDoc(filename, NULL, password); if (!doc->isOk()) { Message(ICON_WARNING, "PDF Viewer", "@Cant_open_file", 2000); return 0; } } } else { Message(ICON_WARNING, "PDF Viewer", "@Cant_open_file", 2000); return 0; } } npages = doc->getNumPages(); paperColor[0] = 255; paperColor[1] = 255; paperColor[2] = 255; splashOut = new MySplashOutputDev(USE4 ? splashModeMono4 : splashModeMono8, 4, gFalse, paperColor); splashOut->startDoc(doc->getXRef()); Outline* outline = doc->getOutline(); if (outline && outline->getItems()) { GooList* items = outline->getItems(); if (items->getLength() == 1) { OutlineItem* first = (OutlineItem*)items->get(0); first->open(); items = first->getKids(); update_toc(items, 0); first->close(); } else if (items->getLength() > 1) { update_toc(items, 0); } } DataFile = GetAssociatedFile(FileName, 0); f = fopen(DataFile, "rb"); if (f == NULL || fread(&docstate, 1, sizeof(tdocstate), f) != sizeof(tdocstate) || docstate.magic != 0x9751) { docstate.magic = 0x9751; docstate.page = 1; docstate.offx = 0; docstate.offy = 0; docstate.scale = 100; docstate.rscale = 150; docstate.orient = 0; docstate.nbmk = 0; } if (f != NULL) fclose(f); cpage = docstate.page; subpage = docstate.subpage; offx = docstate.offx; offy = docstate.offy; if (docstate.scale == 0) { scale = get_fit_scale(); ScaleZoomType = ZoomTypeFitWidth; } else { scale = docstate.scale; } rscale = docstate.rscale; reflow_mode = (docstate.orient & 0x80) ? 1 : 0; gcfg = GetGlobalConfig(); // ko = ReadInt(gcfg, "keeporient", 0); ko = -1; if (GetGlobalOrientation() == -1 || ko == 0) { orient = GetOrientation(); } else { orient = docstate.orient & 0x7f; SetOrientation(orient); } if (argc >= 3) { if (argv[2][0] == '=') { #ifdef USESYNOPSIS long long position; TSynopsisItem::PositionToLong(argv[2] + 1, &position); cpage = position_to_page(position >> 40); #else // cpage = atoi(position_to_page(argv[2] + 1)); cpage = atoi(argv[2] + 1); #endif } else {
void OBSProjector::UpdateMultiview() { multiviewScenes.clear(); multiviewLabels.clear(); struct obs_video_info ovi; obs_get_video_info(&ovi); uint32_t w = ovi.base_width; uint32_t h = ovi.base_height; fw = float(w); fh = float(h); ratio = fw / fh; struct obs_frontend_source_list scenes = {}; obs_frontend_get_scenes(&scenes); multiviewLabels.emplace_back(CreateLabel(Str("StudioMode.Preview"), h / 2)); multiviewLabels.emplace_back(CreateLabel(Str("StudioMode.Program"), h / 2)); multiviewLayout = static_cast<MultiviewLayout>(config_get_int( GetGlobalConfig(), "BasicWindow", "MultiviewLayout")); drawLabel = config_get_bool(GetGlobalConfig(), "BasicWindow", "MultiviewDrawNames"); drawSafeArea = config_get_bool(GetGlobalConfig(), "BasicWindow", "MultiviewDrawAreas"); mouseSwitching = config_get_bool(GetGlobalConfig(), "BasicWindow", "MultiviewMouseSwitch"); transitionOnDoubleClick = config_get_bool(GetGlobalConfig(), "BasicWindow", "TransitionOnDoubleClick"); switch(multiviewLayout) { case MultiviewLayout::HORIZONTAL_TOP_24_SCENES: pvwprgCX = fw / 3; pvwprgCY = fh / 3; maxSrcs = 24; break; default: pvwprgCX = fw / 2; pvwprgCY = fh / 2; maxSrcs = 8; } ppiCX = pvwprgCX - thicknessx2; ppiCY = pvwprgCY - thicknessx2; ppiScaleX = (pvwprgCX - thicknessx2) / fw; ppiScaleY = (pvwprgCY - thicknessx2) / fh; scenesCX = pvwprgCX / 2; scenesCY = pvwprgCY / 2; siCX = scenesCX - thicknessx2; siCY = scenesCY - thicknessx2; siScaleX = (scenesCX - thicknessx2) / fw; siScaleY = (scenesCY - thicknessx2) / fh; numSrcs = 0; size_t i = 0; while (i < scenes.sources.num && numSrcs < maxSrcs) { obs_source_t *src = scenes.sources.array[i++]; OBSData data = obs_source_get_private_settings(src); obs_data_release(data); obs_data_set_default_bool(data, "show_in_multiview", true); if (!obs_data_get_bool(data, "show_in_multiview")) continue; // We have a displayable source. numSrcs++; multiviewScenes.emplace_back(OBSGetWeakRef(src)); obs_source_inc_showing(src); std::string name = std::to_string(numSrcs) + " - " + obs_source_get_name(src); multiviewLabels.emplace_back(CreateLabel(name.c_str(), h / 3)); } obs_frontend_source_list_free(&scenes); }
OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_, int monitor, QString title, ProjectorType type_) : OBSQTDisplay (widget, Qt::Window), source (source_), removedSignal (obs_source_get_signal_handler(source), "remove", OBSSourceRemoved, this) { projectorTitle = std::move(title); savedMonitor = monitor; isWindow = savedMonitor < 0; type = type_; if (isWindow) { setWindowIcon(QIcon::fromTheme("obs", QIcon(":/res/images/obs.png"))); UpdateProjectorTitle(projectorTitle); windowedProjectors.push_back(this); resize(480, 270); } else { setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); QScreen *screen = QGuiApplication::screens()[savedMonitor]; setGeometry(screen->geometry()); QAction *action = new QAction(this); action->setShortcut(Qt::Key_Escape); addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(EscapeTriggered())); } SetAlwaysOnTop(this, config_get_bool(GetGlobalConfig(), "BasicWindow", "ProjectorAlwaysOnTop")); setAttribute(Qt::WA_DeleteOnClose, true); //disable application quit when last window closed setAttribute(Qt::WA_QuitOnClose, false); installEventFilter(CreateShortcutFilter()); auto addDrawCallback = [this] () { bool isMultiview = type == ProjectorType::Multiview; obs_display_add_draw_callback(GetDisplay(), isMultiview ? OBSRenderMultiview : OBSRender, this); obs_display_set_background_color(GetDisplay(), 0x000000); }; connect(this, &OBSQTDisplay::DisplayCreated, addDrawCallback); bool hideCursor = config_get_bool(GetGlobalConfig(), "BasicWindow", "HideProjectorCursor"); if (hideCursor && !isWindow) { QPixmap empty(16, 16); empty.fill(Qt::transparent); setCursor(QCursor(empty)); } if (type == ProjectorType::Multiview) { obs_enter_graphics(); // All essential action should be placed inside this area gs_render_start(true); gs_vertex2f(actionSafePercentage, actionSafePercentage); gs_vertex2f(actionSafePercentage, 1 - actionSafePercentage); gs_vertex2f(1 - actionSafePercentage, 1 - actionSafePercentage); gs_vertex2f(1 - actionSafePercentage, actionSafePercentage); gs_vertex2f(actionSafePercentage, actionSafePercentage); actionSafeMargin = gs_render_save(); // All graphics should be placed inside this area gs_render_start(true); gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage); gs_vertex2f(graphicsSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(1 - graphicsSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(1 - graphicsSafePercentage, graphicsSafePercentage); gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage); graphicsSafeMargin = gs_render_save(); // 4:3 safe area for widescreen gs_render_start(true); gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage); gs_vertex2f(1 - fourByThreeSafePercentage, graphicsSafePercentage); gs_vertex2f(1 - fourByThreeSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(fourByThreeSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage); fourByThreeSafeMargin = gs_render_save(); gs_render_start(true); gs_vertex2f(0.0f, 0.5f); gs_vertex2f(lineLength, 0.5f); leftLine = gs_render_save(); gs_render_start(true); gs_vertex2f(0.5f, 0.0f); gs_vertex2f(0.5f, lineLength); topLine = gs_render_save(); gs_render_start(true); gs_vertex2f(1.0f, 0.5f); gs_vertex2f(1 - lineLength, 0.5f); rightLine = gs_render_save(); obs_leave_graphics(); solid = obs_get_base_effect(OBS_EFFECT_SOLID); color = gs_effect_get_param_by_name(solid, "color"); UpdateMultiview(); multiviewProjectors.push_back(this); } App()->IncrementSleepInhibition(); if (source) obs_source_inc_showing(source); ready = true; show(); // We need it here to allow keyboard input in X11 to listen to Escape if (!isWindow) activateWindow(); }