├── .clang-format ├── .gitignore ├── CMakeLists.txt ├── COPYING ├── LICENSE ├── README.md ├── cmake ├── FindCEF.cmake └── FindOBS.cmake ├── data └── locale │ ├── de-DE.ini │ └── en-US.ini ├── img └── obs-linuxbrowser.png └── src ├── browser ├── base64.cpp ├── base64.hpp ├── browser-app.cpp ├── browser-app.hpp ├── browser-client.cpp ├── browser-client.hpp ├── browser-subprocess.cpp ├── browser.cpp ├── split-message.cpp └── split-message.hpp ├── config.h.in ├── plugin ├── main.c ├── manager.c ├── manager.h └── windows_keycode.h └── shared.h /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM # LLVM, Google, Chromium, Mozilla, WebKit 2 | AccessModifierOffset: -8 3 | AlignEscapedNewlinesLeft: true 4 | AlignTrailingComments: true 5 | AllowAllParametersOfDeclarationOnNextLine: false 6 | AllowShortBlocksOnASingleLine: false 7 | AllowShortCaseLabelsOnASingleLine: false 8 | AllowShortFunctionsOnASingleLine: false # None(false), Inline, All(true) 9 | AllowShortIfStatementsOnASingleLine: false 10 | AllowShortLoopsOnASingleLine: false 11 | AlwaysBreakAfterDefinitionReturnType: false 12 | AlwaysBreakBeforeMultilineStrings: true 13 | AlwaysBreakTemplateDeclarations: true 14 | BinPackParameters: true 15 | BreakBeforeBinaryOperators: NonAssignment # None, NonAssignment, All 16 | BreakBeforeBraces: Custom # Attach, Linux, Stroustrup, Allman, GNU 17 | BraceWrapping: 18 | AfterClass: false 19 | AfterControlStatement: false 20 | AfterEnum: true 21 | AfterFunction: true 22 | AfterNamespace: true 23 | AfterStruct: false 24 | AfterUnion: false 25 | AfterExternBlock: true 26 | BeforeCatch: true 27 | BeforeElse: false 28 | IndentBraces: false 29 | SplitEmptyFunction: false 30 | SplitEmptyNamespace: true 31 | BreakBeforeInheritanceComma: true 32 | BreakBeforeTernaryOperators: true 33 | BreakConstructorInitializers: BeforeComma 34 | ColumnLimit: 100 35 | # CommentPragmas 36 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 37 | ConstructorInitializerIndentWidth: 8 38 | ContinuationIndentWidth: 4 39 | Cpp11BracedListStyle: true 40 | DerivePointerAlignment: false 41 | DisableFormat: false 42 | ExperimentalAutoDetectBinPacking: false 43 | # ForEachMacros 44 | IncludeBlocks: Preserve 45 | #IncludeCategories: 46 | # - Regex: '^c?std.*' 47 | # Priority: 1 48 | # - Regex: '^obs' 49 | # Priority: 2 50 | # - Regex: '^(include/)?cef.*' 51 | # Priority: 3 52 | # - Regex: '.h$' 53 | # Priority: 4 54 | # - Regex: '.hpp$' 55 | # Priority: 5 56 | IndentCaseLabels: false 57 | # IndentPPDirectives: false 58 | IndentWidth: 8 59 | IndentWrappedFunctionNames: false 60 | KeepEmptyLinesAtTheStartOfBlocks: false 61 | Language: Cpp # None, Cpp, JavaScript, Proto 62 | MaxEmptyLinesToKeep: 1 63 | NamespaceIndentation: Inner # None, Inner, All 64 | # ObjCSpaceAfterProperty 65 | # ObjCSpaceBeforeProtocolList 66 | #// PenaltyBreakBeforeFirstCallParameter 67 | #// PenaltyBreakComment 68 | #// PenaltyBreakFirstLessLess 69 | #// PenaltyBreakString 70 | #// PenaltyExcessCharacter 71 | #// PenaltyReturnTypeOnItsOwnLine: 72 | PointerAlignment: Left # Left, Right, Middle 73 | SpaceAfterCStyleCast: true 74 | SpaceBeforeAssignmentOperators: true 75 | SpaceBeforeParens: ControlStatements # Never, ControlStatements, Always 76 | SpaceInEmptyParentheses: false 77 | SpacesBeforeTrailingComments: 1 78 | SpacesInAngles: false 79 | SpacesInCStyleCastParentheses: false 80 | SpacesInContainerLiterals: false 81 | SpacesInParentheses: false 82 | SpacesInSquareBrackets: false 83 | Standard: Cpp11 # Cpp03, Cpp11, Auto 84 | TabWidth: 8 85 | UseTab: ForIndentation # Never(false), ForIndentation, Always(true) 86 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | 3 | build/ 4 | releases/ 5 | src/config.h 6 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.0) 2 | project (obs-linuxbrowser LANGUAGES C CXX VERSION 0.6.1) 3 | 4 | set(CMAKE_BUILD_TYPE Release CACHE STRING "CMake build type") 5 | 6 | set(INSTALL_SYSTEMWIDE false CACHE BOOL "Install to system wide OBS directories instead of local ones") 7 | 8 | if (${INSTALL_SYSTEMWIDE}) 9 | set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Installation prefix") 10 | if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 11 | set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Installation prefix" FORCE) 12 | endif() 13 | else() 14 | set(CMAKE_INSTALL_PREFIX "$ENV{HOME}" CACHE PATH "Installation prefix") 15 | if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 16 | set(CMAKE_INSTALL_PREFIX "$ENV{HOME}" CACHE PATH "Installation prefix" FORCE) 17 | endif() 18 | endif() 19 | 20 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${obs-linuxbrowser_SOURCE_DIR}/cmake) 21 | set(CMAKE_INCLUDE_CURRENT_DIR true) 22 | 23 | find_package(OBS REQUIRED) 24 | find_package(CEF REQUIRED) 25 | 26 | math(EXPR BITS "8*${CMAKE_SIZEOF_VOID_P}") 27 | set(PLUGIN_DIRECTORY "${CMAKE_BINARY_DIR}/build/obs-linuxbrowser") 28 | set(PLUGIN_BIN_DIRECTORY "${PLUGIN_DIRECTORY}/bin/${BITS}bit") 29 | set(PLUGIN_DATA_DIRECTORY "${PLUGIN_DIRECTORY}/data") 30 | set(PLUGIN_CEF_DATA_DIRECTORY "${PLUGIN_DATA_DIRECTORY}/cef") 31 | 32 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_BIN_DIRECTORY}) 33 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PLUGIN_BIN_DIRECTORY}) 34 | 35 | # setting up plugin build 36 | file(COPY ${CMAKE_SOURCE_DIR}/data/locale DESTINATION ${PLUGIN_DATA_DIRECTORY}) 37 | file(COPY ${CEF_LIBRARY_PATH}/libcef.so DESTINATION ${PLUGIN_BIN_DIRECTORY}) 38 | file(COPY ${CEF_LIBRARY_PATH}/natives_blob.bin DESTINATION ${PLUGIN_BIN_DIRECTORY}) 39 | file(COPY ${CEF_LIBRARY_PATH}/snapshot_blob.bin DESTINATION ${PLUGIN_BIN_DIRECTORY}) 40 | file(COPY ${CEF_LIBRARY_PATH}/v8_context_snapshot.bin DESTINATION ${PLUGIN_BIN_DIRECTORY}) 41 | file(COPY ${CEF_RESOURCE_DIR}/icudtl.dat DESTINATION ${PLUGIN_BIN_DIRECTORY}) 42 | file(COPY ${CEF_RESOURCE_DIR}/cef.pak DESTINATION ${PLUGIN_CEF_DATA_DIRECTORY}) 43 | file(COPY ${CEF_RESOURCE_DIR}/cef_100_percent.pak DESTINATION ${PLUGIN_CEF_DATA_DIRECTORY}) 44 | file(COPY ${CEF_RESOURCE_DIR}/cef_200_percent.pak DESTINATION ${PLUGIN_CEF_DATA_DIRECTORY}) 45 | file(COPY ${CEF_RESOURCE_DIR}/cef_extensions.pak DESTINATION ${PLUGIN_CEF_DATA_DIRECTORY}) 46 | file(COPY ${CEF_RESOURCE_DIR}/devtools_resources.pak DESTINATION ${PLUGIN_CEF_DATA_DIRECTORY}) 47 | file(COPY ${CEF_RESOURCE_DIR}/locales DESTINATION ${PLUGIN_CEF_DATA_DIRECTORY}) 48 | 49 | # compilation 50 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") 51 | set(CMAKE_CXX_STANDARD 11) 52 | set(CMAKE_CXX_STANDARD_REQUIRED true) 53 | 54 | # Ensure a consistent command chain on all systems 55 | set(CMAKE_CXX_EXTENSIONS false) 56 | 57 | include_directories(src ${PROJECT_BINARY_DIR}/src ${OBS_INCLUDE_DIR} ${CEF_INCLUDE_DIR}) 58 | 59 | set(PLUGIN_SOURCES 60 | src/plugin/main.c 61 | src/plugin/manager.c 62 | ) 63 | set(BROWSER_SHARED_SOURCES 64 | src/browser/base64.cpp 65 | src/browser/browser-app.cpp 66 | src/browser/browser-client.cpp 67 | src/browser/split-message.cpp 68 | ) 69 | set(BROWSER_SOURCES 70 | src/browser/browser.cpp 71 | ) 72 | set(BROWSER_SUBPROCESS_SOURCES 73 | src/browser/browser.cpp 74 | ) 75 | 76 | configure_file( 77 | ${PROJECT_SOURCE_DIR}/src/config.h.in 78 | ${PROJECT_BINARY_DIR}/src/config.h 79 | ) 80 | 81 | add_library(obs-linuxbrowser MODULE ${PLUGIN_SOURCES}) 82 | target_link_libraries(obs-linuxbrowser ${OBS_LIBRARIES} rt) 83 | if (${INSTALL_SYSTEMWIDE}) # Failsafe for people who update linuxbrowser by just overwriting current installation without deleting it first 84 | # Remove 'lib' file prefix for compliance of default .so names in /usr/lib/obs-plugins 85 | set_target_properties(obs-linuxbrowser PROPERTIES PREFIX "") 86 | endif() 87 | 88 | add_library(browser_shared OBJECT ${BROWSER_SHARED_SOURCES}) 89 | 90 | add_executable(browser ${BROWSER_SOURCES} $) 91 | target_link_libraries(browser ${CEF_LIBRARIES} pthread rt -static-libstdc++) 92 | target_compile_features(browser PUBLIC ${LINUXBROWSER_CXX_FEATURES}) 93 | 94 | add_executable(browser-subprocess ${BROWSER_SUBPROCESS_SOURCES} $) 95 | target_link_libraries(browser-subprocess ${CEF_LIBRARIES} pthread rt -static-libstdc++) 96 | target_compile_features(browser-subprocess PUBLIC ${LINUXBROWSER_CXX_FEATURES}) 97 | 98 | if (${INSTALL_SYSTEMWIDE}) 99 | install(DIRECTORY ${PLUGIN_BIN_DIRECTORY}/ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/obs-plugins) 100 | install(DIRECTORY ${PLUGIN_DATA_DIRECTORY}/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/obs/obs-plugins/obs-linuxbrowser) 101 | else() 102 | install(DIRECTORY ${PLUGIN_DIRECTORY} DESTINATION ${CMAKE_INSTALL_PREFIX}/.config/obs-studio/plugins USE_SOURCE_PERMISSIONS) 103 | endif() 104 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 Library 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 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /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 | {description} 294 | Copyright (C) {year} {fullname} 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 | {signature of Ty Coon}, 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 | **Good news!** Starting with version 25, OBS Studio ships with browser source that work on Linux. 2 | I recommend you to use that and report any issues at [obs-browser repo](https://github.com/obsproject/obs-browser) and/or official discord community. 3 | 4 | I will archive this repository from now on. I would like to say big thanks to all the users, testers and contributors. 5 | Special thanks to [NexAdn](https://github.com/NexAdn) who helped maintain this repository for most of the time! 6 | 7 | # About 8 | 9 | This is a browser source plugin for [obs-studio](https://github.com/obsproject/obs-studio) based 10 | on [Chromium Embedded Framework](https://bitbucket.org/chromiumembedded/cef). This plugin is Linux only. 11 | 12 | Unfortunately, I was not able to make [obsproject/obs-browser](https://github.com/obsproject/obs-browser) work on Linux, 13 | so I decided to create a separate plugin using the same engine, so both plugins should have feature parity in 14 | terms of browser capabilities. 15 | 16 | ![Browser window](img/obs-linuxbrowser.png) 17 | 18 | # Dependencies 19 | 20 | * OBS-Studio 21 | * libgconf 22 | 23 | # Installing (binary release) 24 | 25 | * Download the latest release from the [releases page](https://github.com/bazukas/obs-linuxbrowser/releases). Make sure the release version matches obs-studio version on your system [1]. 26 | * `mkdir -p $HOME/.config/obs-studio/plugins` 27 | * Untar, e.g.: `tar -zxvf linuxbrowser0.6.1-obs23.0.2-64bit.tgz -C $HOME/.config/obs-studio/plugins/` 28 | * Install the dependencies (see Dependencies section) 29 | 30 | 31 | Arch Linux users can install obs-linuxbrowser from the official AUR packages [obs-linuxbrowser](https://aur.archlinux.org/packages/obs-linuxbrowser) or [obs-linuxbrowser-bin](https://aur.archlinux.org/packages/obs-linuxbrowser-bin). 32 | 33 | You don't need to build the plugin if you've downloaded a binary release, instructions below are for people who want to compile the plugin themselves. 34 | 35 | [1] Every binary release has the version number of OBS contained as part of the file name, e.g. “linuxbrowser0.6.1-obs23.0.2-64bit.tgz” refers to obs-linuxbrowser version 0.6.1 with OBS version 23.0.2. 36 | 37 | # Building from source 38 | 39 | **The following steps are NOT necessary, if you have already installed a binary release of obs-linuxbrowser!** 40 | 41 | ## Building CEF 42 | 43 | * Download CEF minimal or standard binary release from http://opensource.spotify.com/cefbuilds/index.html [2] 44 | * Extract and cd into folder 45 | * Run `cmake ./ && make libcef_dll_wrapper` 46 | 47 | [2] Due to unknown reasons certain CEF versions do not work properly with OBS-Studio. See issue [#63](https://github.com/bazukas/obs-linuxbrowser/issues/63) for a list of versions which have been confirmed to be working and to track progress on this issue. 48 | 49 | ## Building Plugin 50 | 51 | Make sure you have obs-studio installed. 52 | 53 | * `cd obs-linuxbrowser` 54 | * `mkdir build` 55 | * `cd build` 56 | * `cmake -DCEF_ROOT_DIR= ..` (don't forget the two dots at the end!) [3] 57 | * `make` 58 | 59 | [3] If you've installed OBS under an installation prefix other than `/usr` (meaning include files aren't located at `/usr/include/obs` and library files aren't located at `/usr/lib`), you need to set `OBS_ROOT_DIR` to reflect the actual installation prefix. If you don't know your installation prefix, you can also set `OBS_INCLUDE_SEARCH_DIR` to the location of your OBS installation's header files and `OBS_LIBRARY_SEARCH_DIR` to the location of your OBS installation's library (.so) files. *In most cases, though, this is NOT required at all.* 60 | 61 | *Info: If you intend to install obs-linuxbrowser system wide (though the OBS developers don't recommend that), you can add `-DINSTALL_SYSTEMWIDE=true` to the CMake call. obs-linuxbrowser will then be installed to `/usr/lib/obs-plugins` (binaries) and `/usr/share/obs/obs-plugins/obs-linuxbrowser` (data).* 62 | 63 | ## Installing compiled sources 64 | 65 | * Run `make install` to install all plugin binaries to `$HOME/.config/obs-studio/plugins`. 66 | * Make sure to have all dependencies installed on your system 67 | 68 | # Flash 69 | 70 | You can enable flash by providing the path to your installed pepper flash library file and its version. 71 | Some distributions provide packages with the plugin, but you can also extract one from google chrome installation. 72 | The Flash version can be found in manifest.json that is usually found in same directory as .so file. 73 | 74 | # JavaScript bindings 75 | obs-linuxbrowser provides some JS bindings that are working the same way as the ones from obs-browser do. Additionally, a constant `window.obsstudio.linuxbrowser = true` has been introduced to allow the distinction between obs-browser and obs-linuxbrowser on the website. 76 | 77 | All off the following bindings are children of `window.obsstudio`. 78 | 79 | ## Callbacks 80 | * `onActiveChange(bool isActive)` – called whenever the source becomes activated or deactivated 81 | * `onVisibilityChange(bool isVisible)` – called whenever the source is shown or hidden 82 | 83 | ## Constants 84 | * `linuxbrowser = true` – Indicates obs-linuxbrowser is being used 85 | * `pluginVersion` – A string containing the plugin's version 86 | 87 | # Known issues 88 | ## obs-linuxbrowser does not compile with recent versions of CEF 89 | Due to changes of the CEF API, recent versions of CEF are no longer compatible with obs-linuxbrowser. An attempt to solve this issue has been made and can be tried out by checking out the `fix-new-cef-api-108-110` branch. Unfortunately, this branch hasn't been merged to `master` yet due to the problems described in [#121](https://github.com/bazukas/obs-linuxbrowser/issues/121). 90 | 91 | ## OBS snap installation crashing when trying to create a Linuxbrowser object 92 | **obs-linuxbrowser does not support Snap installations** as these have some known restrictions that make our plugin crash. Please install OBS your distribution's standard way (e.g. via APT, RPM, etc.). 93 | 94 | See [#105](https://github.com/bazukas/obs-linuxbrowser/issues/105) for details. 95 | 96 | ## Old version of OBS not starting with new version of obs-linuxbrowser installed 97 | Using obs-linuxbrowser with an older OBS version than the one which has been used for compilation makes OBS break. Compile obs-linuxbrowser with the same OBS version you are going to use for streaming/recording or select a binary release whose OBS version matches the same version as yours. If you've compiled obs-linuxbrowser yourself, recompile it with the older version of OBS. 98 | 99 | ## OBS-Linuxbrowser not displaying any content with certain versions of CEF 100 | ~~Some builds of CEF seem to be not working with obs-linuxbrowser. 101 | We weren't able to figure out the exact cause of this, but we assume that it's a CEF-related issue we can't fix. 102 | Check issue [#63](https://github.com/bazukas/obs-linuxbrowser/issues/63) for information about CEF versions that are known to be working.~~ 103 | This issue seems to have been resolved. If it occurs again, please open a new issue. 104 | 105 | *Problems might also occur when updating CEF withouth recompiling obs-linuxbrowser afterwards. **Please make sure to recompile obs-linuxbrowser before opening issues concerning problems with certain CEF versions.*** 106 | 107 | ## Transparency not working correctly: Transparent white browser content appears gray on white scene background. 108 | As stated in issue [#58](https://github.com/bazukas/obs-linuxbrowser/issues/58), there is a limitation in CEF, making it unable to detect the background of the OBS scenes. 109 | Instead, premultiplied alpha values are used, which somehow make transparent white colors appear gray (every color on the grayscale is a bit darker than normal when using transparency). 110 | With a black background, transparency seems to be working out quite fine. 111 | 112 | This issue cannot be fixed. 113 | 114 | ## OBS-Linuxbrowser not compiling, complaining about having to use ISO C++11 standard (old compiler versions) 115 | ~~See [#88](https://github.com/bazukas/obs-linuxbrowser/issues/88) for details. Some older compiler versions seem to have trouble with our current CMake setup. Using newer versions (e.g. GCC 8.x) should work.~~ 116 | This issue should've been resolved with versions 0.5.3 and above. 117 | 118 | ## OBS-Linuxbrowser crashing when using amdgpu 119 | See [#89](https://github.com/bazukas/obs-linuxbrowser/issues/89) for details. obs-linuxbrowser seems to crash on machines using amdgpu drivers. Unfortunately, this issue cannot be fixed. 120 | -------------------------------------------------------------------------------- /cmake/FindCEF.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Source: https://github.com/obsproject/obs-browser/blob/89aa4ee8b6c7ae12acbd90158feca1fe61dedf7d/FindCEF.cmake 3 | # 4 | include(FindPackageHandleStandardArgs) 5 | 6 | SET(CEF_ROOT_DIR "/opt/cef" CACHE PATH "Path to a CEF distributed build") 7 | message(STATUS "Looking for Chromium Embedded Framework in ${CEF_ROOT_DIR}") 8 | 9 | find_path(CEF_INCLUDE_DIR 10 | "cef_version.h" 11 | NAMES 12 | cef_version.h 13 | HINTS 14 | ${CEF_ROOT_DIR} 15 | PATH_SUFFIXES 16 | include/ 17 | ) 18 | 19 | find_library(CEF_LIBRARY 20 | "Chromium Embedded Framework" 21 | NAMES 22 | cef 23 | libcef 24 | PATHS 25 | ${CEF_ROOT_DIR} 26 | ${CEF_ROOT_DIR} 27 | PATH_SUFFIXES 28 | /Release 29 | ) 30 | find_library(CEF_LIBRARY_DEBUG 31 | "Chromium Embedded Framework" 32 | NAMES 33 | cef 34 | libcef 35 | PATHS 36 | ${CEF_ROOT_DIR} 37 | ${CEF_ROOT_DIR} 38 | PATH_SUFFIXES 39 | /Debug 40 | ) 41 | 42 | find_library(CEFWRAPPER_LIBRARY 43 | "CEF wrapper" 44 | NAMES 45 | cef_dll_wrapper 46 | libcef_dll_wrapper 47 | PATHS 48 | ${CEF_ROOT_DIR} 49 | ${CEF_ROOT_DIR}/libcef_dll 50 | ${CEF_ROOT_DIR}/libcef_dll_wrapper 51 | ${CEF_ROOT_DIR}/build/libcef_dll 52 | ${CEF_ROOT_DIR}/build/libcef_dll_wrapper 53 | PATH_SUFFIXES 54 | /Release 55 | ) 56 | 57 | find_library(CEFWRAPPER_LIBRARY_DEBUG 58 | "CEF wrapper" 59 | NAMES 60 | cef_dll_wrapper 61 | libcef_dll_wrapper 62 | PATHS 63 | ${CEF_ROOT_DIR}/libcef_dll/Debug 64 | ${CEF_ROOT_DIR}/libcef_dll_wrapper/Debug 65 | ${CEF_ROOT_DIR}/build/libcef_dll/Debug 66 | ${CEF_ROOT_DIR}/build/libcef_dll_wrapper/Debug 67 | ) 68 | 69 | find_path(CEF_RESOURCE_DIR 70 | "CEF resources directory" 71 | NAMES 72 | cef_100_percent.pak 73 | cef_200_percent.pak 74 | cef_extensions.pak 75 | cef.pak 76 | devtools_resources.pak 77 | icudtl.dat 78 | PATHS 79 | ${CEF_ROOT_DIR} 80 | PATH_SUFFIXES 81 | /Resources 82 | ) 83 | 84 | if(NOT CEF_LIBRARY) 85 | message(FATAL_ERROR "Could not find the CEF shared library" ) 86 | set(CEF_FOUND false) 87 | return() 88 | endif() 89 | 90 | get_filename_component(CEF_LIBRARY_PATH ${CEF_LIBRARY} PATH) 91 | 92 | if(NOT CEFWRAPPER_LIBRARY) 93 | message(FATAL_ERROR "Could not find the CEF wrapper library" ) 94 | set(CEF_FOUND false) 95 | return() 96 | endif() 97 | 98 | # Parse chrome build 99 | set(CEF_CHROME_VERSION_BUILD_NUMBER_REGEX "#define CHROME_VERSION_BUILD ([0-9]+)") 100 | file(STRINGS "${CEF_INCLUDE_DIR}/cef_version.h" CEF_CHROME_BUILD REGEX "${CEF_CHROME_VERSION_BUILD_NUMBER_REGEX}") 101 | string(REGEX REPLACE 102 | "${CEF_CHROME_VERSION_BUILD_NUMBER_REGEX}" 103 | "\\1" 104 | CEF_CHROME_BUILD 105 | "${CEF_CHROME_BUILD}" 106 | ) 107 | 108 | set(CEF_LIBRARIES 109 | ${CEFWRAPPER_LIBRARY} 110 | ${CEF_LIBRARY} 111 | ) 112 | 113 | set(CEF_INCLUDE_DIR 114 | "${CEF_INCLUDE_DIR}" 115 | "${CEF_INCLUDE_DIR}/.." 116 | ) 117 | 118 | set(CEF_INCLUDE_DIRS 119 | ${CEF_INCLUDE_DIR} 120 | ) 121 | 122 | if (CEF_LIBRARY_DEBUG AND CEFWRAPPER_LIBRARY_DEBUG) 123 | list(APPEND CEF_LIBRARIES 124 | ${CEFWRAPPER_LIBRARY_DEBUG} 125 | ${CEF_LIBRARY_DEBUG}) 126 | endif() 127 | 128 | 129 | find_package_handle_standard_args(CEF 130 | DEFAULT_MSG 131 | CEF_LIBRARY 132 | CEFWRAPPER_LIBRARY 133 | CEF_RESOURCE_DIR 134 | CEF_INCLUDE_DIR 135 | ) 136 | 137 | mark_as_advanced( 138 | CEF_LIBRARY 139 | CEFWRAPPER_LIBRARY 140 | CEF_LIBRARIES 141 | CEF_INCLUDE_DIR 142 | CEF_RESOURCE_DIR 143 | CEF_CHROME_VERSION_BUILD_NUMBER_REGEX 144 | ) 145 | -------------------------------------------------------------------------------- /cmake/FindOBS.cmake: -------------------------------------------------------------------------------- 1 | set(OBS_ROOT_DIR 2 | "/usr" 3 | CACHE 4 | PATH "OBS installation prefix" 5 | ) 6 | 7 | message(STATUS "Looking for OBS Studio in prefix ${OBS_ROOT_DIR}") 8 | 9 | if (CMAKE_SIZEOF_VOID_P MATCHES "8") 10 | set(_LIBSUFFIXES /lib64 /lib) 11 | else() 12 | set(_LIBSUFFIXES /lib) 13 | endif() 14 | 15 | set(_INCSUFFIXES /include) 16 | 17 | find_library(OBS_LIBRARY 18 | NAMES 19 | obs 20 | "OBS Studio" 21 | HINTS 22 | "${OBS_LIBRARY_SEARCH_DIR}" 23 | PATHS 24 | "${OBS_ROOT_DIR}" 25 | PATH_SUFFIXES 26 | "${_LIBSUFFIXES}" 27 | ) 28 | 29 | find_path(OBS_INCLUDE_DIR 30 | NAMES 31 | obs.h obs.hpp 32 | "OBS Studio" 33 | HINTS 34 | "${OBS_INCLUDE_SEARCH_DIR}" 35 | PATHS 36 | "${OBS_ROOT_DIR}" 37 | "/usr" 38 | PATH_SUFFIXES 39 | include/ 40 | include/obs 41 | ) 42 | 43 | include(FindPackageHandleStandardArgs) 44 | find_package_handle_standard_args(OBS 45 | DEFAULT_MSG 46 | OBS_LIBRARY 47 | OBS_INCLUDE_DIR 48 | ${_deps_check} 49 | ) 50 | 51 | if (OBS_FOUND) 52 | set(OBS_LIBRARIES "${OBS_LIBRARY}") 53 | mark_as_advanced(OBS_ROOT_DIR) 54 | endif() 55 | 56 | mark_as_advanced( 57 | OBS_INCLUDE_DIR 58 | OBS_LIBRARY 59 | ) 60 | -------------------------------------------------------------------------------- /data/locale/de-DE.ini: -------------------------------------------------------------------------------- 1 | LinuxBrowser="Linux-Browser" 2 | LocalFile="Lokale Datei" 3 | URL="URL" 4 | Width="Breite" 5 | Height="Höhe" 6 | FPS="FPS" 7 | ReloadPage="Seite neuladen" 8 | ReloadOnScene="Bei Aktivierung neuladen" 9 | FlashPath="Flash-Plugin-Pfad" 10 | FlashVersion="Flash-Plugin-Version" 11 | RestartBrowser="Browser neustarten" 12 | StopOnHide="Browser stoppen, wenn versteckt" 13 | CustomCSS="Eigenes CSS" 14 | CSSFileReset="CSS-Dateipfad zurücksetzen" 15 | CustomJS="Eigenes JavaScript" 16 | JSFileReset="JS-Dateipfad zurücksetzen" 17 | EnvironmentVariables="Umgebungsvariablen" 18 | CommandLineArguments="Kommandozeilen-Argumente" 19 | HideScrollbars="Scrolleisten verstecken" 20 | Zoom="Zoom" 21 | ScrollVertical="Vertikal scrollen" 22 | ScrollHorizontal="Horizontal scrollen" 23 | -------------------------------------------------------------------------------- /data/locale/en-US.ini: -------------------------------------------------------------------------------- 1 | LinuxBrowser="Linux Browser" 2 | LocalFile="Local file" 3 | URL="URL" 4 | Width="Width" 5 | Height="Height" 6 | FPS="FPS" 7 | ReloadPage="Reload Page" 8 | ReloadOnScene="Reload on activate" 9 | FlashPath="Flash Plugin Path" 10 | FlashVersion="Flash Plugin Version" 11 | RestartBrowser="Restart Browser" 12 | StopOnHide="Stop browser while hidden" 13 | CustomCSS="Custom CSS" 14 | CSSFileReset="Reset CSS file path" 15 | CustomJS="Custom JavaScript" 16 | JSFileReset="Reset JS file path" 17 | EnvironmentVariables="Environment Variables" 18 | CommandLineArguments="Command-Line Arguments" 19 | HideScrollbars="Hide Scrollbars" 20 | Zoom="Zoom" 21 | ScrollVertical="Vertical Scroll" 22 | ScrollHorizontal="Horizontal Scroll" 23 | -------------------------------------------------------------------------------- /img/obs-linuxbrowser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazukas/obs-linuxbrowser/267e04e96bab60677cf70a42f812ccbabcd72b55/img/obs-linuxbrowser.png -------------------------------------------------------------------------------- /src/browser/base64.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | base64.cpp and base64.h 3 | 4 | Copyright (C) 2004-2008 Ren� Nyffenegger 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the author be held liable for any damages 8 | arising from the use of this software. 9 | 10 | Permission is granted to anyone to use this software for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original source code. 21 | 22 | 3. This notice may not be removed or altered from any source distribution. 23 | 24 | Ren� Nyffenegger rene.nyffenegger@adp-gmbh.ch 25 | 26 | */ 27 | 28 | #include "base64.hpp" 29 | #include 30 | 31 | static const std::string base64_chars = 32 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 33 | "abcdefghijklmnopqrstuvwxyz" 34 | "0123456789+/"; 35 | 36 | static inline bool is_base64(unsigned char c) 37 | { 38 | return (isalnum(c) || (c == '+') || (c == '/')); 39 | } 40 | 41 | std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) 42 | { 43 | std::string ret; 44 | int i = 0; 45 | int j = 0; 46 | unsigned char char_array_3[3]; 47 | unsigned char char_array_4[4]; 48 | 49 | while (in_len--) { 50 | char_array_3[i++] = *(bytes_to_encode++); 51 | if (i == 3) { 52 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 53 | char_array_4[1] = 54 | ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); 55 | char_array_4[2] = 56 | ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); 57 | char_array_4[3] = char_array_3[2] & 0x3f; 58 | 59 | for (i = 0; (i < 4); i++) 60 | ret += base64_chars[char_array_4[i]]; 61 | i = 0; 62 | } 63 | } 64 | 65 | if (i) { 66 | for (j = i; j < 3; j++) 67 | char_array_3[j] = '\0'; 68 | 69 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 70 | char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); 71 | char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); 72 | char_array_4[3] = char_array_3[2] & 0x3f; 73 | 74 | for (j = 0; (j < i + 1); j++) 75 | ret += base64_chars[char_array_4[j]]; 76 | 77 | while ((i++ < 3)) 78 | ret += '='; 79 | } 80 | 81 | return ret; 82 | } 83 | 84 | std::string base64_decode(std::string const& encoded_string) 85 | { 86 | int in_len = encoded_string.size(); 87 | int i = 0; 88 | int j = 0; 89 | int in_ = 0; 90 | unsigned char char_array_4[4], char_array_3[3]; 91 | std::string ret; 92 | 93 | while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_])) { 94 | char_array_4[i++] = encoded_string[in_]; 95 | in_++; 96 | if (i == 4) { 97 | for (i = 0; i < 4; i++) 98 | char_array_4[i] = base64_chars.find(char_array_4[i]); 99 | 100 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 101 | char_array_3[1] = 102 | ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 103 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 104 | 105 | for (i = 0; (i < 3); i++) 106 | ret += char_array_3[i]; 107 | i = 0; 108 | } 109 | } 110 | 111 | if (i) { 112 | for (j = i; j < 4; j++) 113 | char_array_4[j] = 0; 114 | 115 | for (j = 0; j < 4; j++) 116 | char_array_4[j] = base64_chars.find(char_array_4[j]); 117 | 118 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 119 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 120 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 121 | 122 | for (j = 0; (j < i - 1); j++) 123 | ret += char_array_3[j]; 124 | } 125 | 126 | return ret; 127 | } 128 | -------------------------------------------------------------------------------- /src/browser/base64.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | base64.cpp and base64.h 3 | 4 | Copyright (C) 2004-2008 Renй Nyffenegger 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the author be held liable for any damages 8 | arising from the use of this software. 9 | 10 | Permission is granted to anyone to use this software for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original source code. 21 | 22 | 3. This notice may not be removed or altered from any source distribution. 23 | 24 | Renй Nyffenegger rene.nyffenegger@adp-gmbh.ch 25 | 26 | */ 27 | #include 28 | 29 | std::string base64_encode(unsigned char const*, unsigned int len); 30 | std::string base64_decode(std::string const& s); 31 | -------------------------------------------------------------------------------- /src/browser/browser-app.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Azat Khasanshin 3 | Copyright (C) 2018 by Adrian Schollmeyer 4 | 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 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "browser-app.hpp" 30 | #include "config.h" 31 | 32 | /* for signal handling */ 33 | namespace 34 | { 35 | int static_in_fd{0}; 36 | BrowserApp* ba{nullptr}; 37 | void file_changed(int signum) 38 | { 39 | inotify_event event; 40 | 41 | if (static_in_fd != 0 && ba != nullptr) { 42 | read(static_in_fd, (void*) &event, sizeof(inotify_event)); 43 | ba->ReloadPage(); 44 | } 45 | } 46 | 47 | bool beginsWith(const std::string& base, const std::string& beginning) 48 | { 49 | return base.substr(0, beginning.size()) == beginning; 50 | } 51 | } // namespace 52 | 53 | BrowserApp::BrowserApp(char* shmname) 54 | { 55 | if (shmname != nullptr && beginsWith({shmname}, {SHM_NAME})) { 56 | shm_name = shmname; 57 | 58 | // init inotify 59 | in_fd = inotify_init1(IN_NONBLOCK); 60 | fcntl(in_fd, F_SETFL, O_ASYNC); 61 | fcntl(in_fd, F_SETOWN, getpid()); 62 | struct sigaction action; 63 | std::memset(&action, 0, sizeof(struct sigaction)); 64 | action.sa_handler = file_changed; 65 | sigaction(SIGIO, &action, nullptr); 66 | static_in_fd = in_fd; 67 | ba = this; 68 | 69 | InitSharedData(); 70 | } 71 | } 72 | 73 | BrowserApp::~BrowserApp() 74 | { 75 | UninitSharedData(); 76 | if (in_fd) 77 | close(in_fd); 78 | } 79 | 80 | void BrowserApp::OnBeforeCommandLineProcessing(const CefString& processType, 81 | CefRefPtr commandLine) 82 | { 83 | commandLine->AppendSwitchWithValue("autoplay-policy", "no-user-gesture-required"); 84 | } 85 | 86 | // Open shared memory and read initial data 87 | void BrowserApp::InitSharedData() 88 | { 89 | fd = shm_open(shm_name.c_str(), O_RDWR, S_IRUSR | S_IWUSR); 90 | if (fd == -1) { 91 | std::cerr << "Browser: shared memory open failed\n"; 92 | return; 93 | } 94 | data = reinterpret_cast( 95 | mmap(nullptr, sizeof(shared_data), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); 96 | 97 | if (data == MAP_FAILED) { 98 | std::cerr << "Browser: data mapping failed\n"; 99 | return; 100 | } 101 | 102 | pthread_mutex_lock(&data->mutex); 103 | qid = data->qid; 104 | width = data->width; 105 | height = data->height; 106 | fps = data->fps; 107 | pthread_mutex_unlock(&data->mutex); 108 | 109 | data = reinterpret_cast(mmap(nullptr, sizeof(shared_data) + MAX_DATA_SIZE, 110 | PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); 111 | if (data == MAP_FAILED) { 112 | std::cerr << "Browser: data remapping failed\n"; 113 | return; 114 | } 115 | } 116 | 117 | void BrowserApp::UninitSharedData() 118 | { 119 | if (data && data != MAP_FAILED) { 120 | munmap(data, sizeof(shared_data) + MAX_DATA_SIZE); 121 | } 122 | } 123 | 124 | // Message receiver loop 125 | void BrowserApp::MessageThreadWorker() 126 | { 127 | std::unordered_map splitMessages; 128 | size_t max_buf_size = MAX_MESSAGE_SIZE; 129 | ssize_t received; 130 | CefMouseEvent e; 131 | CefKeyEvent ke; 132 | 133 | browser_message_t msg; 134 | 135 | while (true) { 136 | received = msgrcv(this->GetQueueId(), &msg, max_buf_size, 0, MSG_NOERROR); 137 | if (received != -1) { 138 | switch (msg.generic.type) { 139 | case MESSAGE_TYPE_URL: 140 | this->UrlChanged(msg.text.text); 141 | break; 142 | case MESSAGE_TYPE_URL_LONG: 143 | 144 | if (splitMessages.count(msg.split_text.id) <= 0) { 145 | splitMessages.insert( 146 | {msg.split_text.id, 147 | new SplitMessage(msg.split_text.id, 148 | msg.split_text.max)}); 149 | } 150 | 151 | splitMessages.at(msg.split_text.id)->addMessage(msg); 152 | 153 | if (splitMessages.at(msg.split_text.id)->dataIsReady()) { 154 | this->UrlChanged( 155 | splitMessages.at(msg.split_text.id)->getData()); 156 | delete splitMessages.at(msg.split_text.id); 157 | splitMessages.erase(msg.split_text.id); 158 | } 159 | break; 160 | case MESSAGE_TYPE_SIZE: 161 | this->SizeChanged(); 162 | break; 163 | case MESSAGE_TYPE_RELOAD: 164 | this->ReloadPage(); 165 | break; 166 | case MESSAGE_TYPE_CSS: 167 | this->CssChanged(msg.text.text); 168 | break; 169 | case MESSAGE_TYPE_JS: 170 | this->JsChanged(msg.text.text); 171 | break; 172 | case MESSAGE_TYPE_MOUSE_CLICK: 173 | e.modifiers = msg.mouse_click.modifiers; 174 | e.x = msg.mouse_click.x; 175 | e.y = msg.mouse_click.y; 176 | this->GetBrowser()->GetHost()->SendMouseClickEvent( 177 | e, 178 | static_cast( 179 | msg.mouse_click.button_type), 180 | msg.mouse_click.mouse_up, msg.mouse_click.click_count); 181 | break; 182 | case MESSAGE_TYPE_MOUSE_MOVE: 183 | e.modifiers = msg.mouse_move.modifiers; 184 | e.x = msg.mouse_move.x; 185 | e.y = msg.mouse_move.y; 186 | this->GetBrowser()->GetHost()->SendMouseMoveEvent( 187 | e, msg.mouse_move.mouse_leave); 188 | break; 189 | case MESSAGE_TYPE_MOUSE_WHEEL: 190 | e.modifiers = msg.mouse_wheel.modifiers; 191 | e.x = msg.mouse_wheel.x; 192 | e.y = msg.mouse_wheel.y; 193 | this->GetBrowser()->GetHost()->SendMouseWheelEvent( 194 | e, msg.mouse_wheel.x_delta, msg.mouse_wheel.y_delta); 195 | break; 196 | case MESSAGE_TYPE_FOCUS: 197 | this->GetBrowser()->GetHost()->SendFocusEvent(msg.focus.focus); 198 | break; 199 | case MESSAGE_TYPE_KEY: 200 | /* I have no idea what is happening */ 201 | ke.windows_key_code = msg.key.native_vkey; 202 | ke.native_key_code = msg.key.native_vkey; 203 | ke.modifiers = msg.key.modifiers; 204 | ke.type = msg.key.key_up ? KEYEVENT_KEYUP : KEYEVENT_RAWKEYDOWN; 205 | if (msg.key.chr != 0) { 206 | ke.character = msg.key.chr; 207 | if (!msg.key.key_up) 208 | ke.type = KEYEVENT_CHAR; 209 | } 210 | this->GetBrowser()->GetHost()->SendKeyEvent(ke); 211 | break; 212 | case MESSAGE_TYPE_SCROLLBARS: 213 | this->GetClient()->SetScrollbars(this->GetBrowser(), 214 | msg.generic_state.state); 215 | break; 216 | case MESSAGE_TYPE_ZOOM: 217 | this->GetClient()->SetZoom(this->GetBrowser(), msg.zoom.zoom); 218 | break; 219 | case MESSAGE_TYPE_SCROLL: 220 | this->GetClient()->SetScroll( 221 | this->GetBrowser(), msg.scroll.vertical, msg.scroll.horizontal); 222 | break; 223 | case MESSAGE_TYPE_ACTIVE_STATE_CHANGE: 224 | this->UpdateActiveStateJS(msg.active_state.active); 225 | break; 226 | case MESSAGE_TYPE_VISIBILITY_CHANGE: 227 | this->UpdateVisibilityStateJS(msg.visibility.visible); 228 | break; 229 | } 230 | } 231 | } 232 | } 233 | 234 | void BrowserApp::SizeChanged() 235 | { 236 | pthread_mutex_lock(&data->mutex); 237 | width = data->width; 238 | height = data->height; 239 | 240 | browser->GetHost()->WasResized(); 241 | pthread_mutex_unlock(&data->mutex); 242 | } 243 | 244 | void BrowserApp::UrlChanged(const char* url) 245 | { 246 | this->UrlChanged(std::string(url)); 247 | } 248 | 249 | void BrowserApp::UrlChanged(std::string url) 250 | { 251 | CefString cef_url; 252 | cef_url.FromString(url); 253 | browser->GetMainFrame()->LoadURL(cef_url); 254 | 255 | if (in_wd >= 0) { 256 | inotify_rm_watch(in_fd, in_wd); 257 | in_wd = -1; 258 | } 259 | 260 | if (beginsWith(url, "file:///")) { 261 | in_wd = inotify_add_watch(in_fd, url.substr(8).c_str(), IN_MODIFY); 262 | } 263 | } 264 | 265 | void BrowserApp::CssChanged(const char* css_file) 266 | { 267 | std::ifstream t{css_file, std::ifstream::in}; 268 | if (t.good()) { 269 | std::stringstream buffer; 270 | buffer << t.rdbuf(); 271 | css = buffer.str(); 272 | } else { 273 | css = ""; 274 | } 275 | 276 | client->ChangeCss(css); 277 | } 278 | 279 | void BrowserApp::JsChanged(std::string jsFile) 280 | { 281 | std::ifstream t{jsFile, std::ifstream::in}; 282 | if (t.good()) { 283 | std::stringstream buf; 284 | buf << t.rdbuf(); 285 | this->js = buf.str(); 286 | } else { 287 | this->js = ""; 288 | } 289 | 290 | this->client->ChangeJs(this->js); 291 | } 292 | 293 | void BrowserApp::ReloadPage() 294 | { 295 | browser->ReloadIgnoreCache(); 296 | } 297 | 298 | // Browser instance is being initialized here 299 | void BrowserApp::OnContextInitialized() 300 | { 301 | if (shm_name.empty()) 302 | return; 303 | 304 | CefWindowInfo info; 305 | info.width = width; 306 | info.height = height; 307 | info.windowless_rendering_enabled = true; 308 | 309 | CefBrowserSettings settings; 310 | settings.windowless_frame_rate = fps; 311 | 312 | CefRefPtr client{new BrowserClient(data, css)}; 313 | this->client = client; 314 | 315 | browser = CefBrowserHost::CreateBrowserSync( 316 | info, client.get(), "https://github.com/bazukas/obs-linuxbrowser/", settings, nullptr); 317 | client->SetScroll(browser, 0, 0); // workaround for scroll to bottom bug 318 | 319 | messageThread = std::thread{[this] { this->MessageThreadWorker(); }}; 320 | } 321 | 322 | void BrowserApp::OnContextCreated(CefRefPtr browser, CefRefPtr frame, 323 | CefRefPtr context) 324 | { 325 | CefRefPtr globalObj = context->GetGlobal(); 326 | 327 | CefRefPtr obsStudioObj = CefV8Value::CreateObject(0, 0); 328 | globalObj->SetValue("obsstudio", obsStudioObj, V8_PROPERTY_ATTRIBUTE_NONE); 329 | 330 | obsStudioObj->SetValue("linuxbrowser", CefV8Value::CreateBool(true), 331 | V8_PROPERTY_ATTRIBUTE_NONE); 332 | 333 | obsStudioObj->SetValue("pluginVersion", CefV8Value::CreateString(LINUXBROWSER_VERSION), 334 | V8_PROPERTY_ATTRIBUTE_NONE); 335 | } 336 | 337 | bool BrowserApp::OnProcessMessageReceived(CefRefPtr browser, 338 | CefProcessId source_process, 339 | CefRefPtr message) 340 | { 341 | DCHECK(source_process == PID_BROWSER); 342 | 343 | CefRefPtr args = message->GetArgumentList(); 344 | 345 | if (message->GetName() == "Visibility") { 346 | CefV8ValueList arguments{CefV8Value::CreateBool(args->GetBool(0))}; 347 | ExecuteJSFunction(browser, "onVisiblityChange", arguments); 348 | } else if (message->GetName() == "Active") { 349 | CefV8ValueList arguments{CefV8Value::CreateBool(args->GetBool(0))}; 350 | ExecuteJSFunction(browser, "onActiveChange", arguments); 351 | } else { 352 | return false; 353 | } 354 | 355 | return true; 356 | } 357 | 358 | void BrowserApp::ExecuteJSFunction(CefRefPtr browser, const char* functionName, 359 | CefV8ValueList arguments) 360 | { 361 | CefRefPtr context = browser->GetMainFrame()->GetV8Context(); 362 | 363 | context->Enter(); 364 | 365 | CefRefPtr globalObj = context->GetGlobal(); 366 | CefRefPtr obsStudioObj = globalObj->GetValue("obsstudio"); 367 | CefRefPtr jsFunction = obsStudioObj->GetValue(functionName); 368 | 369 | if (jsFunction && jsFunction->IsFunction()) { 370 | jsFunction->ExecuteFunction(nullptr, arguments); 371 | } 372 | 373 | context->Exit(); 374 | } 375 | 376 | bool BrowserApp::Execute(const CefString& name, CefRefPtr object, 377 | const CefV8ValueList& arguments, CefRefPtr& retval, 378 | CefString& exception) 379 | { 380 | return true; 381 | } 382 | 383 | void BrowserApp::UpdateActiveStateJS(bool active) 384 | { 385 | CefRefPtr msg{CefProcessMessage::Create("Active")}; 386 | msg->GetArgumentList()->SetBool(0, active); 387 | this->browser->SendProcessMessage(PID_BROWSER, msg); 388 | } 389 | 390 | void BrowserApp::UpdateVisibilityStateJS(bool visible) 391 | { 392 | CefRefPtr msg = CefProcessMessage::Create("Visibility"); 393 | CefRefPtr args = msg->GetArgumentList(); 394 | args->SetBool(0, visible); 395 | this->browser->SendProcessMessage(PID_BROWSER, msg); 396 | } 397 | -------------------------------------------------------------------------------- /src/browser/browser-app.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Azat Khasanshin 3 | Copyright (C) 2018 by Adrian Schollmeyer 4 | 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 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include "browser-client.hpp" 26 | #include "shared.h" 27 | #include "split-message.hpp" 28 | 29 | class BrowserApp 30 | : public CefApp 31 | , public CefBrowserProcessHandler 32 | , public CefRenderProcessHandler 33 | , public CefV8Handler { 34 | public: 35 | BrowserApp(char* shm_name); 36 | ~BrowserApp(); 37 | 38 | virtual CefRefPtr GetBrowserProcessHandler() OVERRIDE 39 | { 40 | return this; 41 | } 42 | 43 | virtual CefRefPtr GetRenderProcessHandler() override 44 | { 45 | return this; 46 | } 47 | 48 | virtual void OnContextInitialized() OVERRIDE; 49 | 50 | int GetQueueId() 51 | { 52 | return qid; 53 | } 54 | CefRefPtr GetBrowser() 55 | { 56 | return browser; 57 | } 58 | void SizeChanged(); 59 | void UrlChanged(const char* url); 60 | void UrlChanged(std::string url); 61 | void CssChanged(const char* css_file); 62 | void JsChanged(std::string jsFile); 63 | void ReloadPage(); 64 | 65 | CefRefPtr GetClient() 66 | { 67 | return client; 68 | } 69 | 70 | void OnBeforeCommandLineProcessing(const CefString& process_type, 71 | CefRefPtr command_line) override; 72 | 73 | virtual void OnContextCreated(CefRefPtr browser, CefRefPtr frame, 74 | CefRefPtr context) override; 75 | 76 | virtual bool OnProcessMessageReceived(CefRefPtr browser, 77 | CefProcessId source_process, 78 | CefRefPtr message) override; 79 | 80 | void UpdateActiveStateJS(bool active); 81 | void UpdateVisibilityStateJS(bool visible); 82 | 83 | virtual bool Execute(const CefString& name, CefRefPtr object, 84 | const CefV8ValueList& arguments, CefRefPtr& retval, 85 | CefString& exception) override; 86 | 87 | private: 88 | void InitSharedData(); 89 | void UninitSharedData(); 90 | 91 | void ExecuteJSFunction(CefRefPtr browser, const char* functionName, 92 | CefV8ValueList arguments); 93 | 94 | void MessageThreadWorker(); 95 | 96 | private: 97 | CefRefPtr browser; 98 | CefRefPtr client; 99 | std::thread messageThread; 100 | std::string shm_name; 101 | uint32_t width; 102 | uint32_t height; 103 | int fps; 104 | int fd; 105 | int qid; 106 | shared_data_t* data; 107 | std::string css; 108 | std::string js; 109 | int in_fd; 110 | int in_wd{-1}; 111 | 112 | IMPLEMENT_REFCOUNTING(BrowserApp); 113 | }; 114 | -------------------------------------------------------------------------------- /src/browser/browser-client.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Azat Khasanshin , 3 | John R. Bradley 4 | Copyright (C) 2018, 2019 by Adrian Schollmeyer 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | #include 20 | #include 21 | 22 | #include "base64.hpp" 23 | #include "browser-client.hpp" 24 | 25 | BrowserClient::BrowserClient(shared_data_t* data, std::string css) 26 | { 27 | this->data = data; 28 | this->css = css; 29 | } 30 | 31 | BC_GET_VIEW_RECT_RETURN_TYPE BrowserClient::GetViewRect(CefRefPtr browser, 32 | CefRect& rect) 33 | { 34 | pthread_mutex_lock(&data->mutex); 35 | rect.Set(0, 0, data->width, data->height); 36 | pthread_mutex_unlock(&data->mutex); 37 | BC_GET_VIEW_RECT_RETURN 38 | } 39 | 40 | void BrowserClient::OnPaint(CefRefPtr browser, CefRenderHandler::PaintElementType type, 41 | const CefRenderHandler::RectList& dirtyRects, const void* buffer, 42 | int vwidth, int vheight) 43 | { 44 | // Don't draw popups for now 45 | if (type == PET_VIEW) { 46 | pthread_mutex_lock(&data->mutex); 47 | size_t len = std::min(vwidth * vheight * 4, int(data->width * data->height * 4)); 48 | std::memcpy(&data->data, buffer, len); 49 | pthread_mutex_unlock(&data->mutex); 50 | } 51 | } 52 | 53 | void BrowserClient::OnLoadEnd(CefRefPtr browser, CefRefPtr frame, 54 | int httpStatusCode) 55 | { 56 | if (frame->IsMain() && css != "") { 57 | std::string base64EncodedCSS = base64_encode( 58 | reinterpret_cast(css.c_str()), css.length()); 59 | std::string href = "data:text/css;charset=utf-8;base64," + base64EncodedCSS; 60 | 61 | std::string script = ""; 62 | script += "let link = document.createElement('link');"; 63 | script += "link.setAttribute('rel', 'stylesheet');"; 64 | script += "link.setAttribute('type', 'text/css');"; 65 | script += "link.setAttribute('href', '" + href + "');"; 66 | script += "document.getElementsByTagName('head')[0].appendChild(link);"; 67 | 68 | frame->ExecuteJavaScript(script, href, 0); 69 | } 70 | if (frame->IsMain() && js != "") { 71 | frame->ExecuteJavaScript(this->js, "", 0); 72 | } 73 | SetScrollbars(browser, show_scrollbars); 74 | SetZoom(browser, zoom); 75 | } 76 | 77 | void BrowserClient::SetScrollbars(CefRefPtr browser, bool show) 78 | { 79 | this->show_scrollbars = show; 80 | CefRefPtr frame = browser->GetMainFrame(); 81 | if (show) { 82 | frame->ExecuteJavaScript( 83 | std::string("document.documentElement.style.overflow = 'auto';"), 84 | frame->GetURL(), 0); 85 | } else { 86 | frame->ExecuteJavaScript( 87 | std::string("document.documentElement.style.overflow = 'hidden';"), 88 | frame->GetURL(), 0); 89 | } 90 | SetScroll(browser, scroll_vertical, scroll_horizontal); 91 | } 92 | 93 | void BrowserClient::SetZoom(CefRefPtr browser, uint32_t zoom) 94 | { 95 | this->zoom = zoom; 96 | double zoom_scale{log(zoom / 100.0) / log(1.2)}; 97 | browser->GetHost()->SetZoomLevel(zoom_scale); 98 | } 99 | 100 | void BrowserClient::SetScroll(CefRefPtr browser, uint32_t vertical, uint32_t horizontal) 101 | { 102 | this->scroll_vertical = vertical; 103 | this->scroll_horizontal = horizontal; 104 | CefRefPtr frame{browser->GetMainFrame()}; 105 | std::string script{"window.scrollTo("}; 106 | script += std::to_string(horizontal) + "," + std::to_string(vertical) + ");"; 107 | frame->ExecuteJavaScript(script, frame->GetURL(), 0); 108 | } 109 | 110 | void BrowserClient::ChangeJs(std::string js) 111 | { 112 | this->js = js; 113 | } 114 | -------------------------------------------------------------------------------- /src/browser/browser-client.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Azat Khasanshin 3 | Copyright (C) 2018, 2019 by Adrian Schollmeyer 4 | 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 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | #pragma once 19 | 20 | #include 21 | 22 | #include "shared.h" 23 | 24 | #include "config.h" 25 | 26 | class BrowserClient 27 | : public CefClient 28 | , public CefRenderHandler 29 | , public CefLoadHandler { 30 | public: 31 | BrowserClient(shared_data_t* data, std::string css); 32 | 33 | virtual CefRefPtr GetRenderHandler() OVERRIDE 34 | { 35 | return this; 36 | } 37 | virtual CefRefPtr GetLoadHandler() OVERRIDE 38 | { 39 | return this; 40 | } 41 | 42 | virtual BC_GET_VIEW_RECT_RETURN_TYPE GetViewRect(CefRefPtr browser, 43 | CefRect& rect) override; 44 | virtual void OnPaint(CefRefPtr browser, CefRenderHandler::PaintElementType type, 45 | const CefRenderHandler::RectList& dirtyRects, const void* buffer, 46 | int width, int height) OVERRIDE; 47 | 48 | virtual void OnLoadEnd(CefRefPtr browser, CefRefPtr frame, 49 | int httpStatusCode) OVERRIDE; 50 | 51 | void ChangeCss(std::string css) 52 | { 53 | this->css = css; 54 | }; 55 | void ChangeJs(std::string js); 56 | void SetScrollbars(CefRefPtr browser, bool show); 57 | void SetZoom(CefRefPtr browser, uint32_t zoom); 58 | void SetScroll(CefRefPtr browser, uint32_t vertical, uint32_t horizontal); 59 | 60 | private: 61 | shared_data_t* data; 62 | std::string css; 63 | std::string js; 64 | bool show_scrollbars{true}; 65 | uint32_t zoom; 66 | uint32_t scroll_vertical; 67 | uint32_t scroll_horizontal; 68 | 69 | IMPLEMENT_REFCOUNTING(BrowserClient); 70 | }; 71 | -------------------------------------------------------------------------------- /src/browser/browser-subprocess.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Azat Khasanshin 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 2 of the License, or 7 | (at your option) any later version. 8 | 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 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | #include "browser-app.hpp" 20 | 21 | int main(int argc, char* argv[]) 22 | { 23 | CefRefPtr app{new BrowserApp(nullptr)}; 24 | return CefExecuteProcess({argc, argv}, app.get(), nullptr); 25 | } 26 | -------------------------------------------------------------------------------- /src/browser/browser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Azat Khasanshin 3 | Copyright (C) 2018 by Adrian Schollmeyer 4 | 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 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include "browser-app.hpp" 26 | 27 | /* first argument is full path to the binary 28 | * second is shared memory id */ 29 | int main(int argc, char* argv[]) 30 | { 31 | /* shutdown if parent process dies */ 32 | prctl(PR_SET_PDEATHSIG, SIGTERM); 33 | 34 | /* different path settings for cef */ 35 | std::string data_dir{argv[1]}; 36 | std::string resources_dir{data_dir + "/cef"}; 37 | std::string locales_dir{resources_dir + "/locales"}; 38 | std::string home_dir{getpwuid(getuid())->pw_dir}; 39 | std::string cache_dir{home_dir + "/.cache/obs-linuxbrowser/" + std::string{argv[2]}}; 40 | std::string subprocess_path{std::string{argv[0]} + "-subprocess"}; 41 | 42 | CefRefPtr app{new BrowserApp(argv[2])}; 43 | 44 | CefSettings settings; 45 | CefString(&settings.browser_subprocess_path).FromString(subprocess_path); 46 | CefString(&settings.resources_dir_path).FromString(resources_dir); 47 | CefString(&settings.locales_dir_path).FromString(locales_dir); 48 | CefString(&settings.cache_path).FromString(cache_dir); 49 | settings.no_sandbox = true; 50 | settings.windowless_rendering_enabled = true; 51 | 52 | CefInitialize({argc, argv}, settings, app.get(), nullptr); 53 | CefRunMessageLoop(); 54 | CefShutdown(); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /src/browser/split-message.cpp: -------------------------------------------------------------------------------- 1 | #include "split-message.hpp" 2 | 3 | SplitMessage::SplitMessage(const uint8_t id, const uint8_t size) : id(id), size(size) 4 | {} 5 | 6 | SplitMessage::~SplitMessage() 7 | {} 8 | 9 | std::string SplitMessage::getData() const 10 | { 11 | std::string res; 12 | for (auto m : this->messages) { 13 | res += m.second; 14 | } 15 | 16 | return res; 17 | } 18 | 19 | bool SplitMessage::dataIsReady() const 20 | { 21 | for (uint8_t i = 0; i < this->size; i++) { 22 | try { 23 | this->messages.at(i); 24 | } 25 | catch (std::out_of_range&) { 26 | return false; 27 | } 28 | } 29 | return true; 30 | } 31 | 32 | void SplitMessage::addMessage(const browser_message_t& msg) 33 | { 34 | // Only insert message if the id and size match; else silent fail 35 | if (msg.split_text.id == this->id && msg.split_text.max == this->size) { 36 | this->messages.insert({msg.split_text.count, std::string{msg.split_text.text}}); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/browser/split-message.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 by Adrian Schollmeyer 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 2 of the License, or 7 | (at your option) any later version. 8 | 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 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "shared.h" 24 | 25 | class SplitMessage { 26 | public: 27 | SplitMessage(const uint8_t id, const uint8_t size); 28 | ~SplitMessage(); 29 | 30 | SplitMessage operator=(const SplitMessage&) = delete; 31 | 32 | std::string getData() const; 33 | bool dataIsReady() const; 34 | 35 | void addMessage(const browser_message_t& msg); 36 | 37 | private: 38 | std::map messages; 39 | 40 | const uint8_t id; 41 | const uint8_t size; 42 | }; 43 | -------------------------------------------------------------------------------- /src/config.h.in: -------------------------------------------------------------------------------- 1 | // clang-format off 2 | 3 | #define LINUXBROWSER_VERSION "@PROJECT_VERSION@" 4 | #define CEF_BUILD @CEF_CHROME_BUILD@ 5 | 6 | #if CEF_BUILD >= 3578 7 | # define BC_GET_VIEW_RECT_RETURN_TYPE void 8 | # define BC_GET_VIEW_RECT_RETURN 9 | #else 10 | # define BC_GET_VIEW_RECT_RETURN_TYPE bool 11 | # define BC_GET_VIEW_RECT_RETURN return true; 12 | #endif 13 | -------------------------------------------------------------------------------- /src/plugin/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Azat Khasanshin 3 | Copyright (C) 2018 by Adrian Schollmeyer 4 | 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 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | #include 19 | #include 20 | #include 21 | 22 | #include "manager.h" 23 | #include "windows_keycode.h" 24 | 25 | OBS_DECLARE_MODULE() 26 | OBS_MODULE_USE_DEFAULT_LOCALE("linuxbrowser-source", "en-US") 27 | 28 | struct browser_data { 29 | /* settings */ 30 | char* url; 31 | uint32_t width; 32 | uint32_t height; 33 | uint32_t fps; 34 | char* css_file; 35 | char* js_file; 36 | bool hide_scrollbars; 37 | uint32_t zoom; 38 | uint32_t scroll_vertical; 39 | uint32_t scroll_horizontal; 40 | bool reload_on_scene; 41 | bool stop_on_hide; 42 | 43 | /* internal data */ 44 | obs_source_t* source; 45 | obs_data_t* settings; 46 | gs_texture_t* activeTexture; 47 | pthread_mutex_t textureLock; 48 | browser_manager_t* manager; 49 | 50 | obs_hotkey_id reload_page_key; 51 | }; 52 | 53 | static const char* browser_get_name(void* unused) 54 | { 55 | UNUSED_PARAMETER(unused); 56 | return obs_module_text("LinuxBrowser"); 57 | } 58 | 59 | /* update stored parameters, see if they have changed and call 60 | * browser_manager methods based on that */ 61 | static void browser_update(void* vptr, obs_data_t* settings) 62 | { 63 | struct browser_data* data = vptr; 64 | 65 | uint32_t width = obs_data_get_int(settings, "width"); 66 | uint32_t height = obs_data_get_int(settings, "height"); 67 | bool resize = width != data->width || height != data->height; 68 | data->width = width; 69 | data->height = height; 70 | data->fps = obs_data_get_int(settings, "fps"); 71 | bool hide_scrollbars = obs_data_get_bool(settings, "hide_scrollbars"); 72 | uint32_t zoom = obs_data_get_int(settings, "zoom"); 73 | uint32_t scroll_vertical = obs_data_get_int(settings, "scroll_vertical"); 74 | uint32_t scroll_horizontal = obs_data_get_int(settings, "scroll_horizontal"); 75 | data->reload_on_scene = obs_data_get_bool(settings, "reload_on_scene"); 76 | data->stop_on_hide = obs_data_get_bool(settings, "stop_on_hide"); 77 | 78 | bool is_local = obs_data_get_bool(settings, "is_local_file"); 79 | const char* url; 80 | if (is_local) 81 | url = obs_data_get_string(settings, "local_file"); 82 | else 83 | url = obs_data_get_string(settings, "url"); 84 | 85 | const char* css_file = obs_data_get_string(settings, "css_file"); 86 | const char* js_file = obs_data_get_string(settings, "js_file"); 87 | 88 | if (!data->manager) 89 | data->manager = create_browser_manager(data->width, data->height, data->fps, 90 | settings, obs_source_get_name(data->source)); 91 | 92 | if (data->hide_scrollbars != hide_scrollbars) { 93 | data->hide_scrollbars = hide_scrollbars; 94 | browser_manager_set_scrollbars(data->manager, !hide_scrollbars); 95 | } 96 | if (data->zoom != zoom) { 97 | data->zoom = zoom; 98 | browser_manager_set_zoom(data->manager, zoom); 99 | } 100 | if (data->scroll_vertical != scroll_vertical 101 | || data->scroll_horizontal != scroll_horizontal) { 102 | data->scroll_vertical = scroll_vertical; 103 | data->scroll_horizontal = scroll_horizontal; 104 | browser_manager_set_scroll(data->manager, scroll_vertical, scroll_horizontal); 105 | } 106 | 107 | if (!data->url || strcmp(url, data->url) != 0) { 108 | if (data->url) { 109 | bfree(data->url); 110 | data->url = NULL; 111 | } 112 | if (is_local) { 113 | size_t len = strlen("file://") + strlen(url) + 1; 114 | data->url = bzalloc(len); 115 | snprintf(data->url, len, "file://%s", url); 116 | } else { 117 | data->url = bstrdup(url); 118 | } 119 | browser_manager_change_url(data->manager, data->url); 120 | } 121 | if (!data->css_file || strcmp(css_file, data->css_file) != 0) { 122 | if (data->css_file) { 123 | bfree(data->css_file); 124 | data->css_file = NULL; 125 | } 126 | data->css_file = bstrdup(css_file); 127 | browser_manager_change_css_file(data->manager, data->css_file); 128 | } 129 | if (!data->js_file || strcmp(js_file, data->js_file) != 0) { 130 | if (data->js_file) { 131 | bfree(data->js_file); 132 | data->js_file = NULL; 133 | } 134 | data->js_file = bstrdup(js_file); 135 | browser_manager_change_js_file(data->manager, data->js_file); 136 | } 137 | 138 | /* need to recreate texture if size changed */ 139 | pthread_mutex_lock(&data->textureLock); 140 | obs_enter_graphics(); 141 | if (resize || !data->activeTexture) { 142 | if (resize) 143 | browser_manager_change_size(data->manager, data->width, data->height); 144 | if (data->activeTexture) { 145 | gs_texture_destroy(data->activeTexture); 146 | data->activeTexture = NULL; 147 | } 148 | data->activeTexture = 149 | gs_texture_create(width, height, GS_BGRA, 1, NULL, GS_DYNAMIC); 150 | } 151 | obs_leave_graphics(); 152 | pthread_mutex_unlock(&data->textureLock); 153 | } 154 | 155 | static void reload_hotkey_pressed(void* vptr, obs_hotkey_id id, obs_hotkey_t* key, bool pressed) 156 | { 157 | UNUSED_PARAMETER(id); 158 | UNUSED_PARAMETER(key); 159 | UNUSED_PARAMETER(pressed); 160 | 161 | struct browser_data* data = vptr; 162 | browser_manager_change_css_file(data->manager, data->css_file); 163 | browser_manager_change_js_file(data->manager, data->js_file); 164 | browser_manager_reload_page(data->manager); 165 | } 166 | 167 | static void* browser_create(obs_data_t* settings, obs_source_t* source) 168 | { 169 | struct browser_data* data = bzalloc(sizeof(struct browser_data)); 170 | data->source = source; 171 | data->settings = settings; 172 | pthread_mutex_init(&data->textureLock, NULL); 173 | 174 | browser_update(data, settings); 175 | 176 | data->reload_page_key = 177 | obs_hotkey_register_source(source, "linuxbrowser.reloadpage", 178 | obs_module_text("ReloadPage"), reload_hotkey_pressed, data); 179 | return data; 180 | } 181 | 182 | static void browser_destroy(void* vptr) 183 | { 184 | struct browser_data* data = vptr; 185 | if (!data) 186 | return; 187 | 188 | pthread_mutex_destroy(&data->textureLock); 189 | if (data->activeTexture) { 190 | obs_enter_graphics(); 191 | gs_texture_destroy(data->activeTexture); 192 | data->activeTexture = NULL; 193 | obs_leave_graphics(); 194 | } 195 | 196 | if (data->manager) { 197 | destroy_browser_manager(data->manager); 198 | data->manager = NULL; 199 | } 200 | 201 | obs_hotkey_unregister(data->reload_page_key); 202 | 203 | if (data->url) { 204 | bfree(data->url); 205 | data->url = NULL; 206 | } 207 | if (data->css_file) { 208 | bfree(data->css_file); 209 | data->css_file = NULL; 210 | } 211 | if (data->js_file) { 212 | bfree(data->js_file); 213 | data->js_file = NULL; 214 | } 215 | bfree(data); 216 | } 217 | 218 | static uint32_t browser_get_width(void* vptr) 219 | { 220 | struct browser_data* data = vptr; 221 | return data->width; 222 | } 223 | 224 | static uint32_t browser_get_height(void* vptr) 225 | { 226 | struct browser_data* data = vptr; 227 | return data->height; 228 | } 229 | 230 | static bool reload_button_clicked(obs_properties_t* props, obs_property_t* property, void* vptr) 231 | { 232 | UNUSED_PARAMETER(props); 233 | UNUSED_PARAMETER(property); 234 | struct browser_data* data = vptr; 235 | browser_manager_change_css_file(data->manager, data->css_file); 236 | browser_manager_change_js_file(data->manager, data->js_file); 237 | browser_manager_reload_page(data->manager); 238 | return true; 239 | } 240 | 241 | static void reload_on_scene(void* vptr) 242 | { 243 | struct browser_data* data = vptr; 244 | if (data->reload_on_scene) 245 | browser_manager_reload_page(data->manager); 246 | } 247 | 248 | static bool css_file_reset_button_clicked(obs_properties_t* props, obs_property_t* property, 249 | void* vptr) 250 | { 251 | UNUSED_PARAMETER(props); 252 | UNUSED_PARAMETER(property); 253 | struct browser_data* data = vptr; 254 | obs_data_t* settings = data->settings; 255 | 256 | obs_data_erase(settings, "css_file"); 257 | browser_update(data, settings); 258 | 259 | return true; 260 | } 261 | 262 | static bool js_file_reset_button_clicked(obs_properties_t* props, obs_property_t* property, 263 | void* vptr) 264 | { 265 | UNUSED_PARAMETER(props); 266 | UNUSED_PARAMETER(property); 267 | struct browser_data* data = vptr; 268 | obs_data_t* settings = data->settings; 269 | 270 | obs_data_erase(settings, "js_file"); 271 | browser_update(data, settings); 272 | 273 | return true; 274 | } 275 | 276 | static bool restart_button_clicked(obs_properties_t* props, obs_property_t* property, void* vptr) 277 | { 278 | UNUSED_PARAMETER(props); 279 | UNUSED_PARAMETER(property); 280 | struct browser_data* data = vptr; 281 | browser_manager_restart_browser(data->manager); 282 | browser_manager_change_css_file(data->manager, data->css_file); 283 | browser_manager_change_js_file(data->manager, data->js_file); 284 | browser_manager_change_url(data->manager, data->url); 285 | browser_manager_set_scrollbars(data->manager, !data->hide_scrollbars); 286 | browser_manager_set_zoom(data->manager, data->zoom); 287 | browser_manager_set_scroll(data->manager, data->scroll_vertical, data->scroll_horizontal); 288 | return true; 289 | } 290 | 291 | static bool is_local_file_modified(obs_properties_t* props, obs_property_t* prop, 292 | obs_data_t* settings) 293 | { 294 | UNUSED_PARAMETER(prop); 295 | 296 | bool enabled = obs_data_get_bool(settings, "is_local_file"); 297 | obs_property_t* url = obs_properties_get(props, "url"); 298 | obs_property_t* local_file = obs_properties_get(props, "local_file"); 299 | obs_property_set_visible(url, !enabled); 300 | obs_property_set_visible(local_file, enabled); 301 | 302 | return true; 303 | } 304 | 305 | static obs_properties_t* browser_get_properties(void* vptr) 306 | { 307 | UNUSED_PARAMETER(vptr); 308 | obs_properties_t* props = obs_properties_create(); 309 | 310 | obs_property_t* prop = 311 | obs_properties_add_bool(props, "is_local_file", obs_module_text("LocalFile")); 312 | obs_property_set_modified_callback(prop, is_local_file_modified); 313 | obs_properties_add_path(props, "local_file", obs_module_text("LocalFile"), OBS_PATH_FILE, 314 | "*.*", NULL); 315 | 316 | obs_properties_add_text(props, "url", obs_module_text("URL"), OBS_TEXT_DEFAULT); 317 | obs_properties_add_int(props, "width", obs_module_text("Width"), 1, MAX_BROWSER_WIDTH, 1); 318 | obs_properties_add_int(props, "height", obs_module_text("Height"), 1, MAX_BROWSER_HEIGHT, 319 | 1); 320 | obs_properties_add_int(props, "fps", obs_module_text("FPS"), 1, 60, 1); 321 | obs_properties_add_bool(props, "hide_scrollbars", obs_module_text("HideScrollbars")); 322 | obs_properties_add_int(props, "zoom", obs_module_text("Zoom"), 1, 500, 1); 323 | obs_properties_add_int(props, "scroll_vertical", obs_module_text("ScrollVertical"), 0, 324 | 10000000, 1); 325 | obs_properties_add_int(props, "scroll_horizontal", obs_module_text("ScrollHorizontal"), 0, 326 | 10000000, 1); 327 | 328 | obs_properties_add_button(props, "reload", obs_module_text("ReloadPage"), 329 | reload_button_clicked); 330 | obs_properties_add_bool(props, "reload_on_scene", obs_module_text("ReloadOnScene")); 331 | 332 | obs_properties_add_path(props, "css_file", obs_module_text("CustomCSS"), OBS_PATH_FILE, 333 | "*.css", NULL); 334 | obs_properties_add_button(props, "css_file_reset", obs_module_text("CSSFileReset"), 335 | css_file_reset_button_clicked); 336 | obs_properties_add_path(props, "js_file", obs_module_text("CustomJS"), OBS_PATH_FILE, 337 | "*.js", NULL); 338 | obs_properties_add_button(props, "js_file_reset", obs_module_text("JSFileReset"), 339 | js_file_reset_button_clicked); 340 | 341 | obs_properties_add_path(props, "flash_path", obs_module_text("FlashPath"), OBS_PATH_FILE, 342 | "*.so", NULL); 343 | obs_properties_add_text(props, "flash_version", obs_module_text("FlashVersion"), 344 | OBS_TEXT_DEFAULT); 345 | obs_properties_add_editable_list(props, "cef_environment", 346 | obs_module_text("EnvironmentVariables"), 347 | OBS_EDITABLE_LIST_TYPE_STRINGS, NULL, NULL); 348 | obs_properties_add_editable_list(props, "cef_command_line", 349 | obs_module_text("CommandLineArguments"), 350 | OBS_EDITABLE_LIST_TYPE_STRINGS, NULL, NULL); 351 | 352 | obs_properties_add_button(props, "restart", obs_module_text("RestartBrowser"), 353 | restart_button_clicked); 354 | obs_properties_add_bool(props, "stop_on_hide", obs_module_text("StopOnHide")); 355 | 356 | return props; 357 | } 358 | 359 | static void browser_get_defaults(obs_data_t* settings) 360 | { 361 | obs_data_set_default_string(settings, "url", "http://www.obsproject.com"); 362 | obs_data_set_default_int(settings, "width", 800); 363 | obs_data_set_default_int(settings, "height", 600); 364 | obs_data_set_default_int(settings, "fps", 30); 365 | obs_data_set_default_string(settings, "flash_path", ""); 366 | obs_data_set_default_string(settings, "flash_version", ""); 367 | obs_data_set_default_int(settings, "zoom", 100); 368 | } 369 | 370 | static void browser_tick(void* vptr, float seconds) 371 | { 372 | UNUSED_PARAMETER(seconds); 373 | struct browser_data* data = vptr; 374 | pthread_mutex_lock(&data->textureLock); 375 | 376 | if (!data->activeTexture || !obs_source_showing(data->source)) { 377 | pthread_mutex_unlock(&data->textureLock); 378 | return; 379 | } 380 | 381 | lock_browser_manager(data->manager); 382 | obs_enter_graphics(); 383 | gs_texture_set_image(data->activeTexture, get_browser_manager_data(data->manager), 384 | data->width * 4, false); 385 | obs_leave_graphics(); 386 | unlock_browser_manager(data->manager); 387 | 388 | pthread_mutex_unlock(&data->textureLock); 389 | } 390 | 391 | static void browser_render(void* vptr, gs_effect_t* effect) 392 | { 393 | struct browser_data* data = vptr; 394 | pthread_mutex_lock(&data->textureLock); 395 | 396 | if (!data->activeTexture) { 397 | pthread_mutex_unlock(&data->textureLock); 398 | return; 399 | } 400 | 401 | gs_reset_blend_state(); 402 | gs_effect_set_texture(gs_effect_get_param_by_name(effect, "image"), data->activeTexture); 403 | gs_draw_sprite(data->activeTexture, 0, data->width, data->height); 404 | 405 | pthread_mutex_unlock(&data->textureLock); 406 | } 407 | 408 | static void browser_mouse_click(void* vptr, const struct obs_mouse_event* event, int32_t type, 409 | bool mouse_up, uint32_t click_count) 410 | { 411 | struct browser_data* data = vptr; 412 | browser_manager_send_mouse_click(data->manager, event->x, event->y, event->modifiers, type, 413 | mouse_up, click_count); 414 | } 415 | 416 | static void browser_mouse_move(void* vptr, const struct obs_mouse_event* event, bool mouse_leave) 417 | { 418 | struct browser_data* data = vptr; 419 | browser_manager_send_mouse_move(data->manager, event->x, event->y, event->modifiers, 420 | mouse_leave); 421 | } 422 | 423 | static void browser_mouse_wheel(void* vptr, const struct obs_mouse_event* event, int x_delta, 424 | int y_delta) 425 | { 426 | struct browser_data* data = vptr; 427 | browser_manager_send_mouse_wheel(data->manager, event->x, event->y, event->modifiers, 428 | x_delta, y_delta); 429 | } 430 | 431 | static void browser_focus(void* vptr, bool focus) 432 | { 433 | struct browser_data* data = vptr; 434 | browser_manager_send_focus(data->manager, focus); 435 | } 436 | 437 | 438 | static int custom_get_virtual_key(obs_key_t key) 439 | { 440 | switch (key) { 441 | case OBS_KEY_RETURN: return VK_RETURN; 442 | case OBS_KEY_ESCAPE: return VK_ESCAPE; 443 | case OBS_KEY_TAB: return VK_TAB; 444 | case OBS_KEY_BACKTAB: return VK_OEM_BACKTAB; 445 | case OBS_KEY_BACKSPACE: return VK_BACK; 446 | case OBS_KEY_INSERT: return VK_INSERT; 447 | case OBS_KEY_DELETE: return VK_DELETE; 448 | case OBS_KEY_PAUSE: return VK_PAUSE; 449 | case OBS_KEY_PRINT: return VK_SNAPSHOT; 450 | case OBS_KEY_CLEAR: return VK_CLEAR; 451 | case OBS_KEY_HOME: return VK_HOME; 452 | case OBS_KEY_END: return VK_END; 453 | case OBS_KEY_LEFT: return VK_LEFT; 454 | case OBS_KEY_UP: return VK_UP; 455 | case OBS_KEY_RIGHT: return VK_RIGHT; 456 | case OBS_KEY_DOWN: return VK_DOWN; 457 | case OBS_KEY_PAGEUP: return VK_PRIOR; 458 | case OBS_KEY_PAGEDOWN: return VK_NEXT; 459 | 460 | case OBS_KEY_SHIFT: return VK_SHIFT; 461 | case OBS_KEY_CONTROL: return VK_CONTROL; 462 | case OBS_KEY_ALT: return VK_MENU; 463 | case OBS_KEY_CAPSLOCK: return VK_CAPITAL; 464 | case OBS_KEY_NUMLOCK: return VK_NUMLOCK; 465 | case OBS_KEY_SCROLLLOCK: return VK_SCROLL; 466 | 467 | case OBS_KEY_F1: return VK_F1; 468 | case OBS_KEY_F2: return VK_F2; 469 | case OBS_KEY_F3: return VK_F3; 470 | case OBS_KEY_F4: return VK_F4; 471 | case OBS_KEY_F5: return VK_F5; 472 | case OBS_KEY_F6: return VK_F6; 473 | case OBS_KEY_F7: return VK_F7; 474 | case OBS_KEY_F8: return VK_F8; 475 | case OBS_KEY_F9: return VK_F9; 476 | case OBS_KEY_F10: return VK_F10; 477 | case OBS_KEY_F11: return VK_F11; 478 | case OBS_KEY_F12: return VK_F12; 479 | case OBS_KEY_F13: return VK_F13; 480 | case OBS_KEY_F14: return VK_F14; 481 | case OBS_KEY_F15: return VK_F15; 482 | case OBS_KEY_F16: return VK_F16; 483 | case OBS_KEY_F17: return VK_F17; 484 | case OBS_KEY_F18: return VK_F18; 485 | case OBS_KEY_F19: return VK_F19; 486 | case OBS_KEY_F20: return VK_F20; 487 | case OBS_KEY_F21: return VK_F21; 488 | case OBS_KEY_F22: return VK_F22; 489 | case OBS_KEY_F23: return VK_F23; 490 | case OBS_KEY_F24: return VK_F24; 491 | 492 | case OBS_KEY_SPACE: return VK_SPACE; 493 | 494 | case OBS_KEY_APOSTROPHE: return VK_OEM_7; 495 | case OBS_KEY_PLUS: return VK_OEM_PLUS; 496 | case OBS_KEY_COMMA: return VK_OEM_COMMA; 497 | case OBS_KEY_MINUS: return VK_OEM_MINUS; 498 | case OBS_KEY_PERIOD: return VK_OEM_PERIOD; 499 | case OBS_KEY_SLASH: return VK_OEM_2; 500 | case OBS_KEY_0: return '0'; 501 | case OBS_KEY_1: return '1'; 502 | case OBS_KEY_2: return '2'; 503 | case OBS_KEY_3: return '3'; 504 | case OBS_KEY_4: return '4'; 505 | case OBS_KEY_5: return '5'; 506 | case OBS_KEY_6: return '6'; 507 | case OBS_KEY_7: return '7'; 508 | case OBS_KEY_8: return '8'; 509 | case OBS_KEY_9: return '9'; 510 | case OBS_KEY_NUMASTERISK: return VK_MULTIPLY; 511 | case OBS_KEY_NUMPLUS: return VK_ADD; 512 | case OBS_KEY_NUMMINUS: return VK_SUBTRACT; 513 | case OBS_KEY_NUMPERIOD: return VK_DECIMAL; 514 | case OBS_KEY_NUMSLASH: return VK_DIVIDE; 515 | case OBS_KEY_NUM0: return VK_NUMPAD0; 516 | case OBS_KEY_NUM1: return VK_NUMPAD1; 517 | case OBS_KEY_NUM2: return VK_NUMPAD2; 518 | case OBS_KEY_NUM3: return VK_NUMPAD3; 519 | case OBS_KEY_NUM4: return VK_NUMPAD4; 520 | case OBS_KEY_NUM5: return VK_NUMPAD5; 521 | case OBS_KEY_NUM6: return VK_NUMPAD6; 522 | case OBS_KEY_NUM7: return VK_NUMPAD7; 523 | case OBS_KEY_NUM8: return VK_NUMPAD8; 524 | case OBS_KEY_NUM9: return VK_NUMPAD9; 525 | case OBS_KEY_SEMICOLON: return VK_OEM_1; 526 | case OBS_KEY_A: return 'A'; 527 | case OBS_KEY_B: return 'B'; 528 | case OBS_KEY_C: return 'C'; 529 | case OBS_KEY_D: return 'D'; 530 | case OBS_KEY_E: return 'E'; 531 | case OBS_KEY_F: return 'F'; 532 | case OBS_KEY_G: return 'G'; 533 | case OBS_KEY_H: return 'H'; 534 | case OBS_KEY_I: return 'I'; 535 | case OBS_KEY_J: return 'J'; 536 | case OBS_KEY_K: return 'K'; 537 | case OBS_KEY_L: return 'L'; 538 | case OBS_KEY_M: return 'M'; 539 | case OBS_KEY_N: return 'N'; 540 | case OBS_KEY_O: return 'O'; 541 | case OBS_KEY_P: return 'P'; 542 | case OBS_KEY_Q: return 'Q'; 543 | case OBS_KEY_R: return 'R'; 544 | case OBS_KEY_S: return 'S'; 545 | case OBS_KEY_T: return 'T'; 546 | case OBS_KEY_U: return 'U'; 547 | case OBS_KEY_V: return 'V'; 548 | case OBS_KEY_W: return 'W'; 549 | case OBS_KEY_X: return 'X'; 550 | case OBS_KEY_Y: return 'Y'; 551 | case OBS_KEY_Z: return 'Z'; 552 | case OBS_KEY_BRACKETLEFT: return VK_OEM_4; 553 | case OBS_KEY_BACKSLASH: return VK_OEM_5; 554 | case OBS_KEY_BRACKETRIGHT: return VK_OEM_6; 555 | case OBS_KEY_ASCIITILDE: return VK_OEM_3; 556 | 557 | case OBS_KEY_HENKAN: return VK_CONVERT; 558 | case OBS_KEY_MUHENKAN: return VK_NONCONVERT; 559 | case OBS_KEY_KANJI: return VK_KANJI; 560 | case OBS_KEY_TOUROKU: return VK_OEM_FJ_TOUROKU; 561 | case OBS_KEY_MASSYO: return VK_OEM_FJ_MASSHOU; 562 | 563 | case OBS_KEY_HANGUL: return VK_HANGUL; 564 | 565 | case OBS_KEY_BACKSLASH_RT102: return VK_OEM_102; 566 | 567 | case OBS_KEY_MOUSE1: return VK_LBUTTON; 568 | case OBS_KEY_MOUSE2: return VK_RBUTTON; 569 | case OBS_KEY_MOUSE3: return VK_MBUTTON; 570 | case OBS_KEY_MOUSE4: return VK_XBUTTON1; 571 | case OBS_KEY_MOUSE5: return VK_XBUTTON2; 572 | 573 | /* TODO: Implement keys for non-US keyboards */ 574 | default:; 575 | } 576 | return 0; 577 | } 578 | 579 | static void browser_key_click(void* vptr, const struct obs_key_event* event, bool key_up) 580 | { 581 | struct browser_data* data = vptr; 582 | char chr = 0; 583 | if (event->text) 584 | chr = event->text[0]; 585 | blog(LOG_INFO, "Key: %s %d %d %d", event->text, event->native_vkey, event->native_scancode, custom_get_virtual_key(obs_key_from_virtual_key(event->native_vkey))); 586 | 587 | browser_manager_send_key(data->manager, key_up, custom_get_virtual_key(obs_key_from_virtual_key(event->native_vkey)), event->modifiers, chr); 588 | } 589 | 590 | static void browser_source_activate(void* vptr) 591 | { 592 | reload_on_scene(vptr); 593 | 594 | struct browser_data* data = vptr; 595 | browser_manager_send_active_state_change(data->manager, true); 596 | } 597 | 598 | static void browser_source_deactivate(void* vptr) 599 | { 600 | struct browser_data* data = vptr; 601 | browser_manager_send_active_state_change(data->manager, false); 602 | } 603 | 604 | static void browser_source_show(void* vptr) 605 | { 606 | struct browser_data* data = vptr; 607 | browser_manager_send_visibility_change(data->manager, true); 608 | 609 | if (data->stop_on_hide) { 610 | browser_manager_start_browser(data->manager); 611 | browser_manager_change_css_file(data->manager, data->css_file); 612 | browser_manager_change_js_file(data->manager, data->js_file); 613 | browser_manager_change_url(data->manager, data->url); 614 | browser_manager_set_scrollbars(data->manager, !data->hide_scrollbars); 615 | browser_manager_set_zoom(data->manager, data->zoom); 616 | browser_manager_set_scroll(data->manager, data->scroll_vertical, 617 | data->scroll_horizontal); 618 | } 619 | } 620 | 621 | static void browser_source_hide(void* vptr) 622 | { 623 | struct browser_data* data = vptr; 624 | browser_manager_send_visibility_change(data->manager, false); 625 | 626 | if (data->stop_on_hide) 627 | browser_manager_stop_browser(data->manager); 628 | } 629 | 630 | bool obs_module_load(void) 631 | { 632 | struct obs_source_info info = {}; 633 | info.id = "linuxbrowser-source"; 634 | info.type = OBS_SOURCE_TYPE_INPUT; 635 | info.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_INTERACTION; 636 | 637 | info.get_name = browser_get_name; 638 | info.create = browser_create; 639 | info.destroy = browser_destroy; 640 | info.update = browser_update; 641 | info.get_width = browser_get_width; 642 | info.get_height = browser_get_height; 643 | info.get_properties = browser_get_properties; 644 | info.get_defaults = browser_get_defaults; 645 | info.video_tick = browser_tick; 646 | info.video_render = browser_render; 647 | 648 | info.mouse_click = browser_mouse_click; 649 | info.mouse_move = browser_mouse_move; 650 | info.mouse_wheel = browser_mouse_wheel; 651 | info.focus = browser_focus; 652 | info.key_click = browser_key_click; 653 | 654 | info.activate = browser_source_activate; 655 | info.deactivate = browser_source_deactivate; 656 | info.show = browser_source_show; 657 | info.hide = browser_source_hide; 658 | 659 | obs_register_source(&info); 660 | return true; 661 | } 662 | -------------------------------------------------------------------------------- /src/plugin/manager.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Azat Khasanshin 3 | Copyright (C) 2018 by Adrian Schollmeyer 4 | 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 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "manager.h" 30 | 31 | char* get_shm_name(const char* uid) 32 | { 33 | char* shm_name = bzalloc(SHM_MAX); 34 | snprintf(shm_name, SHM_MAX, "%s-%s", SHM_NAME, uid); 35 | // escape out '/' character 36 | char* current_pos = strchr(shm_name + 1, '/'); 37 | while (current_pos) { 38 | *current_pos = '|'; 39 | current_pos = strchr(current_pos, '/'); 40 | } 41 | return shm_name; 42 | } 43 | 44 | /* remove an optional set of matching quotes (single or double), 45 | * from the beginning and end of a string */ 46 | static char* remove_matching_quotes(char* val) 47 | { 48 | size_t len = strlen(val); 49 | if (len < 2) 50 | return val; 51 | 52 | char first = val[0]; 53 | char last = val[len - 1]; 54 | if (first != last || !strchr("'\"", first)) 55 | return val; 56 | 57 | val[len - 1] = '\0'; 58 | return val + 1; 59 | } 60 | 61 | /* mostly building strings for arguments and env variables for 62 | * browser process */ 63 | static void spawn_renderer(browser_manager_t* manager) 64 | { 65 | if (manager->spawned) 66 | return; 67 | 68 | char* bin_dir = bstrdup(obs_get_module_binary_path(obs_current_module())); 69 | char* s = strrchr(bin_dir, '/'); 70 | if (s) 71 | *(s + 1) = '\0'; 72 | 73 | const char* sflash_path = obs_data_get_string(manager->settings, "flash_path"); 74 | const char* sflash_version = obs_data_get_string(manager->settings, "flash_version"); 75 | 76 | size_t flash_path_size = strlen("--ppapi-flash-path=") + strlen(sflash_path) + 1; 77 | char* flash_path = bzalloc(flash_path_size); 78 | snprintf(flash_path, flash_path_size, "--ppapi-flash-path=%s", sflash_path); 79 | 80 | size_t flash_version_size = strlen("--ppapi-flash-version=") + strlen(sflash_version) + 1; 81 | char* flash_version = bzalloc(flash_version_size); 82 | snprintf(flash_version, flash_version_size, "--ppapi-flash-version=%s", sflash_version); 83 | 84 | size_t renderer_size = strlen(bin_dir) + strlen("browser") + 1; 85 | char* renderer = bzalloc(renderer_size); 86 | snprintf(renderer, renderer_size, "%sbrowser", bin_dir); 87 | 88 | char* data_path = (char*) obs_get_module_data_path(obs_current_module()); 89 | 90 | obs_data_array_t* env_vars = obs_data_get_array(manager->settings, "cef_environment"); 91 | size_t env_num = obs_data_array_count(env_vars); 92 | 93 | obs_data_array_t* command_lines = obs_data_get_array(manager->settings, "cef_command_line"); 94 | size_t arg_num = 6 + obs_data_array_count(command_lines); 95 | 96 | char** argv = bzalloc(sizeof(char*) * arg_num); 97 | argv[0] = renderer; 98 | argv[1] = data_path; 99 | argv[2] = manager->shmname; 100 | argv[3] = flash_path; 101 | argv[4] = flash_version; 102 | 103 | for (int i = 0; i < arg_num - 6; ++i) { 104 | obs_data_t* item = obs_data_array_item(command_lines, i); 105 | const char* value = obs_data_get_string(item, "value"); 106 | argv[5 + i] = bstrdup(value); 107 | obs_data_release(item); 108 | } 109 | 110 | argv[arg_num - 1] = NULL; 111 | 112 | manager->pid = fork(); 113 | if (manager->pid == 0) { 114 | setenv("LD_LIBRARY_PATH", bin_dir, 1); 115 | for (int i = 0; i < env_num; ++i) { 116 | obs_data_t* item = obs_data_array_item(env_vars, i); 117 | const char* value = obs_data_get_string(item, "value"); 118 | char* entry = bstrdup(value); 119 | /* split entry "env_name=env_val" */ 120 | char* env_name = strtok(entry, "="); 121 | char* env_val = strtok(NULL, ""); 122 | if (env_name && env_val) { 123 | env_val = remove_matching_quotes(env_val); 124 | setenv(env_name, env_val, 1); 125 | } 126 | bfree(entry); 127 | obs_data_release(item); 128 | } 129 | execv(renderer, argv); 130 | } 131 | 132 | for (int i = 0; i < arg_num - 6; ++i) { 133 | bfree(argv[5 + i]); 134 | } 135 | obs_data_array_release(command_lines); 136 | bfree(argv); 137 | 138 | bfree(bin_dir); 139 | bfree(flash_path); 140 | bfree(flash_version); 141 | bfree(renderer); 142 | 143 | manager->spawned = true; 144 | } 145 | 146 | static void kill_renderer(browser_manager_t* manager) 147 | { 148 | if (manager->pid > 0) { 149 | kill(manager->pid, SIGTERM); 150 | waitpid(manager->pid, NULL, 0); 151 | manager->spawned = false; 152 | } 153 | } 154 | 155 | /* setting up shared data for the browser process */ 156 | browser_manager_t* create_browser_manager(uint32_t width, uint32_t height, int fps, 157 | obs_data_t* settings, const char* uid) 158 | { 159 | if (width > MAX_BROWSER_WIDTH || height > MAX_BROWSER_HEIGHT) 160 | return NULL; 161 | 162 | struct browser_manager* manager = bzalloc(sizeof(struct browser_manager)); 163 | manager->settings = settings; 164 | 165 | manager->qid = msgget(IPC_PRIVATE, S_IRUSR | S_IWUSR); 166 | if (manager->qid == -1) { 167 | blog(LOG_ERROR, "msgget error"); 168 | return NULL; 169 | } 170 | 171 | manager->shmname = get_shm_name(uid); 172 | manager->fd = shm_open(manager->shmname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); 173 | if (manager->fd == -1) { 174 | blog(LOG_ERROR, "shm_open error"); 175 | return NULL; 176 | } 177 | if (ftruncate(manager->fd, sizeof(struct shared_data) + MAX_DATA_SIZE) == -1) { 178 | blog(LOG_ERROR, "ftruncate error"); 179 | return NULL; 180 | } 181 | manager->data = 182 | (struct shared_data*) mmap(NULL, sizeof(struct shared_data) + MAX_DATA_SIZE, 183 | PROT_READ | PROT_WRITE, MAP_SHARED, manager->fd, 0); 184 | if (manager->data == MAP_FAILED) { 185 | blog(LOG_ERROR, "mmap error"); 186 | return NULL; 187 | } 188 | manager->data->qid = manager->qid; 189 | manager->data->width = width; 190 | manager->data->height = height; 191 | manager->data->fps = fps; 192 | 193 | pthread_mutexattr_t attrmutex; 194 | pthread_mutexattr_init(&attrmutex); 195 | pthread_mutexattr_setpshared(&attrmutex, PTHREAD_PROCESS_SHARED); 196 | pthread_mutex_init(&manager->data->mutex, &attrmutex); 197 | 198 | spawn_renderer(manager); 199 | 200 | return manager; 201 | }; 202 | 203 | void destroy_browser_manager(browser_manager_t* manager) 204 | { 205 | kill_renderer(manager); 206 | pthread_mutex_destroy(&manager->data->mutex); 207 | if (manager->data != NULL && manager->data != MAP_FAILED) 208 | munmap(manager->data, sizeof(struct shared_data) + MAX_DATA_SIZE); 209 | if (manager->fd != -1 && manager->shmname != NULL) { 210 | shm_unlink(manager->shmname); 211 | } 212 | if (manager->shmname) 213 | bfree(manager->shmname); 214 | bfree(manager); 215 | } 216 | 217 | void lock_browser_manager(browser_manager_t* manager) 218 | { 219 | pthread_mutex_lock(&manager->data->mutex); 220 | } 221 | 222 | void unlock_browser_manager(browser_manager_t* manager) 223 | { 224 | pthread_mutex_unlock(&manager->data->mutex); 225 | } 226 | 227 | uint8_t* get_browser_manager_data(browser_manager_t* manager) 228 | { 229 | return &manager->data->data; 230 | } 231 | 232 | void browser_manager_change_url(browser_manager_t* manager, const char* url) 233 | { 234 | if (manager->qid == -1) 235 | return; 236 | 237 | if (strlen(url) < (MAX_MESSAGE_SIZE - 1)) { 238 | browser_message_t buf; 239 | buf.text.type = MESSAGE_TYPE_URL; 240 | strncpy(buf.text.text, url, MAX_MESSAGE_SIZE - 1); 241 | 242 | msgsnd(manager->qid, &buf, strlen(url) + 1, 0); 243 | } else { 244 | uint8_t packages = ceil((double) strlen(url) / (double) (MAX_MESSAGE_SIZE - 3)); 245 | 246 | static uint8_t split_id = 0; 247 | split_id++; 248 | for (uint8_t i = 0; i < packages; i++) { 249 | browser_message_t buf; 250 | buf.split_text.id = split_id; 251 | buf.split_text.count = i; 252 | buf.split_text.max = packages; 253 | buf.split_text.type = MESSAGE_TYPE_URL_LONG; 254 | 255 | strncpy(buf.split_text.text, &url[i * (MAX_MESSAGE_SIZE - 3)], 256 | MAX_MESSAGE_SIZE - 3); 257 | msgsnd(manager->qid, &buf, strlen(buf.split_text.text) + 3, 0); 258 | } 259 | } 260 | } 261 | 262 | void browser_manager_change_css_file(browser_manager_t* manager, const char* css_file) 263 | { 264 | if (manager->qid == -1) 265 | return; 266 | 267 | browser_message_t buf; 268 | buf.text.type = MESSAGE_TYPE_CSS; 269 | strncpy(buf.text.text, css_file, MAX_MESSAGE_SIZE); 270 | 271 | msgsnd(manager->qid, &buf, strlen(css_file) + 1, 0); 272 | } 273 | 274 | void browser_manager_change_js_file(browser_manager_t* manager, const char* js_file) 275 | { 276 | if (manager->qid < 0) 277 | return; 278 | 279 | browser_message_t buf; 280 | buf.text.type = MESSAGE_TYPE_JS; 281 | strncpy(buf.text.text, js_file, MAX_MESSAGE_SIZE); 282 | 283 | msgsnd(manager->qid, &buf, strlen(js_file) + 1, 0); 284 | } 285 | 286 | void browser_manager_change_size(browser_manager_t* manager, uint32_t width, uint32_t height) 287 | { 288 | pthread_mutex_lock(&manager->data->mutex); 289 | 290 | manager->data->width = width; 291 | manager->data->height = height; 292 | 293 | if (manager->qid == -1) 294 | return; 295 | 296 | browser_message_t buf; 297 | buf.generic.type = MESSAGE_TYPE_SIZE; 298 | msgsnd(manager->qid, &buf, 0, 0); 299 | 300 | pthread_mutex_unlock(&manager->data->mutex); 301 | } 302 | 303 | void browser_manager_set_scrollbars(browser_manager_t* manager, bool show) 304 | { 305 | if (manager->qid == -1) 306 | return; 307 | 308 | browser_message_t buf; 309 | buf.generic_state.type = MESSAGE_TYPE_SCROLLBARS; 310 | buf.generic_state.state = show; 311 | msgsnd(manager->qid, &buf, 1, 0); 312 | } 313 | 314 | void browser_manager_set_zoom(browser_manager_t* manager, uint32_t zoom) 315 | { 316 | if (manager->qid == -1) 317 | return; 318 | 319 | browser_message_t buf; 320 | buf.zoom.type = MESSAGE_TYPE_ZOOM; 321 | buf.zoom.zoom = zoom; 322 | msgsnd(manager->qid, &buf, sizeof(zoom), 0); 323 | } 324 | 325 | void browser_manager_set_scroll(browser_manager_t* manager, uint32_t vertical, uint32_t horizontal) 326 | { 327 | if (manager->qid == -1) 328 | return; 329 | 330 | browser_message_t buf; 331 | buf.scroll.type = MESSAGE_TYPE_SCROLL; 332 | buf.scroll.vertical = vertical; 333 | buf.scroll.horizontal = horizontal; 334 | msgsnd(manager->qid, &buf, sizeof(vertical) + sizeof(horizontal), 0); 335 | } 336 | 337 | void browser_manager_reload_page(browser_manager_t* manager) 338 | { 339 | if (manager->qid == -1) 340 | return; 341 | 342 | browser_message_t buf; 343 | buf.generic.type = MESSAGE_TYPE_RELOAD; 344 | msgsnd(manager->qid, &buf, 0, 0); 345 | } 346 | 347 | void browser_manager_restart_browser(browser_manager_t* manager) 348 | { 349 | pthread_mutex_lock(&manager->data->mutex); 350 | kill_renderer(manager); 351 | spawn_renderer(manager); 352 | pthread_mutex_unlock(&manager->data->mutex); 353 | } 354 | 355 | void browser_manager_start_browser(browser_manager_t* manager) 356 | { 357 | pthread_mutex_lock(&manager->data->mutex); 358 | // TODO Double spawn prevention? 359 | spawn_renderer(manager); 360 | pthread_mutex_unlock(&manager->data->mutex); 361 | } 362 | 363 | void browser_manager_stop_browser(browser_manager_t* manager) 364 | { 365 | pthread_mutex_lock(&manager->data->mutex); 366 | // TODO Double kill prevention? 367 | kill_renderer(manager); 368 | pthread_mutex_unlock(&manager->data->mutex); 369 | } 370 | 371 | void browser_manager_send_mouse_click(browser_manager_t* manager, int32_t x, int32_t y, 372 | uint32_t modifiers, int32_t button_type, bool mouse_up, 373 | uint32_t click_count) 374 | { 375 | if (manager->qid == -1) 376 | return; 377 | 378 | browser_message_t buf; 379 | buf.mouse_click.type = MESSAGE_TYPE_MOUSE_CLICK; 380 | buf.mouse_click.x = x; 381 | buf.mouse_click.y = y; 382 | buf.mouse_click.modifiers = modifiers; 383 | buf.mouse_click.button_type = button_type; 384 | buf.mouse_click.mouse_up = mouse_up; 385 | buf.mouse_click.click_count = click_count; 386 | 387 | msgsnd(manager->qid, &buf, sizeof(buf), 0); 388 | } 389 | 390 | void browser_manager_send_mouse_move(browser_manager_t* manager, int32_t x, int32_t y, 391 | uint32_t modifiers, bool mouse_leave) 392 | { 393 | if (manager->qid == -1) 394 | return; 395 | 396 | // struct mouse_move_message buf; 397 | browser_message_t buf; 398 | buf.mouse_move.type = MESSAGE_TYPE_MOUSE_MOVE; 399 | buf.mouse_move.x = x; 400 | buf.mouse_move.y = y; 401 | buf.mouse_move.modifiers = modifiers; 402 | buf.mouse_move.mouse_leave = mouse_leave; 403 | 404 | msgsnd(manager->qid, &buf, sizeof(buf), 0); 405 | } 406 | 407 | void browser_manager_send_mouse_wheel(browser_manager_t* manager, int32_t x, int32_t y, 408 | uint32_t modifiers, int x_delta, int y_delta) 409 | { 410 | if (manager->qid == -1) 411 | return; 412 | 413 | browser_message_t buf; 414 | buf.mouse_wheel.type = MESSAGE_TYPE_MOUSE_WHEEL; 415 | buf.mouse_wheel.x = x; 416 | buf.mouse_wheel.y = y; 417 | buf.mouse_wheel.modifiers = modifiers; 418 | buf.mouse_wheel.x_delta = x_delta; 419 | buf.mouse_wheel.y_delta = y_delta; 420 | 421 | msgsnd(manager->qid, &buf, sizeof(buf), 0); 422 | } 423 | 424 | void browser_manager_send_focus(browser_manager_t* manager, bool focus) 425 | { 426 | if (manager->qid == -1) 427 | return; 428 | 429 | browser_message_t buf; 430 | buf.focus.type = MESSAGE_TYPE_FOCUS; 431 | buf.focus.focus = focus; 432 | 433 | msgsnd(manager->qid, &buf, sizeof(buf), 0); 434 | } 435 | 436 | void browser_manager_send_key(browser_manager_t* manager, bool key_up, uint32_t native_vkey, 437 | uint32_t modifiers, char chr) 438 | { 439 | if (manager->qid == -1) 440 | return; 441 | 442 | browser_message_t buf; 443 | buf.key.type = MESSAGE_TYPE_KEY; 444 | buf.key.key_up = key_up; 445 | buf.key.native_vkey = native_vkey; 446 | buf.key.modifiers = modifiers; 447 | buf.key.chr = chr; 448 | 449 | msgsnd(manager->qid, &buf, sizeof(buf), 0); 450 | } 451 | 452 | void browser_manager_send_active_state_change(browser_manager_t* manager, bool active) 453 | { 454 | if (manager->qid == -1) 455 | return; 456 | 457 | browser_message_t buf; 458 | buf.active_state.type = MESSAGE_TYPE_ACTIVE_STATE_CHANGE; 459 | buf.active_state.active = active; 460 | msgsnd(manager->qid, &buf, sizeof(buf), 0); 461 | } 462 | 463 | void browser_manager_send_visibility_change(browser_manager_t* manager, bool visible) 464 | { 465 | if (manager->qid == -1) 466 | return; 467 | 468 | browser_message_t buf; 469 | buf.visibility.type = MESSAGE_TYPE_VISIBILITY_CHANGE; 470 | buf.visibility.visible = visible; 471 | msgsnd(manager->qid, &buf, sizeof(buf), 0); 472 | } 473 | -------------------------------------------------------------------------------- /src/plugin/manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Azat Khasanshin 3 | Copyright (C) 2018 by Adrian Schollmeyer 4 | 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 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | 21 | #include 22 | 23 | #include "shared.h" 24 | 25 | #define blog(level, msg, ...) blog(level, "obs-linuxbrowser: " msg, ##__VA_ARGS__) 26 | 27 | typedef struct browser_manager { 28 | int fd; 29 | int pid; 30 | int qid; 31 | char* shmname; 32 | obs_data_t* settings; 33 | struct shared_data* data; 34 | bool spawned; 35 | } browser_manager_t; 36 | 37 | browser_manager_t* create_browser_manager(uint32_t width, uint32_t height, int fps, 38 | obs_data_t* settings, const char* uid); 39 | void destroy_browser_manager(browser_manager_t* manager); 40 | void lock_browser_manager(browser_manager_t* manager); 41 | void unlock_browser_manager(browser_manager_t* manager); 42 | uint8_t* get_browser_manager_data(browser_manager_t* manager); 43 | 44 | void browser_manager_change_url(browser_manager_t* manager, const char* url); 45 | void browser_manager_change_css_file(browser_manager_t* manager, const char* css_file); 46 | void browser_manager_change_js_file(browser_manager_t* manager, const char* js_file); 47 | void browser_manager_change_size(browser_manager_t* manager, uint32_t width, uint32_t height); 48 | void browser_manager_set_scrollbars(browser_manager_t* manager, bool show); 49 | void browser_manager_set_zoom(browser_manager_t* manager, uint32_t zoom); 50 | void browser_manager_set_scroll(browser_manager_t* manager, uint32_t vertical, uint32_t horizontal); 51 | void browser_manager_reload_page(browser_manager_t* manager); 52 | void browser_manager_restart_browser(browser_manager_t* manager); 53 | void browser_manager_start_browser(browser_manager_t* manager); 54 | void browser_manager_stop_browser(browser_manager_t* manager); 55 | 56 | void browser_manager_send_mouse_click(browser_manager_t* manager, int32_t x, int32_t y, 57 | uint32_t modifiers, int32_t button_type, bool mouse_up, 58 | uint32_t click_count); 59 | void browser_manager_send_mouse_move(browser_manager_t* manager, int32_t x, int32_t y, 60 | uint32_t modifiers, bool mouse_leave); 61 | void browser_manager_send_mouse_wheel(browser_manager_t* manager, int32_t x, int32_t y, 62 | uint32_t modifiers, int x_delta, int y_delta); 63 | void browser_manager_send_focus(browser_manager_t* manager, bool focus); 64 | void browser_manager_send_key(browser_manager_t* manager, bool key_up, uint32_t native_vkey, 65 | uint32_t modifiers, char chr); 66 | void browser_manager_send_active_state_change(browser_manager_t* manager, bool active); 67 | void browser_manager_send_visibility_change(browser_manager_t* manager, bool visible); 68 | -------------------------------------------------------------------------------- /src/plugin/windows_keycode.h: -------------------------------------------------------------------------------- 1 | #ifndef VK_UNKNOWN 2 | 3 | #define VK_UNKNOWN 0 4 | 5 | // Left mouse button 6 | #ifndef VK_LBUTTON 7 | #define VK_LBUTTON 0x01 8 | #endif 9 | // Right mouse button 10 | #ifndef VK_RBUTTON 11 | #define VK_RBUTTON 0x02 12 | #endif 13 | // Middle mouse button (three-button mouse) 14 | #ifndef VK_MBUTTON 15 | #define VK_MBUTTON 0x04 16 | #endif 17 | #ifndef VK_XBUTTON1 18 | #define VK_XBUTTON1 0x05 19 | #endif 20 | #ifndef VK_XBUTTON2 21 | #define VK_XBUTTON2 0x06 22 | #endif 23 | 24 | #ifndef VK_BACK 25 | #define VK_BACK 0x08 26 | #endif 27 | #ifndef VK_TAB 28 | #define VK_TAB 0x09 29 | #endif 30 | #ifndef VK_CLEAR 31 | #define VK_CLEAR 0x0C 32 | #endif 33 | #ifndef VK_RETURN 34 | #define VK_RETURN 0x0D 35 | #endif 36 | #ifndef VK_SHIFT 37 | #define VK_SHIFT 0x10 38 | #endif 39 | #ifndef VK_CONTROL 40 | #define VK_CONTROL 0x11 // CTRL key 41 | #endif 42 | #ifndef VK_MENU 43 | #define VK_MENU 0x12 // ALT key 44 | #endif 45 | #ifndef VK_PAUSE 46 | #define VK_PAUSE 0x13 // PAUSE key 47 | #endif 48 | #ifndef VK_CAPITAL 49 | #define VK_CAPITAL 0x14 // CAPS LOCK key 50 | #endif 51 | #ifndef VK_KANA 52 | #define VK_KANA 0x15 // Input Method Editor (IME) Kana mode 53 | #endif 54 | #ifndef VK_HANGUL 55 | #define VK_HANGUL 0x15 // IME Hangul mode 56 | #endif 57 | #ifndef VK_JUNJA 58 | #define VK_JUNJA 0x17 // IME Junja mode 59 | #endif 60 | #ifndef VK_FINAL 61 | #define VK_FINAL 0x18 // IME final mode 62 | #endif 63 | #ifndef VK_HANJA 64 | #define VK_HANJA 0x19 // IME Hanja mode 65 | #endif 66 | #ifndef VK_KANJI 67 | #define VK_KANJI 0x19 // IME Kanji mode 68 | #endif 69 | #ifndef VK_ESCAPE 70 | #define VK_ESCAPE 0x1B // ESC key 71 | #endif 72 | #ifndef VK_CONVERT 73 | #define VK_CONVERT 0x1C // IME convert 74 | #endif 75 | #ifndef VK_NONCONVERT 76 | #define VK_NONCONVERT 0x1D // IME nonconvert 77 | #endif 78 | #ifndef VK_ACCEPT 79 | #define VK_ACCEPT 0x1E // IME accept 80 | #endif 81 | #ifndef VK_MODECHANGE 82 | #define VK_MODECHANGE 0x1F // IME mode change request 83 | #endif 84 | #ifndef VK_SPACE 85 | #define VK_SPACE 0x20 // SPACE key 86 | #endif 87 | #ifndef VK_PRIOR 88 | #define VK_PRIOR 0x21 // PAGE UP key 89 | #endif 90 | #ifndef VK_NEXT 91 | #define VK_NEXT 0x22 // PAGE DOWN key 92 | #endif 93 | #ifndef VK_END 94 | #define VK_END 0x23 // END key 95 | #endif 96 | #ifndef VK_HOME 97 | #define VK_HOME 0x24 // HOME key 98 | #endif 99 | #ifndef VK_LEFT 100 | #define VK_LEFT 0x25 // LEFT ARROW key 101 | #endif 102 | #ifndef VK_UP 103 | #define VK_UP 0x26 // UP ARROW key 104 | #endif 105 | #ifndef VK_RIGHT 106 | #define VK_RIGHT 0x27 // RIGHT ARROW key 107 | #endif 108 | #ifndef VK_DOWN 109 | #define VK_DOWN 0x28 // DOWN ARROW key 110 | #endif 111 | #ifndef VK_SELECT 112 | #define VK_SELECT 0x29 // SELECT key 113 | #endif 114 | #ifndef VK_PRINT 115 | #define VK_PRINT 0x2A // PRINT key 116 | #endif 117 | #ifndef VK_EXECUTE 118 | #define VK_EXECUTE 0x2B // EXECUTE key 119 | #endif 120 | #ifndef VK_SNAPSHOT 121 | #define VK_SNAPSHOT 0x2C // PRINT SCREEN key 122 | #endif 123 | #ifndef VK_INSERT 124 | #define VK_INSERT 0x2D // INS key 125 | #endif 126 | #ifndef VK_DELETE 127 | #define VK_DELETE 0x2E // DEL key 128 | #endif 129 | #ifndef VK_HELP 130 | #define VK_HELP 0x2F // HELP key 131 | #endif 132 | 133 | #define VK_0 0x30 134 | #define VK_1 0x31 135 | #define VK_2 0x32 136 | #define VK_3 0x33 137 | #define VK_4 0x34 138 | #define VK_5 0x35 139 | #define VK_6 0x36 140 | #define VK_7 0x37 141 | #define VK_8 0x38 142 | #define VK_9 0x39 143 | #define VK_A 0x41 144 | #define VK_B 0x42 145 | #define VK_C 0x43 146 | #define VK_D 0x44 147 | #define VK_E 0x45 148 | #define VK_F 0x46 149 | #define VK_G 0x47 150 | #define VK_H 0x48 151 | #define VK_I 0x49 152 | #define VK_J 0x4A 153 | #define VK_K 0x4B 154 | #define VK_L 0x4C 155 | #define VK_M 0x4D 156 | #define VK_N 0x4E 157 | #define VK_O 0x4F 158 | #define VK_P 0x50 159 | #define VK_Q 0x51 160 | #define VK_R 0x52 161 | #define VK_S 0x53 162 | #define VK_T 0x54 163 | #define VK_U 0x55 164 | #define VK_V 0x56 165 | #define VK_W 0x57 166 | #define VK_X 0x58 167 | #define VK_Y 0x59 168 | #define VK_Z 0x5A 169 | 170 | #define VK_LWIN 0x5B // Left Windows key (Microsoft Natural keyboard) 171 | 172 | #define VK_RWIN 0x5C // Right Windows key (Natural keyboard) 173 | 174 | #define VK_APPS 0x5D // Applications key (Natural keyboard) 175 | 176 | #define VK_SLEEP 0x5F // Computer Sleep key 177 | 178 | // Num pad keys 179 | #define VK_NUMPAD0 0x60 180 | #define VK_NUMPAD1 0x61 181 | #define VK_NUMPAD2 0x62 182 | #define VK_NUMPAD3 0x63 183 | #define VK_NUMPAD4 0x64 184 | #define VK_NUMPAD5 0x65 185 | #define VK_NUMPAD6 0x66 186 | #define VK_NUMPAD7 0x67 187 | #define VK_NUMPAD8 0x68 188 | #define VK_NUMPAD9 0x69 189 | #define VK_MULTIPLY 0x6A 190 | #define VK_ADD 0x6B 191 | #define VK_SEPARATOR 0x6C 192 | #define VK_SUBTRACT 0x6D 193 | #define VK_DECIMAL 0x6E 194 | #define VK_DIVIDE 0x6F 195 | 196 | #define VK_F1 0x70 197 | #define VK_F2 0x71 198 | #define VK_F3 0x72 199 | #define VK_F4 0x73 200 | #define VK_F5 0x74 201 | #define VK_F6 0x75 202 | #define VK_F7 0x76 203 | #define VK_F8 0x77 204 | #define VK_F9 0x78 205 | #define VK_F10 0x79 206 | #define VK_F11 0x7A 207 | #define VK_F12 0x7B 208 | #define VK_F13 0x7C 209 | #define VK_F14 0x7D 210 | #define VK_F15 0x7E 211 | #define VK_F16 0x7F 212 | #define VK_F17 0x80 213 | #define VK_F18 0x81 214 | #define VK_F19 0x82 215 | #define VK_F20 0x83 216 | #define VK_F21 0x84 217 | #define VK_F22 0x85 218 | #define VK_F23 0x86 219 | #define VK_F24 0x87 220 | 221 | #define VK_NUMLOCK 0x90 222 | #define VK_SCROLL 0x91 223 | #define VK_LSHIFT 0xA0 224 | #define VK_RSHIFT 0xA1 225 | #define VK_LCONTROL 0xA2 226 | #define VK_RCONTROL 0xA3 227 | #define VK_LMENU 0xA4 228 | #define VK_RMENU 0xA5 229 | 230 | #define VK_BROWSER_BACK 0xA6 // Windows 2000/XP: Browser Back key 231 | #define VK_BROWSER_FORWARD 0xA7 // Windows 2000/XP: Browser Forward key 232 | #define VK_BROWSER_REFRESH 0xA8 // Windows 2000/XP: Browser Refresh key 233 | #define VK_BROWSER_STOP 0xA9 // Windows 2000/XP: Browser Stop key 234 | #define VK_BROWSER_SEARCH 0xAA // Windows 2000/XP: Browser Search key 235 | #define VK_BROWSER_FAVORITES 0xAB // Windows 2000/XP: Browser Favorites key 236 | #define VK_BROWSER_HOME 0xAC // Windows 2000/XP: Browser Start and Home key 237 | #define VK_VOLUME_MUTE 0xAD // Windows 2000/XP: Volume Mute key 238 | #define VK_VOLUME_DOWN 0xAE // Windows 2000/XP: Volume Down key 239 | #define VK_VOLUME_UP 0xAF // Windows 2000/XP: Volume Up key 240 | #define VK_MEDIA_NEXT_TRACK 0xB0 // Windows 2000/XP: Next Track key 241 | #define VK_MEDIA_PREV_TRACK 0xB1 // Windows 2000/XP: Previous Track key 242 | #define VK_MEDIA_STOP 0xB2 // Windows 2000/XP: Stop Media key 243 | #define VK_MEDIA_PLAY_PAUSE 0xB3 // Windows 2000/XP: Play/Pause Media key 244 | #define VK_MEDIA_LAUNCH_MAIL 0xB4 // Windows 2000/XP: Start Mail key 245 | #define VK_MEDIA_LAUNCH_MEDIA_SELECT 0xB5 // Windows 2000/XP: Select Media key 246 | #define VK_MEDIA_LAUNCH_APP1 0xB6 // VK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key 247 | #define VK_MEDIA_LAUNCH_APP2 0xB7 // VK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key 248 | 249 | // VK_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key 250 | #define VK_OEM_1 0xBA 251 | 252 | // Windows 2000/XP: For any country/region, the '+' key 253 | #define VK_OEM_PLUS 0xBB 254 | 255 | // Windows 2000/XP: For any country/region, the ',' key 256 | #define VK_OEM_COMMA 0xBC 257 | 258 | // Windows 2000/XP: For any country/region, the '-' key 259 | #define VK_OEM_MINUS 0xBD 260 | 261 | // Windows 2000/XP: For any country/region, the '.' key 262 | #define VK_OEM_PERIOD 0xBE 263 | 264 | // VK_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key 265 | #define VK_OEM_2 0xBF 266 | 267 | // VK_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key 268 | #define VK_OEM_3 0xC0 269 | 270 | // VK_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key 271 | #define VK_OEM_4 0xDB 272 | 273 | // VK_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key 274 | #define VK_OEM_5 0xDC 275 | 276 | // VK_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key 277 | #define VK_OEM_6 0xDD 278 | 279 | // VK_OEM_7 (DE) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key 280 | #define VK_OEM_7 0xDE 281 | 282 | // VK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard. 283 | #define VK_OEM_8 0xDF 284 | 285 | // VK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard 286 | #define VK_OEM_102 0xE2 287 | 288 | #define VK_OEM_BACKTAB 0xF5 289 | #define VK_OEM_FJ_TOUROKU 0x94 290 | #define VK_OEM_FJ_MASSHOU 0x93 291 | 292 | // Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key 293 | #define VK_PROCESSKEY 0xE5 294 | 295 | // Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP 296 | #define VK_PACKET 0xE7 297 | 298 | #define VK_ATTN 0xF6 // Attn key 299 | #define VK_CRSEL 0xF7 // CrSel key 300 | #define VK_EXSEL 0xF8 // ExSel key 301 | #define VK_EREOF 0xF9 // Erase EOF key 302 | #define VK_PLAY 0xFA // Play key 303 | #define VK_ZOOM 0xFB // Zoom key 304 | 305 | #define VK_NONAME 0xFC // Reserved for future use 306 | 307 | #define VK_PA1 0xFD // VK_PA1 (FD) PA1 key 308 | 309 | #define VK_OEM_CLEAR 0xFE // Clear key 310 | 311 | #endif // VK_UNKNOWN 312 | -------------------------------------------------------------------------------- /src/shared.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 by Azat Khasanshin 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 2 of the License, or 7 | (at your option) any later version. 8 | 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 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #define SHM_NAME "/linuxbrowser" 21 | #define SHM_MAX 50 22 | 23 | #define MAX_BROWSER_WIDTH 4096 24 | #define MAX_BROWSER_HEIGHT 4096 25 | #define MAX_DATA_SIZE MAX_BROWSER_WIDTH* MAX_BROWSER_HEIGHT * 4 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | typedef struct shared_data { 32 | pthread_mutex_t mutex; 33 | int qid; 34 | int fps; 35 | uint32_t width; 36 | uint32_t height; 37 | uint8_t data; 38 | } shared_data_t; 39 | 40 | #define MAX_MESSAGE_SIZE 1024 41 | #define MESSAGE_TYPE_URL 1 42 | #define MESSAGE_TYPE_SIZE 2 43 | #define MESSAGE_TYPE_RELOAD 3 44 | #define MESSAGE_TYPE_CSS 4 45 | #define MESSAGE_TYPE_MOUSE_CLICK 5 46 | #define MESSAGE_TYPE_MOUSE_MOVE 6 47 | #define MESSAGE_TYPE_MOUSE_WHEEL 7 48 | #define MESSAGE_TYPE_FOCUS 8 49 | #define MESSAGE_TYPE_KEY 9 50 | #define MESSAGE_TYPE_SCROLLBARS 10 51 | #define MESSAGE_TYPE_ZOOM 11 52 | #define MESSAGE_TYPE_SCROLL 12 53 | #define MESSAGE_TYPE_ACTIVE_STATE_CHANGE 13 54 | #define MESSAGE_TYPE_VISIBILITY_CHANGE 14 55 | #define MESSAGE_TYPE_URL_LONG 15 56 | #define MESSAGE_TYPE_JS 16 57 | 58 | typedef union { 59 | struct { 60 | long type; 61 | uint8_t data[MAX_MESSAGE_SIZE]; 62 | } generic; 63 | 64 | struct { 65 | long type; 66 | bool state; 67 | } generic_state; 68 | 69 | struct { 70 | long type; 71 | char text[MAX_MESSAGE_SIZE]; 72 | } text; 73 | 74 | struct { 75 | long type; 76 | uint8_t id; 77 | uint8_t count; 78 | uint8_t max; 79 | char text[MAX_MESSAGE_SIZE - 3]; 80 | } split_text; 81 | 82 | struct { 83 | long type; 84 | int32_t x; 85 | int32_t y; 86 | uint32_t modifiers; 87 | int32_t button_type; 88 | bool mouse_up; 89 | uint32_t click_count; 90 | } mouse_click; 91 | 92 | struct { 93 | long type; 94 | int32_t x; 95 | int32_t y; 96 | uint32_t modifiers; 97 | bool mouse_leave; 98 | } mouse_move; 99 | 100 | struct { 101 | long type; 102 | int32_t x; 103 | int32_t y; 104 | uint32_t modifiers; 105 | int x_delta; 106 | int y_delta; 107 | } mouse_wheel; 108 | 109 | struct { 110 | long type; 111 | bool focus; 112 | } focus; 113 | 114 | struct { 115 | long type; 116 | bool key_up; 117 | uint32_t native_vkey; 118 | uint32_t modifiers; 119 | char chr; 120 | } key; 121 | 122 | struct { 123 | long type; 124 | uint32_t zoom; 125 | } zoom; 126 | 127 | struct { 128 | long type; 129 | uint32_t vertical; 130 | uint32_t horizontal; 131 | } scroll; 132 | 133 | struct { 134 | long type; 135 | bool active; 136 | } active_state; 137 | 138 | struct { 139 | long type; 140 | bool visible; 141 | } visibility; 142 | } browser_message_t; 143 | 144 | // struct generic_message { 145 | // long type; 146 | // uint8_t data[MAX_MESSAGE_SIZE]; 147 | // }; 148 | // 149 | // struct text_message { 150 | // long type; 151 | // char text[MAX_MESSAGE_SIZE]; 152 | // }; 153 | // 154 | // struct split_text_message { 155 | // long type; 156 | // uint8_t id; 157 | // uint8_t count; 158 | // uint8_t max; 159 | // char text[MAX_MESSAGE_SIZE - 3]; 160 | // }; 161 | // 162 | // struct mouse_click_message { 163 | // long type; 164 | // int32_t x; 165 | // int32_t y; 166 | // uint32_t modifiers; 167 | // int32_t button_type; 168 | // bool mouse_up; 169 | // uint32_t click_count; 170 | // }; 171 | // 172 | // struct mouse_move_message { 173 | // long type; 174 | // int32_t x; 175 | // int32_t y; 176 | // uint32_t modifiers; 177 | // bool mouse_leave; 178 | // }; 179 | // 180 | // struct mouse_wheel_message { 181 | // long type; 182 | // int32_t x; 183 | // int32_t y; 184 | // uint32_t modifiers; 185 | // int x_delta; 186 | // int y_delta; 187 | // }; 188 | // 189 | // struct focus_message { 190 | // long type; 191 | // bool focus; 192 | // }; 193 | // 194 | // struct key_message { 195 | // long type; 196 | // bool key_up; 197 | // uint32_t native_vkey; 198 | // uint32_t modifiers; 199 | // char chr; 200 | // }; 201 | // 202 | // struct zoom_message { 203 | // long type; 204 | // uint32_t zoom; 205 | // }; 206 | // 207 | // struct scroll_message { 208 | // long type; 209 | // uint32_t vertical; 210 | // uint32_t horizontal; 211 | // }; 212 | // 213 | // struct active_state_message { 214 | // long type; 215 | // bool active; 216 | // }; 217 | // 218 | // struct visibility_message { 219 | // long type; 220 | // bool visible; 221 | // }; 222 | --------------------------------------------------------------------------------