window-basic-main.cpp 221 KB

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