window-basic-main.cpp 221 KB

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