├── .clang-format ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ └── config.yml └── workflows │ └── ci.yml ├── .gitignore ├── CMakeLists.txt ├── Dockerfile ├── LICENSE.txt ├── README.md ├── assets ├── blobdrop.svg └── completions │ ├── bash-completion │ └── completions │ │ └── blobdrop │ ├── fish │ └── vendor_completions.d │ │ └── blobdrop.fish │ └── zsh │ └── site-functions │ └── _blobdrop ├── doc ├── Doxyfile └── man │ └── man1 │ └── blobdrop.1 ├── flake.lock ├── flake.nix ├── icons.qrc ├── scripts ├── build-appimage.sh ├── build.sh └── format-code.sh ├── src ├── Models │ ├── path_model.cpp │ └── path_model.hpp ├── Util │ ├── util.cpp │ └── util.hpp ├── backend.cpp ├── backend.hpp ├── getopts.cpp ├── getopts.hpp ├── main.cpp ├── mimedb.cpp ├── mimedb.hpp ├── path.cpp ├── path.hpp ├── path_registry.cpp ├── path_registry.hpp ├── qml │ ├── Main.qml │ ├── PathView.qml │ └── Welcome.qml ├── remote.cpp ├── remote.hpp ├── settings.cpp ├── settings.hpp ├── stdin.cpp ├── stdin.hpp ├── stdout.cpp ├── stdout.hpp ├── version.cpp ├── version.hpp ├── xcb.cpp └── xcb.hpp └── tests ├── CMakeLists.txt ├── README.md └── path_test.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | AccessModifierOffset: -4 4 | AlignAfterOpenBracket: DontAlign 5 | AlignArrayOfStructures: None 6 | AlignConsecutiveAssignments: None 7 | AlignConsecutiveMacros: None 8 | AlignConsecutiveBitFields: None 9 | AlignConsecutiveDeclarations: None 10 | AlignEscapedNewlines: DontAlign 11 | AlignOperands: false 12 | AlignTrailingComments: false 13 | AllowAllArgumentsOnNextLine: true 14 | AllowAllConstructorInitializersOnNextLine: true 15 | AllowAllParametersOfDeclarationOnNextLine: true 16 | AllowShortEnumsOnASingleLine: true 17 | AllowShortBlocksOnASingleLine: Never 18 | AllowShortCaseLabelsOnASingleLine: false 19 | AllowShortFunctionsOnASingleLine: None 20 | AllowShortLambdasOnASingleLine: All 21 | AllowShortIfStatementsOnASingleLine: Never 22 | AllowShortLoopsOnASingleLine: false 23 | AlwaysBreakAfterReturnType: None 24 | AlwaysBreakBeforeMultilineStrings: false 25 | AlwaysBreakTemplateDeclarations: Yes 26 | BinPackArguments: false 27 | BinPackParameters: false 28 | BreakBeforeBinaryOperators: None 29 | # BreakBeforeConceptDeclarations: Allowed 30 | BreakBeforeConceptDeclarations: false 31 | BreakBeforeBraces: Attach 32 | BreakBeforeInheritanceComma: false 33 | BreakInheritanceList: AfterComma 34 | BreakBeforeTernaryOperators: false 35 | BreakConstructorInitializers: BeforeColon 36 | BreakStringLiterals: false 37 | ColumnLimit: 0 38 | CompactNamespaces: false 39 | ConstructorInitializerIndentWidth: 4 40 | ContinuationIndentWidth: 4 41 | Cpp11BracedListStyle: true 42 | DeriveLineEnding: false 43 | DerivePointerAlignment: false 44 | DisableFormat: false 45 | EmptyLineAfterAccessModifier: Never 46 | EmptyLineBeforeAccessModifier: Leave 47 | ExperimentalAutoDetectBinPacking: false 48 | FixNamespaceComments: false 49 | IncludeBlocks: Preserve 50 | IndentAccessModifiers: false 51 | IndentCaseLabels: false 52 | IndentCaseBlocks: true 53 | IndentGotoLabels: false 54 | IndentPPDirectives: None 55 | IndentExternBlock: AfterExternBlock 56 | IndentRequires: false 57 | IndentWidth: 4 58 | IndentWrappedFunctionNames: false 59 | InsertTrailingCommas: Wrapped 60 | KeepEmptyLinesAtTheStartOfBlocks: true 61 | LambdaBodyIndentation: OuterScope 62 | MaxEmptyLinesToKeep: 2 63 | NamespaceIndentation: None 64 | PenaltyBreakAssignment: 2 65 | PenaltyBreakBeforeFirstCallParameter: 19 66 | PenaltyBreakComment: 300 67 | PenaltyBreakFirstLessLess: 120 68 | PenaltyBreakString: 1000 69 | PenaltyBreakTemplateDeclaration: 10 70 | PenaltyExcessCharacter: 1000000 71 | PenaltyReturnTypeOnItsOwnLine: 60 72 | PenaltyIndentedWhitespace: 0 73 | PointerAlignment: Right 74 | PPIndentWidth: -1 75 | ReferenceAlignment: Pointer 76 | ReflowComments: false 77 | ShortNamespaceLines: 1 78 | SortIncludes: CaseSensitive 79 | SortUsingDeclarations: false 80 | SpaceAfterCStyleCast: true 81 | SpaceAfterLogicalNot: false 82 | SpaceAfterTemplateKeyword: false 83 | SpaceAroundPointerQualifiers: Default 84 | SpaceBeforeAssignmentOperators: true 85 | SpaceBeforeCaseColon: false 86 | SpaceBeforeCpp11BracedList: true 87 | SpaceBeforeCtorInitializerColon: true 88 | SpaceBeforeInheritanceColon: true 89 | SpaceBeforeParens: ControlStatements 90 | SpaceBeforeRangeBasedForLoopColon: true 91 | SpaceBeforeSquareBrackets: false 92 | SpaceInEmptyBlock: false 93 | SpaceInEmptyParentheses: false 94 | SpacesBeforeTrailingComments: 1 95 | SpacesInAngles: Never 96 | SpacesInCStyleCastParentheses: false 97 | SpacesInConditionalStatement: false 98 | SpacesInContainerLiterals: false 99 | SpacesInLineCommentPrefix: 100 | Minimum: 1 101 | Maximum: -1 102 | SpacesInParentheses: false 103 | SpacesInSquareBrackets: false 104 | Standard: Latest 105 | TabWidth: 4 106 | UseCRLF: false 107 | UseTab: AlignWithSpaces 108 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 109 | # PackConstructorInitializers: CurrentLine 110 | ... 111 | 112 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## Issues and bug reports 4 | When filing a bug report, please state clearly what the problem is, i.e. explain which behaviour is observed and which behaviour is expected instead. 5 | 6 | ## Development 7 | Code contributions are much welcomed and appreciated. 8 | Please make sure that the code is formatted according to the `.clang-format` file in the root of the repository. If you have not configured your editor to format automatically, you can use the [format-code.sh](/scripts/format-code.sh) script or `git clang-format`, before committing. 9 | Additionally make sure that all [tests](/tests) pass. 10 | If you add new command line flags, make sure to add them to the [shell completion files](/assets/completions) as well. 11 | 12 | ### Submitting Patches 13 | You can either submit your changes as a pull request on Github or send them via email to me. In the latter case make sure that your email client does not break the formatting of your patch, I recommend using `git send-email` for this. 14 | 15 | ### Developer's Certificate of Origin 16 | By making a contribution to this project, I certify that: 17 | 18 | 1. The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or 19 | 2. The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or 20 | 3. The contribution was provided directly to me by some other person who certified (1), (2) or (3) and I have not modified it. 21 | 4. I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Guided bug report 2 | description: "File a bug report. If you know what you are doing, feel free to open a blank issue below." 3 | body: 4 | - type: textarea 5 | id: description 6 | attributes: 7 | label: Describe the bug 8 | placeholder: A clear and concise description of what the bug is. 9 | validations: 10 | required: true 11 | - type: textarea 12 | id: reproduce 13 | attributes: 14 | label: To reproduce 15 | placeholder: Steps to reproduce the behavior. 16 | validations: 17 | required: false 18 | - type: textarea 19 | id: expected 20 | attributes: 21 | label: Expected behavior 22 | placeholder: A clear and concise description of what you expected to happen. 23 | validations: 24 | required: false 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Continuous Integration 2 | on: [push, pull_request] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v4 8 | - uses: cachix/install-nix-action@v27 9 | with: 10 | nix_path: nixpkgs=channel:nixos-unstable 11 | - run: nix flake check --print-build-logs 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | 3 | *.slo 4 | *.lo 5 | *.o 6 | *.a 7 | *.la 8 | *.lai 9 | *.so 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | 15 | /.qmake.cache 16 | /.qmake.stash 17 | *.pro.user 18 | *.pro.user.* 19 | *.qbs.user 20 | *.qbs.user.* 21 | *.moc 22 | moc_*.cpp 23 | qrc_*.cpp 24 | ui_*.h 25 | Makefile* 26 | build-*/ 27 | 28 | # QtCreator 29 | 30 | *.autosave 31 | 32 | # QtCtreator Qml 33 | *.qmlproject.user 34 | *.qmlproject.user.* 35 | 36 | # QtCtreator CMake 37 | CMakeLists.txt.user 38 | 39 | #Ignore build folder 40 | build/ 41 | .directory 42 | # vim 43 | *.swp 44 | compile_commands.json 45 | .clangd 46 | 47 | # documentation 48 | html/ 49 | latex/ 50 | 51 | .cache/ 52 | .gitattributes 53 | /result 54 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.31) 2 | project(blobdrop VERSION 2.1 DESCRIPTION "Drag and drop files directly out of the terminal") 3 | 4 | option(BUILD_TESTING "Build the testing tree.") 5 | 6 | set(CMAKE_CXX_STANDARD 23) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | set(CMAKE_CXX_EXTENSIONS OFF) 9 | 10 | list(APPEND QT_MODULES Core Qml Quick QuickControls2 DBus Svg) 11 | find_package(Qt6 6.9 COMPONENTS ${QT_MODULES} REQUIRED) 12 | qt_standard_project_setup(REQUIRES ${Qt6_VERSION}) 13 | list(TRANSFORM QT_MODULES PREPEND "Qt6::") 14 | 15 | list(APPEND LINK_LIBS ${QT_MODULES}) 16 | 17 | if (UNIX AND NOT APPLE) 18 | find_package(PkgConfig REQUIRED) 19 | list(APPEND PKGCONFIG_MODULES "xcb" "xcb-ewmh") 20 | foreach(PKG IN LISTS PKGCONFIG_MODULES) 21 | pkg_check_modules("${PKG}" REQUIRED IMPORTED_TARGET "${PKG}") 22 | endforeach() 23 | list(TRANSFORM PKGCONFIG_MODULES PREPEND "PkgConfig::") 24 | endif() 25 | 26 | include(FetchContent) 27 | FetchContent_Declare(quartz GIT_REPOSITORY https://github.com/vimpostor/quartz.git GIT_TAG v0.9.1) 28 | FetchContent_MakeAvailable(quartz) 29 | 30 | list(APPEND LINK_LIBS ${PKGCONFIG_MODULES}) 31 | 32 | include_directories("src" "src/Models") 33 | add_compile_definitions(BLOBDROP_VERSION="${PROJECT_VERSION}") 34 | 35 | file(GLOB_RECURSE SRCS "src/*.cpp") 36 | file(GLOB_RECURSE HDRS "src/*.hpp") 37 | file(GLOB_RECURSE QMLS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.qml") 38 | 39 | qt_add_resources(RESOURCES "${CMAKE_SOURCE_DIR}/icons.qrc") 40 | 41 | qt_add_executable(${PROJECT_NAME} ${SRCS} ${RESOURCES}) 42 | 43 | qt_add_qml_module(${PROJECT_NAME} URI "Backend" VERSION "${PROJECT_VERSION}" QML_FILES ${QMLS} SOURCES "src/Models/path_model.cpp") 44 | set_target_properties(${PROJECT_NAME} PROPERTIES QT_QMLCACHEGEN_ARGUMENTS "--only-bytecode") 45 | 46 | target_link_libraries(${PROJECT_NAME} PRIVATE ${LINK_LIBS}) 47 | quartz_link(${PROJECT_NAME} NO_ICONS) 48 | 49 | # install 50 | install(TARGETS ${PROJECT_NAME} RUNTIME) 51 | install(DIRECTORY "${CMAKE_SOURCE_DIR}/doc/man/" TYPE MAN) 52 | install(DIRECTORY "${CMAKE_SOURCE_DIR}/assets/completions/" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}") 53 | 54 | # testing 55 | if (BUILD_TESTING) 56 | enable_testing() 57 | add_subdirectory(tests) 58 | endif() 59 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Build with: podman build -t blobdrop . 2 | # Run with: podman run -v "$PWD:/output" blobdrop 3 | FROM docker.io/vimpostor/appimage-qt6 4 | 5 | RUN apt-get -y install libxcb-ewmh-dev 6 | 7 | ADD . /build 8 | WORKDIR /build 9 | RUN scripts/build-appimage.sh 10 | CMD cp *-x86_64.AppImage /output 11 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Blobdrop 2 | 3 | [![Continuous Integration](https://github.com/vimpostor/blobdrop/actions/workflows/ci.yml/badge.svg)](https://github.com/vimpostor/blobdrop/actions/workflows/ci.yml) 4 | 5 | Drag and drop your files directly from the terminal. 6 | 7 | https://github.com/vimpostor/blobdrop/assets/21310755/1957b6a7-475c-4930-80b9-18564ef39eb9 8 | 9 | 10 | # Installation 11 | 12 | Note: For Arch Linux users there is an [AUR package](https://aur.archlinux.org/packages/blobdrop-git), for Nix users there is a [flake](flake.nix) available and an official package in [nixpkgs](https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/bl/blobdrop/package.nix). 13 | You can also download an AppImage from the [latest release](https://github.com/vimpostor/blobdrop/releases/latest). 14 | 15 | ## Building from source 16 | 17 | Make sure you have a C++23 compiler and the latest Qt with the Declarative and Svg modules installed. 18 | 19 | ```bash 20 | cmake -B build 21 | cmake --build build 22 | 23 | # install the build/blobdrop binary 24 | cmake --install build 25 | ``` 26 | 27 | # Usage 28 | 29 | ```bash 30 | blobdrop [files-to-drag] 31 | ``` 32 | 33 | For more options see `blobdrop -h` or the man page `blobdrop(1)`. 34 | 35 | ## Features 36 | 37 | - Start drag automatically without a GUI 38 | - Hide the parent terminal emulator while dragging 39 | - Automatically quit once all paths have been dragged 40 | - Auto-hide the GUI while dragging 41 | - Show mime icons and thumbnails for media 42 | - Drag all files at once 43 | - Preview files with a single click 44 | - Shell completions 45 | - Act as a sink and print dropped files to the terminal 46 | - Pipe filenames asynchronously into stdin 47 | 48 | ### Frontends 49 | 50 | Blobdrop implements multiple frontends to drag the files from: 51 | 52 | - [From a normal window](https://github.com/vimpostor/blobdrop/assets/21310755/d86f5039-05cd-4444-9e43-cc51cf4073db) 53 | - [Inside a desktop notification](https://github.com/vimpostor/blobdrop/assets/21310755/482b4bc1-2f15-43e3-b980-1f573c494a91), using the `x-kde-urls` Notifications extension 54 | - [As an immediate drop to a click location](https://user-images.githubusercontent.com/21310755/266832800-519773b6-d154-4fd7-9faf-dfb25217055c.mp4), this works on all EWMH-compliant window managers 55 | - As clipboard content, allowing to paste the file URIs to other programs 56 | - As an [OSC8 hyper link](https://github.com/vimpostor/blobdrop/commit/3ba601c690571460fc8cd130abb57c7a15c67cf1) in the terminal emulator, but currently there exists no terminal emulator that can drag and drop OSC8 links 57 | 58 | # Alternatives 59 | 60 | - [dragon](https://github.com/mwh/dragon) - A GTK implementation of the same concept 61 | - [clidrag](https://github.com/rkevin-arch/CLIdrag) - A CLI-only implementation 62 | - [ripdrag](https://github.com/nik012003/ripdrag) - Like dragon with GTK, but rewritten in Rust 63 | 64 | Note that none of these alternatives provide a workflow similar to blobdrop's immediate frontend (except clidrag, but it lacks many UX improvements). 65 | -------------------------------------------------------------------------------- /assets/blobdrop.svg: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 22 | image/svg+xml 23 | 25 | 26 | 27 | 28 | 30 | 51 | 55 | 59 | 60 | -------------------------------------------------------------------------------- /assets/completions/bash-completion/completions/blobdrop: -------------------------------------------------------------------------------- 1 | _blobdrop() { 2 | local cur prev words cword split 3 | local opts=" 4 | -h --help 5 | -v --version 6 | -b --frameless 7 | -c --cursor 8 | -f --frontend 9 | -i --intercept 10 | -I --icon-only 11 | -k --keep 12 | -p --persistent 13 | -P --prefix 14 | -R --remote 15 | -s --thumb-size 16 | -t --ontop 17 | -x --auto-quit 18 | " 19 | _init_completion -s 20 | 21 | case "$prev" in 22 | -x|--auto-quit) 23 | COMPREPLY=($(compgen -W 'never first all' -- "$cur")) 24 | return 25 | ;; 26 | -f|--frontend) 27 | COMPREPLY=($(compgen -W 'auto gui immediate notify clipboard stdout' -- "$cur")) 28 | return 29 | ;; 30 | esac 31 | 32 | case "$cur" in 33 | -*) 34 | COMPREPLY=($(compgen -W "$opts" -- "$cur")) 35 | [[ ${COMPREPLY-} == *= ]] || compopt +o nospace 36 | ;; 37 | *) 38 | COMPREPLY=($(compgen -f -- "$cur")) 39 | esac 40 | return 0 41 | } 42 | 43 | complete -F _blobdrop -o bashdefault -o default blobdrop 44 | -------------------------------------------------------------------------------- /assets/completions/fish/vendor_completions.d/blobdrop.fish: -------------------------------------------------------------------------------- 1 | complete -c blobdrop -s '-h' -l 'help' -d 'show help' 2 | complete -c blobdrop -s '-v' -l 'version' -d 'show version' 3 | complete -c blobdrop -s '-b' -l 'frameless' -d 'show frameless window' 4 | complete -c blobdrop -s '-c' -l 'cursor' -d 'spawn window at mouse cursor' 5 | complete -c blobdrop -s '-f' -l 'frontend' -d 'selects frontend' -xa "auto\t'automatic' gui\t'show window' immediate\t'drag immediately' notify\t'drag from notification' clipboard\t'copy to clipboard' stdout\t'print OSC8 link'" 6 | complete -c blobdrop -s '-i' -l 'intercept' -d 'intercept another DnD' 7 | complete -c blobdrop -s '-I' -l 'icon-only' -d 'only show icons' 8 | complete -c blobdrop -s '-k' -l 'keep' -d 'keep dropped files' 9 | complete -c blobdrop -s '-p' -l 'persistent' -d 'disable autohiding during drag' 10 | complete -c blobdrop -s '-P' -l 'prefix' -d 'remote prefix' -xa "(__fish_print_hostnames)" 11 | complete -c blobdrop -s '-R' -l 'remote' -d 'enable ssh remote transparency' 12 | complete -c blobdrop -s '-s' -l 'thumb-size' -d 'set thumbnail size' -x 13 | complete -c blobdrop -s '-t' -l 'ontop' -d 'keep window on top' 14 | complete -c blobdrop -s '-x' -l 'auto-quit' -d 'autoquit behaviour' -xa "never\t'do not autoquit' first\t'after first drag' all\t'after all items have been dragged'" 15 | -------------------------------------------------------------------------------- /assets/completions/zsh/site-functions/_blobdrop: -------------------------------------------------------------------------------- 1 | #compdef blobdrop 2 | 3 | _blobdrop() { 4 | _arguments {-h,--help}'[show help]' {-v,--version}'[show version]' {-b,--frameless}'[show frameless window]' {-c,--cursor}'[spawn window at mouse cursor]' {-f,--frontend}'[selects frontend]:arg:((auto\:"automatic" gui\:"show window" immediate\:"drag immediately" notify\:"drag from notification" clipboard\:"copy to clipboard" stdout\:"print OSC8 link"))' {-i,--intercept}'[intercept another DnD]' {-I,--icon-only}'[only show icons]' {-k,--keep}'[keep dropped files]' {-p,--persistent}'[disable autohiding during drag]' {-P,--prefix}'[specify remote prefix]:arg:_hosts' {-R,--remote}'[enable ssh network transparency]' {-s,--thumb-size}'[thumbnail size]:num: ' {-t,--ontop}'[keep window on top]' {-x,--auto-quit}'[autoquit behaviour]:arg:((never\:"do not autoquit" first\:"after first drag" all\:"after all items have been dragged"))' '*: arg:_files' 5 | return 0 6 | } 7 | 8 | _blobdrop 9 | -------------------------------------------------------------------------------- /doc/man/man1/blobdrop.1: -------------------------------------------------------------------------------- 1 | .TH "blobdrop" 1 "07 July 2022" "" "blobdrop Documentation" 2 | 3 | .SH NAME 4 | blobdrop \- Quickly drag and drop files from the terminal 5 | 6 | .SH SYNOPSIS 7 | .B blobdrop 8 | [\-hvbciIkpRt] 9 | [\-f \fIOPT\fP] 10 | [\-P \fIOPT\fP] 11 | [\-s \fIOPT\fP] 12 | [\-x \fIOPT\fP] 13 | .I FILES 14 | 15 | .SH DESCRIPTION 16 | 17 | .P 18 | This program allows you to drag files directly from the terminal to other applications. 19 | It can be used both as a source (files can be dragged from the terminal) and as a sink (dropped file names will be printed in the terminal). 20 | 21 | Filenames can either be given as command line arguments or by piping them into stdin, one filename per line. 22 | 23 | Several frontends are available to drag files from. By default, blobdrop will immediately start the drag operation without having to hold down the mouse. The user can then just click on the target drop location, meaning by default there is no GUI involved. 24 | See 25 | .B FRONTENDS 26 | for more information. 27 | 28 | .TP 29 | .B \-h, \-\-help 30 | Show help. 31 | .TP 32 | .B \-v, \-\-version 33 | Show version information. 34 | .TP 35 | .B \-b, \-\-frameless 36 | Show a frameless window. 37 | .TP 38 | .B \-c, \-\-cursor 39 | Spawn the window at the location of the mouse cursor. 40 | .TP 41 | .B \-f, \-\-frontend \fIOPT\fP 42 | Selects the frontend. Must be one of {"auto" (default), "gui", "immediate", "notify", "clipboard", "stdout"}. For a more detailed explanation of the frontend options see 43 | .B FRONTENDS 44 | below. 45 | .TP 46 | .B \-i, \-\-intercept 47 | Intercept another drag and drop operation. This option is useful to convert other external drag and drop events into drag and drop events that use any of the available frontends. Using this option will unconditionally start the 48 | .B gui 49 | frontend to intercept another drag and drop operation. Once an element is dropped into the window, the 50 | .B \-\-frontend 51 | option determines the frontend of the outgoing converted drag and drop event. 52 | .TP 53 | .B \-I, \-\-icon-only 54 | Show only thumbnail icons. This option has no effect if a frontend other than the 55 | .B gui 56 | frontend is active. 57 | .TP 58 | .B \-k, \-\-keep 59 | When using sink mode, keep dropped files around by default. 60 | .TP 61 | .B \-p, \-\-persistent 62 | Do not auto-hide the window while dragging. 63 | .TP 64 | .B \-P, \-\-prefix 65 | Manually specify a remote prefix to be used with the \-\-remote option instead of using a heuristic. 66 | .TP 67 | .B \-R, \-\-remote 68 | Enable ssh remote transparency. This sets the URI scheme to 69 | .B sftp:// 70 | and the username, hostname and port based on heuristics, thus making it possible to drag and drop across a forwarded X11 session from a remote host. DnD requires trusted X11 forwarding (ssh -Y). In case of the heuristic failing, the \-\-prefix option can be used to manually set a value. 71 | .TP 72 | .B \-s, \-\-thumb\-size \fIOPT\fP 73 | Sets the size of the thumbnail for listed images. The default size is 64. 74 | .TP 75 | .B \-t, \-\-ontop 76 | Keep the window on top of other windows. 77 | .TP 78 | .B \-x, \-\-auto\-quit \fIOPT\fP 79 | Changes the conditions when blobdrop will automatically quit. Must be one of {"never", "first", "all" (default)}. See 80 | .B AUTOQUIT BEHAVIOUR 81 | below. 82 | 83 | .SH EXIT STATUS 84 | Returns zero on success. 85 | 86 | .SH FRONTENDS 87 | Blobdrop has multiple frontends available that change the behaviour how the drag and drop operation starts. The frontend can be chosen with the 88 | .B \-\-frontend 89 | option. 90 | .SS "auto" 91 | This is the default frontend and chooses one of the following frontends automatically based on some conditions. On X11, the 92 | .B immediate 93 | frontend is used unless no file is passed, in which case the 94 | .B gui 95 | frontend is started instead. On Wayland the 96 | .B gui 97 | frontend is used in all cases due to limitations of the Wayland protocol. 98 | 99 | .SS "gui" 100 | This frontend shows an user interface that lists all items. Each item can be conveniently dragged on its own, or alternatively there is a button to drag all items at once. 101 | 102 | .SS "immediate" 103 | This frontend starts the drag operation automatically without showing a GUI in between. The user does not need to hold any mouse button and can just move the mouse cursor to the target location and then click once to drop the files. 104 | .br 105 | Due to limitations in Wayland, this option is only available on X11. This option also works over XWayland, but then the target drop location is required to be running in XWayland too. Native Wayland does not have support for this frontend, because the spec requires an implicit grab for native wl_data_device::start_drag() operations, thus making it impossible to implement this workflow on Wayland. 106 | .br 107 | Another feature implemented in immediate mode is that the parent terminal window will be hidden automatically during the drag operation, unless the 108 | .B \-\-persistent 109 | option is set. This is useful for usecases where the target application is hidden behind the terminal where blobdrop was started from, which is often the case with floating window managers. This is an additional second usability improvement that is unfortunately also not possible to implement on Wayland due to "security" restrictions. 110 | 111 | .SS "notify" 112 | This frontend spawns a notification containing the URLs of the files to drag in the 113 | .I x\-kde\-urls 114 | field. Window managers with support for this field then enable the notification to be dragged itself into other application windows. This option is mainly useful on KDE Plasma. 115 | 116 | .SS "clipboard" 117 | This copies the file URIs (not the content) to the clipboard, which can then be pasted in supported programs. 118 | 119 | .SS "stdout" 120 | This frontend simply prints all files in the terminal as OSC8 links. Terminal emulators with support for OSC8 could allow the user to drag and drop such links directly. This option is equivalent to "ls \-\-hyperlink=always". 121 | 122 | .SH AUTOQUIT BEHAVIOUR 123 | Using 124 | .B \-\-auto\-quit 125 | it is possible to specify the behaviour when blobdrop will automatically quit. The following options are possible, 126 | .B all 127 | is the default behaviour. 128 | .SS "never" 129 | This option means that blobdrop will never automatically quit. 130 | .SS "first" 131 | Using this option causes blobdrop to quit after the first drag operation has finished. 132 | .SS "all" 133 | With this option blobdrop keeps track of which items have been dragged already. It quits when all paths have been dragged at least once. 134 | 135 | .SH DEFAULT ARGUMENTS 136 | The 137 | .B $BLOBDROP_ARGS 138 | environment variable can be used to provide default arguments. The default arguments will be prepended to the actually passed arguments, for example: 139 | .PP 140 | .in +2n 141 | .EX 142 | $ \fBBLOBDROP_ARGS\fP=\fI"\-f gui \-p"\fP \fBblobdrop\fP \-x \fInever\fP image.png 143 | $ # is equivalent to: 144 | $ \fBblobdrop\fP \-f \fIgui\fP \-p \-x \fInever\fP image.png 145 | .EE 146 | .in 147 | .PP 148 | 149 | This can be useful to change the default value of some options permanently. 150 | 151 | .SH EXAMPLES 152 | Here are some example usecases. 153 | 154 | The following example drags all png files in the current directory. 155 | .PP 156 | .in +2n 157 | .EX 158 | $ \fBblobdrop\fP *.png 159 | .EE 160 | .in 161 | .PP 162 | 163 | The next example drags a single file and explicitly does not show a GUI, always starting the drag operation right away. The user does not need to hold any mouse button. Then the user can just click on the target location to drop the file. 164 | .PP 165 | .in +2n 166 | .EX 167 | $ \fBblobdrop\fP \-f \fIimmediate\fP upload.mp4 168 | .EE 169 | .in 170 | .PP 171 | 172 | The example below shows a new frameless window that always stays on top of other windows, containing all files chosen in the fzf selection selection prompt. 173 | .PP 174 | .in +2n 175 | .EX 176 | $ \fBblobdrop\fP \-tb \-f \fIgui\fP $(\fBfzf\fP \-m) 177 | .EE 178 | .in 179 | .PP 180 | 181 | In this example blobdrop sends a desktop notification containing the URL of the given file and then quits immediately. On supported window managers the desktop notification itself can be dragged and dropped to any application. 182 | .PP 183 | .in +2n 184 | .EX 185 | $ \fBblobdrop\fP \-f \fInotify\fP doc.pdf 186 | .EE 187 | .in 188 | .PP 189 | 190 | The below example shows a window displaying all files that contain the phrase "uploadable". The UI will show up right away and if the 191 | .B grep 192 | command takes a while, then the UI will already display the files that were found so far. The list will be updated live, as all operations are done asynchronously. 193 | .PP 194 | .in +2n 195 | .EX 196 | $ \fBgrep\fP \-R \-\-files\-with\-matches uploadable | \fBblobdrop\fP 197 | .EE 198 | .in 199 | .PP 200 | 201 | The example below spawns a window under the cursor that intercepts any existing drag and drop operation and converts it into an outgoing immediate drag and drop operation. This can be helpful for touchpad users, where needing to hold a mouse button while simultaneously moving the mouse is an accessibility nightmare. 202 | .PP 203 | .in +2n 204 | .EX 205 | $ \fBblobdrop\fP \-ic \-f \fIimmediate\fP \-x \fIfirst\fP 206 | .EE 207 | .in 208 | .PP 209 | 210 | It is also possible to integrate blobdrop in other external programs. For example if you use the ranger commandline file manager, you can use blobdrop to drag any file with a simple keybinding in your ~/.config/ranger/rc.conf: 211 | .PP 212 | .in +2n 213 | .EX 214 | map shell blobdrop %p 215 | .EE 216 | .in 217 | .PP 218 | 219 | In tmux it is possible to drag the file under the cursor on double click with this "oneliner" keybinding: 220 | .PP 221 | .in +2n 222 | .EX 223 | bind \-n DoubleClick1Pane run\-shell "blobdrop \\"#{pane_current_path}/$(echo '#{mouse_line}' | cut \-c \-$((#{mouse_x} \- 1)) | grep \-o '\\\\S*$' )\\"\\"$(echo '#{mouse_line}' | cut \-c #{mouse_x}\- | grep \-o '^\\\\S*')\\"" 224 | .EE 225 | .in 226 | .PP 227 | 228 | .SH HOMEPAGE 229 | https://github.com/vimpostor/blobdrop 230 | 231 | Please report bugs and feature requests in the issue tracker. 232 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1745526057, 6 | "narHash": "sha256-ITSpPDwvLBZBnPRS2bUcHY3gZSwis/uTe255QgMtTLA=", 7 | "owner": "NixOS", 8 | "repo": "nixpkgs", 9 | "rev": "f771eb401a46846c1aebd20552521b233dd7e18b", 10 | "type": "github" 11 | }, 12 | "original": { 13 | "owner": "NixOS", 14 | "ref": "nixos-unstable", 15 | "repo": "nixpkgs", 16 | "type": "github" 17 | } 18 | }, 19 | "quartz": { 20 | "inputs": { 21 | "nixpkgs": "nixpkgs" 22 | }, 23 | "locked": { 24 | "lastModified": 1745756152, 25 | "narHash": "sha256-VBerxEGnokW3IvqYSMSzq+nDxJH9t5trEnumqHTLEcc=", 26 | "owner": "vimpostor", 27 | "repo": "quartz", 28 | "rev": "3f752d89599d3cd54f31c2a9fb31d13269007bec", 29 | "type": "github" 30 | }, 31 | "original": { 32 | "owner": "vimpostor", 33 | "repo": "quartz", 34 | "type": "github" 35 | } 36 | }, 37 | "root": { 38 | "inputs": { 39 | "quartz": "quartz" 40 | } 41 | } 42 | }, 43 | "root": "root", 44 | "version": 7 45 | } 46 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Drag and drop your files directly out of the terminal"; 3 | inputs = { 4 | quartz.url = "github:vimpostor/quartz"; 5 | }; 6 | 7 | outputs = { self, quartz }: quartz.lib.eachSystem (system: 8 | let 9 | pkgs = quartz.inputs.nixpkgs.legacyPackages.${system}; 10 | stdenvs = [ { name = "gcc"; pkg = pkgs.gcc14Stdenv; } { name = "clang"; pkg = pkgs.llvmPackages_18.stdenv; } ]; 11 | defaultStdenv = (builtins.head stdenvs).name; 12 | makeStdenvPkg = env: env.mkDerivation { 13 | pname = "blobdrop"; 14 | version = quartz.lib.cmakeProjectVersion ./CMakeLists.txt; 15 | 16 | src = ./.; 17 | 18 | nativeBuildInputs = with pkgs; [ 19 | cmake 20 | pkg-config 21 | qt6.wrapQtAppsHook 22 | ]; 23 | buildInputs = with pkgs; [ 24 | qt6.qtbase 25 | qt6.qtdeclarative 26 | qt6.qtsvg 27 | xorg.libxcb 28 | xorg.xcbutilwm 29 | ]; 30 | 31 | cmakeFlags = quartz.lib.cmakeWrapper { inherit pkgs; cmakeFile = ./CMakeLists.txt; }; 32 | }; 33 | in { 34 | packages = { 35 | default = self.outputs.packages.${system}.${defaultStdenv}; 36 | } // builtins.listToAttrs (map (x: { name = x.name; value = makeStdenvPkg x.pkg; }) stdenvs); 37 | checks = { 38 | format = pkgs.runCommand "format" { src = ./.; nativeBuildInputs = [ pkgs.clang-tools pkgs.git ]; } "mkdir $out && cd $src && find . -type f -path './*\\.[hc]pp' -exec clang-format -style=file --dry-run --Werror {} \\;"; 39 | } // builtins.listToAttrs (map (x: { name = "tests-" + x.name; value = (makeStdenvPkg x.pkg).overrideAttrs (finalAttrs: previousAttrs: { 40 | doCheck = true; 41 | cmakeFlags = previousAttrs.cmakeFlags ++ ["-DBUILD_TESTING=ON"]; 42 | QT_QPA_PLATFORM = "offscreen"; 43 | } 44 | ); }) stdenvs); 45 | } 46 | ); 47 | } 48 | -------------------------------------------------------------------------------- /icons.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | assets/blobdrop.svg 4 | 5 | 6 | -------------------------------------------------------------------------------- /scripts/build-appimage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr 6 | cmake --build build 7 | DESTDIR=AppDir cmake --install build 8 | 9 | # create fake desktop file 10 | mkdir -p AppDir/usr/share/applications 11 | cat > AppDir/usr/share/applications/blobdrop.desktop <<'EOF' 12 | #!/usr/bin/env xdg-open 13 | [Desktop Entry] 14 | Type=Application 15 | Name=blobdrop 16 | Exec=blobdrop 17 | Categories=Utility; 18 | Icon=blobdrop 19 | EOF 20 | 21 | # install placeholder icon 22 | mkdir -p AppDir/usr/share/icons/hicolor/scalable/apps 23 | cp assets/blobdrop.svg AppDir/usr/share/icons/hicolor/scalable/apps/ 24 | 25 | QML_SOURCES_PATHS="$PWD/src/qml" linuxdeploy --appdir AppDir --plugin qt --output appimage 26 | -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cmake -B build -G Ninja -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_TESTING=ON 6 | cmake --build build 7 | -------------------------------------------------------------------------------- /scripts/format-code.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | git ls-files| grep -E '.*\.[ch]pp$'| xargs clang-format -style=file -i 4 | 5 | # return only with EXIT_SUCCESS if there were no changes 6 | # otherwise show the changes and return with error code 7 | STATUS="$(git status -s)" 8 | if [ -n "$STATUS" ]; then 9 | git --no-pager diff && false 10 | fi 11 | -------------------------------------------------------------------------------- /src/Models/path_model.cpp: -------------------------------------------------------------------------------- 1 | #include "path_model.hpp" 2 | 3 | #include 4 | 5 | #include "backend.hpp" 6 | #include "path_registry.hpp" 7 | #include "settings.hpp" 8 | 9 | PathModel::PathModel(QObject *parent) { 10 | paths = PathRegistry::get()->paths; 11 | connect(PathRegistry::get(), &PathRegistry::pathAdded, this, &PathModel::add_path); 12 | connect(Backend::get(), &Backend::drag_finished, this, &PathModel::taint_all_used); 13 | } 14 | 15 | int PathModel::rowCount(const QModelIndex &) const { 16 | return paths.size(); 17 | } 18 | 19 | QVariant PathModel::data(const QModelIndex &index, int role) const { 20 | const auto &p = paths[index.row()]; 21 | switch (role) { 22 | case PathRole: 23 | return QString::fromStdString(p.path.string()); 24 | case UriRole: 25 | return QString::fromStdString(p.get_uri()); 26 | case PrettyRole: 27 | return QString::fromStdString(p.pretty_print()); 28 | case UsedRole: 29 | return p.used; 30 | case MultiselectRole: 31 | return p.multiselect; 32 | case IconRole: 33 | return QString::fromStdString(p.iconName); 34 | case ThumbnailRole: 35 | return p.thumbnail; 36 | case ExistsRole: 37 | return p.exists; 38 | default: 39 | return QVariant(); 40 | }; 41 | } 42 | 43 | QHash PathModel::roleNames() const { 44 | return role_names; 45 | } 46 | 47 | void PathModel::taint_used(int i) { 48 | paths[i].used = true; 49 | emit dataChanged(index(i, 0), index(i, 0)); 50 | check_should_quit(); 51 | } 52 | 53 | void PathModel::taint_all_used() { 54 | std::ranges::for_each(paths, [&](auto &p) { p.used = true; }); 55 | emit dataChanged(index(0, 0), index(paths.size() - 1, 0)); 56 | check_should_quit(); 57 | } 58 | 59 | void PathModel::multiselect(int i) { 60 | paths[i].multiselect = !paths[i].multiselect; 61 | multiselected += (2 * paths[i].multiselect) - 1; 62 | emit dataChanged(index(i, 0), index(i, 0)); 63 | refresh_folded_paths(); 64 | } 65 | 66 | void PathModel::refresh_folded_paths() { 67 | // only add multiselected items in multiselect mode 68 | auto v = paths | std::views::filter([&](const auto &i) { return !multiselected || i.multiselect; }); 69 | folded_uri_list = std::ranges::fold_left(v, QString(), [](QString s, const auto p) { return s.append(QString::fromStdString(p.get_uri()) + "\r\n"); }); 70 | emit foldedUriListChanged(); 71 | } 72 | 73 | void PathModel::open(int i) const { 74 | if (!paths[i].open()) { 75 | std::cerr << "Failed to open path" << paths[i].get_uri(); 76 | }; 77 | } 78 | 79 | void PathModel::finish_init() { 80 | if (paths.empty()) { 81 | // nothing to do for now 82 | return; 83 | } 84 | 85 | // frontends that have an immediate effect, can do their work now 86 | Backend::get()->exec_frontend(paths); 87 | 88 | const auto f = Settings::get()->effective_frontend(); 89 | if (f == Settings::Frontend::Stdout || f == Settings::Frontend::Notification || f == Settings::Frontend::Clipboard) { 90 | taint_all_used(); 91 | } 92 | } 93 | 94 | void PathModel::add_path(Path p) { 95 | beginInsertRows(QModelIndex(), paths.size(), paths.size()); 96 | paths.emplace_back(p); 97 | endInsertRows(); 98 | } 99 | 100 | void PathModel::check_should_quit() { 101 | const auto quit = Settings::get()->auto_quit_behavior; 102 | if (quit == Settings::AutoQuitBehavior::First || (quit == Settings::AutoQuitBehavior::All && std::ranges::all_of(paths, [](auto p) { return p.used; }))) { 103 | Backend::get()->quit_delayed(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/Models/path_model.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "path.hpp" 8 | 9 | class PathModel : public QAbstractListModel { 10 | Q_OBJECT 11 | QML_ELEMENT 12 | QML_SINGLETON 13 | 14 | Q_PROPERTY(QString foldedUriList MEMBER folded_uri_list NOTIFY foldedUriListChanged) 15 | Q_PROPERTY(int multiSelected MEMBER multiselected NOTIFY foldedUriListChanged) 16 | public: 17 | explicit PathModel(QObject *parent = nullptr); 18 | 19 | virtual int rowCount(const QModelIndex &) const override; 20 | virtual QVariant data(const QModelIndex &index, int role) const override; 21 | virtual QHash roleNames() const override; 22 | 23 | Q_INVOKABLE void taint_used(int i); 24 | Q_INVOKABLE void taint_all_used(); 25 | Q_INVOKABLE void multiselect(int i); 26 | Q_INVOKABLE void refresh_folded_paths(); 27 | Q_INVOKABLE void open(int i) const; 28 | Q_INVOKABLE void finish_init(); 29 | void add_path(Path p); 30 | signals: 31 | void foldedUriListChanged(); 32 | private: 33 | enum RoleNames { 34 | PathRole = Qt::UserRole, 35 | UriRole, 36 | PrettyRole, 37 | UsedRole, 38 | MultiselectRole, 39 | IconRole, 40 | ThumbnailRole, 41 | ExistsRole, 42 | }; 43 | QHash role_names {{PathRole, "path"}, {UriRole, "uri"}, {PrettyRole, "pretty"}, {UsedRole, "used"}, {MultiselectRole, "multiselect"}, {IconRole, "iconName"}, {ThumbnailRole, "thumbnail"}, {ExistsRole, "exists"}}; 44 | std::vector paths; 45 | QString folded_uri_list; 46 | int multiselected = 0; 47 | void check_should_quit(); 48 | }; 49 | -------------------------------------------------------------------------------- /src/Util/util.cpp: -------------------------------------------------------------------------------- 1 | #include "util.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef Q_OS_UNIX 9 | #include 10 | #endif 11 | 12 | namespace Util { 13 | 14 | const char *home_dir() { 15 | static const char *result = nullptr; 16 | if (!result) { 17 | result = getenv("HOME"); 18 | #ifdef Q_OS_UNIX 19 | if (!result) { 20 | result = getpwuid(getuid())->pw_dir; 21 | } 22 | #endif 23 | } 24 | 25 | return result; 26 | } 27 | 28 | std::string pwd() { 29 | static std::string result; 30 | if (result.empty()) { 31 | result = std::filesystem::current_path().string(); 32 | } 33 | return result; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Util/util.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std::chrono_literals; 12 | 13 | namespace Util { 14 | 15 | const char *home_dir(); 16 | std::string pwd(); 17 | } 18 | -------------------------------------------------------------------------------- /src/backend.cpp: -------------------------------------------------------------------------------- 1 | #include "backend.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "path_registry.hpp" 12 | #include "settings.hpp" 13 | #include "stdin.hpp" 14 | #include "stdout.hpp" 15 | 16 | void Backend::quit_delayed(const std::chrono::milliseconds delay) { 17 | // cancel any pending drags 18 | if (drag) { 19 | drag->cancel(); 20 | } 21 | // remove the possibly set keep-below hint, as we want to quit now 22 | Backend::get()->restore_terminal(); 23 | 24 | Settings::get()->suppress_always_on_bottom = true; 25 | QTimer::singleShot(delay, qGuiApp, QGuiApplication::quit); 26 | } 27 | 28 | void Backend::drag_paths(const std::vector &paths) { 29 | hide_terminal(); 30 | // needed for intercept mode 31 | Settings::get()->setHideGui(true); 32 | 33 | // Not a memory leak, Qt takes ownership both over the QDrag as well as the QMimeData 34 | drag = new QDrag(this); 35 | auto mimedata = new QMimeData(); 36 | 37 | QList urls; 38 | for (auto &i : paths) { 39 | urls.push_back(i.get_url()); 40 | } 41 | 42 | mimedata->setUrls(urls); 43 | drag->setMimeData(mimedata); 44 | 45 | constexpr const int cursor_size = 24; 46 | QPixmap pixmap; 47 | if (paths.size() == 1) { 48 | const auto p = paths.front(); 49 | if (!p.thumbnail.isEmpty()) { 50 | // try using the thumbnail first 51 | constexpr const int max_size = 128; 52 | pixmap = QPixmap(p.thumbnail.toLocalFile()); 53 | if (std::max(pixmap.width(), pixmap.height()) > max_size) { 54 | pixmap = pixmap.scaled(QSize(max_size, max_size), Qt::KeepAspectRatio, Qt::SmoothTransformation); 55 | } 56 | } 57 | if (pixmap.isNull()) { 58 | // fallback to mime type icon 59 | pixmap = QIcon::fromTheme(QString::fromStdString(p.iconName)).pixmap(cursor_size); 60 | } 61 | } else { 62 | // show a collective pseudo thumbnail of all files 63 | pixmap = QIcon::fromTheme("emblem-documents").pixmap(cursor_size); 64 | } 65 | if (!pixmap.isNull()) { 66 | drag->setPixmap(pixmap); 67 | } 68 | 69 | // The object is destroyed by Qt as soon as the drag is finished 70 | connect(drag, &QObject::destroyed, this, [this]() { 71 | restore_terminal(); 72 | emit drag_finished(); 73 | drag = nullptr; 74 | }); 75 | 76 | std::ignore = drag->exec(); 77 | } 78 | 79 | void Backend::print_hyperlinks(const std::vector &paths) { 80 | for (auto &i : paths) { 81 | Stdout::print_osc8_link(i.get_uri(), i.pretty_print()); 82 | } 83 | } 84 | 85 | void Backend::send_drag_notification(const std::vector &uris) { 86 | #if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) 87 | if (uris.empty()) { 88 | return; 89 | } 90 | 91 | auto session = QDBusConnection::sessionBus(); 92 | auto msg = QDBusMessage::createMethodCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify"); 93 | 94 | QList urls; 95 | for (const auto &u : uris) { 96 | urls.push_back(QString::fromStdString(u.get_uri())); 97 | } 98 | 99 | QVariantMap hints; 100 | hints["x-kde-urls"] = urls; 101 | QString title = "Drag file"; 102 | if (uris.size() > 1) { 103 | title += "s"; 104 | } 105 | msg.setArguments({"blobdrop", 0U, "cursor-arrow", title, "", QStringList(), hints, 5000}); 106 | session.call(msg); 107 | #endif 108 | } 109 | 110 | void Backend::copy_to_clipboard(const std::vector &paths) { 111 | // not a memory leak, ownership is later transferred to Qt with setMimeData() 112 | auto *mime = new QMimeData; 113 | 114 | QList urls; 115 | for (auto &i : paths) { 116 | urls.push_back(i.get_url()); 117 | } 118 | 119 | mime->setUrls(urls); 120 | auto *clip = QGuiApplication::clipboard(); 121 | clip->setMimeData(mime); 122 | } 123 | 124 | void Backend::hide_terminal() { 125 | #if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) 126 | if (Settings::get()->suppress_always_on_bottom || Settings::get()->intercept || !Stdin::get()->is_tty || !xcb.init()) { 127 | return; 128 | } 129 | 130 | last_window = xcb.active_window(); 131 | if (last_window) { 132 | xcb.set_keep_window_below(last_window); 133 | } 134 | #endif 135 | } 136 | 137 | void Backend::restore_terminal() { 138 | #if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) 139 | if (!last_window) { 140 | return; 141 | } 142 | 143 | xcb.set_keep_window_below(last_window, false); 144 | last_window = 0; 145 | #endif 146 | } 147 | 148 | void Backend::exec_frontend(const std::vector &paths) { 149 | const auto f = Settings::get()->effective_frontend(true); 150 | if (f == Settings::Frontend::Immediate) { 151 | Backend::get()->drag_paths(paths); 152 | } else if (f == Settings::Frontend::Stdout) { 153 | Backend::get()->print_hyperlinks(paths); 154 | } else if (f == Settings::Frontend::Notification) { 155 | Backend::get()->send_drag_notification(paths); 156 | } else if (f == Settings::Frontend::Clipboard) { 157 | Backend::get()->copy_to_clipboard(paths); 158 | } 159 | } 160 | 161 | QPoint Backend::get_mouse_pos() const { 162 | return QCursor::pos(); 163 | } 164 | 165 | void Backend::handle_dropped_urls(const QList &urls) { 166 | std::vector paths; 167 | for (auto &u : urls) { 168 | auto url = u.toString().toStdString(); 169 | if (url.starts_with("file://")) { 170 | url = url.substr(7); 171 | } 172 | paths.push_back(url); 173 | } 174 | 175 | if (Settings::get()->keep_dropped_files) { 176 | for (auto &i : paths) { 177 | PathRegistry::get()->add_path(i); 178 | } 179 | } 180 | 181 | if (Settings::get()->intercept) { 182 | QTimer::singleShot(0, qGuiApp, [this, paths]() { exec_frontend(paths); }); 183 | } else { 184 | Backend::get()->print_hyperlinks(paths); 185 | } 186 | 187 | if (Settings::get()->auto_quit_behavior == Settings::AutoQuitBehavior::First && Settings::get()->effective_frontend(true) != Settings::Frontend::Immediate) { 188 | Backend::get()->quit_delayed(); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /src/backend.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Util/util.hpp" 10 | #include "path.hpp" 11 | 12 | #if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) 13 | #include "xcb.hpp" 14 | #endif 15 | 16 | class Backend : public QObject { 17 | Q_OBJECT 18 | QML_ELEMENT 19 | QML_SINGLETON 20 | public: 21 | QML_CPP_SINGLETON(Backend) 22 | 23 | void quit_delayed(const std::chrono::milliseconds delay = 100ms); 24 | void drag_paths(const std::vector &paths); 25 | void print_hyperlinks(const std::vector &paths); 26 | void send_drag_notification(const std::vector &uris); 27 | void copy_to_clipboard(const std::vector &paths); 28 | 29 | void hide_terminal(); 30 | void restore_terminal(); 31 | 32 | void exec_frontend(const std::vector &paths); 33 | Q_INVOKABLE QPoint get_mouse_pos() const; 34 | Q_INVOKABLE void handle_dropped_urls(const QList &urls); 35 | signals: 36 | void drag_finished(); 37 | private: 38 | QDrag *drag = nullptr; 39 | #if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) 40 | Xcb xcb; 41 | xcb_window_t last_window = 0; 42 | #endif 43 | }; 44 | -------------------------------------------------------------------------------- /src/getopts.cpp: -------------------------------------------------------------------------------- 1 | #include "getopts.hpp" 2 | #include "settings.hpp" 3 | 4 | #include 5 | 6 | #include "remote.hpp" 7 | 8 | namespace Getopts { 9 | 10 | QStringList setup_args(int argc, char *argv[]) { 11 | const auto *env = std::getenv("BLOBDROP_ARGS"); 12 | return quartz::getopts::prepend_args(argc, argv, env); 13 | } 14 | 15 | bool parse(const QStringList &args) { 16 | QCommandLineParser p; 17 | p.setApplicationDescription("Quickly drag and drop files from the terminal to applications."); 18 | p.addHelpOption(); 19 | p.addVersionOption(); 20 | 21 | const auto make_descr = [](const std::ranges::range auto &opts) { return std::ranges::fold_left(opts, std::string(), [](const auto &l, const auto &r) { return l + " " + r; }); }; 22 | // must be in the same order as the enum 23 | constexpr std::array frontend_opts = {"auto", "gui", "immediate", "notify", "clipboard", "stdout"}; 24 | const std::string frontends_descr = make_descr(frontend_opts); 25 | constexpr std::array auto_quit_opts = {"never", "first", "all"}; 26 | const std::string auto_quit_descr = make_descr(auto_quit_opts); 27 | 28 | QCommandLineOption frameless_opt(QStringList() << "b" 29 | << "frameless", 30 | "Show a frameless window."); 31 | QCommandLineOption cursor_opt(QStringList() << "c" 32 | << "cursor", 33 | "Spawn window at the mouse cursor."); 34 | QCommandLineOption frontend_opt(QStringList() << "f" 35 | << "frontend", 36 | "Selects the frontend. Must be one of:" + QString::fromStdString(frontends_descr) + " (default auto).", 37 | "frontend"); 38 | QCommandLineOption intercept_opt(QStringList() << "i" 39 | << "intercept", 40 | "Intercept another drag and drop."); 41 | QCommandLineOption icononly_opt(QStringList() << "I" 42 | << "icon-only", 43 | "Only show icons."); 44 | QCommandLineOption keep_opt(QStringList() << "k" 45 | << "keep", 46 | "Keep dropped files around in sink mode."); 47 | QCommandLineOption persistent_opt(QStringList() << "p" 48 | << "persistent", 49 | "Do not auto-hide the window while dragging."); 50 | QCommandLineOption prefix_opt(QStringList() << "P" 51 | << "prefix", 52 | "Specify a remote prefix.", 53 | "prefix"); 54 | QCommandLineOption remote_opt(QStringList() << "R" 55 | << "remote", 56 | "Enable ssh remote transparency."); 57 | QCommandLineOption thumbnailsize_opt(QStringList() << "s" 58 | << "thumb-size", 59 | "Set thumbnail size (default 64).", 60 | "size"); 61 | QCommandLineOption ontop_opt(QStringList() << "t" 62 | << "ontop", 63 | "Keep the window on top of other windows."); 64 | QCommandLineOption auto_quit_opt(QStringList() << "x" 65 | << "auto-quit", 66 | "The amount of drags after which the program should automatically close. Must be one of:" + QString::fromStdString(auto_quit_descr) + " (default all).", 67 | "behaviour"); 68 | 69 | p.addOptions({frameless_opt, cursor_opt, frontend_opt, intercept_opt, icononly_opt, keep_opt, persistent_opt, prefix_opt, remote_opt, thumbnailsize_opt, ontop_opt, auto_quit_opt}); 70 | p.process(args); 71 | 72 | if (p.isSet(auto_quit_opt)) { 73 | const auto opt = p.value(auto_quit_opt); 74 | int choice = std::ranges::find(auto_quit_opts, opt.toStdString()) - auto_quit_opts.cbegin(); 75 | if (static_cast(choice) > Settings::AutoQuitBehavior::All) { 76 | std::cerr << "auto-quit needs to be one of:" << auto_quit_descr << std::endl; 77 | return false; 78 | } 79 | Settings::get()->auto_quit_behavior = static_cast(choice); 80 | } 81 | Settings::get()->remote = p.isSet(remote_opt); 82 | if (p.isSet(thumbnailsize_opt)) { 83 | const auto v = p.value(thumbnailsize_opt).toInt(); 84 | if (v) { 85 | Settings::get()->thumbnail_size = v; 86 | } else { 87 | std::cerr << "Thumbnail size must be an integer." << std::endl; 88 | return false; 89 | } 90 | } 91 | if (p.isSet(prefix_opt)) { 92 | if (!Settings::get()->remote) { 93 | std::cerr << "This option has no effect if remote support is not enabled" << std::endl; 94 | return false; 95 | } 96 | Remote::get()->hardcode_prefix(p.value(prefix_opt)); 97 | } 98 | Settings::get()->always_on_top = p.isSet(ontop_opt); 99 | Settings::get()->keep_dropped_files = p.isSet(keep_opt); 100 | 101 | if (p.isSet(frontend_opt)) { 102 | // find frontend, even if only a prefix matches 103 | auto frontend_selection = std::views::zip(frontend_opts, std::views::iota(0UZ, frontend_opts.size())) | std::views::filter([&](const auto &i) { return std::string(std::get<0>(i)).starts_with(p.value(frontend_opt).toStdString()); }); 104 | if (frontend_selection.empty()) { 105 | // match must be unique 106 | std::cerr << "frontend needs to be one of the following:" << frontends_descr << std::endl; 107 | return false; 108 | } 109 | const auto c = static_cast(std::get<1>(frontend_selection.front())); 110 | if (c == Settings::Frontend::Immediate && quartz::util::is_wayland()) { 111 | std::cerr << "Wayland does not have support for this frontend, as the spec requires an implicit grab for native wl_data_device::start_drag() operations, thus making it impossible to implement this workflow on Wayland." << std::endl 112 | << "This frontend might work over XWayland (force it with QT_QPA_PLATFORM=xcb) but will likely be very buggy. Please switch to X11 to get the optimal usability experience or use another frontend." << std::endl; 113 | return false; 114 | } 115 | Settings::get()->frontend = c; 116 | } 117 | 118 | Settings::get()->suppress_always_on_bottom = p.isSet(persistent_opt); 119 | Settings::get()->frameless = p.isSet(frameless_opt); 120 | Settings::get()->spawn_on_cursor = p.isSet(cursor_opt); 121 | Settings::get()->intercept = p.isSet(intercept_opt); 122 | Settings::get()->icon_only = p.isSet(icononly_opt); 123 | 124 | // add all trailing arguments to the path list 125 | std::ranges::for_each(p.positionalArguments(), [](auto i) { PathRegistry::get()->add_path(i.toStdString()); }); 126 | return true; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/getopts.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "path_registry.hpp" 8 | #include "settings.hpp" 9 | 10 | namespace Getopts { 11 | 12 | QStringList setup_args(int argc, char *argv[]); 13 | bool parse(const QStringList &args); 14 | } 15 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef Q_OS_UNIX 9 | #include 10 | #endif 11 | 12 | #include "backend.hpp" 13 | #include "getopts.hpp" 14 | #include "version.hpp" 15 | 16 | int main(int argc, char *argv[]) { 17 | QCoreApplication::setOrganizationName("blobdrop"); 18 | QCoreApplication::setApplicationName("blobdrop"); 19 | QCoreApplication::setApplicationVersion(Version::version_string()); 20 | QGuiApplication app(argc, argv); 21 | 22 | #ifdef Q_OS_UNIX 23 | // handle unix signals 24 | quartz::Signals signal_handler {{SIGINT, SIGHUP, SIGTERM, SIGQUIT}, [](int) { Backend::get()->quit_delayed(0ms); }}; 25 | #endif 26 | 27 | const auto &args = Getopts::setup_args(argc, argv); 28 | if (!Getopts::parse(args)) { 29 | return EXIT_FAILURE; 30 | } 31 | 32 | QGuiApplication::setWindowIcon(QIcon::fromTheme("blobdrop", QIcon(":/blobdrop"))); 33 | 34 | QQmlApplicationEngine engine; 35 | 36 | engine.loadFromModule("Backend", "Main"); 37 | if (engine.rootObjects().isEmpty()) { 38 | return EXIT_FAILURE; 39 | } 40 | 41 | return app.exec(); 42 | } 43 | -------------------------------------------------------------------------------- /src/mimedb.cpp: -------------------------------------------------------------------------------- 1 | #include "mimedb.hpp" 2 | 3 | std::string MimeDb::getIcon(const std::filesystem::path &p) const { 4 | if (std::filesystem::is_directory(p)) { 5 | /** 6 | * Early return for directories: 7 | * mimeTypeForFile incorrectly returns application-octet-stream for them 8 | */ 9 | return "inode-directory"; 10 | } 11 | 12 | std::string result = getMimetype(p).iconName().toStdString(); 13 | if (result.empty()) { 14 | result = "text-x-generic"; 15 | } 16 | return result; 17 | } 18 | 19 | 20 | QMimeType MimeDb::getMimetype(const std::filesystem::path &p) const { 21 | return db.mimeTypeForFile(QString::fromStdString(p.string()), QMimeDatabase::MatchExtension); 22 | } 23 | -------------------------------------------------------------------------------- /src/mimedb.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include "Util/util.hpp" 9 | 10 | class MimeDb { 11 | public: 12 | SINGLETON(MimeDb) 13 | std::string getIcon(const std::filesystem::path &p) const; 14 | QMimeType getMimetype(const std::filesystem::path &p) const; 15 | private: 16 | QMimeDatabase db; 17 | }; 18 | -------------------------------------------------------------------------------- /src/path.cpp: -------------------------------------------------------------------------------- 1 | #include "path.hpp" 2 | 3 | #include 4 | 5 | #include "Util/util.hpp" 6 | #include "mimedb.hpp" 7 | #include "remote.hpp" 8 | #include "settings.hpp" 9 | 10 | Path::Path(const std::string &p) 11 | : path(std::filesystem::absolute(p)) { 12 | try { 13 | exists = std::filesystem::exists(path); 14 | } catch (const std::filesystem::filesystem_error &ex) { 15 | std::cerr << ex.what() << std::endl; 16 | } 17 | iconName = MimeDb::get()->getIcon(path); 18 | 19 | // If this is an image, initialize the thumbnail 20 | if (MimeDb::get()->getMimetype(path).name().startsWith("image")) { 21 | // Just reuse the file itself, QML itself can later create an image on demand from this 22 | thumbnail = get_url(); 23 | } 24 | } 25 | 26 | std::string Path::get_uri() const { 27 | return get_url().toString().toStdString(); 28 | } 29 | 30 | QUrl Path::get_url() const { 31 | auto res = QUrl::fromLocalFile(QString::fromStdString(path.string())); 32 | 33 | if (Settings::get()->remote) { 34 | std::ignore = Remote::get()->rewire_url(res); 35 | } 36 | 37 | return res; 38 | } 39 | 40 | std::string Path::pretty_print() const { 41 | std::string result = path.string(); 42 | 43 | const auto pwd = Util::pwd() + std::string(1, std::filesystem::path::preferred_separator); 44 | const auto home = Util::home_dir(); 45 | if (result.starts_with(pwd)) { 46 | result = result.substr(pwd.length()); 47 | } else if (home && result.starts_with(home)) { 48 | result.replace(0, std::strlen(home), "~"); 49 | } 50 | 51 | return result; 52 | } 53 | 54 | bool Path::open() const { 55 | return QDesktopServices::openUrl(get_url()); 56 | } 57 | -------------------------------------------------------------------------------- /src/path.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class Path { 8 | public: 9 | Path(const std::string &p); 10 | std::filesystem::path path; 11 | bool used = false; 12 | QUrl thumbnail; 13 | bool exists = false; 14 | std::string iconName; 15 | bool multiselect = false; 16 | 17 | std::string get_uri() const; 18 | QUrl get_url() const; 19 | std::string pretty_print() const; 20 | bool open() const; 21 | }; 22 | -------------------------------------------------------------------------------- /src/path_registry.cpp: -------------------------------------------------------------------------------- 1 | #include "path_registry.hpp" 2 | 3 | void PathRegistry::add_path(Path p) { 4 | paths.emplace_back(p); 5 | #if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN) 6 | if (Settings::get()->supportsImmediate()) { 7 | // if no other frontend was explicitly selected, 8 | // we could begin an immediate drag now (once startup is complete) 9 | Settings::get()->can_drag_immediately = true; 10 | } 11 | #endif 12 | emit pathAdded(p); 13 | } 14 | -------------------------------------------------------------------------------- /src/path_registry.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Util/util.hpp" 6 | #include "path.hpp" 7 | #include "settings.hpp" 8 | 9 | class PathRegistry : public QObject { 10 | Q_OBJECT 11 | public: 12 | SINGLETON(PathRegistry) 13 | void add_path(Path p); 14 | std::vector paths; 15 | signals: 16 | void pathAdded(Path p); 17 | }; 18 | -------------------------------------------------------------------------------- /src/qml/Main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2 | import QtQuick.Controls.Material 3 | import Quartz 4 | 5 | import Backend 6 | 7 | ApplicationWindow { 8 | id: root 9 | visible: Settings.needsGui 10 | flags: Qt.Dialog | (Settings.alwaysOnTop ? Qt.WindowStaysOnTopHint : 0) | (Settings.alwaysOnBottom ? Qt.WindowStaysOnBottomHint : 0) | (Settings.frameless ? Qt.FramelessWindowHint : 0) 11 | title: Stdin.closed ? "Blobdrop" : "Reading from stdin..." 12 | width: Settings.iconOnly ? Settings.thumbnailSize + 16 : 400 13 | height: Math.max(48, Math.min(800, pathView.count ? pathView.contentHeight + 2 * pathView.anchors.topMargin : 350)) 14 | Material.theme: Material.System 15 | Material.primary: Material.Green 16 | Material.accent: Material.Pink 17 | Component.onCompleted: { 18 | if (Settings.spawnOnCursor) { 19 | root.x = Backend.get_mouse_pos().x - width / 2; 20 | root.y = Backend.get_mouse_pos().y - height / 2; 21 | } 22 | } 23 | Shortcut { 24 | sequences: [StandardKey.Quit, StandardKey.Cancel, "Q"] 25 | onActivated: Qt.quit(); 26 | } 27 | DropArea { 28 | enabled: !pathView.dragActive 29 | onDropped: (drop) => { 30 | Backend.handle_dropped_urls(drop.urls); 31 | } 32 | } 33 | Welcome { 34 | anchors { left: parent.left; right: parent.right; margins: 48; verticalCenter: parent.verticalCenter } 35 | visible: !pathView.count 36 | } 37 | PathView { 38 | id: pathView 39 | anchors.fill: parent 40 | anchors.leftMargin: 4 41 | anchors.rightMargin: 4 42 | anchors.topMargin: 4 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/qml/PathView.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2 | import QtQuick.Controls.Material 3 | import Quartz 4 | 5 | import Backend 6 | 7 | ListView { 8 | id: pathView 9 | property bool dragActive: false 10 | 11 | model: PathModel 12 | visible: count 13 | spacing: 6 14 | header: Button { 15 | width: parent.width 16 | height: pathView.count > 1 ? 40 : 0 17 | Behavior on height { NumberAnimation { duration: 300; easing.type: Easing.InOutSine }} 18 | visible: pathView.count > 1 19 | highlighted: true 20 | text: "Drag all " + (PathModel.multiSelected ? PathModel.multiSelected : pathView.count) + " items" 21 | Button { 22 | id: dragallDummy 23 | visible: false 24 | icon.name: "emblem-documents-symbolic" 25 | icon.color: "transparent" 26 | width: Settings.thumbnailSize 27 | height: Settings.thumbnailSize 28 | } 29 | DragArea { 30 | anchors.fill: parent 31 | target: dragallDummy 32 | dragUri: PathModel.foldedUriList 33 | Component.onCompleted: { 34 | PathModel.finish_init(); 35 | } 36 | onPreDragStarted: { 37 | PathModel.refresh_folded_paths(); 38 | } 39 | onDragStarted: { 40 | Settings.alwaysOnBottom = true; 41 | pathView.dragActive = true; 42 | } 43 | onDragFinished: (dropAction) => { 44 | PathModel.taint_all_used(); 45 | Settings.alwaysOnBottom = false; 46 | pathView.dragActive = false; 47 | } 48 | } 49 | } 50 | delegate: Item { 51 | height: Settings.thumbnailSize 52 | width: ListView.view.width 53 | Pane { 54 | id: pane 55 | anchors.fill: parent 56 | Material.elevation: 6 57 | padding: 0 58 | Button { 59 | id: iconButton 60 | anchors { left: parent.left; top: parent.top; bottom: parent.bottom } 61 | width: height 62 | visible: thumbnail == "" 63 | icon.name: iconName 64 | icon.source: "qrc:///blobdrop" // fallback icon 65 | icon.color: "transparent" 66 | icon.width: parent.height 67 | icon.height: parent.height 68 | flat: true 69 | enabled: false 70 | } 71 | Image { 72 | id: thumbnailImg 73 | anchors.fill: iconButton 74 | visible: !iconButton.visible 75 | source: thumbnail 76 | fillMode: Image.PreserveAspectCrop 77 | mipmap: true 78 | asynchronous: true 79 | } 80 | Label { 81 | anchors { left: iconButton.right; right: usedIndicator.left; rightMargin: 4; } 82 | text: pretty 83 | elide: Text.ElideRight 84 | height: parent.height 85 | verticalAlignment: Text.AlignVCenter 86 | horizontalAlignment: Text.AlignHCenter 87 | wrapMode: Text.Wrap 88 | visible: !Settings.iconOnly 89 | ToolTip.text: path 90 | ToolTip.visible: dragArea.containsMouse && (count > 1) 91 | ToolTip.delay: 1500 92 | ToolTip.timeout: 2000 93 | } 94 | Rectangle { 95 | id: usedIndicator 96 | anchors { right: parent.right; top: parent.top; bottom: parent.bottom } 97 | width: 8 + multiselect * 40 98 | color: used ? Material.primary : exists ? Material.color(Material.Grey) : Material.color(Material.Red) 99 | Behavior on width { NumberAnimation { duration: 200; easing.type: Easing.InOutSine }} 100 | Behavior on color { ColorAnimation { duration: 200; easing.type: Easing.InOutSine }} 101 | } 102 | } 103 | DragArea { 104 | id: dragArea 105 | anchors.fill: parent 106 | target: iconButton.visible ? iconButton : thumbnailImg 107 | dragUri: uri 108 | hoverEnabled: true 109 | acceptedButtons: Qt.LeftButton | Qt.RightButton 110 | onClicked: (ev) => { 111 | if (ev.modifiers & Qt.ControlModifier) { 112 | PathModel.multiselect(index); 113 | } else { 114 | PathModel.open(index); 115 | } 116 | } 117 | onDragStarted: { 118 | Settings.alwaysOnBottom = true; 119 | pathView.dragActive = true; 120 | } 121 | onDragFinished: (dropAction) => { 122 | PathModel.taint_used(index) 123 | Settings.alwaysOnBottom = false; 124 | pathView.dragActive = false; 125 | } 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/qml/Welcome.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2 | import QtQuick.Controls.Material 3 | 4 | import Backend 5 | 6 | Column { 7 | spacing: 64 8 | Label { 9 | width: parent.width 10 | horizontalAlignment: Text.AlignHCenter 11 | text: Settings.intercept ? "Intercept and convert an existing DnD action by dropping it here." : "Pass file names as arguments or pipe them to stdin to make them appear here and drag them anywhere.\nAlternatively use this window as a sink by dropping files here." 12 | wrapMode: Text.WordWrap 13 | } 14 | CheckBox { 15 | anchors.horizontalCenter: parent.horizontalCenter 16 | text: "Keep dropped items" 17 | checked: Settings.keepDroppedFiles 18 | onCheckedChanged: Settings.keepDroppedFiles = checked; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/remote.cpp: -------------------------------------------------------------------------------- 1 | #include "remote.hpp" 2 | 3 | #include 4 | 5 | #ifdef Q_OS_UNIX 6 | #include 7 | #include 8 | #endif 9 | 10 | bool Remote::rewire_url(QUrl &url) { 11 | if (!init_done) { 12 | init(); 13 | } 14 | if (!ok) { 15 | return false; 16 | } 17 | 18 | url.setScheme(scheme); 19 | url.setUserName(username); 20 | url.setHost(host); 21 | url.setPort(port); 22 | 23 | return true; 24 | } 25 | 26 | void Remote::hardcode_prefix(const QString &prefix) { 27 | init_done = true; 28 | QUrl url {prefix}; 29 | if (!url.scheme().isEmpty()) { 30 | scheme = url.scheme(); 31 | } 32 | username = url.userName(); 33 | host = url.host(); 34 | port = url.port(); 35 | ok = url.isValid(); 36 | } 37 | 38 | void Remote::init() { 39 | init_done = true; 40 | 41 | username = get_username(); 42 | if (username.isEmpty()) { 43 | std::cerr << "Could not read username" << std::endl; 44 | return; 45 | } 46 | 47 | host = get_local_domain(); 48 | if (host.isEmpty()) { 49 | std::cerr << "Could not read host" << std::endl; 50 | return; 51 | } 52 | 53 | // not a big deal if this fails, usually it still works without an explicit port 54 | port = get_port(); 55 | 56 | ok = true; 57 | } 58 | 59 | QString Remote::get_local_domain() { 60 | #ifndef Q_OS_UNIX 61 | return {}; 62 | #else 63 | char host[_POSIX_HOST_NAME_MAX]; 64 | if (gethostname(host, _POSIX_HOST_NAME_MAX)) { 65 | std::cerr << "gethostname failed" << std::endl; 66 | return {}; 67 | } 68 | 69 | // got the host, try to get the FQDN 70 | struct addrinfo hints, *res; 71 | memset(&hints, 0, sizeof(hints)); 72 | hints.ai_family = AF_UNSPEC; 73 | hints.ai_socktype = SOCK_STREAM; 74 | hints.ai_flags = AI_CANONNAME; 75 | 76 | int err = getaddrinfo(host, "http", &hints, &res); 77 | if (err) { 78 | std::cerr << "getaddrinfo failed: " << gai_strerror(err) << std::endl; 79 | return {}; 80 | } 81 | 82 | const auto fqdn = res->ai_canonname; 83 | std::string result; 84 | 85 | if (!strncmp(fqdn, host, _POSIX_HOST_NAME_MAX)) { 86 | std::cerr << "failed to retreive a proper FQDN for " << host << std::endl; 87 | } else { 88 | result = fqdn; 89 | 90 | // remove possible leading dot 91 | if (result.starts_with('.')) { 92 | result = result.substr(1); 93 | } 94 | } 95 | 96 | freeaddrinfo(res); 97 | return QString::fromStdString(result); 98 | #endif 99 | } 100 | 101 | QString Remote::get_username() { 102 | #ifdef Q_OS_UNIX 103 | return getlogin(); 104 | #else 105 | return {}; 106 | #endif 107 | } 108 | 109 | int Remote::get_port() { 110 | const auto env = std::getenv("SSH_CONNECTION"); 111 | if (env) { 112 | std::string ssh_connection {env}; 113 | const auto n = ssh_connection.rfind(' '); 114 | if (n != std::string::npos) { 115 | try { 116 | return std::stoi(ssh_connection.substr(n + 1)); 117 | } catch (std::invalid_argument const &) { 118 | std::cerr << "Failed to parse port number " << ssh_connection << std::endl; 119 | } 120 | } 121 | } 122 | return -1; 123 | } 124 | -------------------------------------------------------------------------------- /src/remote.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Util/util.hpp" 6 | 7 | class Remote { 8 | public: 9 | SINGLETON(Remote) 10 | bool rewire_url(QUrl &url); 11 | void hardcode_prefix(const QString &prefix); 12 | private: 13 | void init(); 14 | QString get_local_domain(); 15 | QString get_username(); 16 | int get_port(); 17 | 18 | bool init_done = false; 19 | bool ok = false; 20 | 21 | QString scheme = "sftp"; 22 | QString username; 23 | QString host; 24 | int port = -1; 25 | }; 26 | -------------------------------------------------------------------------------- /src/settings.cpp: -------------------------------------------------------------------------------- 1 | #include "settings.hpp" 2 | 3 | bool Settings::supportsImmediate() const { 4 | #if defined(Q_OS_WIN) 5 | return false; 6 | #endif 7 | return !quartz::util::is_wayland(); 8 | } 9 | 10 | void Settings::setAlwaysOnBottom(const bool v) { 11 | if (!suppress_always_on_bottom) { 12 | always_on_bottom = v; 13 | emit alwaysOnBottomChanged(always_on_bottom); 14 | } 15 | } 16 | 17 | Settings::Frontend Settings::effective_frontend(bool outgoing) const { 18 | if (intercept && !outgoing) { 19 | return Settings::Frontend::Gui; 20 | } else if (frontend == Settings::Frontend::Auto) { 21 | if (intercept) { 22 | // for intercept and outgoing prefer Immediate as default frontend 23 | return supportsImmediate() ? Settings::Frontend::Immediate : Settings::Frontend::Stdout; 24 | } else { 25 | // in general (not outgoing), prefer immediate and fallback to GUI 26 | return can_drag_immediately ? Settings::Frontend::Immediate : Settings::Frontend::Gui; 27 | } 28 | } 29 | return frontend; 30 | } 31 | 32 | bool Settings::needs_gui() const { 33 | // Since the corresponding QML property is marked as constant, 34 | // it does not matter if this changes during runtime: 35 | // QML won't get the updated value. 36 | // This means we will never have the problem, where e.g. 37 | // file names are passed over stdin with a delay, 38 | // so initially the auto frontend would show a GUI (because no filenames are ready), 39 | // but then filenames come trickling in on stdin while the GUI is already showing 40 | // so this boolean would change to false for the Auto frontend, 41 | // meaning the GUI could hide again. 42 | // Of course in that case the GUI should stay visible if it was visible once. 43 | return effective_frontend() == Settings::Frontend::Gui && !hide_gui; 44 | } 45 | 46 | void Settings::setHideGui(const bool h) { 47 | hide_gui = h; 48 | emit hideGuiChanged(h); 49 | } 50 | -------------------------------------------------------------------------------- /src/settings.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Util/util.hpp" 4 | 5 | class Settings : public QObject { 6 | Q_OBJECT 7 | QML_ELEMENT 8 | QML_SINGLETON 9 | 10 | Q_PROPERTY(bool alwaysOnTop MEMBER always_on_top CONSTANT) 11 | Q_PROPERTY(bool alwaysOnBottom MEMBER always_on_bottom WRITE setAlwaysOnBottom NOTIFY alwaysOnBottomChanged) 12 | Q_PROPERTY(bool keepDroppedFiles MEMBER keep_dropped_files NOTIFY keepDroppedFilesChanged) 13 | Q_PROPERTY(bool frameless MEMBER frameless CONSTANT) 14 | Q_PROPERTY(bool needsGui READ needs_gui NOTIFY hideGuiChanged) 15 | Q_PROPERTY(bool spawnOnCursor MEMBER spawn_on_cursor CONSTANT) 16 | Q_PROPERTY(bool intercept MEMBER intercept CONSTANT) 17 | Q_PROPERTY(int thumbnailSize MEMBER thumbnail_size CONSTANT) 18 | Q_PROPERTY(bool iconOnly MEMBER icon_only CONSTANT) 19 | public: 20 | enum class AutoQuitBehavior { 21 | Never, 22 | First, 23 | All, 24 | }; 25 | enum class Frontend { 26 | Auto, // choose automatically 27 | Gui, // show a window to drag files from 28 | Immediate, // perform drag immediately without needing to hold down the mouse 29 | Notification, // show a desktop notification to drag from 30 | Clipboard, // copy URI to clipboard 31 | Stdout, // print a link in the terminal using OSC8 32 | }; 33 | 34 | QML_CPP_SINGLETON(Settings) 35 | 36 | AutoQuitBehavior auto_quit_behavior = Settings::AutoQuitBehavior::All; 37 | Frontend frontend = Settings::Frontend::Auto; 38 | bool supportsImmediate() const; 39 | void setAlwaysOnBottom(const bool v); 40 | Frontend effective_frontend(bool outgoing = false) const; 41 | void setHideGui(const bool h); 42 | 43 | bool always_on_top = false; 44 | bool always_on_bottom = false; 45 | bool keep_dropped_files = false; 46 | bool frameless = false; 47 | bool can_drag_immediately = false; 48 | bool suppress_always_on_bottom = false; 49 | bool spawn_on_cursor = false; 50 | bool intercept = false; 51 | int thumbnail_size = 64; 52 | bool icon_only = false; 53 | bool remote = false; 54 | signals: 55 | void alwaysOnBottomChanged(bool alwaysOnBottom); 56 | void keepDroppedFilesChanged(bool keepDroppedFiles); 57 | void hideGuiChanged(bool hide); 58 | private: 59 | bool needs_gui() const; 60 | bool hide_gui = false; 61 | }; 62 | -------------------------------------------------------------------------------- /src/stdin.cpp: -------------------------------------------------------------------------------- 1 | #include "stdin.hpp" 2 | 3 | #include "backend.hpp" 4 | 5 | Stdin::Stdin(bool) { 6 | stdin_nb = fileno(stdin); 7 | // do not buffer stdin line-wise 8 | disable_canonical_mode(); 9 | 10 | this->socket = std::make_unique(stdin_nb, QSocketNotifier::Read); 11 | connect(socket.get(), &QSocketNotifier::activated, this, &Stdin::read); 12 | } 13 | 14 | Stdin::~Stdin() { 15 | reset_terminal_mode(); 16 | } 17 | 18 | Stdin *Stdin::get() { 19 | static Stdin s {true}; 20 | return &s; 21 | } 22 | 23 | Stdin *Stdin::create(QQmlEngine *qmlEngine, QJSEngine *jsEngine) { 24 | auto res = get(); 25 | QJSEngine::setObjectOwnership(res, QJSEngine::CppOwnership); 26 | return res; 27 | } 28 | 29 | void Stdin::disable_canonical_mode() { 30 | #ifdef Q_OS_UNIX 31 | struct termios term; 32 | 33 | if (tcgetattr(stdin_nb, &orig_term)) { 34 | // Failed, this likely means that no tty is attached 35 | // Also suppress hiding the parent terminal automatically, 36 | // as we were likely not started from a terminal 37 | is_tty = false; 38 | return; 39 | } 40 | term = orig_term; 41 | 42 | // unset canonical mode bit 43 | term.c_lflag &= ~ICANON; 44 | // echo input characters 45 | term.c_lflag |= ECHO; 46 | // Required so that std::cin.get() always returns at minimum one character 47 | // This should never block the main thread falsely, 48 | // because we only invoke a read() if we got an explicit socket activated event, 49 | // so data should already be waiting for us to read 50 | term.c_cc[VMIN] = 1; 51 | // No timeout, because we only read data if it is already available 52 | term.c_cc[VTIME] = 0; 53 | 54 | // change the mode immediately 55 | std::ignore = tcsetattr(stdin_nb, TCSANOW, &term); 56 | reset_term = true; 57 | #endif 58 | } 59 | 60 | void Stdin::reset_terminal_mode() { 61 | #ifdef Q_OS_UNIX 62 | if (reset_term) { 63 | // reset the terminal mode, because it is not reset automatically 64 | std::ignore = tcsetattr(stdin_nb, TCSANOW, &orig_term); 65 | } 66 | #endif 67 | } 68 | 69 | void Stdin::read() { 70 | char c; 71 | bool line_complete = false; 72 | 73 | // we need to do low-level parsing, because we want to react to any ESC pressed right away 74 | if (std::cin.good()) { 75 | c = std::cin.get(); 76 | if (c == '\n' || c == '\r' || c == std::istream::traits_type::eof()) { 77 | line_complete = true; 78 | } else if (c == 0x1B) { 79 | // ESC pressed, abort 80 | Backend::get()->quit_delayed(0ms); 81 | } else { 82 | current_line += c; 83 | } 84 | } 85 | 86 | if (!std::cin.good()) { 87 | socket->setEnabled(false); 88 | setClosed(true); 89 | } else if (!current_line.empty() && line_complete) { 90 | setClosed(false); 91 | PathRegistry::get()->add_path(current_line); 92 | current_line.clear(); 93 | } 94 | } 95 | 96 | void Stdin::setClosed(bool closed) { 97 | if (closed == m_closed) { 98 | return; 99 | } 100 | m_closed = closed; 101 | emit closedChanged(); 102 | } 103 | -------------------------------------------------------------------------------- /src/stdin.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "path_registry.hpp" 8 | 9 | #ifdef Q_OS_UNIX 10 | #include 11 | #endif 12 | 13 | class Stdin : public QObject { 14 | Q_OBJECT 15 | QML_ELEMENT 16 | QML_SINGLETON 17 | Q_PROPERTY(bool closed MEMBER m_closed NOTIFY closedChanged) 18 | public: 19 | explicit Stdin(bool); 20 | ~Stdin(); 21 | 22 | static Stdin *get(); 23 | static Stdin *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine); 24 | 25 | bool is_tty = true; 26 | signals: 27 | void closedChanged(); 28 | private: 29 | void disable_canonical_mode(); 30 | void reset_terminal_mode(); 31 | void read(); 32 | bool m_closed = true; 33 | void setClosed(bool closed); 34 | std::unique_ptr socket; 35 | int stdin_nb = -1; 36 | std::string current_line; 37 | #ifdef Q_OS_UNIX 38 | bool reset_term = false; 39 | struct termios orig_term; 40 | #endif 41 | }; 42 | -------------------------------------------------------------------------------- /src/stdout.cpp: -------------------------------------------------------------------------------- 1 | #include "stdout.hpp" 2 | 3 | void Stdout::print_osc8_link(const std::string &url, const std::string &text) { 4 | std::cout << std::format("\e]8;;{}\e\\{}\e]8;;\e\\", url, text) << std::endl; 5 | } 6 | -------------------------------------------------------------------------------- /src/stdout.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Stdout { 7 | void print_osc8_link(const std::string &url, const std::string &text); 8 | }; 9 | -------------------------------------------------------------------------------- /src/version.cpp: -------------------------------------------------------------------------------- 1 | #include "version.hpp" 2 | 3 | namespace Version { 4 | 5 | const char *version_string() { 6 | return BLOBDROP_VERSION; 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/version.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Version { 4 | 5 | const char *version_string(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/xcb.cpp: -------------------------------------------------------------------------------- 1 | #include "xcb.hpp" 2 | 3 | #if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | // Is 0 really quite correct here? 10 | // We should pass the default screen number instead, which we can obtain via the second parameter to xcb_connect(). 11 | // https://xcb.freedesktop.org/xlibtoxcbtranslationguide/ 12 | // Unfortunately, we don't have that as we just grab the connection from Qt. 13 | // 14 | // Apparently previously Qt could return the default screen number with QX11Info::appScreen(), 15 | // but that is not available in Qt6 anymore. 16 | // 17 | // I manually tested xcb_connect() and it seems to return 0 anyway. 18 | // But it doesn't matter that much, because all of our calls don't really seem to care and find the correct window even if it's on a different screen. 19 | // 20 | // If this ever becomes a problem, we still have the option to not reuse Qt's xcb connection and instead create our own with xcb_connect(). 21 | static const constexpr int default_screen = 0; 22 | 23 | bool Xcb::init() { 24 | if (ok) { 25 | // don't need to init twice 26 | return true; 27 | } 28 | 29 | const auto qt_x11 = qGuiApp->nativeInterface(); 30 | if (!qt_x11) { 31 | return false; 32 | } 33 | // reuse the Qt xcb connection 34 | conn = qt_x11->connection(); 35 | if (!conn) { 36 | return false; 37 | } 38 | 39 | // init ewmh connection 40 | ok = xcb_ewmh_init_atoms_replies(&ewmh, xcb_ewmh_init_atoms(conn, &ewmh), nullptr); 41 | return ok; 42 | } 43 | 44 | xcb_window_t Xcb::active_window() { 45 | xcb_window_t res; 46 | // try to get the currently active/focused window 47 | if (!xcb_ewmh_get_active_window_reply(&ewmh, xcb_ewmh_get_active_window_unchecked(&ewmh, default_screen), &res, nullptr)) { 48 | std::cerr << "Cannot get active window" << std::endl; 49 | return 0; 50 | } 51 | return res; 52 | } 53 | 54 | void Xcb::set_keep_window_below(xcb_window_t window, const bool value) { 55 | const auto v = value ? XCB_EWMH_WM_STATE_ADD : XCB_EWMH_WM_STATE_REMOVE; 56 | 57 | // add the corresponding enum value to the window's _NET_WM_STATE 58 | // this method can set two values at once (e.g. to maximize both vertically and horizontally in one call), 59 | // but we don't need that, so we set the second parameter to XCB_ATOM_NONE 60 | std::ignore = xcb_ewmh_request_change_wm_state(&ewmh, default_screen, window, v, ewmh._NET_WM_STATE_BELOW, XCB_ATOM_NONE, XCB_EWMH_CLIENT_SOURCE_TYPE_NORMAL); 61 | // this is needed so that the call actually takes effect 62 | std::ignore = xcb_get_window_attributes_reply(conn, xcb_get_window_attributes(conn, window), nullptr); 63 | 64 | // write pending data to the socket 65 | xcb_flush(conn); 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/xcb.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) 6 | 7 | #include 8 | #include 9 | 10 | class Xcb { 11 | public: 12 | bool init(); 13 | xcb_window_t active_window(); 14 | void set_keep_window_below(xcb_window_t window, const bool value = true); 15 | private: 16 | bool ok = false; 17 | xcb_connection_t *conn = nullptr; 18 | xcb_ewmh_connection_t ewmh; 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TESTING_TARGET tests) 2 | file(GLOB_RECURSE TESTING_SRCS "*.cpp") 3 | 4 | find_package(Qt6Test REQUIRED) 5 | 6 | list(REMOVE_ITEM SRCS "${CMAKE_SOURCE_DIR}/src/main.cpp") 7 | qt_add_executable("${TESTING_TARGET}" ${TESTING_SRCS} ${SRCS}) 8 | add_test(NAME "${TESTING_TARGET}" COMMAND "${TESTING_TARGET}") 9 | list(APPEND LINK_LIBS Qt6::Test) 10 | target_link_libraries("${TESTING_TARGET}" PRIVATE ${LINK_LIBS}) 11 | quartz_link("${TESTING_TARGET}" NO_ICONS) 12 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # Testing Suite 2 | 3 | This directory contains a testing suite based on QTest. 4 | 5 | It is easy to run the tests locally: 6 | ```bash 7 | cd .. # from the root of the repo 8 | cmake -B build -DBUILD_TESTING=ON 9 | cmake --build build 10 | ctest --test-dir build --output-on-failure 11 | ``` 12 | -------------------------------------------------------------------------------- /tests/path_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Util/util.hpp" 4 | #include "path.hpp" 5 | 6 | class PathTest : public QObject { 7 | Q_OBJECT 8 | private: 9 | std::string pwd; 10 | private slots: 11 | void initTestCase() { 12 | pwd = Util::pwd(); 13 | } 14 | 15 | void test_path_uris() { 16 | QVERIFY(!pwd.empty()); 17 | const std::string filename = "test.txt"; 18 | const auto path = pwd + "/" + filename; 19 | const auto uri = "file://" + path; 20 | 21 | // relative path 22 | QCOMPARE(Path(filename).get_uri(), uri); 23 | // absolute path 24 | QCOMPARE(Path(path).get_uri(), uri); 25 | } 26 | }; 27 | 28 | QTEST_MAIN(PathTest) 29 | #include "path_test.moc" 30 | --------------------------------------------------------------------------------