window-basic-main.cpp 221 KB

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