window-basic-main.cpp 190 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249
  1. /******************************************************************************
  2. Copyright (C) 2013-2015 by Hugh Bailey <[email protected]>
  3. Zachary Lund <[email protected]>
  4. Philippe Groarke <[email protected]>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ******************************************************************************/
  16. #include <ctime>
  17. #include <obs.hpp>
  18. #include <QGuiApplication>
  19. #include <QMessageBox>
  20. #include <QShowEvent>
  21. #include <QDesktopServices>
  22. #include <QFileDialog>
  23. #include <QDesktopWidget>
  24. #include <QScreen>
  25. #include <QColorDialog>
  26. #include <QSizePolicy>
  27. #include <util/dstr.h>
  28. #include <util/util.hpp>
  29. #include <util/platform.h>
  30. #include <util/profiler.hpp>
  31. #include <util/dstr.hpp>
  32. #include "obs-app.hpp"
  33. #include "platform.hpp"
  34. #include "visibility-item-widget.hpp"
  35. #include "item-widget-helpers.hpp"
  36. #include "window-basic-settings.hpp"
  37. #include "window-namedialog.hpp"
  38. #include "window-basic-auto-config.hpp"
  39. #include "window-basic-source-select.hpp"
  40. #include "window-basic-main.hpp"
  41. #include "window-basic-stats.hpp"
  42. #include "window-basic-main-outputs.hpp"
  43. #include "window-log-reply.hpp"
  44. #include "window-projector.hpp"
  45. #include "window-remux.hpp"
  46. #include "qt-wrappers.hpp"
  47. #include "display-helpers.hpp"
  48. #include "volume-control.hpp"
  49. #include "remote-text.hpp"
  50. #include <fstream>
  51. #include <sstream>
  52. #ifdef _WIN32
  53. #include "win-update/win-update.hpp"
  54. #endif
  55. #include "ui_OBSBasic.h"
  56. #include "ui_ColorSelect.h"
  57. #include <fstream>
  58. #include <sstream>
  59. #include <QScreen>
  60. #include <QWindow>
  61. #include <json11.hpp>
  62. using namespace json11;
  63. using namespace std;
  64. #ifdef BROWSER_AVAILABLE
  65. #include <browser-panel.hpp>
  66. #endif
  67. #include "ui-config.h"
  68. struct QCef;
  69. struct QCefCookieManager;
  70. QCef *cef = nullptr;
  71. QCefCookieManager *panel_cookies = nullptr;
  72. void DestroyPanelCookieManager();
  73. namespace {
  74. template <typename OBSRef>
  75. struct SignalContainer {
  76. OBSRef ref;
  77. vector<shared_ptr<OBSSignal>> handlers;
  78. };
  79. }
  80. extern volatile long insideEventLoop;
  81. Q_DECLARE_METATYPE(OBSScene);
  82. Q_DECLARE_METATYPE(OBSSceneItem);
  83. Q_DECLARE_METATYPE(OBSSource);
  84. Q_DECLARE_METATYPE(obs_order_movement);
  85. Q_DECLARE_METATYPE(SignalContainer<OBSScene>);
  86. template <typename T>
  87. static T GetOBSRef(QListWidgetItem *item)
  88. {
  89. return item->data(static_cast<int>(QtDataRole::OBSRef)).value<T>();
  90. }
  91. template <typename T>
  92. static void SetOBSRef(QListWidgetItem *item, T &&val)
  93. {
  94. item->setData(static_cast<int>(QtDataRole::OBSRef),
  95. QVariant::fromValue(val));
  96. }
  97. static void AddExtraModulePaths()
  98. {
  99. char base_module_dir[512];
  100. #if defined(_WIN32) || defined(__APPLE__)
  101. int ret = GetProgramDataPath(base_module_dir, sizeof(base_module_dir),
  102. "obs-studio/plugins/%module%");
  103. #else
  104. int ret = GetConfigPath(base_module_dir, sizeof(base_module_dir),
  105. "obs-studio/plugins/%module%");
  106. #endif
  107. if (ret <= 0)
  108. return;
  109. string path = (char*)base_module_dir;
  110. #if defined(__APPLE__)
  111. obs_add_module_path((path + "/bin").c_str(), (path + "/data").c_str());
  112. BPtr<char> config_bin = os_get_config_path_ptr("obs-studio/plugins/%module%/bin");
  113. BPtr<char> config_data = os_get_config_path_ptr("obs-studio/plugins/%module%/data");
  114. obs_add_module_path(config_bin, config_data);
  115. #elif ARCH_BITS == 64
  116. obs_add_module_path((path + "/bin/64bit").c_str(),
  117. (path + "/data").c_str());
  118. #else
  119. obs_add_module_path((path + "/bin/32bit").c_str(),
  120. (path + "/data").c_str());
  121. #endif
  122. }
  123. extern obs_frontend_callbacks *InitializeAPIInterface(OBSBasic *main);
  124. static int CountVideoSources()
  125. {
  126. int count = 0;
  127. auto countSources = [] (void *param, obs_source_t *source)
  128. {
  129. if (!source)
  130. return true;
  131. uint32_t flags = obs_source_get_output_flags(source);
  132. if ((flags & OBS_SOURCE_VIDEO) != 0)
  133. (*reinterpret_cast<int*>(param))++;
  134. return true;
  135. };
  136. obs_enum_sources(countSources, &count);
  137. return count;
  138. }
  139. void assignDockToggle(QDockWidget *dock, QAction *action)
  140. {
  141. auto handleWindowToggle = [action] (bool vis)
  142. {
  143. action->blockSignals(true);
  144. action->setChecked(vis);
  145. action->blockSignals(false);
  146. };
  147. auto handleMenuToggle = [dock] (bool check)
  148. {
  149. dock->blockSignals(true);
  150. dock->setVisible(check);
  151. dock->blockSignals(false);
  152. };
  153. dock->connect(dock->toggleViewAction(), &QAction::toggled,
  154. handleWindowToggle);
  155. dock->connect(action, &QAction::toggled,
  156. handleMenuToggle);
  157. }
  158. extern void RegisterTwitchAuth();
  159. extern void RegisterMixerAuth();
  160. extern void RegisterRestreamAuth();
  161. OBSBasic::OBSBasic(QWidget *parent)
  162. : OBSMainWindow (parent),
  163. ui (new Ui::OBSBasic)
  164. {
  165. setAttribute(Qt::WA_NativeWindow);
  166. #if TWITCH_ENABLED
  167. RegisterTwitchAuth();
  168. #endif
  169. #if MIXER_ENABLED
  170. RegisterMixerAuth();
  171. #endif
  172. #if RESTREAM_ENABLED
  173. RegisterRestreamAuth();
  174. #endif
  175. setAcceptDrops(true);
  176. api = InitializeAPIInterface(this);
  177. ui->setupUi(this);
  178. ui->previewDisabledLabel->setVisible(false);
  179. startingDockLayout = saveState();
  180. statsDock = new OBSDock();
  181. statsDock->setObjectName(QStringLiteral("statsDock"));
  182. statsDock->setFeatures(QDockWidget::AllDockWidgetFeatures);
  183. statsDock->setWindowTitle(QTStr("Basic.Stats"));
  184. addDockWidget(Qt::BottomDockWidgetArea, statsDock);
  185. statsDock->setVisible(false);
  186. statsDock->setFloating(true);
  187. statsDock->resize(700, 200);
  188. copyActionsDynamicProperties();
  189. char styleSheetPath[512];
  190. int ret = GetProfilePath(styleSheetPath, sizeof(styleSheetPath),
  191. "stylesheet.qss");
  192. if (ret > 0) {
  193. if (QFile::exists(styleSheetPath)) {
  194. QString path = QString("file:///") +
  195. QT_UTF8(styleSheetPath);
  196. App()->setStyleSheet(path);
  197. }
  198. }
  199. qRegisterMetaType<OBSScene> ("OBSScene");
  200. qRegisterMetaType<OBSSceneItem>("OBSSceneItem");
  201. qRegisterMetaType<OBSSource> ("OBSSource");
  202. qRegisterMetaType<obs_hotkey_id>("obs_hotkey_id");
  203. qRegisterMetaTypeStreamOperators<
  204. std::vector<std::shared_ptr<OBSSignal>>>(
  205. "std::vector<std::shared_ptr<OBSSignal>>");
  206. qRegisterMetaTypeStreamOperators<OBSScene>("OBSScene");
  207. qRegisterMetaTypeStreamOperators<OBSSceneItem>("OBSSceneItem");
  208. ui->scenes->setAttribute(Qt::WA_MacShowFocusRect, false);
  209. ui->sources->setAttribute(Qt::WA_MacShowFocusRect, false);
  210. ui->scenes->setItemDelegate(new SceneRenameDelegate(ui->scenes));
  211. auto displayResize = [this]() {
  212. struct obs_video_info ovi;
  213. if (obs_get_video_info(&ovi))
  214. ResizePreview(ovi.base_width, ovi.base_height);
  215. };
  216. connect(windowHandle(), &QWindow::screenChanged, displayResize);
  217. connect(ui->preview, &OBSQTDisplay::DisplayResized, displayResize);
  218. delete shortcutFilter;
  219. shortcutFilter = CreateShortcutFilter();
  220. installEventFilter(shortcutFilter);
  221. stringstream name;
  222. name << "OBS " << App()->GetVersionString();
  223. blog(LOG_INFO, "%s", name.str().c_str());
  224. blog(LOG_INFO, "---------------------------------");
  225. UpdateTitleBar();
  226. connect(ui->scenes->itemDelegate(),
  227. SIGNAL(closeEditor(QWidget*,
  228. QAbstractItemDelegate::EndEditHint)),
  229. this,
  230. SLOT(SceneNameEdited(QWidget*,
  231. QAbstractItemDelegate::EndEditHint)));
  232. cpuUsageInfo = os_cpu_usage_info_start();
  233. cpuUsageTimer = new QTimer(this);
  234. connect(cpuUsageTimer.data(), SIGNAL(timeout()),
  235. ui->statusbar, SLOT(UpdateCPUUsage()));
  236. cpuUsageTimer->start(3000);
  237. QAction *renameScene = new QAction(ui->scenesDock);
  238. renameScene->setShortcutContext(Qt::WidgetWithChildrenShortcut);
  239. connect(renameScene, SIGNAL(triggered()), this, SLOT(EditSceneName()));
  240. ui->scenesDock->addAction(renameScene);
  241. QAction *renameSource = new QAction(ui->sourcesDock);
  242. renameSource->setShortcutContext(Qt::WidgetWithChildrenShortcut);
  243. connect(renameSource, SIGNAL(triggered()), this,
  244. SLOT(EditSceneItemName()));
  245. ui->sourcesDock->addAction(renameSource);
  246. #ifdef __APPLE__
  247. renameScene->setShortcut({Qt::Key_Return});
  248. renameSource->setShortcut({Qt::Key_Return});
  249. ui->actionRemoveSource->setShortcuts({Qt::Key_Backspace});
  250. ui->actionRemoveScene->setShortcuts({Qt::Key_Backspace});
  251. ui->action_Settings->setMenuRole(QAction::PreferencesRole);
  252. ui->actionE_xit->setMenuRole(QAction::QuitRole);
  253. #else
  254. renameScene->setShortcut({Qt::Key_F2});
  255. renameSource->setShortcut({Qt::Key_F2});
  256. #endif
  257. auto addNudge = [this](const QKeySequence &seq, const char *s)
  258. {
  259. QAction *nudge = new QAction(ui->preview);
  260. nudge->setShortcut(seq);
  261. nudge->setShortcutContext(Qt::WidgetShortcut);
  262. ui->preview->addAction(nudge);
  263. connect(nudge, SIGNAL(triggered()), this, s);
  264. };
  265. addNudge(Qt::Key_Up, SLOT(NudgeUp()));
  266. addNudge(Qt::Key_Down, SLOT(NudgeDown()));
  267. addNudge(Qt::Key_Left, SLOT(NudgeLeft()));
  268. addNudge(Qt::Key_Right, SLOT(NudgeRight()));
  269. assignDockToggle(ui->scenesDock, ui->toggleScenes);
  270. assignDockToggle(ui->sourcesDock, ui->toggleSources);
  271. assignDockToggle(ui->mixerDock, ui->toggleMixer);
  272. assignDockToggle(ui->transitionsDock, ui->toggleTransitions);
  273. assignDockToggle(ui->controlsDock, ui->toggleControls);
  274. assignDockToggle(statsDock, ui->toggleStats);
  275. //hide all docking panes
  276. ui->toggleScenes->setChecked(false);
  277. ui->toggleSources->setChecked(false);
  278. ui->toggleMixer->setChecked(false);
  279. ui->toggleTransitions->setChecked(false);
  280. ui->toggleControls->setChecked(false);
  281. ui->toggleStats->setChecked(false);
  282. QPoint curPos;
  283. //restore parent window geometry
  284. const char *geometry = config_get_string(App()->GlobalConfig(),
  285. "BasicWindow", "geometry");
  286. if (geometry != NULL) {
  287. QByteArray byteArray = QByteArray::fromBase64(
  288. QByteArray(geometry));
  289. restoreGeometry(byteArray);
  290. QRect windowGeometry = normalGeometry();
  291. if (!WindowPositionValid(windowGeometry)) {
  292. QRect rect = App()->desktop()->geometry();
  293. setGeometry(QStyle::alignedRect(
  294. Qt::LeftToRight,
  295. Qt::AlignCenter,
  296. size(), rect));
  297. }
  298. curPos = pos();
  299. } else {
  300. QRect desktopRect = QGuiApplication::primaryScreen()->geometry();
  301. QSize adjSize = desktopRect.size() / 2 - size() / 2;
  302. curPos = QPoint(adjSize.width(), adjSize.height());
  303. }
  304. QPoint curSize(width(), height());
  305. QPoint statsDockSize(statsDock->width(), statsDock->height());
  306. QPoint statsDockPos = curSize / 2 - statsDockSize / 2;
  307. QPoint newPos = curPos + statsDockPos;
  308. statsDock->move(newPos);
  309. ui->previewLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  310. ui->previewLabel->setProperty("themeID", "previewProgramLabels");
  311. bool labels = config_get_bool(GetGlobalConfig(),
  312. "BasicWindow", "StudioModeLabels");
  313. if (!previewProgramMode)
  314. ui->previewLabel->setHidden(true);
  315. else
  316. ui->previewLabel->setHidden(!labels);
  317. }
  318. static void SaveAudioDevice(const char *name, int channel, obs_data_t *parent,
  319. vector<OBSSource> &audioSources)
  320. {
  321. obs_source_t *source = obs_get_output_source(channel);
  322. if (!source)
  323. return;
  324. audioSources.push_back(source);
  325. obs_data_t *data = obs_save_source(source);
  326. obs_data_set_obj(parent, name, data);
  327. obs_data_release(data);
  328. obs_source_release(source);
  329. }
  330. static obs_data_t *GenerateSaveData(obs_data_array_t *sceneOrder,
  331. obs_data_array_t *quickTransitionData, int transitionDuration,
  332. obs_data_array_t *transitions,
  333. OBSScene &scene, OBSSource &curProgramScene,
  334. obs_data_array_t *savedProjectorList)
  335. {
  336. obs_data_t *saveData = obs_data_create();
  337. vector<OBSSource> audioSources;
  338. audioSources.reserve(5);
  339. SaveAudioDevice(DESKTOP_AUDIO_1, 1, saveData, audioSources);
  340. SaveAudioDevice(DESKTOP_AUDIO_2, 2, saveData, audioSources);
  341. SaveAudioDevice(AUX_AUDIO_1, 3, saveData, audioSources);
  342. SaveAudioDevice(AUX_AUDIO_2, 4, saveData, audioSources);
  343. SaveAudioDevice(AUX_AUDIO_3, 5, saveData, audioSources);
  344. SaveAudioDevice(AUX_AUDIO_4, 6, saveData, audioSources);
  345. /* -------------------------------- */
  346. /* save non-group sources */
  347. auto FilterAudioSources = [&](obs_source_t *source)
  348. {
  349. if (obs_source_is_group(source))
  350. return false;
  351. return find(begin(audioSources), end(audioSources), source) ==
  352. end(audioSources);
  353. };
  354. using FilterAudioSources_t = decltype(FilterAudioSources);
  355. obs_data_array_t *sourcesArray = obs_save_sources_filtered(
  356. [](void *data, obs_source_t *source)
  357. {
  358. return (*static_cast<FilterAudioSources_t*>(data))(source);
  359. }, static_cast<void*>(&FilterAudioSources));
  360. /* -------------------------------- */
  361. /* save group sources separately */
  362. /* saving separately ensures they won't be loaded in older versions */
  363. obs_data_array_t *groupsArray = obs_save_sources_filtered(
  364. [](void*, obs_source_t *source)
  365. {
  366. return obs_source_is_group(source);
  367. }, nullptr);
  368. /* -------------------------------- */
  369. obs_source_t *transition = obs_get_output_source(0);
  370. obs_source_t *currentScene = obs_scene_get_source(scene);
  371. const char *sceneName = obs_source_get_name(currentScene);
  372. const char *programName = obs_source_get_name(curProgramScene);
  373. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  374. "Basic", "SceneCollection");
  375. obs_data_set_string(saveData, "current_scene", sceneName);
  376. obs_data_set_string(saveData, "current_program_scene", programName);
  377. obs_data_set_array(saveData, "scene_order", sceneOrder);
  378. obs_data_set_string(saveData, "name", sceneCollection);
  379. obs_data_set_array(saveData, "sources", sourcesArray);
  380. obs_data_set_array(saveData, "groups", groupsArray);
  381. obs_data_set_array(saveData, "quick_transitions", quickTransitionData);
  382. obs_data_set_array(saveData, "transitions", transitions);
  383. obs_data_set_array(saveData, "saved_projectors", savedProjectorList);
  384. obs_data_array_release(sourcesArray);
  385. obs_data_array_release(groupsArray);
  386. obs_data_set_string(saveData, "current_transition",
  387. obs_source_get_name(transition));
  388. obs_data_set_int(saveData, "transition_duration", transitionDuration);
  389. obs_source_release(transition);
  390. return saveData;
  391. }
  392. void OBSBasic::copyActionsDynamicProperties()
  393. {
  394. // Themes need the QAction dynamic properties
  395. for (QAction *x : ui->scenesToolbar->actions()) {
  396. QWidget* temp = ui->scenesToolbar->widgetForAction(x);
  397. for (QByteArray &y : x->dynamicPropertyNames()) {
  398. temp->setProperty(y, x->property(y));
  399. }
  400. }
  401. for (QAction *x : ui->sourcesToolbar->actions()) {
  402. QWidget* temp = ui->sourcesToolbar->widgetForAction(x);
  403. for (QByteArray &y : x->dynamicPropertyNames()) {
  404. temp->setProperty(y, x->property(y));
  405. }
  406. }
  407. }
  408. void OBSBasic::UpdateVolumeControlsDecayRate()
  409. {
  410. double meterDecayRate = config_get_double(basicConfig, "Audio",
  411. "MeterDecayRate");
  412. for (size_t i = 0; i < volumes.size(); i++) {
  413. volumes[i]->SetMeterDecayRate(meterDecayRate);
  414. }
  415. }
  416. void OBSBasic::UpdateVolumeControlsPeakMeterType()
  417. {
  418. uint32_t peakMeterTypeIdx = config_get_uint(basicConfig, "Audio",
  419. "PeakMeterType");
  420. enum obs_peak_meter_type peakMeterType;
  421. switch (peakMeterTypeIdx) {
  422. case 0:
  423. peakMeterType = SAMPLE_PEAK_METER;
  424. break;
  425. case 1:
  426. peakMeterType = TRUE_PEAK_METER;
  427. break;
  428. default:
  429. peakMeterType = SAMPLE_PEAK_METER;
  430. break;
  431. }
  432. for (size_t i = 0; i < volumes.size(); i++) {
  433. volumes[i]->setPeakMeterType(peakMeterType);
  434. }
  435. }
  436. void OBSBasic::ClearVolumeControls()
  437. {
  438. for (VolControl *vol : volumes)
  439. delete vol;
  440. volumes.clear();
  441. }
  442. obs_data_array_t *OBSBasic::SaveSceneListOrder()
  443. {
  444. obs_data_array_t *sceneOrder = obs_data_array_create();
  445. for (int i = 0; i < ui->scenes->count(); i++) {
  446. obs_data_t *data = obs_data_create();
  447. obs_data_set_string(data, "name",
  448. QT_TO_UTF8(ui->scenes->item(i)->text()));
  449. obs_data_array_push_back(sceneOrder, data);
  450. obs_data_release(data);
  451. }
  452. return sceneOrder;
  453. }
  454. obs_data_array_t *OBSBasic::SaveProjectors()
  455. {
  456. obs_data_array_t *savedProjectors = obs_data_array_create();
  457. auto saveProjector = [savedProjectors](OBSProjector *projector) {
  458. if (!projector)
  459. return;
  460. obs_data_t *data = obs_data_create();
  461. ProjectorType type = projector->GetProjectorType();
  462. switch (type) {
  463. case ProjectorType::Scene:
  464. case ProjectorType::Source: {
  465. obs_source_t *source = projector->GetSource();
  466. const char *name = obs_source_get_name(source);
  467. obs_data_set_string(data, "name", name);
  468. break;
  469. }
  470. default:
  471. break;
  472. }
  473. obs_data_set_int(data, "monitor", projector->GetMonitor());
  474. obs_data_set_int(data, "type", static_cast<int>(type));
  475. obs_data_set_string(data, "geometry",
  476. projector->saveGeometry().toBase64()
  477. .constData());
  478. obs_data_array_push_back(savedProjectors, data);
  479. obs_data_release(data);
  480. };
  481. for (QPointer<QWidget> &proj : projectors)
  482. saveProjector(static_cast<OBSProjector *>(proj.data()));
  483. for (QPointer<QWidget> &proj : windowProjectors)
  484. saveProjector(static_cast<OBSProjector *>(proj.data()));
  485. return savedProjectors;
  486. }
  487. void OBSBasic::Save(const char *file)
  488. {
  489. OBSScene scene = GetCurrentScene();
  490. OBSSource curProgramScene = OBSGetStrongRef(programScene);
  491. if (!curProgramScene)
  492. curProgramScene = obs_scene_get_source(scene);
  493. obs_data_array_t *sceneOrder = SaveSceneListOrder();
  494. obs_data_array_t *transitions = SaveTransitions();
  495. obs_data_array_t *quickTrData = SaveQuickTransitions();
  496. obs_data_array_t *savedProjectorList = SaveProjectors();
  497. obs_data_t *saveData = GenerateSaveData(sceneOrder, quickTrData,
  498. ui->transitionDuration->value(), transitions,
  499. scene, curProgramScene, savedProjectorList);
  500. obs_data_set_bool(saveData, "preview_locked", ui->preview->Locked());
  501. obs_data_set_bool(saveData, "scaling_enabled",
  502. ui->preview->IsFixedScaling());
  503. obs_data_set_int(saveData, "scaling_level",
  504. ui->preview->GetScalingLevel());
  505. obs_data_set_double(saveData, "scaling_off_x",
  506. ui->preview->GetScrollX());
  507. obs_data_set_double(saveData, "scaling_off_y",
  508. ui->preview->GetScrollY());
  509. if (api) {
  510. obs_data_t *moduleObj = obs_data_create();
  511. api->on_save(moduleObj);
  512. obs_data_set_obj(saveData, "modules", moduleObj);
  513. obs_data_release(moduleObj);
  514. }
  515. if (!obs_data_save_json_safe(saveData, file, "tmp", "bak"))
  516. blog(LOG_ERROR, "Could not save scene data to %s", file);
  517. obs_data_release(saveData);
  518. obs_data_array_release(sceneOrder);
  519. obs_data_array_release(quickTrData);
  520. obs_data_array_release(transitions);
  521. obs_data_array_release(savedProjectorList);
  522. }
  523. void OBSBasic::DeferSaveBegin()
  524. {
  525. os_atomic_inc_long(&disableSaving);
  526. }
  527. void OBSBasic::DeferSaveEnd()
  528. {
  529. long result = os_atomic_dec_long(&disableSaving);
  530. if (result == 0) {
  531. SaveProject();
  532. }
  533. }
  534. static void LoadAudioDevice(const char *name, int channel, obs_data_t *parent)
  535. {
  536. obs_data_t *data = obs_data_get_obj(parent, name);
  537. if (!data)
  538. return;
  539. obs_source_t *source = obs_load_source(data);
  540. if (source) {
  541. obs_set_output_source(channel, source);
  542. obs_source_release(source);
  543. }
  544. obs_data_release(data);
  545. }
  546. static inline bool HasAudioDevices(const char *source_id)
  547. {
  548. const char *output_id = source_id;
  549. obs_properties_t *props = obs_get_source_properties(output_id);
  550. size_t count = 0;
  551. if (!props)
  552. return false;
  553. obs_property_t *devices = obs_properties_get(props, "device_id");
  554. if (devices)
  555. count = obs_property_list_item_count(devices);
  556. obs_properties_destroy(props);
  557. return count != 0;
  558. }
  559. void OBSBasic::CreateFirstRunSources()
  560. {
  561. bool hasDesktopAudio = HasAudioDevices(App()->OutputAudioSource());
  562. bool hasInputAudio = HasAudioDevices(App()->InputAudioSource());
  563. if (hasDesktopAudio)
  564. ResetAudioDevice(App()->OutputAudioSource(), "default",
  565. Str("Basic.DesktopDevice1"), 1);
  566. if (hasInputAudio)
  567. ResetAudioDevice(App()->InputAudioSource(), "default",
  568. Str("Basic.AuxDevice1"), 3);
  569. }
  570. void OBSBasic::CreateDefaultScene(bool firstStart)
  571. {
  572. disableSaving++;
  573. ClearSceneData();
  574. InitDefaultTransitions();
  575. CreateDefaultQuickTransitions();
  576. ui->transitionDuration->setValue(300);
  577. SetTransition(fadeTransition);
  578. obs_scene_t *scene = obs_scene_create(Str("Basic.Scene"));
  579. if (firstStart)
  580. CreateFirstRunSources();
  581. SetCurrentScene(scene, true);
  582. obs_scene_release(scene);
  583. disableSaving--;
  584. }
  585. static void ReorderItemByName(QListWidget *lw, const char *name, int newIndex)
  586. {
  587. for (int i = 0; i < lw->count(); i++) {
  588. QListWidgetItem *item = lw->item(i);
  589. if (strcmp(name, QT_TO_UTF8(item->text())) == 0) {
  590. if (newIndex != i) {
  591. item = lw->takeItem(i);
  592. lw->insertItem(newIndex, item);
  593. }
  594. break;
  595. }
  596. }
  597. }
  598. void OBSBasic::LoadSceneListOrder(obs_data_array_t *array)
  599. {
  600. size_t num = obs_data_array_count(array);
  601. for (size_t i = 0; i < num; i++) {
  602. obs_data_t *data = obs_data_array_item(array, i);
  603. const char *name = obs_data_get_string(data, "name");
  604. ReorderItemByName(ui->scenes, name, (int)i);
  605. obs_data_release(data);
  606. }
  607. }
  608. void OBSBasic::LoadSavedProjectors(obs_data_array_t *array)
  609. {
  610. for (SavedProjectorInfo *info : savedProjectorsArray) {
  611. delete info;
  612. }
  613. savedProjectorsArray.clear();
  614. size_t num = obs_data_array_count(array);
  615. for (size_t i = 0; i < num; i++) {
  616. obs_data_t *data = obs_data_array_item(array, i);
  617. SavedProjectorInfo *info = new SavedProjectorInfo();
  618. info->monitor = obs_data_get_int(data, "monitor");
  619. info->type = static_cast<ProjectorType>(obs_data_get_int(data,
  620. "type"));
  621. info->geometry = std::string(
  622. obs_data_get_string(data, "geometry"));
  623. info->name = std::string(obs_data_get_string(data, "name"));
  624. savedProjectorsArray.emplace_back(info);
  625. obs_data_release(data);
  626. }
  627. }
  628. static void LogFilter(obs_source_t*, obs_source_t *filter, void *v_val)
  629. {
  630. const char *name = obs_source_get_name(filter);
  631. const char *id = obs_source_get_id(filter);
  632. int val = (int)(intptr_t)v_val;
  633. string indent;
  634. for (int i = 0; i < val; i++)
  635. indent += " ";
  636. blog(LOG_INFO, "%s- filter: '%s' (%s)", indent.c_str(), name, id);
  637. }
  638. static bool LogSceneItem(obs_scene_t*, obs_sceneitem_t *item, void *v_val)
  639. {
  640. obs_source_t *source = obs_sceneitem_get_source(item);
  641. const char *name = obs_source_get_name(source);
  642. const char *id = obs_source_get_id(source);
  643. int indent_count = (int)(intptr_t)v_val;
  644. string indent;
  645. for (int i = 0; i < indent_count; i++)
  646. indent += " ";
  647. blog(LOG_INFO, "%s- source: '%s' (%s)", indent.c_str(), name, id);
  648. obs_monitoring_type monitoring_type =
  649. obs_source_get_monitoring_type(source);
  650. if (monitoring_type != OBS_MONITORING_TYPE_NONE) {
  651. const char *type =
  652. (monitoring_type == OBS_MONITORING_TYPE_MONITOR_ONLY)
  653. ? "monitor only"
  654. : "monitor and output";
  655. blog(LOG_INFO, " %s- monitoring: %s", indent.c_str(), type);
  656. }
  657. int child_indent = 1 + indent_count;
  658. obs_source_enum_filters(source, LogFilter, (void*)(intptr_t)child_indent);
  659. if (obs_sceneitem_is_group(item))
  660. obs_sceneitem_group_enum_items(item, LogSceneItem, (void*)(intptr_t)child_indent);
  661. return true;
  662. }
  663. void OBSBasic::LogScenes()
  664. {
  665. blog(LOG_INFO, "------------------------------------------------");
  666. blog(LOG_INFO, "Loaded scenes:");
  667. for (int i = 0; i < ui->scenes->count(); i++) {
  668. QListWidgetItem *item = ui->scenes->item(i);
  669. OBSScene scene = GetOBSRef<OBSScene>(item);
  670. obs_source_t *source = obs_scene_get_source(scene);
  671. const char *name = obs_source_get_name(source);
  672. blog(LOG_INFO, "- scene '%s':", name);
  673. obs_scene_enum_items(scene, LogSceneItem, (void*)(intptr_t)1);
  674. obs_source_enum_filters(source, LogFilter, (void*)(intptr_t)1);
  675. }
  676. blog(LOG_INFO, "------------------------------------------------");
  677. }
  678. void OBSBasic::Load(const char *file)
  679. {
  680. disableSaving++;
  681. obs_data_t *data = obs_data_create_from_json_file_safe(file, "bak");
  682. if (!data) {
  683. disableSaving--;
  684. blog(LOG_INFO, "No scene file found, creating default scene");
  685. CreateDefaultScene(true);
  686. SaveProject();
  687. return;
  688. }
  689. ClearSceneData();
  690. InitDefaultTransitions();
  691. obs_data_t *modulesObj = obs_data_get_obj(data, "modules");
  692. if (api)
  693. api->on_preload(modulesObj);
  694. obs_data_array_t *sceneOrder = obs_data_get_array(data, "scene_order");
  695. obs_data_array_t *sources = obs_data_get_array(data, "sources");
  696. obs_data_array_t *groups = obs_data_get_array(data, "groups");
  697. obs_data_array_t *transitions= obs_data_get_array(data, "transitions");
  698. const char *sceneName = obs_data_get_string(data,
  699. "current_scene");
  700. const char *programSceneName = obs_data_get_string(data,
  701. "current_program_scene");
  702. const char *transitionName = obs_data_get_string(data,
  703. "current_transition");
  704. if (!opt_starting_scene.empty()) {
  705. programSceneName = opt_starting_scene.c_str();
  706. if (!IsPreviewProgramMode())
  707. sceneName = opt_starting_scene.c_str();
  708. }
  709. int newDuration = obs_data_get_int(data, "transition_duration");
  710. if (!newDuration)
  711. newDuration = 300;
  712. if (!transitionName)
  713. transitionName = obs_source_get_name(fadeTransition);
  714. const char *curSceneCollection = config_get_string(
  715. App()->GlobalConfig(), "Basic", "SceneCollection");
  716. obs_data_set_default_string(data, "name", curSceneCollection);
  717. const char *name = obs_data_get_string(data, "name");
  718. obs_source_t *curScene;
  719. obs_source_t *curProgramScene;
  720. obs_source_t *curTransition;
  721. if (!name || !*name)
  722. name = curSceneCollection;
  723. LoadAudioDevice(DESKTOP_AUDIO_1, 1, data);
  724. LoadAudioDevice(DESKTOP_AUDIO_2, 2, data);
  725. LoadAudioDevice(AUX_AUDIO_1, 3, data);
  726. LoadAudioDevice(AUX_AUDIO_2, 4, data);
  727. LoadAudioDevice(AUX_AUDIO_3, 5, data);
  728. LoadAudioDevice(AUX_AUDIO_4, 6, data);
  729. if (!sources) {
  730. sources = groups;
  731. groups = nullptr;
  732. } else {
  733. obs_data_array_push_back_array(sources, groups);
  734. }
  735. obs_load_sources(sources, nullptr, nullptr);
  736. if (transitions)
  737. LoadTransitions(transitions);
  738. if (sceneOrder)
  739. LoadSceneListOrder(sceneOrder);
  740. obs_data_array_release(transitions);
  741. curTransition = FindTransition(transitionName);
  742. if (!curTransition)
  743. curTransition = fadeTransition;
  744. ui->transitionDuration->setValue(newDuration);
  745. SetTransition(curTransition);
  746. retryScene:
  747. curScene = obs_get_source_by_name(sceneName);
  748. curProgramScene = obs_get_source_by_name(programSceneName);
  749. /* if the starting scene command line parameter is bad at all,
  750. * fall back to original settings */
  751. if (!opt_starting_scene.empty() && (!curScene || !curProgramScene)) {
  752. sceneName = obs_data_get_string(data, "current_scene");
  753. programSceneName = obs_data_get_string(data,
  754. "current_program_scene");
  755. obs_source_release(curScene);
  756. obs_source_release(curProgramScene);
  757. opt_starting_scene.clear();
  758. goto retryScene;
  759. }
  760. if (!curProgramScene) {
  761. curProgramScene = curScene;
  762. obs_source_addref(curScene);
  763. }
  764. SetCurrentScene(curScene, true);
  765. if (IsPreviewProgramMode())
  766. TransitionToScene(curProgramScene, true);
  767. obs_source_release(curScene);
  768. obs_source_release(curProgramScene);
  769. obs_data_array_release(sources);
  770. obs_data_array_release(groups);
  771. obs_data_array_release(sceneOrder);
  772. /* ------------------- */
  773. bool projectorSave = config_get_bool(GetGlobalConfig(), "BasicWindow",
  774. "SaveProjectors");
  775. if (projectorSave) {
  776. obs_data_array_t *savedProjectors = obs_data_get_array(data,
  777. "saved_projectors");
  778. if (savedProjectors) {
  779. LoadSavedProjectors(savedProjectors);
  780. OpenSavedProjectors();
  781. activateWindow();
  782. }
  783. obs_data_array_release(savedProjectors);
  784. }
  785. /* ------------------- */
  786. std::string file_base = strrchr(file, '/') + 1;
  787. file_base.erase(file_base.size() - 5, 5);
  788. config_set_string(App()->GlobalConfig(), "Basic", "SceneCollection",
  789. name);
  790. config_set_string(App()->GlobalConfig(), "Basic", "SceneCollectionFile",
  791. file_base.c_str());
  792. obs_data_array_t *quickTransitionData = obs_data_get_array(data,
  793. "quick_transitions");
  794. LoadQuickTransitions(quickTransitionData);
  795. obs_data_array_release(quickTransitionData);
  796. RefreshQuickTransitions();
  797. bool previewLocked = obs_data_get_bool(data, "preview_locked");
  798. ui->preview->SetLocked(previewLocked);
  799. ui->actionLockPreview->setChecked(previewLocked);
  800. /* ---------------------- */
  801. bool fixedScaling = obs_data_get_bool(data, "scaling_enabled");
  802. int scalingLevel = (int)obs_data_get_int(data, "scaling_level");
  803. float scrollOffX = (float)obs_data_get_double(data, "scaling_off_x");
  804. float scrollOffY = (float)obs_data_get_double(data, "scaling_off_y");
  805. if (fixedScaling) {
  806. ui->preview->SetScalingLevel(scalingLevel);
  807. ui->preview->SetScrollingOffset(scrollOffX, scrollOffY);
  808. }
  809. ui->preview->SetFixedScaling(fixedScaling);
  810. /* ---------------------- */
  811. if (api)
  812. api->on_load(modulesObj);
  813. obs_data_release(modulesObj);
  814. obs_data_release(data);
  815. if (!opt_starting_scene.empty())
  816. opt_starting_scene.clear();
  817. if (opt_start_streaming) {
  818. blog(LOG_INFO, "Starting stream due to command line parameter");
  819. QMetaObject::invokeMethod(this, "StartStreaming",
  820. Qt::QueuedConnection);
  821. opt_start_streaming = false;
  822. }
  823. if (opt_start_recording) {
  824. blog(LOG_INFO, "Starting recording due to command line parameter");
  825. QMetaObject::invokeMethod(this, "StartRecording",
  826. Qt::QueuedConnection);
  827. opt_start_recording = false;
  828. }
  829. if (opt_start_replaybuffer) {
  830. QMetaObject::invokeMethod(this, "StartReplayBuffer",
  831. Qt::QueuedConnection);
  832. opt_start_replaybuffer = false;
  833. }
  834. LogScenes();
  835. disableSaving--;
  836. if (api) {
  837. api->on_event(OBS_FRONTEND_EVENT_SCENE_CHANGED);
  838. api->on_event(OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED);
  839. }
  840. }
  841. #define SERVICE_PATH "service.json"
  842. void OBSBasic::SaveService()
  843. {
  844. if (!service)
  845. return;
  846. char serviceJsonPath[512];
  847. int ret = GetProfilePath(serviceJsonPath, sizeof(serviceJsonPath),
  848. SERVICE_PATH);
  849. if (ret <= 0)
  850. return;
  851. obs_data_t *data = obs_data_create();
  852. obs_data_t *settings = obs_service_get_settings(service);
  853. obs_data_set_string(data, "type", obs_service_get_type(service));
  854. obs_data_set_obj(data, "settings", settings);
  855. if (!obs_data_save_json_safe(data, serviceJsonPath, "tmp", "bak"))
  856. blog(LOG_WARNING, "Failed to save service");
  857. obs_data_release(settings);
  858. obs_data_release(data);
  859. }
  860. bool OBSBasic::LoadService()
  861. {
  862. const char *type;
  863. char serviceJsonPath[512];
  864. int ret = GetProfilePath(serviceJsonPath, sizeof(serviceJsonPath),
  865. SERVICE_PATH);
  866. if (ret <= 0)
  867. return false;
  868. obs_data_t *data = obs_data_create_from_json_file_safe(serviceJsonPath,
  869. "bak");
  870. obs_data_set_default_string(data, "type", "rtmp_common");
  871. type = obs_data_get_string(data, "type");
  872. obs_data_t *settings = obs_data_get_obj(data, "settings");
  873. obs_data_t *hotkey_data = obs_data_get_obj(data, "hotkeys");
  874. service = obs_service_create(type, "default_service", settings,
  875. hotkey_data);
  876. obs_service_release(service);
  877. obs_data_release(hotkey_data);
  878. obs_data_release(settings);
  879. obs_data_release(data);
  880. return !!service;
  881. }
  882. bool OBSBasic::InitService()
  883. {
  884. ProfileScope("OBSBasic::InitService");
  885. if (LoadService())
  886. return true;
  887. service = obs_service_create("rtmp_common", "default_service", nullptr,
  888. nullptr);
  889. if (!service)
  890. return false;
  891. obs_service_release(service);
  892. return true;
  893. }
  894. static const double scaled_vals[] =
  895. {
  896. 1.0,
  897. 1.25,
  898. (1.0/0.75),
  899. 1.5,
  900. (1.0/0.6),
  901. 1.75,
  902. 2.0,
  903. 2.25,
  904. 2.5,
  905. 2.75,
  906. 3.0,
  907. 0.0
  908. };
  909. extern void CheckExistingCookieId();
  910. bool OBSBasic::InitBasicConfigDefaults()
  911. {
  912. QList<QScreen*> screens = QGuiApplication::screens();
  913. if (!screens.size()) {
  914. OBSErrorBox(NULL, "There appears to be no monitors. Er, this "
  915. "technically shouldn't be possible.");
  916. return false;
  917. }
  918. QScreen *primaryScreen = QGuiApplication::primaryScreen();
  919. uint32_t cx = primaryScreen->size().width();
  920. uint32_t cy = primaryScreen->size().height();
  921. bool oldResolutionDefaults = config_get_bool(App()->GlobalConfig(),
  922. "General", "Pre19Defaults");
  923. /* use 1920x1080 for new default base res if main monitor is above
  924. * 1920x1080, but don't apply for people from older builds -- only to
  925. * new users */
  926. if (!oldResolutionDefaults && (cx * cy) > (1920 * 1080)) {
  927. cx = 1920;
  928. cy = 1080;
  929. }
  930. bool changed = false;
  931. /* ----------------------------------------------------- */
  932. /* move over old FFmpeg track settings */
  933. if (config_has_user_value(basicConfig, "AdvOut", "FFAudioTrack") &&
  934. !config_has_user_value(basicConfig, "AdvOut", "Pre22.1Settings")) {
  935. int track = (int)config_get_int(basicConfig, "AdvOut",
  936. "FFAudioTrack");
  937. config_set_int(basicConfig, "AdvOut", "FFAudioMixes",
  938. 1LL << (track - 1));
  939. config_set_bool(basicConfig, "AdvOut", "Pre22.1Settings", true);
  940. changed = true;
  941. }
  942. /* ----------------------------------------------------- */
  943. /* move over mixer values in advanced if older config */
  944. if (config_has_user_value(basicConfig, "AdvOut", "RecTrackIndex") &&
  945. !config_has_user_value(basicConfig, "AdvOut", "RecTracks")) {
  946. uint64_t track = config_get_uint(basicConfig, "AdvOut",
  947. "RecTrackIndex");
  948. track = 1ULL << (track - 1);
  949. config_set_uint(basicConfig, "AdvOut", "RecTracks", track);
  950. config_remove_value(basicConfig, "AdvOut", "RecTrackIndex");
  951. changed = true;
  952. }
  953. /* ----------------------------------------------------- */
  954. if (changed)
  955. config_save_safe(basicConfig, "tmp", nullptr);
  956. /* ----------------------------------------------------- */
  957. config_set_default_string(basicConfig, "Output", "Mode", "Simple");
  958. config_set_default_string(basicConfig, "SimpleOutput", "FilePath",
  959. GetDefaultVideoSavePath().c_str());
  960. config_set_default_string(basicConfig, "SimpleOutput", "RecFormat",
  961. "flv");
  962. config_set_default_uint (basicConfig, "SimpleOutput", "VBitrate",
  963. 2500);
  964. config_set_default_uint (basicConfig, "SimpleOutput", "ABitrate", 160);
  965. config_set_default_bool (basicConfig, "SimpleOutput", "UseAdvanced",
  966. false);
  967. config_set_default_bool (basicConfig, "SimpleOutput", "EnforceBitrate",
  968. true);
  969. config_set_default_string(basicConfig, "SimpleOutput", "Preset",
  970. "veryfast");
  971. config_set_default_string(basicConfig, "SimpleOutput", "NVENCPreset",
  972. "hq");
  973. config_set_default_string(basicConfig, "SimpleOutput", "RecQuality",
  974. "Stream");
  975. config_set_default_bool(basicConfig, "SimpleOutput", "RecRB", false);
  976. config_set_default_int(basicConfig, "SimpleOutput", "RecRBTime", 20);
  977. config_set_default_int(basicConfig, "SimpleOutput", "RecRBSize", 512);
  978. config_set_default_string(basicConfig, "SimpleOutput", "RecRBPrefix",
  979. "Replay");
  980. config_set_default_bool (basicConfig, "AdvOut", "ApplyServiceSettings",
  981. true);
  982. config_set_default_bool (basicConfig, "AdvOut", "UseRescale", false);
  983. config_set_default_uint (basicConfig, "AdvOut", "TrackIndex", 1);
  984. config_set_default_string(basicConfig, "AdvOut", "Encoder", "obs_x264");
  985. config_set_default_string(basicConfig, "AdvOut", "RecType", "Standard");
  986. config_set_default_string(basicConfig, "AdvOut", "RecFilePath",
  987. GetDefaultVideoSavePath().c_str());
  988. config_set_default_string(basicConfig, "AdvOut", "RecFormat", "flv");
  989. config_set_default_bool (basicConfig, "AdvOut", "RecUseRescale",
  990. false);
  991. config_set_default_uint (basicConfig, "AdvOut", "RecTracks", (1<<0));
  992. config_set_default_string(basicConfig, "AdvOut", "RecEncoder",
  993. "none");
  994. config_set_default_bool (basicConfig, "AdvOut", "FFOutputToFile",
  995. true);
  996. config_set_default_string(basicConfig, "AdvOut", "FFFilePath",
  997. GetDefaultVideoSavePath().c_str());
  998. config_set_default_string(basicConfig, "AdvOut", "FFExtension", "mp4");
  999. config_set_default_uint (basicConfig, "AdvOut", "FFVBitrate", 2500);
  1000. config_set_default_uint (basicConfig, "AdvOut", "FFVGOPSize", 250);
  1001. config_set_default_bool (basicConfig, "AdvOut", "FFUseRescale",
  1002. false);
  1003. config_set_default_bool (basicConfig, "AdvOut", "FFIgnoreCompat",
  1004. false);
  1005. config_set_default_uint (basicConfig, "AdvOut", "FFABitrate", 160);
  1006. config_set_default_uint (basicConfig, "AdvOut", "FFAudioMixes", 1);
  1007. config_set_default_uint (basicConfig, "AdvOut", "Track1Bitrate", 160);
  1008. config_set_default_uint (basicConfig, "AdvOut", "Track2Bitrate", 160);
  1009. config_set_default_uint (basicConfig, "AdvOut", "Track3Bitrate", 160);
  1010. config_set_default_uint (basicConfig, "AdvOut", "Track4Bitrate", 160);
  1011. config_set_default_uint (basicConfig, "AdvOut", "Track5Bitrate", 160);
  1012. config_set_default_uint (basicConfig, "AdvOut", "Track6Bitrate", 160);
  1013. config_set_default_bool (basicConfig, "AdvOut", "RecRB", false);
  1014. config_set_default_uint (basicConfig, "AdvOut", "RecRBTime", 20);
  1015. config_set_default_int (basicConfig, "AdvOut", "RecRBSize", 512);
  1016. config_set_default_uint (basicConfig, "Video", "BaseCX", cx);
  1017. config_set_default_uint (basicConfig, "Video", "BaseCY", cy);
  1018. /* don't allow BaseCX/BaseCY to be susceptible to defaults changing */
  1019. if (!config_has_user_value(basicConfig, "Video", "BaseCX") ||
  1020. !config_has_user_value(basicConfig, "Video", "BaseCY")) {
  1021. config_set_uint(basicConfig, "Video", "BaseCX", cx);
  1022. config_set_uint(basicConfig, "Video", "BaseCY", cy);
  1023. config_save_safe(basicConfig, "tmp", nullptr);
  1024. }
  1025. config_set_default_string(basicConfig, "Output", "FilenameFormatting",
  1026. "%CCYY-%MM-%DD %hh-%mm-%ss");
  1027. config_set_default_bool (basicConfig, "Output", "DelayEnable", false);
  1028. config_set_default_uint (basicConfig, "Output", "DelaySec", 20);
  1029. config_set_default_bool (basicConfig, "Output", "DelayPreserve", true);
  1030. config_set_default_bool (basicConfig, "Output", "Reconnect", true);
  1031. config_set_default_uint (basicConfig, "Output", "RetryDelay", 10);
  1032. config_set_default_uint (basicConfig, "Output", "MaxRetries", 20);
  1033. config_set_default_string(basicConfig, "Output", "BindIP", "default");
  1034. config_set_default_bool (basicConfig, "Output", "NewSocketLoopEnable",
  1035. false);
  1036. config_set_default_bool (basicConfig, "Output", "LowLatencyEnable",
  1037. false);
  1038. int i = 0;
  1039. uint32_t scale_cx = cx;
  1040. uint32_t scale_cy = cy;
  1041. /* use a default scaled resolution that has a pixel count no higher
  1042. * than 1280x720 */
  1043. while (((scale_cx * scale_cy) > (1280 * 720)) && scaled_vals[i] > 0.0) {
  1044. double scale = scaled_vals[i++];
  1045. scale_cx = uint32_t(double(cx) / scale);
  1046. scale_cy = uint32_t(double(cy) / scale);
  1047. }
  1048. config_set_default_uint (basicConfig, "Video", "OutputCX", scale_cx);
  1049. config_set_default_uint (basicConfig, "Video", "OutputCY", scale_cy);
  1050. /* don't allow OutputCX/OutputCY to be susceptible to defaults
  1051. * changing */
  1052. if (!config_has_user_value(basicConfig, "Video", "OutputCX") ||
  1053. !config_has_user_value(basicConfig, "Video", "OutputCY")) {
  1054. config_set_uint(basicConfig, "Video", "OutputCX", scale_cx);
  1055. config_set_uint(basicConfig, "Video", "OutputCY", scale_cy);
  1056. config_save_safe(basicConfig, "tmp", nullptr);
  1057. }
  1058. config_set_default_uint (basicConfig, "Video", "FPSType", 0);
  1059. config_set_default_string(basicConfig, "Video", "FPSCommon", "30");
  1060. config_set_default_uint (basicConfig, "Video", "FPSInt", 30);
  1061. config_set_default_uint (basicConfig, "Video", "FPSNum", 30);
  1062. config_set_default_uint (basicConfig, "Video", "FPSDen", 1);
  1063. config_set_default_string(basicConfig, "Video", "ScaleType", "bicubic");
  1064. config_set_default_string(basicConfig, "Video", "ColorFormat", "NV12");
  1065. config_set_default_string(basicConfig, "Video", "ColorSpace", "601");
  1066. config_set_default_string(basicConfig, "Video", "ColorRange",
  1067. "Partial");
  1068. config_set_default_string(basicConfig, "Audio", "MonitoringDeviceId",
  1069. "default");
  1070. config_set_default_string(basicConfig, "Audio", "MonitoringDeviceName",
  1071. Str("Basic.Settings.Advanced.Audio.MonitoringDevice"
  1072. ".Default"));
  1073. config_set_default_uint (basicConfig, "Audio", "SampleRate", 44100);
  1074. config_set_default_string(basicConfig, "Audio", "ChannelSetup",
  1075. "Stereo");
  1076. config_set_default_double(basicConfig, "Audio", "MeterDecayRate",
  1077. VOLUME_METER_DECAY_FAST);
  1078. config_set_default_uint (basicConfig, "Audio", "PeakMeterType", 0);
  1079. CheckExistingCookieId();
  1080. return true;
  1081. }
  1082. extern bool EncoderAvailable(const char *encoder);
  1083. void OBSBasic::InitBasicConfigDefaults2()
  1084. {
  1085. bool oldEncDefaults = config_get_bool(App()->GlobalConfig(),
  1086. "General", "Pre23Defaults");
  1087. bool useNV = EncoderAvailable("ffmpeg_nvenc") && !oldEncDefaults;
  1088. config_set_default_string(basicConfig, "SimpleOutput", "StreamEncoder",
  1089. useNV ? SIMPLE_ENCODER_NVENC : SIMPLE_ENCODER_X264);
  1090. config_set_default_string(basicConfig, "SimpleOutput", "RecEncoder",
  1091. useNV ? SIMPLE_ENCODER_NVENC : SIMPLE_ENCODER_X264);
  1092. }
  1093. bool OBSBasic::InitBasicConfig()
  1094. {
  1095. ProfileScope("OBSBasic::InitBasicConfig");
  1096. char configPath[512];
  1097. int ret = GetProfilePath(configPath, sizeof(configPath), "");
  1098. if (ret <= 0) {
  1099. OBSErrorBox(nullptr, "Failed to get profile path");
  1100. return false;
  1101. }
  1102. if (os_mkdir(configPath) == MKDIR_ERROR) {
  1103. OBSErrorBox(nullptr, "Failed to create profile path");
  1104. return false;
  1105. }
  1106. ret = GetProfilePath(configPath, sizeof(configPath), "basic.ini");
  1107. if (ret <= 0) {
  1108. OBSErrorBox(nullptr, "Failed to get base.ini path");
  1109. return false;
  1110. }
  1111. int code = basicConfig.Open(configPath, CONFIG_OPEN_ALWAYS);
  1112. if (code != CONFIG_SUCCESS) {
  1113. OBSErrorBox(NULL, "Failed to open basic.ini: %d", code);
  1114. return false;
  1115. }
  1116. if (config_get_string(basicConfig, "General", "Name") == nullptr) {
  1117. const char *curName = config_get_string(App()->GlobalConfig(),
  1118. "Basic", "Profile");
  1119. config_set_string(basicConfig, "General", "Name", curName);
  1120. basicConfig.SaveSafe("tmp");
  1121. }
  1122. return InitBasicConfigDefaults();
  1123. }
  1124. void OBSBasic::InitOBSCallbacks()
  1125. {
  1126. ProfileScope("OBSBasic::InitOBSCallbacks");
  1127. signalHandlers.reserve(signalHandlers.size() + 6);
  1128. signalHandlers.emplace_back(obs_get_signal_handler(), "source_create",
  1129. OBSBasic::SourceCreated, this);
  1130. signalHandlers.emplace_back(obs_get_signal_handler(), "source_remove",
  1131. OBSBasic::SourceRemoved, this);
  1132. signalHandlers.emplace_back(obs_get_signal_handler(), "source_activate",
  1133. OBSBasic::SourceActivated, this);
  1134. signalHandlers.emplace_back(obs_get_signal_handler(), "source_deactivate",
  1135. OBSBasic::SourceDeactivated, this);
  1136. signalHandlers.emplace_back(obs_get_signal_handler(), "source_rename",
  1137. OBSBasic::SourceRenamed, this);
  1138. }
  1139. void OBSBasic::InitPrimitives()
  1140. {
  1141. ProfileScope("OBSBasic::InitPrimitives");
  1142. obs_enter_graphics();
  1143. gs_render_start(true);
  1144. gs_vertex2f(0.0f, 0.0f);
  1145. gs_vertex2f(0.0f, 1.0f);
  1146. gs_vertex2f(1.0f, 1.0f);
  1147. gs_vertex2f(1.0f, 0.0f);
  1148. gs_vertex2f(0.0f, 0.0f);
  1149. box = gs_render_save();
  1150. gs_render_start(true);
  1151. gs_vertex2f(0.0f, 0.0f);
  1152. gs_vertex2f(0.0f, 1.0f);
  1153. boxLeft = gs_render_save();
  1154. gs_render_start(true);
  1155. gs_vertex2f(0.0f, 0.0f);
  1156. gs_vertex2f(1.0f, 0.0f);
  1157. boxTop = gs_render_save();
  1158. gs_render_start(true);
  1159. gs_vertex2f(1.0f, 0.0f);
  1160. gs_vertex2f(1.0f, 1.0f);
  1161. boxRight = gs_render_save();
  1162. gs_render_start(true);
  1163. gs_vertex2f(0.0f, 1.0f);
  1164. gs_vertex2f(1.0f, 1.0f);
  1165. boxBottom = gs_render_save();
  1166. gs_render_start(true);
  1167. for (int i = 0; i <= 360; i += (360/20)) {
  1168. float pos = RAD(float(i));
  1169. gs_vertex2f(cosf(pos), sinf(pos));
  1170. }
  1171. circle = gs_render_save();
  1172. obs_leave_graphics();
  1173. }
  1174. void OBSBasic::ReplayBufferClicked()
  1175. {
  1176. if (outputHandler->ReplayBufferActive())
  1177. StopReplayBuffer();
  1178. else
  1179. StartReplayBuffer();
  1180. };
  1181. void OBSBasic::ResetOutputs()
  1182. {
  1183. ProfileScope("OBSBasic::ResetOutputs");
  1184. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  1185. bool advOut = astrcmpi(mode, "Advanced") == 0;
  1186. if (!outputHandler || !outputHandler->Active()) {
  1187. outputHandler.reset();
  1188. outputHandler.reset(advOut ?
  1189. CreateAdvancedOutputHandler(this) :
  1190. CreateSimpleOutputHandler(this));
  1191. delete replayBufferButton;
  1192. if (outputHandler->replayBuffer) {
  1193. replayBufferButton = new QPushButton(
  1194. QTStr("Basic.Main.StartReplayBuffer"),
  1195. this);
  1196. replayBufferButton->setCheckable(true);
  1197. connect(replayBufferButton.data(),
  1198. &QPushButton::clicked,
  1199. this,
  1200. &OBSBasic::ReplayBufferClicked);
  1201. replayBufferButton->setProperty("themeID", "replayBufferButton");
  1202. ui->buttonsVLayout->insertWidget(2, replayBufferButton);
  1203. }
  1204. if (sysTrayReplayBuffer)
  1205. sysTrayReplayBuffer->setEnabled(
  1206. !!outputHandler->replayBuffer);
  1207. } else {
  1208. outputHandler->Update();
  1209. }
  1210. }
  1211. static void AddProjectorMenuMonitors(QMenu *parent, QObject *target,
  1212. const char *slot);
  1213. #define STARTUP_SEPARATOR \
  1214. "==== Startup complete ==============================================="
  1215. #define SHUTDOWN_SEPARATOR \
  1216. "==== Shutting down =================================================="
  1217. #define UNSUPPORTED_ERROR \
  1218. "Failed to initialize video:\n\nRequired graphics API functionality " \
  1219. "not found. Your GPU may not be supported."
  1220. #define UNKNOWN_ERROR \
  1221. "Failed to initialize video. Your GPU may not be supported, " \
  1222. "or your graphics drivers may need to be updated."
  1223. void OBSBasic::OBSInit()
  1224. {
  1225. ProfileScope("OBSBasic::OBSInit");
  1226. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  1227. "Basic", "SceneCollectionFile");
  1228. char savePath[512];
  1229. char fileName[512];
  1230. int ret;
  1231. if (!sceneCollection)
  1232. throw "Failed to get scene collection name";
  1233. ret = snprintf(fileName, 512, "obs-studio/basic/scenes/%s.json",
  1234. sceneCollection);
  1235. if (ret <= 0)
  1236. throw "Failed to create scene collection file name";
  1237. ret = GetConfigPath(savePath, sizeof(savePath), fileName);
  1238. if (ret <= 0)
  1239. throw "Failed to get scene collection json file path";
  1240. if (!InitBasicConfig())
  1241. throw "Failed to load basic.ini";
  1242. if (!ResetAudio())
  1243. throw "Failed to initialize audio";
  1244. ret = ResetVideo();
  1245. switch (ret) {
  1246. case OBS_VIDEO_MODULE_NOT_FOUND:
  1247. throw "Failed to initialize video: Graphics module not found";
  1248. case OBS_VIDEO_NOT_SUPPORTED:
  1249. throw UNSUPPORTED_ERROR;
  1250. case OBS_VIDEO_INVALID_PARAM:
  1251. throw "Failed to initialize video: Invalid parameters";
  1252. default:
  1253. if (ret != OBS_VIDEO_SUCCESS)
  1254. throw UNKNOWN_ERROR;
  1255. }
  1256. /* load audio monitoring */
  1257. #if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
  1258. const char *device_name = config_get_string(basicConfig, "Audio",
  1259. "MonitoringDeviceName");
  1260. const char *device_id = config_get_string(basicConfig, "Audio",
  1261. "MonitoringDeviceId");
  1262. obs_set_audio_monitoring_device(device_name, device_id);
  1263. blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s",
  1264. device_name, device_id);
  1265. #endif
  1266. InitOBSCallbacks();
  1267. InitHotkeys();
  1268. AddExtraModulePaths();
  1269. blog(LOG_INFO, "---------------------------------");
  1270. obs_load_all_modules();
  1271. blog(LOG_INFO, "---------------------------------");
  1272. obs_log_loaded_modules();
  1273. blog(LOG_INFO, "---------------------------------");
  1274. obs_post_load_modules();
  1275. #ifdef BROWSER_AVAILABLE
  1276. cef = obs_browser_init_panel();
  1277. #endif
  1278. InitBasicConfigDefaults2();
  1279. CheckForSimpleModeX264Fallback();
  1280. blog(LOG_INFO, STARTUP_SEPARATOR);
  1281. ResetOutputs();
  1282. CreateHotkeys();
  1283. if (!InitService())
  1284. throw "Failed to initialize service";
  1285. InitPrimitives();
  1286. sceneDuplicationMode = config_get_bool(App()->GlobalConfig(),
  1287. "BasicWindow", "SceneDuplicationMode");
  1288. swapScenesMode = config_get_bool(App()->GlobalConfig(),
  1289. "BasicWindow", "SwapScenesMode");
  1290. editPropertiesMode = config_get_bool(App()->GlobalConfig(),
  1291. "BasicWindow", "EditPropertiesMode");
  1292. if (!opt_studio_mode) {
  1293. SetPreviewProgramMode(config_get_bool(App()->GlobalConfig(),
  1294. "BasicWindow", "PreviewProgramMode"));
  1295. } else {
  1296. SetPreviewProgramMode(true);
  1297. opt_studio_mode = false;
  1298. }
  1299. #define SET_VISIBILITY(name, control) \
  1300. do { \
  1301. if (config_has_user_value(App()->GlobalConfig(), \
  1302. "BasicWindow", name)) { \
  1303. bool visible = config_get_bool(App()->GlobalConfig(), \
  1304. "BasicWindow", name); \
  1305. ui->control->setChecked(visible); \
  1306. } \
  1307. } while (false)
  1308. SET_VISIBILITY("ShowListboxToolbars", toggleListboxToolbars);
  1309. SET_VISIBILITY("ShowStatusBar", toggleStatusBar);
  1310. #undef SET_VISIBILITY
  1311. #ifndef __APPLE__
  1312. {
  1313. ProfileScope("OBSBasic::Load");
  1314. disableSaving--;
  1315. Load(savePath);
  1316. disableSaving++;
  1317. }
  1318. #endif
  1319. TimedCheckForUpdates();
  1320. loaded = true;
  1321. previewEnabled = config_get_bool(App()->GlobalConfig(),
  1322. "BasicWindow", "PreviewEnabled");
  1323. if (!previewEnabled && !IsPreviewProgramMode())
  1324. QMetaObject::invokeMethod(this, "EnablePreviewDisplay",
  1325. Qt::QueuedConnection,
  1326. Q_ARG(bool, previewEnabled));
  1327. #ifdef _WIN32
  1328. uint32_t winVer = GetWindowsVersion();
  1329. if (winVer > 0 && winVer < 0x602) {
  1330. bool disableAero = config_get_bool(basicConfig, "Video",
  1331. "DisableAero");
  1332. SetAeroEnabled(!disableAero);
  1333. }
  1334. #endif
  1335. #ifndef __APPLE__
  1336. RefreshSceneCollections();
  1337. #endif
  1338. RefreshProfiles();
  1339. disableSaving--;
  1340. auto addDisplay = [this] (OBSQTDisplay *window)
  1341. {
  1342. obs_display_add_draw_callback(window->GetDisplay(),
  1343. OBSBasic::RenderMain, this);
  1344. struct obs_video_info ovi;
  1345. if (obs_get_video_info(&ovi))
  1346. ResizePreview(ovi.base_width, ovi.base_height);
  1347. };
  1348. connect(ui->preview, &OBSQTDisplay::DisplayCreated, addDisplay);
  1349. #ifdef _WIN32
  1350. SetWin32DropStyle(this);
  1351. show();
  1352. #endif
  1353. bool alwaysOnTop = config_get_bool(App()->GlobalConfig(), "BasicWindow",
  1354. "AlwaysOnTop");
  1355. if (alwaysOnTop || opt_always_on_top) {
  1356. SetAlwaysOnTop(this, true);
  1357. ui->actionAlwaysOnTop->setChecked(true);
  1358. }
  1359. #ifndef _WIN32
  1360. show();
  1361. #endif
  1362. /* setup stats dock */
  1363. OBSBasicStats *statsDlg = new OBSBasicStats(statsDock, false);
  1364. statsDock->setWidget(statsDlg);
  1365. const char *dockStateStr = config_get_string(App()->GlobalConfig(),
  1366. "BasicWindow", "DockState");
  1367. if (!dockStateStr) {
  1368. on_resetUI_triggered();
  1369. } else {
  1370. QByteArray dockState =
  1371. QByteArray::fromBase64(QByteArray(dockStateStr));
  1372. if (!restoreState(dockState))
  1373. on_resetUI_triggered();
  1374. }
  1375. bool pre23Defaults = config_get_bool(App()->GlobalConfig(),
  1376. "General", "Pre23Defaults");
  1377. if (pre23Defaults) {
  1378. bool resetDockLock23 = config_get_bool(App()->GlobalConfig(),
  1379. "General", "ResetDockLock23");
  1380. if (!resetDockLock23) {
  1381. config_set_bool(App()->GlobalConfig(),
  1382. "General", "ResetDockLock23", true);
  1383. config_remove_value(App()->GlobalConfig(),
  1384. "BasicWindow", "DocksLocked");
  1385. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  1386. }
  1387. }
  1388. bool docksLocked = config_get_bool(App()->GlobalConfig(),
  1389. "BasicWindow", "DocksLocked");
  1390. on_lockUI_toggled(docksLocked);
  1391. ui->lockUI->blockSignals(true);
  1392. ui->lockUI->setChecked(docksLocked);
  1393. ui->lockUI->blockSignals(false);
  1394. #ifndef __APPLE__
  1395. SystemTray(true);
  1396. #endif
  1397. if (windowState().testFlag(Qt::WindowFullScreen))
  1398. fullscreenInterface = true;
  1399. bool has_last_version = config_has_user_value(App()->GlobalConfig(),
  1400. "General", "LastVersion");
  1401. bool first_run = config_get_bool(App()->GlobalConfig(), "General",
  1402. "FirstRun");
  1403. if (!first_run) {
  1404. config_set_bool(App()->GlobalConfig(), "General", "FirstRun",
  1405. true);
  1406. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  1407. }
  1408. if (!first_run && !has_last_version && !Active()) {
  1409. QString msg;
  1410. msg = QTStr("Basic.FirstStartup.RunWizard");
  1411. QMessageBox::StandardButton button =
  1412. OBSMessageBox::question(this, QTStr("Basic.AutoConfig"),
  1413. msg);
  1414. if (button == QMessageBox::Yes) {
  1415. QMetaObject::invokeMethod(this,
  1416. "on_autoConfigure_triggered",
  1417. Qt::QueuedConnection);
  1418. } else {
  1419. msg = QTStr("Basic.FirstStartup.RunWizard.NoClicked");
  1420. OBSMessageBox::information(this,
  1421. QTStr("Basic.AutoConfig"), msg);
  1422. }
  1423. }
  1424. ToggleMixerLayout(config_get_bool(App()->GlobalConfig(), "BasicWindow",
  1425. "VerticalVolControl"));
  1426. if (config_get_bool(basicConfig, "General", "OpenStatsOnStartup"))
  1427. on_stats_triggered();
  1428. OBSBasicStats::InitializeValues();
  1429. /* ----------------------- */
  1430. /* Add multiview menu */
  1431. ui->viewMenu->addSeparator();
  1432. multiviewProjectorMenu = new QMenu(QTStr("MultiviewProjector"));
  1433. ui->viewMenu->addMenu(multiviewProjectorMenu);
  1434. AddProjectorMenuMonitors(multiviewProjectorMenu, this,
  1435. SLOT(OpenMultiviewProjector()));
  1436. connect(ui->viewMenu->menuAction(), &QAction::hovered, this,
  1437. &OBSBasic::UpdateMultiviewProjectorMenu);
  1438. ui->viewMenu->addAction(QTStr("MultiviewWindowed"),
  1439. this, SLOT(OpenMultiviewWindow()));
  1440. #if !defined(_WIN32) && !defined(__APPLE__)
  1441. delete ui->actionShowCrashLogs;
  1442. delete ui->actionUploadLastCrashLog;
  1443. delete ui->menuCrashLogs;
  1444. delete ui->actionCheckForUpdates;
  1445. ui->actionShowCrashLogs = nullptr;
  1446. ui->actionUploadLastCrashLog = nullptr;
  1447. ui->menuCrashLogs = nullptr;
  1448. ui->actionCheckForUpdates = nullptr;
  1449. #endif
  1450. #ifdef __APPLE__
  1451. /* This is an incredibly unpleasant hack for macOS to isolate CEF
  1452. * initialization until after all tasks related to Qt startup and main
  1453. * window initialization have completed. There is a macOS-specific bug
  1454. * within either CEF and/or Qt that can cause a crash if both Qt and
  1455. * CEF are loading at the same time.
  1456. *
  1457. * CEF will typically load fine after about two iterations from this
  1458. * point, and all Qt tasks are typically fully completed after about
  1459. * four or five iterations, but to be "ultra" safe, an arbitrarily
  1460. * large number such as 10 is used. This hack is extremely unpleasant,
  1461. * but is worth doing instead of being forced to isolate the entire
  1462. * browser plugin in to a separate process as before.
  1463. *
  1464. * Again, this hack is specific to macOS only. Fortunately, on other
  1465. * operating systems, such issues do not occur. */
  1466. QMetaObject::invokeMethod(this, "DeferredLoad",
  1467. Qt::QueuedConnection,
  1468. Q_ARG(QString, QT_UTF8(savePath)),
  1469. Q_ARG(int, 10));
  1470. #else
  1471. OnFirstLoad();
  1472. #endif
  1473. }
  1474. void OBSBasic::OnFirstLoad()
  1475. {
  1476. if (api)
  1477. api->on_event(OBS_FRONTEND_EVENT_FINISHED_LOADING);
  1478. #ifdef BROWSER_AVAILABLE
  1479. /* Attempt to load init screen if available */
  1480. if (cef) {
  1481. WhatsNewInfoThread *wnit = new WhatsNewInfoThread();
  1482. if (wnit) {
  1483. connect(wnit, &WhatsNewInfoThread::Result,
  1484. this, &OBSBasic::ReceivedIntroJson);
  1485. }
  1486. if (wnit) {
  1487. introCheckThread.reset(wnit);
  1488. introCheckThread->start();
  1489. }
  1490. }
  1491. #endif
  1492. Auth::Load();
  1493. }
  1494. void OBSBasic::DeferredLoad(const QString &file, int requeueCount)
  1495. {
  1496. if (--requeueCount > 0) {
  1497. QMetaObject::invokeMethod(this, "DeferredLoad",
  1498. Qt::QueuedConnection,
  1499. Q_ARG(QString, file),
  1500. Q_ARG(int, requeueCount));
  1501. return;
  1502. }
  1503. Load(QT_TO_UTF8(file));
  1504. RefreshSceneCollections();
  1505. OnFirstLoad();
  1506. /* Minimizng to tray on initial startup does not work on mac
  1507. * unless it is done in the deferred load */
  1508. SystemTray(true);
  1509. }
  1510. /* shows a "what's new" page on startup of new versions using CEF */
  1511. void OBSBasic::ReceivedIntroJson(const QString &text)
  1512. {
  1513. #ifdef BROWSER_AVAILABLE
  1514. #ifdef _WIN32
  1515. std::string err;
  1516. Json json = Json::parse(QT_TO_UTF8(text), err);
  1517. if (!err.empty())
  1518. return;
  1519. std::string info_url;
  1520. int info_increment = -1;
  1521. /* check to see if there's an info page for this version */
  1522. const Json::array &items = json.array_items();
  1523. for (const Json &item : items) {
  1524. const std::string &version = item["version"].string_value();
  1525. const std::string &url = item["url"].string_value();
  1526. int increment = item["increment"].int_value();
  1527. int rc = item["RC"].int_value();
  1528. int major = 0;
  1529. int minor = 0;
  1530. sscanf(version.c_str(), "%d.%d", &major, &minor);
  1531. #if OBS_RELEASE_CANDIDATE > 0
  1532. if (major == OBS_RELEASE_CANDIDATE_MAJOR &&
  1533. minor == OBS_RELEASE_CANDIDATE_MINOR &&
  1534. rc == OBS_RELEASE_CANDIDATE) {
  1535. #else
  1536. if (major == LIBOBS_API_MAJOR_VER &&
  1537. minor == LIBOBS_API_MINOR_VER &&
  1538. rc == 0) {
  1539. #endif
  1540. info_url = url;
  1541. info_increment = increment;
  1542. }
  1543. }
  1544. /* this version was not found, or no info for this version */
  1545. if (info_increment == -1) {
  1546. return;
  1547. }
  1548. #if OBS_RELEASE_CANDIDATE > 0
  1549. uint32_t lastVersion = config_get_int(App()->GlobalConfig(), "General",
  1550. "LastRCVersion");
  1551. #else
  1552. uint32_t lastVersion = config_get_int(App()->GlobalConfig(), "General",
  1553. "LastVersion");
  1554. #endif
  1555. int current_version_increment = -1;
  1556. #if OBS_RELEASE_CANDIDATE > 0
  1557. if (lastVersion < OBS_RELEASE_CANDIDATE_VER) {
  1558. #else
  1559. if ((lastVersion & ~0xFFFF) < (LIBOBS_API_VER & ~0xFFFF)) {
  1560. #endif
  1561. config_set_int(App()->GlobalConfig(), "General",
  1562. "InfoIncrement", -1);
  1563. } else {
  1564. current_version_increment = config_get_int(
  1565. App()->GlobalConfig(), "General",
  1566. "InfoIncrement");
  1567. }
  1568. if (info_increment <= current_version_increment) {
  1569. return;
  1570. }
  1571. config_set_int(App()->GlobalConfig(), "General",
  1572. "InfoIncrement", info_increment);
  1573. /* Don't show What's New dialog for new users */
  1574. #if !defined(OBS_RELEASE_CANDIDATE) || OBS_RELEASE_CANDIDATE == 0
  1575. if (!lastVersion) {
  1576. return;
  1577. }
  1578. #endif
  1579. cef->init_browser();
  1580. ExecuteFuncSafeBlock([] {cef->wait_for_browser_init();});
  1581. QDialog *dlg = new QDialog(this);
  1582. dlg->setAttribute(Qt::WA_DeleteOnClose, true);
  1583. dlg->setWindowTitle("What's New");
  1584. dlg->resize(700, 600);
  1585. Qt::WindowFlags flags = dlg->windowFlags();
  1586. Qt::WindowFlags helpFlag = Qt::WindowContextHelpButtonHint;
  1587. dlg->setWindowFlags(flags & (~helpFlag));
  1588. QCefWidget *cefWidget = cef->create_widget(nullptr, info_url);
  1589. if (!cefWidget) {
  1590. return;
  1591. }
  1592. connect(cefWidget, SIGNAL(titleChanged(const QString &)),
  1593. dlg, SLOT(setWindowTitle(const QString &)));
  1594. QPushButton *close = new QPushButton(QTStr("Close"));
  1595. connect(close, &QAbstractButton::clicked,
  1596. dlg, &QDialog::accept);
  1597. QHBoxLayout *bottomLayout = new QHBoxLayout();
  1598. bottomLayout->addStretch();
  1599. bottomLayout->addWidget(close);
  1600. bottomLayout->addStretch();
  1601. QVBoxLayout *topLayout = new QVBoxLayout(dlg);
  1602. topLayout->addWidget(cefWidget);
  1603. topLayout->addLayout(bottomLayout);
  1604. dlg->show();
  1605. #else
  1606. UNUSED_PARAMETER(text);
  1607. #endif
  1608. #else
  1609. UNUSED_PARAMETER(text);
  1610. #endif
  1611. }
  1612. void OBSBasic::UpdateMultiviewProjectorMenu()
  1613. {
  1614. multiviewProjectorMenu->clear();
  1615. AddProjectorMenuMonitors(multiviewProjectorMenu, this,
  1616. SLOT(OpenMultiviewProjector()));
  1617. }
  1618. void OBSBasic::InitHotkeys()
  1619. {
  1620. ProfileScope("OBSBasic::InitHotkeys");
  1621. struct obs_hotkeys_translations t = {};
  1622. t.insert = Str("Hotkeys.Insert");
  1623. t.del = Str("Hotkeys.Delete");
  1624. t.home = Str("Hotkeys.Home");
  1625. t.end = Str("Hotkeys.End");
  1626. t.page_up = Str("Hotkeys.PageUp");
  1627. t.page_down = Str("Hotkeys.PageDown");
  1628. t.num_lock = Str("Hotkeys.NumLock");
  1629. t.scroll_lock = Str("Hotkeys.ScrollLock");
  1630. t.caps_lock = Str("Hotkeys.CapsLock");
  1631. t.backspace = Str("Hotkeys.Backspace");
  1632. t.tab = Str("Hotkeys.Tab");
  1633. t.print = Str("Hotkeys.Print");
  1634. t.pause = Str("Hotkeys.Pause");
  1635. t.left = Str("Hotkeys.Left");
  1636. t.right = Str("Hotkeys.Right");
  1637. t.up = Str("Hotkeys.Up");
  1638. t.down = Str("Hotkeys.Down");
  1639. #ifdef _WIN32
  1640. t.meta = Str("Hotkeys.Windows");
  1641. #else
  1642. t.meta = Str("Hotkeys.Super");
  1643. #endif
  1644. t.menu = Str("Hotkeys.Menu");
  1645. t.space = Str("Hotkeys.Space");
  1646. t.numpad_num = Str("Hotkeys.NumpadNum");
  1647. t.numpad_multiply = Str("Hotkeys.NumpadMultiply");
  1648. t.numpad_divide = Str("Hotkeys.NumpadDivide");
  1649. t.numpad_plus = Str("Hotkeys.NumpadAdd");
  1650. t.numpad_minus = Str("Hotkeys.NumpadSubtract");
  1651. t.numpad_decimal = Str("Hotkeys.NumpadDecimal");
  1652. t.apple_keypad_num = Str("Hotkeys.AppleKeypadNum");
  1653. t.apple_keypad_multiply = Str("Hotkeys.AppleKeypadMultiply");
  1654. t.apple_keypad_divide = Str("Hotkeys.AppleKeypadDivide");
  1655. t.apple_keypad_plus = Str("Hotkeys.AppleKeypadAdd");
  1656. t.apple_keypad_minus = Str("Hotkeys.AppleKeypadSubtract");
  1657. t.apple_keypad_decimal = Str("Hotkeys.AppleKeypadDecimal");
  1658. t.apple_keypad_equal = Str("Hotkeys.AppleKeypadEqual");
  1659. t.mouse_num = Str("Hotkeys.MouseButton");
  1660. t.escape = Str("Hotkeys.Escape");
  1661. obs_hotkeys_set_translations(&t);
  1662. obs_hotkeys_set_audio_hotkeys_translations(Str("Mute"), Str("Unmute"),
  1663. Str("Push-to-mute"), Str("Push-to-talk"));
  1664. obs_hotkeys_set_sceneitem_hotkeys_translations(
  1665. Str("SceneItemShow"), Str("SceneItemHide"));
  1666. obs_hotkey_enable_callback_rerouting(true);
  1667. obs_hotkey_set_callback_routing_func(OBSBasic::HotkeyTriggered, this);
  1668. }
  1669. void OBSBasic::ProcessHotkey(obs_hotkey_id id, bool pressed)
  1670. {
  1671. obs_hotkey_trigger_routed_callback(id, pressed);
  1672. }
  1673. void OBSBasic::HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed)
  1674. {
  1675. OBSBasic &basic = *static_cast<OBSBasic*>(data);
  1676. QMetaObject::invokeMethod(&basic, "ProcessHotkey",
  1677. Q_ARG(obs_hotkey_id, id), Q_ARG(bool, pressed));
  1678. }
  1679. void OBSBasic::CreateHotkeys()
  1680. {
  1681. ProfileScope("OBSBasic::CreateHotkeys");
  1682. auto LoadHotkeyData = [&](const char *name) -> OBSData
  1683. {
  1684. const char *info = config_get_string(basicConfig,
  1685. "Hotkeys", name);
  1686. if (!info)
  1687. return {};
  1688. obs_data_t *data = obs_data_create_from_json(info);
  1689. if (!data)
  1690. return {};
  1691. OBSData res = data;
  1692. obs_data_release(data);
  1693. return res;
  1694. };
  1695. auto LoadHotkey = [&](obs_hotkey_id id, const char *name)
  1696. {
  1697. obs_data_array_t *array =
  1698. obs_data_get_array(LoadHotkeyData(name), "bindings");
  1699. obs_hotkey_load(id, array);
  1700. obs_data_array_release(array);
  1701. };
  1702. auto LoadHotkeyPair = [&](obs_hotkey_pair_id id, const char *name0,
  1703. const char *name1)
  1704. {
  1705. obs_data_array_t *array0 =
  1706. obs_data_get_array(LoadHotkeyData(name0), "bindings");
  1707. obs_data_array_t *array1 =
  1708. obs_data_get_array(LoadHotkeyData(name1), "bindings");
  1709. obs_hotkey_pair_load(id, array0, array1);
  1710. obs_data_array_release(array0);
  1711. obs_data_array_release(array1);
  1712. };
  1713. #define MAKE_CALLBACK(pred, method, log_action) \
  1714. [](void *data, obs_hotkey_pair_id, obs_hotkey_t*, bool pressed) \
  1715. { \
  1716. OBSBasic &basic = *static_cast<OBSBasic*>(data); \
  1717. if ((pred) && pressed) { \
  1718. blog(LOG_INFO, log_action " due to hotkey"); \
  1719. method(); \
  1720. return true; \
  1721. } \
  1722. return false; \
  1723. }
  1724. streamingHotkeys = obs_hotkey_pair_register_frontend(
  1725. "OBSBasic.StartStreaming",
  1726. Str("Basic.Main.StartStreaming"),
  1727. "OBSBasic.StopStreaming",
  1728. Str("Basic.Main.StopStreaming"),
  1729. MAKE_CALLBACK(!basic.outputHandler->StreamingActive() &&
  1730. basic.ui->streamButton->isEnabled(),
  1731. basic.StartStreaming, "Starting stream"),
  1732. MAKE_CALLBACK(basic.outputHandler->StreamingActive() &&
  1733. basic.ui->streamButton->isEnabled(),
  1734. basic.StopStreaming, "Stopping stream"),
  1735. this, this);
  1736. LoadHotkeyPair(streamingHotkeys,
  1737. "OBSBasic.StartStreaming", "OBSBasic.StopStreaming");
  1738. auto cb = [] (void *data, obs_hotkey_id, obs_hotkey_t*, bool pressed)
  1739. {
  1740. OBSBasic &basic = *static_cast<OBSBasic*>(data);
  1741. if (basic.outputHandler->StreamingActive() && pressed) {
  1742. basic.ForceStopStreaming();
  1743. }
  1744. };
  1745. forceStreamingStopHotkey = obs_hotkey_register_frontend(
  1746. "OBSBasic.ForceStopStreaming",
  1747. Str("Basic.Main.ForceStopStreaming"),
  1748. cb, this);
  1749. LoadHotkey(forceStreamingStopHotkey,
  1750. "OBSBasic.ForceStopStreaming");
  1751. recordingHotkeys = obs_hotkey_pair_register_frontend(
  1752. "OBSBasic.StartRecording",
  1753. Str("Basic.Main.StartRecording"),
  1754. "OBSBasic.StopRecording",
  1755. Str("Basic.Main.StopRecording"),
  1756. MAKE_CALLBACK(!basic.outputHandler->RecordingActive() &&
  1757. !basic.ui->recordButton->isChecked(),
  1758. basic.StartRecording, "Starting recording"),
  1759. MAKE_CALLBACK(basic.outputHandler->RecordingActive() &&
  1760. basic.ui->recordButton->isChecked(),
  1761. basic.StopRecording, "Stopping recording"),
  1762. this, this);
  1763. LoadHotkeyPair(recordingHotkeys,
  1764. "OBSBasic.StartRecording", "OBSBasic.StopRecording");
  1765. replayBufHotkeys = obs_hotkey_pair_register_frontend(
  1766. "OBSBasic.StartReplayBuffer",
  1767. Str("Basic.Main.StartReplayBuffer"),
  1768. "OBSBasic.StopReplayBuffer",
  1769. Str("Basic.Main.StopReplayBuffer"),
  1770. MAKE_CALLBACK(!basic.outputHandler->ReplayBufferActive(),
  1771. basic.StartReplayBuffer, "Starting replay buffer"),
  1772. MAKE_CALLBACK(basic.outputHandler->ReplayBufferActive(),
  1773. basic.StopReplayBuffer, "Stopping replay buffer"),
  1774. this, this);
  1775. LoadHotkeyPair(replayBufHotkeys,
  1776. "OBSBasic.StartReplayBuffer", "OBSBasic.StopReplayBuffer");
  1777. #undef MAKE_CALLBACK
  1778. auto togglePreviewProgram = [] (void *data, obs_hotkey_id,
  1779. obs_hotkey_t*, bool pressed)
  1780. {
  1781. if (pressed)
  1782. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1783. "on_modeSwitch_clicked",
  1784. Qt::QueuedConnection);
  1785. };
  1786. togglePreviewProgramHotkey = obs_hotkey_register_frontend(
  1787. "OBSBasic.TogglePreviewProgram",
  1788. Str("Basic.TogglePreviewProgramMode"),
  1789. togglePreviewProgram, this);
  1790. LoadHotkey(togglePreviewProgramHotkey, "OBSBasic.TogglePreviewProgram");
  1791. auto transition = [] (void *data, obs_hotkey_id, obs_hotkey_t*,
  1792. bool pressed)
  1793. {
  1794. if (pressed)
  1795. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1796. "TransitionClicked",
  1797. Qt::QueuedConnection);
  1798. };
  1799. transitionHotkey = obs_hotkey_register_frontend(
  1800. "OBSBasic.Transition",
  1801. Str("Transition"), transition, this);
  1802. LoadHotkey(transitionHotkey, "OBSBasic.Transition");
  1803. }
  1804. void OBSBasic::ClearHotkeys()
  1805. {
  1806. obs_hotkey_pair_unregister(streamingHotkeys);
  1807. obs_hotkey_pair_unregister(recordingHotkeys);
  1808. obs_hotkey_pair_unregister(replayBufHotkeys);
  1809. obs_hotkey_unregister(forceStreamingStopHotkey);
  1810. obs_hotkey_unregister(togglePreviewProgramHotkey);
  1811. obs_hotkey_unregister(transitionHotkey);
  1812. }
  1813. OBSBasic::~OBSBasic()
  1814. {
  1815. if (updateCheckThread && updateCheckThread->isRunning())
  1816. updateCheckThread->wait();
  1817. delete multiviewProjectorMenu;
  1818. delete previewProjector;
  1819. delete studioProgramProjector;
  1820. delete previewProjectorSource;
  1821. delete previewProjectorMain;
  1822. delete sourceProjector;
  1823. delete sceneProjectorMenu;
  1824. delete scaleFilteringMenu;
  1825. delete colorMenu;
  1826. delete colorWidgetAction;
  1827. delete colorSelect;
  1828. delete deinterlaceMenu;
  1829. delete perSceneTransitionMenu;
  1830. delete shortcutFilter;
  1831. delete trayMenu;
  1832. delete programOptions;
  1833. delete program;
  1834. /* XXX: any obs data must be released before calling obs_shutdown.
  1835. * currently, we can't automate this with C++ RAII because of the
  1836. * delicate nature of obs_shutdown needing to be freed before the UI
  1837. * can be freed, and we have no control over the destruction order of
  1838. * the Qt UI stuff, so we have to manually clear any references to
  1839. * libobs. */
  1840. delete cpuUsageTimer;
  1841. os_cpu_usage_info_destroy(cpuUsageInfo);
  1842. obs_hotkey_set_callback_routing_func(nullptr, nullptr);
  1843. ClearHotkeys();
  1844. service = nullptr;
  1845. outputHandler.reset();
  1846. if (interaction)
  1847. delete interaction;
  1848. if (properties)
  1849. delete properties;
  1850. if (filters)
  1851. delete filters;
  1852. if (transformWindow)
  1853. delete transformWindow;
  1854. if (advAudioWindow)
  1855. delete advAudioWindow;
  1856. if (about)
  1857. delete about;
  1858. obs_display_remove_draw_callback(ui->preview->GetDisplay(),
  1859. OBSBasic::RenderMain, this);
  1860. obs_enter_graphics();
  1861. gs_vertexbuffer_destroy(box);
  1862. gs_vertexbuffer_destroy(boxLeft);
  1863. gs_vertexbuffer_destroy(boxTop);
  1864. gs_vertexbuffer_destroy(boxRight);
  1865. gs_vertexbuffer_destroy(boxBottom);
  1866. gs_vertexbuffer_destroy(circle);
  1867. obs_leave_graphics();
  1868. /* When shutting down, sometimes source references can get in to the
  1869. * event queue, and if we don't forcibly process those events they
  1870. * won't get processed until after obs_shutdown has been called. I
  1871. * really wish there were a more elegant way to deal with this via C++,
  1872. * but Qt doesn't use C++ in a normal way, so you can't really rely on
  1873. * normal C++ behavior for your data to be freed in the order that you
  1874. * expect or want it to. */
  1875. QApplication::sendPostedEvents(this);
  1876. config_set_int(App()->GlobalConfig(), "General", "LastVersion",
  1877. LIBOBS_API_VER);
  1878. #if OBS_RELEASE_CANDIDATE > 0
  1879. config_set_int(App()->GlobalConfig(), "General", "LastRCVersion",
  1880. OBS_RELEASE_CANDIDATE_VER);
  1881. #endif
  1882. bool alwaysOnTop = IsAlwaysOnTop(this);
  1883. config_set_bool(App()->GlobalConfig(), "BasicWindow", "PreviewEnabled",
  1884. previewEnabled);
  1885. config_set_bool(App()->GlobalConfig(), "BasicWindow", "AlwaysOnTop",
  1886. alwaysOnTop);
  1887. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1888. "SceneDuplicationMode", sceneDuplicationMode);
  1889. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1890. "SwapScenesMode", swapScenesMode);
  1891. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1892. "EditPropertiesMode", editPropertiesMode);
  1893. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1894. "PreviewProgramMode", IsPreviewProgramMode());
  1895. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1896. "DocksLocked", ui->lockUI->isChecked());
  1897. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  1898. #ifdef _WIN32
  1899. uint32_t winVer = GetWindowsVersion();
  1900. if (winVer > 0 && winVer < 0x602) {
  1901. bool disableAero = config_get_bool(basicConfig, "Video",
  1902. "DisableAero");
  1903. if (disableAero) {
  1904. SetAeroEnabled(true);
  1905. }
  1906. }
  1907. #endif
  1908. #ifdef BROWSER_AVAILABLE
  1909. DestroyPanelCookieManager();
  1910. delete cef;
  1911. cef = nullptr;
  1912. #endif
  1913. }
  1914. void OBSBasic::SaveProjectNow()
  1915. {
  1916. if (disableSaving)
  1917. return;
  1918. projectChanged = true;
  1919. SaveProjectDeferred();
  1920. }
  1921. void OBSBasic::SaveProject()
  1922. {
  1923. if (disableSaving)
  1924. return;
  1925. projectChanged = true;
  1926. QMetaObject::invokeMethod(this, "SaveProjectDeferred",
  1927. Qt::QueuedConnection);
  1928. }
  1929. void OBSBasic::SaveProjectDeferred()
  1930. {
  1931. if (disableSaving)
  1932. return;
  1933. if (!projectChanged)
  1934. return;
  1935. projectChanged = false;
  1936. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  1937. "Basic", "SceneCollectionFile");
  1938. char savePath[512];
  1939. char fileName[512];
  1940. int ret;
  1941. if (!sceneCollection)
  1942. return;
  1943. ret = snprintf(fileName, 512, "obs-studio/basic/scenes/%s.json",
  1944. sceneCollection);
  1945. if (ret <= 0)
  1946. return;
  1947. ret = GetConfigPath(savePath, sizeof(savePath), fileName);
  1948. if (ret <= 0)
  1949. return;
  1950. Save(savePath);
  1951. }
  1952. OBSSource OBSBasic::GetProgramSource()
  1953. {
  1954. return OBSGetStrongRef(programScene);
  1955. }
  1956. OBSScene OBSBasic::GetCurrentScene()
  1957. {
  1958. QListWidgetItem *item = ui->scenes->currentItem();
  1959. return item ? GetOBSRef<OBSScene>(item) : nullptr;
  1960. }
  1961. OBSSceneItem OBSBasic::GetSceneItem(QListWidgetItem *item)
  1962. {
  1963. return item ? GetOBSRef<OBSSceneItem>(item) : nullptr;
  1964. }
  1965. OBSSceneItem OBSBasic::GetCurrentSceneItem()
  1966. {
  1967. return ui->sources->Get(GetTopSelectedSourceItem());
  1968. }
  1969. void OBSBasic::UpdatePreviewScalingMenu()
  1970. {
  1971. bool fixedScaling = ui->preview->IsFixedScaling();
  1972. float scalingAmount = ui->preview->GetScalingAmount();
  1973. if (!fixedScaling) {
  1974. ui->actionScaleWindow->setChecked(true);
  1975. ui->actionScaleCanvas->setChecked(false);
  1976. ui->actionScaleOutput->setChecked(false);
  1977. return;
  1978. }
  1979. obs_video_info ovi;
  1980. obs_get_video_info(&ovi);
  1981. ui->actionScaleWindow->setChecked(false);
  1982. ui->actionScaleCanvas->setChecked(scalingAmount == 1.0f);
  1983. ui->actionScaleOutput->setChecked(
  1984. scalingAmount == float(ovi.output_width) / float(ovi.base_width));
  1985. }
  1986. void OBSBasic::CreateInteractionWindow(obs_source_t *source)
  1987. {
  1988. if (interaction)
  1989. interaction->close();
  1990. interaction = new OBSBasicInteraction(this, source);
  1991. interaction->Init();
  1992. interaction->setAttribute(Qt::WA_DeleteOnClose, true);
  1993. }
  1994. void OBSBasic::CreatePropertiesWindow(obs_source_t *source)
  1995. {
  1996. if (properties)
  1997. properties->close();
  1998. properties = new OBSBasicProperties(this, source);
  1999. properties->Init();
  2000. properties->setAttribute(Qt::WA_DeleteOnClose, true);
  2001. }
  2002. void OBSBasic::CreateFiltersWindow(obs_source_t *source)
  2003. {
  2004. if (filters)
  2005. filters->close();
  2006. filters = new OBSBasicFilters(this, source);
  2007. filters->Init();
  2008. filters->setAttribute(Qt::WA_DeleteOnClose, true);
  2009. }
  2010. /* Qt callbacks for invokeMethod */
  2011. void OBSBasic::AddScene(OBSSource source)
  2012. {
  2013. const char *name = obs_source_get_name(source);
  2014. obs_scene_t *scene = obs_scene_from_source(source);
  2015. QListWidgetItem *item = new QListWidgetItem(QT_UTF8(name));
  2016. SetOBSRef(item, OBSScene(scene));
  2017. ui->scenes->addItem(item);
  2018. obs_hotkey_register_source(source, "OBSBasic.SelectScene",
  2019. Str("Basic.Hotkeys.SelectScene"),
  2020. [](void *data,
  2021. obs_hotkey_id, obs_hotkey_t*, bool pressed)
  2022. {
  2023. OBSBasic *main =
  2024. reinterpret_cast<OBSBasic*>(App()->GetMainWindow());
  2025. auto potential_source = static_cast<obs_source_t*>(data);
  2026. auto source = obs_source_get_ref(potential_source);
  2027. if (source && pressed)
  2028. main->SetCurrentScene(source);
  2029. obs_source_release(source);
  2030. }, static_cast<obs_source_t*>(source));
  2031. signal_handler_t *handler = obs_source_get_signal_handler(source);
  2032. SignalContainer<OBSScene> container;
  2033. container.ref = scene;
  2034. container.handlers.assign({
  2035. std::make_shared<OBSSignal>(handler, "item_add",
  2036. OBSBasic::SceneItemAdded, this),
  2037. std::make_shared<OBSSignal>(handler, "item_select",
  2038. OBSBasic::SceneItemSelected, this),
  2039. std::make_shared<OBSSignal>(handler, "item_deselect",
  2040. OBSBasic::SceneItemDeselected, this),
  2041. std::make_shared<OBSSignal>(handler, "reorder",
  2042. OBSBasic::SceneReordered, this),
  2043. });
  2044. item->setData(static_cast<int>(QtDataRole::OBSSignals),
  2045. QVariant::fromValue(container));
  2046. /* if the scene already has items (a duplicated scene) add them */
  2047. auto addSceneItem = [this] (obs_sceneitem_t *item)
  2048. {
  2049. AddSceneItem(item);
  2050. };
  2051. using addSceneItem_t = decltype(addSceneItem);
  2052. obs_scene_enum_items(scene,
  2053. [] (obs_scene_t*, obs_sceneitem_t *item, void *param)
  2054. {
  2055. addSceneItem_t *func;
  2056. func = reinterpret_cast<addSceneItem_t*>(param);
  2057. (*func)(item);
  2058. return true;
  2059. }, &addSceneItem);
  2060. SaveProject();
  2061. if (!disableSaving) {
  2062. obs_source_t *source = obs_scene_get_source(scene);
  2063. blog(LOG_INFO, "User added scene '%s'",
  2064. obs_source_get_name(source));
  2065. OBSProjector::UpdateMultiviewProjectors();
  2066. }
  2067. if (api)
  2068. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  2069. }
  2070. void OBSBasic::RemoveScene(OBSSource source)
  2071. {
  2072. obs_scene_t *scene = obs_scene_from_source(source);
  2073. QListWidgetItem *sel = nullptr;
  2074. int count = ui->scenes->count();
  2075. for (int i = 0; i < count; i++) {
  2076. auto item = ui->scenes->item(i);
  2077. auto cur_scene = GetOBSRef<OBSScene>(item);
  2078. if (cur_scene != scene)
  2079. continue;
  2080. sel = item;
  2081. break;
  2082. }
  2083. if (sel != nullptr) {
  2084. if (sel == ui->scenes->currentItem())
  2085. ui->sources->Clear();
  2086. delete sel;
  2087. }
  2088. SaveProject();
  2089. if (!disableSaving) {
  2090. blog(LOG_INFO, "User Removed scene '%s'",
  2091. obs_source_get_name(source));
  2092. OBSProjector::UpdateMultiviewProjectors();
  2093. }
  2094. if (api)
  2095. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  2096. }
  2097. static bool select_one(obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  2098. {
  2099. obs_sceneitem_t *selectedItem =
  2100. reinterpret_cast<obs_sceneitem_t*>(param);
  2101. if (obs_sceneitem_is_group(item))
  2102. obs_sceneitem_group_enum_items(item, select_one, param);
  2103. obs_sceneitem_select(item, (selectedItem == item));
  2104. UNUSED_PARAMETER(scene);
  2105. return true;
  2106. }
  2107. void OBSBasic::AddSceneItem(OBSSceneItem item)
  2108. {
  2109. obs_scene_t *scene = obs_sceneitem_get_scene(item);
  2110. if (GetCurrentScene() == scene)
  2111. ui->sources->Add(item);
  2112. SaveProject();
  2113. if (!disableSaving) {
  2114. obs_source_t *sceneSource = obs_scene_get_source(scene);
  2115. obs_source_t *itemSource = obs_sceneitem_get_source(item);
  2116. blog(LOG_INFO, "User added source '%s' (%s) to scene '%s'",
  2117. obs_source_get_name(itemSource),
  2118. obs_source_get_id(itemSource),
  2119. obs_source_get_name(sceneSource));
  2120. obs_scene_enum_items(scene, select_one, (obs_sceneitem_t*)item);
  2121. }
  2122. }
  2123. void OBSBasic::UpdateSceneSelection(OBSSource source)
  2124. {
  2125. if (source) {
  2126. obs_scene_t *scene = obs_scene_from_source(source);
  2127. const char *name = obs_source_get_name(source);
  2128. if (!scene)
  2129. return;
  2130. QList<QListWidgetItem*> items =
  2131. ui->scenes->findItems(QT_UTF8(name), Qt::MatchExactly);
  2132. if (items.count()) {
  2133. sceneChanging = true;
  2134. ui->scenes->setCurrentItem(items.first());
  2135. sceneChanging = false;
  2136. OBSScene curScene =
  2137. GetOBSRef<OBSScene>(ui->scenes->currentItem());
  2138. if (api && scene != curScene)
  2139. api->on_event(OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED);
  2140. }
  2141. }
  2142. }
  2143. static void RenameListValues(QListWidget *listWidget, const QString &newName,
  2144. const QString &prevName)
  2145. {
  2146. QList<QListWidgetItem*> items =
  2147. listWidget->findItems(prevName, Qt::MatchExactly);
  2148. for (int i = 0; i < items.count(); i++)
  2149. items[i]->setText(newName);
  2150. }
  2151. void OBSBasic::RenameSources(OBSSource source, QString newName,
  2152. QString prevName)
  2153. {
  2154. RenameListValues(ui->scenes, newName, prevName);
  2155. for (size_t i = 0; i < volumes.size(); i++) {
  2156. if (volumes[i]->GetName().compare(prevName) == 0)
  2157. volumes[i]->SetName(newName);
  2158. }
  2159. OBSProjector::RenameProjector(prevName, newName);
  2160. SaveProject();
  2161. obs_scene_t *scene = obs_scene_from_source(source);
  2162. if (scene)
  2163. OBSProjector::UpdateMultiviewProjectors();
  2164. }
  2165. void OBSBasic::SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select)
  2166. {
  2167. SignalBlocker sourcesSignalBlocker(ui->sources);
  2168. if (scene != GetCurrentScene() || ignoreSelectionUpdate)
  2169. return;
  2170. ui->sources->SelectItem(item, select);
  2171. }
  2172. static inline bool SourceMixerHidden(obs_source_t *source)
  2173. {
  2174. obs_data_t *priv_settings = obs_source_get_private_settings(source);
  2175. bool hidden = obs_data_get_bool(priv_settings, "mixer_hidden");
  2176. obs_data_release(priv_settings);
  2177. return hidden;
  2178. }
  2179. static inline void SetSourceMixerHidden(obs_source_t *source, bool hidden)
  2180. {
  2181. obs_data_t *priv_settings = obs_source_get_private_settings(source);
  2182. obs_data_set_bool(priv_settings, "mixer_hidden", hidden);
  2183. obs_data_release(priv_settings);
  2184. }
  2185. void OBSBasic::GetAudioSourceFilters()
  2186. {
  2187. QAction *action = reinterpret_cast<QAction*>(sender());
  2188. VolControl *vol = action->property("volControl").value<VolControl*>();
  2189. obs_source_t *source = vol->GetSource();
  2190. CreateFiltersWindow(source);
  2191. }
  2192. void OBSBasic::GetAudioSourceProperties()
  2193. {
  2194. QAction *action = reinterpret_cast<QAction*>(sender());
  2195. VolControl *vol = action->property("volControl").value<VolControl*>();
  2196. obs_source_t *source = vol->GetSource();
  2197. CreatePropertiesWindow(source);
  2198. }
  2199. void OBSBasic::HideAudioControl()
  2200. {
  2201. QAction *action = reinterpret_cast<QAction*>(sender());
  2202. VolControl *vol = action->property("volControl").value<VolControl*>();
  2203. obs_source_t *source = vol->GetSource();
  2204. if (!SourceMixerHidden(source)) {
  2205. SetSourceMixerHidden(source, true);
  2206. DeactivateAudioSource(source);
  2207. }
  2208. }
  2209. void OBSBasic::UnhideAllAudioControls()
  2210. {
  2211. auto UnhideAudioMixer = [this] (obs_source_t *source) /* -- */
  2212. {
  2213. if (!obs_source_active(source))
  2214. return true;
  2215. if (!SourceMixerHidden(source))
  2216. return true;
  2217. SetSourceMixerHidden(source, false);
  2218. ActivateAudioSource(source);
  2219. return true;
  2220. };
  2221. using UnhideAudioMixer_t = decltype(UnhideAudioMixer);
  2222. auto PreEnum = [] (void *data, obs_source_t *source) -> bool /* -- */
  2223. {
  2224. return (*reinterpret_cast<UnhideAudioMixer_t *>(data))(source);
  2225. };
  2226. obs_enum_sources(PreEnum, &UnhideAudioMixer);
  2227. }
  2228. void OBSBasic::ToggleHideMixer()
  2229. {
  2230. OBSSceneItem item = GetCurrentSceneItem();
  2231. OBSSource source = obs_sceneitem_get_source(item);
  2232. if (!SourceMixerHidden(source)) {
  2233. SetSourceMixerHidden(source, true);
  2234. DeactivateAudioSource(source);
  2235. } else {
  2236. SetSourceMixerHidden(source, false);
  2237. ActivateAudioSource(source);
  2238. }
  2239. }
  2240. void OBSBasic::MixerRenameSource()
  2241. {
  2242. QAction *action = reinterpret_cast<QAction*>(sender());
  2243. VolControl *vol = action->property("volControl").value<VolControl*>();
  2244. OBSSource source = vol->GetSource();
  2245. const char *prevName = obs_source_get_name(source);
  2246. for (;;) {
  2247. string name;
  2248. bool accepted = NameDialog::AskForName(this,
  2249. QTStr("Basic.Main.MixerRename.Title"),
  2250. QTStr("Basic.Main.MixerRename.Text"),
  2251. name,
  2252. QT_UTF8(prevName));
  2253. if (!accepted)
  2254. return;
  2255. if (name.empty()) {
  2256. OBSMessageBox::information(this,
  2257. QTStr("NoNameEntered.Title"),
  2258. QTStr("NoNameEntered.Text"));
  2259. continue;
  2260. }
  2261. OBSSource sourceTest = obs_get_source_by_name(name.c_str());
  2262. obs_source_release(sourceTest);
  2263. if (sourceTest) {
  2264. OBSMessageBox::information(this,
  2265. QTStr("NameExists.Title"),
  2266. QTStr("NameExists.Text"));
  2267. continue;
  2268. }
  2269. obs_source_set_name(source, name.c_str());
  2270. break;
  2271. }
  2272. }
  2273. void OBSBasic::VolControlContextMenu()
  2274. {
  2275. VolControl *vol = reinterpret_cast<VolControl*>(sender());
  2276. /* ------------------- */
  2277. QAction hideAction(QTStr("Hide"), this);
  2278. QAction unhideAllAction(QTStr("UnhideAll"), this);
  2279. QAction mixerRenameAction(QTStr("Rename"), this);
  2280. QAction copyFiltersAction(QTStr("Copy.Filters"), this);
  2281. QAction pasteFiltersAction(QTStr("Paste.Filters"), this);
  2282. QAction filtersAction(QTStr("Filters"), this);
  2283. QAction propertiesAction(QTStr("Properties"), this);
  2284. QAction advPropAction(QTStr("Basic.MainMenu.Edit.AdvAudio"), this);
  2285. QAction toggleControlLayoutAction(QTStr("VerticalLayout"), this);
  2286. toggleControlLayoutAction.setCheckable(true);
  2287. toggleControlLayoutAction.setChecked(config_get_bool(GetGlobalConfig(),
  2288. "BasicWindow", "VerticalVolControl"));
  2289. /* ------------------- */
  2290. connect(&hideAction, &QAction::triggered,
  2291. this, &OBSBasic::HideAudioControl,
  2292. Qt::DirectConnection);
  2293. connect(&unhideAllAction, &QAction::triggered,
  2294. this, &OBSBasic::UnhideAllAudioControls,
  2295. Qt::DirectConnection);
  2296. connect(&mixerRenameAction, &QAction::triggered,
  2297. this, &OBSBasic::MixerRenameSource,
  2298. Qt::DirectConnection);
  2299. connect(&copyFiltersAction, &QAction::triggered,
  2300. this, &OBSBasic::AudioMixerCopyFilters,
  2301. Qt::DirectConnection);
  2302. connect(&pasteFiltersAction, &QAction::triggered,
  2303. this, &OBSBasic::AudioMixerPasteFilters,
  2304. Qt::DirectConnection);
  2305. connect(&filtersAction, &QAction::triggered,
  2306. this, &OBSBasic::GetAudioSourceFilters,
  2307. Qt::DirectConnection);
  2308. connect(&propertiesAction, &QAction::triggered,
  2309. this, &OBSBasic::GetAudioSourceProperties,
  2310. Qt::DirectConnection);
  2311. connect(&advPropAction, &QAction::triggered,
  2312. this, &OBSBasic::on_actionAdvAudioProperties_triggered,
  2313. Qt::DirectConnection);
  2314. /* ------------------- */
  2315. connect(&toggleControlLayoutAction, &QAction::changed, this,
  2316. &OBSBasic::ToggleVolControlLayout,
  2317. Qt::DirectConnection);
  2318. /* ------------------- */
  2319. hideAction.setProperty("volControl",
  2320. QVariant::fromValue<VolControl*>(vol));
  2321. mixerRenameAction.setProperty("volControl",
  2322. QVariant::fromValue<VolControl*>(vol));
  2323. copyFiltersAction.setProperty("volControl",
  2324. QVariant::fromValue<VolControl*>(vol));
  2325. pasteFiltersAction.setProperty("volControl",
  2326. QVariant::fromValue<VolControl*>(vol));
  2327. filtersAction.setProperty("volControl",
  2328. QVariant::fromValue<VolControl*>(vol));
  2329. propertiesAction.setProperty("volControl",
  2330. QVariant::fromValue<VolControl*>(vol));
  2331. /* ------------------- */
  2332. if (copyFiltersString == nullptr)
  2333. pasteFiltersAction.setEnabled(false);
  2334. else
  2335. pasteFiltersAction.setEnabled(true);
  2336. QMenu popup;
  2337. popup.addAction(&unhideAllAction);
  2338. popup.addAction(&hideAction);
  2339. popup.addAction(&mixerRenameAction);
  2340. popup.addSeparator();
  2341. popup.addAction(&copyFiltersAction);
  2342. popup.addAction(&pasteFiltersAction);
  2343. popup.addSeparator();
  2344. popup.addAction(&toggleControlLayoutAction);
  2345. popup.addSeparator();
  2346. popup.addAction(&filtersAction);
  2347. popup.addAction(&propertiesAction);
  2348. popup.addAction(&advPropAction);
  2349. popup.exec(QCursor::pos());
  2350. }
  2351. void OBSBasic::on_hMixerScrollArea_customContextMenuRequested()
  2352. {
  2353. StackedMixerAreaContextMenuRequested();
  2354. }
  2355. void OBSBasic::on_vMixerScrollArea_customContextMenuRequested()
  2356. {
  2357. StackedMixerAreaContextMenuRequested();
  2358. }
  2359. void OBSBasic::StackedMixerAreaContextMenuRequested()
  2360. {
  2361. QAction unhideAllAction(QTStr("UnhideAll"), this);
  2362. QAction advPropAction(QTStr("Basic.MainMenu.Edit.AdvAudio"), this);
  2363. QAction toggleControlLayoutAction(QTStr("VerticalLayout"), this);
  2364. toggleControlLayoutAction.setCheckable(true);
  2365. toggleControlLayoutAction.setChecked(config_get_bool(GetGlobalConfig(),
  2366. "BasicWindow", "VerticalVolControl"));
  2367. /* ------------------- */
  2368. connect(&unhideAllAction, &QAction::triggered,
  2369. this, &OBSBasic::UnhideAllAudioControls,
  2370. Qt::DirectConnection);
  2371. connect(&advPropAction, &QAction::triggered,
  2372. this, &OBSBasic::on_actionAdvAudioProperties_triggered,
  2373. Qt::DirectConnection);
  2374. /* ------------------- */
  2375. connect(&toggleControlLayoutAction, &QAction::changed, this,
  2376. &OBSBasic::ToggleVolControlLayout,
  2377. Qt::DirectConnection);
  2378. /* ------------------- */
  2379. QMenu popup;
  2380. popup.addAction(&unhideAllAction);
  2381. popup.addSeparator();
  2382. popup.addAction(&toggleControlLayoutAction);
  2383. popup.addSeparator();
  2384. popup.addAction(&advPropAction);
  2385. popup.exec(QCursor::pos());
  2386. }
  2387. void OBSBasic::ToggleMixerLayout(bool vertical)
  2388. {
  2389. if (vertical) {
  2390. ui->stackedMixerArea->setMinimumSize(180, 220);
  2391. ui->stackedMixerArea->setCurrentIndex(1);
  2392. } else {
  2393. ui->stackedMixerArea->setMinimumSize(220, 0);
  2394. ui->stackedMixerArea->setCurrentIndex(0);
  2395. }
  2396. }
  2397. void OBSBasic::ToggleVolControlLayout()
  2398. {
  2399. bool vertical = !config_get_bool(GetGlobalConfig(), "BasicWindow",
  2400. "VerticalVolControl");
  2401. config_set_bool(GetGlobalConfig(), "BasicWindow", "VerticalVolControl",
  2402. vertical);
  2403. ToggleMixerLayout(vertical);
  2404. // We need to store it so we can delete current and then add
  2405. // at the right order
  2406. vector<OBSSource> sources;
  2407. for (size_t i = 0; i != volumes.size(); i++)
  2408. sources.emplace_back(volumes[i]->GetSource());
  2409. ClearVolumeControls();
  2410. for (const auto &source : sources)
  2411. ActivateAudioSource(source);
  2412. }
  2413. void OBSBasic::ActivateAudioSource(OBSSource source)
  2414. {
  2415. if (SourceMixerHidden(source))
  2416. return;
  2417. bool vertical = config_get_bool(GetGlobalConfig(), "BasicWindow",
  2418. "VerticalVolControl");
  2419. VolControl *vol = new VolControl(source, true, vertical);
  2420. double meterDecayRate = config_get_double(basicConfig, "Audio",
  2421. "MeterDecayRate");
  2422. vol->SetMeterDecayRate(meterDecayRate);
  2423. uint32_t peakMeterTypeIdx = config_get_uint(basicConfig, "Audio",
  2424. "PeakMeterType");
  2425. enum obs_peak_meter_type peakMeterType;
  2426. switch (peakMeterTypeIdx) {
  2427. case 0:
  2428. peakMeterType = SAMPLE_PEAK_METER;
  2429. break;
  2430. case 1:
  2431. peakMeterType = TRUE_PEAK_METER;
  2432. break;
  2433. default:
  2434. peakMeterType = SAMPLE_PEAK_METER;
  2435. break;
  2436. }
  2437. vol->setPeakMeterType(peakMeterType);
  2438. vol->setContextMenuPolicy(Qt::CustomContextMenu);
  2439. connect(vol, &QWidget::customContextMenuRequested,
  2440. this, &OBSBasic::VolControlContextMenu);
  2441. connect(vol, &VolControl::ConfigClicked,
  2442. this, &OBSBasic::VolControlContextMenu);
  2443. InsertQObjectByName(volumes, vol);
  2444. for (auto volume : volumes) {
  2445. if (vertical)
  2446. ui->vVolControlLayout->addWidget(volume);
  2447. else
  2448. ui->hVolControlLayout->addWidget(volume);
  2449. }
  2450. }
  2451. void OBSBasic::DeactivateAudioSource(OBSSource source)
  2452. {
  2453. for (size_t i = 0; i < volumes.size(); i++) {
  2454. if (volumes[i]->GetSource() == source) {
  2455. delete volumes[i];
  2456. volumes.erase(volumes.begin() + i);
  2457. break;
  2458. }
  2459. }
  2460. }
  2461. bool OBSBasic::QueryRemoveSource(obs_source_t *source)
  2462. {
  2463. if (obs_source_get_type(source) == OBS_SOURCE_TYPE_SCENE &&
  2464. !obs_source_is_group(source)) {
  2465. int count = ui->scenes->count();
  2466. if (count == 1) {
  2467. OBSMessageBox::information(this,
  2468. QTStr("FinalScene.Title"),
  2469. QTStr("FinalScene.Text"));
  2470. return false;
  2471. }
  2472. }
  2473. const char *name = obs_source_get_name(source);
  2474. QString text = QTStr("ConfirmRemove.Text");
  2475. text.replace("$1", QT_UTF8(name));
  2476. QMessageBox remove_source(this);
  2477. remove_source.setText(text);
  2478. QAbstractButton *Yes = remove_source.addButton(QTStr("Yes"),
  2479. QMessageBox::YesRole);
  2480. remove_source.addButton(QTStr("No"), QMessageBox::NoRole);
  2481. remove_source.setIcon(QMessageBox::Question);
  2482. remove_source.setWindowTitle(QTStr("ConfirmRemove.Title"));
  2483. remove_source.exec();
  2484. return Yes == remove_source.clickedButton();
  2485. }
  2486. #define UPDATE_CHECK_INTERVAL (60*60*24*4) /* 4 days */
  2487. #ifdef UPDATE_SPARKLE
  2488. void init_sparkle_updater(bool update_to_undeployed);
  2489. void trigger_sparkle_update();
  2490. #endif
  2491. void OBSBasic::TimedCheckForUpdates()
  2492. {
  2493. if (!config_get_bool(App()->GlobalConfig(), "General",
  2494. "EnableAutoUpdates"))
  2495. return;
  2496. #ifdef UPDATE_SPARKLE
  2497. init_sparkle_updater(config_get_bool(App()->GlobalConfig(), "General",
  2498. "UpdateToUndeployed"));
  2499. #elif _WIN32
  2500. long long lastUpdate = config_get_int(App()->GlobalConfig(), "General",
  2501. "LastUpdateCheck");
  2502. uint32_t lastVersion = config_get_int(App()->GlobalConfig(), "General",
  2503. "LastVersion");
  2504. if (lastVersion < LIBOBS_API_VER) {
  2505. lastUpdate = 0;
  2506. config_set_int(App()->GlobalConfig(), "General",
  2507. "LastUpdateCheck", 0);
  2508. }
  2509. long long t = (long long)time(nullptr);
  2510. long long secs = t - lastUpdate;
  2511. if (secs > UPDATE_CHECK_INTERVAL)
  2512. CheckForUpdates(false);
  2513. #endif
  2514. }
  2515. void OBSBasic::CheckForUpdates(bool manualUpdate)
  2516. {
  2517. #ifdef UPDATE_SPARKLE
  2518. trigger_sparkle_update();
  2519. #elif _WIN32
  2520. ui->actionCheckForUpdates->setEnabled(false);
  2521. if (updateCheckThread && updateCheckThread->isRunning())
  2522. return;
  2523. updateCheckThread.reset(new AutoUpdateThread(manualUpdate));
  2524. updateCheckThread->start();
  2525. #endif
  2526. UNUSED_PARAMETER(manualUpdate);
  2527. }
  2528. void OBSBasic::updateCheckFinished()
  2529. {
  2530. ui->actionCheckForUpdates->setEnabled(true);
  2531. }
  2532. void OBSBasic::DuplicateSelectedScene()
  2533. {
  2534. OBSScene curScene = GetCurrentScene();
  2535. if (!curScene)
  2536. return;
  2537. OBSSource curSceneSource = obs_scene_get_source(curScene);
  2538. QString format{obs_source_get_name(curSceneSource)};
  2539. format += " %1";
  2540. int i = 2;
  2541. QString placeHolderText = format.arg(i);
  2542. obs_source_t *source = nullptr;
  2543. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  2544. obs_source_release(source);
  2545. placeHolderText = format.arg(++i);
  2546. }
  2547. for (;;) {
  2548. string name;
  2549. bool accepted = NameDialog::AskForName(this,
  2550. QTStr("Basic.Main.AddSceneDlg.Title"),
  2551. QTStr("Basic.Main.AddSceneDlg.Text"),
  2552. name,
  2553. placeHolderText);
  2554. if (!accepted)
  2555. return;
  2556. if (name.empty()) {
  2557. OBSMessageBox::information(this,
  2558. QTStr("NoNameEntered.Title"),
  2559. QTStr("NoNameEntered.Text"));
  2560. continue;
  2561. }
  2562. obs_source_t *source = obs_get_source_by_name(name.c_str());
  2563. if (source) {
  2564. OBSMessageBox::information(this,
  2565. QTStr("NameExists.Title"),
  2566. QTStr("NameExists.Text"));
  2567. obs_source_release(source);
  2568. continue;
  2569. }
  2570. obs_scene_t *scene = obs_scene_duplicate(curScene,
  2571. name.c_str(), OBS_SCENE_DUP_REFS);
  2572. source = obs_scene_get_source(scene);
  2573. SetCurrentScene(source, true);
  2574. obs_scene_release(scene);
  2575. break;
  2576. }
  2577. }
  2578. void OBSBasic::RemoveSelectedScene()
  2579. {
  2580. OBSScene scene = GetCurrentScene();
  2581. if (scene) {
  2582. obs_source_t *source = obs_scene_get_source(scene);
  2583. if (QueryRemoveSource(source)) {
  2584. obs_source_remove(source);
  2585. if (api)
  2586. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  2587. }
  2588. }
  2589. }
  2590. void OBSBasic::RemoveSelectedSceneItem()
  2591. {
  2592. OBSSceneItem item = GetCurrentSceneItem();
  2593. if (item) {
  2594. obs_source_t *source = obs_sceneitem_get_source(item);
  2595. if (QueryRemoveSource(source))
  2596. obs_sceneitem_remove(item);
  2597. }
  2598. }
  2599. void OBSBasic::ReorderSources(OBSScene scene)
  2600. {
  2601. if (scene != GetCurrentScene() || ui->sources->IgnoreReorder())
  2602. return;
  2603. ui->sources->ReorderItems();
  2604. SaveProject();
  2605. }
  2606. /* OBS Callbacks */
  2607. void OBSBasic::SceneReordered(void *data, calldata_t *params)
  2608. {
  2609. OBSBasic *window = static_cast<OBSBasic*>(data);
  2610. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  2611. QMetaObject::invokeMethod(window, "ReorderSources",
  2612. Q_ARG(OBSScene, OBSScene(scene)));
  2613. }
  2614. void OBSBasic::SceneItemAdded(void *data, calldata_t *params)
  2615. {
  2616. OBSBasic *window = static_cast<OBSBasic*>(data);
  2617. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2618. QMetaObject::invokeMethod(window, "AddSceneItem",
  2619. Q_ARG(OBSSceneItem, OBSSceneItem(item)));
  2620. }
  2621. void OBSBasic::SceneItemSelected(void *data, calldata_t *params)
  2622. {
  2623. OBSBasic *window = static_cast<OBSBasic*>(data);
  2624. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  2625. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2626. QMetaObject::invokeMethod(window, "SelectSceneItem",
  2627. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  2628. Q_ARG(bool, true));
  2629. }
  2630. void OBSBasic::SceneItemDeselected(void *data, calldata_t *params)
  2631. {
  2632. OBSBasic *window = static_cast<OBSBasic*>(data);
  2633. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  2634. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2635. QMetaObject::invokeMethod(window, "SelectSceneItem",
  2636. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  2637. Q_ARG(bool, false));
  2638. }
  2639. void OBSBasic::SourceCreated(void *data, calldata_t *params)
  2640. {
  2641. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2642. if (obs_scene_from_source(source) != NULL)
  2643. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2644. "AddScene", WaitConnection(),
  2645. Q_ARG(OBSSource, OBSSource(source)));
  2646. }
  2647. void OBSBasic::SourceRemoved(void *data, calldata_t *params)
  2648. {
  2649. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2650. if (obs_scene_from_source(source) != NULL)
  2651. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2652. "RemoveScene",
  2653. Q_ARG(OBSSource, OBSSource(source)));
  2654. }
  2655. void OBSBasic::SourceActivated(void *data, calldata_t *params)
  2656. {
  2657. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2658. uint32_t flags = obs_source_get_output_flags(source);
  2659. if (flags & OBS_SOURCE_AUDIO)
  2660. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2661. "ActivateAudioSource",
  2662. Q_ARG(OBSSource, OBSSource(source)));
  2663. }
  2664. void OBSBasic::SourceDeactivated(void *data, calldata_t *params)
  2665. {
  2666. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2667. uint32_t flags = obs_source_get_output_flags(source);
  2668. if (flags & OBS_SOURCE_AUDIO)
  2669. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2670. "DeactivateAudioSource",
  2671. Q_ARG(OBSSource, OBSSource(source)));
  2672. }
  2673. void OBSBasic::SourceRenamed(void *data, calldata_t *params)
  2674. {
  2675. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2676. const char *newName = calldata_string(params, "new_name");
  2677. const char *prevName = calldata_string(params, "prev_name");
  2678. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2679. "RenameSources",
  2680. Q_ARG(OBSSource, source),
  2681. Q_ARG(QString, QT_UTF8(newName)),
  2682. Q_ARG(QString, QT_UTF8(prevName)));
  2683. blog(LOG_INFO, "Source '%s' renamed to '%s'", prevName, newName);
  2684. }
  2685. void OBSBasic::DrawBackdrop(float cx, float cy)
  2686. {
  2687. if (!box)
  2688. return;
  2689. GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_DEFAULT, "DrawBackdrop");
  2690. gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID);
  2691. gs_eparam_t *color = gs_effect_get_param_by_name(solid, "color");
  2692. gs_technique_t *tech = gs_effect_get_technique(solid, "Solid");
  2693. vec4 colorVal;
  2694. vec4_set(&colorVal, 0.0f, 0.0f, 0.0f, 1.0f);
  2695. gs_effect_set_vec4(color, &colorVal);
  2696. gs_technique_begin(tech);
  2697. gs_technique_begin_pass(tech, 0);
  2698. gs_matrix_push();
  2699. gs_matrix_identity();
  2700. gs_matrix_scale3f(float(cx), float(cy), 1.0f);
  2701. gs_load_vertexbuffer(box);
  2702. gs_draw(GS_TRISTRIP, 0, 0);
  2703. gs_matrix_pop();
  2704. gs_technique_end_pass(tech);
  2705. gs_technique_end(tech);
  2706. gs_load_vertexbuffer(nullptr);
  2707. GS_DEBUG_MARKER_END();
  2708. }
  2709. void OBSBasic::RenderMain(void *data, uint32_t cx, uint32_t cy)
  2710. {
  2711. GS_DEBUG_MARKER_BEGIN(GS_DEBUG_COLOR_DEFAULT, "RenderMain");
  2712. OBSBasic *window = static_cast<OBSBasic*>(data);
  2713. obs_video_info ovi;
  2714. obs_get_video_info(&ovi);
  2715. window->previewCX = int(window->previewScale * float(ovi.base_width));
  2716. window->previewCY = int(window->previewScale * float(ovi.base_height));
  2717. gs_viewport_push();
  2718. gs_projection_push();
  2719. QSize previewSize = GetPixelSize(window->ui->preview);
  2720. float right = float(previewSize.width()) - window->previewX;
  2721. float bottom = float(previewSize.height()) - window->previewY;
  2722. gs_ortho(-window->previewX, right,
  2723. -window->previewY, bottom,
  2724. -100.0f, 100.0f);
  2725. window->ui->preview->DrawOverflow();
  2726. /* --------------------------------------- */
  2727. gs_ortho(0.0f, float(ovi.base_width), 0.0f, float(ovi.base_height),
  2728. -100.0f, 100.0f);
  2729. gs_set_viewport(window->previewX, window->previewY,
  2730. window->previewCX, window->previewCY);
  2731. window->DrawBackdrop(float(ovi.base_width), float(ovi.base_height));
  2732. if (window->IsPreviewProgramMode()) {
  2733. OBSScene scene = window->GetCurrentScene();
  2734. obs_source_t *source = obs_scene_get_source(scene);
  2735. if (source)
  2736. obs_source_video_render(source);
  2737. } else {
  2738. obs_render_main_texture();
  2739. }
  2740. gs_load_vertexbuffer(nullptr);
  2741. /* --------------------------------------- */
  2742. gs_ortho(-window->previewX, right,
  2743. -window->previewY, bottom,
  2744. -100.0f, 100.0f);
  2745. gs_reset_viewport();
  2746. window->ui->preview->DrawSceneEditing();
  2747. /* --------------------------------------- */
  2748. gs_projection_pop();
  2749. gs_viewport_pop();
  2750. GS_DEBUG_MARKER_END();
  2751. UNUSED_PARAMETER(cx);
  2752. UNUSED_PARAMETER(cy);
  2753. }
  2754. /* Main class functions */
  2755. obs_service_t *OBSBasic::GetService()
  2756. {
  2757. if (!service) {
  2758. service = obs_service_create("rtmp_common", NULL, NULL,
  2759. nullptr);
  2760. obs_service_release(service);
  2761. }
  2762. return service;
  2763. }
  2764. void OBSBasic::SetService(obs_service_t *newService)
  2765. {
  2766. if (newService)
  2767. service = newService;
  2768. }
  2769. bool OBSBasic::StreamingActive() const
  2770. {
  2771. if (!outputHandler)
  2772. return false;
  2773. return outputHandler->StreamingActive();
  2774. }
  2775. bool OBSBasic::Active() const
  2776. {
  2777. if (!outputHandler)
  2778. return false;
  2779. return outputHandler->Active();
  2780. }
  2781. #ifdef _WIN32
  2782. #define IS_WIN32 1
  2783. #else
  2784. #define IS_WIN32 0
  2785. #endif
  2786. static inline int AttemptToResetVideo(struct obs_video_info *ovi)
  2787. {
  2788. return obs_reset_video(ovi);
  2789. }
  2790. static inline enum obs_scale_type GetScaleType(ConfigFile &basicConfig)
  2791. {
  2792. const char *scaleTypeStr = config_get_string(basicConfig,
  2793. "Video", "ScaleType");
  2794. if (astrcmpi(scaleTypeStr, "bilinear") == 0)
  2795. return OBS_SCALE_BILINEAR;
  2796. else if (astrcmpi(scaleTypeStr, "lanczos") == 0)
  2797. return OBS_SCALE_LANCZOS;
  2798. else
  2799. return OBS_SCALE_BICUBIC;
  2800. }
  2801. static inline enum video_format GetVideoFormatFromName(const char *name)
  2802. {
  2803. if (astrcmpi(name, "I420") == 0)
  2804. return VIDEO_FORMAT_I420;
  2805. else if (astrcmpi(name, "NV12") == 0)
  2806. return VIDEO_FORMAT_NV12;
  2807. else if (astrcmpi(name, "I444") == 0)
  2808. return VIDEO_FORMAT_I444;
  2809. #if 0 //currently unsupported
  2810. else if (astrcmpi(name, "YVYU") == 0)
  2811. return VIDEO_FORMAT_YVYU;
  2812. else if (astrcmpi(name, "YUY2") == 0)
  2813. return VIDEO_FORMAT_YUY2;
  2814. else if (astrcmpi(name, "UYVY") == 0)
  2815. return VIDEO_FORMAT_UYVY;
  2816. #endif
  2817. else
  2818. return VIDEO_FORMAT_RGBA;
  2819. }
  2820. void OBSBasic::ResetUI()
  2821. {
  2822. bool studioPortraitLayout = config_get_bool(GetGlobalConfig(),
  2823. "BasicWindow", "StudioPortraitLayout");
  2824. bool labels = config_get_bool(GetGlobalConfig(),
  2825. "BasicWindow", "StudioModeLabels");
  2826. if (studioPortraitLayout)
  2827. ui->previewLayout->setDirection(QBoxLayout::TopToBottom);
  2828. else
  2829. ui->previewLayout->setDirection(QBoxLayout::LeftToRight);
  2830. if (previewProgramMode)
  2831. ui->previewLabel->setHidden(!labels);
  2832. if (programLabel)
  2833. programLabel->setHidden(!labels);
  2834. }
  2835. int OBSBasic::ResetVideo()
  2836. {
  2837. if (outputHandler && outputHandler->Active())
  2838. return OBS_VIDEO_CURRENTLY_ACTIVE;
  2839. ProfileScope("OBSBasic::ResetVideo");
  2840. struct obs_video_info ovi;
  2841. int ret;
  2842. GetConfigFPS(ovi.fps_num, ovi.fps_den);
  2843. const char *colorFormat = config_get_string(basicConfig, "Video",
  2844. "ColorFormat");
  2845. const char *colorSpace = config_get_string(basicConfig, "Video",
  2846. "ColorSpace");
  2847. const char *colorRange = config_get_string(basicConfig, "Video",
  2848. "ColorRange");
  2849. ovi.graphics_module = App()->GetRenderModule();
  2850. ovi.base_width = (uint32_t)config_get_uint(basicConfig,
  2851. "Video", "BaseCX");
  2852. ovi.base_height = (uint32_t)config_get_uint(basicConfig,
  2853. "Video", "BaseCY");
  2854. ovi.output_width = (uint32_t)config_get_uint(basicConfig,
  2855. "Video", "OutputCX");
  2856. ovi.output_height = (uint32_t)config_get_uint(basicConfig,
  2857. "Video", "OutputCY");
  2858. ovi.output_format = GetVideoFormatFromName(colorFormat);
  2859. ovi.colorspace = astrcmpi(colorSpace, "601") == 0 ?
  2860. VIDEO_CS_601 : VIDEO_CS_709;
  2861. ovi.range = astrcmpi(colorRange, "Full") == 0 ?
  2862. VIDEO_RANGE_FULL : VIDEO_RANGE_PARTIAL;
  2863. ovi.adapter = config_get_uint(App()->GlobalConfig(),
  2864. "Video", "AdapterIdx");
  2865. ovi.gpu_conversion = true;
  2866. ovi.scale_type = GetScaleType(basicConfig);
  2867. if (ovi.base_width == 0 || ovi.base_height == 0) {
  2868. ovi.base_width = 1920;
  2869. ovi.base_height = 1080;
  2870. config_set_uint(basicConfig, "Video", "BaseCX", 1920);
  2871. config_set_uint(basicConfig, "Video", "BaseCY", 1080);
  2872. }
  2873. if (ovi.output_width == 0 || ovi.output_height == 0) {
  2874. ovi.output_width = ovi.base_width;
  2875. ovi.output_height = ovi.base_height;
  2876. config_set_uint(basicConfig, "Video", "OutputCX",
  2877. ovi.base_width);
  2878. config_set_uint(basicConfig, "Video", "OutputCY",
  2879. ovi.base_height);
  2880. }
  2881. ret = AttemptToResetVideo(&ovi);
  2882. if (IS_WIN32 && ret != OBS_VIDEO_SUCCESS) {
  2883. if (ret == OBS_VIDEO_CURRENTLY_ACTIVE) {
  2884. blog(LOG_WARNING, "Tried to reset when "
  2885. "already active");
  2886. return ret;
  2887. }
  2888. /* Try OpenGL if DirectX fails on windows */
  2889. if (astrcmpi(ovi.graphics_module, DL_OPENGL) != 0) {
  2890. blog(LOG_WARNING, "Failed to initialize obs video (%d) "
  2891. "with graphics_module='%s', retrying "
  2892. "with graphics_module='%s'",
  2893. ret, ovi.graphics_module,
  2894. DL_OPENGL);
  2895. ovi.graphics_module = DL_OPENGL;
  2896. ret = AttemptToResetVideo(&ovi);
  2897. }
  2898. } else if (ret == OBS_VIDEO_SUCCESS) {
  2899. ResizePreview(ovi.base_width, ovi.base_height);
  2900. if (program)
  2901. ResizeProgram(ovi.base_width, ovi.base_height);
  2902. }
  2903. if (ret == OBS_VIDEO_SUCCESS) {
  2904. OBSBasicStats::InitializeValues();
  2905. OBSProjector::UpdateMultiviewProjectors();
  2906. }
  2907. return ret;
  2908. }
  2909. bool OBSBasic::ResetAudio()
  2910. {
  2911. ProfileScope("OBSBasic::ResetAudio");
  2912. struct obs_audio_info ai;
  2913. ai.samples_per_sec = config_get_uint(basicConfig, "Audio",
  2914. "SampleRate");
  2915. const char *channelSetupStr = config_get_string(basicConfig,
  2916. "Audio", "ChannelSetup");
  2917. if (strcmp(channelSetupStr, "Mono") == 0)
  2918. ai.speakers = SPEAKERS_MONO;
  2919. else if (strcmp(channelSetupStr, "2.1") == 0)
  2920. ai.speakers = SPEAKERS_2POINT1;
  2921. else if (strcmp(channelSetupStr, "4.0") == 0)
  2922. ai.speakers = SPEAKERS_4POINT0;
  2923. else if (strcmp(channelSetupStr, "4.1") == 0)
  2924. ai.speakers = SPEAKERS_4POINT1;
  2925. else if (strcmp(channelSetupStr, "5.1") == 0)
  2926. ai.speakers = SPEAKERS_5POINT1;
  2927. else if (strcmp(channelSetupStr, "7.1") == 0)
  2928. ai.speakers = SPEAKERS_7POINT1;
  2929. else
  2930. ai.speakers = SPEAKERS_STEREO;
  2931. return obs_reset_audio(&ai);
  2932. }
  2933. void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceId,
  2934. const char *deviceDesc, int channel)
  2935. {
  2936. bool disable = deviceId && strcmp(deviceId, "disabled") == 0;
  2937. obs_source_t *source;
  2938. obs_data_t *settings;
  2939. source = obs_get_output_source(channel);
  2940. if (source) {
  2941. if (disable) {
  2942. obs_set_output_source(channel, nullptr);
  2943. } else {
  2944. settings = obs_source_get_settings(source);
  2945. const char *oldId = obs_data_get_string(settings,
  2946. "device_id");
  2947. if (strcmp(oldId, deviceId) != 0) {
  2948. obs_data_set_string(settings, "device_id",
  2949. deviceId);
  2950. obs_source_update(source, settings);
  2951. }
  2952. obs_data_release(settings);
  2953. }
  2954. obs_source_release(source);
  2955. } else if (!disable) {
  2956. settings = obs_data_create();
  2957. obs_data_set_string(settings, "device_id", deviceId);
  2958. source = obs_source_create(sourceId, deviceDesc, settings,
  2959. nullptr);
  2960. obs_data_release(settings);
  2961. obs_set_output_source(channel, source);
  2962. obs_source_release(source);
  2963. }
  2964. }
  2965. void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
  2966. {
  2967. QSize targetSize;
  2968. bool isFixedScaling;
  2969. obs_video_info ovi;
  2970. /* resize preview panel to fix to the top section of the window */
  2971. targetSize = GetPixelSize(ui->preview);
  2972. isFixedScaling = ui->preview->IsFixedScaling();
  2973. obs_get_video_info(&ovi);
  2974. if (isFixedScaling) {
  2975. previewScale = ui->preview->GetScalingAmount();
  2976. GetCenterPosFromFixedScale(int(cx), int(cy),
  2977. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  2978. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  2979. previewX, previewY, previewScale);
  2980. previewX += ui->preview->GetScrollX();
  2981. previewY += ui->preview->GetScrollY();
  2982. } else {
  2983. GetScaleAndCenterPos(int(cx), int(cy),
  2984. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  2985. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  2986. previewX, previewY, previewScale);
  2987. }
  2988. previewX += float(PREVIEW_EDGE_SIZE);
  2989. previewY += float(PREVIEW_EDGE_SIZE);
  2990. }
  2991. void OBSBasic::CloseDialogs()
  2992. {
  2993. QList<QDialog*> childDialogs = this->findChildren<QDialog *>();
  2994. if (!childDialogs.isEmpty()) {
  2995. for (int i = 0; i < childDialogs.size(); ++i) {
  2996. childDialogs.at(i)->close();
  2997. }
  2998. }
  2999. for (QPointer<QWidget> &projector : windowProjectors) {
  3000. delete projector;
  3001. projector.clear();
  3002. }
  3003. for (QPointer<QWidget> &projector : projectors) {
  3004. delete projector;
  3005. projector.clear();
  3006. }
  3007. if (!stats.isNull()) stats->close(); //call close to save Stats geometry
  3008. if (!remux.isNull()) remux->close();
  3009. }
  3010. void OBSBasic::EnumDialogs()
  3011. {
  3012. visDialogs.clear();
  3013. modalDialogs.clear();
  3014. visMsgBoxes.clear();
  3015. /* fill list of Visible dialogs and Modal dialogs */
  3016. QList<QDialog*> dialogs = findChildren<QDialog*>();
  3017. for (QDialog *dialog : dialogs) {
  3018. if (dialog->isVisible())
  3019. visDialogs.append(dialog);
  3020. if (dialog->isModal())
  3021. modalDialogs.append(dialog);
  3022. }
  3023. /* fill list of Visible message boxes */
  3024. QList<QMessageBox*> msgBoxes = findChildren<QMessageBox*>();
  3025. for (QMessageBox *msgbox : msgBoxes) {
  3026. if (msgbox->isVisible())
  3027. visMsgBoxes.append(msgbox);
  3028. }
  3029. }
  3030. void OBSBasic::ClearSceneData()
  3031. {
  3032. disableSaving++;
  3033. CloseDialogs();
  3034. ClearVolumeControls();
  3035. ClearListItems(ui->scenes);
  3036. ui->sources->Clear();
  3037. ClearQuickTransitions();
  3038. ui->transitions->clear();
  3039. obs_set_output_source(0, nullptr);
  3040. obs_set_output_source(1, nullptr);
  3041. obs_set_output_source(2, nullptr);
  3042. obs_set_output_source(3, nullptr);
  3043. obs_set_output_source(4, nullptr);
  3044. obs_set_output_source(5, nullptr);
  3045. lastScene = nullptr;
  3046. swapScene = nullptr;
  3047. programScene = nullptr;
  3048. auto cb = [](void *unused, obs_source_t *source)
  3049. {
  3050. obs_source_remove(source);
  3051. UNUSED_PARAMETER(unused);
  3052. return true;
  3053. };
  3054. obs_enum_sources(cb, nullptr);
  3055. if (api)
  3056. api->on_event(OBS_FRONTEND_EVENT_SCENE_COLLECTION_CLEANUP);
  3057. disableSaving--;
  3058. blog(LOG_INFO, "All scene data cleared");
  3059. blog(LOG_INFO, "------------------------------------------------");
  3060. }
  3061. void OBSBasic::closeEvent(QCloseEvent *event)
  3062. {
  3063. /* Do not close window if inside of a temporary event loop because we
  3064. * could be inside of an Auth::LoadUI call. Keep trying once per
  3065. * second until we've exit any known sub-loops. */
  3066. if (os_atomic_load_long(&insideEventLoop) != 0) {
  3067. QTimer::singleShot(1000, this, SLOT(close()));
  3068. event->ignore();
  3069. return;
  3070. }
  3071. if (isVisible())
  3072. config_set_string(App()->GlobalConfig(),
  3073. "BasicWindow", "geometry",
  3074. saveGeometry().toBase64().constData());
  3075. if (outputHandler && outputHandler->Active()) {
  3076. SetShowing(true);
  3077. QMessageBox::StandardButton button = OBSMessageBox::question(
  3078. this, QTStr("ConfirmExit.Title"),
  3079. QTStr("ConfirmExit.Text"));
  3080. if (button == QMessageBox::No) {
  3081. event->ignore();
  3082. return;
  3083. }
  3084. }
  3085. QWidget::closeEvent(event);
  3086. if (!event->isAccepted())
  3087. return;
  3088. blog(LOG_INFO, SHUTDOWN_SEPARATOR);
  3089. if (introCheckThread)
  3090. introCheckThread->wait();
  3091. if (updateCheckThread)
  3092. updateCheckThread->wait();
  3093. if (logUploadThread)
  3094. logUploadThread->wait();
  3095. signalHandlers.clear();
  3096. Auth::Save();
  3097. SaveProjectNow();
  3098. auth.reset();
  3099. config_set_string(App()->GlobalConfig(),
  3100. "BasicWindow", "DockState",
  3101. saveState().toBase64().constData());
  3102. if (api)
  3103. api->on_event(OBS_FRONTEND_EVENT_EXIT);
  3104. disableSaving++;
  3105. /* Clear all scene data (dialogs, widgets, widget sub-items, scenes,
  3106. * sources, etc) so that all references are released before shutdown */
  3107. ClearSceneData();
  3108. App()->quit();
  3109. }
  3110. void OBSBasic::changeEvent(QEvent *event)
  3111. {
  3112. if (event->type() == QEvent::WindowStateChange &&
  3113. isMinimized() &&
  3114. trayIcon &&
  3115. trayIcon->isVisible() &&
  3116. sysTrayMinimizeToTray()) {
  3117. ToggleShowHide();
  3118. }
  3119. }
  3120. void OBSBasic::on_actionShow_Recordings_triggered()
  3121. {
  3122. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  3123. const char *type = config_get_string(basicConfig, "AdvOut", "RecType");
  3124. const char *adv_path = strcmp(type, "Standard") ?
  3125. config_get_string(basicConfig, "AdvOut", "FFFilePath") :
  3126. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  3127. const char *path = strcmp(mode, "Advanced") ?
  3128. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  3129. adv_path;
  3130. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  3131. }
  3132. void OBSBasic::on_actionRemux_triggered()
  3133. {
  3134. if (!remux.isNull()) {
  3135. remux->show();
  3136. remux->raise();
  3137. return;
  3138. }
  3139. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  3140. const char *path = strcmp(mode, "Advanced") ?
  3141. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  3142. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  3143. OBSRemux *remuxDlg;
  3144. remuxDlg = new OBSRemux(path, this);
  3145. remuxDlg->show();
  3146. remux = remuxDlg;
  3147. }
  3148. void OBSBasic::on_action_Settings_triggered()
  3149. {
  3150. static bool settings_already_executing = false;
  3151. /* Do not load settings window if inside of a temporary event loop
  3152. * because we could be inside of an Auth::LoadUI call. Keep trying
  3153. * once per second until we've exit any known sub-loops. */
  3154. if (os_atomic_load_long(&insideEventLoop) != 0) {
  3155. QTimer::singleShot(1000, this,
  3156. SLOT(on_action_Settings_triggered()));
  3157. return;
  3158. }
  3159. if (settings_already_executing) {
  3160. return;
  3161. }
  3162. settings_already_executing = true;
  3163. OBSBasicSettings settings(this);
  3164. settings.exec();
  3165. SystemTray(false);
  3166. settings_already_executing = false;
  3167. }
  3168. void OBSBasic::on_actionAdvAudioProperties_triggered()
  3169. {
  3170. if (advAudioWindow != nullptr) {
  3171. advAudioWindow->raise();
  3172. return;
  3173. }
  3174. advAudioWindow = new OBSBasicAdvAudio(this);
  3175. advAudioWindow->show();
  3176. advAudioWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  3177. connect(advAudioWindow, SIGNAL(destroyed()),
  3178. this, SLOT(on_advAudioProps_destroyed()));
  3179. }
  3180. void OBSBasic::on_advAudioProps_clicked()
  3181. {
  3182. on_actionAdvAudioProperties_triggered();
  3183. }
  3184. void OBSBasic::on_advAudioProps_destroyed()
  3185. {
  3186. advAudioWindow = nullptr;
  3187. }
  3188. void OBSBasic::on_scenes_currentItemChanged(QListWidgetItem *current,
  3189. QListWidgetItem *prev)
  3190. {
  3191. obs_source_t *source = NULL;
  3192. if (sceneChanging)
  3193. return;
  3194. if (current) {
  3195. obs_scene_t *scene;
  3196. scene = GetOBSRef<OBSScene>(current);
  3197. source = obs_scene_get_source(scene);
  3198. }
  3199. SetCurrentScene(source);
  3200. if (api)
  3201. api->on_event(OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED);
  3202. UNUSED_PARAMETER(prev);
  3203. }
  3204. void OBSBasic::EditSceneName()
  3205. {
  3206. QListWidgetItem *item = ui->scenes->currentItem();
  3207. Qt::ItemFlags flags = item->flags();
  3208. item->setFlags(flags | Qt::ItemIsEditable);
  3209. ui->scenes->editItem(item);
  3210. item->setFlags(flags);
  3211. }
  3212. static void AddProjectorMenuMonitors(QMenu *parent, QObject *target,
  3213. const char *slot)
  3214. {
  3215. QAction *action;
  3216. QList<QScreen*> screens = QGuiApplication::screens();
  3217. for (int i = 0; i < screens.size(); i++) {
  3218. QRect screenGeometry = screens[i]->geometry();
  3219. QString str = QString("%1 %2: %3x%4 @ %5,%6").
  3220. arg(QTStr("Display"),
  3221. QString::number(i + 1),
  3222. QString::number(screenGeometry.width()),
  3223. QString::number(screenGeometry.height()),
  3224. QString::number(screenGeometry.x()),
  3225. QString::number(screenGeometry.y()));
  3226. action = parent->addAction(str, target, slot);
  3227. action->setProperty("monitor", i);
  3228. }
  3229. }
  3230. void OBSBasic::on_scenes_customContextMenuRequested(const QPoint &pos)
  3231. {
  3232. QListWidgetItem *item = ui->scenes->itemAt(pos);
  3233. QMenu popup(this);
  3234. QMenu order(QTStr("Basic.MainMenu.Edit.Order"), this);
  3235. popup.addAction(QTStr("Add"),
  3236. this, SLOT(on_actionAddScene_triggered()));
  3237. if (item) {
  3238. popup.addSeparator();
  3239. popup.addAction(QTStr("Duplicate"),
  3240. this, SLOT(DuplicateSelectedScene()));
  3241. popup.addAction(QTStr("Rename"),
  3242. this, SLOT(EditSceneName()));
  3243. popup.addAction(QTStr("Remove"),
  3244. this, SLOT(RemoveSelectedScene()));
  3245. popup.addSeparator();
  3246. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveUp"),
  3247. this, SLOT(on_actionSceneUp_triggered()));
  3248. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveDown"),
  3249. this, SLOT(on_actionSceneDown_triggered()));
  3250. order.addSeparator();
  3251. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToTop"),
  3252. this, SLOT(MoveSceneToTop()));
  3253. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToBottom"),
  3254. this, SLOT(MoveSceneToBottom()));
  3255. popup.addMenu(&order);
  3256. popup.addSeparator();
  3257. delete sceneProjectorMenu;
  3258. sceneProjectorMenu = new QMenu(QTStr("SceneProjector"));
  3259. AddProjectorMenuMonitors(sceneProjectorMenu, this,
  3260. SLOT(OpenSceneProjector()));
  3261. popup.addMenu(sceneProjectorMenu);
  3262. QAction *sceneWindow = popup.addAction(
  3263. QTStr("SceneWindow"),
  3264. this, SLOT(OpenSceneWindow()));
  3265. popup.addAction(sceneWindow);
  3266. popup.addSeparator();
  3267. popup.addAction(QTStr("Filters"), this,
  3268. SLOT(OpenSceneFilters()));
  3269. popup.addSeparator();
  3270. delete perSceneTransitionMenu;
  3271. perSceneTransitionMenu = CreatePerSceneTransitionMenu();
  3272. popup.addMenu(perSceneTransitionMenu);
  3273. /* ---------------------- */
  3274. QAction *multiviewAction = popup.addAction(
  3275. QTStr("ShowInMultiview"));
  3276. OBSSource source = GetCurrentSceneSource();
  3277. OBSData data = obs_source_get_private_settings(source);
  3278. obs_data_release(data);
  3279. obs_data_set_default_bool(data, "show_in_multiview",
  3280. true);
  3281. bool show = obs_data_get_bool(data, "show_in_multiview");
  3282. multiviewAction->setCheckable(true);
  3283. multiviewAction->setChecked(show);
  3284. auto showInMultiview = [] (OBSData data)
  3285. {
  3286. bool show = obs_data_get_bool(data,
  3287. "show_in_multiview");
  3288. obs_data_set_bool(data, "show_in_multiview",
  3289. !show);
  3290. OBSProjector::UpdateMultiviewProjectors();
  3291. };
  3292. connect(multiviewAction, &QAction::triggered,
  3293. std::bind(showInMultiview, data));
  3294. }
  3295. popup.exec(QCursor::pos());
  3296. }
  3297. void OBSBasic::on_actionAddScene_triggered()
  3298. {
  3299. string name;
  3300. QString format{QTStr("Basic.Main.DefaultSceneName.Text")};
  3301. int i = 2;
  3302. QString placeHolderText = format.arg(i);
  3303. obs_source_t *source = nullptr;
  3304. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  3305. obs_source_release(source);
  3306. placeHolderText = format.arg(++i);
  3307. }
  3308. bool accepted = NameDialog::AskForName(this,
  3309. QTStr("Basic.Main.AddSceneDlg.Title"),
  3310. QTStr("Basic.Main.AddSceneDlg.Text"),
  3311. name,
  3312. placeHolderText);
  3313. if (accepted) {
  3314. if (name.empty()) {
  3315. OBSMessageBox::information(this,
  3316. QTStr("NoNameEntered.Title"),
  3317. QTStr("NoNameEntered.Text"));
  3318. on_actionAddScene_triggered();
  3319. return;
  3320. }
  3321. obs_source_t *source = obs_get_source_by_name(name.c_str());
  3322. if (source) {
  3323. OBSMessageBox::information(this,
  3324. QTStr("NameExists.Title"),
  3325. QTStr("NameExists.Text"));
  3326. obs_source_release(source);
  3327. on_actionAddScene_triggered();
  3328. return;
  3329. }
  3330. obs_scene_t *scene = obs_scene_create(name.c_str());
  3331. source = obs_scene_get_source(scene);
  3332. SetCurrentScene(source);
  3333. obs_scene_release(scene);
  3334. }
  3335. }
  3336. void OBSBasic::on_actionRemoveScene_triggered()
  3337. {
  3338. OBSScene scene = GetCurrentScene();
  3339. obs_source_t *source = obs_scene_get_source(scene);
  3340. if (source && QueryRemoveSource(source))
  3341. obs_source_remove(source);
  3342. }
  3343. void OBSBasic::ChangeSceneIndex(bool relative, int offset, int invalidIdx)
  3344. {
  3345. int idx = ui->scenes->currentRow();
  3346. if (idx == -1 || idx == invalidIdx)
  3347. return;
  3348. sceneChanging = true;
  3349. QListWidgetItem *item = ui->scenes->takeItem(idx);
  3350. if (!relative)
  3351. idx = 0;
  3352. ui->scenes->insertItem(idx + offset, item);
  3353. ui->scenes->setCurrentRow(idx + offset);
  3354. item->setSelected(true);
  3355. sceneChanging = false;
  3356. OBSProjector::UpdateMultiviewProjectors();
  3357. }
  3358. void OBSBasic::on_actionSceneUp_triggered()
  3359. {
  3360. ChangeSceneIndex(true, -1, 0);
  3361. }
  3362. void OBSBasic::on_actionSceneDown_triggered()
  3363. {
  3364. ChangeSceneIndex(true, 1, ui->scenes->count() - 1);
  3365. }
  3366. void OBSBasic::MoveSceneToTop()
  3367. {
  3368. ChangeSceneIndex(false, 0, 0);
  3369. }
  3370. void OBSBasic::MoveSceneToBottom()
  3371. {
  3372. ChangeSceneIndex(false, ui->scenes->count() - 1,
  3373. ui->scenes->count() - 1);
  3374. }
  3375. void OBSBasic::EditSceneItemName()
  3376. {
  3377. int idx = GetTopSelectedSourceItem();
  3378. ui->sources->Edit(idx);
  3379. }
  3380. void OBSBasic::SetDeinterlacingMode()
  3381. {
  3382. QAction *action = reinterpret_cast<QAction*>(sender());
  3383. obs_deinterlace_mode mode =
  3384. (obs_deinterlace_mode)action->property("mode").toInt();
  3385. OBSSceneItem sceneItem = GetCurrentSceneItem();
  3386. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  3387. obs_source_set_deinterlace_mode(source, mode);
  3388. }
  3389. void OBSBasic::SetDeinterlacingOrder()
  3390. {
  3391. QAction *action = reinterpret_cast<QAction*>(sender());
  3392. obs_deinterlace_field_order order =
  3393. (obs_deinterlace_field_order)action->property("order").toInt();
  3394. OBSSceneItem sceneItem = GetCurrentSceneItem();
  3395. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  3396. obs_source_set_deinterlace_field_order(source, order);
  3397. }
  3398. QMenu *OBSBasic::AddDeinterlacingMenu(QMenu *menu, obs_source_t *source)
  3399. {
  3400. obs_deinterlace_mode deinterlaceMode =
  3401. obs_source_get_deinterlace_mode(source);
  3402. obs_deinterlace_field_order deinterlaceOrder =
  3403. obs_source_get_deinterlace_field_order(source);
  3404. QAction *action;
  3405. #define ADD_MODE(name, mode) \
  3406. action = menu->addAction(QTStr("" name), this, \
  3407. SLOT(SetDeinterlacingMode())); \
  3408. action->setProperty("mode", (int)mode); \
  3409. action->setCheckable(true); \
  3410. action->setChecked(deinterlaceMode == mode);
  3411. ADD_MODE("Disable", OBS_DEINTERLACE_MODE_DISABLE);
  3412. ADD_MODE("Deinterlacing.Discard", OBS_DEINTERLACE_MODE_DISCARD);
  3413. ADD_MODE("Deinterlacing.Retro", OBS_DEINTERLACE_MODE_RETRO);
  3414. ADD_MODE("Deinterlacing.Blend", OBS_DEINTERLACE_MODE_BLEND);
  3415. ADD_MODE("Deinterlacing.Blend2x", OBS_DEINTERLACE_MODE_BLEND_2X);
  3416. ADD_MODE("Deinterlacing.Linear", OBS_DEINTERLACE_MODE_LINEAR);
  3417. ADD_MODE("Deinterlacing.Linear2x", OBS_DEINTERLACE_MODE_LINEAR_2X);
  3418. ADD_MODE("Deinterlacing.Yadif", OBS_DEINTERLACE_MODE_YADIF);
  3419. ADD_MODE("Deinterlacing.Yadif2x", OBS_DEINTERLACE_MODE_YADIF_2X);
  3420. #undef ADD_MODE
  3421. menu->addSeparator();
  3422. #define ADD_ORDER(name, order) \
  3423. action = menu->addAction(QTStr("Deinterlacing." name), this, \
  3424. SLOT(SetDeinterlacingOrder())); \
  3425. action->setProperty("order", (int)order); \
  3426. action->setCheckable(true); \
  3427. action->setChecked(deinterlaceOrder == order);
  3428. ADD_ORDER("TopFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_TOP);
  3429. ADD_ORDER("BottomFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_BOTTOM);
  3430. #undef ADD_ORDER
  3431. return menu;
  3432. }
  3433. void OBSBasic::SetScaleFilter()
  3434. {
  3435. QAction *action = reinterpret_cast<QAction*>(sender());
  3436. obs_scale_type mode = (obs_scale_type)action->property("mode").toInt();
  3437. OBSSceneItem sceneItem = GetCurrentSceneItem();
  3438. obs_sceneitem_set_scale_filter(sceneItem, mode);
  3439. }
  3440. QMenu *OBSBasic::AddScaleFilteringMenu(QMenu *menu, obs_sceneitem_t *item)
  3441. {
  3442. obs_scale_type scaleFilter = obs_sceneitem_get_scale_filter(item);
  3443. QAction *action;
  3444. #define ADD_MODE(name, mode) \
  3445. action = menu->addAction(QTStr("" name), this, \
  3446. SLOT(SetScaleFilter())); \
  3447. action->setProperty("mode", (int)mode); \
  3448. action->setCheckable(true); \
  3449. action->setChecked(scaleFilter == mode);
  3450. ADD_MODE("Disable", OBS_SCALE_DISABLE);
  3451. ADD_MODE("ScaleFiltering.Point", OBS_SCALE_POINT);
  3452. ADD_MODE("ScaleFiltering.Bilinear", OBS_SCALE_BILINEAR);
  3453. ADD_MODE("ScaleFiltering.Bicubic", OBS_SCALE_BICUBIC);
  3454. ADD_MODE("ScaleFiltering.Lanczos", OBS_SCALE_LANCZOS);
  3455. ADD_MODE("ScaleFiltering.Area", OBS_SCALE_AREA);
  3456. #undef ADD_MODE
  3457. return menu;
  3458. }
  3459. QMenu *OBSBasic::AddBackgroundColorMenu(QMenu *menu, QWidgetAction *widgetAction,
  3460. ColorSelect *select, obs_sceneitem_t *item)
  3461. {
  3462. QAction *action;
  3463. menu->setStyleSheet(QString(
  3464. "*[bgColor=\"1\"]{background-color:rgba(255,68,68,33%);}" \
  3465. "*[bgColor=\"2\"]{background-color:rgba(255,255,68,33%);}" \
  3466. "*[bgColor=\"3\"]{background-color:rgba(68,255,68,33%);}" \
  3467. "*[bgColor=\"4\"]{background-color:rgba(68,255,255,33%);}" \
  3468. "*[bgColor=\"5\"]{background-color:rgba(68,68,255,33%);}" \
  3469. "*[bgColor=\"6\"]{background-color:rgba(255,68,255,33%);}" \
  3470. "*[bgColor=\"7\"]{background-color:rgba(68,68,68,33%);}" \
  3471. "*[bgColor=\"8\"]{background-color:rgba(255,255,255,33%);}"));
  3472. obs_data_t *privData = obs_sceneitem_get_private_settings(item);
  3473. obs_data_release(privData);
  3474. obs_data_set_default_int(privData, "color-preset", 0);
  3475. int preset = obs_data_get_int(privData, "color-preset");
  3476. action = menu->addAction(QTStr("Clear"), this,
  3477. + SLOT(ColorChange()));
  3478. action->setCheckable(true);
  3479. action->setProperty("bgColor", 0);
  3480. action->setChecked(preset == 0);
  3481. action = menu->addAction(QTStr("CustomColor"), this,
  3482. + SLOT(ColorChange()));
  3483. action->setCheckable(true);
  3484. action->setProperty("bgColor", 1);
  3485. action->setChecked(preset == 1);
  3486. menu->addSeparator();
  3487. widgetAction->setDefaultWidget(select);
  3488. for (int i = 1; i < 9; i++) {
  3489. stringstream button;
  3490. button << "preset" << i;
  3491. QPushButton *colorButton = select->findChild<QPushButton *>(
  3492. button.str().c_str());
  3493. if (preset == i + 1)
  3494. colorButton->setStyleSheet("border: 2px solid black");
  3495. colorButton->setProperty("bgColor", i);
  3496. select->connect(colorButton, SIGNAL(released()), this,
  3497. SLOT(ColorChange()));
  3498. }
  3499. menu->addAction(widgetAction);
  3500. return menu;
  3501. }
  3502. ColorSelect::ColorSelect(QWidget *parent)
  3503. : QWidget(parent),
  3504. ui(new Ui::ColorSelect)
  3505. {
  3506. ui->setupUi(this);
  3507. }
  3508. void OBSBasic::CreateSourcePopupMenu(int idx, bool preview)
  3509. {
  3510. QMenu popup(this);
  3511. delete previewProjectorSource;
  3512. delete sourceProjector;
  3513. delete scaleFilteringMenu;
  3514. delete colorMenu;
  3515. delete colorWidgetAction;
  3516. delete colorSelect;
  3517. delete deinterlaceMenu;
  3518. if (preview) {
  3519. QAction *action = popup.addAction(
  3520. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  3521. this, SLOT(TogglePreview()));
  3522. action->setCheckable(true);
  3523. action->setChecked(
  3524. obs_display_enabled(ui->preview->GetDisplay()));
  3525. if (IsPreviewProgramMode())
  3526. action->setEnabled(false);
  3527. popup.addAction(ui->actionLockPreview);
  3528. popup.addMenu(ui->scalingMenu);
  3529. previewProjectorSource = new QMenu(QTStr("PreviewProjector"));
  3530. AddProjectorMenuMonitors(previewProjectorSource, this,
  3531. SLOT(OpenPreviewProjector()));
  3532. popup.addMenu(previewProjectorSource);
  3533. QAction *previewWindow = popup.addAction(
  3534. QTStr("PreviewWindow"),
  3535. this, SLOT(OpenPreviewWindow()));
  3536. popup.addAction(previewWindow);
  3537. popup.addSeparator();
  3538. }
  3539. QPointer<QMenu> addSourceMenu = CreateAddSourcePopupMenu();
  3540. if (addSourceMenu)
  3541. popup.addMenu(addSourceMenu);
  3542. ui->actionCopyFilters->setEnabled(false);
  3543. ui->actionCopySource->setEnabled(false);
  3544. if (ui->sources->MultipleBaseSelected()) {
  3545. popup.addSeparator();
  3546. popup.addAction(QTStr("Basic.Main.GroupItems"),
  3547. ui->sources, SLOT(GroupSelectedItems()));
  3548. } else if (ui->sources->GroupsSelected()) {
  3549. popup.addSeparator();
  3550. popup.addAction(QTStr("Basic.Main.Ungroup"),
  3551. ui->sources, SLOT(UngroupSelectedGroups()));
  3552. }
  3553. popup.addSeparator();
  3554. popup.addAction(ui->actionCopySource);
  3555. popup.addAction(ui->actionPasteRef);
  3556. popup.addAction(ui->actionPasteDup);
  3557. popup.addSeparator();
  3558. popup.addSeparator();
  3559. popup.addAction(ui->actionCopyFilters);
  3560. popup.addAction(ui->actionPasteFilters);
  3561. popup.addSeparator();
  3562. if (idx != -1) {
  3563. if (addSourceMenu)
  3564. popup.addSeparator();
  3565. OBSSceneItem sceneItem = ui->sources->Get(idx);
  3566. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  3567. uint32_t flags = obs_source_get_output_flags(source);
  3568. bool isAsyncVideo = (flags & OBS_SOURCE_ASYNC_VIDEO) ==
  3569. OBS_SOURCE_ASYNC_VIDEO;
  3570. bool hasAudio = (flags & OBS_SOURCE_AUDIO) ==
  3571. OBS_SOURCE_AUDIO;
  3572. QAction *action;
  3573. colorMenu = new QMenu(QTStr("ChangeBG"));
  3574. colorWidgetAction = new QWidgetAction(colorMenu);
  3575. colorSelect = new ColorSelect(colorMenu);
  3576. popup.addMenu(AddBackgroundColorMenu(colorMenu,
  3577. colorWidgetAction, colorSelect, sceneItem));
  3578. popup.addAction(QTStr("Rename"), this,
  3579. SLOT(EditSceneItemName()));
  3580. popup.addAction(QTStr("Remove"), this,
  3581. SLOT(on_actionRemoveSource_triggered()));
  3582. popup.addSeparator();
  3583. popup.addMenu(ui->orderMenu);
  3584. popup.addMenu(ui->transformMenu);
  3585. sourceProjector = new QMenu(QTStr("SourceProjector"));
  3586. AddProjectorMenuMonitors(sourceProjector, this,
  3587. SLOT(OpenSourceProjector()));
  3588. QAction *sourceWindow = popup.addAction(
  3589. QTStr("SourceWindow"),
  3590. this, SLOT(OpenSourceWindow()));
  3591. popup.addAction(sourceWindow);
  3592. popup.addSeparator();
  3593. if (hasAudio) {
  3594. QAction *actionHideMixer = popup.addAction(
  3595. QTStr("HideMixer"),
  3596. this, SLOT(ToggleHideMixer()));
  3597. actionHideMixer->setCheckable(true);
  3598. actionHideMixer->setChecked(SourceMixerHidden(source));
  3599. }
  3600. if (isAsyncVideo) {
  3601. deinterlaceMenu = new QMenu(QTStr("Deinterlacing"));
  3602. popup.addMenu(AddDeinterlacingMenu(deinterlaceMenu, source));
  3603. popup.addSeparator();
  3604. }
  3605. QAction *resizeOutput = popup.addAction(
  3606. QTStr("ResizeOutputSizeOfSource"), this,
  3607. SLOT(ResizeOutputSizeOfSource()));
  3608. int width = obs_source_get_width(source);
  3609. int height = obs_source_get_height(source);
  3610. resizeOutput->setEnabled(!obs_video_active());
  3611. if (width == 0 || height == 0)
  3612. resizeOutput->setEnabled(false);
  3613. scaleFilteringMenu = new QMenu(QTStr("ScaleFiltering"));
  3614. popup.addMenu(AddScaleFilteringMenu(scaleFilteringMenu, sceneItem));
  3615. popup.addSeparator();
  3616. popup.addMenu(sourceProjector);
  3617. popup.addAction(sourceWindow);
  3618. popup.addSeparator();
  3619. action = popup.addAction(QTStr("Interact"), this,
  3620. SLOT(on_actionInteract_triggered()));
  3621. action->setEnabled(obs_source_get_output_flags(source) &
  3622. OBS_SOURCE_INTERACTION);
  3623. popup.addAction(QTStr("Filters"), this,
  3624. SLOT(OpenFilters()));
  3625. popup.addAction(QTStr("Properties"), this,
  3626. SLOT(on_actionSourceProperties_triggered()));
  3627. ui->actionCopyFilters->setEnabled(true);
  3628. ui->actionCopySource->setEnabled(true);
  3629. } else {
  3630. ui->actionPasteFilters->setEnabled(false);
  3631. }
  3632. popup.exec(QCursor::pos());
  3633. }
  3634. void OBSBasic::on_sources_customContextMenuRequested(const QPoint &pos)
  3635. {
  3636. if (ui->scenes->count()) {
  3637. QModelIndex idx = ui->sources->indexAt(pos);
  3638. CreateSourcePopupMenu(idx.row(), false);
  3639. }
  3640. }
  3641. void OBSBasic::on_scenes_itemDoubleClicked(QListWidgetItem *witem)
  3642. {
  3643. if (!witem)
  3644. return;
  3645. if (IsPreviewProgramMode()) {
  3646. bool doubleClickSwitch = config_get_bool(App()->GlobalConfig(),
  3647. "BasicWindow", "TransitionOnDoubleClick");
  3648. if (doubleClickSwitch) {
  3649. OBSScene scene = GetCurrentScene();
  3650. if (scene)
  3651. SetCurrentScene(scene, false, true);
  3652. }
  3653. }
  3654. }
  3655. void OBSBasic::AddSource(const char *id)
  3656. {
  3657. if (id && *id) {
  3658. OBSBasicSourceSelect sourceSelect(this, id);
  3659. sourceSelect.exec();
  3660. if (sourceSelect.newSource && strcmp(id, "group") != 0)
  3661. CreatePropertiesWindow(sourceSelect.newSource);
  3662. }
  3663. }
  3664. QMenu *OBSBasic::CreateAddSourcePopupMenu()
  3665. {
  3666. const char *type;
  3667. bool foundValues = false;
  3668. bool foundDeprecated = false;
  3669. size_t idx = 0;
  3670. QMenu *popup = new QMenu(QTStr("Add"), this);
  3671. QMenu *deprecated = new QMenu(QTStr("Deprecated"), popup);
  3672. auto getActionAfter = [] (QMenu *menu, const QString &name)
  3673. {
  3674. QList<QAction*> actions = menu->actions();
  3675. for (QAction *menuAction : actions) {
  3676. if (menuAction->text().compare(name) >= 0)
  3677. return menuAction;
  3678. }
  3679. return (QAction*)nullptr;
  3680. };
  3681. auto addSource = [this, getActionAfter] (QMenu *popup,
  3682. const char *type, const char *name)
  3683. {
  3684. QString qname = QT_UTF8(name);
  3685. QAction *popupItem = new QAction(qname, this);
  3686. popupItem->setData(QT_UTF8(type));
  3687. connect(popupItem, SIGNAL(triggered(bool)),
  3688. this, SLOT(AddSourceFromAction()));
  3689. QAction *after = getActionAfter(popup, qname);
  3690. popup->insertAction(after, popupItem);
  3691. };
  3692. while (obs_enum_input_types(idx++, &type)) {
  3693. const char *name = obs_source_get_display_name(type);
  3694. uint32_t caps = obs_get_source_output_flags(type);
  3695. if ((caps & OBS_SOURCE_CAP_DISABLED) != 0)
  3696. continue;
  3697. if ((caps & OBS_SOURCE_DEPRECATED) == 0) {
  3698. addSource(popup, type, name);
  3699. } else {
  3700. addSource(deprecated, type, name);
  3701. foundDeprecated = true;
  3702. }
  3703. foundValues = true;
  3704. }
  3705. addSource(popup, "scene", Str("Basic.Scene"));
  3706. popup->addSeparator();
  3707. QAction *addGroup = new QAction(QTStr("Group"), this);
  3708. addGroup->setData(QT_UTF8("group"));
  3709. connect(addGroup, SIGNAL(triggered(bool)),
  3710. this, SLOT(AddSourceFromAction()));
  3711. popup->addAction(addGroup);
  3712. if (!foundDeprecated) {
  3713. delete deprecated;
  3714. deprecated = nullptr;
  3715. }
  3716. if (!foundValues) {
  3717. delete popup;
  3718. popup = nullptr;
  3719. } else if (foundDeprecated) {
  3720. popup->addSeparator();
  3721. popup->addMenu(deprecated);
  3722. }
  3723. return popup;
  3724. }
  3725. void OBSBasic::AddSourceFromAction()
  3726. {
  3727. QAction *action = qobject_cast<QAction*>(sender());
  3728. if (!action)
  3729. return;
  3730. AddSource(QT_TO_UTF8(action->data().toString()));
  3731. }
  3732. void OBSBasic::AddSourcePopupMenu(const QPoint &pos)
  3733. {
  3734. if (!GetCurrentScene()) {
  3735. // Tell the user he needs a scene first (help beginners).
  3736. OBSMessageBox::information(this,
  3737. QTStr("Basic.Main.AddSourceHelp.Title"),
  3738. QTStr("Basic.Main.AddSourceHelp.Text"));
  3739. return;
  3740. }
  3741. QScopedPointer<QMenu> popup(CreateAddSourcePopupMenu());
  3742. if (popup)
  3743. popup->exec(pos);
  3744. }
  3745. void OBSBasic::on_actionAddSource_triggered()
  3746. {
  3747. AddSourcePopupMenu(QCursor::pos());
  3748. }
  3749. static bool remove_items(obs_scene_t *, obs_sceneitem_t *item, void *param)
  3750. {
  3751. vector<OBSSceneItem> &items =
  3752. *reinterpret_cast<vector<OBSSceneItem>*>(param);
  3753. if (obs_sceneitem_selected(item)) {
  3754. items.emplace_back(item);
  3755. } else if (obs_sceneitem_is_group(item)) {
  3756. obs_sceneitem_group_enum_items(item, remove_items, &items);
  3757. }
  3758. return true;
  3759. };
  3760. void OBSBasic::on_actionRemoveSource_triggered()
  3761. {
  3762. vector<OBSSceneItem> items;
  3763. obs_scene_enum_items(GetCurrentScene(), remove_items, &items);
  3764. if (!items.size())
  3765. return;
  3766. auto removeMultiple = [this] (size_t count)
  3767. {
  3768. QString text = QTStr("ConfirmRemove.TextMultiple")
  3769. .arg(QString::number(count));
  3770. QMessageBox remove_items(this);
  3771. remove_items.setText(text);
  3772. QAbstractButton *Yes = remove_items.addButton(QTStr("Yes"),
  3773. QMessageBox::YesRole);
  3774. remove_items.addButton(QTStr("No"), QMessageBox::NoRole);
  3775. remove_items.setIcon(QMessageBox::Question);
  3776. remove_items.setWindowTitle(QTStr("ConfirmRemove.Title"));
  3777. remove_items.exec();
  3778. return Yes == remove_items.clickedButton();
  3779. };
  3780. if (items.size() == 1) {
  3781. OBSSceneItem &item = items[0];
  3782. obs_source_t *source = obs_sceneitem_get_source(item);
  3783. if (source && QueryRemoveSource(source))
  3784. obs_sceneitem_remove(item);
  3785. } else {
  3786. if (removeMultiple(items.size())) {
  3787. for (auto &item : items)
  3788. obs_sceneitem_remove(item);
  3789. }
  3790. }
  3791. }
  3792. void OBSBasic::on_actionInteract_triggered()
  3793. {
  3794. OBSSceneItem item = GetCurrentSceneItem();
  3795. OBSSource source = obs_sceneitem_get_source(item);
  3796. if (source)
  3797. CreateInteractionWindow(source);
  3798. }
  3799. void OBSBasic::on_actionSourceProperties_triggered()
  3800. {
  3801. OBSSceneItem item = GetCurrentSceneItem();
  3802. OBSSource source = obs_sceneitem_get_source(item);
  3803. if (source)
  3804. CreatePropertiesWindow(source);
  3805. }
  3806. void OBSBasic::on_actionSourceUp_triggered()
  3807. {
  3808. OBSSceneItem item = GetCurrentSceneItem();
  3809. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3810. }
  3811. void OBSBasic::on_actionSourceDown_triggered()
  3812. {
  3813. OBSSceneItem item = GetCurrentSceneItem();
  3814. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3815. }
  3816. void OBSBasic::on_actionMoveUp_triggered()
  3817. {
  3818. OBSSceneItem item = GetCurrentSceneItem();
  3819. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3820. }
  3821. void OBSBasic::on_actionMoveDown_triggered()
  3822. {
  3823. OBSSceneItem item = GetCurrentSceneItem();
  3824. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3825. }
  3826. void OBSBasic::on_actionMoveToTop_triggered()
  3827. {
  3828. OBSSceneItem item = GetCurrentSceneItem();
  3829. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_TOP);
  3830. }
  3831. void OBSBasic::on_actionMoveToBottom_triggered()
  3832. {
  3833. OBSSceneItem item = GetCurrentSceneItem();
  3834. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_BOTTOM);
  3835. }
  3836. static BPtr<char> ReadLogFile(const char *subdir, const char *log)
  3837. {
  3838. char logDir[512];
  3839. if (GetConfigPath(logDir, sizeof(logDir), subdir) <= 0)
  3840. return nullptr;
  3841. string path = (char*)logDir;
  3842. path += "/";
  3843. path += log;
  3844. BPtr<char> file = os_quick_read_utf8_file(path.c_str());
  3845. if (!file)
  3846. blog(LOG_WARNING, "Failed to read log file %s", path.c_str());
  3847. return file;
  3848. }
  3849. void OBSBasic::UploadLog(const char *subdir, const char *file)
  3850. {
  3851. BPtr<char> fileString{ReadLogFile(subdir, file)};
  3852. if (!fileString)
  3853. return;
  3854. if (!*fileString)
  3855. return;
  3856. ui->menuLogFiles->setEnabled(false);
  3857. stringstream ss;
  3858. ss << "OBS " << App()->GetVersionString()
  3859. << " log file uploaded at " << CurrentDateTimeString()
  3860. << "\n\n" << fileString;
  3861. if (logUploadThread) {
  3862. logUploadThread->wait();
  3863. }
  3864. RemoteTextThread *thread = new RemoteTextThread(
  3865. "https://obsproject.com/logs/upload",
  3866. "text/plain", ss.str().c_str());
  3867. logUploadThread.reset(thread);
  3868. connect(thread, &RemoteTextThread::Result,
  3869. this, &OBSBasic::logUploadFinished);
  3870. logUploadThread->start();
  3871. }
  3872. void OBSBasic::on_actionShowLogs_triggered()
  3873. {
  3874. char logDir[512];
  3875. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3876. return;
  3877. QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
  3878. QDesktopServices::openUrl(url);
  3879. }
  3880. void OBSBasic::on_actionUploadCurrentLog_triggered()
  3881. {
  3882. UploadLog("obs-studio/logs", App()->GetCurrentLog());
  3883. }
  3884. void OBSBasic::on_actionUploadLastLog_triggered()
  3885. {
  3886. UploadLog("obs-studio/logs", App()->GetLastLog());
  3887. }
  3888. void OBSBasic::on_actionViewCurrentLog_triggered()
  3889. {
  3890. char logDir[512];
  3891. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3892. return;
  3893. const char* log = App()->GetCurrentLog();
  3894. string path = (char*)logDir;
  3895. path += "/";
  3896. path += log;
  3897. QUrl url = QUrl::fromLocalFile(QT_UTF8(path.c_str()));
  3898. QDesktopServices::openUrl(url);
  3899. }
  3900. void OBSBasic::on_actionShowCrashLogs_triggered()
  3901. {
  3902. char logDir[512];
  3903. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/crashes") <= 0)
  3904. return;
  3905. QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
  3906. QDesktopServices::openUrl(url);
  3907. }
  3908. void OBSBasic::on_actionUploadLastCrashLog_triggered()
  3909. {
  3910. UploadLog("obs-studio/crashes", App()->GetLastCrashLog());
  3911. }
  3912. void OBSBasic::on_actionCheckForUpdates_triggered()
  3913. {
  3914. CheckForUpdates(true);
  3915. }
  3916. void OBSBasic::logUploadFinished(const QString &text, const QString &error)
  3917. {
  3918. ui->menuLogFiles->setEnabled(true);
  3919. if (text.isEmpty()) {
  3920. OBSMessageBox::information(this,
  3921. QTStr("LogReturnDialog.ErrorUploadingLog"),
  3922. error);
  3923. return;
  3924. }
  3925. obs_data_t *returnData = obs_data_create_from_json(QT_TO_UTF8(text));
  3926. string resURL = obs_data_get_string(returnData, "url");
  3927. QString logURL = resURL.c_str();
  3928. obs_data_release(returnData);
  3929. OBSLogReply logDialog(this, logURL);
  3930. logDialog.exec();
  3931. }
  3932. static void RenameListItem(OBSBasic *parent, QListWidget *listWidget,
  3933. obs_source_t *source, const string &name)
  3934. {
  3935. const char *prevName = obs_source_get_name(source);
  3936. if (name == prevName)
  3937. return;
  3938. obs_source_t *foundSource = obs_get_source_by_name(name.c_str());
  3939. QListWidgetItem *listItem = listWidget->currentItem();
  3940. if (foundSource || name.empty()) {
  3941. listItem->setText(QT_UTF8(prevName));
  3942. if (foundSource) {
  3943. OBSMessageBox::information(parent,
  3944. QTStr("NameExists.Title"),
  3945. QTStr("NameExists.Text"));
  3946. } else if (name.empty()) {
  3947. OBSMessageBox::information(parent,
  3948. QTStr("NoNameEntered.Title"),
  3949. QTStr("NoNameEntered.Text"));
  3950. }
  3951. obs_source_release(foundSource);
  3952. } else {
  3953. listItem->setText(QT_UTF8(name.c_str()));
  3954. obs_source_set_name(source, name.c_str());
  3955. }
  3956. }
  3957. void OBSBasic::SceneNameEdited(QWidget *editor,
  3958. QAbstractItemDelegate::EndEditHint endHint)
  3959. {
  3960. OBSScene scene = GetCurrentScene();
  3961. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  3962. string text = QT_TO_UTF8(edit->text().trimmed());
  3963. if (!scene)
  3964. return;
  3965. obs_source_t *source = obs_scene_get_source(scene);
  3966. RenameListItem(this, ui->scenes, source, text);
  3967. if (api)
  3968. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  3969. UNUSED_PARAMETER(endHint);
  3970. }
  3971. void OBSBasic::OpenFilters()
  3972. {
  3973. OBSSceneItem item = GetCurrentSceneItem();
  3974. OBSSource source = obs_sceneitem_get_source(item);
  3975. CreateFiltersWindow(source);
  3976. }
  3977. void OBSBasic::OpenSceneFilters()
  3978. {
  3979. OBSScene scene = GetCurrentScene();
  3980. OBSSource source = obs_scene_get_source(scene);
  3981. CreateFiltersWindow(source);
  3982. }
  3983. #define RECORDING_START \
  3984. "==== Recording Start ==============================================="
  3985. #define RECORDING_STOP \
  3986. "==== Recording Stop ================================================"
  3987. #define REPLAY_BUFFER_START \
  3988. "==== Replay Buffer Start ==========================================="
  3989. #define REPLAY_BUFFER_STOP \
  3990. "==== Replay Buffer Stop ============================================"
  3991. #define STREAMING_START \
  3992. "==== Streaming Start ==============================================="
  3993. #define STREAMING_STOP \
  3994. "==== Streaming Stop ================================================"
  3995. void OBSBasic::StartStreaming()
  3996. {
  3997. if (outputHandler->StreamingActive())
  3998. return;
  3999. if (disableOutputsRef)
  4000. return;
  4001. if (api)
  4002. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTING);
  4003. SaveProject();
  4004. ui->streamButton->setEnabled(false);
  4005. ui->streamButton->setText(QTStr("Basic.Main.Connecting"));
  4006. if (sysTrayStream) {
  4007. sysTrayStream->setEnabled(false);
  4008. sysTrayStream->setText(ui->streamButton->text());
  4009. }
  4010. if (!outputHandler->StartStreaming(service)) {
  4011. QString message = !outputHandler->lastError.empty()
  4012. ? QTStr(outputHandler->lastError.c_str())
  4013. : QTStr("Output.StartFailedGeneric");
  4014. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  4015. ui->streamButton->setEnabled(true);
  4016. ui->streamButton->setChecked(false);
  4017. if (sysTrayStream) {
  4018. sysTrayStream->setText(ui->streamButton->text());
  4019. sysTrayStream->setEnabled(true);
  4020. }
  4021. QMessageBox::critical(this, QTStr("Output.StartStreamFailed"),
  4022. message);
  4023. return;
  4024. }
  4025. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  4026. "BasicWindow", "RecordWhenStreaming");
  4027. if (recordWhenStreaming)
  4028. StartRecording();
  4029. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  4030. "BasicWindow", "ReplayBufferWhileStreaming");
  4031. if (replayBufferWhileStreaming)
  4032. StartReplayBuffer();
  4033. }
  4034. #ifdef _WIN32
  4035. static inline void UpdateProcessPriority()
  4036. {
  4037. const char *priority = config_get_string(App()->GlobalConfig(),
  4038. "General", "ProcessPriority");
  4039. if (priority && strcmp(priority, "Normal") != 0)
  4040. SetProcessPriority(priority);
  4041. }
  4042. static inline void ClearProcessPriority()
  4043. {
  4044. const char *priority = config_get_string(App()->GlobalConfig(),
  4045. "General", "ProcessPriority");
  4046. if (priority && strcmp(priority, "Normal") != 0)
  4047. SetProcessPriority("Normal");
  4048. }
  4049. #else
  4050. #define UpdateProcessPriority() do {} while(false)
  4051. #define ClearProcessPriority() do {} while(false)
  4052. #endif
  4053. inline void OBSBasic::OnActivate()
  4054. {
  4055. if (ui->profileMenu->isEnabled()) {
  4056. ui->profileMenu->setEnabled(false);
  4057. ui->autoConfigure->setEnabled(false);
  4058. App()->IncrementSleepInhibition();
  4059. UpdateProcessPriority();
  4060. if (trayIcon)
  4061. trayIcon->setIcon(QIcon::fromTheme("obs-tray-active",
  4062. QIcon(":/res/images/tray_active.png")));
  4063. }
  4064. }
  4065. inline void OBSBasic::OnDeactivate()
  4066. {
  4067. if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
  4068. ui->profileMenu->setEnabled(true);
  4069. ui->autoConfigure->setEnabled(true);
  4070. App()->DecrementSleepInhibition();
  4071. ClearProcessPriority();
  4072. if (trayIcon)
  4073. trayIcon->setIcon(QIcon::fromTheme("obs-tray",
  4074. QIcon(":/res/images/obs.png")));
  4075. }
  4076. }
  4077. void OBSBasic::StopStreaming()
  4078. {
  4079. SaveProject();
  4080. if (outputHandler->StreamingActive())
  4081. outputHandler->StopStreaming(streamingStopping);
  4082. OnDeactivate();
  4083. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  4084. "BasicWindow", "RecordWhenStreaming");
  4085. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  4086. "BasicWindow", "KeepRecordingWhenStreamStops");
  4087. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  4088. StopRecording();
  4089. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  4090. "BasicWindow", "ReplayBufferWhileStreaming");
  4091. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  4092. "BasicWindow", "KeepReplayBufferStreamStops");
  4093. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  4094. StopReplayBuffer();
  4095. }
  4096. void OBSBasic::ForceStopStreaming()
  4097. {
  4098. SaveProject();
  4099. if (outputHandler->StreamingActive())
  4100. outputHandler->StopStreaming(true);
  4101. OnDeactivate();
  4102. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  4103. "BasicWindow", "RecordWhenStreaming");
  4104. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  4105. "BasicWindow", "KeepRecordingWhenStreamStops");
  4106. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  4107. StopRecording();
  4108. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  4109. "BasicWindow", "ReplayBufferWhileStreaming");
  4110. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  4111. "BasicWindow", "KeepReplayBufferStreamStops");
  4112. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  4113. StopReplayBuffer();
  4114. }
  4115. void OBSBasic::StreamDelayStarting(int sec)
  4116. {
  4117. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  4118. ui->streamButton->setEnabled(true);
  4119. ui->streamButton->setChecked(true);
  4120. if (sysTrayStream) {
  4121. sysTrayStream->setText(ui->streamButton->text());
  4122. sysTrayStream->setEnabled(true);
  4123. }
  4124. if (!startStreamMenu.isNull())
  4125. startStreamMenu->deleteLater();
  4126. startStreamMenu = new QMenu();
  4127. startStreamMenu->addAction(QTStr("Basic.Main.StopStreaming"),
  4128. this, SLOT(StopStreaming()));
  4129. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  4130. this, SLOT(ForceStopStreaming()));
  4131. ui->streamButton->setMenu(startStreamMenu);
  4132. ui->statusbar->StreamDelayStarting(sec);
  4133. OnActivate();
  4134. }
  4135. void OBSBasic::StreamDelayStopping(int sec)
  4136. {
  4137. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  4138. ui->streamButton->setEnabled(true);
  4139. ui->streamButton->setChecked(false);
  4140. if (sysTrayStream) {
  4141. sysTrayStream->setText(ui->streamButton->text());
  4142. sysTrayStream->setEnabled(true);
  4143. }
  4144. if (!startStreamMenu.isNull())
  4145. startStreamMenu->deleteLater();
  4146. startStreamMenu = new QMenu();
  4147. startStreamMenu->addAction(QTStr("Basic.Main.StartStreaming"),
  4148. this, SLOT(StartStreaming()));
  4149. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  4150. this, SLOT(ForceStopStreaming()));
  4151. ui->streamButton->setMenu(startStreamMenu);
  4152. ui->statusbar->StreamDelayStopping(sec);
  4153. if (api)
  4154. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPING);
  4155. }
  4156. void OBSBasic::StreamingStart()
  4157. {
  4158. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  4159. ui->streamButton->setEnabled(true);
  4160. ui->streamButton->setChecked(true);
  4161. ui->statusbar->StreamStarted(outputHandler->streamOutput);
  4162. if (sysTrayStream) {
  4163. sysTrayStream->setText(ui->streamButton->text());
  4164. sysTrayStream->setEnabled(true);
  4165. }
  4166. if (api)
  4167. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTED);
  4168. OnActivate();
  4169. blog(LOG_INFO, STREAMING_START);
  4170. }
  4171. void OBSBasic::StreamStopping()
  4172. {
  4173. ui->streamButton->setText(QTStr("Basic.Main.StoppingStreaming"));
  4174. if (sysTrayStream)
  4175. sysTrayStream->setText(ui->streamButton->text());
  4176. streamingStopping = true;
  4177. if (api)
  4178. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPING);
  4179. }
  4180. void OBSBasic::StreamingStop(int code, QString last_error)
  4181. {
  4182. const char *errorDescription;
  4183. DStr errorMessage;
  4184. bool use_last_error = false;
  4185. switch (code) {
  4186. case OBS_OUTPUT_BAD_PATH:
  4187. errorDescription = Str("Output.ConnectFail.BadPath");
  4188. break;
  4189. case OBS_OUTPUT_CONNECT_FAILED:
  4190. use_last_error = true;
  4191. errorDescription = Str("Output.ConnectFail.ConnectFailed");
  4192. break;
  4193. case OBS_OUTPUT_INVALID_STREAM:
  4194. errorDescription = Str("Output.ConnectFail.InvalidStream");
  4195. break;
  4196. default:
  4197. case OBS_OUTPUT_ERROR:
  4198. use_last_error = true;
  4199. errorDescription = Str("Output.ConnectFail.Error");
  4200. break;
  4201. case OBS_OUTPUT_DISCONNECTED:
  4202. /* doesn't happen if output is set to reconnect. note that
  4203. * reconnects are handled in the output, not in the UI */
  4204. use_last_error = true;
  4205. errorDescription = Str("Output.ConnectFail.Disconnected");
  4206. }
  4207. if (use_last_error && !last_error.isEmpty())
  4208. dstr_printf(errorMessage, "%s\n\n%s", errorDescription,
  4209. QT_TO_UTF8(last_error));
  4210. else
  4211. dstr_copy(errorMessage, errorDescription);
  4212. ui->statusbar->StreamStopped();
  4213. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  4214. ui->streamButton->setEnabled(true);
  4215. ui->streamButton->setChecked(false);
  4216. if (sysTrayStream) {
  4217. sysTrayStream->setText(ui->streamButton->text());
  4218. sysTrayStream->setEnabled(true);
  4219. }
  4220. streamingStopping = false;
  4221. if (api)
  4222. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPED);
  4223. OnDeactivate();
  4224. blog(LOG_INFO, STREAMING_STOP);
  4225. if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  4226. OBSMessageBox::information(this,
  4227. QTStr("Output.ConnectFail.Title"),
  4228. QT_UTF8(errorMessage));
  4229. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  4230. SysTrayNotify(QT_UTF8(errorDescription), QSystemTrayIcon::Warning);
  4231. }
  4232. if (!startStreamMenu.isNull()) {
  4233. ui->streamButton->setMenu(nullptr);
  4234. startStreamMenu->deleteLater();
  4235. startStreamMenu = nullptr;
  4236. }
  4237. }
  4238. void OBSBasic::AutoRemux()
  4239. {
  4240. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  4241. bool advanced = astrcmpi(mode, "Advanced") == 0;
  4242. const char *path = !advanced
  4243. ? config_get_string(basicConfig, "SimpleOutput", "FilePath")
  4244. : config_get_string(basicConfig, "AdvOut", "RecFilePath");
  4245. /* do not save if using FFmpeg output in advanced output mode */
  4246. if (advanced) {
  4247. const char *type = config_get_string(basicConfig, "AdvOut",
  4248. "RecType");
  4249. if (astrcmpi(type, "FFmpeg") == 0) {
  4250. return;
  4251. }
  4252. }
  4253. QString input;
  4254. input += path;
  4255. input += "/";
  4256. input += remuxFilename.c_str();
  4257. QFileInfo fi(remuxFilename.c_str());
  4258. /* do not remux if lossless */
  4259. if (fi.suffix().compare("avi", Qt::CaseInsensitive) == 0) {
  4260. return;
  4261. }
  4262. QString output;
  4263. output += path;
  4264. output += "/";
  4265. output += fi.completeBaseName();
  4266. output += ".mp4";
  4267. OBSRemux *remux = new OBSRemux(path, this, true);
  4268. remux->show();
  4269. remux->AutoRemux(input, output);
  4270. }
  4271. void OBSBasic::StartRecording()
  4272. {
  4273. if (outputHandler->RecordingActive())
  4274. return;
  4275. if (disableOutputsRef)
  4276. return;
  4277. if (api)
  4278. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTING);
  4279. SaveProject();
  4280. if (!outputHandler->StartRecording())
  4281. ui->recordButton->setChecked(false);
  4282. }
  4283. void OBSBasic::RecordStopping()
  4284. {
  4285. ui->recordButton->setText(QTStr("Basic.Main.StoppingRecording"));
  4286. if (sysTrayRecord)
  4287. sysTrayRecord->setText(ui->recordButton->text());
  4288. recordingStopping = true;
  4289. if (api)
  4290. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPING);
  4291. }
  4292. void OBSBasic::StopRecording()
  4293. {
  4294. SaveProject();
  4295. if (outputHandler->RecordingActive())
  4296. outputHandler->StopRecording(recordingStopping);
  4297. OnDeactivate();
  4298. }
  4299. void OBSBasic::RecordingStart()
  4300. {
  4301. ui->statusbar->RecordingStarted(outputHandler->fileOutput);
  4302. ui->recordButton->setText(QTStr("Basic.Main.StopRecording"));
  4303. ui->recordButton->setChecked(true);
  4304. if (sysTrayRecord)
  4305. sysTrayRecord->setText(ui->recordButton->text());
  4306. recordingStopping = false;
  4307. if (api)
  4308. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTED);
  4309. OnActivate();
  4310. blog(LOG_INFO, RECORDING_START);
  4311. }
  4312. void OBSBasic::RecordingStop(int code)
  4313. {
  4314. ui->statusbar->RecordingStopped();
  4315. ui->recordButton->setText(QTStr("Basic.Main.StartRecording"));
  4316. ui->recordButton->setChecked(false);
  4317. if (sysTrayRecord)
  4318. sysTrayRecord->setText(ui->recordButton->text());
  4319. blog(LOG_INFO, RECORDING_STOP);
  4320. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  4321. OBSMessageBox::information(this,
  4322. QTStr("Output.RecordFail.Title"),
  4323. QTStr("Output.RecordFail.Unsupported"));
  4324. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  4325. OBSMessageBox::information(this,
  4326. QTStr("Output.RecordNoSpace.Title"),
  4327. QTStr("Output.RecordNoSpace.Msg"));
  4328. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  4329. OBSMessageBox::information(this,
  4330. QTStr("Output.RecordError.Title"),
  4331. QTStr("Output.RecordError.Msg"));
  4332. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  4333. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  4334. QSystemTrayIcon::Warning);
  4335. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  4336. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  4337. QSystemTrayIcon::Warning);
  4338. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  4339. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  4340. QSystemTrayIcon::Warning);
  4341. }
  4342. if (api)
  4343. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPED);
  4344. if (remuxAfterRecord)
  4345. AutoRemux();
  4346. OnDeactivate();
  4347. }
  4348. #define RP_NO_HOTKEY_TITLE QTStr("Output.ReplayBuffer.NoHotkey.Title")
  4349. #define RP_NO_HOTKEY_TEXT QTStr("Output.ReplayBuffer.NoHotkey.Msg")
  4350. void OBSBasic::StartReplayBuffer()
  4351. {
  4352. if (!outputHandler || !outputHandler->replayBuffer)
  4353. return;
  4354. if (outputHandler->ReplayBufferActive())
  4355. return;
  4356. if (disableOutputsRef)
  4357. return;
  4358. if (!NoSourcesConfirmation()) {
  4359. replayBufferButton->setChecked(false);
  4360. return;
  4361. }
  4362. obs_output_t *output = outputHandler->replayBuffer;
  4363. obs_data_t *hotkeys = obs_hotkeys_save_output(output);
  4364. obs_data_array_t *bindings = obs_data_get_array(hotkeys,
  4365. "ReplayBuffer.Save");
  4366. size_t count = obs_data_array_count(bindings);
  4367. obs_data_array_release(bindings);
  4368. obs_data_release(hotkeys);
  4369. if (!count) {
  4370. OBSMessageBox::information(this,
  4371. RP_NO_HOTKEY_TITLE,
  4372. RP_NO_HOTKEY_TEXT);
  4373. replayBufferButton->setChecked(false);
  4374. return;
  4375. }
  4376. if (api)
  4377. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING);
  4378. SaveProject();
  4379. if (!outputHandler->StartReplayBuffer())
  4380. replayBufferButton->setChecked(false);
  4381. }
  4382. void OBSBasic::ReplayBufferStopping()
  4383. {
  4384. if (!outputHandler || !outputHandler->replayBuffer)
  4385. return;
  4386. replayBufferButton->setText(QTStr("Basic.Main.StoppingReplayBuffer"));
  4387. if (sysTrayReplayBuffer)
  4388. sysTrayReplayBuffer->setText(replayBufferButton->text());
  4389. replayBufferStopping = true;
  4390. if (api)
  4391. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING);
  4392. }
  4393. void OBSBasic::StopReplayBuffer()
  4394. {
  4395. if (!outputHandler || !outputHandler->replayBuffer)
  4396. return;
  4397. SaveProject();
  4398. if (outputHandler->ReplayBufferActive())
  4399. outputHandler->StopReplayBuffer(replayBufferStopping);
  4400. OnDeactivate();
  4401. }
  4402. void OBSBasic::ReplayBufferStart()
  4403. {
  4404. if (!outputHandler || !outputHandler->replayBuffer)
  4405. return;
  4406. replayBufferButton->setText(QTStr("Basic.Main.StopReplayBuffer"));
  4407. replayBufferButton->setChecked(true);
  4408. if (sysTrayReplayBuffer)
  4409. sysTrayReplayBuffer->setText(replayBufferButton->text());
  4410. replayBufferStopping = false;
  4411. if (api)
  4412. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED);
  4413. OnActivate();
  4414. blog(LOG_INFO, REPLAY_BUFFER_START);
  4415. }
  4416. void OBSBasic::ReplayBufferSave()
  4417. {
  4418. if (!outputHandler || !outputHandler->replayBuffer)
  4419. return;
  4420. if (!outputHandler->ReplayBufferActive())
  4421. return;
  4422. calldata_t cd = {0};
  4423. proc_handler_t *ph = obs_output_get_proc_handler(
  4424. outputHandler->replayBuffer);
  4425. proc_handler_call(ph, "save", &cd);
  4426. calldata_free(&cd);
  4427. }
  4428. void OBSBasic::ReplayBufferStop(int code)
  4429. {
  4430. if (!outputHandler || !outputHandler->replayBuffer)
  4431. return;
  4432. replayBufferButton->setText(QTStr("Basic.Main.StartReplayBuffer"));
  4433. replayBufferButton->setChecked(false);
  4434. if (sysTrayReplayBuffer)
  4435. sysTrayReplayBuffer->setText(replayBufferButton->text());
  4436. blog(LOG_INFO, REPLAY_BUFFER_STOP);
  4437. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  4438. OBSMessageBox::information(this,
  4439. QTStr("Output.RecordFail.Title"),
  4440. QTStr("Output.RecordFail.Unsupported"));
  4441. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  4442. OBSMessageBox::information(this,
  4443. QTStr("Output.RecordNoSpace.Title"),
  4444. QTStr("Output.RecordNoSpace.Msg"));
  4445. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  4446. OBSMessageBox::information(this,
  4447. QTStr("Output.RecordError.Title"),
  4448. QTStr("Output.RecordError.Msg"));
  4449. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  4450. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  4451. QSystemTrayIcon::Warning);
  4452. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  4453. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  4454. QSystemTrayIcon::Warning);
  4455. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  4456. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  4457. QSystemTrayIcon::Warning);
  4458. }
  4459. if (api)
  4460. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED);
  4461. OnDeactivate();
  4462. }
  4463. bool OBSBasic::NoSourcesConfirmation()
  4464. {
  4465. if (CountVideoSources() == 0 && isVisible()) {
  4466. QString msg;
  4467. msg = QTStr("NoSources.Text");
  4468. msg += "\n\n";
  4469. msg += QTStr("NoSources.Text.AddSource");
  4470. QMessageBox messageBox(this);
  4471. messageBox.setWindowTitle(QTStr("NoSources.Title"));
  4472. messageBox.setText(msg);
  4473. QAbstractButton *Yes = messageBox.addButton(QTStr("Yes"),
  4474. QMessageBox::YesRole);
  4475. messageBox.addButton(QTStr("No"), QMessageBox::NoRole);
  4476. messageBox.setIcon(QMessageBox::Question);
  4477. messageBox.exec();
  4478. if (messageBox.clickedButton() != Yes)
  4479. return false;
  4480. }
  4481. return true;
  4482. }
  4483. void OBSBasic::on_streamButton_clicked()
  4484. {
  4485. if (outputHandler->StreamingActive()) {
  4486. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  4487. "WarnBeforeStoppingStream");
  4488. if (confirm && isVisible()) {
  4489. QMessageBox::StandardButton button =
  4490. OBSMessageBox::question(this,
  4491. QTStr("ConfirmStop.Title"),
  4492. QTStr("ConfirmStop.Text"));
  4493. if (button == QMessageBox::No) {
  4494. ui->streamButton->setChecked(true);
  4495. return;
  4496. }
  4497. }
  4498. StopStreaming();
  4499. } else {
  4500. if (!NoSourcesConfirmation()) {
  4501. ui->streamButton->setChecked(false);
  4502. return;
  4503. }
  4504. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  4505. "WarnBeforeStartingStream");
  4506. obs_data_t *settings = obs_service_get_settings(service);
  4507. bool bwtest = obs_data_get_bool(settings, "bwtest");
  4508. obs_data_release(settings);
  4509. if (bwtest && isVisible()) {
  4510. QMessageBox::StandardButton button =
  4511. OBSMessageBox::question(this,
  4512. QTStr("ConfirmBWTest.Title"),
  4513. QTStr("ConfirmBWTest.Text"));
  4514. if (button == QMessageBox::No) {
  4515. ui->streamButton->setChecked(false);
  4516. return;
  4517. }
  4518. } else if (confirm && isVisible()) {
  4519. QMessageBox::StandardButton button =
  4520. OBSMessageBox::question(this,
  4521. QTStr("ConfirmStart.Title"),
  4522. QTStr("ConfirmStart.Text"));
  4523. if (button == QMessageBox::No) {
  4524. ui->streamButton->setChecked(false);
  4525. return;
  4526. }
  4527. }
  4528. StartStreaming();
  4529. }
  4530. }
  4531. void OBSBasic::on_recordButton_clicked()
  4532. {
  4533. if (outputHandler->RecordingActive()) {
  4534. StopRecording();
  4535. } else {
  4536. if (!NoSourcesConfirmation()) {
  4537. ui->recordButton->setChecked(false);
  4538. return;
  4539. }
  4540. StartRecording();
  4541. }
  4542. }
  4543. void OBSBasic::on_settingsButton_clicked()
  4544. {
  4545. on_action_Settings_triggered();
  4546. }
  4547. void OBSBasic::on_actionHelpPortal_triggered()
  4548. {
  4549. QUrl url = QUrl("https://obsproject.com/help", QUrl::TolerantMode);
  4550. QDesktopServices::openUrl(url);
  4551. }
  4552. void OBSBasic::on_actionWebsite_triggered()
  4553. {
  4554. QUrl url = QUrl("https://obsproject.com", QUrl::TolerantMode);
  4555. QDesktopServices::openUrl(url);
  4556. }
  4557. void OBSBasic::on_actionDiscord_triggered()
  4558. {
  4559. QUrl url = QUrl("https://obsproject.com/discord", QUrl::TolerantMode);
  4560. QDesktopServices::openUrl(url);
  4561. }
  4562. void OBSBasic::on_actionShowSettingsFolder_triggered()
  4563. {
  4564. char path[512];
  4565. int ret = GetConfigPath(path, 512, "obs-studio");
  4566. if (ret <= 0)
  4567. return;
  4568. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  4569. }
  4570. void OBSBasic::on_actionShowProfileFolder_triggered()
  4571. {
  4572. char path[512];
  4573. int ret = GetProfilePath(path, 512, "");
  4574. if (ret <= 0)
  4575. return;
  4576. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  4577. }
  4578. int OBSBasic::GetTopSelectedSourceItem()
  4579. {
  4580. QModelIndexList selectedItems =
  4581. ui->sources->selectionModel()->selectedIndexes();
  4582. return selectedItems.count() ? selectedItems[0].row() : -1;
  4583. }
  4584. void OBSBasic::on_preview_customContextMenuRequested(const QPoint &pos)
  4585. {
  4586. CreateSourcePopupMenu(GetTopSelectedSourceItem(), true);
  4587. UNUSED_PARAMETER(pos);
  4588. }
  4589. void OBSBasic::on_program_customContextMenuRequested(const QPoint&)
  4590. {
  4591. QMenu popup(this);
  4592. QPointer<QMenu> studioProgramProjector;
  4593. studioProgramProjector = new QMenu(
  4594. QTStr("StudioProgramProjector"));
  4595. AddProjectorMenuMonitors(studioProgramProjector, this,
  4596. SLOT(OpenStudioProgramProjector()));
  4597. popup.addMenu(studioProgramProjector);
  4598. QAction *studioProgramWindow = popup.addAction(
  4599. QTStr("StudioProgramWindow"),
  4600. this, SLOT(OpenStudioProgramWindow()));
  4601. popup.addAction(studioProgramWindow);
  4602. popup.exec(QCursor::pos());
  4603. }
  4604. void OBSBasic::on_previewDisabledLabel_customContextMenuRequested(
  4605. const QPoint &pos)
  4606. {
  4607. QMenu popup(this);
  4608. delete previewProjectorMain;
  4609. QAction *action = popup.addAction(
  4610. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  4611. this, SLOT(TogglePreview()));
  4612. action->setCheckable(true);
  4613. action->setChecked(obs_display_enabled(ui->preview->GetDisplay()));
  4614. previewProjectorMain = new QMenu(QTStr("PreviewProjector"));
  4615. AddProjectorMenuMonitors(previewProjectorMain, this,
  4616. SLOT(OpenPreviewProjector()));
  4617. QAction *previewWindow = popup.addAction(
  4618. QTStr("PreviewWindow"),
  4619. this, SLOT(OpenPreviewWindow()));
  4620. popup.addMenu(previewProjectorMain);
  4621. popup.addAction(previewWindow);
  4622. popup.exec(QCursor::pos());
  4623. UNUSED_PARAMETER(pos);
  4624. }
  4625. void OBSBasic::on_actionAlwaysOnTop_triggered()
  4626. {
  4627. #ifndef _WIN32
  4628. /* Make sure all dialogs are safely and successfully closed before
  4629. * switching the always on top mode due to the fact that windows all
  4630. * have to be recreated, so queue the actual toggle to happen after
  4631. * all events related to closing the dialogs have finished */
  4632. CloseDialogs();
  4633. #endif
  4634. QMetaObject::invokeMethod(this, "ToggleAlwaysOnTop",
  4635. Qt::QueuedConnection);
  4636. }
  4637. void OBSBasic::ToggleAlwaysOnTop()
  4638. {
  4639. bool isAlwaysOnTop = IsAlwaysOnTop(this);
  4640. ui->actionAlwaysOnTop->setChecked(!isAlwaysOnTop);
  4641. SetAlwaysOnTop(this, !isAlwaysOnTop);
  4642. show();
  4643. }
  4644. void OBSBasic::GetFPSCommon(uint32_t &num, uint32_t &den) const
  4645. {
  4646. const char *val = config_get_string(basicConfig, "Video", "FPSCommon");
  4647. if (strcmp(val, "10") == 0) {
  4648. num = 10;
  4649. den = 1;
  4650. } else if (strcmp(val, "20") == 0) {
  4651. num = 20;
  4652. den = 1;
  4653. } else if (strcmp(val, "24 NTSC") == 0) {
  4654. num = 24000;
  4655. den = 1001;
  4656. } else if (strcmp(val, "25 PAL") == 0) {
  4657. num = 25;
  4658. den = 1;
  4659. } else if (strcmp(val, "29.97") == 0) {
  4660. num = 30000;
  4661. den = 1001;
  4662. } else if (strcmp(val, "48") == 0) {
  4663. num = 48;
  4664. den = 1;
  4665. } else if (strcmp(val, "50 PAL") == 0) {
  4666. num = 50;
  4667. den = 1;
  4668. } else if (strcmp(val, "59.94") == 0) {
  4669. num = 60000;
  4670. den = 1001;
  4671. } else if (strcmp(val, "60") == 0) {
  4672. num = 60;
  4673. den = 1;
  4674. } else {
  4675. num = 30;
  4676. den = 1;
  4677. }
  4678. }
  4679. void OBSBasic::GetFPSInteger(uint32_t &num, uint32_t &den) const
  4680. {
  4681. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSInt");
  4682. den = 1;
  4683. }
  4684. void OBSBasic::GetFPSFraction(uint32_t &num, uint32_t &den) const
  4685. {
  4686. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNum");
  4687. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSDen");
  4688. }
  4689. void OBSBasic::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
  4690. {
  4691. num = 1000000000;
  4692. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNS");
  4693. }
  4694. void OBSBasic::GetConfigFPS(uint32_t &num, uint32_t &den) const
  4695. {
  4696. uint32_t type = config_get_uint(basicConfig, "Video", "FPSType");
  4697. if (type == 1) //"Integer"
  4698. GetFPSInteger(num, den);
  4699. else if (type == 2) //"Fraction"
  4700. GetFPSFraction(num, den);
  4701. else if (false) //"Nanoseconds", currently not implemented
  4702. GetFPSNanoseconds(num, den);
  4703. else
  4704. GetFPSCommon(num, den);
  4705. }
  4706. config_t *OBSBasic::Config() const
  4707. {
  4708. return basicConfig;
  4709. }
  4710. void OBSBasic::on_actionEditTransform_triggered()
  4711. {
  4712. if (transformWindow)
  4713. transformWindow->close();
  4714. transformWindow = new OBSBasicTransform(this);
  4715. transformWindow->show();
  4716. transformWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  4717. }
  4718. static obs_transform_info copiedTransformInfo;
  4719. static obs_sceneitem_crop copiedCropInfo;
  4720. void OBSBasic::on_actionCopyTransform_triggered()
  4721. {
  4722. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4723. {
  4724. if (!obs_sceneitem_selected(item))
  4725. return true;
  4726. obs_sceneitem_defer_update_begin(item);
  4727. obs_sceneitem_get_info(item, &copiedTransformInfo);
  4728. obs_sceneitem_get_crop(item, &copiedCropInfo);
  4729. obs_sceneitem_defer_update_end(item);
  4730. UNUSED_PARAMETER(scene);
  4731. UNUSED_PARAMETER(param);
  4732. return true;
  4733. };
  4734. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4735. ui->actionPasteTransform->setEnabled(true);
  4736. }
  4737. void OBSBasic::on_actionPasteTransform_triggered()
  4738. {
  4739. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4740. {
  4741. if (!obs_sceneitem_selected(item))
  4742. return true;
  4743. obs_sceneitem_defer_update_begin(item);
  4744. obs_sceneitem_set_info(item, &copiedTransformInfo);
  4745. obs_sceneitem_set_crop(item, &copiedCropInfo);
  4746. obs_sceneitem_defer_update_end(item);
  4747. UNUSED_PARAMETER(scene);
  4748. UNUSED_PARAMETER(param);
  4749. return true;
  4750. };
  4751. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4752. }
  4753. static bool reset_tr(obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4754. {
  4755. if (obs_sceneitem_is_group(item))
  4756. obs_sceneitem_group_enum_items(item, reset_tr, nullptr);
  4757. if (!obs_sceneitem_selected(item))
  4758. return true;
  4759. obs_sceneitem_defer_update_begin(item);
  4760. obs_transform_info info;
  4761. vec2_set(&info.pos, 0.0f, 0.0f);
  4762. vec2_set(&info.scale, 1.0f, 1.0f);
  4763. info.rot = 0.0f;
  4764. info.alignment = OBS_ALIGN_TOP | OBS_ALIGN_LEFT;
  4765. info.bounds_type = OBS_BOUNDS_NONE;
  4766. info.bounds_alignment = OBS_ALIGN_CENTER;
  4767. vec2_set(&info.bounds, 0.0f, 0.0f);
  4768. obs_sceneitem_set_info(item, &info);
  4769. obs_sceneitem_crop crop = {};
  4770. obs_sceneitem_set_crop(item, &crop);
  4771. obs_sceneitem_defer_update_end(item);
  4772. UNUSED_PARAMETER(scene);
  4773. UNUSED_PARAMETER(param);
  4774. return true;
  4775. }
  4776. void OBSBasic::on_actionResetTransform_triggered()
  4777. {
  4778. obs_scene_enum_items(GetCurrentScene(), reset_tr, nullptr);
  4779. }
  4780. static void GetItemBox(obs_sceneitem_t *item, vec3 &tl, vec3 &br)
  4781. {
  4782. matrix4 boxTransform;
  4783. obs_sceneitem_get_box_transform(item, &boxTransform);
  4784. vec3_set(&tl, M_INFINITE, M_INFINITE, 0.0f);
  4785. vec3_set(&br, -M_INFINITE, -M_INFINITE, 0.0f);
  4786. auto GetMinPos = [&] (float x, float y)
  4787. {
  4788. vec3 pos;
  4789. vec3_set(&pos, x, y, 0.0f);
  4790. vec3_transform(&pos, &pos, &boxTransform);
  4791. vec3_min(&tl, &tl, &pos);
  4792. vec3_max(&br, &br, &pos);
  4793. };
  4794. GetMinPos(0.0f, 0.0f);
  4795. GetMinPos(1.0f, 0.0f);
  4796. GetMinPos(0.0f, 1.0f);
  4797. GetMinPos(1.0f, 1.0f);
  4798. }
  4799. static vec3 GetItemTL(obs_sceneitem_t *item)
  4800. {
  4801. vec3 tl, br;
  4802. GetItemBox(item, tl, br);
  4803. return tl;
  4804. }
  4805. static void SetItemTL(obs_sceneitem_t *item, const vec3 &tl)
  4806. {
  4807. vec3 newTL;
  4808. vec2 pos;
  4809. obs_sceneitem_get_pos(item, &pos);
  4810. newTL = GetItemTL(item);
  4811. pos.x += tl.x - newTL.x;
  4812. pos.y += tl.y - newTL.y;
  4813. obs_sceneitem_set_pos(item, &pos);
  4814. }
  4815. static bool RotateSelectedSources(obs_scene_t *scene, obs_sceneitem_t *item,
  4816. void *param)
  4817. {
  4818. if (obs_sceneitem_is_group(item))
  4819. obs_sceneitem_group_enum_items(item, RotateSelectedSources,
  4820. param);
  4821. if (!obs_sceneitem_selected(item))
  4822. return true;
  4823. float rot = *reinterpret_cast<float*>(param);
  4824. vec3 tl = GetItemTL(item);
  4825. rot += obs_sceneitem_get_rot(item);
  4826. if (rot >= 360.0f) rot -= 360.0f;
  4827. else if (rot <= -360.0f) rot += 360.0f;
  4828. obs_sceneitem_set_rot(item, rot);
  4829. obs_sceneitem_force_update_transform(item);
  4830. SetItemTL(item, tl);
  4831. UNUSED_PARAMETER(scene);
  4832. return true;
  4833. };
  4834. void OBSBasic::on_actionRotate90CW_triggered()
  4835. {
  4836. float f90CW = 90.0f;
  4837. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CW);
  4838. }
  4839. void OBSBasic::on_actionRotate90CCW_triggered()
  4840. {
  4841. float f90CCW = -90.0f;
  4842. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CCW);
  4843. }
  4844. void OBSBasic::on_actionRotate180_triggered()
  4845. {
  4846. float f180 = 180.0f;
  4847. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f180);
  4848. }
  4849. static bool MultiplySelectedItemScale(obs_scene_t *scene, obs_sceneitem_t *item,
  4850. void *param)
  4851. {
  4852. vec2 &mul = *reinterpret_cast<vec2*>(param);
  4853. if (obs_sceneitem_is_group(item))
  4854. obs_sceneitem_group_enum_items(item, MultiplySelectedItemScale,
  4855. param);
  4856. if (!obs_sceneitem_selected(item))
  4857. return true;
  4858. vec3 tl = GetItemTL(item);
  4859. vec2 scale;
  4860. obs_sceneitem_get_scale(item, &scale);
  4861. vec2_mul(&scale, &scale, &mul);
  4862. obs_sceneitem_set_scale(item, &scale);
  4863. obs_sceneitem_force_update_transform(item);
  4864. SetItemTL(item, tl);
  4865. UNUSED_PARAMETER(scene);
  4866. return true;
  4867. }
  4868. void OBSBasic::on_actionFlipHorizontal_triggered()
  4869. {
  4870. vec2 scale;
  4871. vec2_set(&scale, -1.0f, 1.0f);
  4872. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4873. &scale);
  4874. }
  4875. void OBSBasic::on_actionFlipVertical_triggered()
  4876. {
  4877. vec2 scale;
  4878. vec2_set(&scale, 1.0f, -1.0f);
  4879. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4880. &scale);
  4881. }
  4882. static bool CenterAlignSelectedItems(obs_scene_t *scene, obs_sceneitem_t *item,
  4883. void *param)
  4884. {
  4885. obs_bounds_type boundsType = *reinterpret_cast<obs_bounds_type*>(param);
  4886. if (obs_sceneitem_is_group(item))
  4887. obs_sceneitem_group_enum_items(item, CenterAlignSelectedItems,
  4888. param);
  4889. if (!obs_sceneitem_selected(item))
  4890. return true;
  4891. obs_video_info ovi;
  4892. obs_get_video_info(&ovi);
  4893. obs_transform_info itemInfo;
  4894. vec2_set(&itemInfo.pos, 0.0f, 0.0f);
  4895. vec2_set(&itemInfo.scale, 1.0f, 1.0f);
  4896. itemInfo.alignment = OBS_ALIGN_LEFT | OBS_ALIGN_TOP;
  4897. itemInfo.rot = 0.0f;
  4898. vec2_set(&itemInfo.bounds,
  4899. float(ovi.base_width), float(ovi.base_height));
  4900. itemInfo.bounds_type = boundsType;
  4901. itemInfo.bounds_alignment = OBS_ALIGN_CENTER;
  4902. obs_sceneitem_set_info(item, &itemInfo);
  4903. UNUSED_PARAMETER(scene);
  4904. return true;
  4905. }
  4906. void OBSBasic::on_actionFitToScreen_triggered()
  4907. {
  4908. obs_bounds_type boundsType = OBS_BOUNDS_SCALE_INNER;
  4909. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4910. &boundsType);
  4911. }
  4912. void OBSBasic::on_actionStretchToScreen_triggered()
  4913. {
  4914. obs_bounds_type boundsType = OBS_BOUNDS_STRETCH;
  4915. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4916. &boundsType);
  4917. }
  4918. enum class CenterType {
  4919. Scene,
  4920. Vertical,
  4921. Horizontal
  4922. };
  4923. static bool center_to_scene(obs_scene_t *, obs_sceneitem_t *item, void *param)
  4924. {
  4925. CenterType centerType = *reinterpret_cast<CenterType*>(param);
  4926. vec3 tl, br, itemCenter, screenCenter, offset;
  4927. obs_video_info ovi;
  4928. obs_transform_info oti;
  4929. if (obs_sceneitem_is_group(item))
  4930. obs_sceneitem_group_enum_items(item, center_to_scene,
  4931. &centerType);
  4932. if (!obs_sceneitem_selected(item))
  4933. return true;
  4934. obs_get_video_info(&ovi);
  4935. obs_sceneitem_get_info(item, &oti);
  4936. if (centerType == CenterType::Scene)
  4937. vec3_set(&screenCenter, float(ovi.base_width),
  4938. float(ovi.base_height), 0.0f);
  4939. else if (centerType == CenterType::Vertical)
  4940. vec3_set(&screenCenter, float(oti.bounds.x),
  4941. float(ovi.base_height), 0.0f);
  4942. else if (centerType == CenterType::Horizontal)
  4943. vec3_set(&screenCenter, float(ovi.base_width),
  4944. float(oti.bounds.y), 0.0f);
  4945. vec3_mulf(&screenCenter, &screenCenter, 0.5f);
  4946. GetItemBox(item, tl, br);
  4947. vec3_sub(&itemCenter, &br, &tl);
  4948. vec3_mulf(&itemCenter, &itemCenter, 0.5f);
  4949. vec3_add(&itemCenter, &itemCenter, &tl);
  4950. vec3_sub(&offset, &screenCenter, &itemCenter);
  4951. vec3_add(&tl, &tl, &offset);
  4952. if (centerType == CenterType::Vertical)
  4953. tl.x = oti.pos.x;
  4954. else if (centerType == CenterType::Horizontal)
  4955. tl.y = oti.pos.y;
  4956. SetItemTL(item, tl);
  4957. return true;
  4958. };
  4959. void OBSBasic::on_actionCenterToScreen_triggered()
  4960. {
  4961. CenterType centerType = CenterType::Scene;
  4962. obs_scene_enum_items(GetCurrentScene(), center_to_scene, &centerType);
  4963. }
  4964. void OBSBasic::on_actionVerticalCenter_triggered()
  4965. {
  4966. CenterType centerType = CenterType::Vertical;
  4967. obs_scene_enum_items(GetCurrentScene(), center_to_scene, &centerType);
  4968. }
  4969. void OBSBasic::on_actionHorizontalCenter_triggered()
  4970. {
  4971. CenterType centerType = CenterType::Horizontal;
  4972. obs_scene_enum_items(GetCurrentScene(), center_to_scene, &centerType);
  4973. }
  4974. void OBSBasic::EnablePreviewDisplay(bool enable)
  4975. {
  4976. obs_display_set_enabled(ui->preview->GetDisplay(), enable);
  4977. ui->preview->setVisible(enable);
  4978. ui->previewDisabledLabel->setVisible(!enable);
  4979. }
  4980. void OBSBasic::TogglePreview()
  4981. {
  4982. previewEnabled = !previewEnabled;
  4983. EnablePreviewDisplay(previewEnabled);
  4984. }
  4985. static bool nudge_callback(obs_scene_t*, obs_sceneitem_t *item, void *param)
  4986. {
  4987. if (obs_sceneitem_locked(item))
  4988. return true;
  4989. struct vec2 &offset = *reinterpret_cast<struct vec2*>(param);
  4990. struct vec2 pos;
  4991. if (!obs_sceneitem_selected(item)) {
  4992. if (obs_sceneitem_is_group(item)) {
  4993. struct vec3 offset3;
  4994. vec3_set(&offset3, offset.x, offset.y, 0.0f);
  4995. struct matrix4 matrix;
  4996. obs_sceneitem_get_draw_transform(item, &matrix);
  4997. vec4_set(&matrix.t, 0.0f, 0.0f, 0.0f, 1.0f);
  4998. matrix4_inv(&matrix, &matrix);
  4999. vec3_transform(&offset3, &offset3, &matrix);
  5000. struct vec2 new_offset;
  5001. vec2_set(&new_offset, offset3.x, offset3.y);
  5002. obs_sceneitem_group_enum_items(item, nudge_callback,
  5003. &new_offset);
  5004. }
  5005. return true;
  5006. }
  5007. obs_sceneitem_get_pos(item, &pos);
  5008. vec2_add(&pos, &pos, &offset);
  5009. obs_sceneitem_set_pos(item, &pos);
  5010. return true;
  5011. }
  5012. void OBSBasic::Nudge(int dist, MoveDir dir)
  5013. {
  5014. if (ui->preview->Locked())
  5015. return;
  5016. struct vec2 offset;
  5017. vec2_set(&offset, 0.0f, 0.0f);
  5018. switch (dir) {
  5019. case MoveDir::Up: offset.y = (float)-dist; break;
  5020. case MoveDir::Down: offset.y = (float) dist; break;
  5021. case MoveDir::Left: offset.x = (float)-dist; break;
  5022. case MoveDir::Right: offset.x = (float) dist; break;
  5023. }
  5024. obs_scene_enum_items(GetCurrentScene(), nudge_callback, &offset);
  5025. }
  5026. void OBSBasic::NudgeUp() {Nudge(1, MoveDir::Up);}
  5027. void OBSBasic::NudgeDown() {Nudge(1, MoveDir::Down);}
  5028. void OBSBasic::NudgeLeft() {Nudge(1, MoveDir::Left);}
  5029. void OBSBasic::NudgeRight() {Nudge(1, MoveDir::Right);}
  5030. OBSProjector *OBSBasic::OpenProjector(obs_source_t *source, int monitor,
  5031. QString title, ProjectorType type)
  5032. {
  5033. /* seriously? 10 monitors? */
  5034. if (monitor > 9 || monitor > QGuiApplication::screens().size() - 1)
  5035. return nullptr;
  5036. OBSProjector *projector = new OBSProjector(nullptr, source, monitor,
  5037. title, type);
  5038. if (monitor < 0) {
  5039. for (auto &projPtr : windowProjectors) {
  5040. if (!projPtr) {
  5041. projPtr = projector;
  5042. projector = nullptr;
  5043. }
  5044. }
  5045. if (projector)
  5046. windowProjectors.push_back(projector);
  5047. } else {
  5048. delete projectors[monitor];
  5049. projectors[monitor].clear();
  5050. projectors[monitor] = projector;
  5051. }
  5052. return projector;
  5053. }
  5054. void OBSBasic::OpenStudioProgramProjector()
  5055. {
  5056. int monitor = sender()->property("monitor").toInt();
  5057. OpenProjector(nullptr, monitor, nullptr, ProjectorType::StudioProgram);
  5058. }
  5059. void OBSBasic::OpenPreviewProjector()
  5060. {
  5061. int monitor = sender()->property("monitor").toInt();
  5062. OpenProjector(nullptr, monitor, nullptr, ProjectorType::Preview);
  5063. }
  5064. void OBSBasic::OpenSourceProjector()
  5065. {
  5066. int monitor = sender()->property("monitor").toInt();
  5067. OBSSceneItem item = GetCurrentSceneItem();
  5068. if (!item)
  5069. return;
  5070. OpenProjector(obs_sceneitem_get_source(item), monitor, nullptr,
  5071. ProjectorType::Source);
  5072. }
  5073. void OBSBasic::OpenMultiviewProjector()
  5074. {
  5075. int monitor = sender()->property("monitor").toInt();
  5076. OpenProjector(nullptr, monitor, nullptr, ProjectorType::Multiview);
  5077. }
  5078. void OBSBasic::OpenSceneProjector()
  5079. {
  5080. int monitor = sender()->property("monitor").toInt();
  5081. OBSScene scene = GetCurrentScene();
  5082. if (!scene)
  5083. return;
  5084. OpenProjector(obs_scene_get_source(scene), monitor, nullptr,
  5085. ProjectorType::Scene);
  5086. }
  5087. void OBSBasic::OpenStudioProgramWindow()
  5088. {
  5089. OpenProjector(nullptr, -1, QTStr("StudioProgramWindow"),
  5090. ProjectorType::StudioProgram);
  5091. }
  5092. void OBSBasic::OpenPreviewWindow()
  5093. {
  5094. OpenProjector(nullptr, -1, QTStr("PreviewWindow"),
  5095. ProjectorType::Preview);
  5096. }
  5097. void OBSBasic::OpenSourceWindow()
  5098. {
  5099. OBSSceneItem item = GetCurrentSceneItem();
  5100. if (!item)
  5101. return;
  5102. OBSSource source = obs_sceneitem_get_source(item);
  5103. QString title = QString::fromUtf8(obs_source_get_name(source));
  5104. OpenProjector(obs_sceneitem_get_source(item), -1, title,
  5105. ProjectorType::Source);
  5106. }
  5107. void OBSBasic::OpenMultiviewWindow()
  5108. {
  5109. OpenProjector(nullptr, -1, QTStr("MultiviewWindowed"),
  5110. ProjectorType::Multiview);
  5111. }
  5112. void OBSBasic::OpenSceneWindow()
  5113. {
  5114. OBSScene scene = GetCurrentScene();
  5115. if (!scene)
  5116. return;
  5117. OBSSource source = obs_scene_get_source(scene);
  5118. QString title = QString::fromUtf8(obs_source_get_name(source));
  5119. OpenProjector(obs_scene_get_source(scene), -1, title,
  5120. ProjectorType::Scene);
  5121. }
  5122. void OBSBasic::OpenSavedProjectors()
  5123. {
  5124. for (SavedProjectorInfo *info : savedProjectorsArray) {
  5125. OBSProjector *projector = nullptr;
  5126. switch (info->type) {
  5127. case ProjectorType::Source:
  5128. case ProjectorType::Scene: {
  5129. OBSSource source = obs_get_source_by_name(
  5130. info->name.c_str());
  5131. if (!source)
  5132. continue;
  5133. QString title = nullptr;
  5134. if (info->monitor < 0)
  5135. title = QString::fromUtf8(
  5136. obs_source_get_name(source));
  5137. projector = OpenProjector(source, info->monitor, title,
  5138. info->type);
  5139. obs_source_release(source);
  5140. break;
  5141. }
  5142. case ProjectorType::Preview: {
  5143. projector = OpenProjector(nullptr, info->monitor,
  5144. QTStr("PreviewWindow"),
  5145. ProjectorType::Preview);
  5146. break;
  5147. }
  5148. case ProjectorType::StudioProgram: {
  5149. projector = OpenProjector(nullptr, info->monitor,
  5150. QTStr("StudioProgramWindow"),
  5151. ProjectorType::StudioProgram);
  5152. break;
  5153. }
  5154. case ProjectorType::Multiview: {
  5155. projector = OpenProjector(nullptr, info->monitor,
  5156. QTStr("MultiviewWindowed"),
  5157. ProjectorType::Multiview);
  5158. break;
  5159. }
  5160. }
  5161. if (projector && !info->geometry.empty() && info->monitor < 0) {
  5162. QByteArray byteArray = QByteArray::fromBase64(
  5163. QByteArray(info->geometry.c_str()));
  5164. projector->restoreGeometry(byteArray);
  5165. if (!WindowPositionValid(projector->normalGeometry())) {
  5166. QRect rect = App()->desktop()->geometry();
  5167. projector->setGeometry(QStyle::alignedRect(
  5168. Qt::LeftToRight,
  5169. Qt::AlignCenter, size(), rect));
  5170. }
  5171. }
  5172. }
  5173. }
  5174. void OBSBasic::on_actionFullscreenInterface_triggered()
  5175. {
  5176. if (!fullscreenInterface)
  5177. showFullScreen();
  5178. else
  5179. showNormal();
  5180. fullscreenInterface = !fullscreenInterface;
  5181. }
  5182. void OBSBasic::UpdateTitleBar()
  5183. {
  5184. stringstream name;
  5185. const char *profile = config_get_string(App()->GlobalConfig(),
  5186. "Basic", "Profile");
  5187. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  5188. "Basic", "SceneCollection");
  5189. name << "OBS ";
  5190. if (previewProgramMode)
  5191. name << "Studio ";
  5192. name << App()->GetVersionString();
  5193. if (App()->IsPortableMode())
  5194. name << " - Portable Mode";
  5195. name << " - " << Str("TitleBar.Profile") << ": " << profile;
  5196. name << " - " << Str("TitleBar.Scenes") << ": " << sceneCollection;
  5197. setWindowTitle(QT_UTF8(name.str().c_str()));
  5198. }
  5199. int OBSBasic::GetProfilePath(char *path, size_t size, const char *file) const
  5200. {
  5201. char profiles_path[512];
  5202. const char *profile = config_get_string(App()->GlobalConfig(),
  5203. "Basic", "ProfileDir");
  5204. int ret;
  5205. if (!profile)
  5206. return -1;
  5207. if (!path)
  5208. return -1;
  5209. if (!file)
  5210. file = "";
  5211. ret = GetConfigPath(profiles_path, 512, "obs-studio/basic/profiles");
  5212. if (ret <= 0)
  5213. return ret;
  5214. if (!*file)
  5215. return snprintf(path, size, "%s/%s", profiles_path, profile);
  5216. return snprintf(path, size, "%s/%s/%s", profiles_path, profile, file);
  5217. }
  5218. void OBSBasic::on_resetUI_triggered()
  5219. {
  5220. /* prune deleted extra docks */
  5221. for (int i = extraDocks.size() - 1; i >= 0 ; i--) {
  5222. if (!extraDocks[i]) {
  5223. extraDocks.removeAt(i);
  5224. }
  5225. }
  5226. if (extraDocks.size()) {
  5227. QMessageBox::StandardButton button = QMessageBox::question(
  5228. this,
  5229. QTStr("ResetUIWarning.Title"),
  5230. QTStr("ResetUIWarning.Text"));
  5231. if (button == QMessageBox::No)
  5232. return;
  5233. }
  5234. /* undock/hide/center extra docks */
  5235. for (int i = extraDocks.size() - 1; i >= 0 ; i--) {
  5236. if (extraDocks[i]) {
  5237. extraDocks[i]->setVisible(true);
  5238. extraDocks[i]->setFloating(true);
  5239. extraDocks[i]->move(
  5240. frameGeometry().topLeft() +
  5241. rect().center() -
  5242. extraDocks[i]->rect().center());
  5243. extraDocks[i]->setVisible(false);
  5244. }
  5245. }
  5246. restoreState(startingDockLayout);
  5247. #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
  5248. int cx = width();
  5249. int cy = height();
  5250. int cx22_5 = cx * 225 / 1000;
  5251. int cx5 = cx * 5 / 100;
  5252. cy = cy * 225 / 1000;
  5253. int mixerSize = cx - (cx22_5 * 2 + cx5 * 2);
  5254. QList<QDockWidget*> docks {
  5255. ui->scenesDock,
  5256. ui->sourcesDock,
  5257. ui->mixerDock,
  5258. ui->transitionsDock,
  5259. ui->controlsDock
  5260. };
  5261. QList<int> sizes {
  5262. cx22_5,
  5263. cx22_5,
  5264. mixerSize,
  5265. cx5,
  5266. cx5
  5267. };
  5268. ui->scenesDock->setVisible(true);
  5269. ui->sourcesDock->setVisible(true);
  5270. ui->mixerDock->setVisible(true);
  5271. ui->transitionsDock->setVisible(true);
  5272. ui->controlsDock->setVisible(true);
  5273. statsDock->setVisible(false);
  5274. statsDock->setFloating(true);
  5275. resizeDocks(docks, {cy, cy, cy, cy, cy}, Qt::Vertical);
  5276. resizeDocks(docks, sizes, Qt::Horizontal);
  5277. #endif
  5278. }
  5279. void OBSBasic::on_lockUI_toggled(bool lock)
  5280. {
  5281. QDockWidget::DockWidgetFeatures features = lock
  5282. ? QDockWidget::NoDockWidgetFeatures
  5283. : QDockWidget::AllDockWidgetFeatures;
  5284. QDockWidget::DockWidgetFeatures mainFeatures = features;
  5285. mainFeatures &= ~QDockWidget::QDockWidget::DockWidgetClosable;
  5286. ui->scenesDock->setFeatures(mainFeatures);
  5287. ui->sourcesDock->setFeatures(mainFeatures);
  5288. ui->mixerDock->setFeatures(mainFeatures);
  5289. ui->transitionsDock->setFeatures(mainFeatures);
  5290. ui->controlsDock->setFeatures(mainFeatures);
  5291. statsDock->setFeatures(features);
  5292. for (int i = extraDocks.size() - 1; i >= 0 ; i--) {
  5293. if (!extraDocks[i]) {
  5294. extraDocks.removeAt(i);
  5295. } else {
  5296. extraDocks[i]->setFeatures(features);
  5297. }
  5298. }
  5299. }
  5300. void OBSBasic::on_toggleListboxToolbars_toggled(bool visible)
  5301. {
  5302. ui->sourcesToolbar->setVisible(visible);
  5303. ui->scenesToolbar->setVisible(visible);
  5304. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  5305. "ShowListboxToolbars", visible);
  5306. }
  5307. void OBSBasic::on_toggleStatusBar_toggled(bool visible)
  5308. {
  5309. ui->statusbar->setVisible(visible);
  5310. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  5311. "ShowStatusBar", visible);
  5312. }
  5313. void OBSBasic::on_actionLockPreview_triggered()
  5314. {
  5315. ui->preview->ToggleLocked();
  5316. ui->actionLockPreview->setChecked(ui->preview->Locked());
  5317. }
  5318. void OBSBasic::on_scalingMenu_aboutToShow()
  5319. {
  5320. obs_video_info ovi;
  5321. obs_get_video_info(&ovi);
  5322. QAction *action = ui->actionScaleCanvas;
  5323. QString text = QTStr("Basic.MainMenu.Edit.Scale.Canvas");
  5324. text = text.arg(QString::number(ovi.base_width),
  5325. QString::number(ovi.base_height));
  5326. action->setText(text);
  5327. action = ui->actionScaleOutput;
  5328. text = QTStr("Basic.MainMenu.Edit.Scale.Output");
  5329. text = text.arg(QString::number(ovi.output_width),
  5330. QString::number(ovi.output_height));
  5331. action->setText(text);
  5332. action->setVisible(!(ovi.output_width == ovi.base_width &&
  5333. ovi.output_height == ovi.base_height));
  5334. UpdatePreviewScalingMenu();
  5335. }
  5336. void OBSBasic::on_actionScaleWindow_triggered()
  5337. {
  5338. ui->preview->SetFixedScaling(false);
  5339. ui->preview->ResetScrollingOffset();
  5340. emit ui->preview->DisplayResized();
  5341. }
  5342. void OBSBasic::on_actionScaleCanvas_triggered()
  5343. {
  5344. ui->preview->SetFixedScaling(true);
  5345. ui->preview->SetScalingLevel(0);
  5346. emit ui->preview->DisplayResized();
  5347. }
  5348. void OBSBasic::on_actionScaleOutput_triggered()
  5349. {
  5350. obs_video_info ovi;
  5351. obs_get_video_info(&ovi);
  5352. ui->preview->SetFixedScaling(true);
  5353. float scalingAmount = float(ovi.output_width) / float(ovi.base_width);
  5354. // log base ZOOM_SENSITIVITY of x = log(x) / log(ZOOM_SENSITIVITY)
  5355. int32_t approxScalingLevel = int32_t(
  5356. round(log(scalingAmount) / log(ZOOM_SENSITIVITY)));
  5357. ui->preview->SetScalingLevel(approxScalingLevel);
  5358. ui->preview->SetScalingAmount(scalingAmount);
  5359. emit ui->preview->DisplayResized();
  5360. }
  5361. void OBSBasic::SetShowing(bool showing)
  5362. {
  5363. if (!showing && isVisible()) {
  5364. config_set_string(App()->GlobalConfig(),
  5365. "BasicWindow", "geometry",
  5366. saveGeometry().toBase64().constData());
  5367. /* hide all visible child dialogs */
  5368. visDlgPositions.clear();
  5369. if (!visDialogs.isEmpty()) {
  5370. for (QDialog *dlg : visDialogs) {
  5371. visDlgPositions.append(dlg->pos());
  5372. dlg->hide();
  5373. }
  5374. }
  5375. if (showHide)
  5376. showHide->setText(QTStr("Basic.SystemTray.Show"));
  5377. QTimer::singleShot(250, this, SLOT(hide()));
  5378. if (previewEnabled)
  5379. EnablePreviewDisplay(false);
  5380. setVisible(false);
  5381. #ifdef __APPLE__
  5382. EnableOSXDockIcon(false);
  5383. #endif
  5384. } else if (showing && !isVisible()) {
  5385. if (showHide)
  5386. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  5387. QTimer::singleShot(250, this, SLOT(show()));
  5388. if (previewEnabled)
  5389. EnablePreviewDisplay(true);
  5390. setVisible(true);
  5391. #ifdef __APPLE__
  5392. EnableOSXDockIcon(true);
  5393. #endif
  5394. /* raise and activate window to ensure it is on top */
  5395. raise();
  5396. activateWindow();
  5397. /* show all child dialogs that was visible earlier */
  5398. if (!visDialogs.isEmpty()) {
  5399. for (int i = 0; i < visDialogs.size(); ++i) {
  5400. QDialog *dlg = visDialogs[i];
  5401. dlg->move(visDlgPositions[i]);
  5402. dlg->show();
  5403. }
  5404. }
  5405. /* Unminimize window if it was hidden to tray instead of task
  5406. * bar. */
  5407. if (sysTrayMinimizeToTray()) {
  5408. Qt::WindowStates state;
  5409. state = windowState() & ~Qt::WindowMinimized;
  5410. state |= Qt::WindowActive;
  5411. setWindowState(state);
  5412. }
  5413. }
  5414. }
  5415. void OBSBasic::ToggleShowHide()
  5416. {
  5417. bool showing = isVisible();
  5418. if (showing) {
  5419. /* check for modal dialogs */
  5420. EnumDialogs();
  5421. if (!modalDialogs.isEmpty() || !visMsgBoxes.isEmpty())
  5422. return;
  5423. }
  5424. SetShowing(!showing);
  5425. }
  5426. void OBSBasic::SystemTrayInit()
  5427. {
  5428. trayIcon.reset(new QSystemTrayIcon(QIcon::fromTheme("obs-tray",
  5429. QIcon(":/res/images/obs.png")), this));
  5430. trayIcon->setToolTip("OBS Studio");
  5431. showHide = new QAction(QTStr("Basic.SystemTray.Show"),
  5432. trayIcon.data());
  5433. sysTrayStream = new QAction(QTStr("Basic.Main.StartStreaming"),
  5434. trayIcon.data());
  5435. sysTrayRecord = new QAction(QTStr("Basic.Main.StartRecording"),
  5436. trayIcon.data());
  5437. sysTrayReplayBuffer = new QAction(QTStr("Basic.Main.StartReplayBuffer"),
  5438. trayIcon.data());
  5439. exit = new QAction(QTStr("Exit"),
  5440. trayIcon.data());
  5441. trayMenu = new QMenu;
  5442. previewProjector = new QMenu(QTStr("PreviewProjector"));
  5443. studioProgramProjector = new QMenu(QTStr("StudioProgramProjector"));
  5444. AddProjectorMenuMonitors(previewProjector, this,
  5445. SLOT(OpenPreviewProjector()));
  5446. AddProjectorMenuMonitors(studioProgramProjector, this,
  5447. SLOT(OpenStudioProgramProjector()));
  5448. trayMenu->addAction(showHide);
  5449. trayMenu->addMenu(previewProjector);
  5450. trayMenu->addMenu(studioProgramProjector);
  5451. trayMenu->addAction(sysTrayStream);
  5452. trayMenu->addAction(sysTrayRecord);
  5453. trayMenu->addAction(sysTrayReplayBuffer);
  5454. trayMenu->addAction(exit);
  5455. trayIcon->setContextMenu(trayMenu);
  5456. if (outputHandler && !outputHandler->replayBuffer)
  5457. sysTrayReplayBuffer->setEnabled(false);
  5458. connect(trayIcon.data(),
  5459. SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
  5460. this,
  5461. SLOT(IconActivated(QSystemTrayIcon::ActivationReason)));
  5462. connect(showHide, SIGNAL(triggered()),
  5463. this, SLOT(ToggleShowHide()));
  5464. connect(sysTrayStream, SIGNAL(triggered()),
  5465. this, SLOT(on_streamButton_clicked()));
  5466. connect(sysTrayRecord, SIGNAL(triggered()),
  5467. this, SLOT(on_recordButton_clicked()));
  5468. connect(sysTrayReplayBuffer.data(), &QAction::triggered,
  5469. this, &OBSBasic::ReplayBufferClicked);
  5470. connect(exit, SIGNAL(triggered()),
  5471. this, SLOT(close()));
  5472. }
  5473. void OBSBasic::IconActivated(QSystemTrayIcon::ActivationReason reason)
  5474. {
  5475. // Refresh projector list
  5476. previewProjector->clear();
  5477. studioProgramProjector->clear();
  5478. AddProjectorMenuMonitors(previewProjector, this,
  5479. SLOT(OpenPreviewProjector()));
  5480. AddProjectorMenuMonitors(studioProgramProjector, this,
  5481. SLOT(OpenStudioProgramProjector()));
  5482. if (reason == QSystemTrayIcon::Trigger)
  5483. ToggleShowHide();
  5484. }
  5485. void OBSBasic::SysTrayNotify(const QString &text,
  5486. QSystemTrayIcon::MessageIcon n)
  5487. {
  5488. if (QSystemTrayIcon::supportsMessages()) {
  5489. QSystemTrayIcon::MessageIcon icon =
  5490. QSystemTrayIcon::MessageIcon(n);
  5491. trayIcon->showMessage("OBS Studio", text, icon, 10000);
  5492. }
  5493. }
  5494. void OBSBasic::SystemTray(bool firstStarted)
  5495. {
  5496. if (!QSystemTrayIcon::isSystemTrayAvailable())
  5497. return;
  5498. bool sysTrayWhenStarted = config_get_bool(GetGlobalConfig(),
  5499. "BasicWindow", "SysTrayWhenStarted");
  5500. bool sysTrayEnabled = config_get_bool(GetGlobalConfig(),
  5501. "BasicWindow", "SysTrayEnabled");
  5502. if (firstStarted)
  5503. SystemTrayInit();
  5504. if (!sysTrayWhenStarted && !sysTrayEnabled) {
  5505. trayIcon->hide();
  5506. } else if ((sysTrayWhenStarted && sysTrayEnabled)
  5507. || opt_minimize_tray) {
  5508. trayIcon->show();
  5509. if (firstStarted) {
  5510. QTimer::singleShot(50, this, SLOT(hide()));
  5511. EnablePreviewDisplay(false);
  5512. setVisible(false);
  5513. #ifdef __APPLE__
  5514. EnableOSXDockIcon(false);
  5515. #endif
  5516. opt_minimize_tray = false;
  5517. }
  5518. } else if (sysTrayEnabled) {
  5519. trayIcon->show();
  5520. } else if (!sysTrayEnabled) {
  5521. trayIcon->hide();
  5522. } else if (!sysTrayWhenStarted && sysTrayEnabled) {
  5523. trayIcon->hide();
  5524. }
  5525. if (isVisible())
  5526. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  5527. else
  5528. showHide->setText(QTStr("Basic.SystemTray.Show"));
  5529. }
  5530. bool OBSBasic::sysTrayMinimizeToTray()
  5531. {
  5532. return config_get_bool(GetGlobalConfig(),
  5533. "BasicWindow", "SysTrayMinimizeToTray");
  5534. }
  5535. void OBSBasic::on_actionCopySource_triggered()
  5536. {
  5537. OBSSceneItem item = GetCurrentSceneItem();
  5538. if (!item)
  5539. return;
  5540. on_actionCopyTransform_triggered();
  5541. OBSSource source = obs_sceneitem_get_source(item);
  5542. copyString = obs_source_get_name(source);
  5543. copyVisible = obs_sceneitem_visible(item);
  5544. ui->actionPasteRef->setEnabled(true);
  5545. uint32_t output_flags = obs_source_get_output_flags(source);
  5546. if ((output_flags & OBS_SOURCE_DO_NOT_DUPLICATE) == 0)
  5547. ui->actionPasteDup->setEnabled(true);
  5548. else
  5549. ui->actionPasteDup->setEnabled(false);
  5550. }
  5551. void OBSBasic::on_actionPasteRef_triggered()
  5552. {
  5553. /* do not allow duplicate refs of the same group in the same scene */
  5554. OBSScene scene = GetCurrentScene();
  5555. if (!!obs_scene_get_group(scene, copyString))
  5556. return;
  5557. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, false);
  5558. on_actionPasteTransform_triggered();
  5559. }
  5560. void OBSBasic::on_actionPasteDup_triggered()
  5561. {
  5562. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, true);
  5563. on_actionPasteTransform_triggered();
  5564. }
  5565. void OBSBasic::AudioMixerCopyFilters()
  5566. {
  5567. QAction *action = reinterpret_cast<QAction*>(sender());
  5568. VolControl *vol = action->property("volControl").value<VolControl*>();
  5569. obs_source_t *source = vol->GetSource();
  5570. copyFiltersString = obs_source_get_name(source);
  5571. }
  5572. void OBSBasic::AudioMixerPasteFilters()
  5573. {
  5574. QAction *action = reinterpret_cast<QAction*>(sender());
  5575. VolControl *vol = action->property("volControl").value<VolControl*>();
  5576. obs_source_t *dstSource = vol->GetSource();
  5577. OBSSource source = obs_get_source_by_name(copyFiltersString);
  5578. obs_source_release(source);
  5579. if (source == dstSource)
  5580. return;
  5581. obs_source_copy_filters(dstSource, source);
  5582. }
  5583. void OBSBasic::on_actionCopyFilters_triggered()
  5584. {
  5585. OBSSceneItem item = GetCurrentSceneItem();
  5586. if (!item)
  5587. return;
  5588. OBSSource source = obs_sceneitem_get_source(item);
  5589. copyFiltersString = obs_source_get_name(source);
  5590. ui->actionPasteFilters->setEnabled(true);
  5591. }
  5592. void OBSBasic::on_actionPasteFilters_triggered()
  5593. {
  5594. OBSSource source = obs_get_source_by_name(copyFiltersString);
  5595. obs_source_release(source);
  5596. OBSSceneItem sceneItem = GetCurrentSceneItem();
  5597. OBSSource dstSource = obs_sceneitem_get_source(sceneItem);
  5598. if (source == dstSource)
  5599. return;
  5600. obs_source_copy_filters(dstSource, source);
  5601. }
  5602. static void ConfirmColor(SourceTree *sources, const QColor &color,
  5603. QModelIndexList selectedItems)
  5604. {
  5605. for (int x = 0; x < selectedItems.count(); x++) {
  5606. SourceTreeItem *treeItem = sources
  5607. ->GetItemWidget(selectedItems[x].row());
  5608. treeItem->setStyleSheet("background: "
  5609. + color.name(QColor::HexArgb));
  5610. treeItem->style()->unpolish(treeItem);
  5611. treeItem->style()->polish(treeItem);
  5612. OBSSceneItem sceneItem = sources->Get(
  5613. selectedItems[x].row());
  5614. obs_data_t *privData =
  5615. obs_sceneitem_get_private_settings(sceneItem);
  5616. obs_data_set_int(privData, "color-preset", 1);
  5617. obs_data_set_string(privData, "color",
  5618. QT_TO_UTF8(color.name(
  5619. QColor::HexArgb)));
  5620. obs_data_release(privData);
  5621. }
  5622. }
  5623. void OBSBasic::ColorChange()
  5624. {
  5625. QModelIndexList selectedItems =
  5626. ui->sources->selectionModel()->selectedIndexes();
  5627. QAction *action = qobject_cast<QAction*>(sender());
  5628. QPushButton *colorButton = qobject_cast<QPushButton*>(sender());
  5629. if (selectedItems.count() == 0)
  5630. return;
  5631. if (colorButton) {
  5632. int preset = colorButton->property("bgColor").value<int>();
  5633. for (int x = 0; x < selectedItems.count(); x++) {
  5634. SourceTreeItem *treeItem = ui->sources
  5635. ->GetItemWidget(selectedItems[x].row());
  5636. treeItem->setStyleSheet("");
  5637. treeItem->setProperty("bgColor", preset);
  5638. treeItem->style()->unpolish(treeItem);
  5639. treeItem->style()->polish(treeItem);
  5640. OBSSceneItem sceneItem = ui->sources->Get(
  5641. selectedItems[x].row());
  5642. obs_data_t *privData =
  5643. obs_sceneitem_get_private_settings(sceneItem);
  5644. obs_data_set_int(privData, "color-preset", preset + 1);
  5645. obs_data_set_string(privData, "color", "");
  5646. obs_data_release(privData);
  5647. }
  5648. for (int i = 1; i < 9; i++) {
  5649. stringstream button;
  5650. button << "preset" << i;
  5651. QPushButton *cButton = colorButton->parentWidget()
  5652. ->findChild<QPushButton *>(button.str().c_str());
  5653. cButton->setStyleSheet("border: 1px solid black");
  5654. }
  5655. colorButton->setStyleSheet("border: 2px solid black");
  5656. } else if (action) {
  5657. int preset = action->property("bgColor").value<int>();
  5658. if (preset == 1) {
  5659. OBSSceneItem curSceneItem = GetCurrentSceneItem();
  5660. SourceTreeItem *curTreeItem =
  5661. GetItemWidgetFromSceneItem(curSceneItem);
  5662. obs_data_t *curPrivData =
  5663. obs_sceneitem_get_private_settings(curSceneItem);
  5664. int oldPreset = obs_data_get_int(
  5665. curPrivData, "color-preset");
  5666. const QString oldSheet = curTreeItem->styleSheet();
  5667. auto liveChangeColor = [=](const QColor &color) {
  5668. if (color.isValid()) {
  5669. curTreeItem->setStyleSheet(
  5670. "background: "
  5671. + color.name(QColor::HexArgb));
  5672. }
  5673. };
  5674. auto changedColor = [=](const QColor &color) {
  5675. if (color.isValid()) {
  5676. ConfirmColor(ui->sources, color,
  5677. selectedItems);
  5678. }
  5679. };
  5680. auto rejected = [=]() {
  5681. if (oldPreset == 1) {
  5682. curTreeItem->setStyleSheet(oldSheet);
  5683. curTreeItem->setProperty("bgColor", 0);
  5684. } else if (oldPreset == 0) {
  5685. curTreeItem->setStyleSheet(
  5686. "background: none");
  5687. curTreeItem->setProperty("bgColor", 0);
  5688. } else {
  5689. curTreeItem->setStyleSheet("");
  5690. curTreeItem->setProperty("bgColor",
  5691. oldPreset - 1);
  5692. }
  5693. curTreeItem->style()->unpolish(curTreeItem);
  5694. curTreeItem->style()->polish(curTreeItem);
  5695. };
  5696. QColorDialog::ColorDialogOptions options =
  5697. QColorDialog::ShowAlphaChannel;
  5698. const char *oldColor = obs_data_get_string(curPrivData,
  5699. "color");
  5700. const char *customColor = *oldColor != 0 ? oldColor
  5701. : "#55FF0000";
  5702. #ifdef __APPLE__
  5703. options |= QColorDialog::DontUseNativeDialog;
  5704. #endif
  5705. QColorDialog *colorDialog = new QColorDialog(this);
  5706. colorDialog->setOptions(options);
  5707. colorDialog->setCurrentColor(
  5708. QColor(customColor));
  5709. connect(colorDialog, &QColorDialog::currentColorChanged,
  5710. liveChangeColor);
  5711. connect(colorDialog, &QColorDialog::colorSelected,
  5712. changedColor);
  5713. connect(colorDialog, &QColorDialog::rejected,
  5714. rejected);
  5715. colorDialog->open();
  5716. obs_data_release(curPrivData);
  5717. } else {
  5718. for (int x = 0; x < selectedItems.count(); x++) {
  5719. SourceTreeItem *treeItem = ui->sources
  5720. ->GetItemWidget(selectedItems[x].row());
  5721. treeItem->setStyleSheet("background: none");
  5722. treeItem->setProperty("bgColor", preset);
  5723. treeItem->style()->unpolish(treeItem);
  5724. treeItem->style()->polish(treeItem);
  5725. OBSSceneItem sceneItem = ui->sources->Get(
  5726. selectedItems[x].row());
  5727. obs_data_t *privData =
  5728. obs_sceneitem_get_private_settings(
  5729. sceneItem);
  5730. obs_data_set_int(privData, "color-preset",
  5731. preset);
  5732. obs_data_set_string(privData, "color", "");
  5733. obs_data_release(privData);
  5734. }
  5735. }
  5736. }
  5737. }
  5738. SourceTreeItem *OBSBasic::GetItemWidgetFromSceneItem(
  5739. obs_sceneitem_t *sceneItem)
  5740. {
  5741. int i = 0;
  5742. SourceTreeItem *treeItem = ui->sources->GetItemWidget(i);
  5743. OBSSceneItem item = ui->sources->Get(i);
  5744. int64_t id = obs_sceneitem_get_id(sceneItem);
  5745. while (treeItem && obs_sceneitem_get_id(item) != id) {
  5746. i++;
  5747. treeItem = ui->sources->GetItemWidget(i);
  5748. item = ui->sources->Get(i);
  5749. }
  5750. if(treeItem)
  5751. return treeItem;
  5752. return nullptr;
  5753. }
  5754. void OBSBasic::on_autoConfigure_triggered()
  5755. {
  5756. AutoConfig test(this);
  5757. test.setModal(true);
  5758. test.show();
  5759. test.exec();
  5760. }
  5761. void OBSBasic::on_stats_triggered()
  5762. {
  5763. if (!stats.isNull()) {
  5764. stats->show();
  5765. stats->raise();
  5766. return;
  5767. }
  5768. OBSBasicStats *statsDlg;
  5769. statsDlg = new OBSBasicStats(nullptr);
  5770. statsDlg->show();
  5771. stats = statsDlg;
  5772. }
  5773. void OBSBasic::on_actionShowAbout_triggered()
  5774. {
  5775. if (about)
  5776. about->close();
  5777. about = new OBSAbout(this);
  5778. about->show();
  5779. about->setAttribute(Qt::WA_DeleteOnClose, true);
  5780. }
  5781. void OBSBasic::ResizeOutputSizeOfSource()
  5782. {
  5783. if (ui->streamButton->isChecked() || ui->recordButton->isChecked() ||
  5784. (replayBufferButton && replayBufferButton->isChecked()))
  5785. return;
  5786. QMessageBox resize_output(this);
  5787. resize_output.setText(QTStr("ResizeOutputSizeOfSource.Text") +
  5788. "\n\n" + QTStr("ResizeOutputSizeOfSource.Continue"));
  5789. QAbstractButton *Yes = resize_output.addButton(QTStr("Yes"),
  5790. QMessageBox::YesRole);
  5791. resize_output.addButton(QTStr("No"), QMessageBox::NoRole);
  5792. resize_output.setIcon(QMessageBox::Warning);
  5793. resize_output.setWindowTitle(QTStr("ResizeOutputSizeOfSource"));
  5794. resize_output.exec();
  5795. if (resize_output.clickedButton() != Yes)
  5796. return;
  5797. OBSSource source = obs_sceneitem_get_source(GetCurrentSceneItem());
  5798. int width = obs_source_get_width(source);
  5799. int height = obs_source_get_height(source);
  5800. config_set_uint(basicConfig, "Video", "BaseCX", width);
  5801. config_set_uint(basicConfig, "Video", "BaseCY", height);
  5802. config_set_uint(basicConfig, "Video", "OutputCX", width);
  5803. config_set_uint(basicConfig, "Video", "OutputCY", height);
  5804. ResetVideo();
  5805. on_actionFitToScreen_triggered();
  5806. }
  5807. QAction *OBSBasic::AddDockWidget(QDockWidget *dock)
  5808. {
  5809. QAction *action = ui->viewMenuDocks->addAction(dock->windowTitle());
  5810. action->setCheckable(true);
  5811. assignDockToggle(dock, action);
  5812. extraDocks.push_back(dock);
  5813. bool lock = ui->lockUI->isChecked();
  5814. QDockWidget::DockWidgetFeatures features = lock
  5815. ? QDockWidget::NoDockWidgetFeatures
  5816. : QDockWidget::AllDockWidgetFeatures;
  5817. dock->setFeatures(features);
  5818. /* prune deleted docks */
  5819. for (int i = extraDocks.size() - 1; i >= 0 ; i--) {
  5820. if (!extraDocks[i]) {
  5821. extraDocks.removeAt(i);
  5822. }
  5823. }
  5824. return action;
  5825. }
  5826. OBSBasic *OBSBasic::Get()
  5827. {
  5828. return reinterpret_cast<OBSBasic*>(App()->GetMainWindow());
  5829. }
  5830. bool OBSBasic::StreamingActive()
  5831. {
  5832. if (!outputHandler)
  5833. return false;
  5834. return outputHandler->StreamingActive();
  5835. }
  5836. bool OBSBasic::RecordingActive()
  5837. {
  5838. if (!outputHandler)
  5839. return false;
  5840. return outputHandler->RecordingActive();
  5841. }
  5842. bool OBSBasic::ReplayBufferActive()
  5843. {
  5844. if (!outputHandler)
  5845. return false;
  5846. return outputHandler->ReplayBufferActive();
  5847. }
  5848. SceneRenameDelegate::SceneRenameDelegate(QObject *parent)
  5849. : QStyledItemDelegate(parent)
  5850. {
  5851. }
  5852. void SceneRenameDelegate::setEditorData(QWidget *editor,
  5853. const QModelIndex &index) const
  5854. {
  5855. QStyledItemDelegate::setEditorData(editor, index);
  5856. QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor);
  5857. if (lineEdit)
  5858. lineEdit->selectAll();
  5859. }