window-basic-main.cpp 221 KB

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