window-basic-main.cpp 221 KB

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