├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── copyFiles.bat ├── copyReleaseFiles.bat ├── data └── locale │ ├── en-US.ini │ └── sv-SE.ini ├── external └── FindLibObs.cmake ├── makeDebugDist.bat ├── makeDist.bat ├── src ├── capture-internals.h ├── getHWND.c ├── getHWND.h ├── monitor.c ├── properties.c ├── setup.c ├── signals.c ├── tick.c └── window-follower.h └── troubleshooting.md /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /debug64 3 | /debug32 4 | /dist 5 | /distDebug -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | project(window-follower) 3 | 4 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 5 | set(CMAKE_AUTOMOC ON) 6 | set(CMAKE_AUTOUIC ON) 7 | 8 | find_package(LibObs REQUIRED) 9 | 10 | set(PLUGIN_SOURCES 11 | src/getHWND.c 12 | src/setup.c 13 | src/tick.c 14 | src/properties.c 15 | src/monitor.c 16 | src/signals.c 17 | ) 18 | 19 | set(PLUGIN_HEADERS 20 | src/capture-internals.h 21 | src/getHWND.h 22 | src/window-follower.h 23 | ) 24 | 25 | include_directories( 26 | "${LIBOBS_INCLUDE_DIR}/../UI/obs-frontend-api" 27 | "${LIBOBS_INCLUDE_DIR}/../deps/ipc-util" 28 | "${LIBOBS_INCLUDE_DIR}/../deps/libcaption") 29 | 30 | # --- Platform-independent build settings --- 31 | add_library(window-follower MODULE 32 | ${PLUGIN_SOURCES} 33 | ${PLUGIN_HEADERS}) 34 | 35 | 36 | target_link_libraries(window-follower 37 | libobs) 38 | 39 | # --- End of section --- 40 | 41 | # --- Windows-specific build settings and tasks --- 42 | if(WIN32) 43 | if(NOT DEFINED OBS_FRONTEND_LIB) 44 | set(OBS_FRONTEND_LIB "OBS_FRONTEND_LIB-NOTFOUND" CACHE FILEPATH "OBS frontend library") 45 | message(FATAL_ERROR "Could not find OBS Frontend API\'s library !") 46 | endif() 47 | 48 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 49 | set(ARCH_NAME "64bit") 50 | set(OBS_BUILDDIR_ARCH "build64") 51 | else() 52 | set(ARCH_NAME "32bit") 53 | set(OBS_BUILDDIR_ARCH "build32") 54 | endif() 55 | 56 | include_directories( 57 | "${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/UI" 58 | ) 59 | 60 | target_link_libraries(window-follower 61 | "${OBS_FRONTEND_LIB}") 62 | 63 | # --- Release package helper --- 64 | # The "release" folder has a structure similar OBS' one on Windows 65 | set(RELEASE_DIR "${PROJECT_SOURCE_DIR}/release") 66 | 67 | add_custom_command(TARGET window-follower POST_BUILD 68 | COMMAND if $==1 ( 69 | "${CMAKE_COMMAND}" -E make_directory 70 | "${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}" 71 | "${RELEASE_DIR}/obs-plugins/${ARCH_NAME}") 72 | 73 | COMMAND if $==1 ("${CMAKE_COMMAND}" -E copy_directory 74 | "${PROJECT_SOURCE_DIR}/data" 75 | "${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}") 76 | 77 | COMMAND if $==1 ("${CMAKE_COMMAND}" -E copy 78 | "$" 79 | "${RELEASE_DIR}/obs-plugins/${ARCH_NAME}") 80 | 81 | # Copy to obs-studio dev environment for immediate testing 82 | COMMAND if $==1 ( 83 | "${CMAKE_COMMAND}" -E copy 84 | "$" 85 | "${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$/obs-plugins/${ARCH_NAME}") 86 | 87 | COMMAND if $==1 ( 88 | "${CMAKE_COMMAND}" -E make_directory 89 | "${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$/data/obs-plugins/${CMAKE_PROJECT_NAME}") 90 | 91 | COMMAND if $==1 ( 92 | "${CMAKE_COMMAND}" -E copy_directory 93 | "${PROJECT_SOURCE_DIR}/data" 94 | "${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$/data/obs-plugins/${CMAKE_PROJECT_NAME}") 95 | ) 96 | # --- End of sub-section --- 97 | 98 | endif() 99 | # --- End of section --- 100 | 101 | # --- Linux-specific build settings and tasks --- 102 | if(UNIX AND NOT APPLE) 103 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 104 | 105 | set_target_properties(window-follower PROPERTIES PREFIX "") 106 | target_link_libraries(window-follower 107 | obs-frontend-api) 108 | 109 | file(GLOB locale_files data/locale/*.ini) 110 | 111 | install(TARGETS window-follower 112 | LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/obs-plugins") 113 | install(FILES ${locale_files} 114 | DESTINATION "${CMAKE_INSTALL_PREFIX}/share/obs/obs-plugins/${CMAKE_PROJECT_NAME}/locale") 115 | endif() 116 | # --- End of section --- 117 | 118 | # -- OS X specific build settings and tasks -- 119 | if(APPLE) 120 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -fvisibility=default") 121 | 122 | set_target_properties(window-follower PROPERTIES PREFIX "") 123 | target_link_libraries(window-follower "${OBS_FRONTEND_LIB}") 124 | endif() 125 | # -- End of section -- 126 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # window-follower 2 | OBS plugin that makes scene items follow the movement of the window the source is capturing from 3 | 4 | ## Usage 5 | Add the plugin to the scene with the scene item that you want to work with. Set the scene item to work with. 6 | 7 | ## Additional options 8 | * Stay in bounds: Ensures that the scene item doesn't leave the scene if the window moves out of bounds. 9 | * Scale mode: How to translate window coordinates to scene coordinates. Only really matters in multimonitor setups. 10 | * Monitor: The monitor to use when in monitor to scene scale mode. 11 | 12 | ## Limitations 13 | * The scene item should not be rotated or skewed. 14 | 15 | ## Build 16 | ### Windows 17 | First follow build procedures for [obs-studio](https://github.com/obsproject/obs-studio/wiki/install-instructions#windows-build-directions). 18 | 19 | - Building obs-studio will produce an `obs.lib` file, generated inside the build directories - e.g. `obs-studio/build/libobs/debug/obs.lib` 20 | 21 | - Assuming you have cmake, prior to first configure, add the following entries: 22 | 23 | | Entry name | Type | Value (e.g.) | 24 | |--------------------|----------|------------------------------------------------------| 25 | | LIBOBS_LIB | FILEPATH | /obs-studio/path/to/obs.lib | 26 | | LIBOBS_INCLUDE_DIR | PATH | /obs-studio/libobs | 27 | | OBS_FRONTEND_LIB | FILEPATH | /obs-studio/UI/obs-frontend-api/obs-frontend-api.lib | 28 | 29 | - Click 'Configure', which will run 30 | - Click 'Generate' 31 | 32 | This should produce the desired development environment, which after building, shall produce the plugin dll file. 33 | -------------------------------------------------------------------------------- /copyFiles.bat: -------------------------------------------------------------------------------- 1 | copy Debug64\Debug\*.dll ..\obs-studio\debug64\rundir\Debug\obs-plugins\64bit 2 | copy Debug64\Debug\*.pdb ..\obs-studio\debug64\rundir\Debug\obs-plugins\64bit 3 | copy Debug32\Debug\*.dll ..\obs-studio\debug32\rundir\Debug\obs-plugins\32bit 4 | copy Debug32\Debug\*.pdb ..\obs-studio\debug32\rundir\Debug\obs-plugins\32bit 5 | 6 | copy data\locale\*.ini ..\obs-studio\debug64\rundir\Debug\data\obs-plugins\window-follower\locale 7 | copy data\locale\*.ini ..\obs-studio\debug32\rundir\Debug\data\obs-plugins\window-follower\locale 8 | 9 | pause -------------------------------------------------------------------------------- /copyReleaseFiles.bat: -------------------------------------------------------------------------------- 1 | copy Debug64\Release\*.dll ..\obs-studio\debug64\rundir\Release\obs-plugins\64bit 2 | rem copy Debug64\Release\*.pdb ..\obs-studio\debug64\rundir\Release\obs-plugins\64bit 3 | copy Debug32\Release\*.dll ..\obs-studio\debug32\rundir\Release\obs-plugins\32bit 4 | rem copy Debug32\Release\*.pdb ..\obs-studio\debug32\rundir\Release\obs-plugins\32bit 5 | 6 | copy data\locale\*.ini ..\obs-studio\debug64\rundir\Release\data\obs-plugins\window-follower\locale 7 | copy data\locale\*.ini ..\obs-studio\debug32\rundir\Release\data\obs-plugins\window-follower\locale 8 | 9 | pause -------------------------------------------------------------------------------- /data/locale/en-US.ini: -------------------------------------------------------------------------------- 1 | WindowFollower="Window follower" 2 | SourceId="Source" 3 | SourceId.LongDesc="The source item to move" 4 | SourceId.None="None" 5 | ScalePos="Positions scaling" 6 | ScalePos.LongDesc="How the window position is mapped to the position of the scene item" 7 | ScalePos.None="No scaling" 8 | ScalePos.MonitorToScene="Monitor to scene" 9 | ScalePos.DesktopToScene="Desktop to scene" 10 | StayInBounds="Stay in bounds" 11 | StayInBounds.LongDesc="Keep the entire scene item fully within the set boundraries." 12 | Monitor="Monitor" 13 | Monitor.LongDesc="Monitor to scale from" 14 | Bounds.Group="Bounds" 15 | Bounds.Left="Left" 16 | Bounds.Left.LongDesc="The left edge of the area that the scene item moves in." 17 | Bounds.Top="Top" 18 | Bounds.Top.LongDesc="The top edge of the area that the scene item moves in." 19 | Bounds.Width="Width" 20 | Bounds.Width.LongDesc="The width of the area that the scene item moves in." 21 | Bounds.Height="Height" 22 | Bounds.Height.LongDesc="The height of the area that the scene item moves in." 23 | HideMinimized="Hide if minimized" -------------------------------------------------------------------------------- /data/locale/sv-SE.ini: -------------------------------------------------------------------------------- 1 | WindowFollower="Fönsterföljare" 2 | SourceId="Källa" 3 | SourceId.LongDesc="Scenobjektet att flytta" 4 | SourceId.None="Ingen" 5 | ScalePos="Positionsskalning" 6 | ScalePos.LongDesc="Hur fönsterpositionen ska mappas till scenobjektets position" 7 | ScalePos.None="Ingen skalning" 8 | ScalePos.MonitorToScene="Skärm till scen" 9 | ScalePos.DesktopToScene="Skrivbord till scen" 10 | StayInBounds="Stanna inom gränserna" 11 | StayInBounds.LongDesc="Håll hela scenobjektet helt inom de satta gränserna" 12 | Monitor="Skärm" 13 | Monitor.LongDesc="Skärm att skala från" 14 | Bounds.Group="Gränser" 15 | Bounds.Left="Vänster" 16 | Bounds.Left.LongDesc="Den vänstra gränsen för området som scenobjektet rör sig i." 17 | Bounds.Top="Topp" 18 | Bounds.Top.LongDesc="Den övre gränsen för området som scenobjektet rör sig i." 19 | Bounds.Width="Bredd" 20 | Bounds.Width.LongDesc="Bredden på området scenobjektet rör sig i." 21 | Bounds.Height="Höjd" 22 | Bounds.Height.LongDesc="Höjden på området scenobjektet rör sig i." 23 | HideMinimized="Dölj om minimerad" -------------------------------------------------------------------------------- /external/FindLibObs.cmake: -------------------------------------------------------------------------------- 1 | # This module can be copied and used by external plugins for OBS 2 | # 3 | # Once done these will be defined: 4 | # 5 | # LIBOBS_FOUND 6 | # LIBOBS_INCLUDE_DIRS 7 | # LIBOBS_LIBRARIES 8 | 9 | find_package(PkgConfig QUIET) 10 | if (PKG_CONFIG_FOUND) 11 | pkg_check_modules(_OBS QUIET obs libobs) 12 | endif() 13 | 14 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 15 | set(_lib_suffix 64) 16 | else() 17 | set(_lib_suffix 32) 18 | endif() 19 | 20 | if(DEFINED CMAKE_BUILD_TYPE) 21 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 22 | set(_build_type_base "debug") 23 | else() 24 | set(_build_type_base "release") 25 | endif() 26 | endif() 27 | 28 | find_path(LIBOBS_INCLUDE_DIR 29 | NAMES obs.h 30 | HINTS 31 | ENV obsPath${_lib_suffix} 32 | ENV obsPath 33 | ${obsPath} 34 | PATHS 35 | /usr/include /usr/local/include /opt/local/include /sw/include 36 | PATH_SUFFIXES 37 | libobs 38 | ) 39 | 40 | function(find_obs_lib base_name repo_build_path lib_name) 41 | string(TOUPPER "${base_name}" base_name_u) 42 | 43 | if(DEFINED _build_type_base) 44 | set(_build_type_${repo_build_path} "${_build_type_base}/${repo_build_path}") 45 | set(_build_type_${repo_build_path}${_lib_suffix} "${_build_type_base}${_lib_suffix}/${repo_build_path}") 46 | endif() 47 | 48 | find_library(${base_name_u}_LIB 49 | NAMES ${_${base_name_u}_LIBRARIES} ${lib_name} lib${lib_name} 50 | HINTS 51 | ENV obsPath${_lib_suffix} 52 | ENV obsPath 53 | ${obsPath} 54 | ${_${base_name_u}_LIBRARY_DIRS} 55 | PATHS 56 | /usr/lib /usr/local/lib /opt/local/lib /sw/lib 57 | PATH_SUFFIXES 58 | lib${_lib_suffix} lib 59 | libs${_lib_suffix} libs 60 | bin${_lib_suffix} bin 61 | ../lib${_lib_suffix} ../lib 62 | ../libs${_lib_suffix} ../libs 63 | ../bin${_lib_suffix} ../bin 64 | # base repo non-msvc-specific search paths 65 | ${_build_type_${repo_build_path}} 66 | ${_build_type_${repo_build_path}${_lib_suffix}} 67 | build/${repo_build_path} 68 | build${_lib_suffix}/${repo_build_path} 69 | # base repo msvc-specific search paths on windows 70 | build${_lib_suffix}/${repo_build_path}/Debug 71 | build${_lib_suffix}/${repo_build_path}/RelWithDebInfo 72 | build/${repo_build_path}/Debug 73 | build/${repo_build_path}/RelWithDebInfo 74 | ) 75 | endfunction() 76 | 77 | find_obs_lib(LIBOBS libobs obs) 78 | 79 | if(MSVC) 80 | find_obs_lib(W32_PTHREADS deps/w32-pthreads w32-pthreads) 81 | endif() 82 | 83 | include(FindPackageHandleStandardArgs) 84 | find_package_handle_standard_args(Libobs DEFAULT_MSG LIBOBS_LIB LIBOBS_INCLUDE_DIR) 85 | mark_as_advanced(LIBOBS_INCLUDE_DIR LIBOBS_LIB) 86 | 87 | if(LIBOBS_FOUND) 88 | if(MSVC) 89 | if (NOT DEFINED W32_PTHREADS_LIB) 90 | message(FATAL_ERROR "Could not find the w32-pthreads library" ) 91 | endif() 92 | 93 | set(W32_PTHREADS_INCLUDE_DIR ${LIBOBS_INCLUDE_DIR}/../deps/w32-pthreads) 94 | endif() 95 | 96 | set(LIBOBS_INCLUDE_DIRS ${LIBOBS_INCLUDE_DIR} ${W32_PTHREADS_INCLUDE_DIR}) 97 | set(LIBOBS_LIBRARIES ${LIBOBS_LIB} ${W32_PTHREADS_LIB}) 98 | include(${LIBOBS_INCLUDE_DIR}/../cmake/external/ObsPluginHelpers.cmake) 99 | 100 | # allows external plugins to easily use/share common dependencies that are often included with libobs (such as FFmpeg) 101 | if(NOT DEFINED INCLUDED_LIBOBS_CMAKE_MODULES) 102 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LIBOBS_INCLUDE_DIR}/../cmake/Modules/") 103 | set(INCLUDED_LIBOBS_CMAKE_MODULES true) 104 | endif() 105 | else() 106 | message(FATAL_ERROR "Could not find the libobs library" ) 107 | endif() 108 | -------------------------------------------------------------------------------- /makeDebugDist.bat: -------------------------------------------------------------------------------- 1 | copy Debug64\Debug\*.dll distDebug\obs-plugins\64bit 2 | copy Debug64\Debug\*.pdb distDebug\obs-plugins\64bit 3 | copy Debug32\Debug\*.dll distDebug\obs-plugins\32bit 4 | copy Debug32\Debug\*.pdb distDebug\obs-plugins\32bit 5 | 6 | copy data\locale\*.ini distDebug\data\obs-plugins\window-follower\locale 7 | 8 | pause -------------------------------------------------------------------------------- /makeDist.bat: -------------------------------------------------------------------------------- 1 | copy Debug64\Release\*.dll dist\obs-plugins\64bit 2 | rem copy Debug64\Release\*.pdb dist\obs-plugins\64bit 3 | copy Debug32\Release\*.dll dist\obs-plugins\32bit 4 | rem copy Debug32\Release\*.pdb dist\obs-plugins\32bit 5 | 6 | copy data\locale\*.ini dist\data\obs-plugins\window-follower\locale 7 | 8 | pause -------------------------------------------------------------------------------- /src/capture-internals.h: -------------------------------------------------------------------------------- 1 | #ifndef CAPTURE_INTERNALS_H 2 | #define CAPTURE_INTERNALS_H 3 | 4 | #include 5 | #include 6 | 7 | #define WIN32_LEAN_AND_MEAN 8 | #include 9 | #include 10 | #include 11 | 12 | struct dc_capture { 13 | gs_texture_t *texture; 14 | bool texture_written; 15 | int x, y; 16 | uint32_t width; 17 | uint32_t height; 18 | 19 | bool compatibility; 20 | HDC hdc; 21 | HBITMAP bmp, old_bmp; 22 | BYTE *bits; 23 | 24 | bool capture_cursor; 25 | bool cursor_captured; 26 | bool cursor_hidden; 27 | CURSORINFO ci; 28 | 29 | bool valid; 30 | }; 31 | 32 | struct winrt_exports { 33 | BOOL *(*winrt_capture_supported)(); 34 | struct winrt_capture *(*winrt_capture_init)(BOOL cursor, HWND window, 35 | BOOL client_area); 36 | void (*winrt_capture_free)(struct winrt_capture *capture); 37 | void (*winrt_capture_render)(struct winrt_capture *capture, 38 | gs_effect_t *effect); 39 | uint32_t(*winrt_capture_width)(const struct winrt_capture *capture); 40 | uint32_t(*winrt_capture_height)(const struct winrt_capture *capture); 41 | }; 42 | 43 | enum window_capture_method { 44 | METHOD_AUTO, 45 | METHOD_BITBLT, 46 | METHOD_WGC, 47 | }; 48 | 49 | struct window_capture { 50 | obs_source_t *source; 51 | 52 | char *title; 53 | char *class; 54 | char *executable; 55 | enum window_capture_method method; 56 | enum window_priority priority; 57 | bool cursor; 58 | bool compatibility; 59 | bool client_area; 60 | bool use_wildcards; /* TODO */ 61 | 62 | struct dc_capture capture; 63 | 64 | bool wgc_supported; 65 | void *winrt_module; 66 | struct winrt_exports exports; 67 | struct winrt_capture *capture_winrt; 68 | 69 | float resize_timer; 70 | float check_window_timer; 71 | float cursor_check_time; 72 | 73 | HWND window; 74 | RECT last_rect; 75 | }; 76 | 77 | struct cached_cursor { 78 | gs_texture_t *texture; 79 | uint32_t cx; 80 | uint32_t cy; 81 | }; 82 | 83 | struct cursor_data { 84 | gs_texture_t *texture; 85 | HCURSOR current_cursor; 86 | POINT cursor_pos; 87 | long x_hotspot; 88 | long y_hotspot; 89 | bool visible; 90 | 91 | uint32_t last_cx; 92 | uint32_t last_cy; 93 | 94 | DARRAY(struct cached_cursor) cached_textures; 95 | }; 96 | 97 | 98 | enum capture_mode { 99 | CAPTURE_MODE_ANY, 100 | CAPTURE_MODE_WINDOW, 101 | CAPTURE_MODE_HOTKEY 102 | }; 103 | 104 | enum hook_rate { 105 | HOOK_RATE_SLOW, 106 | HOOK_RATE_NORMAL, 107 | HOOK_RATE_FAST, 108 | HOOK_RATE_FASTEST 109 | }; 110 | 111 | struct game_capture_config { 112 | char *title; 113 | char *class; 114 | char *executable; 115 | enum window_priority priority; 116 | enum capture_mode mode; 117 | uint32_t scale_cx; 118 | uint32_t scale_cy; 119 | bool cursor; 120 | bool force_shmem; 121 | bool force_scaling; 122 | bool allow_transparency; 123 | bool limit_framerate; 124 | bool capture_overlays; 125 | bool anticheat_hook; 126 | enum hook_rate hook_rate; 127 | }; 128 | 129 | struct game_capture { 130 | obs_source_t *source; 131 | 132 | struct cursor_data cursor_data; 133 | HANDLE injector_process; 134 | uint32_t cx; 135 | uint32_t cy; 136 | uint32_t pitch; 137 | DWORD process_id; 138 | DWORD thread_id; 139 | HWND next_window; 140 | HWND window; 141 | float retry_time; 142 | float fps_reset_time; 143 | float retry_interval; 144 | struct dstr title; 145 | struct dstr class; 146 | struct dstr executable; 147 | enum window_priority priority; 148 | obs_hotkey_pair_id hotkey_pair; 149 | volatile long hotkey_window; 150 | volatile bool deactivate_hook; 151 | volatile bool activate_hook_now; 152 | bool wait_for_target_startup; 153 | bool showing; 154 | bool active; 155 | bool capturing; 156 | bool activate_hook; 157 | bool process_is_64bit; 158 | bool error_acquiring; 159 | bool dwm_capture; 160 | bool initial_config; 161 | bool convert_16bit; 162 | bool is_app; 163 | bool cursor_hidden; 164 | 165 | struct game_capture_config config; 166 | 167 | ipc_pipe_server_t pipe; 168 | gs_texture_t *texture; 169 | struct hook_info *global_hook_info; 170 | HANDLE keepalive_mutex; 171 | HANDLE hook_init; 172 | HANDLE hook_restart; 173 | HANDLE hook_stop; 174 | HANDLE hook_ready; 175 | HANDLE hook_exit; 176 | HANDLE hook_data_map; 177 | HANDLE global_hook_info_map; 178 | HANDLE target_process; 179 | HANDLE texture_mutexes[2]; 180 | wchar_t *app_sid; 181 | int retrying; 182 | float cursor_check_time; 183 | 184 | union { 185 | struct { 186 | struct shmem_data *shmem_data; 187 | uint8_t *texture_buffers[2]; 188 | }; 189 | 190 | struct shtex_data *shtex_data; 191 | void *data; 192 | }; 193 | 194 | void (*copy_texture)(struct game_capture *); 195 | }; 196 | 197 | #endif -------------------------------------------------------------------------------- /src/getHWND.c: -------------------------------------------------------------------------------- 1 | #include "getHWND.h" 2 | #include "capture-internals.h" 3 | 4 | #include 5 | #include 6 | 7 | HWND *GetHWND(obs_source_t *source) { 8 | 9 | if(!source) return NULL; 10 | 11 | void *data = source->context.data; 12 | const char *id = obs_source_get_id(source); 13 | 14 | if(!data) return NULL; 15 | 16 | if(strcmp(id, "game_capture") == 0) { 17 | struct game_capture *gcData = (struct game_capture *)data; 18 | return &gcData->window; 19 | } 20 | if(strcmp(id, "window_capture") == 0) { 21 | struct window_capture *wcData = (struct window_capture *)data; 22 | return &wcData->window; 23 | } 24 | 25 | return NULL; 26 | } 27 | 28 | bool CanGetHWND(obs_source_t *source) { 29 | const char *id = obs_source_get_id(source); 30 | 31 | if(strcmp(id, "game_capture") == 0) return true; 32 | if(strcmp(id, "window_capture") == 0) return true; 33 | 34 | return false; 35 | } -------------------------------------------------------------------------------- /src/getHWND.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef GET_HWND_H 3 | #define GET_HWND_H 4 | 5 | #define WIN32_LEAN_AND_MEAN 6 | #include 7 | #include 8 | #include 9 | 10 | HWND* GetHWND(obs_source_t*); 11 | 12 | bool CanGetHWND(obs_source_t*); 13 | 14 | #endif -------------------------------------------------------------------------------- /src/monitor.c: -------------------------------------------------------------------------------- 1 | #include "window-follower.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | static char *getFriendlyMonitorName(const MONITORINFOEXW *info); 8 | 9 | struct monitor_enum_set_monitor_data { 10 | window_follower_data_t *filter; 11 | const char *monitorName; 12 | }; 13 | 14 | BOOL CALLBACK monitor_enum_set_monitor( 15 | HMONITOR Arg1, 16 | HDC Arg2, 17 | LPRECT Arg3, 18 | LPARAM Arg4 19 | ) { 20 | struct monitor_enum_set_monitor_data *cbData = (struct monitor_enum_set_monitor_data *)Arg4; 21 | 22 | MONITORINFOEXA info; 23 | info.cbSize = sizeof(info); 24 | 25 | BOOL success = GetMonitorInfoA(Arg1, (LPMONITORINFO)&info); 26 | 27 | if(strcmp(info.szDevice, cbData->monitorName) != 0) return TRUE; 28 | 29 | cbData->filter->monitor = Arg1; 30 | cbData->filter->baseWindowDisplayArea = *Arg3; 31 | return FALSE; 32 | } 33 | 34 | void updateMonitor(window_follower_data_t *filter, obs_data_t *settings) { 35 | struct monitor_enum_set_monitor_data cbData = {.filter = filter, .monitorName = obs_data_get_string(settings, "monitor")}; 36 | EnumDisplayMonitors(NULL, NULL, monitor_enum_set_monitor, (LPARAM)&cbData); 37 | } 38 | 39 | static bool monitor_changed(void *data, obs_properties_t *props, 40 | obs_property_t *p, obs_data_t *settings) { 41 | window_follower_data_t *filter = data; 42 | 43 | updatePosScale(filter, settings); 44 | 45 | return false; 46 | } 47 | 48 | static BOOL CALLBACK monitor_enum_proplist_add( 49 | HMONITOR Arg1, 50 | HDC Arg2, 51 | LPRECT Arg3, 52 | LPARAM Arg4 53 | ) { 54 | obs_property_t *p = (obs_property_t *)Arg4; 55 | MONITORINFOEXW info; 56 | char *friendlyName, *devName; 57 | info.cbSize = sizeof(info); 58 | 59 | BOOL success = GetMonitorInfoW(Arg1, (LPMONITORINFO)&info); 60 | if(!success) return TRUE; 61 | 62 | os_wcs_to_utf8_ptr(info.szDevice, sizeof(info.szDevice)/sizeof(WCHAR), &devName); 63 | 64 | friendlyName=getFriendlyMonitorName(&info); 65 | if(!friendlyName) friendlyName = devName; 66 | 67 | obs_property_list_add_string(p, friendlyName, devName); 68 | 69 | bfree(friendlyName); 70 | if(friendlyName!=devName) bfree(devName); 71 | 72 | return TRUE; 73 | } 74 | 75 | void createMonitorProperty(window_follower_data_t *filter, obs_properties_t *props) { 76 | obs_property_t *p = obs_properties_add_list(props, "monitor", T_("Monitor"), 77 | OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING); 78 | EnumDisplayMonitors(NULL, NULL, monitor_enum_proplist_add, (LPARAM)p); 79 | obs_property_set_long_description(p, T_("Monitor.LongDesc")); 80 | obs_property_set_modified_callback2(p, monitor_changed, filter); 81 | } 82 | 83 | static char *getFriendlyMonitorName(const MONITORINFOEXW *info) { 84 | UINT32 numPath, numMode; 85 | DISPLAYCONFIG_PATH_INFO *paths=NULL; 86 | DISPLAYCONFIG_MODE_INFO *modes=NULL; 87 | 88 | char *ret = NULL; 89 | 90 | if(GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &numPath, &numMode) != ERROR_SUCCESS) { 91 | return NULL; 92 | } 93 | 94 | paths = bmalloc(sizeof(DISPLAYCONFIG_PATH_INFO) * numPath); 95 | modes = bmalloc(sizeof(DISPLAYCONFIG_MODE_INFO) * numMode); 96 | 97 | if(QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &numPath, 98 | paths, &numMode, modes, 99 | NULL) != ERROR_SUCCESS) { 100 | 101 | goto freeBuffs; 102 | } 103 | 104 | for(size_t pathIndex = 0; pathIndex < numPath; ++pathIndex) { 105 | DISPLAYCONFIG_PATH_INFO *path = &paths[pathIndex]; 106 | 107 | DISPLAYCONFIG_SOURCE_DEVICE_NAME source = { 108 | .header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME, 109 | .header.size = sizeof(source), 110 | .header.adapterId = path->sourceInfo.adapterId, 111 | .header.id = path->sourceInfo.id 112 | }; 113 | 114 | if(DisplayConfigGetDeviceInfo(&source.header) != ERROR_SUCCESS) continue; 115 | if(wcscmp(info->szDevice,source.viewGdiDeviceName) != 0) continue; 116 | 117 | DISPLAYCONFIG_TARGET_DEVICE_NAME target = { 118 | .header.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME, 119 | .header.size = sizeof(target), 120 | .header.adapterId = path->sourceInfo.adapterId, 121 | .header.id = path->targetInfo.id 122 | }; 123 | 124 | if(DisplayConfigGetDeviceInfo(&target.header) != ERROR_SUCCESS) continue; 125 | 126 | os_wcs_to_utf8_ptr(target.monitorFriendlyDeviceName, sizeof(target.monitorFriendlyDeviceName) / sizeof(WCHAR), &ret); 127 | break; 128 | } 129 | 130 | freeBuffs: 131 | bfree(modes); 132 | bfree(paths); 133 | 134 | return ret; 135 | } -------------------------------------------------------------------------------- /src/properties.c: -------------------------------------------------------------------------------- 1 | #include "getHWND.h" 2 | #include "window-follower.h" 3 | 4 | #include 5 | #include 6 | 7 | static bool source_enum_proplist_add(obs_scene_t *scene, 8 | obs_sceneitem_t *item, void *p) { 9 | obs_source_t *source = obs_sceneitem_get_source(item); 10 | if(!CanGetHWND(source)) return true; 11 | 12 | const char *name = obs_source_get_name(source); 13 | 14 | obs_property_list_add_string((obs_property_t *)p, name, name); 15 | UNUSED_PARAMETER(scene); 16 | return true; 17 | } 18 | 19 | void setupSceneItem(window_follower_data_t *filter, obs_data_t *settings) { 20 | 21 | const char *sourceName = obs_data_get_string(settings, "sourceId"); 22 | 23 | if(filter->sceneItem) { 24 | obs_sceneitem_release(filter->sceneItem); 25 | } 26 | 27 | filter->sceneItem = obs_scene_find_source(filter->scene, sourceName); 28 | 29 | if(filter->sceneItem) { 30 | obs_sceneitem_addref(filter->sceneItem); 31 | } 32 | 33 | if(filter->mainSource) { 34 | obs_source_release(filter->mainSource); 35 | } 36 | 37 | obs_source_t *source = obs_sceneitem_get_source(filter->sceneItem); 38 | 39 | if(source) { 40 | obs_source_addref(source); 41 | filter->mainSource = source; 42 | } 43 | 44 | filter->hwndPtr = GetHWND(source); 45 | } 46 | 47 | static bool source_changed(void *data, obs_properties_t *props, 48 | obs_property_t *p, obs_data_t *settings) { 49 | window_follower_data_t *filter = data; 50 | 51 | setupSceneItem(filter, settings); 52 | 53 | return false;//no need to rebuild the properties 54 | } 55 | 56 | enum PosScaleMode parsePosScale(const char *posScaleName) { 57 | if(strcmp(posScaleName, "None") == 0) return PosScaleNone; 58 | if(strcmp(posScaleName, "MonitorToScene") == 0) return PosScaleMonitorToScene; 59 | if(strcmp(posScaleName, "DesktopToScene") == 0) return PosScaleDesktopToScene; 60 | 61 | return PosScaleNone; 62 | } 63 | 64 | bool posScaleUsesMonitor(enum PosScaleMode posScale) { 65 | switch(posScale) { 66 | case PosScaleMonitorToScene: return true; 67 | default: return false; 68 | } 69 | } 70 | 71 | bool updatePosScale(window_follower_data_t *filter, obs_data_t *settings) { 72 | enum PosScaleMode newPosScale = parsePosScale(obs_data_get_string(settings, "posScale")); 73 | 74 | enum PosScaleMode oldPosScale = filter->posScale; 75 | filter->posScale = newPosScale; 76 | 77 | filter->monitor = NULL; 78 | if(posScaleUsesMonitor(newPosScale)) { 79 | updateMonitor(filter, settings); 80 | } 81 | if(filter->monitor == NULL) { 82 | filter->baseWindowDisplayArea.left = GetSystemMetrics(SM_YVIRTUALSCREEN); 83 | filter->baseWindowDisplayArea.top = GetSystemMetrics(SM_XVIRTUALSCREEN); 84 | filter->baseWindowDisplayArea.right = filter->baseWindowDisplayArea.left + GetSystemMetrics(SM_CXVIRTUALSCREEN); 85 | filter->baseWindowDisplayArea.bottom = filter->baseWindowDisplayArea.top + GetSystemMetrics(SM_CYVIRTUALSCREEN); 86 | } 87 | 88 | //we need to rebuild the properties if we switch between posscale modes that use and doesn't use a monitor 89 | return posScaleUsesMonitor(newPosScale) != posScaleUsesMonitor(oldPosScale); 90 | } 91 | 92 | static bool posScale_changed(void *data, obs_properties_t *props, 93 | obs_property_t *p, obs_data_t *settings) { 94 | window_follower_data_t *filter = data; 95 | 96 | return updatePosScale(filter, settings); 97 | } 98 | 99 | void updateBounds(window_follower_data_t *filter, obs_data_t *settings) { 100 | filter->sceneBoundsLeft = (int)obs_data_get_int(settings, "boundsLeft"); 101 | filter->sceneBoundsTop = (int)obs_data_get_int(settings, "boundsTop"); 102 | filter->sceneBoundsWidth = (int)obs_data_get_int(settings, "boundsWidth"); 103 | filter->sceneBoundsHeight = (int)obs_data_get_int(settings, "boundsHeight"); 104 | } 105 | 106 | bool bounds_changed(void *data, obs_properties_t *props, 107 | obs_property_t *p, obs_data_t *settings) { 108 | window_follower_data_t *filter = data; 109 | 110 | updateBounds(filter, settings); 111 | 112 | return false; 113 | } 114 | 115 | void updateStayInBoundsField(window_follower_data_t *filter, obs_data_t *settings) { 116 | filter->stayInBounds = obs_data_get_bool(settings, "stayInBounds"); 117 | } 118 | 119 | static bool stayInBounds_changed(void *data, obs_properties_t *props, 120 | obs_property_t *p, obs_data_t *settings) { 121 | window_follower_data_t *filter = data; 122 | 123 | updateStayInBoundsField(filter, settings); 124 | 125 | return false; 126 | } 127 | 128 | void updateHideMinimizedField(window_follower_data_t *filter, obs_data_t *settings) { 129 | filter->hideMinimized = obs_data_get_bool(settings, "hideMinimized"); 130 | } 131 | 132 | static bool hideMinimized_changed(void *data, obs_properties_t *props, 133 | obs_property_t *p, obs_data_t *settings) { 134 | window_follower_data_t *filter = data; 135 | 136 | updateHideMinimizedField(filter, settings); 137 | 138 | return false; 139 | } 140 | 141 | obs_properties_t *window_follower_properties(void *data) { 142 | window_follower_data_t *filter = data; 143 | obs_properties_t *props = obs_properties_create(); 144 | 145 | struct obs_video_info vidInfo; 146 | obs_get_video_info(&vidInfo); 147 | 148 | if(!filter->scene) return props; 149 | 150 | { 151 | obs_property_t *p = obs_properties_add_list(props, "sourceId", T_("SourceId"), 152 | OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING); 153 | obs_property_list_add_string(p, T_("SourceId.None"), "sourceIdNone"); 154 | obs_property_set_long_description(p, T_("SourceId.LongDesc")); 155 | obs_property_set_modified_callback2(p, source_changed, filter); 156 | 157 | // A list of sources 158 | obs_scene_enum_items(filter->scene, source_enum_proplist_add, (void *)p); 159 | obs_property_set_modified_callback2(p, source_changed, filter); 160 | } 161 | 162 | { 163 | obs_property_t *p = obs_properties_add_list(props, "posScale", T_("ScalePos"), 164 | OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING); 165 | obs_property_list_add_string(p, T_("ScalePos.None"), "None"); 166 | obs_property_list_add_string(p, T_("ScalePos.MonitorToScene"), "MonitorToScene"); 167 | obs_property_list_add_string(p, T_("ScalePos.DesktopToScene"), "DesktopToScene"); 168 | obs_property_set_long_description(p, T_("ScalePos.LongDesc")); 169 | obs_property_set_modified_callback2(p, posScale_changed, filter); 170 | } 171 | 172 | if(posScaleUsesMonitor(filter->posScale)) { 173 | createMonitorProperty(filter, props); 174 | } 175 | 176 | { 177 | obs_properties_t *boundsProps = obs_properties_create(); 178 | { 179 | obs_property_t *p = obs_properties_add_int(boundsProps, "boundsLeft", T_("Bounds.Left"), 0, vidInfo.base_width, 32); 180 | obs_property_set_long_description(p, T_("Bounds.Left.LongDesc")); 181 | obs_property_set_modified_callback2(p, bounds_changed, filter); 182 | } 183 | { 184 | obs_property_t *p = obs_properties_add_int(boundsProps, "boundsWidth", T_("Bounds.Width"), 0, vidInfo.base_width, 32); 185 | obs_property_set_long_description(p, T_("Bounds.Width.LongDesc")); 186 | obs_property_set_modified_callback2(p, bounds_changed, filter); 187 | } 188 | { 189 | obs_property_t *p = obs_properties_add_int(boundsProps, "boundsTop", T_("Bounds.Top"), 0, vidInfo.base_height, 32); 190 | obs_property_set_long_description(p, T_("Bounds.Top.LongDesc")); 191 | obs_property_set_modified_callback2(p, bounds_changed, filter); 192 | } 193 | { 194 | obs_property_t *p = obs_properties_add_int(boundsProps, "boundsHeight", T_("Bounds.Height"), 0, vidInfo.base_height, 32); 195 | obs_property_set_long_description(p, T_("Bounds.Height.LongDesc")); 196 | obs_property_set_modified_callback2(p, bounds_changed, filter); 197 | } 198 | 199 | { 200 | obs_property_t *p = obs_properties_add_bool(boundsProps, "stayInBounds", T_("StayInBounds")); 201 | obs_property_set_long_description(p, T_("StayInBounds.LongDesc")); 202 | obs_property_set_modified_callback2(p, stayInBounds_changed, filter); 203 | } 204 | 205 | obs_properties_add_group(props, "bounds", T_("Bounds.Group"), OBS_GROUP_NORMAL, boundsProps); 206 | } 207 | 208 | { 209 | obs_property_t *p = obs_properties_add_bool(props, "hideMinimized", T_("HideMinimized")); 210 | obs_property_set_modified_callback2(p, hideMinimized_changed, filter); 211 | } 212 | 213 | return props; 214 | } 215 | 216 | void window_follower_defaults(obs_data_t *settings) { 217 | struct obs_video_info vidInfo; 218 | obs_get_video_info(&vidInfo); 219 | 220 | obs_data_set_default_string(settings, "posScale", "DesktopToScene"); 221 | obs_data_set_default_bool(settings, "stayInBounds", false); 222 | 223 | obs_data_set_default_int(settings, "boundsLeft", 0); 224 | obs_data_set_default_int(settings, "boundsWidth", vidInfo.base_width); 225 | obs_data_set_default_int(settings, "boundsTop", 0); 226 | obs_data_set_default_int(settings, "boundsHeight", vidInfo.base_height); 227 | 228 | obs_data_set_default_bool(settings, "hideMinimized", true); 229 | } -------------------------------------------------------------------------------- /src/setup.c: -------------------------------------------------------------------------------- 1 | #include "window-follower.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | OBS_DECLARE_MODULE() 8 | OBS_MODULE_USE_DEFAULT_LOCALE("window-follower", "en-US") 9 | 10 | static void window_follower_save(void *data, obs_data_t *settings) { 11 | window_follower_data_t *filter = data; 12 | } 13 | 14 | static void window_follower_updateSettings(void *data, obs_data_t *settings) { 15 | window_follower_data_t *filter = data; 16 | 17 | } 18 | 19 | static void *window_follower_create(obs_data_t *settings, obs_source_t *context) { 20 | window_follower_data_t *filter = bzalloc(sizeof(*filter)); 21 | filter->filterSource = context; 22 | window_follower_signal_setup(filter); 23 | 24 | return filter; 25 | } 26 | 27 | void window_follower_lateInit(window_follower_data_t *filter) { 28 | obs_source_t *sceneSource = obs_filter_get_parent(filter->filterSource); 29 | filter->scene = obs_scene_from_source(sceneSource); 30 | 31 | window_follower_signal_lateSetup(filter); 32 | 33 | filter->lateInitializationDone = true; 34 | } 35 | 36 | static void window_follower_remove(void *data, obs_source_t *source) { 37 | window_follower_data_t *filter = data; 38 | 39 | if(filter->mainSource) { 40 | obs_source_release(filter->mainSource); 41 | filter->mainSource = NULL; 42 | } 43 | 44 | if(filter->sceneItem) { 45 | obs_sceneitem_release(filter->sceneItem); 46 | filter->sceneItem = NULL; 47 | } 48 | 49 | window_follower_signal_cleanup(filter); 50 | 51 | UNUSED_PARAMETER(source); 52 | } 53 | 54 | static void window_follower_destroy(void *data) { 55 | window_follower_data_t *filter = data; 56 | bfree(filter); 57 | } 58 | 59 | static void window_follower_load(void *data, obs_data_t *settings) { 60 | window_follower_data_t *filter = data; 61 | 62 | setupSceneItem(filter, settings); 63 | updateStayInBoundsField(filter, settings); 64 | updatePosScale(filter, settings); 65 | updateBounds(filter, settings); 66 | updateHideMinimizedField(filter, settings); 67 | } 68 | 69 | static void window_follower_show(void *data) { 70 | window_follower_data_t *filter = data; 71 | 72 | obs_data_t *settings = obs_source_get_settings(filter->filterSource); 73 | 74 | setupSceneItem(filter, settings); 75 | updateStayInBoundsField(filter, settings); 76 | updatePosScale(filter, settings); 77 | updateBounds(filter, settings); 78 | updateHideMinimizedField(filter, settings); 79 | 80 | obs_data_release(settings); 81 | } 82 | 83 | static const char *window_follower_get_name(void *unused) { 84 | UNUSED_PARAMETER(unused); 85 | return T_("WindowFollower"); 86 | } 87 | 88 | struct obs_source_info window_follower = { 89 | .id = "window-follower", 90 | .type = OBS_SOURCE_TYPE_FILTER, 91 | .output_flags = OBS_SOURCE_VIDEO, 92 | .get_name = window_follower_get_name, 93 | .create = window_follower_create, 94 | .destroy = window_follower_destroy, 95 | .update = window_follower_updateSettings, 96 | .get_properties = window_follower_properties, 97 | .get_defaults = window_follower_defaults, 98 | .video_tick = window_follower_tick, 99 | .save = window_follower_save, 100 | .load = window_follower_load, 101 | .filter_remove = window_follower_remove, 102 | .show = window_follower_show 103 | }; 104 | 105 | bool obs_module_load(void) { 106 | if(obs_get_version() != LIBOBS_API_VER) { 107 | return false; 108 | } 109 | 110 | obs_register_source(&window_follower); 111 | return true; 112 | } 113 | 114 | OBS_MODULE_AUTHOR("Henke37"); 115 | 116 | const char *obs_module_name(void) { 117 | return "Window-follower"; 118 | } 119 | 120 | const char *obs_module_description(void) { 121 | return "Makes scene items follow the movement of the window the source is capturing from"; 122 | } -------------------------------------------------------------------------------- /src/signals.c: -------------------------------------------------------------------------------- 1 | #include "window-follower.h" 2 | 3 | #include 4 | 5 | void window_follower_onAdd(void *data, calldata_t *cd) { 6 | window_follower_data_t *filter = data; 7 | obs_sceneitem_t *item = calldata_ptr(cd, "item"); 8 | } 9 | 10 | void window_follower_onRemove(void *data, calldata_t *cd) { 11 | window_follower_data_t *filter = data; 12 | obs_sceneitem_t *item=calldata_ptr(cd, "item"); 13 | 14 | if(item != filter->sceneItem) return; 15 | 16 | if(filter->sceneItem) { 17 | obs_sceneitem_release(filter->sceneItem); 18 | obs_source_release(filter->mainSource); 19 | 20 | filter->sceneItem = NULL; 21 | filter->mainSource = NULL; 22 | filter->hwndPtr = NULL; 23 | } 24 | } 25 | 26 | void window_follower_signal_lateSetup(window_follower_data_t *filter) { 27 | if(!filter->scene) return; 28 | signal_handler_t *sigHandler = obs_source_get_signal_handler(obs_scene_get_source(filter->scene)); 29 | 30 | signal_handler_connect(sigHandler, "item_add", window_follower_onAdd, filter); 31 | signal_handler_connect(sigHandler, "item_remove", window_follower_onRemove, filter); 32 | } 33 | 34 | void window_follower_signal_setup(window_follower_data_t *filter) { 35 | } 36 | 37 | void window_follower_signal_cleanup(window_follower_data_t *filter) { 38 | if(!filter->scene) return; 39 | signal_handler_t *sigHandler = obs_source_get_signal_handler(obs_scene_get_source(filter->scene)); 40 | 41 | signal_handler_disconnect(sigHandler, "item_add", window_follower_onAdd, filter); 42 | signal_handler_disconnect(sigHandler, "item_remove", window_follower_onRemove, filter); 43 | } -------------------------------------------------------------------------------- /src/tick.c: -------------------------------------------------------------------------------- 1 | #include "window-follower.h" 2 | 3 | #include 4 | #include 5 | 6 | void realTick(window_follower_data_t *filter); 7 | 8 | void window_follower_tick(void *data, float seconds) { 9 | window_follower_data_t *filter = data; 10 | 11 | if(!filter->lateInitializationDone) { 12 | window_follower_lateInit(filter); 13 | } 14 | 15 | if(filter->sceneItem) { 16 | //filter->pos.x += 0.1f; 17 | //if (filter->pos.x > 400) filter->pos.x -= 400; 18 | 19 | if(filter->hwndPtr) { 20 | if(IsWindow(*filter->hwndPtr)) { 21 | BOOL iconic = IsIconic(*filter->hwndPtr); 22 | if(!iconic) { 23 | realTick(filter); 24 | } 25 | if(filter->hideMinimized) { 26 | obs_sceneitem_set_visible(filter->sceneItem, !iconic); 27 | } 28 | } 29 | } 30 | 31 | obs_sceneitem_set_pos(filter->sceneItem, &filter->pos); 32 | } 33 | } 34 | 35 | void realTick(window_follower_data_t *filter) { 36 | RECT wndPos; 37 | GetWindowRect(*filter->hwndPtr, &wndPos); 38 | 39 | float itemWidth = (float)obs_source_get_width(filter->mainSource); 40 | float itemHeight = (float)obs_source_get_height(filter->mainSource); 41 | 42 | struct vec2 scale; 43 | obs_sceneitem_get_scale(filter->sceneItem, &scale); 44 | itemWidth *= scale.x; 45 | itemHeight *= scale.y; 46 | 47 | if(filter->posScale == PosScaleNone) { 48 | filter->pos.x = (float)wndPos.left; 49 | filter->pos.y = (float)wndPos.top; 50 | } else { 51 | float adjustedLeft = (float)wndPos.left - filter->baseWindowDisplayArea.left; 52 | float adjustedTop = (float)wndPos.top - filter->baseWindowDisplayArea.top; 53 | 54 | float xScaler = (float)filter->sceneBoundsWidth / (float)(filter->baseWindowDisplayArea.right - filter->baseWindowDisplayArea.left); 55 | float yScaler = (float)filter->sceneBoundsHeight / (float)(filter->baseWindowDisplayArea.bottom - filter->baseWindowDisplayArea.top); 56 | 57 | filter->pos.x = adjustedLeft * xScaler + filter->sceneBoundsLeft; 58 | filter->pos.y = adjustedTop * yScaler + filter->sceneBoundsTop; 59 | } 60 | 61 | if(filter->stayInBounds) { 62 | int sceneBoundsRight = filter->sceneBoundsLeft + filter->sceneBoundsWidth; 63 | int sceneBoundsBottom = filter->sceneBoundsTop + filter->sceneBoundsHeight; 64 | 65 | if(filter->pos.x < 0) filter->pos.x = 0; 66 | if(filter->pos.x + itemWidth > sceneBoundsRight) filter->pos.x = sceneBoundsRight - itemWidth; 67 | 68 | if(filter->pos.y < 0) filter->pos.y = 0; 69 | if(filter->pos.y + itemHeight > sceneBoundsBottom) filter->pos.y = sceneBoundsBottom - itemHeight; 70 | } 71 | } -------------------------------------------------------------------------------- /src/window-follower.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOW_FOLLOWER_H 2 | #define WINDOW_FOLLOWER_H 3 | 4 | #define WIN32_LEAN_AND_MEAN 5 | #include 6 | 7 | #include 8 | 9 | enum PosScaleMode { 10 | PosScaleNone, 11 | PosScaleMonitorToScene, 12 | PosScaleDesktopToScene 13 | }; 14 | 15 | struct window_follower_data { 16 | HWND *hwndPtr; 17 | obs_source_t *filterSource; 18 | obs_source_t *mainSource; 19 | obs_scene_t *scene; 20 | obs_sceneitem_t *sceneItem; 21 | 22 | struct vec2 pos; 23 | RECT baseWindowDisplayArea; 24 | 25 | bool lateInitializationDone; 26 | 27 | bool stayInBounds; 28 | bool hideMinimized; 29 | 30 | enum PosScaleMode posScale; 31 | 32 | HMONITOR monitor; 33 | 34 | int sceneBoundsTop; 35 | int sceneBoundsLeft; 36 | int sceneBoundsWidth; 37 | int sceneBoundsHeight; 38 | }; 39 | 40 | typedef struct window_follower_data window_follower_data_t; 41 | 42 | void window_follower_lateInit(window_follower_data_t *filter); 43 | 44 | void window_follower_tick(void *data, float seconds); 45 | obs_properties_t *window_follower_properties(void *data); 46 | void window_follower_defaults(obs_data_t *settings); 47 | 48 | void setupSceneItem(window_follower_data_t *filter, obs_data_t *settings); 49 | void updateStayInBoundsField(window_follower_data_t *filter, obs_data_t *settings); 50 | bool updatePosScale(window_follower_data_t *filter, obs_data_t *settings); 51 | void updateBounds(window_follower_data_t *filter, obs_data_t *settings); 52 | void updateStayInBoundsField(window_follower_data_t *filter, obs_data_t *settings); 53 | void updateHideMinimizedField(window_follower_data_t *filter, obs_data_t *settings); 54 | 55 | void createMonitorProperty(window_follower_data_t *filter, obs_properties_t *props); 56 | void updateMonitor(window_follower_data_t *filter, obs_data_t *settings); 57 | 58 | void window_follower_signal_lateSetup(window_follower_data_t *filter); 59 | void window_follower_signal_setup(window_follower_data_t *filter); 60 | void window_follower_signal_cleanup(window_follower_data_t *filter); 61 | 62 | 63 | #define T_(v) obs_module_text(v) 64 | 65 | #endif -------------------------------------------------------------------------------- /troubleshooting.md: -------------------------------------------------------------------------------- 1 | # Troubleshooting 2 | 3 | 4 | ## I'm not seeing any filter settings 5 | 6 | You added the filter to the source. Add it to the scene instead. 7 | This is because filters on sources apply to all instances of the source on all scenes. 8 | 9 | 10 | ## I updated OBS and the plugin no longer loads 11 | 12 | That's by design. Due to the black magic used in this plugin, changes in OBS may require adjusting the code in this plugin to match. 13 | 14 | 15 | ## I can't move the scene item 16 | 17 | This plugin moves the scene item for you. Use the boundrary settings to control where it can position the source. 18 | 19 | 20 | ## The scene item left the set boundraries 21 | 22 | That's by design. If the window leaves the monitor, so will the scene item. 23 | 24 | Use the "keep in bounds" setting if you dislike this. 25 | 26 | 27 | ## The scene item doesn't move when the window moves. 28 | 29 | Check that the boundrary settings doesn't have a width or height of zero. 30 | 31 | 32 | ## Strange behavior on multi monitor setups 33 | 34 | Ensure that you have selected the correct scale mode and monitor settings. 35 | 36 | 37 | ## The monitor setting shows/doesn't show when it should. 38 | 39 | This is a defect in the OBS settings system. Reopen the filter settings and it should correct itself. --------------------------------------------------------------------------------