window-basic-main.cpp 221 KB

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