window-basic-main.cpp 159 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100
  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 <time.h>
  17. #include <obs.hpp>
  18. #include <QGuiApplication>
  19. #include <QMessageBox>
  20. #include <QShowEvent>
  21. #include <QDesktopServices>
  22. #include <QFileDialog>
  23. #include <QDesktopWidget>
  24. #include <QRect>
  25. #include <QScreen>
  26. #include <util/dstr.h>
  27. #include <util/util.hpp>
  28. #include <util/platform.h>
  29. #include <util/profiler.hpp>
  30. #include <util/dstr.hpp>
  31. #include <graphics/math-defs.h>
  32. #include "obs-app.hpp"
  33. #include "platform.hpp"
  34. #include "visibility-item-widget.hpp"
  35. #include "item-widget-helpers.hpp"
  36. #include "window-basic-settings.hpp"
  37. #include "window-namedialog.hpp"
  38. #include "window-basic-auto-config.hpp"
  39. #include "window-basic-source-select.hpp"
  40. #include "window-basic-main.hpp"
  41. #include "window-basic-stats.hpp"
  42. #include "window-basic-main-outputs.hpp"
  43. #include "window-basic-properties.hpp"
  44. #include "window-log-reply.hpp"
  45. #include "window-projector.hpp"
  46. #include "window-remux.hpp"
  47. #include "qt-wrappers.hpp"
  48. #include "display-helpers.hpp"
  49. #include "volume-control.hpp"
  50. #include "remote-text.hpp"
  51. #if defined(_WIN32) && defined(ENABLE_WIN_UPDATER)
  52. #include "win-update/win-update.hpp"
  53. #endif
  54. #include "ui_OBSBasic.h"
  55. #include <fstream>
  56. #include <sstream>
  57. #include <QScreen>
  58. #include <QWindow>
  59. using namespace std;
  60. namespace {
  61. template <typename OBSRef>
  62. struct SignalContainer {
  63. OBSRef ref;
  64. vector<shared_ptr<OBSSignal>> handlers;
  65. };
  66. }
  67. Q_DECLARE_METATYPE(OBSScene);
  68. Q_DECLARE_METATYPE(OBSSceneItem);
  69. Q_DECLARE_METATYPE(OBSSource);
  70. Q_DECLARE_METATYPE(obs_order_movement);
  71. Q_DECLARE_METATYPE(SignalContainer<OBSScene>);
  72. template <typename T>
  73. static T GetOBSRef(QListWidgetItem *item)
  74. {
  75. return item->data(static_cast<int>(QtDataRole::OBSRef)).value<T>();
  76. }
  77. template <typename T>
  78. static void SetOBSRef(QListWidgetItem *item, T &&val)
  79. {
  80. item->setData(static_cast<int>(QtDataRole::OBSRef),
  81. QVariant::fromValue(val));
  82. }
  83. static void AddExtraModulePaths()
  84. {
  85. char base_module_dir[512];
  86. #if defined(_WIN32) || defined(__APPLE__)
  87. int ret = GetProgramDataPath(base_module_dir, sizeof(base_module_dir),
  88. "obs-studio/plugins/%module%");
  89. #else
  90. int ret = GetConfigPath(base_module_dir, sizeof(base_module_dir),
  91. "obs-studio/plugins/%module%");
  92. #endif
  93. if (ret <= 0)
  94. return;
  95. string path = (char*)base_module_dir;
  96. #if defined(__APPLE__)
  97. obs_add_module_path((path + "/bin").c_str(), (path + "/data").c_str());
  98. BPtr<char> config_bin = os_get_config_path_ptr("obs-studio/plugins/%module%/bin");
  99. BPtr<char> config_data = os_get_config_path_ptr("obs-studio/plugins/%module%/data");
  100. obs_add_module_path(config_bin, config_data);
  101. #elif ARCH_BITS == 64
  102. obs_add_module_path((path + "/bin/64bit").c_str(),
  103. (path + "/data").c_str());
  104. #else
  105. obs_add_module_path((path + "/bin/32bit").c_str(),
  106. (path + "/data").c_str());
  107. #endif
  108. }
  109. static QList<QKeySequence> DeleteKeys;
  110. OBSBasic::OBSBasic(QWidget *parent)
  111. : OBSMainWindow (parent),
  112. ui (new Ui::OBSBasic)
  113. {
  114. setAttribute(Qt::WA_NativeWindow);
  115. setAcceptDrops(true);
  116. ui->setupUi(this);
  117. ui->previewDisabledLabel->setVisible(false);
  118. startingDockLayout = saveState();
  119. copyActionsDynamicProperties();
  120. ui->sources->setItemDelegate(new VisibilityItemDelegate(ui->sources));
  121. char styleSheetPath[512];
  122. int ret = GetProfilePath(styleSheetPath, sizeof(styleSheetPath),
  123. "stylesheet.qss");
  124. if (ret > 0) {
  125. if (QFile::exists(styleSheetPath)) {
  126. QString path = QString("file:///") +
  127. QT_UTF8(styleSheetPath);
  128. App()->setStyleSheet(path);
  129. }
  130. }
  131. qRegisterMetaType<OBSScene> ("OBSScene");
  132. qRegisterMetaType<OBSSceneItem>("OBSSceneItem");
  133. qRegisterMetaType<OBSSource> ("OBSSource");
  134. qRegisterMetaType<obs_hotkey_id>("obs_hotkey_id");
  135. qRegisterMetaTypeStreamOperators<
  136. std::vector<std::shared_ptr<OBSSignal>>>(
  137. "std::vector<std::shared_ptr<OBSSignal>>");
  138. qRegisterMetaTypeStreamOperators<OBSScene>("OBSScene");
  139. qRegisterMetaTypeStreamOperators<OBSSceneItem>("OBSSceneItem");
  140. ui->scenes->setAttribute(Qt::WA_MacShowFocusRect, false);
  141. ui->sources->setAttribute(Qt::WA_MacShowFocusRect, false);
  142. auto displayResize = [this]() {
  143. struct obs_video_info ovi;
  144. if (obs_get_video_info(&ovi))
  145. ResizePreview(ovi.base_width, ovi.base_height);
  146. };
  147. connect(windowHandle(), &QWindow::screenChanged, displayResize);
  148. connect(ui->preview, &OBSQTDisplay::DisplayResized, displayResize);
  149. installEventFilter(CreateShortcutFilter());
  150. stringstream name;
  151. name << "OBS " << App()->GetVersionString();
  152. blog(LOG_INFO, "%s", name.str().c_str());
  153. blog(LOG_INFO, "---------------------------------");
  154. UpdateTitleBar();
  155. connect(ui->scenes->itemDelegate(),
  156. SIGNAL(closeEditor(QWidget*,
  157. QAbstractItemDelegate::EndEditHint)),
  158. this,
  159. SLOT(SceneNameEdited(QWidget*,
  160. QAbstractItemDelegate::EndEditHint)));
  161. connect(ui->sources->itemDelegate(),
  162. SIGNAL(closeEditor(QWidget*,
  163. QAbstractItemDelegate::EndEditHint)),
  164. this,
  165. SLOT(SceneItemNameEdited(QWidget*,
  166. QAbstractItemDelegate::EndEditHint)));
  167. cpuUsageInfo = os_cpu_usage_info_start();
  168. cpuUsageTimer = new QTimer(this);
  169. connect(cpuUsageTimer, SIGNAL(timeout()),
  170. ui->statusbar, SLOT(UpdateCPUUsage()));
  171. cpuUsageTimer->start(3000);
  172. DeleteKeys =
  173. #ifdef __APPLE__
  174. QList<QKeySequence>{{Qt::Key_Backspace}} <<
  175. #endif
  176. QKeySequence::keyBindings(QKeySequence::Delete);
  177. #ifdef __APPLE__
  178. ui->actionRemoveSource->setShortcuts(DeleteKeys);
  179. ui->actionRemoveScene->setShortcuts(DeleteKeys);
  180. ui->action_Settings->setMenuRole(QAction::PreferencesRole);
  181. ui->actionE_xit->setMenuRole(QAction::QuitRole);
  182. #endif
  183. auto addNudge = [this](const QKeySequence &seq, const char *s)
  184. {
  185. QAction *nudge = new QAction(ui->preview);
  186. nudge->setShortcut(seq);
  187. nudge->setShortcutContext(Qt::WidgetShortcut);
  188. ui->preview->addAction(nudge);
  189. connect(nudge, SIGNAL(triggered()), this, s);
  190. };
  191. addNudge(Qt::Key_Up, SLOT(NudgeUp()));
  192. addNudge(Qt::Key_Down, SLOT(NudgeDown()));
  193. addNudge(Qt::Key_Left, SLOT(NudgeLeft()));
  194. addNudge(Qt::Key_Right, SLOT(NudgeRight()));
  195. auto assignDockToggle = [this](QDockWidget *dock, QAction *action)
  196. {
  197. auto handleWindowToggle = [action] (bool vis)
  198. {
  199. action->blockSignals(true);
  200. action->setChecked(vis);
  201. action->blockSignals(false);
  202. };
  203. auto handleMenuToggle = [dock] (bool check)
  204. {
  205. dock->blockSignals(true);
  206. dock->setVisible(check);
  207. dock->blockSignals(false);
  208. };
  209. dock->connect(dock->toggleViewAction(), &QAction::toggled,
  210. handleWindowToggle);
  211. dock->connect(action, &QAction::toggled,
  212. handleMenuToggle);
  213. };
  214. assignDockToggle(ui->scenesDock, ui->toggleScenes);
  215. assignDockToggle(ui->sourcesDock, ui->toggleSources);
  216. assignDockToggle(ui->mixerDock, ui->toggleMixer);
  217. assignDockToggle(ui->transitionsDock, ui->toggleTransitions);
  218. assignDockToggle(ui->controlsDock, ui->toggleControls);
  219. //hide all docking panes
  220. ui->toggleScenes->setChecked(false);
  221. ui->toggleSources->setChecked(false);
  222. ui->toggleMixer->setChecked(false);
  223. ui->toggleTransitions->setChecked(false);
  224. ui->toggleControls->setChecked(false);
  225. //restore parent window geometry
  226. const char *geometry = config_get_string(App()->GlobalConfig(),
  227. "BasicWindow", "geometry");
  228. if (geometry != NULL) {
  229. QByteArray byteArray = QByteArray::fromBase64(
  230. QByteArray(geometry));
  231. restoreGeometry(byteArray);
  232. QRect windowGeometry = normalGeometry();
  233. if (!WindowPositionValid(windowGeometry)) {
  234. QRect rect = App()->desktop()->geometry();
  235. setGeometry(QStyle::alignedRect(
  236. Qt::LeftToRight,
  237. Qt::AlignCenter,
  238. size(), rect));
  239. }
  240. }
  241. }
  242. static void SaveAudioDevice(const char *name, int channel, obs_data_t *parent,
  243. vector<OBSSource> &audioSources)
  244. {
  245. obs_source_t *source = obs_get_output_source(channel);
  246. if (!source)
  247. return;
  248. audioSources.push_back(source);
  249. obs_data_t *data = obs_save_source(source);
  250. obs_data_set_obj(parent, name, data);
  251. obs_data_release(data);
  252. obs_source_release(source);
  253. }
  254. static obs_data_t *GenerateSaveData(obs_data_array_t *sceneOrder,
  255. obs_data_array_t *quickTransitionData, int transitionDuration,
  256. obs_data_array_t *transitions,
  257. OBSScene &scene, OBSSource &curProgramScene,
  258. obs_data_array_t *savedProjectorList)
  259. {
  260. obs_data_t *saveData = obs_data_create();
  261. vector<OBSSource> audioSources;
  262. audioSources.reserve(5);
  263. SaveAudioDevice(DESKTOP_AUDIO_1, 1, saveData, audioSources);
  264. SaveAudioDevice(DESKTOP_AUDIO_2, 2, saveData, audioSources);
  265. SaveAudioDevice(AUX_AUDIO_1, 3, saveData, audioSources);
  266. SaveAudioDevice(AUX_AUDIO_2, 4, saveData, audioSources);
  267. SaveAudioDevice(AUX_AUDIO_3, 5, saveData, audioSources);
  268. auto FilterAudioSources = [&](obs_source_t *source)
  269. {
  270. return find(begin(audioSources), end(audioSources), source) ==
  271. end(audioSources);
  272. };
  273. using FilterAudioSources_t = decltype(FilterAudioSources);
  274. obs_data_array_t *sourcesArray = obs_save_sources_filtered(
  275. [](void *data, obs_source_t *source)
  276. {
  277. return (*static_cast<FilterAudioSources_t*>(data))(source);
  278. }, static_cast<void*>(&FilterAudioSources));
  279. obs_source_t *transition = obs_get_output_source(0);
  280. obs_source_t *currentScene = obs_scene_get_source(scene);
  281. const char *sceneName = obs_source_get_name(currentScene);
  282. const char *programName = obs_source_get_name(curProgramScene);
  283. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  284. "Basic", "SceneCollection");
  285. obs_data_set_string(saveData, "current_scene", sceneName);
  286. obs_data_set_string(saveData, "current_program_scene", programName);
  287. obs_data_set_array(saveData, "scene_order", sceneOrder);
  288. obs_data_set_string(saveData, "name", sceneCollection);
  289. obs_data_set_array(saveData, "sources", sourcesArray);
  290. obs_data_set_array(saveData, "quick_transitions", quickTransitionData);
  291. obs_data_set_array(saveData, "transitions", transitions);
  292. obs_data_set_array(saveData, "saved_projectors", savedProjectorList);
  293. obs_data_array_release(sourcesArray);
  294. obs_data_set_string(saveData, "current_transition",
  295. obs_source_get_name(transition));
  296. obs_data_set_int(saveData, "transition_duration", transitionDuration);
  297. obs_source_release(transition);
  298. return saveData;
  299. }
  300. void OBSBasic::copyActionsDynamicProperties()
  301. {
  302. // Themes need the QAction dynamic properties
  303. for (QAction *x : ui->scenesToolbar->actions()) {
  304. QWidget* temp = ui->scenesToolbar->widgetForAction(x);
  305. for (QByteArray &y : x->dynamicPropertyNames()) {
  306. temp->setProperty(y, x->property(y));
  307. }
  308. }
  309. for (QAction *x : ui->sourcesToolbar->actions()) {
  310. QWidget* temp = ui->sourcesToolbar->widgetForAction(x);
  311. for (QByteArray &y : x->dynamicPropertyNames()) {
  312. temp->setProperty(y, x->property(y));
  313. }
  314. }
  315. }
  316. void OBSBasic::UpdateVolumeControlsDecayRate()
  317. {
  318. double meterDecayRate = config_get_double(basicConfig, "Audio",
  319. "MeterDecayRate");
  320. for (size_t i = 0; i < volumes.size(); i++) {
  321. volumes[i]->SetMeterDecayRate(meterDecayRate);
  322. }
  323. }
  324. void OBSBasic::ClearVolumeControls()
  325. {
  326. VolControl *control;
  327. for (size_t i = 0; i < volumes.size(); i++) {
  328. control = volumes[i];
  329. delete control;
  330. }
  331. volumes.clear();
  332. }
  333. obs_data_array_t *OBSBasic::SaveSceneListOrder()
  334. {
  335. obs_data_array_t *sceneOrder = obs_data_array_create();
  336. for (int i = 0; i < ui->scenes->count(); i++) {
  337. obs_data_t *data = obs_data_create();
  338. obs_data_set_string(data, "name",
  339. QT_TO_UTF8(ui->scenes->item(i)->text()));
  340. obs_data_array_push_back(sceneOrder, data);
  341. obs_data_release(data);
  342. }
  343. return sceneOrder;
  344. }
  345. obs_data_array_t *OBSBasic::SaveProjectors()
  346. {
  347. obs_data_array_t *savedProjectors = obs_data_array_create();
  348. auto saveProjector = [savedProjectors](OBSProjector *projector) {
  349. if (!projector)
  350. return;
  351. obs_data_t *data = obs_data_create();
  352. ProjectorType type = projector->GetProjectorType();
  353. switch (type) {
  354. case ProjectorType::Scene:
  355. case ProjectorType::Source: {
  356. obs_source_t *source = projector->GetSource();
  357. const char *name = obs_source_get_name(source);
  358. obs_data_set_string(data, "name", name);
  359. break;
  360. }
  361. default:
  362. break;
  363. }
  364. obs_data_set_int(data, "monitor", projector->GetMonitor());
  365. obs_data_set_int(data, "type", static_cast<int>(type));
  366. obs_data_set_string(data, "geometry",
  367. projector->saveGeometry().toBase64()
  368. .constData());
  369. obs_data_array_push_back(savedProjectors, data);
  370. obs_data_release(data);
  371. };
  372. for (QPointer<QWidget> &proj : projectors)
  373. saveProjector(static_cast<OBSProjector *>(proj.data()));
  374. for (QPointer<QWidget> &proj : windowProjectors)
  375. saveProjector(static_cast<OBSProjector *>(proj.data()));
  376. return savedProjectors;
  377. }
  378. void OBSBasic::Save(const char *file)
  379. {
  380. OBSScene scene = GetCurrentScene();
  381. OBSSource curProgramScene = OBSGetStrongRef(programScene);
  382. if (!curProgramScene)
  383. curProgramScene = obs_scene_get_source(scene);
  384. obs_data_array_t *sceneOrder = SaveSceneListOrder();
  385. obs_data_array_t *transitions = SaveTransitions();
  386. obs_data_array_t *quickTrData = SaveQuickTransitions();
  387. obs_data_array_t *savedProjectorList = SaveProjectors();
  388. obs_data_t *saveData = GenerateSaveData(sceneOrder, quickTrData,
  389. ui->transitionDuration->value(), transitions,
  390. scene, curProgramScene, savedProjectorList);
  391. obs_data_set_bool(saveData, "preview_locked", ui->preview->Locked());
  392. obs_data_set_bool(saveData, "scaling_enabled",
  393. ui->preview->IsFixedScaling());
  394. obs_data_set_int(saveData, "scaling_level",
  395. ui->preview->GetScalingLevel());
  396. obs_data_set_double(saveData, "scaling_off_x",
  397. ui->preview->GetScrollX());
  398. obs_data_set_double(saveData, "scaling_off_y",
  399. ui->preview->GetScrollY());
  400. if (api) {
  401. obs_data_t *moduleObj = obs_data_create();
  402. api->on_save(moduleObj);
  403. obs_data_set_obj(saveData, "modules", moduleObj);
  404. obs_data_release(moduleObj);
  405. }
  406. if (!obs_data_save_json_safe(saveData, file, "tmp", "bak"))
  407. blog(LOG_ERROR, "Could not save scene data to %s", file);
  408. obs_data_release(saveData);
  409. obs_data_array_release(sceneOrder);
  410. obs_data_array_release(quickTrData);
  411. obs_data_array_release(transitions);
  412. obs_data_array_release(savedProjectorList);
  413. }
  414. static void LoadAudioDevice(const char *name, int channel, obs_data_t *parent)
  415. {
  416. obs_data_t *data = obs_data_get_obj(parent, name);
  417. if (!data)
  418. return;
  419. obs_source_t *source = obs_load_source(data);
  420. if (source) {
  421. obs_set_output_source(channel, source);
  422. obs_source_release(source);
  423. }
  424. obs_data_release(data);
  425. }
  426. static inline bool HasAudioDevices(const char *source_id)
  427. {
  428. const char *output_id = source_id;
  429. obs_properties_t *props = obs_get_source_properties(output_id);
  430. size_t count = 0;
  431. if (!props)
  432. return false;
  433. obs_property_t *devices = obs_properties_get(props, "device_id");
  434. if (devices)
  435. count = obs_property_list_item_count(devices);
  436. obs_properties_destroy(props);
  437. return count != 0;
  438. }
  439. void OBSBasic::CreateFirstRunSources()
  440. {
  441. bool hasDesktopAudio = HasAudioDevices(App()->OutputAudioSource());
  442. bool hasInputAudio = HasAudioDevices(App()->InputAudioSource());
  443. if (hasDesktopAudio)
  444. ResetAudioDevice(App()->OutputAudioSource(), "default",
  445. Str("Basic.DesktopDevice1"), 1);
  446. if (hasInputAudio)
  447. ResetAudioDevice(App()->InputAudioSource(), "default",
  448. Str("Basic.AuxDevice1"), 3);
  449. }
  450. void OBSBasic::CreateDefaultScene(bool firstStart)
  451. {
  452. disableSaving++;
  453. ClearSceneData();
  454. InitDefaultTransitions();
  455. CreateDefaultQuickTransitions();
  456. ui->transitionDuration->setValue(300);
  457. SetTransition(fadeTransition);
  458. obs_scene_t *scene = obs_scene_create(Str("Basic.Scene"));
  459. if (firstStart)
  460. CreateFirstRunSources();
  461. AddScene(obs_scene_get_source(scene));
  462. SetCurrentScene(scene, true);
  463. obs_scene_release(scene);
  464. disableSaving--;
  465. }
  466. static void ReorderItemByName(QListWidget *lw, const char *name, int newIndex)
  467. {
  468. for (int i = 0; i < lw->count(); i++) {
  469. QListWidgetItem *item = lw->item(i);
  470. if (strcmp(name, QT_TO_UTF8(item->text())) == 0) {
  471. if (newIndex != i) {
  472. item = lw->takeItem(i);
  473. lw->insertItem(newIndex, item);
  474. }
  475. break;
  476. }
  477. }
  478. }
  479. void OBSBasic::LoadSceneListOrder(obs_data_array_t *array)
  480. {
  481. size_t num = obs_data_array_count(array);
  482. for (size_t i = 0; i < num; i++) {
  483. obs_data_t *data = obs_data_array_item(array, i);
  484. const char *name = obs_data_get_string(data, "name");
  485. ReorderItemByName(ui->scenes, name, (int)i);
  486. obs_data_release(data);
  487. }
  488. }
  489. void OBSBasic::LoadSavedProjectors(obs_data_array_t *array)
  490. {
  491. size_t num = obs_data_array_count(array);
  492. for (size_t i = 0; i < num; i++) {
  493. obs_data_t *data = obs_data_array_item(array, i);
  494. SavedProjectorInfo *info = new SavedProjectorInfo();
  495. info->monitor = obs_data_get_int(data, "monitor");
  496. info->type = static_cast<ProjectorType>(obs_data_get_int(data,
  497. "type"));
  498. info->geometry = std::string(
  499. obs_data_get_string(data, "geometry"));
  500. info->name = std::string(obs_data_get_string(data, "name"));
  501. savedProjectorsArray.emplace_back(info);
  502. obs_data_release(data);
  503. }
  504. }
  505. static void LogFilter(obs_source_t*, obs_source_t *filter, void *v_val)
  506. {
  507. const char *name = obs_source_get_name(filter);
  508. const char *id = obs_source_get_id(filter);
  509. int val = (int)(intptr_t)v_val;
  510. string indent;
  511. for (int i = 0; i < val; i++)
  512. indent += " ";
  513. blog(LOG_INFO, "%s- filter: '%s' (%s)", indent.c_str(), name, id);
  514. }
  515. static bool LogSceneItem(obs_scene_t*, obs_sceneitem_t *item, void*)
  516. {
  517. obs_source_t *source = obs_sceneitem_get_source(item);
  518. const char *name = obs_source_get_name(source);
  519. const char *id = obs_source_get_id(source);
  520. blog(LOG_INFO, " - source: '%s' (%s)", name, id);
  521. obs_monitoring_type monitoring_type =
  522. obs_source_get_monitoring_type(source);
  523. if (monitoring_type != OBS_MONITORING_TYPE_NONE) {
  524. const char *type =
  525. (monitoring_type == OBS_MONITORING_TYPE_MONITOR_ONLY)
  526. ? "monitor only"
  527. : "monitor and output";
  528. blog(LOG_INFO, " - monitoring: %s", type);
  529. }
  530. obs_source_enum_filters(source, LogFilter, (void*)(intptr_t)2);
  531. return true;
  532. }
  533. void OBSBasic::LogScenes()
  534. {
  535. blog(LOG_INFO, "------------------------------------------------");
  536. blog(LOG_INFO, "Loaded scenes:");
  537. for (int i = 0; i < ui->scenes->count(); i++) {
  538. QListWidgetItem *item = ui->scenes->item(i);
  539. OBSScene scene = GetOBSRef<OBSScene>(item);
  540. obs_source_t *source = obs_scene_get_source(scene);
  541. const char *name = obs_source_get_name(source);
  542. blog(LOG_INFO, "- scene '%s':", name);
  543. obs_scene_enum_items(scene, LogSceneItem, nullptr);
  544. obs_source_enum_filters(source, LogFilter, (void*)(intptr_t)1);
  545. }
  546. blog(LOG_INFO, "------------------------------------------------");
  547. }
  548. void OBSBasic::Load(const char *file)
  549. {
  550. disableSaving++;
  551. obs_data_t *data = obs_data_create_from_json_file_safe(file, "bak");
  552. if (!data) {
  553. disableSaving--;
  554. blog(LOG_INFO, "No scene file found, creating default scene");
  555. CreateDefaultScene(true);
  556. SaveProject();
  557. return;
  558. }
  559. ClearSceneData();
  560. InitDefaultTransitions();
  561. obs_data_t *modulesObj = obs_data_get_obj(data, "modules");
  562. if (api)
  563. api->on_preload(modulesObj);
  564. obs_data_array_t *sceneOrder = obs_data_get_array(data, "scene_order");
  565. obs_data_array_t *sources = obs_data_get_array(data, "sources");
  566. obs_data_array_t *transitions= obs_data_get_array(data, "transitions");
  567. const char *sceneName = obs_data_get_string(data,
  568. "current_scene");
  569. const char *programSceneName = obs_data_get_string(data,
  570. "current_program_scene");
  571. const char *transitionName = obs_data_get_string(data,
  572. "current_transition");
  573. if (!opt_starting_scene.empty()) {
  574. programSceneName = opt_starting_scene.c_str();
  575. if (!IsPreviewProgramMode())
  576. sceneName = opt_starting_scene.c_str();
  577. }
  578. int newDuration = obs_data_get_int(data, "transition_duration");
  579. if (!newDuration)
  580. newDuration = 300;
  581. if (!transitionName)
  582. transitionName = obs_source_get_name(fadeTransition);
  583. const char *curSceneCollection = config_get_string(
  584. App()->GlobalConfig(), "Basic", "SceneCollection");
  585. obs_data_set_default_string(data, "name", curSceneCollection);
  586. const char *name = obs_data_get_string(data, "name");
  587. obs_source_t *curScene;
  588. obs_source_t *curProgramScene;
  589. obs_source_t *curTransition;
  590. if (!name || !*name)
  591. name = curSceneCollection;
  592. LoadAudioDevice(DESKTOP_AUDIO_1, 1, data);
  593. LoadAudioDevice(DESKTOP_AUDIO_2, 2, data);
  594. LoadAudioDevice(AUX_AUDIO_1, 3, data);
  595. LoadAudioDevice(AUX_AUDIO_2, 4, data);
  596. LoadAudioDevice(AUX_AUDIO_3, 5, data);
  597. obs_load_sources(sources, OBSBasic::SourceLoaded, this);
  598. if (transitions)
  599. LoadTransitions(transitions);
  600. if (sceneOrder)
  601. LoadSceneListOrder(sceneOrder);
  602. obs_data_array_release(transitions);
  603. curTransition = FindTransition(transitionName);
  604. if (!curTransition)
  605. curTransition = fadeTransition;
  606. ui->transitionDuration->setValue(newDuration);
  607. SetTransition(curTransition);
  608. retryScene:
  609. curScene = obs_get_source_by_name(sceneName);
  610. curProgramScene = obs_get_source_by_name(programSceneName);
  611. /* if the starting scene command line parameter is bad at all,
  612. * fall back to original settings */
  613. if (!opt_starting_scene.empty() && (!curScene || !curProgramScene)) {
  614. sceneName = obs_data_get_string(data, "current_scene");
  615. programSceneName = obs_data_get_string(data,
  616. "current_program_scene");
  617. obs_source_release(curScene);
  618. obs_source_release(curProgramScene);
  619. opt_starting_scene.clear();
  620. goto retryScene;
  621. }
  622. if (!curProgramScene) {
  623. curProgramScene = curScene;
  624. obs_source_addref(curScene);
  625. }
  626. SetCurrentScene(curScene, true);
  627. if (IsPreviewProgramMode())
  628. TransitionToScene(curProgramScene, true);
  629. obs_source_release(curScene);
  630. obs_source_release(curProgramScene);
  631. obs_data_array_release(sources);
  632. obs_data_array_release(sceneOrder);
  633. /* ------------------- */
  634. bool projectorSave = config_get_bool(GetGlobalConfig(), "BasicWindow",
  635. "SaveProjectors");
  636. if (projectorSave) {
  637. obs_data_array_t *savedProjectors = obs_data_get_array(data,
  638. "saved_projectors");
  639. if (savedProjectors)
  640. LoadSavedProjectors(savedProjectors);
  641. obs_data_array_release(savedProjectors);
  642. }
  643. /* ------------------- */
  644. std::string file_base = strrchr(file, '/') + 1;
  645. file_base.erase(file_base.size() - 5, 5);
  646. config_set_string(App()->GlobalConfig(), "Basic", "SceneCollection",
  647. name);
  648. config_set_string(App()->GlobalConfig(), "Basic", "SceneCollectionFile",
  649. file_base.c_str());
  650. obs_data_array_t *quickTransitionData = obs_data_get_array(data,
  651. "quick_transitions");
  652. LoadQuickTransitions(quickTransitionData);
  653. obs_data_array_release(quickTransitionData);
  654. RefreshQuickTransitions();
  655. bool previewLocked = obs_data_get_bool(data, "preview_locked");
  656. ui->preview->SetLocked(previewLocked);
  657. ui->actionLockPreview->setChecked(previewLocked);
  658. /* ---------------------- */
  659. bool fixedScaling = obs_data_get_bool(data, "scaling_enabled");
  660. int scalingLevel = (int)obs_data_get_int(data, "scaling_level");
  661. float scrollOffX = (float)obs_data_get_double(data, "scaling_off_x");
  662. float scrollOffY = (float)obs_data_get_double(data, "scaling_off_y");
  663. if (fixedScaling) {
  664. ui->preview->SetScalingLevel(scalingLevel);
  665. ui->preview->SetScrollingOffset(scrollOffX, scrollOffY);
  666. }
  667. ui->preview->SetFixedScaling(fixedScaling);
  668. /* ---------------------- */
  669. if (api)
  670. api->on_load(modulesObj);
  671. obs_data_release(modulesObj);
  672. obs_data_release(data);
  673. if (!opt_starting_scene.empty())
  674. opt_starting_scene.clear();
  675. if (opt_start_streaming) {
  676. blog(LOG_INFO, "Starting stream due to command line parameter");
  677. QMetaObject::invokeMethod(this, "StartStreaming",
  678. Qt::QueuedConnection);
  679. opt_start_streaming = false;
  680. }
  681. if (opt_start_recording) {
  682. blog(LOG_INFO, "Starting recording due to command line parameter");
  683. QMetaObject::invokeMethod(this, "StartRecording",
  684. Qt::QueuedConnection);
  685. opt_start_recording = false;
  686. }
  687. if (opt_start_replaybuffer) {
  688. QMetaObject::invokeMethod(this, "StartReplayBuffer",
  689. Qt::QueuedConnection);
  690. opt_start_replaybuffer = false;
  691. }
  692. LogScenes();
  693. disableSaving--;
  694. if (api)
  695. api->on_event(OBS_FRONTEND_EVENT_SCENE_CHANGED);
  696. }
  697. #define SERVICE_PATH "service.json"
  698. void OBSBasic::SaveService()
  699. {
  700. if (!service)
  701. return;
  702. char serviceJsonPath[512];
  703. int ret = GetProfilePath(serviceJsonPath, sizeof(serviceJsonPath),
  704. SERVICE_PATH);
  705. if (ret <= 0)
  706. return;
  707. obs_data_t *data = obs_data_create();
  708. obs_data_t *settings = obs_service_get_settings(service);
  709. obs_data_set_string(data, "type", obs_service_get_type(service));
  710. obs_data_set_obj(data, "settings", settings);
  711. if (!obs_data_save_json_safe(data, serviceJsonPath, "tmp", "bak"))
  712. blog(LOG_WARNING, "Failed to save service");
  713. obs_data_release(settings);
  714. obs_data_release(data);
  715. }
  716. bool OBSBasic::LoadService()
  717. {
  718. const char *type;
  719. char serviceJsonPath[512];
  720. int ret = GetProfilePath(serviceJsonPath, sizeof(serviceJsonPath),
  721. SERVICE_PATH);
  722. if (ret <= 0)
  723. return false;
  724. obs_data_t *data = obs_data_create_from_json_file_safe(serviceJsonPath,
  725. "bak");
  726. obs_data_set_default_string(data, "type", "rtmp_common");
  727. type = obs_data_get_string(data, "type");
  728. obs_data_t *settings = obs_data_get_obj(data, "settings");
  729. obs_data_t *hotkey_data = obs_data_get_obj(data, "hotkeys");
  730. service = obs_service_create(type, "default_service", settings,
  731. hotkey_data);
  732. obs_service_release(service);
  733. obs_data_release(hotkey_data);
  734. obs_data_release(settings);
  735. obs_data_release(data);
  736. return !!service;
  737. }
  738. bool OBSBasic::InitService()
  739. {
  740. ProfileScope("OBSBasic::InitService");
  741. if (LoadService())
  742. return true;
  743. service = obs_service_create("rtmp_common", "default_service", nullptr,
  744. nullptr);
  745. if (!service)
  746. return false;
  747. obs_service_release(service);
  748. return true;
  749. }
  750. static const double scaled_vals[] =
  751. {
  752. 1.0,
  753. 1.25,
  754. (1.0/0.75),
  755. 1.5,
  756. (1.0/0.6),
  757. 1.75,
  758. 2.0,
  759. 2.25,
  760. 2.5,
  761. 2.75,
  762. 3.0,
  763. 0.0
  764. };
  765. bool OBSBasic::InitBasicConfigDefaults()
  766. {
  767. QList<QScreen*> screens = QGuiApplication::screens();
  768. if (!screens.size()) {
  769. OBSErrorBox(NULL, "There appears to be no monitors. Er, this "
  770. "technically shouldn't be possible.");
  771. return false;
  772. }
  773. QScreen *primaryScreen = QGuiApplication::primaryScreen();
  774. uint32_t cx = primaryScreen->size().width();
  775. uint32_t cy = primaryScreen->size().height();
  776. bool oldResolutionDefaults = config_get_bool(App()->GlobalConfig(),
  777. "General", "Pre19Defaults");
  778. /* use 1920x1080 for new default base res if main monitor is above
  779. * 1920x1080, but don't apply for people from older builds -- only to
  780. * new users */
  781. if (!oldResolutionDefaults && (cx * cy) > (1920 * 1080)) {
  782. cx = 1920;
  783. cy = 1080;
  784. }
  785. /* ----------------------------------------------------- */
  786. /* move over mixer values in advanced if older config */
  787. if (config_has_user_value(basicConfig, "AdvOut", "RecTrackIndex") &&
  788. !config_has_user_value(basicConfig, "AdvOut", "RecTracks")) {
  789. uint64_t track = config_get_uint(basicConfig, "AdvOut",
  790. "RecTrackIndex");
  791. track = 1ULL << (track - 1);
  792. config_set_uint(basicConfig, "AdvOut", "RecTracks", track);
  793. config_remove_value(basicConfig, "AdvOut", "RecTrackIndex");
  794. config_save_safe(basicConfig, "tmp", nullptr);
  795. }
  796. /* ----------------------------------------------------- */
  797. config_set_default_string(basicConfig, "Output", "Mode", "Simple");
  798. config_set_default_string(basicConfig, "SimpleOutput", "FilePath",
  799. GetDefaultVideoSavePath().c_str());
  800. config_set_default_string(basicConfig, "SimpleOutput", "RecFormat",
  801. "flv");
  802. config_set_default_uint (basicConfig, "SimpleOutput", "VBitrate",
  803. 2500);
  804. config_set_default_string(basicConfig, "SimpleOutput", "StreamEncoder",
  805. SIMPLE_ENCODER_X264);
  806. config_set_default_uint (basicConfig, "SimpleOutput", "ABitrate", 160);
  807. config_set_default_bool (basicConfig, "SimpleOutput", "UseAdvanced",
  808. false);
  809. config_set_default_bool (basicConfig, "SimpleOutput", "EnforceBitrate",
  810. true);
  811. config_set_default_string(basicConfig, "SimpleOutput", "Preset",
  812. "veryfast");
  813. config_set_default_string(basicConfig, "SimpleOutput", "RecQuality",
  814. "Stream");
  815. config_set_default_string(basicConfig, "SimpleOutput", "RecEncoder",
  816. SIMPLE_ENCODER_X264);
  817. config_set_default_bool(basicConfig, "SimpleOutput", "RecRB", false);
  818. config_set_default_int(basicConfig, "SimpleOutput", "RecRBTime", 20);
  819. config_set_default_int(basicConfig, "SimpleOutput", "RecRBSize", 512);
  820. config_set_default_string(basicConfig, "SimpleOutput", "RecRBPrefix",
  821. "Replay");
  822. config_set_default_bool (basicConfig, "AdvOut", "ApplyServiceSettings",
  823. true);
  824. config_set_default_bool (basicConfig, "AdvOut", "UseRescale", false);
  825. config_set_default_uint (basicConfig, "AdvOut", "TrackIndex", 1);
  826. config_set_default_string(basicConfig, "AdvOut", "Encoder", "obs_x264");
  827. config_set_default_string(basicConfig, "AdvOut", "RecType", "Standard");
  828. config_set_default_string(basicConfig, "AdvOut", "RecFilePath",
  829. GetDefaultVideoSavePath().c_str());
  830. config_set_default_string(basicConfig, "AdvOut", "RecFormat", "flv");
  831. config_set_default_bool (basicConfig, "AdvOut", "RecUseRescale",
  832. false);
  833. config_set_default_uint (basicConfig, "AdvOut", "RecTracks", (1<<0));
  834. config_set_default_string(basicConfig, "AdvOut", "RecEncoder",
  835. "none");
  836. config_set_default_bool (basicConfig, "AdvOut", "FFOutputToFile",
  837. true);
  838. config_set_default_string(basicConfig, "AdvOut", "FFFilePath",
  839. GetDefaultVideoSavePath().c_str());
  840. config_set_default_string(basicConfig, "AdvOut", "FFExtension", "mp4");
  841. config_set_default_uint (basicConfig, "AdvOut", "FFVBitrate", 2500);
  842. config_set_default_uint (basicConfig, "AdvOut", "FFVGOPSize", 250);
  843. config_set_default_bool (basicConfig, "AdvOut", "FFUseRescale",
  844. false);
  845. config_set_default_bool (basicConfig, "AdvOut", "FFIgnoreCompat",
  846. false);
  847. config_set_default_uint (basicConfig, "AdvOut", "FFABitrate", 160);
  848. config_set_default_uint (basicConfig, "AdvOut", "FFAudioTrack", 1);
  849. config_set_default_uint (basicConfig, "AdvOut", "Track1Bitrate", 160);
  850. config_set_default_uint (basicConfig, "AdvOut", "Track2Bitrate", 160);
  851. config_set_default_uint (basicConfig, "AdvOut", "Track3Bitrate", 160);
  852. config_set_default_uint (basicConfig, "AdvOut", "Track4Bitrate", 160);
  853. config_set_default_uint (basicConfig, "AdvOut", "Track5Bitrate", 160);
  854. config_set_default_uint (basicConfig, "AdvOut", "Track6Bitrate", 160);
  855. config_set_default_bool (basicConfig, "AdvOut", "RecRB", false);
  856. config_set_default_uint (basicConfig, "AdvOut", "RecRBTime", 20);
  857. config_set_default_int (basicConfig, "AdvOut", "RecRBSize", 512);
  858. config_set_default_uint (basicConfig, "Video", "BaseCX", cx);
  859. config_set_default_uint (basicConfig, "Video", "BaseCY", cy);
  860. /* don't allow BaseCX/BaseCY to be susceptible to defaults changing */
  861. if (!config_has_user_value(basicConfig, "Video", "BaseCX") ||
  862. !config_has_user_value(basicConfig, "Video", "BaseCY")) {
  863. config_set_uint(basicConfig, "Video", "BaseCX", cx);
  864. config_set_uint(basicConfig, "Video", "BaseCY", cy);
  865. config_save_safe(basicConfig, "tmp", nullptr);
  866. }
  867. config_set_default_string(basicConfig, "Output", "FilenameFormatting",
  868. "%CCYY-%MM-%DD %hh-%mm-%ss");
  869. config_set_default_bool (basicConfig, "Output", "DelayEnable", false);
  870. config_set_default_uint (basicConfig, "Output", "DelaySec", 20);
  871. config_set_default_bool (basicConfig, "Output", "DelayPreserve", true);
  872. config_set_default_bool (basicConfig, "Output", "Reconnect", true);
  873. config_set_default_uint (basicConfig, "Output", "RetryDelay", 10);
  874. config_set_default_uint (basicConfig, "Output", "MaxRetries", 20);
  875. config_set_default_string(basicConfig, "Output", "BindIP", "default");
  876. config_set_default_bool (basicConfig, "Output", "NewSocketLoopEnable",
  877. false);
  878. config_set_default_bool (basicConfig, "Output", "LowLatencyEnable",
  879. false);
  880. int i = 0;
  881. uint32_t scale_cx = cx;
  882. uint32_t scale_cy = cy;
  883. /* use a default scaled resolution that has a pixel count no higher
  884. * than 1280x720 */
  885. while (((scale_cx * scale_cy) > (1280 * 720)) && scaled_vals[i] > 0.0) {
  886. double scale = scaled_vals[i++];
  887. scale_cx = uint32_t(double(cx) / scale);
  888. scale_cy = uint32_t(double(cy) / scale);
  889. }
  890. config_set_default_uint (basicConfig, "Video", "OutputCX", scale_cx);
  891. config_set_default_uint (basicConfig, "Video", "OutputCY", scale_cy);
  892. /* don't allow OutputCX/OutputCY to be susceptible to defaults
  893. * changing */
  894. if (!config_has_user_value(basicConfig, "Video", "OutputCX") ||
  895. !config_has_user_value(basicConfig, "Video", "OutputCY")) {
  896. config_set_uint(basicConfig, "Video", "OutputCX", scale_cx);
  897. config_set_uint(basicConfig, "Video", "OutputCY", scale_cy);
  898. config_save_safe(basicConfig, "tmp", nullptr);
  899. }
  900. config_set_default_uint (basicConfig, "Video", "FPSType", 0);
  901. config_set_default_string(basicConfig, "Video", "FPSCommon", "30");
  902. config_set_default_uint (basicConfig, "Video", "FPSInt", 30);
  903. config_set_default_uint (basicConfig, "Video", "FPSNum", 30);
  904. config_set_default_uint (basicConfig, "Video", "FPSDen", 1);
  905. config_set_default_string(basicConfig, "Video", "ScaleType", "bicubic");
  906. config_set_default_string(basicConfig, "Video", "ColorFormat", "NV12");
  907. config_set_default_string(basicConfig, "Video", "ColorSpace", "601");
  908. config_set_default_string(basicConfig, "Video", "ColorRange",
  909. "Partial");
  910. config_set_default_string(basicConfig, "Audio", "MonitoringDeviceId",
  911. "default");
  912. config_set_default_string(basicConfig, "Audio", "MonitoringDeviceName",
  913. Str("Basic.Settings.Advanced.Audio.MonitoringDevice"
  914. ".Default"));
  915. config_set_default_uint (basicConfig, "Audio", "SampleRate", 44100);
  916. config_set_default_string(basicConfig, "Audio", "ChannelSetup",
  917. "Stereo");
  918. config_set_default_double(basicConfig, "Audio", "MeterDecayRate",
  919. VOLUME_METER_DECAY_FAST);
  920. return true;
  921. }
  922. bool OBSBasic::InitBasicConfig()
  923. {
  924. ProfileScope("OBSBasic::InitBasicConfig");
  925. char configPath[512];
  926. int ret = GetProfilePath(configPath, sizeof(configPath), "");
  927. if (ret <= 0) {
  928. OBSErrorBox(nullptr, "Failed to get profile path");
  929. return false;
  930. }
  931. if (os_mkdir(configPath) == MKDIR_ERROR) {
  932. OBSErrorBox(nullptr, "Failed to create profile path");
  933. return false;
  934. }
  935. ret = GetProfilePath(configPath, sizeof(configPath), "basic.ini");
  936. if (ret <= 0) {
  937. OBSErrorBox(nullptr, "Failed to get base.ini path");
  938. return false;
  939. }
  940. int code = basicConfig.Open(configPath, CONFIG_OPEN_ALWAYS);
  941. if (code != CONFIG_SUCCESS) {
  942. OBSErrorBox(NULL, "Failed to open basic.ini: %d", code);
  943. return false;
  944. }
  945. if (config_get_string(basicConfig, "General", "Name") == nullptr) {
  946. const char *curName = config_get_string(App()->GlobalConfig(),
  947. "Basic", "Profile");
  948. config_set_string(basicConfig, "General", "Name", curName);
  949. basicConfig.SaveSafe("tmp");
  950. }
  951. return InitBasicConfigDefaults();
  952. }
  953. void OBSBasic::InitOBSCallbacks()
  954. {
  955. ProfileScope("OBSBasic::InitOBSCallbacks");
  956. signalHandlers.reserve(signalHandlers.size() + 6);
  957. signalHandlers.emplace_back(obs_get_signal_handler(), "source_remove",
  958. OBSBasic::SourceRemoved, this);
  959. signalHandlers.emplace_back(obs_get_signal_handler(), "source_activate",
  960. OBSBasic::SourceActivated, this);
  961. signalHandlers.emplace_back(obs_get_signal_handler(), "source_deactivate",
  962. OBSBasic::SourceDeactivated, this);
  963. signalHandlers.emplace_back(obs_get_signal_handler(), "source_rename",
  964. OBSBasic::SourceRenamed, this);
  965. }
  966. void OBSBasic::InitPrimitives()
  967. {
  968. ProfileScope("OBSBasic::InitPrimitives");
  969. obs_enter_graphics();
  970. gs_render_start(true);
  971. gs_vertex2f(0.0f, 0.0f);
  972. gs_vertex2f(0.0f, 1.0f);
  973. gs_vertex2f(1.0f, 1.0f);
  974. gs_vertex2f(1.0f, 0.0f);
  975. gs_vertex2f(0.0f, 0.0f);
  976. box = gs_render_save();
  977. gs_render_start(true);
  978. gs_vertex2f(0.0f, 0.0f);
  979. gs_vertex2f(0.0f, 1.0f);
  980. boxLeft = gs_render_save();
  981. gs_render_start(true);
  982. gs_vertex2f(0.0f, 0.0f);
  983. gs_vertex2f(1.0f, 0.0f);
  984. boxTop = gs_render_save();
  985. gs_render_start(true);
  986. gs_vertex2f(1.0f, 0.0f);
  987. gs_vertex2f(1.0f, 1.0f);
  988. boxRight = gs_render_save();
  989. gs_render_start(true);
  990. gs_vertex2f(0.0f, 1.0f);
  991. gs_vertex2f(1.0f, 1.0f);
  992. boxBottom = gs_render_save();
  993. gs_render_start(true);
  994. for (int i = 0; i <= 360; i += (360/20)) {
  995. float pos = RAD(float(i));
  996. gs_vertex2f(cosf(pos), sinf(pos));
  997. }
  998. circle = gs_render_save();
  999. obs_leave_graphics();
  1000. }
  1001. void OBSBasic::ReplayBufferClicked()
  1002. {
  1003. if (outputHandler->ReplayBufferActive())
  1004. StopReplayBuffer();
  1005. else
  1006. StartReplayBuffer();
  1007. };
  1008. void OBSBasic::ResetOutputs()
  1009. {
  1010. ProfileScope("OBSBasic::ResetOutputs");
  1011. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  1012. bool advOut = astrcmpi(mode, "Advanced") == 0;
  1013. if (!outputHandler || !outputHandler->Active()) {
  1014. outputHandler.reset();
  1015. outputHandler.reset(advOut ?
  1016. CreateAdvancedOutputHandler(this) :
  1017. CreateSimpleOutputHandler(this));
  1018. delete replayBufferButton;
  1019. if (outputHandler->replayBuffer) {
  1020. replayBufferButton = new QPushButton(
  1021. QTStr("Basic.Main.StartReplayBuffer"),
  1022. this);
  1023. connect(replayBufferButton.data(),
  1024. &QPushButton::clicked,
  1025. this,
  1026. &OBSBasic::ReplayBufferClicked);
  1027. replayBufferButton->setProperty("themeID", "replayBufferButton");
  1028. ui->buttonsVLayout->insertWidget(2, replayBufferButton);
  1029. }
  1030. if (sysTrayReplayBuffer)
  1031. sysTrayReplayBuffer->setEnabled(
  1032. !!outputHandler->replayBuffer);
  1033. } else {
  1034. outputHandler->Update();
  1035. }
  1036. }
  1037. static void AddProjectorMenuMonitors(QMenu *parent, QObject *target,
  1038. const char *slot);
  1039. #define STARTUP_SEPARATOR \
  1040. "==== Startup complete ==============================================="
  1041. #define SHUTDOWN_SEPARATOR \
  1042. "==== Shutting down =================================================="
  1043. extern obs_frontend_callbacks *InitializeAPIInterface(OBSBasic *main);
  1044. #define UNSUPPORTED_ERROR \
  1045. "Failed to initialize video:\n\nRequired graphics API functionality " \
  1046. "not found. Your GPU may not be supported."
  1047. #define UNKNOWN_ERROR \
  1048. "Failed to initialize video. Your GPU may not be supported, " \
  1049. "or your graphics drivers may need to be updated."
  1050. void OBSBasic::OBSInit()
  1051. {
  1052. ProfileScope("OBSBasic::OBSInit");
  1053. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  1054. "Basic", "SceneCollectionFile");
  1055. char savePath[512];
  1056. char fileName[512];
  1057. int ret;
  1058. if (!sceneCollection)
  1059. throw "Failed to get scene collection name";
  1060. ret = snprintf(fileName, 512, "obs-studio/basic/scenes/%s.json",
  1061. sceneCollection);
  1062. if (ret <= 0)
  1063. throw "Failed to create scene collection file name";
  1064. ret = GetConfigPath(savePath, sizeof(savePath), fileName);
  1065. if (ret <= 0)
  1066. throw "Failed to get scene collection json file path";
  1067. if (!InitBasicConfig())
  1068. throw "Failed to load basic.ini";
  1069. if (!ResetAudio())
  1070. throw "Failed to initialize audio";
  1071. ret = ResetVideo();
  1072. switch (ret) {
  1073. case OBS_VIDEO_MODULE_NOT_FOUND:
  1074. throw "Failed to initialize video: Graphics module not found";
  1075. case OBS_VIDEO_NOT_SUPPORTED:
  1076. throw UNSUPPORTED_ERROR;
  1077. case OBS_VIDEO_INVALID_PARAM:
  1078. throw "Failed to initialize video: Invalid parameters";
  1079. default:
  1080. if (ret != OBS_VIDEO_SUCCESS)
  1081. throw UNKNOWN_ERROR;
  1082. }
  1083. /* load audio monitoring */
  1084. #if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
  1085. const char *device_name = config_get_string(basicConfig, "Audio",
  1086. "MonitoringDeviceName");
  1087. const char *device_id = config_get_string(basicConfig, "Audio",
  1088. "MonitoringDeviceId");
  1089. obs_set_audio_monitoring_device(device_name, device_id);
  1090. blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s",
  1091. device_name, device_id);
  1092. #endif
  1093. InitOBSCallbacks();
  1094. InitHotkeys();
  1095. api = InitializeAPIInterface(this);
  1096. AddExtraModulePaths();
  1097. blog(LOG_INFO, "---------------------------------");
  1098. obs_load_all_modules();
  1099. blog(LOG_INFO, "---------------------------------");
  1100. obs_log_loaded_modules();
  1101. blog(LOG_INFO, "---------------------------------");
  1102. obs_post_load_modules();
  1103. CheckForSimpleModeX264Fallback();
  1104. blog(LOG_INFO, STARTUP_SEPARATOR);
  1105. ResetOutputs();
  1106. CreateHotkeys();
  1107. if (!InitService())
  1108. throw "Failed to initialize service";
  1109. InitPrimitives();
  1110. sceneDuplicationMode = config_get_bool(App()->GlobalConfig(),
  1111. "BasicWindow", "SceneDuplicationMode");
  1112. swapScenesMode = config_get_bool(App()->GlobalConfig(),
  1113. "BasicWindow", "SwapScenesMode");
  1114. editPropertiesMode = config_get_bool(App()->GlobalConfig(),
  1115. "BasicWindow", "EditPropertiesMode");
  1116. if (!opt_studio_mode) {
  1117. SetPreviewProgramMode(config_get_bool(App()->GlobalConfig(),
  1118. "BasicWindow", "PreviewProgramMode"));
  1119. } else {
  1120. SetPreviewProgramMode(true);
  1121. opt_studio_mode = false;
  1122. }
  1123. #define SET_VISIBILITY(name, control) \
  1124. do { \
  1125. if (config_has_user_value(App()->GlobalConfig(), \
  1126. "BasicWindow", name)) { \
  1127. bool visible = config_get_bool(App()->GlobalConfig(), \
  1128. "BasicWindow", name); \
  1129. ui->control->setChecked(visible); \
  1130. } \
  1131. } while (false)
  1132. SET_VISIBILITY("ShowListboxToolbars", toggleListboxToolbars);
  1133. SET_VISIBILITY("ShowStatusBar", toggleStatusBar);
  1134. #undef SET_VISIBILITY
  1135. {
  1136. ProfileScope("OBSBasic::Load");
  1137. disableSaving--;
  1138. Load(savePath);
  1139. disableSaving++;
  1140. }
  1141. TimedCheckForUpdates();
  1142. loaded = true;
  1143. previewEnabled = config_get_bool(App()->GlobalConfig(),
  1144. "BasicWindow", "PreviewEnabled");
  1145. if (!previewEnabled && !IsPreviewProgramMode())
  1146. QMetaObject::invokeMethod(this, "EnablePreviewDisplay",
  1147. Qt::QueuedConnection,
  1148. Q_ARG(bool, previewEnabled));
  1149. #ifdef _WIN32
  1150. uint32_t winVer = GetWindowsVersion();
  1151. if (winVer > 0 && winVer < 0x602) {
  1152. bool disableAero = config_get_bool(basicConfig, "Video",
  1153. "DisableAero");
  1154. SetAeroEnabled(!disableAero);
  1155. }
  1156. #endif
  1157. RefreshSceneCollections();
  1158. RefreshProfiles();
  1159. disableSaving--;
  1160. auto addDisplay = [this] (OBSQTDisplay *window)
  1161. {
  1162. obs_display_add_draw_callback(window->GetDisplay(),
  1163. OBSBasic::RenderMain, this);
  1164. struct obs_video_info ovi;
  1165. if (obs_get_video_info(&ovi))
  1166. ResizePreview(ovi.base_width, ovi.base_height);
  1167. };
  1168. connect(ui->preview, &OBSQTDisplay::DisplayCreated, addDisplay);
  1169. #ifdef _WIN32
  1170. SetWin32DropStyle(this);
  1171. show();
  1172. #endif
  1173. bool alwaysOnTop = config_get_bool(App()->GlobalConfig(), "BasicWindow",
  1174. "AlwaysOnTop");
  1175. if (alwaysOnTop || opt_always_on_top) {
  1176. SetAlwaysOnTop(this, true);
  1177. ui->actionAlwaysOnTop->setChecked(true);
  1178. }
  1179. #ifndef _WIN32
  1180. show();
  1181. #endif
  1182. const char *dockStateStr = config_get_string(App()->GlobalConfig(),
  1183. "BasicWindow", "DockState");
  1184. if (!dockStateStr) {
  1185. on_resetUI_triggered();
  1186. } else {
  1187. QByteArray dockState =
  1188. QByteArray::fromBase64(QByteArray(dockStateStr));
  1189. if (!restoreState(dockState))
  1190. on_resetUI_triggered();
  1191. }
  1192. config_set_default_bool(App()->GlobalConfig(), "BasicWindow",
  1193. "DocksLocked", true);
  1194. bool docksLocked = config_get_bool(App()->GlobalConfig(),
  1195. "BasicWindow", "DocksLocked");
  1196. on_lockUI_toggled(docksLocked);
  1197. ui->lockUI->blockSignals(true);
  1198. ui->lockUI->setChecked(docksLocked);
  1199. ui->lockUI->blockSignals(false);
  1200. SystemTray(true);
  1201. if (windowState().testFlag(Qt::WindowFullScreen))
  1202. fullscreenInterface = true;
  1203. bool has_last_version = config_has_user_value(App()->GlobalConfig(),
  1204. "General", "LastVersion");
  1205. bool first_run = config_get_bool(App()->GlobalConfig(), "General",
  1206. "FirstRun");
  1207. if (!first_run) {
  1208. config_set_bool(App()->GlobalConfig(), "General", "FirstRun",
  1209. true);
  1210. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  1211. }
  1212. if (!first_run && !has_last_version && !Active()) {
  1213. QString msg;
  1214. msg = QTStr("Basic.FirstStartup.RunWizard");
  1215. msg += "\n\n";
  1216. msg += QTStr("Basic.FirstStartup.RunWizard.BetaWarning");
  1217. QMessageBox::StandardButton button =
  1218. OBSMessageBox::question(this, QTStr("Basic.AutoConfig"),
  1219. msg);
  1220. if (button == QMessageBox::Yes) {
  1221. on_autoConfigure_triggered();
  1222. } else {
  1223. msg = QTStr("Basic.FirstStartup.RunWizard.NoClicked");
  1224. OBSMessageBox::information(this,
  1225. QTStr("Basic.AutoConfig"), msg);
  1226. }
  1227. }
  1228. if (config_get_bool(basicConfig, "General", "OpenStatsOnStartup"))
  1229. on_stats_triggered();
  1230. OBSBasicStats::InitializeValues();
  1231. /* ----------------------- */
  1232. /* Add multiview menu */
  1233. ui->viewMenu->addSeparator();
  1234. multiviewProjectorMenu = new QMenu(QTStr("MultiviewProjector"));
  1235. ui->viewMenu->addMenu(multiviewProjectorMenu);
  1236. connect(ui->viewMenu->menuAction(), &QAction::hovered, this,
  1237. &OBSBasic::UpdateMultiviewProjectorMenu);
  1238. ui->viewMenu->addAction(QTStr("MultiviewWindowed"),
  1239. this, SLOT(OpenMultiviewWindow()));
  1240. #if !defined(_WIN32) && !defined(__APPLE__)
  1241. delete ui->actionShowCrashLogs;
  1242. delete ui->actionUploadLastCrashLog;
  1243. delete ui->menuCrashLogs;
  1244. delete ui->actionCheckForUpdates;
  1245. ui->actionShowCrashLogs = nullptr;
  1246. ui->actionUploadLastCrashLog = nullptr;
  1247. ui->menuCrashLogs = nullptr;
  1248. ui->actionCheckForUpdates = nullptr;
  1249. #endif
  1250. }
  1251. void OBSBasic::UpdateMultiviewProjectorMenu()
  1252. {
  1253. multiviewProjectorMenu->clear();
  1254. AddProjectorMenuMonitors(multiviewProjectorMenu, this,
  1255. SLOT(OpenMultiviewProjector()));
  1256. }
  1257. void OBSBasic::InitHotkeys()
  1258. {
  1259. ProfileScope("OBSBasic::InitHotkeys");
  1260. struct obs_hotkeys_translations t = {};
  1261. t.insert = Str("Hotkeys.Insert");
  1262. t.del = Str("Hotkeys.Delete");
  1263. t.home = Str("Hotkeys.Home");
  1264. t.end = Str("Hotkeys.End");
  1265. t.page_up = Str("Hotkeys.PageUp");
  1266. t.page_down = Str("Hotkeys.PageDown");
  1267. t.num_lock = Str("Hotkeys.NumLock");
  1268. t.scroll_lock = Str("Hotkeys.ScrollLock");
  1269. t.caps_lock = Str("Hotkeys.CapsLock");
  1270. t.backspace = Str("Hotkeys.Backspace");
  1271. t.tab = Str("Hotkeys.Tab");
  1272. t.print = Str("Hotkeys.Print");
  1273. t.pause = Str("Hotkeys.Pause");
  1274. t.left = Str("Hotkeys.Left");
  1275. t.right = Str("Hotkeys.Right");
  1276. t.up = Str("Hotkeys.Up");
  1277. t.down = Str("Hotkeys.Down");
  1278. #ifdef _WIN32
  1279. t.meta = Str("Hotkeys.Windows");
  1280. #else
  1281. t.meta = Str("Hotkeys.Super");
  1282. #endif
  1283. t.menu = Str("Hotkeys.Menu");
  1284. t.space = Str("Hotkeys.Space");
  1285. t.numpad_num = Str("Hotkeys.NumpadNum");
  1286. t.numpad_multiply = Str("Hotkeys.NumpadMultiply");
  1287. t.numpad_divide = Str("Hotkeys.NumpadDivide");
  1288. t.numpad_plus = Str("Hotkeys.NumpadAdd");
  1289. t.numpad_minus = Str("Hotkeys.NumpadSubtract");
  1290. t.numpad_decimal = Str("Hotkeys.NumpadDecimal");
  1291. t.apple_keypad_num = Str("Hotkeys.AppleKeypadNum");
  1292. t.apple_keypad_multiply = Str("Hotkeys.AppleKeypadMultiply");
  1293. t.apple_keypad_divide = Str("Hotkeys.AppleKeypadDivide");
  1294. t.apple_keypad_plus = Str("Hotkeys.AppleKeypadAdd");
  1295. t.apple_keypad_minus = Str("Hotkeys.AppleKeypadSubtract");
  1296. t.apple_keypad_decimal = Str("Hotkeys.AppleKeypadDecimal");
  1297. t.apple_keypad_equal = Str("Hotkeys.AppleKeypadEqual");
  1298. t.mouse_num = Str("Hotkeys.MouseButton");
  1299. obs_hotkeys_set_translations(&t);
  1300. obs_hotkeys_set_audio_hotkeys_translations(Str("Mute"), Str("Unmute"),
  1301. Str("Push-to-mute"), Str("Push-to-talk"));
  1302. obs_hotkeys_set_sceneitem_hotkeys_translations(
  1303. Str("SceneItemShow"), Str("SceneItemHide"));
  1304. obs_hotkey_enable_callback_rerouting(true);
  1305. obs_hotkey_set_callback_routing_func(OBSBasic::HotkeyTriggered, this);
  1306. }
  1307. void OBSBasic::ProcessHotkey(obs_hotkey_id id, bool pressed)
  1308. {
  1309. obs_hotkey_trigger_routed_callback(id, pressed);
  1310. }
  1311. void OBSBasic::HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed)
  1312. {
  1313. OBSBasic &basic = *static_cast<OBSBasic*>(data);
  1314. QMetaObject::invokeMethod(&basic, "ProcessHotkey",
  1315. Q_ARG(obs_hotkey_id, id), Q_ARG(bool, pressed));
  1316. }
  1317. void OBSBasic::CreateHotkeys()
  1318. {
  1319. ProfileScope("OBSBasic::CreateHotkeys");
  1320. auto LoadHotkeyData = [&](const char *name) -> OBSData
  1321. {
  1322. const char *info = config_get_string(basicConfig,
  1323. "Hotkeys", name);
  1324. if (!info)
  1325. return {};
  1326. obs_data_t *data = obs_data_create_from_json(info);
  1327. if (!data)
  1328. return {};
  1329. OBSData res = data;
  1330. obs_data_release(data);
  1331. return res;
  1332. };
  1333. auto LoadHotkey = [&](obs_hotkey_id id, const char *name)
  1334. {
  1335. obs_data_array_t *array =
  1336. obs_data_get_array(LoadHotkeyData(name), "bindings");
  1337. obs_hotkey_load(id, array);
  1338. obs_data_array_release(array);
  1339. };
  1340. auto LoadHotkeyPair = [&](obs_hotkey_pair_id id, const char *name0,
  1341. const char *name1)
  1342. {
  1343. obs_data_array_t *array0 =
  1344. obs_data_get_array(LoadHotkeyData(name0), "bindings");
  1345. obs_data_array_t *array1 =
  1346. obs_data_get_array(LoadHotkeyData(name1), "bindings");
  1347. obs_hotkey_pair_load(id, array0, array1);
  1348. obs_data_array_release(array0);
  1349. obs_data_array_release(array1);
  1350. };
  1351. #define MAKE_CALLBACK(pred, method, log_action) \
  1352. [](void *data, obs_hotkey_pair_id, obs_hotkey_t*, bool pressed) \
  1353. { \
  1354. OBSBasic &basic = *static_cast<OBSBasic*>(data); \
  1355. if (pred && pressed) { \
  1356. blog(LOG_INFO, log_action " due to hotkey"); \
  1357. method(); \
  1358. return true; \
  1359. } \
  1360. return false; \
  1361. }
  1362. streamingHotkeys = obs_hotkey_pair_register_frontend(
  1363. "OBSBasic.StartStreaming",
  1364. Str("Basic.Main.StartStreaming"),
  1365. "OBSBasic.StopStreaming",
  1366. Str("Basic.Main.StopStreaming"),
  1367. MAKE_CALLBACK(!basic.outputHandler->StreamingActive(),
  1368. basic.StartStreaming, "Starting stream"),
  1369. MAKE_CALLBACK(basic.outputHandler->StreamingActive(),
  1370. basic.StopStreaming, "Stopping stream"),
  1371. this, this);
  1372. LoadHotkeyPair(streamingHotkeys,
  1373. "OBSBasic.StartStreaming", "OBSBasic.StopStreaming");
  1374. auto cb = [] (void *data, obs_hotkey_id, obs_hotkey_t*, bool pressed)
  1375. {
  1376. OBSBasic &basic = *static_cast<OBSBasic*>(data);
  1377. if (basic.outputHandler->StreamingActive() && pressed) {
  1378. basic.ForceStopStreaming();
  1379. }
  1380. };
  1381. forceStreamingStopHotkey = obs_hotkey_register_frontend(
  1382. "OBSBasic.ForceStopStreaming",
  1383. Str("Basic.Main.ForceStopStreaming"),
  1384. cb, this);
  1385. LoadHotkey(forceStreamingStopHotkey,
  1386. "OBSBasic.ForceStopStreaming");
  1387. recordingHotkeys = obs_hotkey_pair_register_frontend(
  1388. "OBSBasic.StartRecording",
  1389. Str("Basic.Main.StartRecording"),
  1390. "OBSBasic.StopRecording",
  1391. Str("Basic.Main.StopRecording"),
  1392. MAKE_CALLBACK(!basic.outputHandler->RecordingActive(),
  1393. basic.StartRecording, "Starting recording"),
  1394. MAKE_CALLBACK(basic.outputHandler->RecordingActive(),
  1395. basic.StopRecording, "Stopping recording"),
  1396. this, this);
  1397. LoadHotkeyPair(recordingHotkeys,
  1398. "OBSBasic.StartRecording", "OBSBasic.StopRecording");
  1399. replayBufHotkeys = obs_hotkey_pair_register_frontend(
  1400. "OBSBasic.StartReplayBuffer",
  1401. Str("Basic.Main.StartReplayBuffer"),
  1402. "OBSBasic.StopReplayBuffer",
  1403. Str("Basic.Main.StopReplayBuffer"),
  1404. MAKE_CALLBACK(!basic.outputHandler->ReplayBufferActive(),
  1405. basic.StartReplayBuffer, "Starting replay buffer"),
  1406. MAKE_CALLBACK(basic.outputHandler->ReplayBufferActive(),
  1407. basic.StopReplayBuffer, "Stopping replay buffer"),
  1408. this, this);
  1409. LoadHotkeyPair(replayBufHotkeys,
  1410. "OBSBasic.StartReplayBuffer", "OBSBasic.StopReplayBuffer");
  1411. #undef MAKE_CALLBACK
  1412. auto togglePreviewProgram = [] (void *data, obs_hotkey_id,
  1413. obs_hotkey_t*, bool pressed)
  1414. {
  1415. if (pressed)
  1416. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1417. "on_modeSwitch_clicked",
  1418. Qt::QueuedConnection);
  1419. };
  1420. togglePreviewProgramHotkey = obs_hotkey_register_frontend(
  1421. "OBSBasic.TogglePreviewProgram",
  1422. Str("Basic.TogglePreviewProgramMode"),
  1423. togglePreviewProgram, this);
  1424. LoadHotkey(togglePreviewProgramHotkey, "OBSBasic.TogglePreviewProgram");
  1425. auto transition = [] (void *data, obs_hotkey_id, obs_hotkey_t*,
  1426. bool pressed)
  1427. {
  1428. if (pressed)
  1429. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1430. "TransitionClicked",
  1431. Qt::QueuedConnection);
  1432. };
  1433. transitionHotkey = obs_hotkey_register_frontend(
  1434. "OBSBasic.Transition",
  1435. Str("Transition"), transition, this);
  1436. LoadHotkey(transitionHotkey, "OBSBasic.Transition");
  1437. }
  1438. void OBSBasic::ClearHotkeys()
  1439. {
  1440. obs_hotkey_pair_unregister(streamingHotkeys);
  1441. obs_hotkey_pair_unregister(recordingHotkeys);
  1442. obs_hotkey_pair_unregister(replayBufHotkeys);
  1443. obs_hotkey_unregister(forceStreamingStopHotkey);
  1444. obs_hotkey_unregister(togglePreviewProgramHotkey);
  1445. obs_hotkey_unregister(transitionHotkey);
  1446. }
  1447. OBSBasic::~OBSBasic()
  1448. {
  1449. if (updateCheckThread && updateCheckThread->isRunning())
  1450. updateCheckThread->wait();
  1451. delete programOptions;
  1452. delete program;
  1453. /* XXX: any obs data must be released before calling obs_shutdown.
  1454. * currently, we can't automate this with C++ RAII because of the
  1455. * delicate nature of obs_shutdown needing to be freed before the UI
  1456. * can be freed, and we have no control over the destruction order of
  1457. * the Qt UI stuff, so we have to manually clear any references to
  1458. * libobs. */
  1459. delete cpuUsageTimer;
  1460. os_cpu_usage_info_destroy(cpuUsageInfo);
  1461. obs_hotkey_set_callback_routing_func(nullptr, nullptr);
  1462. ClearHotkeys();
  1463. service = nullptr;
  1464. outputHandler.reset();
  1465. if (interaction)
  1466. delete interaction;
  1467. if (properties)
  1468. delete properties;
  1469. if (filters)
  1470. delete filters;
  1471. if (transformWindow)
  1472. delete transformWindow;
  1473. if (advAudioWindow)
  1474. delete advAudioWindow;
  1475. obs_display_remove_draw_callback(ui->preview->GetDisplay(),
  1476. OBSBasic::RenderMain, this);
  1477. obs_enter_graphics();
  1478. gs_vertexbuffer_destroy(box);
  1479. gs_vertexbuffer_destroy(boxLeft);
  1480. gs_vertexbuffer_destroy(boxTop);
  1481. gs_vertexbuffer_destroy(boxRight);
  1482. gs_vertexbuffer_destroy(boxBottom);
  1483. gs_vertexbuffer_destroy(circle);
  1484. obs_leave_graphics();
  1485. /* When shutting down, sometimes source references can get in to the
  1486. * event queue, and if we don't forcibly process those events they
  1487. * won't get processed until after obs_shutdown has been called. I
  1488. * really wish there were a more elegant way to deal with this via C++,
  1489. * but Qt doesn't use C++ in a normal way, so you can't really rely on
  1490. * normal C++ behavior for your data to be freed in the order that you
  1491. * expect or want it to. */
  1492. QApplication::sendPostedEvents(this);
  1493. config_set_int(App()->GlobalConfig(), "General", "LastVersion",
  1494. LIBOBS_API_VER);
  1495. bool alwaysOnTop = IsAlwaysOnTop(this);
  1496. config_set_bool(App()->GlobalConfig(), "BasicWindow", "PreviewEnabled",
  1497. previewEnabled);
  1498. config_set_bool(App()->GlobalConfig(), "BasicWindow", "AlwaysOnTop",
  1499. alwaysOnTop);
  1500. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1501. "SceneDuplicationMode", sceneDuplicationMode);
  1502. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1503. "SwapScenesMode", swapScenesMode);
  1504. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1505. "EditPropertiesMode", editPropertiesMode);
  1506. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1507. "PreviewProgramMode", IsPreviewProgramMode());
  1508. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  1509. "DocksLocked", ui->lockUI->isChecked());
  1510. config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
  1511. #ifdef _WIN32
  1512. uint32_t winVer = GetWindowsVersion();
  1513. if (winVer > 0 && winVer < 0x602) {
  1514. bool disableAero = config_get_bool(basicConfig, "Video",
  1515. "DisableAero");
  1516. if (disableAero) {
  1517. SetAeroEnabled(true);
  1518. }
  1519. }
  1520. #endif
  1521. }
  1522. void OBSBasic::SaveProjectNow()
  1523. {
  1524. if (disableSaving)
  1525. return;
  1526. projectChanged = true;
  1527. SaveProjectDeferred();
  1528. }
  1529. void OBSBasic::SaveProject()
  1530. {
  1531. if (disableSaving)
  1532. return;
  1533. projectChanged = true;
  1534. QMetaObject::invokeMethod(this, "SaveProjectDeferred",
  1535. Qt::QueuedConnection);
  1536. }
  1537. void OBSBasic::SaveProjectDeferred()
  1538. {
  1539. if (disableSaving)
  1540. return;
  1541. if (!projectChanged)
  1542. return;
  1543. projectChanged = false;
  1544. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  1545. "Basic", "SceneCollectionFile");
  1546. char savePath[512];
  1547. char fileName[512];
  1548. int ret;
  1549. if (!sceneCollection)
  1550. return;
  1551. ret = snprintf(fileName, 512, "obs-studio/basic/scenes/%s.json",
  1552. sceneCollection);
  1553. if (ret <= 0)
  1554. return;
  1555. ret = GetConfigPath(savePath, sizeof(savePath), fileName);
  1556. if (ret <= 0)
  1557. return;
  1558. Save(savePath);
  1559. }
  1560. OBSSource OBSBasic::GetProgramSource()
  1561. {
  1562. return OBSGetStrongRef(programScene);
  1563. }
  1564. OBSScene OBSBasic::GetCurrentScene()
  1565. {
  1566. QListWidgetItem *item = ui->scenes->currentItem();
  1567. return item ? GetOBSRef<OBSScene>(item) : nullptr;
  1568. }
  1569. OBSSceneItem OBSBasic::GetSceneItem(QListWidgetItem *item)
  1570. {
  1571. return item ? GetOBSRef<OBSSceneItem>(item) : nullptr;
  1572. }
  1573. OBSSceneItem OBSBasic::GetCurrentSceneItem()
  1574. {
  1575. return GetSceneItem(GetTopSelectedSourceItem());
  1576. }
  1577. void OBSBasic::UpdatePreviewScalingMenu()
  1578. {
  1579. bool fixedScaling = ui->preview->IsFixedScaling();
  1580. float scalingAmount = ui->preview->GetScalingAmount();
  1581. if (!fixedScaling) {
  1582. ui->actionScaleWindow->setChecked(true);
  1583. ui->actionScaleCanvas->setChecked(false);
  1584. ui->actionScaleOutput->setChecked(false);
  1585. return;
  1586. }
  1587. obs_video_info ovi;
  1588. obs_get_video_info(&ovi);
  1589. ui->actionScaleWindow->setChecked(false);
  1590. ui->actionScaleCanvas->setChecked(scalingAmount == 1.0f);
  1591. ui->actionScaleOutput->setChecked(
  1592. scalingAmount == float(ovi.output_width) / float(ovi.base_width));
  1593. }
  1594. void OBSBasic::UpdateSources(OBSScene scene)
  1595. {
  1596. ClearListItems(ui->sources);
  1597. obs_scene_enum_items(scene,
  1598. [] (obs_scene_t *scene, obs_sceneitem_t *item, void *p)
  1599. {
  1600. OBSBasic *window = static_cast<OBSBasic*>(p);
  1601. window->InsertSceneItem(item);
  1602. UNUSED_PARAMETER(scene);
  1603. return true;
  1604. }, this);
  1605. }
  1606. void OBSBasic::InsertSceneItem(obs_sceneitem_t *item)
  1607. {
  1608. QListWidgetItem *listItem = new QListWidgetItem();
  1609. SetOBSRef(listItem, OBSSceneItem(item));
  1610. ui->sources->insertItem(0, listItem);
  1611. ui->sources->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
  1612. SetupVisibilityItem(ui->sources, listItem, item);
  1613. }
  1614. void OBSBasic::CreateInteractionWindow(obs_source_t *source)
  1615. {
  1616. if (interaction)
  1617. interaction->close();
  1618. interaction = new OBSBasicInteraction(this, source);
  1619. interaction->Init();
  1620. interaction->setAttribute(Qt::WA_DeleteOnClose, true);
  1621. }
  1622. void OBSBasic::CreatePropertiesWindow(obs_source_t *source)
  1623. {
  1624. if (properties)
  1625. properties->close();
  1626. properties = new OBSBasicProperties(this, source);
  1627. properties->Init();
  1628. properties->setAttribute(Qt::WA_DeleteOnClose, true);
  1629. }
  1630. void OBSBasic::CreateFiltersWindow(obs_source_t *source)
  1631. {
  1632. if (filters)
  1633. filters->close();
  1634. filters = new OBSBasicFilters(this, source);
  1635. filters->Init();
  1636. filters->setAttribute(Qt::WA_DeleteOnClose, true);
  1637. }
  1638. /* Qt callbacks for invokeMethod */
  1639. void OBSBasic::AddScene(OBSSource source)
  1640. {
  1641. const char *name = obs_source_get_name(source);
  1642. obs_scene_t *scene = obs_scene_from_source(source);
  1643. QListWidgetItem *item = new QListWidgetItem(QT_UTF8(name));
  1644. SetOBSRef(item, OBSScene(scene));
  1645. ui->scenes->addItem(item);
  1646. obs_hotkey_register_source(source, "OBSBasic.SelectScene",
  1647. Str("Basic.Hotkeys.SelectScene"),
  1648. [](void *data,
  1649. obs_hotkey_id, obs_hotkey_t*, bool pressed)
  1650. {
  1651. OBSBasic *main =
  1652. reinterpret_cast<OBSBasic*>(App()->GetMainWindow());
  1653. auto potential_source = static_cast<obs_source_t*>(data);
  1654. auto source = obs_source_get_ref(potential_source);
  1655. if (source && pressed)
  1656. main->SetCurrentScene(source);
  1657. obs_source_release(source);
  1658. }, static_cast<obs_source_t*>(source));
  1659. signal_handler_t *handler = obs_source_get_signal_handler(source);
  1660. SignalContainer<OBSScene> container;
  1661. container.ref = scene;
  1662. container.handlers.assign({
  1663. std::make_shared<OBSSignal>(handler, "item_add",
  1664. OBSBasic::SceneItemAdded, this),
  1665. std::make_shared<OBSSignal>(handler, "item_remove",
  1666. OBSBasic::SceneItemRemoved, this),
  1667. std::make_shared<OBSSignal>(handler, "item_select",
  1668. OBSBasic::SceneItemSelected, this),
  1669. std::make_shared<OBSSignal>(handler, "item_deselect",
  1670. OBSBasic::SceneItemDeselected, this),
  1671. std::make_shared<OBSSignal>(handler, "reorder",
  1672. OBSBasic::SceneReordered, this),
  1673. });
  1674. item->setData(static_cast<int>(QtDataRole::OBSSignals),
  1675. QVariant::fromValue(container));
  1676. /* if the scene already has items (a duplicated scene) add them */
  1677. auto addSceneItem = [this] (obs_sceneitem_t *item)
  1678. {
  1679. AddSceneItem(item);
  1680. };
  1681. using addSceneItem_t = decltype(addSceneItem);
  1682. obs_scene_enum_items(scene,
  1683. [] (obs_scene_t*, obs_sceneitem_t *item, void *param)
  1684. {
  1685. addSceneItem_t *func;
  1686. func = reinterpret_cast<addSceneItem_t*>(param);
  1687. (*func)(item);
  1688. return true;
  1689. }, &addSceneItem);
  1690. SaveProject();
  1691. if (!disableSaving) {
  1692. obs_source_t *source = obs_scene_get_source(scene);
  1693. blog(LOG_INFO, "User added scene '%s'",
  1694. obs_source_get_name(source));
  1695. OBSProjector::UpdateMultiviewProjectors();
  1696. }
  1697. if (api)
  1698. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  1699. }
  1700. void OBSBasic::RemoveScene(OBSSource source)
  1701. {
  1702. obs_scene_t *scene = obs_scene_from_source(source);
  1703. QListWidgetItem *sel = nullptr;
  1704. int count = ui->scenes->count();
  1705. for (int i = 0; i < count; i++) {
  1706. auto item = ui->scenes->item(i);
  1707. auto cur_scene = GetOBSRef<OBSScene>(item);
  1708. if (cur_scene != scene)
  1709. continue;
  1710. sel = item;
  1711. break;
  1712. }
  1713. if (sel != nullptr) {
  1714. if (sel == ui->scenes->currentItem())
  1715. ClearListItems(ui->sources);
  1716. delete sel;
  1717. }
  1718. SaveProject();
  1719. if (!disableSaving) {
  1720. blog(LOG_INFO, "User Removed scene '%s'",
  1721. obs_source_get_name(source));
  1722. OBSProjector::UpdateMultiviewProjectors();
  1723. }
  1724. if (api)
  1725. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  1726. }
  1727. void OBSBasic::AddSceneItem(OBSSceneItem item)
  1728. {
  1729. obs_scene_t *scene = obs_sceneitem_get_scene(item);
  1730. if (GetCurrentScene() == scene)
  1731. InsertSceneItem(item);
  1732. SaveProject();
  1733. if (!disableSaving) {
  1734. obs_source_t *sceneSource = obs_scene_get_source(scene);
  1735. obs_source_t *itemSource = obs_sceneitem_get_source(item);
  1736. blog(LOG_INFO, "User added source '%s' (%s) to scene '%s'",
  1737. obs_source_get_name(itemSource),
  1738. obs_source_get_id(itemSource),
  1739. obs_source_get_name(sceneSource));
  1740. }
  1741. }
  1742. void OBSBasic::RemoveSceneItem(OBSSceneItem item)
  1743. {
  1744. for (int i = 0; i < ui->sources->count(); i++) {
  1745. QListWidgetItem *listItem = ui->sources->item(i);
  1746. if (GetOBSRef<OBSSceneItem>(listItem) == item) {
  1747. DeleteListItem(ui->sources, listItem);
  1748. break;
  1749. }
  1750. }
  1751. SaveProject();
  1752. if (!disableSaving) {
  1753. obs_scene_t *scene = obs_sceneitem_get_scene(item);
  1754. obs_source_t *sceneSource = obs_scene_get_source(scene);
  1755. obs_source_t *itemSource = obs_sceneitem_get_source(item);
  1756. blog(LOG_INFO, "User Removed source '%s' (%s) from scene '%s'",
  1757. obs_source_get_name(itemSource),
  1758. obs_source_get_id(itemSource),
  1759. obs_source_get_name(sceneSource));
  1760. }
  1761. }
  1762. void OBSBasic::UpdateSceneSelection(OBSSource source)
  1763. {
  1764. if (source) {
  1765. obs_scene_t *scene = obs_scene_from_source(source);
  1766. const char *name = obs_source_get_name(source);
  1767. if (!scene)
  1768. return;
  1769. QList<QListWidgetItem*> items =
  1770. ui->scenes->findItems(QT_UTF8(name), Qt::MatchExactly);
  1771. if (items.count()) {
  1772. sceneChanging = true;
  1773. ui->scenes->setCurrentItem(items.first());
  1774. sceneChanging = false;
  1775. UpdateSources(scene);
  1776. }
  1777. }
  1778. }
  1779. static void RenameListValues(QListWidget *listWidget, const QString &newName,
  1780. const QString &prevName)
  1781. {
  1782. QList<QListWidgetItem*> items =
  1783. listWidget->findItems(prevName, Qt::MatchExactly);
  1784. for (int i = 0; i < items.count(); i++)
  1785. items[i]->setText(newName);
  1786. }
  1787. void OBSBasic::RenameSources(OBSSource source, QString newName,
  1788. QString prevName)
  1789. {
  1790. RenameListValues(ui->scenes, newName, prevName);
  1791. for (size_t i = 0; i < volumes.size(); i++) {
  1792. if (volumes[i]->GetName().compare(prevName) == 0)
  1793. volumes[i]->SetName(newName);
  1794. }
  1795. OBSProjector::RenameProjector(prevName, newName);
  1796. SaveProject();
  1797. obs_scene_t *scene = obs_scene_from_source(source);
  1798. if (scene)
  1799. OBSProjector::UpdateMultiviewProjectors();
  1800. }
  1801. void OBSBasic::SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select)
  1802. {
  1803. SignalBlocker sourcesSignalBlocker(ui->sources);
  1804. if (scene != GetCurrentScene() || ignoreSelectionUpdate)
  1805. return;
  1806. for (int i = 0; i < ui->sources->count(); i++) {
  1807. QListWidgetItem *witem = ui->sources->item(i);
  1808. QVariant data =
  1809. witem->data(static_cast<int>(QtDataRole::OBSRef));
  1810. if (!data.canConvert<OBSSceneItem>())
  1811. continue;
  1812. if (item != data.value<OBSSceneItem>())
  1813. continue;
  1814. witem->setSelected(select);
  1815. break;
  1816. }
  1817. }
  1818. static inline bool SourceMixerHidden(obs_source_t *source)
  1819. {
  1820. obs_data_t *priv_settings = obs_source_get_private_settings(source);
  1821. bool hidden = obs_data_get_bool(priv_settings, "mixer_hidden");
  1822. obs_data_release(priv_settings);
  1823. return hidden;
  1824. }
  1825. static inline void SetSourceMixerHidden(obs_source_t *source, bool hidden)
  1826. {
  1827. obs_data_t *priv_settings = obs_source_get_private_settings(source);
  1828. obs_data_set_bool(priv_settings, "mixer_hidden", hidden);
  1829. obs_data_release(priv_settings);
  1830. }
  1831. void OBSBasic::GetAudioSourceFilters()
  1832. {
  1833. QAction *action = reinterpret_cast<QAction*>(sender());
  1834. VolControl *vol = action->property("volControl").value<VolControl*>();
  1835. obs_source_t *source = vol->GetSource();
  1836. CreateFiltersWindow(source);
  1837. }
  1838. void OBSBasic::GetAudioSourceProperties()
  1839. {
  1840. QAction *action = reinterpret_cast<QAction*>(sender());
  1841. VolControl *vol = action->property("volControl").value<VolControl*>();
  1842. obs_source_t *source = vol->GetSource();
  1843. CreatePropertiesWindow(source);
  1844. }
  1845. void OBSBasic::HideAudioControl()
  1846. {
  1847. QAction *action = reinterpret_cast<QAction*>(sender());
  1848. VolControl *vol = action->property("volControl").value<VolControl*>();
  1849. obs_source_t *source = vol->GetSource();
  1850. if (!SourceMixerHidden(source)) {
  1851. SetSourceMixerHidden(source, true);
  1852. DeactivateAudioSource(source);
  1853. }
  1854. }
  1855. void OBSBasic::UnhideAllAudioControls()
  1856. {
  1857. auto UnhideAudioMixer = [this] (obs_source_t *source) /* -- */
  1858. {
  1859. if (!obs_source_active(source))
  1860. return true;
  1861. if (!SourceMixerHidden(source))
  1862. return true;
  1863. SetSourceMixerHidden(source, false);
  1864. ActivateAudioSource(source);
  1865. return true;
  1866. };
  1867. using UnhideAudioMixer_t = decltype(UnhideAudioMixer);
  1868. auto PreEnum = [] (void *data, obs_source_t *source) -> bool /* -- */
  1869. {
  1870. return (*reinterpret_cast<UnhideAudioMixer_t *>(data))(source);
  1871. };
  1872. obs_enum_sources(PreEnum, &UnhideAudioMixer);
  1873. }
  1874. void OBSBasic::ToggleHideMixer()
  1875. {
  1876. OBSSceneItem item = GetCurrentSceneItem();
  1877. OBSSource source = obs_sceneitem_get_source(item);
  1878. if (!SourceMixerHidden(source)) {
  1879. SetSourceMixerHidden(source, true);
  1880. DeactivateAudioSource(source);
  1881. } else {
  1882. SetSourceMixerHidden(source, false);
  1883. ActivateAudioSource(source);
  1884. }
  1885. }
  1886. void OBSBasic::MixerRenameSource()
  1887. {
  1888. QAction *action = reinterpret_cast<QAction*>(sender());
  1889. VolControl *vol = action->property("volControl").value<VolControl*>();
  1890. OBSSource source = vol->GetSource();
  1891. const char *prevName = obs_source_get_name(source);
  1892. for (;;) {
  1893. string name;
  1894. bool accepted = NameDialog::AskForName(this,
  1895. QTStr("Basic.Main.MixerRename.Title"),
  1896. QTStr("Basic.Main.MixerRename.Text"),
  1897. name,
  1898. QT_UTF8(prevName));
  1899. if (!accepted)
  1900. return;
  1901. if (name.empty()) {
  1902. OBSMessageBox::information(this,
  1903. QTStr("NoNameEntered.Title"),
  1904. QTStr("NoNameEntered.Text"));
  1905. continue;
  1906. }
  1907. OBSSource sourceTest = obs_get_source_by_name(name.c_str());
  1908. obs_source_release(sourceTest);
  1909. if (sourceTest) {
  1910. OBSMessageBox::information(this,
  1911. QTStr("NameExists.Title"),
  1912. QTStr("NameExists.Text"));
  1913. continue;
  1914. }
  1915. obs_source_set_name(source, name.c_str());
  1916. break;
  1917. }
  1918. }
  1919. void OBSBasic::VolControlContextMenu()
  1920. {
  1921. VolControl *vol = reinterpret_cast<VolControl*>(sender());
  1922. /* ------------------- */
  1923. QAction hideAction(QTStr("Hide"), this);
  1924. QAction unhideAllAction(QTStr("UnhideAll"), this);
  1925. QAction mixerRenameAction(QTStr("Rename"), this);
  1926. QAction filtersAction(QTStr("Filters"), this);
  1927. QAction propertiesAction(QTStr("Properties"), this);
  1928. QAction advPropAction(QTStr("Basic.MainMenu.Edit.AdvAudio"), this);
  1929. /* ------------------- */
  1930. connect(&hideAction, &QAction::triggered,
  1931. this, &OBSBasic::HideAudioControl,
  1932. Qt::DirectConnection);
  1933. connect(&unhideAllAction, &QAction::triggered,
  1934. this, &OBSBasic::UnhideAllAudioControls,
  1935. Qt::DirectConnection);
  1936. connect(&mixerRenameAction, &QAction::triggered,
  1937. this, &OBSBasic::MixerRenameSource,
  1938. Qt::DirectConnection);
  1939. connect(&filtersAction, &QAction::triggered,
  1940. this, &OBSBasic::GetAudioSourceFilters,
  1941. Qt::DirectConnection);
  1942. connect(&propertiesAction, &QAction::triggered,
  1943. this, &OBSBasic::GetAudioSourceProperties,
  1944. Qt::DirectConnection);
  1945. connect(&advPropAction, &QAction::triggered,
  1946. this, &OBSBasic::on_actionAdvAudioProperties_triggered,
  1947. Qt::DirectConnection);
  1948. /* ------------------- */
  1949. hideAction.setProperty("volControl",
  1950. QVariant::fromValue<VolControl*>(vol));
  1951. mixerRenameAction.setProperty("volControl",
  1952. QVariant::fromValue<VolControl*>(vol));
  1953. filtersAction.setProperty("volControl",
  1954. QVariant::fromValue<VolControl*>(vol));
  1955. propertiesAction.setProperty("volControl",
  1956. QVariant::fromValue<VolControl*>(vol));
  1957. /* ------------------- */
  1958. QMenu popup(this);
  1959. popup.addAction(&unhideAllAction);
  1960. popup.addAction(&hideAction);
  1961. popup.addAction(&mixerRenameAction);
  1962. popup.addSeparator();
  1963. popup.addAction(&filtersAction);
  1964. popup.addAction(&propertiesAction);
  1965. popup.addAction(&advPropAction);
  1966. popup.exec(QCursor::pos());
  1967. }
  1968. void OBSBasic::on_mixerScrollArea_customContextMenuRequested()
  1969. {
  1970. QAction unhideAllAction(QTStr("UnhideAll"), this);
  1971. QAction advPropAction(QTStr("Basic.MainMenu.Edit.AdvAudio"), this);
  1972. /* ------------------- */
  1973. connect(&unhideAllAction, &QAction::triggered,
  1974. this, &OBSBasic::UnhideAllAudioControls,
  1975. Qt::DirectConnection);
  1976. connect(&advPropAction, &QAction::triggered,
  1977. this, &OBSBasic::on_actionAdvAudioProperties_triggered,
  1978. Qt::DirectConnection);
  1979. /* ------------------- */
  1980. QMenu popup(this);
  1981. popup.addAction(&unhideAllAction);
  1982. popup.addSeparator();
  1983. popup.addAction(&advPropAction);
  1984. popup.exec(QCursor::pos());
  1985. }
  1986. void OBSBasic::ActivateAudioSource(OBSSource source)
  1987. {
  1988. if (SourceMixerHidden(source))
  1989. return;
  1990. VolControl *vol = new VolControl(source, true);
  1991. double meterDecayRate = config_get_double(basicConfig, "Audio",
  1992. "MeterDecayRate");
  1993. vol->SetMeterDecayRate(meterDecayRate);
  1994. vol->setContextMenuPolicy(Qt::CustomContextMenu);
  1995. connect(vol, &QWidget::customContextMenuRequested,
  1996. this, &OBSBasic::VolControlContextMenu);
  1997. connect(vol, &VolControl::ConfigClicked,
  1998. this, &OBSBasic::VolControlContextMenu);
  1999. volumes.push_back(vol);
  2000. ui->volumeWidgets->layout()->addWidget(vol);
  2001. }
  2002. void OBSBasic::DeactivateAudioSource(OBSSource source)
  2003. {
  2004. for (size_t i = 0; i < volumes.size(); i++) {
  2005. if (volumes[i]->GetSource() == source) {
  2006. delete volumes[i];
  2007. volumes.erase(volumes.begin() + i);
  2008. break;
  2009. }
  2010. }
  2011. }
  2012. bool OBSBasic::QueryRemoveSource(obs_source_t *source)
  2013. {
  2014. if (obs_source_get_type(source) == OBS_SOURCE_TYPE_SCENE) {
  2015. int count = ui->scenes->count();
  2016. if (count == 1) {
  2017. OBSMessageBox::information(this,
  2018. QTStr("FinalScene.Title"),
  2019. QTStr("FinalScene.Text"));
  2020. return false;
  2021. }
  2022. }
  2023. const char *name = obs_source_get_name(source);
  2024. QString text = QTStr("ConfirmRemove.Text");
  2025. text.replace("$1", QT_UTF8(name));
  2026. QMessageBox remove_source(this);
  2027. remove_source.setText(text);
  2028. QAbstractButton *Yes = remove_source.addButton(QTStr("Yes"),
  2029. QMessageBox::YesRole);
  2030. remove_source.addButton(QTStr("No"), QMessageBox::NoRole);
  2031. remove_source.setIcon(QMessageBox::Question);
  2032. remove_source.setWindowTitle(QTStr("ConfirmRemove.Title"));
  2033. remove_source.exec();
  2034. return Yes == remove_source.clickedButton();
  2035. }
  2036. #define UPDATE_CHECK_INTERVAL (60*60*24*4) /* 4 days */
  2037. #ifdef UPDATE_SPARKLE
  2038. void init_sparkle_updater(bool update_to_undeployed);
  2039. void trigger_sparkle_update();
  2040. #endif
  2041. void OBSBasic::TimedCheckForUpdates()
  2042. {
  2043. if (!config_get_bool(App()->GlobalConfig(), "General",
  2044. "EnableAutoUpdates"))
  2045. return;
  2046. #ifdef UPDATE_SPARKLE
  2047. init_sparkle_updater(config_get_bool(App()->GlobalConfig(), "General",
  2048. "UpdateToUndeployed"));
  2049. #elif ENABLE_WIN_UPDATER
  2050. long long lastUpdate = config_get_int(App()->GlobalConfig(), "General",
  2051. "LastUpdateCheck");
  2052. uint32_t lastVersion = config_get_int(App()->GlobalConfig(), "General",
  2053. "LastVersion");
  2054. if (lastVersion < LIBOBS_API_VER) {
  2055. lastUpdate = 0;
  2056. config_set_int(App()->GlobalConfig(), "General",
  2057. "LastUpdateCheck", 0);
  2058. }
  2059. long long t = (long long)time(nullptr);
  2060. long long secs = t - lastUpdate;
  2061. if (secs > UPDATE_CHECK_INTERVAL)
  2062. CheckForUpdates(false);
  2063. #endif
  2064. }
  2065. void OBSBasic::CheckForUpdates(bool manualUpdate)
  2066. {
  2067. #ifdef UPDATE_SPARKLE
  2068. trigger_sparkle_update();
  2069. #elif ENABLE_WIN_UPDATER
  2070. ui->actionCheckForUpdates->setEnabled(false);
  2071. if (updateCheckThread && updateCheckThread->isRunning())
  2072. return;
  2073. updateCheckThread = new AutoUpdateThread(manualUpdate);
  2074. updateCheckThread->start();
  2075. #endif
  2076. UNUSED_PARAMETER(manualUpdate);
  2077. }
  2078. void OBSBasic::updateCheckFinished()
  2079. {
  2080. ui->actionCheckForUpdates->setEnabled(true);
  2081. }
  2082. void OBSBasic::DuplicateSelectedScene()
  2083. {
  2084. OBSScene curScene = GetCurrentScene();
  2085. if (!curScene)
  2086. return;
  2087. OBSSource curSceneSource = obs_scene_get_source(curScene);
  2088. QString format{obs_source_get_name(curSceneSource)};
  2089. format += " %1";
  2090. int i = 2;
  2091. QString placeHolderText = format.arg(i);
  2092. obs_source_t *source = nullptr;
  2093. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  2094. obs_source_release(source);
  2095. placeHolderText = format.arg(++i);
  2096. }
  2097. for (;;) {
  2098. string name;
  2099. bool accepted = NameDialog::AskForName(this,
  2100. QTStr("Basic.Main.AddSceneDlg.Title"),
  2101. QTStr("Basic.Main.AddSceneDlg.Text"),
  2102. name,
  2103. placeHolderText);
  2104. if (!accepted)
  2105. return;
  2106. if (name.empty()) {
  2107. OBSMessageBox::information(this,
  2108. QTStr("NoNameEntered.Title"),
  2109. QTStr("NoNameEntered.Text"));
  2110. continue;
  2111. }
  2112. obs_source_t *source = obs_get_source_by_name(name.c_str());
  2113. if (source) {
  2114. OBSMessageBox::information(this,
  2115. QTStr("NameExists.Title"),
  2116. QTStr("NameExists.Text"));
  2117. obs_source_release(source);
  2118. continue;
  2119. }
  2120. obs_scene_t *scene = obs_scene_duplicate(curScene,
  2121. name.c_str(), OBS_SCENE_DUP_REFS);
  2122. source = obs_scene_get_source(scene);
  2123. AddScene(source);
  2124. SetCurrentScene(source, true);
  2125. obs_scene_release(scene);
  2126. break;
  2127. }
  2128. }
  2129. void OBSBasic::RemoveSelectedScene()
  2130. {
  2131. OBSScene scene = GetCurrentScene();
  2132. if (scene) {
  2133. obs_source_t *source = obs_scene_get_source(scene);
  2134. if (QueryRemoveSource(source)) {
  2135. obs_source_remove(source);
  2136. if (api)
  2137. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  2138. }
  2139. }
  2140. }
  2141. void OBSBasic::RemoveSelectedSceneItem()
  2142. {
  2143. OBSSceneItem item = GetCurrentSceneItem();
  2144. if (item) {
  2145. obs_source_t *source = obs_sceneitem_get_source(item);
  2146. if (QueryRemoveSource(source))
  2147. obs_sceneitem_remove(item);
  2148. }
  2149. }
  2150. struct ReorderInfo {
  2151. int idx = 0;
  2152. OBSBasic *window;
  2153. inline ReorderInfo(OBSBasic *window_) : window(window_) {}
  2154. };
  2155. void OBSBasic::ReorderSceneItem(obs_sceneitem_t *item, size_t idx)
  2156. {
  2157. int count = ui->sources->count();
  2158. int idx_inv = count - (int)idx - 1;
  2159. for (int i = 0; i < count; i++) {
  2160. QListWidgetItem *listItem = ui->sources->item(i);
  2161. OBSSceneItem sceneItem = GetOBSRef<OBSSceneItem>(listItem);
  2162. if (sceneItem == item) {
  2163. if ((int)idx_inv != i) {
  2164. bool sel = (ui->sources->currentRow() == i);
  2165. listItem = TakeListItem(ui->sources, i);
  2166. if (listItem) {
  2167. ui->sources->insertItem(idx_inv,
  2168. listItem);
  2169. SetupVisibilityItem(ui->sources,
  2170. listItem, item);
  2171. if (sel)
  2172. ui->sources->setCurrentRow(
  2173. idx_inv);
  2174. }
  2175. }
  2176. break;
  2177. }
  2178. }
  2179. }
  2180. void OBSBasic::ReorderSources(OBSScene scene)
  2181. {
  2182. ReorderInfo info(this);
  2183. if (scene != GetCurrentScene() || ui->sources->IgnoreReorder())
  2184. return;
  2185. obs_scene_enum_items(scene,
  2186. [] (obs_scene_t*, obs_sceneitem_t *item, void *p)
  2187. {
  2188. ReorderInfo *info =
  2189. reinterpret_cast<ReorderInfo*>(p);
  2190. info->window->ReorderSceneItem(item,
  2191. info->idx++);
  2192. return true;
  2193. }, &info);
  2194. SaveProject();
  2195. }
  2196. /* OBS Callbacks */
  2197. void OBSBasic::SceneReordered(void *data, calldata_t *params)
  2198. {
  2199. OBSBasic *window = static_cast<OBSBasic*>(data);
  2200. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  2201. QMetaObject::invokeMethod(window, "ReorderSources",
  2202. Q_ARG(OBSScene, OBSScene(scene)));
  2203. }
  2204. void OBSBasic::SceneItemAdded(void *data, calldata_t *params)
  2205. {
  2206. OBSBasic *window = static_cast<OBSBasic*>(data);
  2207. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2208. QMetaObject::invokeMethod(window, "AddSceneItem",
  2209. Q_ARG(OBSSceneItem, OBSSceneItem(item)));
  2210. }
  2211. void OBSBasic::SceneItemRemoved(void *data, calldata_t *params)
  2212. {
  2213. OBSBasic *window = static_cast<OBSBasic*>(data);
  2214. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2215. QMetaObject::invokeMethod(window, "RemoveSceneItem",
  2216. Q_ARG(OBSSceneItem, OBSSceneItem(item)));
  2217. }
  2218. void OBSBasic::SceneItemSelected(void *data, calldata_t *params)
  2219. {
  2220. OBSBasic *window = static_cast<OBSBasic*>(data);
  2221. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  2222. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2223. QMetaObject::invokeMethod(window, "SelectSceneItem",
  2224. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  2225. Q_ARG(bool, true));
  2226. }
  2227. void OBSBasic::SceneItemDeselected(void *data, calldata_t *params)
  2228. {
  2229. OBSBasic *window = static_cast<OBSBasic*>(data);
  2230. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  2231. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  2232. QMetaObject::invokeMethod(window, "SelectSceneItem",
  2233. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  2234. Q_ARG(bool, false));
  2235. }
  2236. void OBSBasic::SourceLoaded(void *data, obs_source_t *source)
  2237. {
  2238. OBSBasic *window = static_cast<OBSBasic*>(data);
  2239. if (obs_scene_from_source(source) != NULL)
  2240. QMetaObject::invokeMethod(window,
  2241. "AddScene",
  2242. Q_ARG(OBSSource, OBSSource(source)));
  2243. }
  2244. void OBSBasic::SourceRemoved(void *data, calldata_t *params)
  2245. {
  2246. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2247. if (obs_scene_from_source(source) != NULL)
  2248. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2249. "RemoveScene",
  2250. Q_ARG(OBSSource, OBSSource(source)));
  2251. }
  2252. void OBSBasic::SourceActivated(void *data, calldata_t *params)
  2253. {
  2254. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2255. uint32_t flags = obs_source_get_output_flags(source);
  2256. if (flags & OBS_SOURCE_AUDIO)
  2257. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2258. "ActivateAudioSource",
  2259. Q_ARG(OBSSource, OBSSource(source)));
  2260. }
  2261. void OBSBasic::SourceDeactivated(void *data, calldata_t *params)
  2262. {
  2263. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2264. uint32_t flags = obs_source_get_output_flags(source);
  2265. if (flags & OBS_SOURCE_AUDIO)
  2266. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2267. "DeactivateAudioSource",
  2268. Q_ARG(OBSSource, OBSSource(source)));
  2269. }
  2270. void OBSBasic::SourceRenamed(void *data, calldata_t *params)
  2271. {
  2272. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  2273. const char *newName = calldata_string(params, "new_name");
  2274. const char *prevName = calldata_string(params, "prev_name");
  2275. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  2276. "RenameSources",
  2277. Q_ARG(OBSSource, source),
  2278. Q_ARG(QString, QT_UTF8(newName)),
  2279. Q_ARG(QString, QT_UTF8(prevName)));
  2280. blog(LOG_INFO, "Source '%s' renamed to '%s'", prevName, newName);
  2281. }
  2282. void OBSBasic::DrawBackdrop(float cx, float cy)
  2283. {
  2284. if (!box)
  2285. return;
  2286. gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID);
  2287. gs_eparam_t *color = gs_effect_get_param_by_name(solid, "color");
  2288. gs_technique_t *tech = gs_effect_get_technique(solid, "Solid");
  2289. vec4 colorVal;
  2290. vec4_set(&colorVal, 0.0f, 0.0f, 0.0f, 1.0f);
  2291. gs_effect_set_vec4(color, &colorVal);
  2292. gs_technique_begin(tech);
  2293. gs_technique_begin_pass(tech, 0);
  2294. gs_matrix_push();
  2295. gs_matrix_identity();
  2296. gs_matrix_scale3f(float(cx), float(cy), 1.0f);
  2297. gs_load_vertexbuffer(box);
  2298. gs_draw(GS_TRISTRIP, 0, 0);
  2299. gs_matrix_pop();
  2300. gs_technique_end_pass(tech);
  2301. gs_technique_end(tech);
  2302. gs_load_vertexbuffer(nullptr);
  2303. }
  2304. void OBSBasic::RenderMain(void *data, uint32_t cx, uint32_t cy)
  2305. {
  2306. OBSBasic *window = static_cast<OBSBasic*>(data);
  2307. obs_video_info ovi;
  2308. obs_get_video_info(&ovi);
  2309. window->previewCX = int(window->previewScale * float(ovi.base_width));
  2310. window->previewCY = int(window->previewScale * float(ovi.base_height));
  2311. gs_viewport_push();
  2312. gs_projection_push();
  2313. /* --------------------------------------- */
  2314. gs_ortho(0.0f, float(ovi.base_width), 0.0f, float(ovi.base_height),
  2315. -100.0f, 100.0f);
  2316. gs_set_viewport(window->previewX, window->previewY,
  2317. window->previewCX, window->previewCY);
  2318. window->DrawBackdrop(float(ovi.base_width), float(ovi.base_height));
  2319. if (window->IsPreviewProgramMode()) {
  2320. OBSScene scene = window->GetCurrentScene();
  2321. obs_source_t *source = obs_scene_get_source(scene);
  2322. if (source)
  2323. obs_source_video_render(source);
  2324. } else {
  2325. obs_render_main_texture();
  2326. }
  2327. gs_load_vertexbuffer(nullptr);
  2328. /* --------------------------------------- */
  2329. QSize previewSize = GetPixelSize(window->ui->preview);
  2330. float right = float(previewSize.width()) - window->previewX;
  2331. float bottom = float(previewSize.height()) - window->previewY;
  2332. gs_ortho(-window->previewX, right,
  2333. -window->previewY, bottom,
  2334. -100.0f, 100.0f);
  2335. gs_reset_viewport();
  2336. window->ui->preview->DrawSceneEditing();
  2337. /* --------------------------------------- */
  2338. gs_projection_pop();
  2339. gs_viewport_pop();
  2340. UNUSED_PARAMETER(cx);
  2341. UNUSED_PARAMETER(cy);
  2342. }
  2343. /* Main class functions */
  2344. obs_service_t *OBSBasic::GetService()
  2345. {
  2346. if (!service) {
  2347. service = obs_service_create("rtmp_common", NULL, NULL,
  2348. nullptr);
  2349. obs_service_release(service);
  2350. }
  2351. return service;
  2352. }
  2353. void OBSBasic::SetService(obs_service_t *newService)
  2354. {
  2355. if (newService)
  2356. service = newService;
  2357. }
  2358. bool OBSBasic::StreamingActive() const
  2359. {
  2360. if (!outputHandler)
  2361. return false;
  2362. return outputHandler->StreamingActive();
  2363. }
  2364. bool OBSBasic::Active() const
  2365. {
  2366. if (!outputHandler)
  2367. return false;
  2368. return outputHandler->Active();
  2369. }
  2370. #ifdef _WIN32
  2371. #define IS_WIN32 1
  2372. #else
  2373. #define IS_WIN32 0
  2374. #endif
  2375. static inline int AttemptToResetVideo(struct obs_video_info *ovi)
  2376. {
  2377. return obs_reset_video(ovi);
  2378. }
  2379. static inline enum obs_scale_type GetScaleType(ConfigFile &basicConfig)
  2380. {
  2381. const char *scaleTypeStr = config_get_string(basicConfig,
  2382. "Video", "ScaleType");
  2383. if (astrcmpi(scaleTypeStr, "bilinear") == 0)
  2384. return OBS_SCALE_BILINEAR;
  2385. else if (astrcmpi(scaleTypeStr, "lanczos") == 0)
  2386. return OBS_SCALE_LANCZOS;
  2387. else
  2388. return OBS_SCALE_BICUBIC;
  2389. }
  2390. static inline enum video_format GetVideoFormatFromName(const char *name)
  2391. {
  2392. if (astrcmpi(name, "I420") == 0)
  2393. return VIDEO_FORMAT_I420;
  2394. else if (astrcmpi(name, "NV12") == 0)
  2395. return VIDEO_FORMAT_NV12;
  2396. else if (astrcmpi(name, "I444") == 0)
  2397. return VIDEO_FORMAT_I444;
  2398. #if 0 //currently unsupported
  2399. else if (astrcmpi(name, "YVYU") == 0)
  2400. return VIDEO_FORMAT_YVYU;
  2401. else if (astrcmpi(name, "YUY2") == 0)
  2402. return VIDEO_FORMAT_YUY2;
  2403. else if (astrcmpi(name, "UYVY") == 0)
  2404. return VIDEO_FORMAT_UYVY;
  2405. #endif
  2406. else
  2407. return VIDEO_FORMAT_RGBA;
  2408. }
  2409. void OBSBasic::ResetUI()
  2410. {
  2411. bool studioPortraitLayout = config_get_bool(GetGlobalConfig(),
  2412. "BasicWindow", "StudioPortraitLayout");
  2413. if (studioPortraitLayout)
  2414. ui->previewLayout->setDirection(QBoxLayout::TopToBottom);
  2415. else
  2416. ui->previewLayout->setDirection(QBoxLayout::LeftToRight);
  2417. }
  2418. int OBSBasic::ResetVideo()
  2419. {
  2420. if (outputHandler && outputHandler->Active())
  2421. return OBS_VIDEO_CURRENTLY_ACTIVE;
  2422. ProfileScope("OBSBasic::ResetVideo");
  2423. struct obs_video_info ovi;
  2424. int ret;
  2425. GetConfigFPS(ovi.fps_num, ovi.fps_den);
  2426. const char *colorFormat = config_get_string(basicConfig, "Video",
  2427. "ColorFormat");
  2428. const char *colorSpace = config_get_string(basicConfig, "Video",
  2429. "ColorSpace");
  2430. const char *colorRange = config_get_string(basicConfig, "Video",
  2431. "ColorRange");
  2432. ovi.graphics_module = App()->GetRenderModule();
  2433. ovi.base_width = (uint32_t)config_get_uint(basicConfig,
  2434. "Video", "BaseCX");
  2435. ovi.base_height = (uint32_t)config_get_uint(basicConfig,
  2436. "Video", "BaseCY");
  2437. ovi.output_width = (uint32_t)config_get_uint(basicConfig,
  2438. "Video", "OutputCX");
  2439. ovi.output_height = (uint32_t)config_get_uint(basicConfig,
  2440. "Video", "OutputCY");
  2441. ovi.output_format = GetVideoFormatFromName(colorFormat);
  2442. ovi.colorspace = astrcmpi(colorSpace, "601") == 0 ?
  2443. VIDEO_CS_601 : VIDEO_CS_709;
  2444. ovi.range = astrcmpi(colorRange, "Full") == 0 ?
  2445. VIDEO_RANGE_FULL : VIDEO_RANGE_PARTIAL;
  2446. ovi.adapter = config_get_uint(App()->GlobalConfig(),
  2447. "Video", "AdapterIdx");
  2448. ovi.gpu_conversion = true;
  2449. ovi.scale_type = GetScaleType(basicConfig);
  2450. if (ovi.base_width == 0 || ovi.base_height == 0) {
  2451. ovi.base_width = 1920;
  2452. ovi.base_height = 1080;
  2453. config_set_uint(basicConfig, "Video", "BaseCX", 1920);
  2454. config_set_uint(basicConfig, "Video", "BaseCY", 1080);
  2455. }
  2456. if (ovi.output_width == 0 || ovi.output_height == 0) {
  2457. ovi.output_width = ovi.base_width;
  2458. ovi.output_height = ovi.base_height;
  2459. config_set_uint(basicConfig, "Video", "OutputCX",
  2460. ovi.base_width);
  2461. config_set_uint(basicConfig, "Video", "OutputCY",
  2462. ovi.base_height);
  2463. }
  2464. ret = AttemptToResetVideo(&ovi);
  2465. if (IS_WIN32 && ret != OBS_VIDEO_SUCCESS) {
  2466. if (ret == OBS_VIDEO_CURRENTLY_ACTIVE) {
  2467. blog(LOG_WARNING, "Tried to reset when "
  2468. "already active");
  2469. return ret;
  2470. }
  2471. /* Try OpenGL if DirectX fails on windows */
  2472. if (astrcmpi(ovi.graphics_module, DL_OPENGL) != 0) {
  2473. blog(LOG_WARNING, "Failed to initialize obs video (%d) "
  2474. "with graphics_module='%s', retrying "
  2475. "with graphics_module='%s'",
  2476. ret, ovi.graphics_module,
  2477. DL_OPENGL);
  2478. ovi.graphics_module = DL_OPENGL;
  2479. ret = AttemptToResetVideo(&ovi);
  2480. }
  2481. } else if (ret == OBS_VIDEO_SUCCESS) {
  2482. ResizePreview(ovi.base_width, ovi.base_height);
  2483. if (program)
  2484. ResizeProgram(ovi.base_width, ovi.base_height);
  2485. }
  2486. if (ret == OBS_VIDEO_SUCCESS)
  2487. OBSBasicStats::InitializeValues();
  2488. return ret;
  2489. }
  2490. bool OBSBasic::ResetAudio()
  2491. {
  2492. ProfileScope("OBSBasic::ResetAudio");
  2493. struct obs_audio_info ai;
  2494. ai.samples_per_sec = config_get_uint(basicConfig, "Audio",
  2495. "SampleRate");
  2496. const char *channelSetupStr = config_get_string(basicConfig,
  2497. "Audio", "ChannelSetup");
  2498. if (strcmp(channelSetupStr, "Mono") == 0)
  2499. ai.speakers = SPEAKERS_MONO;
  2500. else if (strcmp(channelSetupStr, "2.1") == 0)
  2501. ai.speakers = SPEAKERS_2POINT1;
  2502. else if (strcmp(channelSetupStr, "4.0") == 0)
  2503. ai.speakers = SPEAKERS_4POINT0;
  2504. else if (strcmp(channelSetupStr, "4.1") == 0)
  2505. ai.speakers = SPEAKERS_4POINT1;
  2506. else if (strcmp(channelSetupStr, "5.1") == 0)
  2507. ai.speakers = SPEAKERS_5POINT1;
  2508. else if (strcmp(channelSetupStr, "7.1") == 0)
  2509. ai.speakers = SPEAKERS_7POINT1;
  2510. else
  2511. ai.speakers = SPEAKERS_STEREO;
  2512. return obs_reset_audio(&ai);
  2513. }
  2514. void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceId,
  2515. const char *deviceDesc, int channel)
  2516. {
  2517. bool disable = deviceId && strcmp(deviceId, "disabled") == 0;
  2518. obs_source_t *source;
  2519. obs_data_t *settings;
  2520. source = obs_get_output_source(channel);
  2521. if (source) {
  2522. if (disable) {
  2523. obs_set_output_source(channel, nullptr);
  2524. } else {
  2525. settings = obs_source_get_settings(source);
  2526. const char *oldId = obs_data_get_string(settings,
  2527. "device_id");
  2528. if (strcmp(oldId, deviceId) != 0) {
  2529. obs_data_set_string(settings, "device_id",
  2530. deviceId);
  2531. obs_source_update(source, settings);
  2532. }
  2533. obs_data_release(settings);
  2534. }
  2535. obs_source_release(source);
  2536. } else if (!disable) {
  2537. settings = obs_data_create();
  2538. obs_data_set_string(settings, "device_id", deviceId);
  2539. source = obs_source_create(sourceId, deviceDesc, settings,
  2540. nullptr);
  2541. obs_data_release(settings);
  2542. obs_set_output_source(channel, source);
  2543. obs_source_release(source);
  2544. }
  2545. }
  2546. void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
  2547. {
  2548. QSize targetSize;
  2549. bool isFixedScaling;
  2550. obs_video_info ovi;
  2551. /* resize preview panel to fix to the top section of the window */
  2552. targetSize = GetPixelSize(ui->preview);
  2553. isFixedScaling = ui->preview->IsFixedScaling();
  2554. obs_get_video_info(&ovi);
  2555. if (isFixedScaling) {
  2556. previewScale = ui->preview->GetScalingAmount();
  2557. GetCenterPosFromFixedScale(int(cx), int(cy),
  2558. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  2559. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  2560. previewX, previewY, previewScale);
  2561. previewX += ui->preview->GetScrollX();
  2562. previewY += ui->preview->GetScrollY();
  2563. } else {
  2564. GetScaleAndCenterPos(int(cx), int(cy),
  2565. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  2566. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  2567. previewX, previewY, previewScale);
  2568. }
  2569. previewX += float(PREVIEW_EDGE_SIZE);
  2570. previewY += float(PREVIEW_EDGE_SIZE);
  2571. }
  2572. void OBSBasic::CloseDialogs()
  2573. {
  2574. QList<QDialog*> childDialogs = this->findChildren<QDialog *>();
  2575. if (!childDialogs.isEmpty()) {
  2576. for (int i = 0; i < childDialogs.size(); ++i) {
  2577. childDialogs.at(i)->close();
  2578. }
  2579. }
  2580. for (QPointer<QWidget> &projector : windowProjectors) {
  2581. delete projector;
  2582. projector.clear();
  2583. }
  2584. for (QPointer<QWidget> &projector : projectors) {
  2585. delete projector;
  2586. projector.clear();
  2587. }
  2588. if (!stats.isNull()) stats->close(); //call close to save Stats geometry
  2589. }
  2590. void OBSBasic::EnumDialogs()
  2591. {
  2592. visDialogs.clear();
  2593. modalDialogs.clear();
  2594. visMsgBoxes.clear();
  2595. /* fill list of Visible dialogs and Modal dialogs */
  2596. QList<QDialog*> dialogs = findChildren<QDialog*>();
  2597. for (QDialog *dialog : dialogs) {
  2598. if (dialog->isVisible())
  2599. visDialogs.append(dialog);
  2600. if (dialog->isModal())
  2601. modalDialogs.append(dialog);
  2602. }
  2603. /* fill list of Visible message boxes */
  2604. QList<QMessageBox*> msgBoxes = findChildren<QMessageBox*>();
  2605. for (QMessageBox *msgbox : msgBoxes) {
  2606. if (msgbox->isVisible())
  2607. visMsgBoxes.append(msgbox);
  2608. }
  2609. }
  2610. void OBSBasic::ClearSceneData()
  2611. {
  2612. disableSaving++;
  2613. CloseDialogs();
  2614. ClearVolumeControls();
  2615. ClearListItems(ui->scenes);
  2616. ClearListItems(ui->sources);
  2617. ClearQuickTransitions();
  2618. ui->transitions->clear();
  2619. obs_set_output_source(0, nullptr);
  2620. obs_set_output_source(1, nullptr);
  2621. obs_set_output_source(2, nullptr);
  2622. obs_set_output_source(3, nullptr);
  2623. obs_set_output_source(4, nullptr);
  2624. obs_set_output_source(5, nullptr);
  2625. lastScene = nullptr;
  2626. swapScene = nullptr;
  2627. programScene = nullptr;
  2628. auto cb = [](void *unused, obs_source_t *source)
  2629. {
  2630. obs_source_remove(source);
  2631. UNUSED_PARAMETER(unused);
  2632. return true;
  2633. };
  2634. obs_enum_sources(cb, nullptr);
  2635. if (api)
  2636. api->on_event(OBS_FRONTEND_EVENT_SCENE_COLLECTION_CLEANUP);
  2637. disableSaving--;
  2638. blog(LOG_INFO, "All scene data cleared");
  2639. blog(LOG_INFO, "------------------------------------------------");
  2640. }
  2641. void OBSBasic::closeEvent(QCloseEvent *event)
  2642. {
  2643. if (isVisible())
  2644. config_set_string(App()->GlobalConfig(),
  2645. "BasicWindow", "geometry",
  2646. saveGeometry().toBase64().constData());
  2647. config_set_string(App()->GlobalConfig(),
  2648. "BasicWindow", "DockState",
  2649. saveState().toBase64().constData());
  2650. if (outputHandler && outputHandler->Active()) {
  2651. SetShowing(true);
  2652. QMessageBox::StandardButton button = OBSMessageBox::question(
  2653. this, QTStr("ConfirmExit.Title"),
  2654. QTStr("ConfirmExit.Text"));
  2655. if (button == QMessageBox::No) {
  2656. event->ignore();
  2657. return;
  2658. }
  2659. }
  2660. QWidget::closeEvent(event);
  2661. if (!event->isAccepted())
  2662. return;
  2663. blog(LOG_INFO, SHUTDOWN_SEPARATOR);
  2664. if (updateCheckThread)
  2665. updateCheckThread->wait();
  2666. if (logUploadThread)
  2667. logUploadThread->wait();
  2668. signalHandlers.clear();
  2669. SaveProjectNow();
  2670. if (api)
  2671. api->on_event(OBS_FRONTEND_EVENT_EXIT);
  2672. disableSaving++;
  2673. /* Clear all scene data (dialogs, widgets, widget sub-items, scenes,
  2674. * sources, etc) so that all references are released before shutdown */
  2675. ClearSceneData();
  2676. App()->quit();
  2677. }
  2678. void OBSBasic::changeEvent(QEvent *event)
  2679. {
  2680. if (event->type() == QEvent::WindowStateChange &&
  2681. isMinimized() &&
  2682. trayIcon &&
  2683. trayIcon->isVisible() &&
  2684. sysTrayMinimizeToTray()) {
  2685. ToggleShowHide();
  2686. }
  2687. }
  2688. void OBSBasic::on_actionShow_Recordings_triggered()
  2689. {
  2690. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  2691. const char *path = strcmp(mode, "Advanced") ?
  2692. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  2693. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  2694. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  2695. }
  2696. void OBSBasic::on_actionRemux_triggered()
  2697. {
  2698. const char *mode = config_get_string(basicConfig, "Output", "Mode");
  2699. const char *path = strcmp(mode, "Advanced") ?
  2700. config_get_string(basicConfig, "SimpleOutput", "FilePath") :
  2701. config_get_string(basicConfig, "AdvOut", "RecFilePath");
  2702. OBSRemux remux(path, this);
  2703. remux.exec();
  2704. }
  2705. void OBSBasic::on_action_Settings_triggered()
  2706. {
  2707. OBSBasicSettings settings(this);
  2708. settings.exec();
  2709. SystemTray(false);
  2710. }
  2711. void OBSBasic::on_actionAdvAudioProperties_triggered()
  2712. {
  2713. if (advAudioWindow != nullptr) {
  2714. advAudioWindow->raise();
  2715. return;
  2716. }
  2717. advAudioWindow = new OBSBasicAdvAudio(this);
  2718. advAudioWindow->show();
  2719. advAudioWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  2720. connect(advAudioWindow, SIGNAL(destroyed()),
  2721. this, SLOT(on_advAudioProps_destroyed()));
  2722. }
  2723. void OBSBasic::on_advAudioProps_clicked()
  2724. {
  2725. on_actionAdvAudioProperties_triggered();
  2726. }
  2727. void OBSBasic::on_advAudioProps_destroyed()
  2728. {
  2729. advAudioWindow = nullptr;
  2730. }
  2731. void OBSBasic::on_scenes_currentItemChanged(QListWidgetItem *current,
  2732. QListWidgetItem *prev)
  2733. {
  2734. obs_source_t *source = NULL;
  2735. if (sceneChanging)
  2736. return;
  2737. if (current) {
  2738. obs_scene_t *scene;
  2739. scene = GetOBSRef<OBSScene>(current);
  2740. source = obs_scene_get_source(scene);
  2741. }
  2742. SetCurrentScene(source);
  2743. UNUSED_PARAMETER(prev);
  2744. }
  2745. void OBSBasic::EditSceneName()
  2746. {
  2747. QListWidgetItem *item = ui->scenes->currentItem();
  2748. Qt::ItemFlags flags = item->flags();
  2749. item->setFlags(flags | Qt::ItemIsEditable);
  2750. ui->scenes->editItem(item);
  2751. item->setFlags(flags);
  2752. }
  2753. static void AddProjectorMenuMonitors(QMenu *parent, QObject *target,
  2754. const char *slot)
  2755. {
  2756. QAction *action;
  2757. QList<QScreen*> screens = QGuiApplication::screens();
  2758. for (int i = 0; i < screens.size(); i++) {
  2759. QRect screenGeometry = screens[i]->geometry();
  2760. QString str = QString("%1 %2: %3x%4 @ %5,%6").
  2761. arg(QTStr("Display"),
  2762. QString::number(i),
  2763. QString::number(screenGeometry.width()),
  2764. QString::number(screenGeometry.height()),
  2765. QString::number(screenGeometry.x()),
  2766. QString::number(screenGeometry.y()));
  2767. action = parent->addAction(str, target, slot);
  2768. action->setProperty("monitor", i);
  2769. }
  2770. }
  2771. void OBSBasic::on_scenes_customContextMenuRequested(const QPoint &pos)
  2772. {
  2773. QListWidgetItem *item = ui->scenes->itemAt(pos);
  2774. QPointer<QMenu> sceneProjectorMenu;
  2775. QMenu popup(this);
  2776. QMenu order(QTStr("Basic.MainMenu.Edit.Order"), this);
  2777. popup.addAction(QTStr("Add"),
  2778. this, SLOT(on_actionAddScene_triggered()));
  2779. if (item) {
  2780. popup.addSeparator();
  2781. popup.addAction(QTStr("Duplicate"),
  2782. this, SLOT(DuplicateSelectedScene()));
  2783. popup.addAction(QTStr("Rename"),
  2784. this, SLOT(EditSceneName()));
  2785. popup.addAction(QTStr("Remove"),
  2786. this, SLOT(RemoveSelectedScene()),
  2787. DeleteKeys.front());
  2788. popup.addSeparator();
  2789. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveUp"),
  2790. this, SLOT(on_actionSceneUp_triggered()));
  2791. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveDown"),
  2792. this, SLOT(on_actionSceneDown_triggered()));
  2793. order.addSeparator();
  2794. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToTop"),
  2795. this, SLOT(MoveSceneToTop()));
  2796. order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToBottom"),
  2797. this, SLOT(MoveSceneToBottom()));
  2798. popup.addMenu(&order);
  2799. popup.addSeparator();
  2800. sceneProjectorMenu = new QMenu(QTStr("SceneProjector"));
  2801. AddProjectorMenuMonitors(sceneProjectorMenu, this,
  2802. SLOT(OpenSceneProjector()));
  2803. popup.addMenu(sceneProjectorMenu);
  2804. QAction *sceneWindow = popup.addAction(
  2805. QTStr("SceneWindow"),
  2806. this, SLOT(OpenSceneWindow()));
  2807. popup.addAction(sceneWindow);
  2808. popup.addSeparator();
  2809. popup.addAction(QTStr("Filters"), this,
  2810. SLOT(OpenSceneFilters()));
  2811. popup.addSeparator();
  2812. QMenu *transitionMenu = CreatePerSceneTransitionMenu();
  2813. popup.addMenu(transitionMenu);
  2814. /* ---------------------- */
  2815. QAction *multiviewAction = popup.addAction(
  2816. QTStr("ShowInMultiview"));
  2817. OBSSource source = GetCurrentSceneSource();
  2818. OBSData data = obs_source_get_private_settings(source);
  2819. obs_data_release(data);
  2820. obs_data_set_default_bool(data, "show_in_multiview",
  2821. true);
  2822. bool show = obs_data_get_bool(data, "show_in_multiview");
  2823. multiviewAction->setCheckable(true);
  2824. multiviewAction->setChecked(show);
  2825. auto showInMultiview = [this] (OBSData data)
  2826. {
  2827. bool show = obs_data_get_bool(data,
  2828. "show_in_multiview");
  2829. obs_data_set_bool(data, "show_in_multiview",
  2830. !show);
  2831. OBSProjector::UpdateMultiviewProjectors();
  2832. };
  2833. connect(multiviewAction, &QAction::triggered,
  2834. std::bind(showInMultiview, data));
  2835. }
  2836. popup.exec(QCursor::pos());
  2837. }
  2838. void OBSBasic::on_actionAddScene_triggered()
  2839. {
  2840. string name;
  2841. QString format{QTStr("Basic.Main.DefaultSceneName.Text")};
  2842. int i = 2;
  2843. QString placeHolderText = format.arg(i);
  2844. obs_source_t *source = nullptr;
  2845. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  2846. obs_source_release(source);
  2847. placeHolderText = format.arg(++i);
  2848. }
  2849. bool accepted = NameDialog::AskForName(this,
  2850. QTStr("Basic.Main.AddSceneDlg.Title"),
  2851. QTStr("Basic.Main.AddSceneDlg.Text"),
  2852. name,
  2853. placeHolderText);
  2854. if (accepted) {
  2855. if (name.empty()) {
  2856. OBSMessageBox::information(this,
  2857. QTStr("NoNameEntered.Title"),
  2858. QTStr("NoNameEntered.Text"));
  2859. on_actionAddScene_triggered();
  2860. return;
  2861. }
  2862. obs_source_t *source = obs_get_source_by_name(name.c_str());
  2863. if (source) {
  2864. OBSMessageBox::information(this,
  2865. QTStr("NameExists.Title"),
  2866. QTStr("NameExists.Text"));
  2867. obs_source_release(source);
  2868. on_actionAddScene_triggered();
  2869. return;
  2870. }
  2871. obs_scene_t *scene = obs_scene_create(name.c_str());
  2872. source = obs_scene_get_source(scene);
  2873. AddScene(source);
  2874. SetCurrentScene(source);
  2875. obs_scene_release(scene);
  2876. }
  2877. }
  2878. void OBSBasic::on_actionRemoveScene_triggered()
  2879. {
  2880. OBSScene scene = GetCurrentScene();
  2881. obs_source_t *source = obs_scene_get_source(scene);
  2882. if (source && QueryRemoveSource(source))
  2883. obs_source_remove(source);
  2884. }
  2885. void OBSBasic::ChangeSceneIndex(bool relative, int offset, int invalidIdx)
  2886. {
  2887. int idx = ui->scenes->currentRow();
  2888. if (idx == -1 || idx == invalidIdx)
  2889. return;
  2890. sceneChanging = true;
  2891. QListWidgetItem *item = ui->scenes->takeItem(idx);
  2892. if (!relative)
  2893. idx = 0;
  2894. ui->scenes->insertItem(idx + offset, item);
  2895. ui->scenes->setCurrentRow(idx + offset);
  2896. item->setSelected(true);
  2897. sceneChanging = false;
  2898. }
  2899. void OBSBasic::on_actionSceneUp_triggered()
  2900. {
  2901. ChangeSceneIndex(true, -1, 0);
  2902. }
  2903. void OBSBasic::on_actionSceneDown_triggered()
  2904. {
  2905. ChangeSceneIndex(true, 1, ui->scenes->count() - 1);
  2906. }
  2907. void OBSBasic::MoveSceneToTop()
  2908. {
  2909. ChangeSceneIndex(false, 0, 0);
  2910. }
  2911. void OBSBasic::MoveSceneToBottom()
  2912. {
  2913. ChangeSceneIndex(false, ui->scenes->count() - 1,
  2914. ui->scenes->count() - 1);
  2915. }
  2916. void OBSBasic::on_sources_itemSelectionChanged()
  2917. {
  2918. SignalBlocker sourcesSignalBlocker(ui->sources);
  2919. auto updateItemSelection = [&]()
  2920. {
  2921. ignoreSelectionUpdate = true;
  2922. for (int i = 0; i < ui->sources->count(); i++)
  2923. {
  2924. QListWidgetItem *wItem = ui->sources->item(i);
  2925. OBSSceneItem item = GetOBSRef<OBSSceneItem>(wItem);
  2926. obs_sceneitem_select(item, wItem->isSelected());
  2927. }
  2928. ignoreSelectionUpdate = false;
  2929. };
  2930. using updateItemSelection_t = decltype(updateItemSelection);
  2931. obs_scene_atomic_update(GetCurrentScene(),
  2932. [](void *data, obs_scene_t *)
  2933. {
  2934. (*static_cast<updateItemSelection_t*>(data))();
  2935. }, static_cast<void*>(&updateItemSelection));
  2936. }
  2937. void OBSBasic::EditSceneItemName()
  2938. {
  2939. QListWidgetItem *item = GetTopSelectedSourceItem();
  2940. Qt::ItemFlags flags = item->flags();
  2941. OBSSceneItem sceneItem= GetOBSRef<OBSSceneItem>(item);
  2942. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2943. const char *name = obs_source_get_name(source);
  2944. item->setText(QT_UTF8(name));
  2945. item->setFlags(flags | Qt::ItemIsEditable);
  2946. ui->sources->removeItemWidget(item);
  2947. ui->sources->editItem(item);
  2948. item->setFlags(flags);
  2949. }
  2950. void OBSBasic::SetDeinterlacingMode()
  2951. {
  2952. QAction *action = reinterpret_cast<QAction*>(sender());
  2953. obs_deinterlace_mode mode =
  2954. (obs_deinterlace_mode)action->property("mode").toInt();
  2955. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2956. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2957. obs_source_set_deinterlace_mode(source, mode);
  2958. }
  2959. void OBSBasic::SetDeinterlacingOrder()
  2960. {
  2961. QAction *action = reinterpret_cast<QAction*>(sender());
  2962. obs_deinterlace_field_order order =
  2963. (obs_deinterlace_field_order)action->property("order").toInt();
  2964. OBSSceneItem sceneItem = GetCurrentSceneItem();
  2965. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  2966. obs_source_set_deinterlace_field_order(source, order);
  2967. }
  2968. QMenu *OBSBasic::AddDeinterlacingMenu(obs_source_t *source)
  2969. {
  2970. QMenu *menu = new QMenu(QTStr("Deinterlacing"));
  2971. obs_deinterlace_mode deinterlaceMode =
  2972. obs_source_get_deinterlace_mode(source);
  2973. obs_deinterlace_field_order deinterlaceOrder =
  2974. obs_source_get_deinterlace_field_order(source);
  2975. QAction *action;
  2976. #define ADD_MODE(name, mode) \
  2977. action = menu->addAction(QTStr("" name), this, \
  2978. SLOT(SetDeinterlacingMode())); \
  2979. action->setProperty("mode", (int)mode); \
  2980. action->setCheckable(true); \
  2981. action->setChecked(deinterlaceMode == mode);
  2982. ADD_MODE("Disable", OBS_DEINTERLACE_MODE_DISABLE);
  2983. ADD_MODE("Deinterlacing.Discard", OBS_DEINTERLACE_MODE_DISCARD);
  2984. ADD_MODE("Deinterlacing.Retro", OBS_DEINTERLACE_MODE_RETRO);
  2985. ADD_MODE("Deinterlacing.Blend", OBS_DEINTERLACE_MODE_BLEND);
  2986. ADD_MODE("Deinterlacing.Blend2x", OBS_DEINTERLACE_MODE_BLEND_2X);
  2987. ADD_MODE("Deinterlacing.Linear", OBS_DEINTERLACE_MODE_LINEAR);
  2988. ADD_MODE("Deinterlacing.Linear2x", OBS_DEINTERLACE_MODE_LINEAR_2X);
  2989. ADD_MODE("Deinterlacing.Yadif", OBS_DEINTERLACE_MODE_YADIF);
  2990. ADD_MODE("Deinterlacing.Yadif2x", OBS_DEINTERLACE_MODE_YADIF_2X);
  2991. #undef ADD_MODE
  2992. menu->addSeparator();
  2993. #define ADD_ORDER(name, order) \
  2994. action = menu->addAction(QTStr("Deinterlacing." name), this, \
  2995. SLOT(SetDeinterlacingOrder())); \
  2996. action->setProperty("order", (int)order); \
  2997. action->setCheckable(true); \
  2998. action->setChecked(deinterlaceOrder == order);
  2999. ADD_ORDER("TopFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_TOP);
  3000. ADD_ORDER("BottomFieldFirst", OBS_DEINTERLACE_FIELD_ORDER_BOTTOM);
  3001. #undef ADD_ORDER
  3002. return menu;
  3003. }
  3004. void OBSBasic::SetScaleFilter()
  3005. {
  3006. QAction *action = reinterpret_cast<QAction*>(sender());
  3007. obs_scale_type mode = (obs_scale_type)action->property("mode").toInt();
  3008. OBSSceneItem sceneItem = GetCurrentSceneItem();
  3009. obs_sceneitem_set_scale_filter(sceneItem, mode);
  3010. }
  3011. QMenu *OBSBasic::AddScaleFilteringMenu(obs_sceneitem_t *item)
  3012. {
  3013. QMenu *menu = new QMenu(QTStr("ScaleFiltering"));
  3014. obs_scale_type scaleFilter = obs_sceneitem_get_scale_filter(item);
  3015. QAction *action;
  3016. #define ADD_MODE(name, mode) \
  3017. action = menu->addAction(QTStr("" name), this, \
  3018. SLOT(SetScaleFilter())); \
  3019. action->setProperty("mode", (int)mode); \
  3020. action->setCheckable(true); \
  3021. action->setChecked(scaleFilter == mode);
  3022. ADD_MODE("Disable", OBS_SCALE_DISABLE);
  3023. ADD_MODE("ScaleFiltering.Point", OBS_SCALE_POINT);
  3024. ADD_MODE("ScaleFiltering.Bilinear", OBS_SCALE_BILINEAR);
  3025. ADD_MODE("ScaleFiltering.Bicubic", OBS_SCALE_BICUBIC);
  3026. ADD_MODE("ScaleFiltering.Lanczos", OBS_SCALE_LANCZOS);
  3027. #undef ADD_MODE
  3028. return menu;
  3029. }
  3030. void OBSBasic::CreateSourcePopupMenu(QListWidgetItem *item, bool preview)
  3031. {
  3032. QMenu popup(this);
  3033. QPointer<QMenu> previewProjector;
  3034. QPointer<QMenu> sourceProjector;
  3035. if (preview) {
  3036. QAction *action = popup.addAction(
  3037. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  3038. this, SLOT(TogglePreview()));
  3039. action->setCheckable(true);
  3040. action->setChecked(
  3041. obs_display_enabled(ui->preview->GetDisplay()));
  3042. if (IsPreviewProgramMode())
  3043. action->setEnabled(false);
  3044. popup.addAction(ui->actionLockPreview);
  3045. popup.addMenu(ui->scalingMenu);
  3046. previewProjector = new QMenu(QTStr("PreviewProjector"));
  3047. AddProjectorMenuMonitors(previewProjector, this,
  3048. SLOT(OpenPreviewProjector()));
  3049. popup.addMenu(previewProjector);
  3050. QAction *previewWindow = popup.addAction(
  3051. QTStr("PreviewWindow"),
  3052. this, SLOT(OpenPreviewWindow()));
  3053. popup.addAction(previewWindow);
  3054. popup.addSeparator();
  3055. }
  3056. QPointer<QMenu> addSourceMenu = CreateAddSourcePopupMenu();
  3057. if (addSourceMenu)
  3058. popup.addMenu(addSourceMenu);
  3059. ui->actionCopyFilters->setEnabled(false);
  3060. ui->actionCopySource->setEnabled(false);
  3061. popup.addSeparator();
  3062. popup.addAction(ui->actionCopySource);
  3063. popup.addAction(ui->actionPasteRef);
  3064. popup.addAction(ui->actionPasteDup);
  3065. popup.addSeparator();
  3066. popup.addSeparator();
  3067. popup.addAction(ui->actionCopyFilters);
  3068. popup.addAction(ui->actionPasteFilters);
  3069. popup.addSeparator();
  3070. if (item) {
  3071. if (addSourceMenu)
  3072. popup.addSeparator();
  3073. OBSSceneItem sceneItem = GetSceneItem(item);
  3074. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  3075. uint32_t flags = obs_source_get_output_flags(source);
  3076. bool isAsyncVideo = (flags & OBS_SOURCE_ASYNC_VIDEO) ==
  3077. OBS_SOURCE_ASYNC_VIDEO;
  3078. bool hasAudio = (flags & OBS_SOURCE_AUDIO) ==
  3079. OBS_SOURCE_AUDIO;
  3080. QAction *action;
  3081. popup.addAction(QTStr("Rename"), this,
  3082. SLOT(EditSceneItemName()));
  3083. popup.addAction(QTStr("Remove"), this,
  3084. SLOT(on_actionRemoveSource_triggered()),
  3085. DeleteKeys.front());
  3086. popup.addSeparator();
  3087. popup.addMenu(ui->orderMenu);
  3088. popup.addMenu(ui->transformMenu);
  3089. sourceProjector = new QMenu(QTStr("SourceProjector"));
  3090. AddProjectorMenuMonitors(sourceProjector, this,
  3091. SLOT(OpenSourceProjector()));
  3092. QAction *sourceWindow = popup.addAction(
  3093. QTStr("SourceWindow"),
  3094. this, SLOT(OpenSourceWindow()));
  3095. popup.addAction(sourceWindow);
  3096. popup.addSeparator();
  3097. if (hasAudio) {
  3098. QAction *actionHideMixer = popup.addAction(
  3099. QTStr("HideMixer"),
  3100. this, SLOT(ToggleHideMixer()));
  3101. actionHideMixer->setCheckable(true);
  3102. actionHideMixer->setChecked(SourceMixerHidden(source));
  3103. }
  3104. if (isAsyncVideo) {
  3105. popup.addMenu(AddDeinterlacingMenu(source));
  3106. popup.addSeparator();
  3107. }
  3108. popup.addMenu(AddScaleFilteringMenu(sceneItem));
  3109. popup.addSeparator();
  3110. popup.addMenu(sourceProjector);
  3111. popup.addAction(sourceWindow);
  3112. popup.addSeparator();
  3113. action = popup.addAction(QTStr("Interact"), this,
  3114. SLOT(on_actionInteract_triggered()));
  3115. action->setEnabled(obs_source_get_output_flags(source) &
  3116. OBS_SOURCE_INTERACTION);
  3117. popup.addAction(QTStr("Filters"), this,
  3118. SLOT(OpenFilters()));
  3119. popup.addAction(QTStr("Properties"), this,
  3120. SLOT(on_actionSourceProperties_triggered()));
  3121. ui->actionCopyFilters->setEnabled(true);
  3122. ui->actionCopySource->setEnabled(true);
  3123. }
  3124. popup.exec(QCursor::pos());
  3125. }
  3126. void OBSBasic::on_sources_customContextMenuRequested(const QPoint &pos)
  3127. {
  3128. if (ui->scenes->count())
  3129. CreateSourcePopupMenu(ui->sources->itemAt(pos), false);
  3130. }
  3131. void OBSBasic::on_sources_itemDoubleClicked(QListWidgetItem *witem)
  3132. {
  3133. if (!witem)
  3134. return;
  3135. OBSSceneItem item = GetSceneItem(witem);
  3136. OBSSource source = obs_sceneitem_get_source(item);
  3137. if (source)
  3138. CreatePropertiesWindow(source);
  3139. }
  3140. void OBSBasic::on_scenes_itemDoubleClicked(QListWidgetItem *witem)
  3141. {
  3142. if (!witem)
  3143. return;
  3144. if (IsPreviewProgramMode()) {
  3145. bool doubleClickSwitch = config_get_bool(App()->GlobalConfig(),
  3146. "BasicWindow", "TransitionOnDoubleClick");
  3147. if (doubleClickSwitch) {
  3148. OBSScene scene = GetCurrentScene();
  3149. if (scene)
  3150. SetCurrentScene(scene, false, true);
  3151. }
  3152. }
  3153. }
  3154. void OBSBasic::AddSource(const char *id)
  3155. {
  3156. if (id && *id) {
  3157. OBSBasicSourceSelect sourceSelect(this, id);
  3158. sourceSelect.exec();
  3159. if (sourceSelect.newSource)
  3160. CreatePropertiesWindow(sourceSelect.newSource);
  3161. }
  3162. }
  3163. QMenu *OBSBasic::CreateAddSourcePopupMenu()
  3164. {
  3165. const char *type;
  3166. bool foundValues = false;
  3167. bool foundDeprecated = false;
  3168. size_t idx = 0;
  3169. QMenu *popup = new QMenu(QTStr("Add"), this);
  3170. QMenu *deprecated = new QMenu(QTStr("Deprecated"), popup);
  3171. auto getActionAfter = [] (QMenu *menu, const QString &name)
  3172. {
  3173. QList<QAction*> actions = menu->actions();
  3174. for (QAction *menuAction : actions) {
  3175. if (menuAction->text().compare(name) >= 0)
  3176. return menuAction;
  3177. }
  3178. return (QAction*)nullptr;
  3179. };
  3180. auto addSource = [this, getActionAfter] (QMenu *popup,
  3181. const char *type, const char *name)
  3182. {
  3183. QString qname = QT_UTF8(name);
  3184. QAction *popupItem = new QAction(qname, this);
  3185. popupItem->setData(QT_UTF8(type));
  3186. connect(popupItem, SIGNAL(triggered(bool)),
  3187. this, SLOT(AddSourceFromAction()));
  3188. QAction *after = getActionAfter(popup, qname);
  3189. popup->insertAction(after, popupItem);
  3190. };
  3191. while (obs_enum_input_types(idx++, &type)) {
  3192. const char *name = obs_source_get_display_name(type);
  3193. uint32_t caps = obs_get_source_output_flags(type);
  3194. if ((caps & OBS_SOURCE_CAP_DISABLED) != 0)
  3195. continue;
  3196. if ((caps & OBS_SOURCE_DEPRECATED) == 0) {
  3197. addSource(popup, type, name);
  3198. } else {
  3199. addSource(deprecated, type, name);
  3200. foundDeprecated = true;
  3201. }
  3202. foundValues = true;
  3203. }
  3204. addSource(popup, "scene", Str("Basic.Scene"));
  3205. if (!foundDeprecated) {
  3206. delete deprecated;
  3207. deprecated = nullptr;
  3208. }
  3209. if (!foundValues) {
  3210. delete popup;
  3211. popup = nullptr;
  3212. } else if (foundDeprecated) {
  3213. popup->addMenu(deprecated);
  3214. }
  3215. return popup;
  3216. }
  3217. void OBSBasic::AddSourceFromAction()
  3218. {
  3219. QAction *action = qobject_cast<QAction*>(sender());
  3220. if (!action)
  3221. return;
  3222. AddSource(QT_TO_UTF8(action->data().toString()));
  3223. }
  3224. void OBSBasic::AddSourcePopupMenu(const QPoint &pos)
  3225. {
  3226. if (!GetCurrentScene()) {
  3227. // Tell the user he needs a scene first (help beginners).
  3228. OBSMessageBox::information(this,
  3229. QTStr("Basic.Main.AddSourceHelp.Title"),
  3230. QTStr("Basic.Main.AddSourceHelp.Text"));
  3231. return;
  3232. }
  3233. QPointer<QMenu> popup = CreateAddSourcePopupMenu();
  3234. if (popup)
  3235. popup->exec(pos);
  3236. }
  3237. void OBSBasic::on_actionAddSource_triggered()
  3238. {
  3239. AddSourcePopupMenu(QCursor::pos());
  3240. }
  3241. void OBSBasic::on_actionRemoveSource_triggered()
  3242. {
  3243. vector<OBSSceneItem> items;
  3244. auto func = [] (obs_scene_t *, obs_sceneitem_t *item, void *param)
  3245. {
  3246. vector<OBSSceneItem> &items =
  3247. *reinterpret_cast<vector<OBSSceneItem>*>(param);
  3248. if (obs_sceneitem_selected(item))
  3249. items.emplace_back(item);
  3250. return true;
  3251. };
  3252. obs_scene_enum_items(GetCurrentScene(), func, &items);
  3253. if (!items.size())
  3254. return;
  3255. auto removeMultiple = [this] (size_t count)
  3256. {
  3257. QString text = QTStr("ConfirmRemove.TextMultiple")
  3258. .arg(QString::number(count));
  3259. QMessageBox remove_items(this);
  3260. remove_items.setText(text);
  3261. QAbstractButton *Yes = remove_items.addButton(QTStr("Yes"),
  3262. QMessageBox::YesRole);
  3263. remove_items.addButton(QTStr("No"), QMessageBox::NoRole);
  3264. remove_items.setIcon(QMessageBox::Question);
  3265. remove_items.setWindowTitle(QTStr("ConfirmRemove.Title"));
  3266. remove_items.exec();
  3267. return Yes == remove_items.clickedButton();
  3268. };
  3269. if (items.size() == 1) {
  3270. OBSSceneItem &item = items[0];
  3271. obs_source_t *source = obs_sceneitem_get_source(item);
  3272. if (source && QueryRemoveSource(source))
  3273. obs_sceneitem_remove(item);
  3274. } else {
  3275. if (removeMultiple(items.size())) {
  3276. for (auto &item : items)
  3277. obs_sceneitem_remove(item);
  3278. }
  3279. }
  3280. }
  3281. void OBSBasic::on_actionInteract_triggered()
  3282. {
  3283. OBSSceneItem item = GetCurrentSceneItem();
  3284. OBSSource source = obs_sceneitem_get_source(item);
  3285. if (source)
  3286. CreateInteractionWindow(source);
  3287. }
  3288. void OBSBasic::on_actionSourceProperties_triggered()
  3289. {
  3290. OBSSceneItem item = GetCurrentSceneItem();
  3291. OBSSource source = obs_sceneitem_get_source(item);
  3292. if (source)
  3293. CreatePropertiesWindow(source);
  3294. }
  3295. void OBSBasic::on_actionSourceUp_triggered()
  3296. {
  3297. OBSSceneItem item = GetCurrentSceneItem();
  3298. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3299. }
  3300. void OBSBasic::on_actionSourceDown_triggered()
  3301. {
  3302. OBSSceneItem item = GetCurrentSceneItem();
  3303. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3304. }
  3305. void OBSBasic::on_actionMoveUp_triggered()
  3306. {
  3307. OBSSceneItem item = GetCurrentSceneItem();
  3308. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  3309. }
  3310. void OBSBasic::on_actionMoveDown_triggered()
  3311. {
  3312. OBSSceneItem item = GetCurrentSceneItem();
  3313. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  3314. }
  3315. void OBSBasic::on_actionMoveToTop_triggered()
  3316. {
  3317. OBSSceneItem item = GetCurrentSceneItem();
  3318. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_TOP);
  3319. }
  3320. void OBSBasic::on_actionMoveToBottom_triggered()
  3321. {
  3322. OBSSceneItem item = GetCurrentSceneItem();
  3323. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_BOTTOM);
  3324. }
  3325. static BPtr<char> ReadLogFile(const char *subdir, const char *log)
  3326. {
  3327. char logDir[512];
  3328. if (GetConfigPath(logDir, sizeof(logDir), subdir) <= 0)
  3329. return nullptr;
  3330. string path = (char*)logDir;
  3331. path += "/";
  3332. path += log;
  3333. BPtr<char> file = os_quick_read_utf8_file(path.c_str());
  3334. if (!file)
  3335. blog(LOG_WARNING, "Failed to read log file %s", path.c_str());
  3336. return file;
  3337. }
  3338. void OBSBasic::UploadLog(const char *subdir, const char *file)
  3339. {
  3340. BPtr<char> fileString{ReadLogFile(subdir, file)};
  3341. if (!fileString)
  3342. return;
  3343. if (!*fileString)
  3344. return;
  3345. ui->menuLogFiles->setEnabled(false);
  3346. stringstream ss;
  3347. ss << "OBS " << App()->GetVersionString()
  3348. << " log file uploaded at " << CurrentDateTimeString()
  3349. << "\n\n" << fileString;
  3350. if (logUploadThread) {
  3351. logUploadThread->wait();
  3352. delete logUploadThread;
  3353. }
  3354. RemoteTextThread *thread = new RemoteTextThread(
  3355. "https://hastebin.com/documents",
  3356. "text/plain", ss.str().c_str());
  3357. logUploadThread = thread;
  3358. connect(thread, &RemoteTextThread::Result,
  3359. this, &OBSBasic::logUploadFinished);
  3360. logUploadThread->start();
  3361. }
  3362. void OBSBasic::on_actionShowLogs_triggered()
  3363. {
  3364. char logDir[512];
  3365. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3366. return;
  3367. QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
  3368. QDesktopServices::openUrl(url);
  3369. }
  3370. void OBSBasic::on_actionUploadCurrentLog_triggered()
  3371. {
  3372. UploadLog("obs-studio/logs", App()->GetCurrentLog());
  3373. }
  3374. void OBSBasic::on_actionUploadLastLog_triggered()
  3375. {
  3376. UploadLog("obs-studio/logs", App()->GetLastLog());
  3377. }
  3378. void OBSBasic::on_actionViewCurrentLog_triggered()
  3379. {
  3380. char logDir[512];
  3381. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
  3382. return;
  3383. const char* log = App()->GetCurrentLog();
  3384. string path = (char*)logDir;
  3385. path += "/";
  3386. path += log;
  3387. QUrl url = QUrl::fromLocalFile(QT_UTF8(path.c_str()));
  3388. QDesktopServices::openUrl(url);
  3389. }
  3390. void OBSBasic::on_actionShowCrashLogs_triggered()
  3391. {
  3392. char logDir[512];
  3393. if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/crashes") <= 0)
  3394. return;
  3395. QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
  3396. QDesktopServices::openUrl(url);
  3397. }
  3398. void OBSBasic::on_actionUploadLastCrashLog_triggered()
  3399. {
  3400. UploadLog("obs-studio/crashes", App()->GetLastCrashLog());
  3401. }
  3402. void OBSBasic::on_actionCheckForUpdates_triggered()
  3403. {
  3404. CheckForUpdates(true);
  3405. }
  3406. void OBSBasic::logUploadFinished(const QString &text, const QString &error)
  3407. {
  3408. ui->menuLogFiles->setEnabled(true);
  3409. if (text.isEmpty()) {
  3410. OBSMessageBox::information(this,
  3411. QTStr("LogReturnDialog.ErrorUploadingLog"),
  3412. error);
  3413. return;
  3414. }
  3415. obs_data_t *returnData = obs_data_create_from_json(QT_TO_UTF8(text));
  3416. string resURL = "https://hastebin.com/";
  3417. resURL += obs_data_get_string(returnData, "key");
  3418. QString logURL = resURL.c_str();
  3419. obs_data_release(returnData);
  3420. OBSLogReply logDialog(this, logURL);
  3421. logDialog.exec();
  3422. }
  3423. static void RenameListItem(OBSBasic *parent, QListWidget *listWidget,
  3424. obs_source_t *source, const string &name)
  3425. {
  3426. const char *prevName = obs_source_get_name(source);
  3427. if (name == prevName)
  3428. return;
  3429. obs_source_t *foundSource = obs_get_source_by_name(name.c_str());
  3430. QListWidgetItem *listItem = listWidget->currentItem();
  3431. if (foundSource || name.empty()) {
  3432. listItem->setText(QT_UTF8(prevName));
  3433. if (foundSource) {
  3434. OBSMessageBox::information(parent,
  3435. QTStr("NameExists.Title"),
  3436. QTStr("NameExists.Text"));
  3437. } else if (name.empty()) {
  3438. OBSMessageBox::information(parent,
  3439. QTStr("NoNameEntered.Title"),
  3440. QTStr("NoNameEntered.Text"));
  3441. }
  3442. obs_source_release(foundSource);
  3443. } else {
  3444. listItem->setText(QT_UTF8(name.c_str()));
  3445. obs_source_set_name(source, name.c_str());
  3446. }
  3447. }
  3448. void OBSBasic::SceneNameEdited(QWidget *editor,
  3449. QAbstractItemDelegate::EndEditHint endHint)
  3450. {
  3451. OBSScene scene = GetCurrentScene();
  3452. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  3453. string text = QT_TO_UTF8(edit->text().trimmed());
  3454. if (!scene)
  3455. return;
  3456. obs_source_t *source = obs_scene_get_source(scene);
  3457. RenameListItem(this, ui->scenes, source, text);
  3458. if (api)
  3459. api->on_event(OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED);
  3460. UNUSED_PARAMETER(endHint);
  3461. }
  3462. void OBSBasic::SceneItemNameEdited(QWidget *editor,
  3463. QAbstractItemDelegate::EndEditHint endHint)
  3464. {
  3465. OBSSceneItem item = GetCurrentSceneItem();
  3466. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  3467. string text = QT_TO_UTF8(edit->text().trimmed());
  3468. if (!item)
  3469. return;
  3470. obs_source_t *source = obs_sceneitem_get_source(item);
  3471. RenameListItem(this, ui->sources, source, text);
  3472. QListWidgetItem *listItem = ui->sources->currentItem();
  3473. listItem->setText(QString());
  3474. SetupVisibilityItem(ui->sources, listItem, item);
  3475. UNUSED_PARAMETER(endHint);
  3476. }
  3477. void OBSBasic::OpenFilters()
  3478. {
  3479. OBSSceneItem item = GetCurrentSceneItem();
  3480. OBSSource source = obs_sceneitem_get_source(item);
  3481. CreateFiltersWindow(source);
  3482. }
  3483. void OBSBasic::OpenSceneFilters()
  3484. {
  3485. OBSScene scene = GetCurrentScene();
  3486. OBSSource source = obs_scene_get_source(scene);
  3487. CreateFiltersWindow(source);
  3488. }
  3489. #define RECORDING_START \
  3490. "==== Recording Start ==============================================="
  3491. #define RECORDING_STOP \
  3492. "==== Recording Stop ================================================"
  3493. #define REPLAY_BUFFER_START \
  3494. "==== Replay Buffer Start ==========================================="
  3495. #define REPLAY_BUFFER_STOP \
  3496. "==== Replay Buffer Stop ============================================"
  3497. #define STREAMING_START \
  3498. "==== Streaming Start ==============================================="
  3499. #define STREAMING_STOP \
  3500. "==== Streaming Stop ================================================"
  3501. void OBSBasic::StartStreaming()
  3502. {
  3503. if (outputHandler->StreamingActive())
  3504. return;
  3505. if (disableOutputsRef)
  3506. return;
  3507. if (api)
  3508. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTING);
  3509. SaveProject();
  3510. ui->streamButton->setEnabled(false);
  3511. ui->streamButton->setText(QTStr("Basic.Main.Connecting"));
  3512. if (sysTrayStream) {
  3513. sysTrayStream->setEnabled(false);
  3514. sysTrayStream->setText(ui->streamButton->text());
  3515. }
  3516. if (!outputHandler->StartStreaming(service)) {
  3517. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3518. ui->streamButton->setEnabled(true);
  3519. ui->streamButton->setChecked(false);
  3520. if (sysTrayStream) {
  3521. sysTrayStream->setText(ui->streamButton->text());
  3522. sysTrayStream->setEnabled(true);
  3523. }
  3524. QMessageBox::critical(this,
  3525. QTStr("Output.StartStreamFailed"),
  3526. QTStr("Output.StartFailedGeneric"));
  3527. return;
  3528. }
  3529. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3530. "BasicWindow", "RecordWhenStreaming");
  3531. if (recordWhenStreaming)
  3532. StartRecording();
  3533. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3534. "BasicWindow", "ReplayBufferWhileStreaming");
  3535. if (replayBufferWhileStreaming)
  3536. StartReplayBuffer();
  3537. }
  3538. #ifdef _WIN32
  3539. static inline void UpdateProcessPriority()
  3540. {
  3541. const char *priority = config_get_string(App()->GlobalConfig(),
  3542. "General", "ProcessPriority");
  3543. if (priority && strcmp(priority, "Normal") != 0)
  3544. SetProcessPriority(priority);
  3545. }
  3546. static inline void ClearProcessPriority()
  3547. {
  3548. const char *priority = config_get_string(App()->GlobalConfig(),
  3549. "General", "ProcessPriority");
  3550. if (priority && strcmp(priority, "Normal") != 0)
  3551. SetProcessPriority("Normal");
  3552. }
  3553. #else
  3554. #define UpdateProcessPriority() do {} while(false)
  3555. #define ClearProcessPriority() do {} while(false)
  3556. #endif
  3557. inline void OBSBasic::OnActivate()
  3558. {
  3559. if (ui->profileMenu->isEnabled()) {
  3560. ui->profileMenu->setEnabled(false);
  3561. ui->autoConfigure->setEnabled(false);
  3562. App()->IncrementSleepInhibition();
  3563. UpdateProcessPriority();
  3564. if (trayIcon)
  3565. trayIcon->setIcon(QIcon(":/res/images/tray_active.png"));
  3566. }
  3567. }
  3568. inline void OBSBasic::OnDeactivate()
  3569. {
  3570. if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
  3571. ui->profileMenu->setEnabled(true);
  3572. ui->autoConfigure->setEnabled(true);
  3573. App()->DecrementSleepInhibition();
  3574. ClearProcessPriority();
  3575. if (trayIcon)
  3576. trayIcon->setIcon(QIcon(":/res/images/obs.png"));
  3577. }
  3578. }
  3579. void OBSBasic::StopStreaming()
  3580. {
  3581. SaveProject();
  3582. if (outputHandler->StreamingActive())
  3583. outputHandler->StopStreaming(streamingStopping);
  3584. OnDeactivate();
  3585. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3586. "BasicWindow", "RecordWhenStreaming");
  3587. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  3588. "BasicWindow", "KeepRecordingWhenStreamStops");
  3589. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  3590. StopRecording();
  3591. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3592. "BasicWindow", "ReplayBufferWhileStreaming");
  3593. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  3594. "BasicWindow", "KeepReplayBufferStreamStops");
  3595. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  3596. StopReplayBuffer();
  3597. }
  3598. void OBSBasic::ForceStopStreaming()
  3599. {
  3600. SaveProject();
  3601. if (outputHandler->StreamingActive())
  3602. outputHandler->StopStreaming(true);
  3603. OnDeactivate();
  3604. bool recordWhenStreaming = config_get_bool(GetGlobalConfig(),
  3605. "BasicWindow", "RecordWhenStreaming");
  3606. bool keepRecordingWhenStreamStops = config_get_bool(GetGlobalConfig(),
  3607. "BasicWindow", "KeepRecordingWhenStreamStops");
  3608. if (recordWhenStreaming && !keepRecordingWhenStreamStops)
  3609. StopRecording();
  3610. bool replayBufferWhileStreaming = config_get_bool(GetGlobalConfig(),
  3611. "BasicWindow", "ReplayBufferWhileStreaming");
  3612. bool keepReplayBufferStreamStops = config_get_bool(GetGlobalConfig(),
  3613. "BasicWindow", "KeepReplayBufferStreamStops");
  3614. if (replayBufferWhileStreaming && !keepReplayBufferStreamStops)
  3615. StopReplayBuffer();
  3616. }
  3617. void OBSBasic::StreamDelayStarting(int sec)
  3618. {
  3619. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  3620. ui->streamButton->setEnabled(true);
  3621. ui->streamButton->setChecked(true);
  3622. if (sysTrayStream) {
  3623. sysTrayStream->setText(ui->streamButton->text());
  3624. sysTrayStream->setEnabled(true);
  3625. }
  3626. if (!startStreamMenu.isNull())
  3627. startStreamMenu->deleteLater();
  3628. startStreamMenu = new QMenu();
  3629. startStreamMenu->addAction(QTStr("Basic.Main.StopStreaming"),
  3630. this, SLOT(StopStreaming()));
  3631. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  3632. this, SLOT(ForceStopStreaming()));
  3633. ui->streamButton->setMenu(startStreamMenu);
  3634. ui->statusbar->StreamDelayStarting(sec);
  3635. OnActivate();
  3636. }
  3637. void OBSBasic::StreamDelayStopping(int sec)
  3638. {
  3639. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3640. ui->streamButton->setEnabled(true);
  3641. ui->streamButton->setChecked(false);
  3642. if (sysTrayStream) {
  3643. sysTrayStream->setText(ui->streamButton->text());
  3644. sysTrayStream->setEnabled(true);
  3645. }
  3646. if (!startStreamMenu.isNull())
  3647. startStreamMenu->deleteLater();
  3648. startStreamMenu = new QMenu();
  3649. startStreamMenu->addAction(QTStr("Basic.Main.StartStreaming"),
  3650. this, SLOT(StartStreaming()));
  3651. startStreamMenu->addAction(QTStr("Basic.Main.ForceStopStreaming"),
  3652. this, SLOT(ForceStopStreaming()));
  3653. ui->streamButton->setMenu(startStreamMenu);
  3654. ui->statusbar->StreamDelayStopping(sec);
  3655. }
  3656. void OBSBasic::StreamingStart()
  3657. {
  3658. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  3659. ui->streamButton->setEnabled(true);
  3660. ui->streamButton->setChecked(true);
  3661. ui->statusbar->StreamStarted(outputHandler->streamOutput);
  3662. if (sysTrayStream) {
  3663. sysTrayStream->setText(ui->streamButton->text());
  3664. sysTrayStream->setEnabled(true);
  3665. }
  3666. if (api)
  3667. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STARTED);
  3668. OnActivate();
  3669. blog(LOG_INFO, STREAMING_START);
  3670. }
  3671. void OBSBasic::StreamStopping()
  3672. {
  3673. ui->streamButton->setText(QTStr("Basic.Main.StoppingStreaming"));
  3674. if (sysTrayStream)
  3675. sysTrayStream->setText(ui->streamButton->text());
  3676. streamingStopping = true;
  3677. if (api)
  3678. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPING);
  3679. }
  3680. void OBSBasic::StreamingStop(int code, QString last_error)
  3681. {
  3682. const char *errorDescription;
  3683. DStr errorMessage;
  3684. bool use_last_error = false;
  3685. switch (code) {
  3686. case OBS_OUTPUT_BAD_PATH:
  3687. errorDescription = Str("Output.ConnectFail.BadPath");
  3688. break;
  3689. case OBS_OUTPUT_CONNECT_FAILED:
  3690. use_last_error = true;
  3691. errorDescription = Str("Output.ConnectFail.ConnectFailed");
  3692. break;
  3693. case OBS_OUTPUT_INVALID_STREAM:
  3694. errorDescription = Str("Output.ConnectFail.InvalidStream");
  3695. break;
  3696. default:
  3697. case OBS_OUTPUT_ERROR:
  3698. use_last_error = true;
  3699. errorDescription = Str("Output.ConnectFail.Error");
  3700. break;
  3701. case OBS_OUTPUT_DISCONNECTED:
  3702. /* doesn't happen if output is set to reconnect. note that
  3703. * reconnects are handled in the output, not in the UI */
  3704. use_last_error = true;
  3705. errorDescription = Str("Output.ConnectFail.Disconnected");
  3706. }
  3707. if (use_last_error && !last_error.isEmpty())
  3708. dstr_printf(errorMessage, "%s\n\n%s", errorDescription,
  3709. QT_TO_UTF8(last_error));
  3710. else
  3711. dstr_copy(errorMessage, errorDescription);
  3712. ui->statusbar->StreamStopped();
  3713. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  3714. ui->streamButton->setEnabled(true);
  3715. ui->streamButton->setChecked(false);
  3716. if (sysTrayStream) {
  3717. sysTrayStream->setText(ui->streamButton->text());
  3718. sysTrayStream->setEnabled(true);
  3719. }
  3720. streamingStopping = false;
  3721. if (api)
  3722. api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPED);
  3723. OnDeactivate();
  3724. blog(LOG_INFO, STREAMING_STOP);
  3725. if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3726. OBSMessageBox::information(this,
  3727. QTStr("Output.ConnectFail.Title"),
  3728. QT_UTF8(errorMessage));
  3729. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3730. SysTrayNotify(QT_UTF8(errorDescription), QSystemTrayIcon::Warning);
  3731. }
  3732. if (!startStreamMenu.isNull()) {
  3733. ui->streamButton->setMenu(nullptr);
  3734. startStreamMenu->deleteLater();
  3735. startStreamMenu = nullptr;
  3736. }
  3737. }
  3738. void OBSBasic::StartRecording()
  3739. {
  3740. if (outputHandler->RecordingActive())
  3741. return;
  3742. if (disableOutputsRef)
  3743. return;
  3744. if (api)
  3745. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTING);
  3746. SaveProject();
  3747. outputHandler->StartRecording();
  3748. }
  3749. void OBSBasic::RecordStopping()
  3750. {
  3751. ui->recordButton->setText(QTStr("Basic.Main.StoppingRecording"));
  3752. if (sysTrayRecord)
  3753. sysTrayRecord->setText(ui->recordButton->text());
  3754. recordingStopping = true;
  3755. if (api)
  3756. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPING);
  3757. }
  3758. void OBSBasic::StopRecording()
  3759. {
  3760. SaveProject();
  3761. if (outputHandler->RecordingActive())
  3762. outputHandler->StopRecording(recordingStopping);
  3763. OnDeactivate();
  3764. }
  3765. void OBSBasic::RecordingStart()
  3766. {
  3767. ui->statusbar->RecordingStarted(outputHandler->fileOutput);
  3768. ui->recordButton->setText(QTStr("Basic.Main.StopRecording"));
  3769. ui->recordButton->setChecked(true);
  3770. if (sysTrayRecord)
  3771. sysTrayRecord->setText(ui->recordButton->text());
  3772. recordingStopping = false;
  3773. if (api)
  3774. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTED);
  3775. OnActivate();
  3776. blog(LOG_INFO, RECORDING_START);
  3777. }
  3778. void OBSBasic::RecordingStop(int code)
  3779. {
  3780. ui->statusbar->RecordingStopped();
  3781. ui->recordButton->setText(QTStr("Basic.Main.StartRecording"));
  3782. ui->recordButton->setChecked(false);
  3783. if (sysTrayRecord)
  3784. sysTrayRecord->setText(ui->recordButton->text());
  3785. blog(LOG_INFO, RECORDING_STOP);
  3786. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  3787. OBSMessageBox::information(this,
  3788. QTStr("Output.RecordFail.Title"),
  3789. QTStr("Output.RecordFail.Unsupported"));
  3790. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  3791. OBSMessageBox::information(this,
  3792. QTStr("Output.RecordNoSpace.Title"),
  3793. QTStr("Output.RecordNoSpace.Msg"));
  3794. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3795. OBSMessageBox::information(this,
  3796. QTStr("Output.RecordError.Title"),
  3797. QTStr("Output.RecordError.Msg"));
  3798. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  3799. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  3800. QSystemTrayIcon::Warning);
  3801. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  3802. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  3803. QSystemTrayIcon::Warning);
  3804. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3805. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  3806. QSystemTrayIcon::Warning);
  3807. }
  3808. if (api)
  3809. api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPED);
  3810. OnDeactivate();
  3811. }
  3812. #define RP_NO_HOTKEY_TITLE QTStr("Output.ReplayBuffer.NoHotkey.Title")
  3813. #define RP_NO_HOTKEY_TEXT QTStr("Output.ReplayBuffer.NoHotkey.Msg")
  3814. void OBSBasic::StartReplayBuffer()
  3815. {
  3816. if (!outputHandler || !outputHandler->replayBuffer)
  3817. return;
  3818. if (outputHandler->ReplayBufferActive())
  3819. return;
  3820. if (disableOutputsRef)
  3821. return;
  3822. obs_output_t *output = outputHandler->replayBuffer;
  3823. obs_data_t *hotkeys = obs_hotkeys_save_output(output);
  3824. obs_data_array_t *bindings = obs_data_get_array(hotkeys,
  3825. "ReplayBuffer.Save");
  3826. size_t count = obs_data_array_count(bindings);
  3827. obs_data_array_release(bindings);
  3828. obs_data_release(hotkeys);
  3829. if (!count) {
  3830. OBSMessageBox::information(this,
  3831. RP_NO_HOTKEY_TITLE,
  3832. RP_NO_HOTKEY_TEXT);
  3833. return;
  3834. }
  3835. if (api)
  3836. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING);
  3837. SaveProject();
  3838. outputHandler->StartReplayBuffer();
  3839. }
  3840. void OBSBasic::ReplayBufferStopping()
  3841. {
  3842. if (!outputHandler || !outputHandler->replayBuffer)
  3843. return;
  3844. replayBufferButton->setText(QTStr("Basic.Main.StoppingReplayBuffer"));
  3845. if (sysTrayReplayBuffer)
  3846. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3847. replayBufferStopping = true;
  3848. if (api)
  3849. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING);
  3850. }
  3851. void OBSBasic::StopReplayBuffer()
  3852. {
  3853. if (!outputHandler || !outputHandler->replayBuffer)
  3854. return;
  3855. SaveProject();
  3856. if (outputHandler->ReplayBufferActive())
  3857. outputHandler->StopReplayBuffer(replayBufferStopping);
  3858. OnDeactivate();
  3859. }
  3860. void OBSBasic::ReplayBufferStart()
  3861. {
  3862. if (!outputHandler || !outputHandler->replayBuffer)
  3863. return;
  3864. replayBufferButton->setText(QTStr("Basic.Main.StopReplayBuffer"));
  3865. if (sysTrayReplayBuffer)
  3866. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3867. replayBufferStopping = false;
  3868. if (api)
  3869. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED);
  3870. OnActivate();
  3871. blog(LOG_INFO, REPLAY_BUFFER_START);
  3872. }
  3873. void OBSBasic::ReplayBufferSave()
  3874. {
  3875. if (!outputHandler || !outputHandler->replayBuffer)
  3876. return;
  3877. if (!outputHandler->ReplayBufferActive())
  3878. return;
  3879. calldata_t cd = {0};
  3880. proc_handler_t *ph = obs_output_get_proc_handler(
  3881. outputHandler->replayBuffer);
  3882. proc_handler_call(ph, "save", &cd);
  3883. calldata_free(&cd);
  3884. }
  3885. void OBSBasic::ReplayBufferStop(int code)
  3886. {
  3887. if (!outputHandler || !outputHandler->replayBuffer)
  3888. return;
  3889. replayBufferButton->setText(QTStr("Basic.Main.StartReplayBuffer"));
  3890. if (sysTrayReplayBuffer)
  3891. sysTrayReplayBuffer->setText(replayBufferButton->text());
  3892. blog(LOG_INFO, REPLAY_BUFFER_STOP);
  3893. if (code == OBS_OUTPUT_UNSUPPORTED && isVisible()) {
  3894. OBSMessageBox::information(this,
  3895. QTStr("Output.RecordFail.Title"),
  3896. QTStr("Output.RecordFail.Unsupported"));
  3897. } else if (code == OBS_OUTPUT_NO_SPACE && isVisible()) {
  3898. OBSMessageBox::information(this,
  3899. QTStr("Output.RecordNoSpace.Title"),
  3900. QTStr("Output.RecordNoSpace.Msg"));
  3901. } else if (code != OBS_OUTPUT_SUCCESS && isVisible()) {
  3902. OBSMessageBox::information(this,
  3903. QTStr("Output.RecordError.Title"),
  3904. QTStr("Output.RecordError.Msg"));
  3905. } else if (code == OBS_OUTPUT_UNSUPPORTED && !isVisible()) {
  3906. SysTrayNotify(QTStr("Output.RecordFail.Unsupported"),
  3907. QSystemTrayIcon::Warning);
  3908. } else if (code == OBS_OUTPUT_NO_SPACE && !isVisible()) {
  3909. SysTrayNotify(QTStr("Output.RecordNoSpace.Msg"),
  3910. QSystemTrayIcon::Warning);
  3911. } else if (code != OBS_OUTPUT_SUCCESS && !isVisible()) {
  3912. SysTrayNotify(QTStr("Output.RecordError.Msg"),
  3913. QSystemTrayIcon::Warning);
  3914. }
  3915. if (api)
  3916. api->on_event(OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED);
  3917. OnDeactivate();
  3918. }
  3919. void OBSBasic::on_streamButton_clicked()
  3920. {
  3921. if (outputHandler->StreamingActive()) {
  3922. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  3923. "WarnBeforeStoppingStream");
  3924. if (confirm && isVisible()) {
  3925. QMessageBox::StandardButton button =
  3926. OBSMessageBox::question(this,
  3927. QTStr("ConfirmStop.Title"),
  3928. QTStr("ConfirmStop.Text"));
  3929. if (button == QMessageBox::No)
  3930. return;
  3931. }
  3932. StopStreaming();
  3933. } else {
  3934. bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow",
  3935. "WarnBeforeStartingStream");
  3936. if (confirm && isVisible()) {
  3937. QMessageBox::StandardButton button =
  3938. OBSMessageBox::question(this,
  3939. QTStr("ConfirmStart.Title"),
  3940. QTStr("ConfirmStart.Text"));
  3941. if (button == QMessageBox::No)
  3942. return;
  3943. }
  3944. StartStreaming();
  3945. }
  3946. }
  3947. void OBSBasic::on_recordButton_clicked()
  3948. {
  3949. if (outputHandler->RecordingActive())
  3950. StopRecording();
  3951. else
  3952. StartRecording();
  3953. }
  3954. void OBSBasic::on_settingsButton_clicked()
  3955. {
  3956. on_action_Settings_triggered();
  3957. }
  3958. void OBSBasic::on_actionHelpPortal_triggered()
  3959. {
  3960. QUrl url = QUrl("https://obsproject.com/help", QUrl::TolerantMode);
  3961. QDesktopServices::openUrl(url);
  3962. }
  3963. void OBSBasic::on_actionWebsite_triggered()
  3964. {
  3965. QUrl url = QUrl("https://obsproject.com", QUrl::TolerantMode);
  3966. QDesktopServices::openUrl(url);
  3967. }
  3968. void OBSBasic::on_actionShowSettingsFolder_triggered()
  3969. {
  3970. char path[512];
  3971. int ret = GetConfigPath(path, 512, "obs-studio");
  3972. if (ret <= 0)
  3973. return;
  3974. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  3975. }
  3976. void OBSBasic::on_actionShowProfileFolder_triggered()
  3977. {
  3978. char path[512];
  3979. int ret = GetProfilePath(path, 512, "");
  3980. if (ret <= 0)
  3981. return;
  3982. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  3983. }
  3984. QListWidgetItem *OBSBasic::GetTopSelectedSourceItem()
  3985. {
  3986. QList<QListWidgetItem*> selectedItems = ui->sources->selectedItems();
  3987. QListWidgetItem *topItem = nullptr;
  3988. if (selectedItems.size() != 0)
  3989. topItem = selectedItems[0];
  3990. return topItem;
  3991. }
  3992. void OBSBasic::on_preview_customContextMenuRequested(const QPoint &pos)
  3993. {
  3994. CreateSourcePopupMenu(GetTopSelectedSourceItem(), true);
  3995. UNUSED_PARAMETER(pos);
  3996. }
  3997. void OBSBasic::on_program_customContextMenuRequested(const QPoint&)
  3998. {
  3999. QMenu popup(this);
  4000. QPointer<QMenu> studioProgramProjector;
  4001. studioProgramProjector = new QMenu(
  4002. QTStr("StudioProgramProjector"));
  4003. AddProjectorMenuMonitors(studioProgramProjector, this,
  4004. SLOT(OpenStudioProgramProjector()));
  4005. popup.addMenu(studioProgramProjector);
  4006. QAction *studioProgramWindow = popup.addAction(
  4007. QTStr("StudioProgramWindow"),
  4008. this, SLOT(OpenStudioProgramWindow()));
  4009. popup.addAction(studioProgramWindow);
  4010. popup.exec(QCursor::pos());
  4011. }
  4012. void OBSBasic::on_previewDisabledLabel_customContextMenuRequested(
  4013. const QPoint &pos)
  4014. {
  4015. QMenu popup(this);
  4016. QPointer<QMenu> previewProjector;
  4017. QAction *action = popup.addAction(
  4018. QTStr("Basic.Main.PreviewConextMenu.Enable"),
  4019. this, SLOT(TogglePreview()));
  4020. action->setCheckable(true);
  4021. action->setChecked(obs_display_enabled(ui->preview->GetDisplay()));
  4022. previewProjector = new QMenu(QTStr("PreviewProjector"));
  4023. AddProjectorMenuMonitors(previewProjector, this,
  4024. SLOT(OpenPreviewProjector()));
  4025. QAction *previewWindow = popup.addAction(
  4026. QTStr("PreviewWindow"),
  4027. this, SLOT(OpenPreviewWindow()));
  4028. popup.addMenu(previewProjector);
  4029. popup.addAction(previewWindow);
  4030. popup.exec(QCursor::pos());
  4031. UNUSED_PARAMETER(pos);
  4032. }
  4033. void OBSBasic::on_actionAlwaysOnTop_triggered()
  4034. {
  4035. CloseDialogs();
  4036. /* Make sure all dialogs are safely and successfully closed before
  4037. * switching the always on top mode due to the fact that windows all
  4038. * have to be recreated, so queue the actual toggle to happen after
  4039. * all events related to closing the dialogs have finished */
  4040. QMetaObject::invokeMethod(this, "ToggleAlwaysOnTop",
  4041. Qt::QueuedConnection);
  4042. }
  4043. void OBSBasic::ToggleAlwaysOnTop()
  4044. {
  4045. bool isAlwaysOnTop = IsAlwaysOnTop(this);
  4046. ui->actionAlwaysOnTop->setChecked(!isAlwaysOnTop);
  4047. SetAlwaysOnTop(this, !isAlwaysOnTop);
  4048. show();
  4049. }
  4050. void OBSBasic::GetFPSCommon(uint32_t &num, uint32_t &den) const
  4051. {
  4052. const char *val = config_get_string(basicConfig, "Video", "FPSCommon");
  4053. if (strcmp(val, "10") == 0) {
  4054. num = 10;
  4055. den = 1;
  4056. } else if (strcmp(val, "20") == 0) {
  4057. num = 20;
  4058. den = 1;
  4059. } else if (strcmp(val, "24 NTSC") == 0) {
  4060. num = 24000;
  4061. den = 1001;
  4062. } else if (strcmp(val, "25") == 0) {
  4063. num = 25;
  4064. den = 1;
  4065. } else if (strcmp(val, "29.97") == 0) {
  4066. num = 30000;
  4067. den = 1001;
  4068. } else if (strcmp(val, "48") == 0) {
  4069. num = 48;
  4070. den = 1;
  4071. } else if (strcmp(val, "59.94") == 0) {
  4072. num = 60000;
  4073. den = 1001;
  4074. } else if (strcmp(val, "60") == 0) {
  4075. num = 60;
  4076. den = 1;
  4077. } else {
  4078. num = 30;
  4079. den = 1;
  4080. }
  4081. }
  4082. void OBSBasic::GetFPSInteger(uint32_t &num, uint32_t &den) const
  4083. {
  4084. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSInt");
  4085. den = 1;
  4086. }
  4087. void OBSBasic::GetFPSFraction(uint32_t &num, uint32_t &den) const
  4088. {
  4089. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNum");
  4090. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSDen");
  4091. }
  4092. void OBSBasic::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
  4093. {
  4094. num = 1000000000;
  4095. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNS");
  4096. }
  4097. void OBSBasic::GetConfigFPS(uint32_t &num, uint32_t &den) const
  4098. {
  4099. uint32_t type = config_get_uint(basicConfig, "Video", "FPSType");
  4100. if (type == 1) //"Integer"
  4101. GetFPSInteger(num, den);
  4102. else if (type == 2) //"Fraction"
  4103. GetFPSFraction(num, den);
  4104. else if (false) //"Nanoseconds", currently not implemented
  4105. GetFPSNanoseconds(num, den);
  4106. else
  4107. GetFPSCommon(num, den);
  4108. }
  4109. config_t *OBSBasic::Config() const
  4110. {
  4111. return basicConfig;
  4112. }
  4113. void OBSBasic::on_actionEditTransform_triggered()
  4114. {
  4115. if (transformWindow)
  4116. transformWindow->close();
  4117. transformWindow = new OBSBasicTransform(this);
  4118. transformWindow->show();
  4119. transformWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  4120. }
  4121. static obs_transform_info copiedTransformInfo;
  4122. static obs_sceneitem_crop copiedCropInfo;
  4123. void OBSBasic::on_actionCopyTransform_triggered()
  4124. {
  4125. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4126. {
  4127. if (!obs_sceneitem_selected(item))
  4128. return true;
  4129. obs_sceneitem_defer_update_begin(item);
  4130. obs_sceneitem_get_info(item, &copiedTransformInfo);
  4131. obs_sceneitem_get_crop(item, &copiedCropInfo);
  4132. obs_sceneitem_defer_update_end(item);
  4133. UNUSED_PARAMETER(scene);
  4134. UNUSED_PARAMETER(param);
  4135. return true;
  4136. };
  4137. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4138. ui->actionPasteTransform->setEnabled(true);
  4139. }
  4140. void OBSBasic::on_actionPasteTransform_triggered()
  4141. {
  4142. auto func = [](obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4143. {
  4144. if (!obs_sceneitem_selected(item))
  4145. return true;
  4146. obs_sceneitem_defer_update_begin(item);
  4147. obs_sceneitem_set_info(item, &copiedTransformInfo);
  4148. obs_sceneitem_set_crop(item, &copiedCropInfo);
  4149. obs_sceneitem_defer_update_end(item);
  4150. UNUSED_PARAMETER(scene);
  4151. UNUSED_PARAMETER(param);
  4152. return true;
  4153. };
  4154. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4155. }
  4156. void OBSBasic::on_actionResetTransform_triggered()
  4157. {
  4158. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4159. {
  4160. if (!obs_sceneitem_selected(item))
  4161. return true;
  4162. obs_sceneitem_defer_update_begin(item);
  4163. obs_transform_info info;
  4164. vec2_set(&info.pos, 0.0f, 0.0f);
  4165. vec2_set(&info.scale, 1.0f, 1.0f);
  4166. info.rot = 0.0f;
  4167. info.alignment = OBS_ALIGN_TOP | OBS_ALIGN_LEFT;
  4168. info.bounds_type = OBS_BOUNDS_NONE;
  4169. info.bounds_alignment = OBS_ALIGN_CENTER;
  4170. vec2_set(&info.bounds, 0.0f, 0.0f);
  4171. obs_sceneitem_set_info(item, &info);
  4172. obs_sceneitem_crop crop = {};
  4173. obs_sceneitem_set_crop(item, &crop);
  4174. obs_sceneitem_defer_update_end(item);
  4175. UNUSED_PARAMETER(scene);
  4176. UNUSED_PARAMETER(param);
  4177. return true;
  4178. };
  4179. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4180. }
  4181. static void GetItemBox(obs_sceneitem_t *item, vec3 &tl, vec3 &br)
  4182. {
  4183. matrix4 boxTransform;
  4184. obs_sceneitem_get_box_transform(item, &boxTransform);
  4185. vec3_set(&tl, M_INFINITE, M_INFINITE, 0.0f);
  4186. vec3_set(&br, -M_INFINITE, -M_INFINITE, 0.0f);
  4187. auto GetMinPos = [&] (float x, float y)
  4188. {
  4189. vec3 pos;
  4190. vec3_set(&pos, x, y, 0.0f);
  4191. vec3_transform(&pos, &pos, &boxTransform);
  4192. vec3_min(&tl, &tl, &pos);
  4193. vec3_max(&br, &br, &pos);
  4194. };
  4195. GetMinPos(0.0f, 0.0f);
  4196. GetMinPos(1.0f, 0.0f);
  4197. GetMinPos(0.0f, 1.0f);
  4198. GetMinPos(1.0f, 1.0f);
  4199. }
  4200. static vec3 GetItemTL(obs_sceneitem_t *item)
  4201. {
  4202. vec3 tl, br;
  4203. GetItemBox(item, tl, br);
  4204. return tl;
  4205. }
  4206. static void SetItemTL(obs_sceneitem_t *item, const vec3 &tl)
  4207. {
  4208. vec3 newTL;
  4209. vec2 pos;
  4210. obs_sceneitem_get_pos(item, &pos);
  4211. newTL = GetItemTL(item);
  4212. pos.x += tl.x - newTL.x;
  4213. pos.y += tl.y - newTL.y;
  4214. obs_sceneitem_set_pos(item, &pos);
  4215. }
  4216. static bool RotateSelectedSources(obs_scene_t *scene, obs_sceneitem_t *item,
  4217. void *param)
  4218. {
  4219. if (!obs_sceneitem_selected(item))
  4220. return true;
  4221. float rot = *reinterpret_cast<float*>(param);
  4222. vec3 tl = GetItemTL(item);
  4223. rot += obs_sceneitem_get_rot(item);
  4224. if (rot >= 360.0f) rot -= 360.0f;
  4225. else if (rot <= -360.0f) rot += 360.0f;
  4226. obs_sceneitem_set_rot(item, rot);
  4227. SetItemTL(item, tl);
  4228. UNUSED_PARAMETER(scene);
  4229. UNUSED_PARAMETER(param);
  4230. return true;
  4231. };
  4232. void OBSBasic::on_actionRotate90CW_triggered()
  4233. {
  4234. float f90CW = 90.0f;
  4235. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CW);
  4236. }
  4237. void OBSBasic::on_actionRotate90CCW_triggered()
  4238. {
  4239. float f90CCW = -90.0f;
  4240. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CCW);
  4241. }
  4242. void OBSBasic::on_actionRotate180_triggered()
  4243. {
  4244. float f180 = 180.0f;
  4245. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f180);
  4246. }
  4247. static bool MultiplySelectedItemScale(obs_scene_t *scene, obs_sceneitem_t *item,
  4248. void *param)
  4249. {
  4250. vec2 &mul = *reinterpret_cast<vec2*>(param);
  4251. if (!obs_sceneitem_selected(item))
  4252. return true;
  4253. vec3 tl = GetItemTL(item);
  4254. vec2 scale;
  4255. obs_sceneitem_get_scale(item, &scale);
  4256. vec2_mul(&scale, &scale, &mul);
  4257. obs_sceneitem_set_scale(item, &scale);
  4258. SetItemTL(item, tl);
  4259. UNUSED_PARAMETER(scene);
  4260. return true;
  4261. }
  4262. void OBSBasic::on_actionFlipHorizontal_triggered()
  4263. {
  4264. vec2 scale;
  4265. vec2_set(&scale, -1.0f, 1.0f);
  4266. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4267. &scale);
  4268. }
  4269. void OBSBasic::on_actionFlipVertical_triggered()
  4270. {
  4271. vec2 scale;
  4272. vec2_set(&scale, 1.0f, -1.0f);
  4273. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  4274. &scale);
  4275. }
  4276. static bool CenterAlignSelectedItems(obs_scene_t *scene, obs_sceneitem_t *item,
  4277. void *param)
  4278. {
  4279. obs_bounds_type boundsType = *reinterpret_cast<obs_bounds_type*>(param);
  4280. if (!obs_sceneitem_selected(item))
  4281. return true;
  4282. obs_video_info ovi;
  4283. obs_get_video_info(&ovi);
  4284. obs_transform_info itemInfo;
  4285. vec2_set(&itemInfo.pos, 0.0f, 0.0f);
  4286. vec2_set(&itemInfo.scale, 1.0f, 1.0f);
  4287. itemInfo.alignment = OBS_ALIGN_LEFT | OBS_ALIGN_TOP;
  4288. itemInfo.rot = 0.0f;
  4289. vec2_set(&itemInfo.bounds,
  4290. float(ovi.base_width), float(ovi.base_height));
  4291. itemInfo.bounds_type = boundsType;
  4292. itemInfo.bounds_alignment = OBS_ALIGN_CENTER;
  4293. obs_sceneitem_set_info(item, &itemInfo);
  4294. UNUSED_PARAMETER(scene);
  4295. return true;
  4296. }
  4297. void OBSBasic::on_actionFitToScreen_triggered()
  4298. {
  4299. obs_bounds_type boundsType = OBS_BOUNDS_SCALE_INNER;
  4300. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4301. &boundsType);
  4302. }
  4303. void OBSBasic::on_actionStretchToScreen_triggered()
  4304. {
  4305. obs_bounds_type boundsType = OBS_BOUNDS_STRETCH;
  4306. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  4307. &boundsType);
  4308. }
  4309. void OBSBasic::on_actionCenterToScreen_triggered()
  4310. {
  4311. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  4312. {
  4313. vec3 tl, br, itemCenter, screenCenter, offset;
  4314. obs_video_info ovi;
  4315. if (!obs_sceneitem_selected(item))
  4316. return true;
  4317. obs_get_video_info(&ovi);
  4318. vec3_set(&screenCenter, float(ovi.base_width),
  4319. float(ovi.base_height), 0.0f);
  4320. vec3_mulf(&screenCenter, &screenCenter, 0.5f);
  4321. GetItemBox(item, tl, br);
  4322. vec3_sub(&itemCenter, &br, &tl);
  4323. vec3_mulf(&itemCenter, &itemCenter, 0.5f);
  4324. vec3_add(&itemCenter, &itemCenter, &tl);
  4325. vec3_sub(&offset, &screenCenter, &itemCenter);
  4326. vec3_add(&tl, &tl, &offset);
  4327. SetItemTL(item, tl);
  4328. UNUSED_PARAMETER(scene);
  4329. UNUSED_PARAMETER(param);
  4330. return true;
  4331. };
  4332. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  4333. }
  4334. void OBSBasic::EnablePreviewDisplay(bool enable)
  4335. {
  4336. obs_display_set_enabled(ui->preview->GetDisplay(), enable);
  4337. ui->preview->setVisible(enable);
  4338. ui->previewDisabledLabel->setVisible(!enable);
  4339. }
  4340. void OBSBasic::TogglePreview()
  4341. {
  4342. previewEnabled = !previewEnabled;
  4343. EnablePreviewDisplay(previewEnabled);
  4344. }
  4345. void OBSBasic::Nudge(int dist, MoveDir dir)
  4346. {
  4347. if (ui->preview->Locked())
  4348. return;
  4349. struct MoveInfo {
  4350. float dist;
  4351. MoveDir dir;
  4352. } info = {(float)dist, dir};
  4353. auto func = [] (obs_scene_t*, obs_sceneitem_t *item, void *param)
  4354. {
  4355. if (obs_sceneitem_locked(item))
  4356. return true;
  4357. MoveInfo *info = reinterpret_cast<MoveInfo*>(param);
  4358. struct vec2 dir;
  4359. struct vec2 pos;
  4360. vec2_set(&dir, 0.0f, 0.0f);
  4361. if (!obs_sceneitem_selected(item))
  4362. return true;
  4363. switch (info->dir) {
  4364. case MoveDir::Up: dir.y = -info->dist; break;
  4365. case MoveDir::Down: dir.y = info->dist; break;
  4366. case MoveDir::Left: dir.x = -info->dist; break;
  4367. case MoveDir::Right: dir.x = info->dist; break;
  4368. }
  4369. obs_sceneitem_get_pos(item, &pos);
  4370. vec2_add(&pos, &pos, &dir);
  4371. obs_sceneitem_set_pos(item, &pos);
  4372. return true;
  4373. };
  4374. obs_scene_enum_items(GetCurrentScene(), func, &info);
  4375. }
  4376. void OBSBasic::NudgeUp() {Nudge(1, MoveDir::Up);}
  4377. void OBSBasic::NudgeDown() {Nudge(1, MoveDir::Down);}
  4378. void OBSBasic::NudgeLeft() {Nudge(1, MoveDir::Left);}
  4379. void OBSBasic::NudgeRight() {Nudge(1, MoveDir::Right);}
  4380. OBSProjector *OBSBasic::OpenProjector(obs_source_t *source, int monitor,
  4381. QString title, ProjectorType type)
  4382. {
  4383. /* seriously? 10 monitors? */
  4384. if (monitor > 9 || monitor > QGuiApplication::screens().size() - 1)
  4385. return nullptr;
  4386. OBSProjector *projector = new OBSProjector(nullptr, source, monitor,
  4387. title, type);
  4388. if (monitor < 0) {
  4389. for (auto &projPtr : windowProjectors) {
  4390. if (!projPtr) {
  4391. projPtr = projector;
  4392. projector = nullptr;
  4393. }
  4394. }
  4395. if (projector)
  4396. windowProjectors.push_back(projector);
  4397. } else {
  4398. delete projectors[monitor];
  4399. projectors[monitor].clear();
  4400. projectors[monitor] = projector;
  4401. }
  4402. projector->Init();
  4403. return projector;
  4404. }
  4405. void OBSBasic::OpenStudioProgramProjector()
  4406. {
  4407. int monitor = sender()->property("monitor").toInt();
  4408. OpenProjector(nullptr, monitor, nullptr, ProjectorType::StudioProgram);
  4409. }
  4410. void OBSBasic::OpenPreviewProjector()
  4411. {
  4412. int monitor = sender()->property("monitor").toInt();
  4413. OpenProjector(nullptr, monitor, nullptr, ProjectorType::Preview);
  4414. }
  4415. void OBSBasic::OpenSourceProjector()
  4416. {
  4417. int monitor = sender()->property("monitor").toInt();
  4418. OBSSceneItem item = GetCurrentSceneItem();
  4419. if (!item)
  4420. return;
  4421. OpenProjector(obs_sceneitem_get_source(item), monitor, nullptr,
  4422. ProjectorType::Source);
  4423. }
  4424. void OBSBasic::OpenMultiviewProjector()
  4425. {
  4426. int monitor = sender()->property("monitor").toInt();
  4427. OpenProjector(nullptr, monitor, nullptr, ProjectorType::Multiview);
  4428. }
  4429. void OBSBasic::OpenSceneProjector()
  4430. {
  4431. int monitor = sender()->property("monitor").toInt();
  4432. OBSScene scene = GetCurrentScene();
  4433. if (!scene)
  4434. return;
  4435. OpenProjector(obs_scene_get_source(scene), monitor, nullptr,
  4436. ProjectorType::Scene);
  4437. }
  4438. void OBSBasic::OpenStudioProgramWindow()
  4439. {
  4440. OpenProjector(nullptr, -1, QTStr("StudioProgramWindow"),
  4441. ProjectorType::StudioProgram);
  4442. }
  4443. void OBSBasic::OpenPreviewWindow()
  4444. {
  4445. OpenProjector(nullptr, -1, QTStr("PreviewWindow"),
  4446. ProjectorType::Preview);
  4447. }
  4448. void OBSBasic::OpenSourceWindow()
  4449. {
  4450. OBSSceneItem item = GetCurrentSceneItem();
  4451. if (!item)
  4452. return;
  4453. OBSSource source = obs_sceneitem_get_source(item);
  4454. QString title = QString::fromUtf8(obs_source_get_name(source));
  4455. OpenProjector(obs_sceneitem_get_source(item), -1, title,
  4456. ProjectorType::Source);
  4457. }
  4458. void OBSBasic::OpenMultiviewWindow()
  4459. {
  4460. OpenProjector(nullptr, -1, QTStr("MultiviewWindowed"),
  4461. ProjectorType::Multiview);
  4462. }
  4463. void OBSBasic::OpenSceneWindow()
  4464. {
  4465. OBSScene scene = GetCurrentScene();
  4466. if (!scene)
  4467. return;
  4468. OBSSource source = obs_scene_get_source(scene);
  4469. QString title = QString::fromUtf8(obs_source_get_name(source));
  4470. OpenProjector(obs_scene_get_source(scene), -1, title,
  4471. ProjectorType::Scene);
  4472. }
  4473. void OBSBasic::OpenSavedProjectors()
  4474. {
  4475. bool projectorSave = config_get_bool(GetGlobalConfig(),
  4476. "BasicWindow", "SaveProjectors");
  4477. if (!projectorSave)
  4478. return;
  4479. for (SavedProjectorInfo *info : savedProjectorsArray) {
  4480. OBSProjector *projector = nullptr;
  4481. switch (info->type) {
  4482. case ProjectorType::Source:
  4483. case ProjectorType::Scene: {
  4484. OBSSource source = obs_get_source_by_name(
  4485. info->name.c_str());
  4486. if (!source)
  4487. continue;
  4488. QString title = nullptr;
  4489. if (info->monitor < 0)
  4490. title = QString::fromUtf8(
  4491. obs_source_get_name(source));
  4492. projector = OpenProjector(source, info->monitor, title,
  4493. info->type);
  4494. obs_source_release(source);
  4495. break;
  4496. }
  4497. case ProjectorType::Preview: {
  4498. projector = OpenProjector(nullptr, info->monitor,
  4499. QTStr("PreviewWindow"),
  4500. ProjectorType::Preview);
  4501. break;
  4502. }
  4503. case ProjectorType::StudioProgram: {
  4504. projector = OpenProjector(nullptr, info->monitor,
  4505. QTStr("StudioProgramWindow"),
  4506. ProjectorType::StudioProgram);
  4507. break;
  4508. }
  4509. case ProjectorType::Multiview: {
  4510. projector = OpenProjector(nullptr, info->monitor,
  4511. QTStr("MultiviewWindowed"),
  4512. ProjectorType::Multiview);
  4513. break;
  4514. }
  4515. }
  4516. if (!info->geometry.empty()) {
  4517. QByteArray byteArray = QByteArray::fromBase64(
  4518. QByteArray(info->geometry.c_str()));
  4519. projector->restoreGeometry(byteArray);
  4520. if (!WindowPositionValid(projector->normalGeometry())) {
  4521. QRect rect = App()->desktop()->geometry();
  4522. projector->setGeometry(QStyle::alignedRect(
  4523. Qt::LeftToRight,
  4524. Qt::AlignCenter, size(), rect));
  4525. }
  4526. }
  4527. }
  4528. }
  4529. void OBSBasic::on_actionFullscreenInterface_triggered()
  4530. {
  4531. if (!fullscreenInterface)
  4532. showFullScreen();
  4533. else
  4534. showNormal();
  4535. fullscreenInterface = !fullscreenInterface;
  4536. }
  4537. void OBSBasic::UpdateTitleBar()
  4538. {
  4539. stringstream name;
  4540. const char *profile = config_get_string(App()->GlobalConfig(),
  4541. "Basic", "Profile");
  4542. const char *sceneCollection = config_get_string(App()->GlobalConfig(),
  4543. "Basic", "SceneCollection");
  4544. name << "OBS ";
  4545. if (previewProgramMode)
  4546. name << "Studio ";
  4547. name << App()->GetVersionString();
  4548. if (App()->IsPortableMode())
  4549. name << " - Portable Mode";
  4550. name << " - " << Str("TitleBar.Profile") << ": " << profile;
  4551. name << " - " << Str("TitleBar.Scenes") << ": " << sceneCollection;
  4552. setWindowTitle(QT_UTF8(name.str().c_str()));
  4553. }
  4554. int OBSBasic::GetProfilePath(char *path, size_t size, const char *file) const
  4555. {
  4556. char profiles_path[512];
  4557. const char *profile = config_get_string(App()->GlobalConfig(),
  4558. "Basic", "ProfileDir");
  4559. int ret;
  4560. if (!profile)
  4561. return -1;
  4562. if (!path)
  4563. return -1;
  4564. if (!file)
  4565. file = "";
  4566. ret = GetConfigPath(profiles_path, 512, "obs-studio/basic/profiles");
  4567. if (ret <= 0)
  4568. return ret;
  4569. if (!*file)
  4570. return snprintf(path, size, "%s/%s", profiles_path, profile);
  4571. return snprintf(path, size, "%s/%s/%s", profiles_path, profile, file);
  4572. }
  4573. void OBSBasic::on_resetUI_triggered()
  4574. {
  4575. restoreState(startingDockLayout);
  4576. #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
  4577. int cx = width();
  4578. int cy = height();
  4579. int cx22_5 = cx * 225 / 1000;
  4580. int cx5 = cx * 5 / 100;
  4581. cy = cy * 225 / 1000;
  4582. int mixerSize = cx - (cx22_5 * 2 + cx5 * 2);
  4583. QList<QDockWidget*> docks {
  4584. ui->scenesDock,
  4585. ui->sourcesDock,
  4586. ui->mixerDock,
  4587. ui->transitionsDock,
  4588. ui->controlsDock
  4589. };
  4590. QList<int> sizes {
  4591. cx22_5,
  4592. cx22_5,
  4593. mixerSize,
  4594. cx5,
  4595. cx5
  4596. };
  4597. ui->scenesDock->setVisible(true);
  4598. ui->sourcesDock->setVisible(true);
  4599. ui->mixerDock->setVisible(true);
  4600. ui->transitionsDock->setVisible(true);
  4601. ui->controlsDock->setVisible(true);
  4602. resizeDocks(docks, {cy, cy, cy, cy, cy}, Qt::Vertical);
  4603. resizeDocks(docks, sizes, Qt::Horizontal);
  4604. #endif
  4605. }
  4606. void OBSBasic::on_lockUI_toggled(bool lock)
  4607. {
  4608. QDockWidget::DockWidgetFeatures features = lock
  4609. ? QDockWidget::NoDockWidgetFeatures
  4610. : QDockWidget::AllDockWidgetFeatures;
  4611. ui->scenesDock->setFeatures(features);
  4612. ui->sourcesDock->setFeatures(features);
  4613. ui->mixerDock->setFeatures(features);
  4614. ui->transitionsDock->setFeatures(features);
  4615. ui->controlsDock->setFeatures(features);
  4616. }
  4617. void OBSBasic::on_toggleListboxToolbars_toggled(bool visible)
  4618. {
  4619. ui->sourcesToolbar->setVisible(visible);
  4620. ui->scenesToolbar->setVisible(visible);
  4621. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  4622. "ShowListboxToolbars", visible);
  4623. }
  4624. void OBSBasic::on_toggleStatusBar_toggled(bool visible)
  4625. {
  4626. ui->statusbar->setVisible(visible);
  4627. config_set_bool(App()->GlobalConfig(), "BasicWindow",
  4628. "ShowStatusBar", visible);
  4629. }
  4630. void OBSBasic::on_actionLockPreview_triggered()
  4631. {
  4632. ui->preview->ToggleLocked();
  4633. ui->actionLockPreview->setChecked(ui->preview->Locked());
  4634. }
  4635. void OBSBasic::on_scalingMenu_aboutToShow()
  4636. {
  4637. obs_video_info ovi;
  4638. obs_get_video_info(&ovi);
  4639. QAction *action = ui->actionScaleCanvas;
  4640. QString text = QTStr("Basic.MainMenu.Edit.Scale.Canvas");
  4641. text = text.arg(QString::number(ovi.base_width),
  4642. QString::number(ovi.base_height));
  4643. action->setText(text);
  4644. action = ui->actionScaleOutput;
  4645. text = QTStr("Basic.MainMenu.Edit.Scale.Output");
  4646. text = text.arg(QString::number(ovi.output_width),
  4647. QString::number(ovi.output_height));
  4648. action->setText(text);
  4649. action->setVisible(!(ovi.output_width == ovi.base_width &&
  4650. ovi.output_height == ovi.base_height));
  4651. UpdatePreviewScalingMenu();
  4652. }
  4653. void OBSBasic::on_actionScaleWindow_triggered()
  4654. {
  4655. ui->preview->SetFixedScaling(false);
  4656. ui->preview->ResetScrollingOffset();
  4657. emit ui->preview->DisplayResized();
  4658. }
  4659. void OBSBasic::on_actionScaleCanvas_triggered()
  4660. {
  4661. ui->preview->SetFixedScaling(true);
  4662. ui->preview->SetScalingLevel(0);
  4663. emit ui->preview->DisplayResized();
  4664. }
  4665. void OBSBasic::on_actionScaleOutput_triggered()
  4666. {
  4667. obs_video_info ovi;
  4668. obs_get_video_info(&ovi);
  4669. ui->preview->SetFixedScaling(true);
  4670. float scalingAmount = float(ovi.output_width) / float(ovi.base_width);
  4671. // log base ZOOM_SENSITIVITY of x = log(x) / log(ZOOM_SENSITIVITY)
  4672. int32_t approxScalingLevel = int32_t(
  4673. round(log(scalingAmount) / log(ZOOM_SENSITIVITY)));
  4674. ui->preview->SetScalingLevel(approxScalingLevel);
  4675. ui->preview->SetScalingAmount(scalingAmount);
  4676. emit ui->preview->DisplayResized();
  4677. }
  4678. void OBSBasic::SetShowing(bool showing)
  4679. {
  4680. if (!showing && isVisible()) {
  4681. config_set_string(App()->GlobalConfig(),
  4682. "BasicWindow", "geometry",
  4683. saveGeometry().toBase64().constData());
  4684. /* hide all visible child dialogs */
  4685. visDlgPositions.clear();
  4686. if (!visDialogs.isEmpty()) {
  4687. for (QDialog *dlg : visDialogs) {
  4688. visDlgPositions.append(dlg->pos());
  4689. dlg->hide();
  4690. }
  4691. }
  4692. if (showHide)
  4693. showHide->setText(QTStr("Basic.SystemTray.Show"));
  4694. QTimer::singleShot(250, this, SLOT(hide()));
  4695. if (previewEnabled)
  4696. EnablePreviewDisplay(false);
  4697. setVisible(false);
  4698. } else if (showing && !isVisible()) {
  4699. if (showHide)
  4700. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  4701. QTimer::singleShot(250, this, SLOT(show()));
  4702. if (previewEnabled)
  4703. EnablePreviewDisplay(true);
  4704. setVisible(true);
  4705. /* show all child dialogs that was visible earlier */
  4706. if (!visDialogs.isEmpty()) {
  4707. for (int i = 0; i < visDialogs.size(); ++i) {
  4708. QDialog *dlg = visDialogs[i];
  4709. dlg->move(visDlgPositions[i]);
  4710. dlg->show();
  4711. }
  4712. }
  4713. /* Unminimize window if it was hidden to tray instead of task
  4714. * bar. */
  4715. if (sysTrayMinimizeToTray()) {
  4716. Qt::WindowStates state;
  4717. state = windowState() & ~Qt::WindowMinimized;
  4718. state |= Qt::WindowActive;
  4719. setWindowState(state);
  4720. }
  4721. }
  4722. }
  4723. void OBSBasic::ToggleShowHide()
  4724. {
  4725. bool showing = isVisible();
  4726. if (showing) {
  4727. /* check for modal dialogs */
  4728. EnumDialogs();
  4729. if (!modalDialogs.isEmpty() || !visMsgBoxes.isEmpty())
  4730. return;
  4731. }
  4732. SetShowing(!showing);
  4733. }
  4734. void OBSBasic::SystemTrayInit()
  4735. {
  4736. trayIcon = new QSystemTrayIcon(QIcon(":/res/images/obs.png"),
  4737. this);
  4738. trayIcon->setToolTip("OBS Studio");
  4739. showHide = new QAction(QTStr("Basic.SystemTray.Show"),
  4740. trayIcon);
  4741. sysTrayStream = new QAction(QTStr("Basic.Main.StartStreaming"),
  4742. trayIcon);
  4743. sysTrayRecord = new QAction(QTStr("Basic.Main.StartRecording"),
  4744. trayIcon);
  4745. sysTrayReplayBuffer = new QAction(QTStr("Basic.Main.StartReplayBuffer"),
  4746. trayIcon);
  4747. exit = new QAction(QTStr("Exit"),
  4748. trayIcon);
  4749. if (outputHandler && !outputHandler->replayBuffer)
  4750. sysTrayReplayBuffer->setEnabled(false);
  4751. connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
  4752. this,
  4753. SLOT(IconActivated(QSystemTrayIcon::ActivationReason)));
  4754. connect(showHide, SIGNAL(triggered()),
  4755. this, SLOT(ToggleShowHide()));
  4756. connect(sysTrayStream, SIGNAL(triggered()),
  4757. this, SLOT(on_streamButton_clicked()));
  4758. connect(sysTrayRecord, SIGNAL(triggered()),
  4759. this, SLOT(on_recordButton_clicked()));
  4760. connect(sysTrayReplayBuffer.data(), &QAction::triggered,
  4761. this, &OBSBasic::ReplayBufferClicked);
  4762. connect(exit, SIGNAL(triggered()),
  4763. this, SLOT(close()));
  4764. trayMenu = new QMenu;
  4765. }
  4766. void OBSBasic::IconActivated(QSystemTrayIcon::ActivationReason reason)
  4767. {
  4768. if (reason == QSystemTrayIcon::Trigger) {
  4769. ToggleShowHide();
  4770. } else if (reason == QSystemTrayIcon::Context) {
  4771. QMenu *previewProjector = new QMenu(QTStr("PreviewProjector"));
  4772. AddProjectorMenuMonitors(previewProjector, this,
  4773. SLOT(OpenPreviewProjector()));
  4774. QMenu *studioProgramProjector = new QMenu(
  4775. QTStr("StudioProgramProjector"));
  4776. AddProjectorMenuMonitors(studioProgramProjector, this,
  4777. SLOT(OpenStudioProgramProjector()));
  4778. trayMenu->clear();
  4779. trayMenu->addAction(showHide);
  4780. trayMenu->addMenu(previewProjector);
  4781. trayMenu->addMenu(studioProgramProjector);
  4782. trayMenu->addAction(sysTrayStream);
  4783. trayMenu->addAction(sysTrayRecord);
  4784. trayMenu->addAction(sysTrayReplayBuffer);
  4785. trayMenu->addAction(exit);
  4786. trayMenu->popup(QCursor::pos());
  4787. }
  4788. }
  4789. void OBSBasic::SysTrayNotify(const QString &text,
  4790. QSystemTrayIcon::MessageIcon n)
  4791. {
  4792. if (QSystemTrayIcon::supportsMessages()) {
  4793. QSystemTrayIcon::MessageIcon icon =
  4794. QSystemTrayIcon::MessageIcon(n);
  4795. trayIcon->showMessage("OBS Studio", text, icon, 10000);
  4796. }
  4797. }
  4798. void OBSBasic::SystemTray(bool firstStarted)
  4799. {
  4800. if (!QSystemTrayIcon::isSystemTrayAvailable())
  4801. return;
  4802. bool sysTrayWhenStarted = config_get_bool(GetGlobalConfig(),
  4803. "BasicWindow", "SysTrayWhenStarted");
  4804. bool sysTrayEnabled = config_get_bool(GetGlobalConfig(),
  4805. "BasicWindow", "SysTrayEnabled");
  4806. if (firstStarted)
  4807. SystemTrayInit();
  4808. if (!sysTrayWhenStarted && !sysTrayEnabled) {
  4809. trayIcon->hide();
  4810. } else if ((sysTrayWhenStarted && sysTrayEnabled)
  4811. || opt_minimize_tray) {
  4812. trayIcon->show();
  4813. if (firstStarted) {
  4814. QTimer::singleShot(50, this, SLOT(hide()));
  4815. EnablePreviewDisplay(false);
  4816. setVisible(false);
  4817. opt_minimize_tray = false;
  4818. }
  4819. } else if (sysTrayEnabled) {
  4820. trayIcon->show();
  4821. } else if (!sysTrayEnabled) {
  4822. trayIcon->hide();
  4823. } else if (!sysTrayWhenStarted && sysTrayEnabled) {
  4824. trayIcon->hide();
  4825. }
  4826. if (isVisible())
  4827. showHide->setText(QTStr("Basic.SystemTray.Hide"));
  4828. else
  4829. showHide->setText(QTStr("Basic.SystemTray.Show"));
  4830. }
  4831. bool OBSBasic::sysTrayMinimizeToTray()
  4832. {
  4833. return config_get_bool(GetGlobalConfig(),
  4834. "BasicWindow", "SysTrayMinimizeToTray");
  4835. }
  4836. void OBSBasic::on_actionCopySource_triggered()
  4837. {
  4838. on_actionCopyTransform_triggered();
  4839. OBSSceneItem item = GetCurrentSceneItem();
  4840. if (!item)
  4841. return;
  4842. OBSSource source = obs_sceneitem_get_source(item);
  4843. copyString = obs_source_get_name(source);
  4844. copyVisible = obs_sceneitem_visible(item);
  4845. ui->actionPasteRef->setEnabled(true);
  4846. uint32_t output_flags = obs_source_get_output_flags(source);
  4847. if ((output_flags & OBS_SOURCE_DO_NOT_DUPLICATE) == 0)
  4848. ui->actionPasteDup->setEnabled(true);
  4849. else
  4850. ui->actionPasteDup->setEnabled(false);
  4851. }
  4852. void OBSBasic::on_actionPasteRef_triggered()
  4853. {
  4854. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, false);
  4855. on_actionPasteTransform_triggered();
  4856. }
  4857. void OBSBasic::on_actionPasteDup_triggered()
  4858. {
  4859. OBSBasicSourceSelect::SourcePaste(copyString, copyVisible, true);
  4860. on_actionPasteTransform_triggered();
  4861. }
  4862. void OBSBasic::on_actionCopyFilters_triggered()
  4863. {
  4864. OBSSceneItem item = GetCurrentSceneItem();
  4865. if (!item)
  4866. return;
  4867. OBSSource source = obs_sceneitem_get_source(item);
  4868. copyFiltersString = obs_source_get_name(source);
  4869. ui->actionPasteFilters->setEnabled(true);
  4870. }
  4871. void OBSBasic::on_actionPasteFilters_triggered()
  4872. {
  4873. OBSSource source = obs_get_source_by_name(copyFiltersString);
  4874. obs_source_release(source);
  4875. OBSSceneItem sceneItem = GetCurrentSceneItem();
  4876. OBSSource dstSource = obs_sceneitem_get_source(sceneItem);
  4877. if (source == dstSource)
  4878. return;
  4879. obs_source_copy_filters(dstSource, source);
  4880. }
  4881. void OBSBasic::on_autoConfigure_triggered()
  4882. {
  4883. AutoConfig test(this);
  4884. test.setModal(true);
  4885. test.show();
  4886. test.exec();
  4887. }
  4888. void OBSBasic::on_stats_triggered()
  4889. {
  4890. if (!stats.isNull()) {
  4891. stats->show();
  4892. stats->raise();
  4893. return;
  4894. }
  4895. OBSBasicStats *statsDlg;
  4896. statsDlg = new OBSBasicStats(nullptr);
  4897. statsDlg->show();
  4898. stats = statsDlg;
  4899. }