window-basic-main.cpp 221 KB

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