summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick O'Doherty <p@trickod.com>2016-03-14 00:06:37 -0400
committerPatrick O'Doherty <p@trickod.com>2016-03-14 00:06:37 -0400
commit6d36cc6ec5e97c715dc8162fc6efe172133bf268 (patch)
treef236d51fdab7e81657b6ab3f168dd1e70172f487
Import maim_3.3.41.orig.tar.gz
[dgit import orig maim_3.3.41.orig.tar.gz]
-rw-r--r--.gitignore2
-rw-r--r--CMakeLists.txt130
-rw-r--r--COPYING674
-rw-r--r--README.md171
-rw-r--r--cmakemodules/FindImlib2.cmake91
-rw-r--r--cmakemodules/FindXFixes.cmake26
-rw-r--r--cmakemodules/FindXRandr.cmake26
-rwxr-xr-xgenerateReadme.sh13
-rw-r--r--license.txt14
-rw-r--r--man-src/maim.1157
-rw-r--r--man-src/maim.1.gzbin0 -> 1560 bytes
-rw-r--r--man-src/maim.1.html158
-rw-r--r--man-src/maim.1.ronn107
-rw-r--r--src/cmdline.c1045
-rw-r--r--src/cmdline.in259
-rw-r--r--src/im.cpp315
-rw-r--r--src/im.hpp52
-rw-r--r--src/main.cpp381
-rw-r--r--src/options.ggo125
-rw-r--r--src/x.cpp95
-rw-r--r--src/x.hpp56
-rwxr-xr-xunitTests.sh44
22 files changed, 3941 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d08a91c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+# These files are ignored since cmake generates them from cmdline.in
+src/cmdline.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..76e84e8
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,130 @@
+cmake_minimum_required( VERSION 2.8 )
+
+project( "maim" )
+set( maim_VERSION_MAJOR 3 )
+set( maim_VERSION_MINOR 3 )
+set( maim_VERSION_PATCH 41 )
+
+set( BIN_TARGET "${PROJECT_NAME}" )
+
+if ( NOT CMAKE_INSTALL_PREFIX )
+ set( CMAKE_INSTALL_PREFIX "/usr" )
+endif()
+
+set( CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Directory where man pages reside. (/usr/share/man, /usr/local/share/man, etc.)" )
+
+set( CMAKE_COMPRESS_MAN TRUE CACHE BOOL "Whether or not to compress the man pages for install." )
+
+if ( CMAKE_COMPRESS_MAN )
+ set( MANTARGET "man-src/maim.1.gz" )
+else()
+ set( MANTARGET "man-src/maim.1" )
+endif()
+
+if( NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE )
+ set( CMAKE_BUILD_TYPE RelWithDebInfo )
+endif()
+
+# Linux compiler initialization.
+if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
+ "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
+ "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" )
+ set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-parameter" )
+ set( CMAKE_CXX_FLAGS_DEBUG "-Wextra -pedantic-errors -O0 -g" )
+ set( CMAKE_CXX_FLAGS_RELEASE "-O2" )
+ set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" )
+ # -Wall: Enable all warnings.
+ # -Wextra: Enable some more warnings.
+ # -Werror: Have errors on warnings.
+ # -pedantic-errors: Even more errors.
+ # -Wno-unused-parameter: Don't error on unused parameters, required since we have function hooks
+ # that have unused parameters.
+ # -O#: Optimization level
+else()
+ message( FATAL_ERROR "Your operating system isn't supported yet! CMake will now exit." )
+endif()
+
+# Add a check target for our makefile.
+find_program( CPPCHECK_EXECUTABLE cppcheck
+ DOC "A tool for static C/C++ code analysis." )
+if ( CPPCHECK_EXECUTABLE )
+ add_custom_target( "check"
+ COMMAND "${CPPCHECK_EXECUTABLE}" "--enable=all" "*"
+ WORKING_DIRECTORY src VERBATIM )
+endif()
+
+# Add our manpage generator if possible. Not needed as we include the man pages by default.
+find_program( RONN_EXECUTABLE ronn
+ DOC "A tool for generating our manpages." )
+find_program( GZIP_EXECUTABLE gzip
+ DOC "A tool for generating our manpages." )
+if ( RONN_EXECUTABLE AND GZIP_EXECUTABLE )
+ add_custom_target( "man"
+ COMMAND "${RONN_EXECUTABLE}" "-r" "maim.1.ronn"
+ COMMAND "${GZIP_EXECUTABLE}" "-k" "maim.1"
+ WORKING_DIRECTORY man-src VERBATIM )
+endif()
+
+# Here we generate some of our code if we can. I package it pre-generated
+# so nobody has to go find and install gengetopt if they don't want to.
+find_program( GENGETOPT_EXECUTABLE gengetopt
+ DOC "A tool to generate code to grab command line options." )
+if ( GENGETOPT_EXECUTABLE )
+ message( "-- Regenerating cmdline.in" )
+ execute_process( COMMAND "${GENGETOPT_EXECUTABLE}" "--input=options.ggo"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src" )
+ file( RENAME "${CMAKE_SOURCE_DIR}/src/cmdline.h" "${CMAKE_SOURCE_DIR}/src/cmdline.in" )
+else()
+ message( "Warning: Command gengetopt not found! Won't regenerate command line code. (If you're just compiling this doesn't matter.)" )
+endif()
+
+# By default our src/options.ggo has our cmake versions variables for
+# the 'version ""' line. We replace them here.
+# The ${CMAKE_SOURCE_DIR} is there to fix problems with OpenBSD's out-of-source build black magic.
+configure_file( "src/cmdline.in" "${CMAKE_SOURCE_DIR}/src/cmdline.h" )
+
+# This allows for "make README.md" to be ran to update the README's help
+# section automatically. We don't add it to ALL because running arbitrary
+# scripts is unsafe and I don't know if systems will actually have it
+# be executbable.
+add_custom_target( README.md "./generateReadme.sh" DEPENDS "maim" )
+
+# Sources
+set( source
+ src/cmdline.c
+ src/im.cpp
+ src/x.cpp
+ src/main.cpp )
+
+# Obtain library paths and make sure they exist.
+set( CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmakemodules" )
+find_package( Imlib2 REQUIRED )
+find_package( X11 REQUIRED )
+find_package( XRandr REQUIRED )
+find_package( XFixes REQUIRED )
+
+set( CMAKE_CXX_FLAGS
+ "${CMAKE_CXX_FLAGS} ${CMAKE_IMLIB2_CXX_FLAGS}" )
+
+# Includes
+include_directories( "${IMLIB2_INCLUDE_DIR}"
+ "${XRANDR_INCLUDE_DIR}"
+ "${X11_INCLUDE_DIR}"
+ "${XFIXES_INCLUDE_DIR}" )
+
+# Executable
+add_executable( "${BIN_TARGET}" ${source} )
+
+# Libraries
+target_link_libraries( "${BIN_TARGET}"
+ ${IMLIB2_LIBRARIES}
+ ${X11_LIBRARIES}
+ "${XRANDR_LIBRARY}"
+ "${XFIXES_LIBRARY}" )
+
+install( TARGETS "${BIN_TARGET}"
+ DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )
+
+install( FILES "${CMAKE_SOURCE_DIR}/${MANTARGET}"
+ DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
+ COMPONENT doc )
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..bdeef3e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,171 @@
+# maim
+
+maim (Make Image) is a utility that takes screenshots of your desktop using imlib2. It's meant to overcome shortcomings of scrot and performs better in several ways.
+
+## Features
+* Allows you to take a screenshot of your desktop and save it in any format.
+* Allows you to take a screenshot of a predetermined region or window of your desktop.
+* If slop (https://github.com/naelstrof/slop) is installed, it can be used for selecting a region to screenshot.
+
+![slopgood](http://farmpolice.com/content/images/2014-10-14-12:14:51.png)
+* Allows you to blend the system cursor to screenshots. (Why don't any other commandline screenshooters do this?)
+
+![screenshot with cursor](http://farmpolice.com/content/images/wow.png)
+
+* Allows you to mask off-screen pixels to be black and transparent in screenshots. (Great for people who use an uneven multi-monitor setup!)
+
+![screenshot mask comparison](http://farmpolice.com/content/images/mask_compare2.png)
+
+## Why use maim over import or scrot?
+* Compared to scrot
+ - maim has no --exec or naming features. This is because maim follows the unix philosophy of "do one thing and do it well". These features are things that should be handled by the shell.
+ - scrot has no way to screenshot a predefined region. maim comes equipped with --geometry features that allow for specified region capture.
+ - With [slop](https://github.com/naelstrof/slop) installed, maim's --select option is far superior to scrot's -s option in many ways. See [slop](https://github.com/naelstrof/slop) for more details.
+ - maim will never error with `giblib error: couldn't grab keyboard:Resource temporarily unavailable` as it never grabs the keyboard. (slop does, but it has proper error handling that keeps it from crashing.)
+* Compared to ImageMagick's import
+ - import doesn't play nicely with compositors; making effects like transparent windows not render properly in the screenshot. maim, like scrot, uses imlib2 which isn't inflicted with this problem.
+* Compared to either
+ - maim can actually take screenshots with your cursor included in them! It does this using the XFixes extension. To my knowledge, no other commandline screenshot utility does this.
+ - For those of you with multiple monitors, maim is aware of which pixels are visible or not and will make off-screen pixels that are in screenshots black and transparent. Import and scrot both mindlessly include off-screen pixel data in their screenshots which is very often just garbage.
+
+## Examples
+I'm including this section because some people don't see how powerful and flexible their shell can be with simple tools like maim. Remember you can always bind keys to shell commands!
+The following can be executed in any bash-like shells:
+
+* Set the screenshot's name to the current time and date:
+```bash
+$ maim ~/Pictures/$(date +%F-%T).png
+```
+
+* Take a screenshot of the active window: (Requires xdotool.)
+```bash
+$ maim -i $(xdotool getactivewindow)
+```
+
+* Custom transparent red selection with 10 pixel padding: (Requires [slop](https://github.com/naelstrof/slop).)
+```bash
+$ maim -s -c 1,0,0,0.6 -p 10
+```
+![Image of maim selecting a window](http://farmpolice.com/content/images/window_selection.png)
+
+* Automatically upload selected region to Imgur: (Requires [Bart's Bash Script Imgur Uploader](http://imgur.com/tools/imgurbash.sh), xclip is optional.)
+```bash
+$ maim -s /tmp/screenshot.png; imgurbash.sh /tmp/screenshot.png
+$ # If xclip is installed, your clipboard should have the online screenshot's URL in it!
+```
+
+In review, maim does one thing and does it well: it takes a screenshot of what you want. :) What you want is up to you, your programming skills, and your imagination.
+
+## How to install
+
+### Install using your Package Manager (preferred)
+
+* [Arch Linux: community/maim](https://www.archlinux.org/packages/community/x86_64/maim/)
+* [Void Linux: maim](https://github.com/voidlinux/void-packages/blob/24ac22af44018e2598047e5ef7fd3522efa79db5/srcpkgs/maim/template)
+* [FreeBSD: graphics/maim](http://www.freshports.org/graphics/maim/)
+* [OpenBSD: graphics/maim](http://openports.se/graphics/maim)
+* Please make a package for maim on your favorite system, and make a pull request to add it to this list.
+
+
+### Install using CMake (Requires CMake)
+
+Note: Dependencies should be installed first: Imlib2, libXrandr, and libXfixes.
+
+```bash
+git clone https://github.com/naelstrof/maim.git
+cd maim
+cmake ./
+make && sudo make install
+```
+
+Make sure to check out and install [slop](https://github.com/naelstrof/slop) too if you want selection capabilities!
+
+help
+----
+Join us on irc at freenode in *#maim*.
+```text
+maim v3.3.41
+
+Copyright (C) 2014 Dalton Nell, Maim Contributors
+(https://github.com/naelstrof/maim/graphs/contributors)
+
+Takes screenshots.
+
+Usage: maim [options] [file]
+
+maim (Make Image) is a utility that takes screenshots of your desktop using
+imlib2. It's meant to overcome shortcomings of scrot and performs better than
+scrot in several ways.
+
+ --help Print help and exit
+ -V, --version Print version and exit
+Options
+ --xdisplay=hostname:number.screen_number
+ Sets the x display.
+ -s, --select Enables user region selection. Requires slop to
+ be installed. (default=off)
+ -x, --x=INT Sets the x coordinate for taking an image
+ -y, --y=INT Sets the y coordinate for taking an image
+ -w, --w=INT Sets the width for taking an image
+ -h, --h=INT Sets the height for taking an image
+ -g, --geometry=WxH+X+Y Set the region to capture
+ -d, --delay=FLOAT Set the amount of time to wait before taking an
+ image. (default=`0.0')
+ -i, --windowid=INT Set the window to capture. Defaults to the root
+ window id.
+ --localize Localizes given geometry to the given window.
+ So "maim -i $ID -g 100x100+0+0 --localize"
+ would screenshot the top-left 100x100 pixels
+ of the given window, rather than the top-left
+ 100x100 pixels of the root window.
+ (default=off)
+ --hidecursor Prevents the system cursor from showing up in
+ screenshots. (default=off)
+ -m, --mask=STRING Masks off-screen pixels so they don't show up
+ in screenshots. (possible values="auto",
+ "off", "on" default=`auto')
+
+Slop Options
+ --nokeyboard Disables the ability to cancel selections with
+ the keyboard. (default=off)
+ -b, --bordersize=INT Set the selection rectangle's thickness. Does
+ nothing when --highlight is enabled.
+ (default=`5')
+ -p, --padding=INT Set the padding size of the selection. Can be
+ negative. (default=`0')
+ -t, --tolerance=INT How far in pixels the mouse can move after
+ clicking and still be detected as a normal
+ click instead of a click and drag. Setting
+ this to 0 will disable window selections.
+ (default=`2')
+ --gracetime=FLOAT Set the amount of time before slop will check
+ for keyboard cancellations in seconds.
+ (default=`0.4')
+ -c, --color=FLOAT,FLOAT,FLOAT,FLOAT
+ Set the selection rectangle's color. Supports
+ RGB or RGBA values.
+ (default=`0.5,0.5,0.5,1')
+ -n, --nodecorations Attempt to select child windows in order to
+ avoid window decorations. (default=off)
+ --min=INT Set the minimum output of width or height
+ values. This is useful to avoid outputting 0.
+ Setting min and max to the same value
+ disables drag selections. (default=`0')
+ --max=INT Set the maximum output of width or height
+ values. Setting min and max to the same value
+ disables drag selections. (default=`0')
+ -l, --highlight Instead of outlining selections, slop
+ highlights it. This is only useful when
+ --color is set to a transparent color.
+ (default=off)
+
+Examples
+ $ # Screenshot the active window
+ $ maim -i $(xdotool getactivewindow)
+
+ $ # Prompt a transparent red selection to screenshot.
+ $ maim -s -c 1,0,0,0.6
+
+ $ # Save a dated screenshot.
+ $ maim ~/$(date +%F-%T).png
+```
diff --git a/cmakemodules/FindImlib2.cmake b/cmakemodules/FindImlib2.cmake
new file mode 100644
index 0000000..660ceb0
--- /dev/null
+++ b/cmakemodules/FindImlib2.cmake
@@ -0,0 +1,91 @@
+#
+# This module finds if IMLIB2 is available and determines where the
+# include files and libraries are.
+# On Unix/Linux it relies on the output of imlib2-config.
+# This code sets the following variables:
+#
+#
+#
+# IMLIB2_FOUND = system has IMLIB2 lib
+#
+# IMLIB2_LIBRARIES = full path to the libraries
+# on Unix/Linux with additional linker flags from "imlib2-config --libs"
+#
+# CMAKE_IMLIB2_CXX_FLAGS = Unix compiler flags for IMLIB2, essentially "`imlib2-config --cxxflags`"
+#
+# IMLIB2_INCLUDE_DIR = where to find headers
+#
+# IMLIB2_LINK_DIRECTORIES = link directories, useful for rpath on Unix
+#
+#
+# author Jan Woetzel and Jan-Friso Evers
+# www.mip.informatik.uni-kiel.de/~jw
+
+IF(WIN32)
+ MESSAGE("FindIMLIB2.cmake: IMLIB2 not (yet) supported on WIN32")
+ SET(IMLIB2_FOUND OFF )
+ELSE(WIN32)
+ IF(UNIX)
+ SET(IMLIB2_CONFIG_PREFER_PATH "$ENV{IMLIB2_HOME}/bin" CACHE STRING "preferred path to imlib2")
+ FIND_PROGRAM(IMLIB2_CONFIG imlib2-config
+ ${IMLIB2_CONFIG_PREFER_PATH}
+ /usr/bin/
+ /opt/gnome/bin/)
+
+ IF (IMLIB2_CONFIG)
+ # OK, found imlib2-config.
+ # set CXXFLAGS to be fed into CXX_FLAGS by the user:
+ SET(IMLIB2_CXX_FLAGS "`${IMLIB2_CONFIG} --cflags`")
+
+ # set INCLUDE_DIRS to prefix+include
+ EXEC_PROGRAM(${IMLIB2_CONFIG}
+ ARGS --prefix
+ OUTPUT_VARIABLE IMLIB2_PREFIX)
+ SET(IMLIB2_INCLUDE_DIR ${IMLIB2_PREFIX}/include CACHE STRING INTERNAL)
+
+ # extract link dirs for rpath
+ EXEC_PROGRAM(${IMLIB2_CONFIG}
+ ARGS --libs
+ OUTPUT_VARIABLE IMLIB2_CONFIG_LIBS)
+
+ # set link libraries and link flags
+ #SET(IMLIB2_LIBRARIES "`${IMLIB2_CONFIG} --libs`")
+ SET(IMLIB2_LIBRARIES ${IMLIB2_CONFIG_LIBS})
+
+ # split off the link dirs (for rpath)
+ # use regular expression to match wildcard equivalent "-L*<endchar>"
+ # with <endchar> is a space or a semicolon
+ STRING(REGEX MATCHALL "[-][L]([^ ;])+"
+ IMLIB2_LINK_DIRECTORIES_WITH_PREFIX
+ "${IMLIB2_CONFIG_LIBS}")
+ #MESSAGE("DBG IMLIB2_LINK_DIRECTORIES_WITH_PREFIX=${IMLIB2_LINK_DIRECTORIES_WITH_PREFIX}")
+
+ # remove prefix -L because we need the pure directory for LINK_DIRECTORIES
+ # replace -L by ; because the separator seems to be lost otherwise (bug or feature?)
+ IF (IMLIB2_LINK_DIRECTORIES_WITH_PREFIX)
+ STRING(REGEX REPLACE "[-][L]" ";" IMLIB2_LINK_DIRECTORIES ${IMLIB2_LINK_DIRECTORIES_WITH_PREFIX} )
+ #MESSAGE("DBG IMLIB2_LINK_DIRECTORIES=${IMLIB2_LINK_DIRECTORIES}")
+ ENDIF (IMLIB2_LINK_DIRECTORIES_WITH_PREFIX)
+
+ # replace space separated string by semicolon separated vector to make
+ # it work with LINK_DIRECTORIES
+ SEPARATE_ARGUMENTS(IMLIB2_LINK_DIRECTORIES)
+
+ MARK_AS_ADVANCED(IMLIB2_CXX_FLAGS
+ IMLIB2_INCLUDE_DIR
+ IMLIB2_LIBRARIES
+ IMLIB2_LINK_DIRECTORIES
+ IMLIB2_CONFIG_PREFER_PATH
+ IMLIB2_CONFIG)
+
+ ELSE(IMLIB2_CONFIG)
+ MESSAGE( "FindIMLIB2.cmake: imlib2-config not found. Please set it manually. IMLIB2_CONFIG=${IMLIB2_CONFIG}")
+ ENDIF(IMLIB2_CONFIG)
+ ENDIF(UNIX)
+ENDIF(WIN32)
+
+IF(IMLIB2_LIBRARIES)
+ IF(IMLIB2_INCLUDE_DIR OR IMLIB2_CXX_FLAGS)
+ SET(IMLIB2_FOUND 1)
+ ENDIF(IMLIB2_INCLUDE_DIR OR IMLIB2_CXX_FLAGS)
+ENDIF(IMLIB2_LIBRARIES)
diff --git a/cmakemodules/FindXFixes.cmake b/cmakemodules/FindXFixes.cmake
new file mode 100644
index 0000000..a832cab
--- /dev/null
+++ b/cmakemodules/FindXFixes.cmake
@@ -0,0 +1,26 @@
+# - Find XFixes
+# Find the XFixes libraries
+#
+# This module defines the following variables:
+# XFIXES_FOUND - 1 if XFIXES_INCLUDE_DIR & XFIXES_LIBRARY are found, 0 otherwise
+# XFIXES_INCLUDE_DIR - where to find Xlib.h, etc.
+# XFIXES_LIBRARY - the X11 library
+#
+
+find_path( XFIXES_INCLUDE_DIR
+ NAMES X11/extensions/Xfixes.h
+ PATH_SUFFIXES X11/extensions
+ DOC "The XFixes include directory" )
+
+find_library( XFIXES_LIBRARY
+ NAMES Xfixes
+ PATHS /usr/lib /lib
+ DOC "The XFixes library" )
+
+if( XFIXES_INCLUDE_DIR AND XFIXES_LIBRARY )
+ set( XFIXES_FOUND 1 )
+else()
+ set( XFIXES_FOUND 0 )
+endif()
+
+mark_as_advanced( XFIXES_INCLUDE_DIR XFIXES_LIBRARY )
diff --git a/cmakemodules/FindXRandr.cmake b/cmakemodules/FindXRandr.cmake
new file mode 100644
index 0000000..1f48e22
--- /dev/null
+++ b/cmakemodules/FindXRandr.cmake
@@ -0,0 +1,26 @@
+# - Find XRandr
+# Find the XRandr libraries
+#
+# This module defines the following variables:
+# XRANDR_FOUND - 1 if XRANDR_INCLUDE_DIR & XRANDR_LIBRARY are found, 0 otherwise
+# XRANDR_INCLUDE_DIR - where to find Xlib.h, etc.
+# XRANDR_LIBRARY - the X11 library
+#
+
+find_path( XRANDR_INCLUDE_DIR
+ NAMES X11/extensions/Xrandr.h
+ PATH_SUFFIXES X11/extensions
+ DOC "The XRandr include directory" )
+
+find_library( XRANDR_LIBRARY
+ NAMES Xrandr
+ PATHS /usr/lib /lib
+ DOC "The XRandr library" )
+
+if( XRANDR_INCLUDE_DIR AND XRANDR_LIBRARY )
+ set( XRANDR_FOUND 1 )
+else()
+ set( XRANDR_FOUND 0 )
+endif()
+
+mark_as_advanced( XRANDR_INCLUDE_DIR XRANDR_LIBRARY )
diff --git a/generateReadme.sh b/generateReadme.sh
new file mode 100755
index 0000000..1937d38
--- /dev/null
+++ b/generateReadme.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+# generateReadme.sh: Regenerates the help section of the README.md using output from ./maim --help.
+
+# Remove help section
+sed -i '/^help$/,/^```$/d' README.md
+
+# Add the help section again.
+echo 'help' >> README.md
+echo '----' >> README.md
+echo 'Join us on irc at freenode in *#maim*.' >> README.md
+echo '```text' >> README.md
+echo "$(./maim --help)" >> README.md
+echo '```' >> README.md
diff --git a/license.txt b/license.txt
new file mode 100644
index 0000000..7b8a8c4
--- /dev/null
+++ b/license.txt
@@ -0,0 +1,14 @@
+Copyright (C) 2014 Dalton Nell, Maim Contributors (https://github.com/naelstrof/maim/graphs/contributors)
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/man-src/maim.1 b/man-src/maim.1
new file mode 100644
index 0000000..10cfe7b
--- /dev/null
+++ b/man-src/maim.1
@@ -0,0 +1,157 @@
+.\" generated with Ronn/v0.7.3
+.\" http://github.com/rtomayko/ronn/tree/0.7.3
+.
+.TH "MAIM" "1" "December 2014" "" ""
+.
+.SH "NAME"
+\fBmaim\fR \- Takes screenshots
+.
+.SH "SYNOPSIS"
+\fBmaim\fR [options] [file]
+.
+.SH "DESCRIPTION"
+maim (MAke IMage) is a utility that takes screenshots of your desktop using imlib2\. It\'s meant to overcome shortcomings of scrot and performs better than scrot in several ways\.
+.
+.SH "OPTIONS"
+.
+.TP
+\fB\-\-help\fR
+Print help and exit
+.
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Print version and exit
+.
+.SS "Options"
+.
+.TP
+\fB\-\-xdisplay=hostname:number\.screen_number\fR
+Sets the x display\.
+.
+.TP
+\fB\-s\fR, \fB\-\-select\fR
+Enables user region selection\. Requires slop to be installed\. (default=off)
+.
+.TP
+\fB\-x\fR, \fB\-\-x=INT\fR
+Sets the x coordinate for taking an image
+.
+.TP
+\fB\-y\fR, \fB\-\-y=INT\fR
+Sets the y coordinate for taking an image
+.
+.TP
+\fB\-w\fR, \fB\-\-w=INT\fR
+Sets the width for taking an image
+.
+.TP
+\fB\-h\fR, \fB\-\-h=INT\fR
+Sets the height for taking an image
+.
+.TP
+\fB\-g\fR, \fB\-\-geometry=WxH+X+Y\fR
+Set the region to capture
+.
+.TP
+\fB\-d\fR, \fB\-\-delay=FLOAT\fR
+Set the amount of time to wait before taking an image\. (default=`0\.0\')
+.
+.TP
+\fB\-i\fR, \fB\-\-windowid=INT\fR
+Set the window to capture\. Defaults to the root window id\.
+.
+.TP
+\fB\-\-localize\fR
+Localizes given geometry to the given window\. So \fBmaim \-i $ID \-g 100x100+0+0 \-\-localize\fR would screenshot the top\-left 100x100 pixels of the given window, rather than the top\-left 100x100 pixels of the root window\. (default=off)
+.
+.TP
+\fB\-\-hidecursor\fR
+Prevents the system cursor from showing up in screenshots\. (default=off)
+.
+.TP
+\fB\-m\fR, \fB\-\-mask=STRING\fR
+Masks off\-screen pixels so they don\'t show up in screenshots\. (possible values="auto", "off", "on" default=`auto\')
+.
+.SS "SLOP OPTIONS"
+.
+.TP
+\fB\-\-nokeyboard\fR
+Disables the ability to cancel selections with the keyboard\. (default=off)
+.
+.TP
+\fB\-b\fR, \fB\-\-bordersize=INT\fR
+Set the selection rectangle\'s thickness\. Does nothing when \fB\-\-highlight\fR is enabled\. (default=`5\')
+.
+.TP
+\fB\-p\fR, \fB\-\-padding=INT\fR
+Set the padding size of the selection\. Can be negative\. (default=`0\')
+.
+.TP
+\fB\-t\fR, \fB\-\-tolerance=INT\fR
+How far in pixels the mouse can move after clicking and still be detected as a normal click instead of a click and drag\. Setting this to 0 will disable window selections\. (default=`2\')
+.
+.TP
+\fB\-\-gracetime=FLOAT\fR
+Set the amount of time before slop will check for keyboard cancellations in seconds\. (default=`0\.4\')
+.
+.TP
+\fB\-c\fR, \fB\-\-color=FLOAT,FLOAT,FLOAT,FLOAT\fR
+Set the selection rectangle\'s color\. Supports RGB or RGBA values\. (default=`0\.5,0\.5,0\.5,1\')
+.
+.TP
+\fB\-n\fR, \fB\-\-nodecorations\fR
+Attempt to select child windows in order to avoid window decorations\. (default=off)
+.
+.TP
+\fB\-\-min=INT\fR
+Set the minimum output of width or height values\. This is useful to avoid outputting 0\. Setting min and max to the same value disables drag selections\. (default=`0\')
+.
+.TP
+\fB\-\-max=INT\fR
+Set the maximum output of width or height values\. Setting min and max to the same value disables drag selections\. (default=`0\')
+.
+.TP
+\fB\-l\fR, \fB\-\-highlight\fR
+Instead of outlining selections, slop highlights it\. This is only useful when \fB\-\-color\fR is set to a transparent color\. (default=off)
+.
+.SH "EXAMPLES"
+Screenshot the active window
+.
+.IP "" 4
+.
+.nf
+
+$ maim \-i $(xdotool getactivewindow)
+.
+.fi
+.
+.IP "" 0
+.
+.P
+Prompt a transparent red selection to screenshot\.
+.
+.IP "" 4
+.
+.nf
+
+$ maim \-s \-c 1,0,0,0\.6
+.
+.fi
+.
+.IP "" 0
+.
+.P
+Save a dated screenshot\.
+.
+.IP "" 4
+.
+.nf
+
+$ maim ~/$(date +%F\-%T)\.png
+.
+.fi
+.
+.IP "" 0
+.
+.SH "COPYRIGHT"
+Copyright (C) 2014 Dalton Nell \fB<naelstrof@gmail\.com>\fR, Maim Contributors \fB<http://github\.com/naelstrof/maim/graphs/contributors>\fR\.
diff --git a/man-src/maim.1.gz b/man-src/maim.1.gz
new file mode 100644
index 0000000..0ae9419
--- /dev/null
+++ b/man-src/maim.1.gz
Binary files differ
diff --git a/man-src/maim.1.html b/man-src/maim.1.html
new file mode 100644
index 0000000..b7fcf1b
--- /dev/null
+++ b/man-src/maim.1.html
@@ -0,0 +1,158 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv='content-type' value='text/html;charset=utf8'>
+ <meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
+ <title>maim(1) - Takes screenshots</title>
+ <style type='text/css' media='all'>
+ /* style: man */
+ body#manpage {margin:0}
+ .mp {max-width:100ex;padding:0 9ex 1ex 4ex}
+ .mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
+ .mp h2 {margin:10px 0 0 0}
+ .mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
+ .mp h3 {margin:0 0 0 4ex}
+ .mp dt {margin:0;clear:left}
+ .mp dt.flush {float:left;width:8ex}
+ .mp dd {margin:0 0 0 9ex}
+ .mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
+ .mp pre {margin-bottom:20px}
+ .mp pre+h2,.mp pre+h3 {margin-top:22px}
+ .mp h2+pre,.mp h3+pre {margin-top:5px}
+ .mp img {display:block;margin:auto}
+ .mp h1.man-title {display:none}
+ .mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
+ .mp h2 {font-size:16px;line-height:1.25}
+ .mp h1 {font-size:20px;line-height:2}
+ .mp {text-align:justify;background:#fff}
+ .mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
+ .mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
+ .mp u {text-decoration:underline}
+ .mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
+ .mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
+ .mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
+ .mp b.man-ref {font-weight:normal;color:#434241}
+ .mp pre {padding:0 4ex}
+ .mp pre code {font-weight:normal;color:#434241}
+ .mp h2+pre,h3+pre {padding-left:0}
+ ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
+ ol.man-decor {width:100%}
+ ol.man-decor li.tl {text-align:left}
+ ol.man-decor li.tc {text-align:center;letter-spacing:4px}
+ ol.man-decor li.tr {text-align:right;float:right}
+ </style>
+</head>
+<!--
+ The following styles are deprecated and will be removed at some point:
+ div#man, div#man ol.man, div#man ol.head, div#man ol.man.
+
+ The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
+ .man-navigation should be used instead.
+-->
+<body id='manpage'>
+ <div class='mp' id='man'>
+
+ <div class='man-navigation' style='display:none'>
+ <a href="#NAME">NAME</a>
+ <a href="#SYNOPSIS">SYNOPSIS</a>
+ <a href="#DESCRIPTION">DESCRIPTION</a>
+ <a href="#OPTIONS">OPTIONS</a>
+ <a href="#EXAMPLES">EXAMPLES</a>
+ <a href="#COPYRIGHT">COPYRIGHT</a>
+ </div>
+
+ <ol class='man-decor man-head man head'>
+ <li class='tl'>maim(1)</li>
+ <li class='tc'></li>
+ <li class='tr'>maim(1)</li>
+ </ol>
+
+ <h2 id="NAME">NAME</h2>
+<p class="man-name">
+ <code>maim</code> - <span class="man-whatis">Takes screenshots</span>
+</p>
+
+<h2 id="SYNOPSIS">SYNOPSIS</h2>
+
+<p><code>maim</code> [options] [file]</p>
+
+<h2 id="DESCRIPTION">DESCRIPTION</h2>
+
+<p>maim (MAke IMage) is a utility that takes screenshots of your desktop using
+imlib2. It's meant to overcome shortcomings of scrot and performs better than
+scrot in several ways.</p>
+
+<h2 id="OPTIONS">OPTIONS</h2>
+
+<dl>
+<dt class="flush"><code>--help</code></dt><dd><p>Print help and exit</p></dd>
+<dt><code>-V</code>, <code>--version</code></dt><dd><p>Print version and exit</p></dd>
+</dl>
+
+
+<h3 id="Options">Options</h3>
+
+<dl>
+<dt><code>--xdisplay=hostname:number.screen_number</code></dt><dd><p>Sets the x display.</p></dd>
+<dt><code>-s</code>, <code>--select</code></dt><dd><p>Enables user region selection. Requires slop to
+be installed. (default=off)</p></dd>
+<dt><code>-x</code>, <code>--x=INT</code></dt><dd><p>Sets the x coordinate for taking an image</p></dd>
+<dt><code>-y</code>, <code>--y=INT</code></dt><dd><p>Sets the y coordinate for taking an image</p></dd>
+<dt><code>-w</code>, <code>--w=INT</code></dt><dd><p>Sets the width for taking an image</p></dd>
+<dt><code>-h</code>, <code>--h=INT</code></dt><dd><p>Sets the height for taking an image</p></dd>
+<dt><code>-g</code>, <code>--geometry=WxH+X+Y</code></dt><dd><p>Set the region to capture</p></dd>
+<dt><code>-d</code>, <code>--delay=FLOAT</code></dt><dd><p>Set the amount of time to wait before taking an image. (default=`0.0')</p></dd>
+<dt><code>-i</code>, <code>--windowid=INT</code></dt><dd><p>Set the window to capture. Defaults to the root window id.</p></dd>
+<dt><code>--localize</code></dt><dd><p>Localizes given geometry to the given window. So <code>maim -i $ID -g 100x100+0+0 --localize</code> would screenshot the top-left 100x100 pixels of the given window, rather than the top-left 100x100 pixels of the root window. (default=off)</p></dd>
+<dt><code>--hidecursor</code></dt><dd><p>Prevents the system cursor from showing up in screenshots. (default=off)</p></dd>
+<dt><code>-m</code>, <code>--mask=STRING</code></dt><dd><p>Masks off-screen pixels so they don't show up in screenshots. (possible values="auto", "off", "on" default=`auto')</p></dd>
+</dl>
+
+
+<h3 id="SLOP-OPTIONS">SLOP OPTIONS</h3>
+
+<dl>
+<dt><code>--nokeyboard</code></dt><dd><p>Disables the ability to cancel selections with the keyboard. (default=off)</p></dd>
+<dt><code>-b</code>, <code>--bordersize=INT</code></dt><dd><p>Set the selection rectangle's thickness. Does nothing when <code>--highlight</code> is enabled. (default=`5')</p></dd>
+<dt><code>-p</code>, <code>--padding=INT</code></dt><dd><p>Set the padding size of the selection. Can be negative. (default=`0')</p></dd>
+<dt><code>-t</code>, <code>--tolerance=INT</code></dt><dd><p>How far in pixels the mouse can move after clicking and still be detected as a normal click instead of a click and drag. Setting this to 0 will disable window selections. (default=`2')</p></dd>
+<dt><code>--gracetime=FLOAT</code></dt><dd><p>Set the amount of time before slop will check for keyboard cancellations in seconds. (default=`0.4')</p></dd>
+<dt><code>-c</code>, <code>--color=FLOAT,FLOAT,FLOAT,FLOAT</code></dt><dd><p>Set the selection rectangle's color. Supports RGB or RGBA values. (default=`0.5,0.5,0.5,1')</p></dd>
+<dt><code>-n</code>, <code>--nodecorations</code></dt><dd><p>Attempt to select child windows in order to avoid window decorations. (default=off)</p></dd>
+<dt><code>--min=INT</code></dt><dd><p>Set the minimum output of width or height values. This is useful to avoid outputting 0. Setting min and max to the same value disables drag selections. (default=`0')</p></dd>
+<dt><code>--max=INT</code></dt><dd><p>Set the maximum output of width or height values. Setting min and max to the same value disables drag selections. (default=`0')</p></dd>
+<dt><code>-l</code>, <code>--highlight</code></dt><dd><p>Instead of outlining selections, slop highlights it. This is only useful when <code>--color</code> is set to a transparent color. (default=off)</p></dd>
+</dl>
+
+
+<h2 id="EXAMPLES">EXAMPLES</h2>
+
+<p> Screenshot the active window</p>
+
+<pre><code>$ maim -i $(xdotool getactivewindow)
+</code></pre>
+
+<p> Prompt a transparent red selection to screenshot.</p>
+
+<pre><code>$ maim -s -c 1,0,0,0.6
+</code></pre>
+
+<p> Save a dated screenshot.</p>
+
+<pre><code>$ maim ~/$(date +%F-%T).png
+</code></pre>
+
+<h2 id="COPYRIGHT">COPYRIGHT</h2>
+
+<p>Maim is Copyright (C) 2014 Dalton Nell <code>&lt;naelstrof@gmail.com&gt;</code> and Maim Contributors <code>&lt;http://github.com/naelstrof/maim/graphs/contributors&gt;</code></p>
+
+
+ <ol class='man-decor man-foot man foot'>
+ <li class='tl'></li>
+ <li class='tc'>December 2014</li>
+ <li class='tr'>maim(1)</li>
+ </ol>
+
+ </div>
+</body>
+</html>
diff --git a/man-src/maim.1.ronn b/man-src/maim.1.ronn
new file mode 100644
index 0000000..107a0ab
--- /dev/null
+++ b/man-src/maim.1.ronn
@@ -0,0 +1,107 @@
+maim(1) -- Takes screenshots
+============================
+
+## SYNOPSIS
+
+`maim` [options] [file]
+
+## DESCRIPTION
+
+maim (MAke IMage) is a utility that takes screenshots of your desktop using
+imlib2. It's meant to overcome shortcomings of scrot and performs better than
+scrot in several ways.
+
+## OPTIONS
+
+ * `--help`:
+ Print help and exit
+
+ * `-V`, `--version`:
+ Print version and exit
+
+### Options
+
+ * `--xdisplay=hostname:number.screen_number`:
+ Sets the x display.
+
+ * `-s`, `--select`:
+ Enables user region selection. Requires slop to
+ be installed. (default=off)
+
+ * `-x`, `--x=INT`:
+ Sets the x coordinate for taking an image
+
+ * `-y`, `--y=INT`:
+ Sets the y coordinate for taking an image
+
+ * `-w`, `--w=INT`:
+ Sets the width for taking an image
+
+ * `-h`, `--h=INT`:
+ Sets the height for taking an image
+
+ * `-g`, `--geometry=WxH+X+Y`:
+ Set the region to capture
+
+ * `-d`, `--delay=FLOAT`:
+ Set the amount of time to wait before taking an image. (default=`0.0')
+
+ * `-i`, `--windowid=INT`:
+ Set the window to capture. Defaults to the root window id.
+
+ * `--localize`:
+ Localizes given geometry to the given window. So `maim -i $ID -g 100x100+0+0 --localize` would screenshot the top-left 100x100 pixels of the given window, rather than the top-left 100x100 pixels of the root window. (default=off)
+
+ * `--hidecursor`:
+ Prevents the system cursor from showing up in screenshots. (default=off)
+
+ * `-m`, `--mask=STRING`:
+ Masks off-screen pixels so they don't show up in screenshots. (possible values="auto", "off", "on" default=`auto')
+
+### SLOP OPTIONS
+
+ * `--nokeyboard`:
+ Disables the ability to cancel selections with the keyboard. (default=off)
+
+ * `-b`, `--bordersize=INT`:
+ Set the selection rectangle's thickness. Does nothing when `--highlight` is enabled. (default=`5')
+
+ * `-p`, `--padding=INT`:
+ Set the padding size of the selection. Can be negative. (default=`0')
+
+ * `-t`, `--tolerance=INT`:
+ How far in pixels the mouse can move after clicking and still be detected as a normal click instead of a click and drag. Setting this to 0 will disable window selections. (default=`2')
+
+ * `--gracetime=FLOAT`:
+ Set the amount of time before slop will check for keyboard cancellations in seconds. (default=`0.4')
+
+ * `-c`, `--color=FLOAT,FLOAT,FLOAT,FLOAT`:
+ Set the selection rectangle's color. Supports RGB or RGBA values. (default=`0.5,0.5,0.5,1')
+
+ * `-n`, `--nodecorations`:
+ Attempt to select child windows in order to avoid window decorations. (default=off)
+
+ * `--min=INT`:
+ Set the minimum output of width or height values. This is useful to avoid outputting 0. Setting min and max to the same value disables drag selections. (default=`0')
+
+ * `--max=INT`:
+ Set the maximum output of width or height values. Setting min and max to the same value disables drag selections. (default=`0')
+
+ * `-l`, `--highlight`:
+ Instead of outlining selections, slop highlights it. This is only useful when `--color` is set to a transparent color. (default=off)
+
+## EXAMPLES
+Screenshot the active window
+
+ $ maim -i $(xdotool getactivewindow)
+
+Prompt a transparent red selection to screenshot.
+
+ $ maim -s -c 1,0,0,0.6
+
+Save a dated screenshot.
+
+ $ maim ~/$(date +%F-%T).png
+## COPYRIGHT
+
+Copyright (C) 2014 Dalton Nell `<naelstrof@gmail.com>`, Maim Contributors `<http://github.com/naelstrof/maim/graphs/contributors>`.
diff --git a/src/cmdline.c b/src/cmdline.c
new file mode 100644
index 0000000..24fcca6
--- /dev/null
+++ b/src/cmdline.c
@@ -0,0 +1,1045 @@
+/*
+ File autogenerated by gengetopt version 2.22.6
+ generated with the following command:
+ /usr/bin/gengetopt --input=options.ggo --unamed-opts --file-name=cmdline
+
+ The developers of gengetopt consider the fixed text that goes in all
+ gengetopt output files to be in the public domain:
+ we make no copyright claims on it.
+*/
+
+/* If we use autoconf. */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef FIX_UNUSED
+#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
+#endif
+
+#include <getopt.h>
+
+#include "cmdline.h"
+
+const char *gengetopt_args_info_purpose = "Takes screenshots.";
+
+const char *gengetopt_args_info_usage = "Usage: maim [options] [file]";
+
+const char *gengetopt_args_info_versiontext = "Copyright (C) 2014 Dalton Nell, Maim Contributors\n(https://github.com/naelstrof/maim/graphs/contributors)";
+
+const char *gengetopt_args_info_description = "maim (Make Image) is a utility that takes screenshots of your desktop using\nimlib2. It's meant to overcome shortcomings of scrot and performs better than\nscrot in several ways.";
+
+const char *gengetopt_args_info_help[] = {
+ " --help Print help and exit",
+ " -V, --version Print version and exit",
+ "Options",
+ " --xdisplay=hostname:number.screen_number\n Sets the x display.",
+ " -s, --select Enables user region selection. Requires slop to\n be installed. (default=off)",
+ " -x, --x=INT Sets the x coordinate for taking an image",
+ " -y, --y=INT Sets the y coordinate for taking an image",
+ " -w, --w=INT Sets the width for taking an image",
+ " -h, --h=INT Sets the height for taking an image",
+ " -g, --geometry=WxH+X+Y Set the region to capture",
+ " -d, --delay=FLOAT Set the amount of time to wait before taking an\n image. (default=`0.0')",
+ " -i, --windowid=INT Set the window to capture. Defaults to the root\n window id.",
+ " --localize Localizes given geometry to the given window.\n So \"maim -i $ID -g 100x100+0+0 --localize\"\n would screenshot the top-left 100x100 pixels\n of the given window, rather than the top-left\n 100x100 pixels of the root window.\n (default=off)",
+ " --hidecursor Prevents the system cursor from showing up in\n screenshots. (default=off)",
+ " -m, --mask=STRING Masks off-screen pixels so they don't show up\n in screenshots. (possible values=\"auto\",\n \"off\", \"on\" default=`auto')",
+ "\nSlop Options",
+ " --nokeyboard Disables the ability to cancel selections with\n the keyboard. (default=off)",
+ " -b, --bordersize=INT Set the selection rectangle's thickness. Does\n nothing when --highlight is enabled.\n (default=`5')",
+ " -p, --padding=INT Set the padding size of the selection. Can be\n negative. (default=`0')",
+ " -t, --tolerance=INT How far in pixels the mouse can move after\n clicking and still be detected as a normal\n click instead of a click and drag. Setting\n this to 0 will disable window selections.\n (default=`2')",
+ " --gracetime=FLOAT Set the amount of time before slop will check\n for keyboard cancellations in seconds.\n (default=`0.4')",
+ " -c, --color=FLOAT,FLOAT,FLOAT,FLOAT\n Set the selection rectangle's color. Supports\n RGB or RGBA values.\n (default=`0.5,0.5,0.5,1')",
+ " -n, --nodecorations Attempt to select child windows in order to\n avoid window decorations. (default=off)",
+ " --min=INT Set the minimum output of width or height\n values. This is useful to avoid outputting 0.\n Setting min and max to the same value\n disables drag selections. (default=`0')",
+ " --max=INT Set the maximum output of width or height\n values. Setting min and max to the same value\n disables drag selections. (default=`0')",
+ " -l, --highlight Instead of outlining selections, slop\n highlights it. This is only useful when\n --color is set to a transparent color.\n (default=off)",
+ "\nExamples\n $ # Screenshot the active window\n $ maim -i $(xdotool getactivewindow)\n\n $ # Prompt a transparent red selection to screenshot.\n $ maim -s -c 1,0,0,0.6\n\n $ # Save a dated screenshot.\n $ maim ~/$(date +%F-%T).png\n",
+ 0
+};
+
+typedef enum {ARG_NO
+ , ARG_FLAG
+ , ARG_STRING
+ , ARG_INT
+} cmdline_parser_arg_type;
+
+static
+void clear_given (struct gengetopt_args_info *args_info);
+static
+void clear_args (struct gengetopt_args_info *args_info);
+
+static int
+cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
+ struct cmdline_parser_params *params, const char *additional_error);
+
+
+const char *cmdline_parser_mask_values[] = {"auto", "off", "on", 0}; /*< Possible values for mask. */
+
+static char *
+gengetopt_strdup (const char *s);
+
+static
+void clear_given (struct gengetopt_args_info *args_info)
+{
+ args_info->help_given = 0 ;
+ args_info->version_given = 0 ;
+ args_info->xdisplay_given = 0 ;
+ args_info->select_given = 0 ;
+ args_info->x_given = 0 ;
+ args_info->y_given = 0 ;
+ args_info->w_given = 0 ;
+ args_info->h_given = 0 ;
+ args_info->geometry_given = 0 ;
+ args_info->delay_given = 0 ;
+ args_info->windowid_given = 0 ;
+ args_info->localize_given = 0 ;
+ args_info->hidecursor_given = 0 ;
+ args_info->mask_given = 0 ;
+ args_info->nokeyboard_given = 0 ;
+ args_info->bordersize_given = 0 ;
+ args_info->padding_given = 0 ;
+ args_info->tolerance_given = 0 ;
+ args_info->gracetime_given = 0 ;
+ args_info->color_given = 0 ;
+ args_info->nodecorations_given = 0 ;
+ args_info->min_given = 0 ;
+ args_info->max_given = 0 ;
+ args_info->highlight_given = 0 ;
+}
+
+static
+void clear_args (struct gengetopt_args_info *args_info)
+{
+ FIX_UNUSED (args_info);
+ args_info->xdisplay_arg = NULL;
+ args_info->xdisplay_orig = NULL;
+ args_info->select_flag = 0;
+ args_info->x_orig = NULL;
+ args_info->y_orig = NULL;
+ args_info->w_orig = NULL;
+ args_info->h_orig = NULL;
+ args_info->geometry_arg = NULL;
+ args_info->geometry_orig = NULL;
+ args_info->delay_arg = gengetopt_strdup ("0.0");
+ args_info->delay_orig = NULL;
+ args_info->windowid_orig = NULL;
+ args_info->localize_flag = 0;
+ args_info->hidecursor_flag = 0;
+ args_info->mask_arg = gengetopt_strdup ("auto");
+ args_info->mask_orig = NULL;
+ args_info->nokeyboard_flag = 0;
+ args_info->bordersize_arg = 5;
+ args_info->bordersize_orig = NULL;
+ args_info->padding_arg = 0;
+ args_info->padding_orig = NULL;
+ args_info->tolerance_arg = 2;
+ args_info->tolerance_orig = NULL;
+ args_info->gracetime_arg = gengetopt_strdup ("0.4");
+ args_info->gracetime_orig = NULL;
+ args_info->color_arg = gengetopt_strdup ("0.5,0.5,0.5,1");
+ args_info->color_orig = NULL;
+ args_info->nodecorations_flag = 0;
+ args_info->min_arg = 0;
+ args_info->min_orig = NULL;
+ args_info->max_arg = 0;
+ args_info->max_orig = NULL;
+ args_info->highlight_flag = 0;
+
+}
+
+static
+void init_args_info(struct gengetopt_args_info *args_info)
+{
+
+
+ args_info->help_help = gengetopt_args_info_help[0] ;
+ args_info->version_help = gengetopt_args_info_help[1] ;
+ args_info->xdisplay_help = gengetopt_args_info_help[3] ;
+ args_info->select_help = gengetopt_args_info_help[4] ;
+ args_info->x_help = gengetopt_args_info_help[5] ;
+ args_info->y_help = gengetopt_args_info_help[6] ;
+ args_info->w_help = gengetopt_args_info_help[7] ;
+ args_info->h_help = gengetopt_args_info_help[8] ;
+ args_info->geometry_help = gengetopt_args_info_help[9] ;
+ args_info->delay_help = gengetopt_args_info_help[10] ;
+ args_info->windowid_help = gengetopt_args_info_help[11] ;
+ args_info->localize_help = gengetopt_args_info_help[12] ;
+ args_info->hidecursor_help = gengetopt_args_info_help[13] ;
+ args_info->mask_help = gengetopt_args_info_help[14] ;
+ args_info->nokeyboard_help = gengetopt_args_info_help[16] ;
+ args_info->bordersize_help = gengetopt_args_info_help[17] ;
+ args_info->padding_help = gengetopt_args_info_help[18] ;
+ args_info->tolerance_help = gengetopt_args_info_help[19] ;
+ args_info->gracetime_help = gengetopt_args_info_help[20] ;
+ args_info->color_help = gengetopt_args_info_help[21] ;
+ args_info->nodecorations_help = gengetopt_args_info_help[22] ;
+ args_info->min_help = gengetopt_args_info_help[23] ;
+ args_info->max_help = gengetopt_args_info_help[24] ;
+ args_info->highlight_help = gengetopt_args_info_help[25] ;
+
+}
+
+void
+cmdline_parser_print_version (void)
+{
+ printf ("%s %s\n",
+ (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
+ CMDLINE_PARSER_VERSION);
+
+ if (strlen(gengetopt_args_info_versiontext) > 0)
+ printf("\n%s\n", gengetopt_args_info_versiontext);
+}
+
+static void print_help_common(void) {
+ cmdline_parser_print_version ();
+
+ if (strlen(gengetopt_args_info_purpose) > 0)
+ printf("\n%s\n", gengetopt_args_info_purpose);
+
+ if (strlen(gengetopt_args_info_usage) > 0)
+ printf("\n%s\n", gengetopt_args_info_usage);
+
+ printf("\n");
+
+ if (strlen(gengetopt_args_info_description) > 0)
+ printf("%s\n\n", gengetopt_args_info_description);
+}
+
+void
+cmdline_parser_print_help (void)
+{
+ int i = 0;
+ print_help_common();
+ while (gengetopt_args_info_help[i])
+ printf("%s\n", gengetopt_args_info_help[i++]);
+}
+
+void
+cmdline_parser_init (struct gengetopt_args_info *args_info)
+{
+ clear_given (args_info);
+ clear_args (args_info);
+ init_args_info (args_info);
+
+ args_info->inputs = 0;
+ args_info->inputs_num = 0;
+}
+
+void
+cmdline_parser_params_init(struct cmdline_parser_params *params)
+{
+ if (params)
+ {
+ params->override = 0;
+ params->initialize = 1;
+ params->check_required = 1;
+ params->check_ambiguity = 0;
+ params->print_errors = 1;
+ }
+}
+
+struct cmdline_parser_params *
+cmdline_parser_params_create(void)
+{
+ struct cmdline_parser_params *params =
+ (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
+ cmdline_parser_params_init(params);
+ return params;
+}
+
+static void
+free_string_field (char **s)
+{
+ if (*s)
+ {
+ free (*s);
+ *s = 0;
+ }
+}
+
+
+static void
+cmdline_parser_release (struct gengetopt_args_info *args_info)
+{
+ unsigned int i;
+ free_string_field (&(args_info->xdisplay_arg));
+ free_string_field (&(args_info->xdisplay_orig));
+ free_string_field (&(args_info->x_orig));
+ free_string_field (&(args_info->y_orig));
+ free_string_field (&(args_info->w_orig));
+ free_string_field (&(args_info->h_orig));
+ free_string_field (&(args_info->geometry_arg));
+ free_string_field (&(args_info->geometry_orig));
+ free_string_field (&(args_info->delay_arg));
+ free_string_field (&(args_info->delay_orig));
+ free_string_field (&(args_info->windowid_orig));
+ free_string_field (&(args_info->mask_arg));
+ free_string_field (&(args_info->mask_orig));
+ free_string_field (&(args_info->bordersize_orig));
+ free_string_field (&(args_info->padding_orig));
+ free_string_field (&(args_info->tolerance_orig));
+ free_string_field (&(args_info->gracetime_arg));
+ free_string_field (&(args_info->gracetime_orig));
+ free_string_field (&(args_info->color_arg));
+ free_string_field (&(args_info->color_orig));
+ free_string_field (&(args_info->min_orig));
+ free_string_field (&(args_info->max_orig));
+
+
+ for (i = 0; i < args_info->inputs_num; ++i)
+ free (args_info->inputs [i]);
+
+ if (args_info->inputs_num)
+ free (args_info->inputs);
+
+ clear_given (args_info);
+}
+
+/**
+ * @param val the value to check
+ * @param values the possible values
+ * @return the index of the matched value:
+ * -1 if no value matched,
+ * -2 if more than one value has matched
+ */
+static int
+check_possible_values(const char *val, const char *values[])
+{
+ int i, found, last;
+ size_t len;
+
+ if (!val) /* otherwise strlen() crashes below */
+ return -1; /* -1 means no argument for the option */
+
+ found = last = 0;
+
+ for (i = 0, len = strlen(val); values[i]; ++i)
+ {
+ if (strncmp(val, values[i], len) == 0)
+ {
+ ++found;
+ last = i;
+ if (strlen(values[i]) == len)
+ return i; /* exact macth no need to check more */
+ }
+ }
+
+ if (found == 1) /* one match: OK */
+ return last;
+
+ return (found ? -2 : -1); /* return many values or none matched */
+}
+
+
+static void
+write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
+{
+ int found = -1;
+ if (arg) {
+ if (values) {
+ found = check_possible_values(arg, values);
+ }
+ if (found >= 0)
+ fprintf(outfile, "%s=\"%s\" # %s\n", opt, arg, values[found]);
+ else
+ fprintf(outfile, "%s=\"%s\"\n", opt, arg);
+ } else {
+ fprintf(outfile, "%s\n", opt);
+ }
+}
+
+
+int
+cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
+{
+ int i = 0;
+
+ if (!outfile)
+ {
+ fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
+ return EXIT_FAILURE;
+ }
+
+ if (args_info->help_given)
+ write_into_file(outfile, "help", 0, 0 );
+ if (args_info->version_given)
+ write_into_file(outfile, "version", 0, 0 );
+ if (args_info->xdisplay_given)
+ write_into_file(outfile, "xdisplay", args_info->xdisplay_orig, 0);
+ if (args_info->select_given)
+ write_into_file(outfile, "select", 0, 0 );
+ if (args_info->x_given)
+ write_into_file(outfile, "x", args_info->x_orig, 0);
+ if (args_info->y_given)
+ write_into_file(outfile, "y", args_info->y_orig, 0);
+ if (args_info->w_given)
+ write_into_file(outfile, "w", args_info->w_orig, 0);
+ if (args_info->h_given)
+ write_into_file(outfile, "h", args_info->h_orig, 0);
+ if (args_info->geometry_given)
+ write_into_file(outfile, "geometry", args_info->geometry_orig, 0);
+ if (args_info->delay_given)
+ write_into_file(outfile, "delay", args_info->delay_orig, 0);
+ if (args_info->windowid_given)
+ write_into_file(outfile, "windowid", args_info->windowid_orig, 0);
+ if (args_info->localize_given)
+ write_into_file(outfile, "localize", 0, 0 );
+ if (args_info->hidecursor_given)
+ write_into_file(outfile, "hidecursor", 0, 0 );
+ if (args_info->mask_given)
+ write_into_file(outfile, "mask", args_info->mask_orig, cmdline_parser_mask_values);
+ if (args_info->nokeyboard_given)
+ write_into_file(outfile, "nokeyboard", 0, 0 );
+ if (args_info->bordersize_given)
+ write_into_file(outfile, "bordersize", args_info->bordersize_orig, 0);
+ if (args_info->padding_given)
+ write_into_file(outfile, "padding", args_info->padding_orig, 0);
+ if (args_info->tolerance_given)
+ write_into_file(outfile, "tolerance", args_info->tolerance_orig, 0);
+ if (args_info->gracetime_given)
+ write_into_file(outfile, "gracetime", args_info->gracetime_orig, 0);
+ if (args_info->color_given)
+ write_into_file(outfile, "color", args_info->color_orig, 0);
+ if (args_info->nodecorations_given)
+ write_into_file(outfile, "nodecorations", 0, 0 );
+ if (args_info->min_given)
+ write_into_file(outfile, "min", args_info->min_orig, 0);
+ if (args_info->max_given)
+ write_into_file(outfile, "max", args_info->max_orig, 0);
+ if (args_info->highlight_given)
+ write_into_file(outfile, "highlight", 0, 0 );
+
+
+ i = EXIT_SUCCESS;
+ return i;
+}
+
+int
+cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
+{
+ FILE *outfile;
+ int i = 0;
+
+ outfile = fopen(filename, "w");
+
+ if (!outfile)
+ {
+ fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
+ return EXIT_FAILURE;
+ }
+
+ i = cmdline_parser_dump(outfile, args_info);
+ fclose (outfile);
+
+ return i;
+}
+
+void
+cmdline_parser_free (struct gengetopt_args_info *args_info)
+{
+ cmdline_parser_release (args_info);
+}
+
+/** @brief replacement of strdup, which is not standard */
+char *
+gengetopt_strdup (const char *s)
+{
+ char *result = 0;
+ if (!s)
+ return result;
+
+ result = (char*)malloc(strlen(s) + 1);
+ if (result == (char*)0)
+ return (char*)0;
+ strcpy(result, s);
+ return result;
+}
+
+int
+cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
+{
+ return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
+}
+
+int
+cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
+ struct cmdline_parser_params *params)
+{
+ int result;
+ result = cmdline_parser_internal (argc, argv, args_info, params, 0);
+
+ if (result == EXIT_FAILURE)
+ {
+ cmdline_parser_free (args_info);
+ exit (EXIT_FAILURE);
+ }
+
+ return result;
+}
+
+int
+cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
+{
+ int result;
+ struct cmdline_parser_params params;
+
+ params.override = override;
+ params.initialize = initialize;
+ params.check_required = check_required;
+ params.check_ambiguity = 0;
+ params.print_errors = 1;
+
+ result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
+
+ if (result == EXIT_FAILURE)
+ {
+ cmdline_parser_free (args_info);
+ exit (EXIT_FAILURE);
+ }
+
+ return result;
+}
+
+int
+cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
+{
+ FIX_UNUSED (args_info);
+ FIX_UNUSED (prog_name);
+ return EXIT_SUCCESS;
+}
+
+
+static char *package_name = 0;
+
+/**
+ * @brief updates an option
+ * @param field the generic pointer to the field to update
+ * @param orig_field the pointer to the orig field
+ * @param field_given the pointer to the number of occurrence of this option
+ * @param prev_given the pointer to the number of occurrence already seen
+ * @param value the argument for this option (if null no arg was specified)
+ * @param possible_values the possible values for this option (if specified)
+ * @param default_value the default value (in case the option only accepts fixed values)
+ * @param arg_type the type of this option
+ * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
+ * @param override @see cmdline_parser_params.override
+ * @param no_free whether to free a possible previous value
+ * @param multiple_option whether this is a multiple option
+ * @param long_opt the corresponding long option
+ * @param short_opt the corresponding short option (or '-' if none)
+ * @param additional_error possible further error specification
+ */
+static
+int update_arg(void *field, char **orig_field,
+ unsigned int *field_given, unsigned int *prev_given,
+ char *value, const char *possible_values[],
+ const char *default_value,
+ cmdline_parser_arg_type arg_type,
+ int check_ambiguity, int override,
+ int no_free, int multiple_option,
+ const char *long_opt, char short_opt,
+ const char *additional_error)
+{
+ char *stop_char = 0;
+ const char *val = value;
+ int found;
+ char **string_field;
+ FIX_UNUSED (field);
+
+ stop_char = 0;
+ found = 0;
+
+ if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
+ {
+ if (short_opt != '-')
+ fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
+ package_name, long_opt, short_opt,
+ (additional_error ? additional_error : ""));
+ else
+ fprintf (stderr, "%s: `--%s' option given more than once%s\n",
+ package_name, long_opt,
+ (additional_error ? additional_error : ""));
+ return 1; /* failure */
+ }
+
+ if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0)
+ {
+ if (short_opt != '-')
+ fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n",
+ package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt, short_opt,
+ (additional_error ? additional_error : ""));
+ else
+ fprintf (stderr, "%s: %s argument, \"%s\", for option `--%s'%s\n",
+ package_name, (found == -2) ? "ambiguous" : "invalid", value, long_opt,
+ (additional_error ? additional_error : ""));
+ return 1; /* failure */
+ }
+
+ if (field_given && *field_given && ! override)
+ return 0;
+ if (prev_given)
+ (*prev_given)++;
+ if (field_given)
+ (*field_given)++;
+ if (possible_values)
+ val = possible_values[found];
+
+ switch(arg_type) {
+ case ARG_FLAG:
+ *((int *)field) = !*((int *)field);
+ break;
+ case ARG_INT:
+ if (val) *((int *)field) = strtol (val, &stop_char, 0);
+ break;
+ case ARG_STRING:
+ if (val) {
+ string_field = (char **)field;
+ if (!no_free && *string_field)
+ free (*string_field); /* free previous string */
+ *string_field = gengetopt_strdup (val);
+ }
+ break;
+ default:
+ break;
+ };
+
+ /* check numeric conversion */
+ switch(arg_type) {
+ case ARG_INT:
+ if (val && !(stop_char && *stop_char == '\0')) {
+ fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
+ return 1; /* failure */
+ }
+ break;
+ default:
+ ;
+ };
+
+ /* store the original value */
+ switch(arg_type) {
+ case ARG_NO:
+ case ARG_FLAG:
+ break;
+ default:
+ if (value && orig_field) {
+ if (no_free) {
+ *orig_field = value;
+ } else {
+ if (*orig_field)
+ free (*orig_field); /* free previous string */
+ *orig_field = gengetopt_strdup (value);
+ }
+ }
+ };
+
+ return 0; /* OK */
+}
+
+
+int
+cmdline_parser_internal (
+ int argc, char **argv, struct gengetopt_args_info *args_info,
+ struct cmdline_parser_params *params, const char *additional_error)
+{
+ int c; /* Character of the parsed option. */
+
+ int error_occurred = 0;
+ struct gengetopt_args_info local_args_info;
+
+ int override;
+ int initialize;
+ int check_required;
+ int check_ambiguity;
+
+ package_name = argv[0];
+
+ override = params->override;
+ initialize = params->initialize;
+ check_required = params->check_required;
+ check_ambiguity = params->check_ambiguity;
+
+ if (initialize)
+ cmdline_parser_init (args_info);
+
+ cmdline_parser_init (&local_args_info);
+
+ optarg = 0;
+ optind = 0;
+ opterr = params->print_errors;
+ optopt = '?';
+
+ while (1)
+ {
+ int option_index = 0;
+
+ static struct option long_options[] = {
+ { "help", 0, NULL, 0 },
+ { "version", 0, NULL, 'V' },
+ { "xdisplay", 1, NULL, 0 },
+ { "select", 0, NULL, 's' },
+ { "x", 1, NULL, 'x' },
+ { "y", 1, NULL, 'y' },
+ { "w", 1, NULL, 'w' },
+ { "h", 1, NULL, 'h' },
+ { "geometry", 1, NULL, 'g' },
+ { "delay", 1, NULL, 'd' },
+ { "windowid", 1, NULL, 'i' },
+ { "localize", 0, NULL, 0 },
+ { "hidecursor", 0, NULL, 0 },
+ { "mask", 1, NULL, 'm' },
+ { "nokeyboard", 0, NULL, 0 },
+ { "bordersize", 1, NULL, 'b' },
+ { "padding", 1, NULL, 'p' },
+ { "tolerance", 1, NULL, 't' },
+ { "gracetime", 1, NULL, 0 },
+ { "color", 1, NULL, 'c' },
+ { "nodecorations", 0, NULL, 'n' },
+ { "min", 1, NULL, 0 },
+ { "max", 1, NULL, 0 },
+ { "highlight", 0, NULL, 'l' },
+ { 0, 0, 0, 0 }
+ };
+
+ c = getopt_long (argc, argv, "Vsx:y:w:h:g:d:i:m:b:p:t:c:nl", long_options, &option_index);
+
+ if (c == -1) break; /* Exit from `while (1)' loop. */
+
+ switch (c)
+ {
+ case 'V': /* Print version and exit. */
+ cmdline_parser_print_version ();
+ cmdline_parser_free (&local_args_info);
+ exit (EXIT_SUCCESS);
+
+ case 's': /* Enables user region selection. Requires slop to be installed.. */
+
+
+ if (update_arg((void *)&(args_info->select_flag), 0, &(args_info->select_given),
+ &(local_args_info.select_given), optarg, 0, 0, ARG_FLAG,
+ check_ambiguity, override, 1, 0, "select", 's',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'x': /* Sets the x coordinate for taking an image. */
+
+
+ if (update_arg( (void *)&(args_info->x_arg),
+ &(args_info->x_orig), &(args_info->x_given),
+ &(local_args_info.x_given), optarg, 0, 0, ARG_INT,
+ check_ambiguity, override, 0, 0,
+ "x", 'x',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'y': /* Sets the y coordinate for taking an image. */
+
+
+ if (update_arg( (void *)&(args_info->y_arg),
+ &(args_info->y_orig), &(args_info->y_given),
+ &(local_args_info.y_given), optarg, 0, 0, ARG_INT,
+ check_ambiguity, override, 0, 0,
+ "y", 'y',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'w': /* Sets the width for taking an image. */
+
+
+ if (update_arg( (void *)&(args_info->w_arg),
+ &(args_info->w_orig), &(args_info->w_given),
+ &(local_args_info.w_given), optarg, 0, 0, ARG_INT,
+ check_ambiguity, override, 0, 0,
+ "w", 'w',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'h': /* Sets the height for taking an image. */
+
+
+ if (update_arg( (void *)&(args_info->h_arg),
+ &(args_info->h_orig), &(args_info->h_given),
+ &(local_args_info.h_given), optarg, 0, 0, ARG_INT,
+ check_ambiguity, override, 0, 0,
+ "h", 'h',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'g': /* Set the region to capture. */
+
+
+ if (update_arg( (void *)&(args_info->geometry_arg),
+ &(args_info->geometry_orig), &(args_info->geometry_given),
+ &(local_args_info.geometry_given), optarg, 0, 0, ARG_STRING,
+ check_ambiguity, override, 0, 0,
+ "geometry", 'g',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'd': /* Set the amount of time to wait before taking an image.. */
+
+
+ if (update_arg( (void *)&(args_info->delay_arg),
+ &(args_info->delay_orig), &(args_info->delay_given),
+ &(local_args_info.delay_given), optarg, 0, "0.0", ARG_STRING,
+ check_ambiguity, override, 0, 0,
+ "delay", 'd',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'i': /* Set the window to capture. Defaults to the root window id.. */
+
+
+ if (update_arg( (void *)&(args_info->windowid_arg),
+ &(args_info->windowid_orig), &(args_info->windowid_given),
+ &(local_args_info.windowid_given), optarg, 0, 0, ARG_INT,
+ check_ambiguity, override, 0, 0,
+ "windowid", 'i',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'm': /* Masks off-screen pixels so they don't show up in screenshots.. */
+
+
+ if (update_arg( (void *)&(args_info->mask_arg),
+ &(args_info->mask_orig), &(args_info->mask_given),
+ &(local_args_info.mask_given), optarg, cmdline_parser_mask_values, "auto", ARG_STRING,
+ check_ambiguity, override, 0, 0,
+ "mask", 'm',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'b': /* Set the selection rectangle's thickness. Does nothing when --highlight is enabled.. */
+
+
+ if (update_arg( (void *)&(args_info->bordersize_arg),
+ &(args_info->bordersize_orig), &(args_info->bordersize_given),
+ &(local_args_info.bordersize_given), optarg, 0, "5", ARG_INT,
+ check_ambiguity, override, 0, 0,
+ "bordersize", 'b',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'p': /* Set the padding size of the selection. Can be negative.. */
+
+
+ if (update_arg( (void *)&(args_info->padding_arg),
+ &(args_info->padding_orig), &(args_info->padding_given),
+ &(local_args_info.padding_given), optarg, 0, "0", ARG_INT,
+ check_ambiguity, override, 0, 0,
+ "padding", 'p',
+ additional_error))
+ goto failure;
+
+ break;
+ case 't': /* How far in pixels the mouse can move after clicking and still be detected as a normal click instead of a click and drag. Setting this to 0 will disable window selections.. */
+
+
+ if (update_arg( (void *)&(args_info->tolerance_arg),
+ &(args_info->tolerance_orig), &(args_info->tolerance_given),
+ &(local_args_info.tolerance_given), optarg, 0, "2", ARG_INT,
+ check_ambiguity, override, 0, 0,
+ "tolerance", 't',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'c': /* Set the selection rectangle's color. Supports RGB or RGBA values.. */
+
+
+ if (update_arg( (void *)&(args_info->color_arg),
+ &(args_info->color_orig), &(args_info->color_given),
+ &(local_args_info.color_given), optarg, 0, "0.5,0.5,0.5,1", ARG_STRING,
+ check_ambiguity, override, 0, 0,
+ "color", 'c',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'n': /* Attempt to select child windows in order to avoid window decorations.. */
+
+
+ if (update_arg((void *)&(args_info->nodecorations_flag), 0, &(args_info->nodecorations_given),
+ &(local_args_info.nodecorations_given), optarg, 0, 0, ARG_FLAG,
+ check_ambiguity, override, 1, 0, "nodecorations", 'n',
+ additional_error))
+ goto failure;
+
+ break;
+ case 'l': /* Instead of outlining selections, slop highlights it. This is only useful when --color is set to a transparent color.. */
+
+
+ if (update_arg((void *)&(args_info->highlight_flag), 0, &(args_info->highlight_given),
+ &(local_args_info.highlight_given), optarg, 0, 0, ARG_FLAG,
+ check_ambiguity, override, 1, 0, "highlight", 'l',
+ additional_error))
+ goto failure;
+
+ break;
+
+ case 0: /* Long option with no short option */
+ if (strcmp (long_options[option_index].name, "help") == 0) {
+ cmdline_parser_print_help ();
+ cmdline_parser_free (&local_args_info);
+ exit (EXIT_SUCCESS);
+ }
+
+ /* Sets the x display.. */
+ if (strcmp (long_options[option_index].name, "xdisplay") == 0)
+ {
+
+
+ if (update_arg( (void *)&(args_info->xdisplay_arg),
+ &(args_info->xdisplay_orig), &(args_info->xdisplay_given),
+ &(local_args_info.xdisplay_given), optarg, 0, 0, ARG_STRING,
+ check_ambiguity, override, 0, 0,
+ "xdisplay", '-',
+ additional_error))
+ goto failure;
+
+ }
+ /* Localizes given geometry to the given window. So \"maim -i $ID -g 100x100+0+0 --localize\" would screenshot the top-left 100x100 pixels of the given window, rather than the top-left 100x100 pixels of the root window.. */
+ else if (strcmp (long_options[option_index].name, "localize") == 0)
+ {
+
+
+ if (update_arg((void *)&(args_info->localize_flag), 0, &(args_info->localize_given),
+ &(local_args_info.localize_given), optarg, 0, 0, ARG_FLAG,
+ check_ambiguity, override, 1, 0, "localize", '-',
+ additional_error))
+ goto failure;
+
+ }
+ /* Prevents the system cursor from showing up in screenshots.. */
+ else if (strcmp (long_options[option_index].name, "hidecursor") == 0)
+ {
+
+
+ if (update_arg((void *)&(args_info->hidecursor_flag), 0, &(args_info->hidecursor_given),
+ &(local_args_info.hidecursor_given), optarg, 0, 0, ARG_FLAG,
+ check_ambiguity, override, 1, 0, "hidecursor", '-',
+ additional_error))
+ goto failure;
+
+ }
+ /* Disables the ability to cancel selections with the keyboard.. */
+ else if (strcmp (long_options[option_index].name, "nokeyboard") == 0)
+ {
+
+
+ if (update_arg((void *)&(args_info->nokeyboard_flag), 0, &(args_info->nokeyboard_given),
+ &(local_args_info.nokeyboard_given), optarg, 0, 0, ARG_FLAG,
+ check_ambiguity, override, 1, 0, "nokeyboard", '-',
+ additional_error))
+ goto failure;
+
+ }
+ /* Set the amount of time before slop will check for keyboard cancellations in seconds.. */
+ else if (strcmp (long_options[option_index].name, "gracetime") == 0)
+ {
+
+
+ if (update_arg( (void *)&(args_info->gracetime_arg),
+ &(args_info->gracetime_orig), &(args_info->gracetime_given),
+ &(local_args_info.gracetime_given), optarg, 0, "0.4", ARG_STRING,
+ check_ambiguity, override, 0, 0,
+ "gracetime", '-',
+ additional_error))
+ goto failure;
+
+ }
+ /* Set the minimum output of width or height values. This is useful to avoid outputting 0. Setting min and max to the same value disables drag selections.. */
+ else if (strcmp (long_options[option_index].name, "min") == 0)
+ {
+
+
+ if (update_arg( (void *)&(args_info->min_arg),
+ &(args_info->min_orig), &(args_info->min_given),
+ &(local_args_info.min_given), optarg, 0, "0", ARG_INT,
+ check_ambiguity, override, 0, 0,
+ "min", '-',
+ additional_error))
+ goto failure;
+
+ }
+ /* Set the maximum output of width or height values. Setting min and max to the same value disables drag selections.. */
+ else if (strcmp (long_options[option_index].name, "max") == 0)
+ {
+
+
+ if (update_arg( (void *)&(args_info->max_arg),
+ &(args_info->max_orig), &(args_info->max_given),
+ &(local_args_info.max_given), optarg, 0, "0", ARG_INT,
+ check_ambiguity, override, 0, 0,
+ "max", '-',
+ additional_error))
+ goto failure;
+
+ }
+
+ break;
+ case '?': /* Invalid option. */
+ /* `getopt_long' already printed an error message. */
+ goto failure;
+
+ default: /* bug: option not considered. */
+ fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
+ abort ();
+ } /* switch */
+ } /* while */
+
+
+
+
+ cmdline_parser_release (&local_args_info);
+
+ if ( error_occurred )
+ return (EXIT_FAILURE);
+
+ if (optind < argc)
+ {
+ int i = 0 ;
+ int found_prog_name = 0;
+ /* whether program name, i.e., argv[0], is in the remaining args
+ (this may happen with some implementations of getopt,
+ but surely not with the one included by gengetopt) */
+
+ i = optind;
+ while (i < argc)
+ if (argv[i++] == argv[0]) {
+ found_prog_name = 1;
+ break;
+ }
+ i = 0;
+
+ args_info->inputs_num = argc - optind - found_prog_name;
+ args_info->inputs =
+ (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
+ while (optind < argc)
+ if (argv[optind++] != argv[0])
+ args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
+ }
+
+ return 0;
+
+failure:
+
+ cmdline_parser_release (&local_args_info);
+ return (EXIT_FAILURE);
+}
diff --git a/src/cmdline.in b/src/cmdline.in
new file mode 100644
index 0000000..54c9f19
--- /dev/null
+++ b/src/cmdline.in
@@ -0,0 +1,259 @@
+/** @file cmdline.h
+ * @brief The header file for the command line option parser
+ * generated by GNU Gengetopt version 2.22.6
+ * http://www.gnu.org/software/gengetopt.
+ * DO NOT modify this file, since it can be overwritten
+ * @author GNU Gengetopt by Lorenzo Bettini */
+
+#ifndef CMDLINE_H
+#define CMDLINE_H
+
+/* If we use autoconf. */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h> /* for FILE */
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#ifndef CMDLINE_PARSER_PACKAGE
+/** @brief the program name (used for printing errors) */
+#define CMDLINE_PARSER_PACKAGE "maim"
+#endif
+
+#ifndef CMDLINE_PARSER_PACKAGE_NAME
+/** @brief the complete program name (used for help and version) */
+#define CMDLINE_PARSER_PACKAGE_NAME "maim"
+#endif
+
+#ifndef CMDLINE_PARSER_VERSION
+/** @brief the program version */
+#define CMDLINE_PARSER_VERSION "v@maim_VERSION_MAJOR@.@maim_VERSION_MINOR@.@maim_VERSION_PATCH@"
+#endif
+
+/** @brief Where the command line options are stored */
+struct gengetopt_args_info
+{
+ const char *help_help; /**< @brief Print help and exit help description. */
+ const char *version_help; /**< @brief Print version and exit help description. */
+ char * xdisplay_arg; /**< @brief Sets the x display.. */
+ char * xdisplay_orig; /**< @brief Sets the x display. original value given at command line. */
+ const char *xdisplay_help; /**< @brief Sets the x display. help description. */
+ int select_flag; /**< @brief Enables user region selection. Requires slop to be installed. (default=off). */
+ const char *select_help; /**< @brief Enables user region selection. Requires slop to be installed. help description. */
+ int x_arg; /**< @brief Sets the x coordinate for taking an image. */
+ char * x_orig; /**< @brief Sets the x coordinate for taking an image original value given at command line. */
+ const char *x_help; /**< @brief Sets the x coordinate for taking an image help description. */
+ int y_arg; /**< @brief Sets the y coordinate for taking an image. */
+ char * y_orig; /**< @brief Sets the y coordinate for taking an image original value given at command line. */
+ const char *y_help; /**< @brief Sets the y coordinate for taking an image help description. */
+ int w_arg; /**< @brief Sets the width for taking an image. */
+ char * w_orig; /**< @brief Sets the width for taking an image original value given at command line. */
+ const char *w_help; /**< @brief Sets the width for taking an image help description. */
+ int h_arg; /**< @brief Sets the height for taking an image. */
+ char * h_orig; /**< @brief Sets the height for taking an image original value given at command line. */
+ const char *h_help; /**< @brief Sets the height for taking an image help description. */
+ char * geometry_arg; /**< @brief Set the region to capture. */
+ char * geometry_orig; /**< @brief Set the region to capture original value given at command line. */
+ const char *geometry_help; /**< @brief Set the region to capture help description. */
+ char * delay_arg; /**< @brief Set the amount of time to wait before taking an image. (default='0.0'). */
+ char * delay_orig; /**< @brief Set the amount of time to wait before taking an image. original value given at command line. */
+ const char *delay_help; /**< @brief Set the amount of time to wait before taking an image. help description. */
+ int windowid_arg; /**< @brief Set the window to capture. Defaults to the root window id.. */
+ char * windowid_orig; /**< @brief Set the window to capture. Defaults to the root window id. original value given at command line. */
+ const char *windowid_help; /**< @brief Set the window to capture. Defaults to the root window id. help description. */
+ int localize_flag; /**< @brief Localizes given geometry to the given window. So \"maim -i $ID -g 100x100+0+0 --localize\" would screenshot the top-left 100x100 pixels of the given window, rather than the top-left 100x100 pixels of the root window. (default=off). */
+ const char *localize_help; /**< @brief Localizes given geometry to the given window. So \"maim -i $ID -g 100x100+0+0 --localize\" would screenshot the top-left 100x100 pixels of the given window, rather than the top-left 100x100 pixels of the root window. help description. */
+ int hidecursor_flag; /**< @brief Prevents the system cursor from showing up in screenshots. (default=off). */
+ const char *hidecursor_help; /**< @brief Prevents the system cursor from showing up in screenshots. help description. */
+ char * mask_arg; /**< @brief Masks off-screen pixels so they don't show up in screenshots. (default='auto'). */
+ char * mask_orig; /**< @brief Masks off-screen pixels so they don't show up in screenshots. original value given at command line. */
+ const char *mask_help; /**< @brief Masks off-screen pixels so they don't show up in screenshots. help description. */
+ int nokeyboard_flag; /**< @brief Disables the ability to cancel selections with the keyboard. (default=off). */
+ const char *nokeyboard_help; /**< @brief Disables the ability to cancel selections with the keyboard. help description. */
+ int bordersize_arg; /**< @brief Set the selection rectangle's thickness. Does nothing when --highlight is enabled. (default='5'). */
+ char * bordersize_orig; /**< @brief Set the selection rectangle's thickness. Does nothing when --highlight is enabled. original value given at command line. */
+ const char *bordersize_help; /**< @brief Set the selection rectangle's thickness. Does nothing when --highlight is enabled. help description. */
+ int padding_arg; /**< @brief Set the padding size of the selection. Can be negative. (default='0'). */
+ char * padding_orig; /**< @brief Set the padding size of the selection. Can be negative. original value given at command line. */
+ const char *padding_help; /**< @brief Set the padding size of the selection. Can be negative. help description. */
+ int tolerance_arg; /**< @brief How far in pixels the mouse can move after clicking and still be detected as a normal click instead of a click and drag. Setting this to 0 will disable window selections. (default='2'). */
+ char * tolerance_orig; /**< @brief How far in pixels the mouse can move after clicking and still be detected as a normal click instead of a click and drag. Setting this to 0 will disable window selections. original value given at command line. */
+ const char *tolerance_help; /**< @brief How far in pixels the mouse can move after clicking and still be detected as a normal click instead of a click and drag. Setting this to 0 will disable window selections. help description. */
+ char * gracetime_arg; /**< @brief Set the amount of time before slop will check for keyboard cancellations in seconds. (default='0.4'). */
+ char * gracetime_orig; /**< @brief Set the amount of time before slop will check for keyboard cancellations in seconds. original value given at command line. */
+ const char *gracetime_help; /**< @brief Set the amount of time before slop will check for keyboard cancellations in seconds. help description. */
+ char * color_arg; /**< @brief Set the selection rectangle's color. Supports RGB or RGBA values. (default='0.5,0.5,0.5,1'). */
+ char * color_orig; /**< @brief Set the selection rectangle's color. Supports RGB or RGBA values. original value given at command line. */
+ const char *color_help; /**< @brief Set the selection rectangle's color. Supports RGB or RGBA values. help description. */
+ int nodecorations_flag; /**< @brief Attempt to select child windows in order to avoid window decorations. (default=off). */
+ const char *nodecorations_help; /**< @brief Attempt to select child windows in order to avoid window decorations. help description. */
+ int min_arg; /**< @brief Set the minimum output of width or height values. This is useful to avoid outputting 0. Setting min and max to the same value disables drag selections. (default='0'). */
+ char * min_orig; /**< @brief Set the minimum output of width or height values. This is useful to avoid outputting 0. Setting min and max to the same value disables drag selections. original value given at command line. */
+ const char *min_help; /**< @brief Set the minimum output of width or height values. This is useful to avoid outputting 0. Setting min and max to the same value disables drag selections. help description. */
+ int max_arg; /**< @brief Set the maximum output of width or height values. Setting min and max to the same value disables drag selections. (default='0'). */
+ char * max_orig; /**< @brief Set the maximum output of width or height values. Setting min and max to the same value disables drag selections. original value given at command line. */
+ const char *max_help; /**< @brief Set the maximum output of width or height values. Setting min and max to the same value disables drag selections. help description. */
+ int highlight_flag; /**< @brief Instead of outlining selections, slop highlights it. This is only useful when --color is set to a transparent color. (default=off). */
+ const char *highlight_help; /**< @brief Instead of outlining selections, slop highlights it. This is only useful when --color is set to a transparent color. help description. */
+
+ unsigned int help_given ; /**< @brief Whether help was given. */
+ unsigned int version_given ; /**< @brief Whether version was given. */
+ unsigned int xdisplay_given ; /**< @brief Whether xdisplay was given. */
+ unsigned int select_given ; /**< @brief Whether select was given. */
+ unsigned int x_given ; /**< @brief Whether x was given. */
+ unsigned int y_given ; /**< @brief Whether y was given. */
+ unsigned int w_given ; /**< @brief Whether w was given. */
+ unsigned int h_given ; /**< @brief Whether h was given. */
+ unsigned int geometry_given ; /**< @brief Whether geometry was given. */
+ unsigned int delay_given ; /**< @brief Whether delay was given. */
+ unsigned int windowid_given ; /**< @brief Whether windowid was given. */
+ unsigned int localize_given ; /**< @brief Whether localize was given. */
+ unsigned int hidecursor_given ; /**< @brief Whether hidecursor was given. */
+ unsigned int mask_given ; /**< @brief Whether mask was given. */
+ unsigned int nokeyboard_given ; /**< @brief Whether nokeyboard was given. */
+ unsigned int bordersize_given ; /**< @brief Whether bordersize was given. */
+ unsigned int padding_given ; /**< @brief Whether padding was given. */
+ unsigned int tolerance_given ; /**< @brief Whether tolerance was given. */
+ unsigned int gracetime_given ; /**< @brief Whether gracetime was given. */
+ unsigned int color_given ; /**< @brief Whether color was given. */
+ unsigned int nodecorations_given ; /**< @brief Whether nodecorations was given. */
+ unsigned int min_given ; /**< @brief Whether min was given. */
+ unsigned int max_given ; /**< @brief Whether max was given. */
+ unsigned int highlight_given ; /**< @brief Whether highlight was given. */
+
+ char **inputs ; /**< @brief unamed options (options without names) */
+ unsigned inputs_num ; /**< @brief unamed options number */
+} ;
+
+/** @brief The additional parameters to pass to parser functions */
+struct cmdline_parser_params
+{
+ int override; /**< @brief whether to override possibly already present options (default 0) */
+ int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */
+ int check_required; /**< @brief whether to check that all required options were provided (default 1) */
+ int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */
+ int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */
+} ;
+
+/** @brief the purpose string of the program */
+extern const char *gengetopt_args_info_purpose;
+/** @brief the usage string of the program */
+extern const char *gengetopt_args_info_usage;
+/** @brief the description string of the program */
+extern const char *gengetopt_args_info_description;
+/** @brief all the lines making the help output */
+extern const char *gengetopt_args_info_help[];
+
+/**
+ * The command line parser
+ * @param argc the number of command line options
+ * @param argv the command line options
+ * @param args_info the structure where option information will be stored
+ * @return 0 if everything went fine, NON 0 if an error took place
+ */
+int cmdline_parser (int argc, char **argv,
+ struct gengetopt_args_info *args_info);
+
+/**
+ * The command line parser (version with additional parameters - deprecated)
+ * @param argc the number of command line options
+ * @param argv the command line options
+ * @param args_info the structure where option information will be stored
+ * @param override whether to override possibly already present options
+ * @param initialize whether to initialize the option structure my_args_info
+ * @param check_required whether to check that all required options were provided
+ * @return 0 if everything went fine, NON 0 if an error took place
+ * @deprecated use cmdline_parser_ext() instead
+ */
+int cmdline_parser2 (int argc, char **argv,
+ struct gengetopt_args_info *args_info,
+ int override, int initialize, int check_required);
+
+/**
+ * The command line parser (version with additional parameters)
+ * @param argc the number of command line options
+ * @param argv the command line options
+ * @param args_info the structure where option information will be stored
+ * @param params additional parameters for the parser
+ * @return 0 if everything went fine, NON 0 if an error took place
+ */
+int cmdline_parser_ext (int argc, char **argv,
+ struct gengetopt_args_info *args_info,
+ struct cmdline_parser_params *params);
+
+/**
+ * Save the contents of the option struct into an already open FILE stream.
+ * @param outfile the stream where to dump options
+ * @param args_info the option struct to dump
+ * @return 0 if everything went fine, NON 0 if an error took place
+ */
+int cmdline_parser_dump(FILE *outfile,
+ struct gengetopt_args_info *args_info);
+
+/**
+ * Save the contents of the option struct into a (text) file.
+ * This file can be read by the config file parser (if generated by gengetopt)
+ * @param filename the file where to save
+ * @param args_info the option struct to save
+ * @return 0 if everything went fine, NON 0 if an error took place
+ */
+int cmdline_parser_file_save(const char *filename,
+ struct gengetopt_args_info *args_info);
+
+/**
+ * Print the help
+ */
+void cmdline_parser_print_help(void);
+/**
+ * Print the version
+ */
+void cmdline_parser_print_version(void);
+
+/**
+ * Initializes all the fields a cmdline_parser_params structure
+ * to their default values
+ * @param params the structure to initialize
+ */
+void cmdline_parser_params_init(struct cmdline_parser_params *params);
+
+/**
+ * Allocates dynamically a cmdline_parser_params structure and initializes
+ * all its fields to their default values
+ * @return the created and initialized cmdline_parser_params structure
+ */
+struct cmdline_parser_params *cmdline_parser_params_create(void);
+
+/**
+ * Initializes the passed gengetopt_args_info structure's fields
+ * (also set default values for options that have a default)
+ * @param args_info the structure to initialize
+ */
+void cmdline_parser_init (struct gengetopt_args_info *args_info);
+/**
+ * Deallocates the string fields of the gengetopt_args_info structure
+ * (but does not deallocate the structure itself)
+ * @param args_info the structure to deallocate
+ */
+void cmdline_parser_free (struct gengetopt_args_info *args_info);
+
+/**
+ * Checks that all the required options were specified
+ * @param args_info the structure to check
+ * @param prog_name the name of the program that will be used to print
+ * possible errors
+ * @return
+ */
+int cmdline_parser_required (struct gengetopt_args_info *args_info,
+ const char *prog_name);
+
+extern const char *cmdline_parser_mask_values[]; /**< @brief Possible values for mask. */
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* CMDLINE_H */
diff --git a/src/im.cpp b/src/im.cpp
new file mode 100644
index 0000000..ab86bca
--- /dev/null
+++ b/src/im.cpp
@@ -0,0 +1,315 @@
+/* im.cpp: Handles starting and managing imlib2.
+ *
+ * Copyright (C) 2014: Dalton Nell, Maim Contributors (https://github.com/naelstrof/maim/graphs/contributors).
+ *
+ * This file is part of Maim.
+ *
+ * Maim is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Maim is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Maim. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "im.hpp"
+
+maim::IMEngine* imengine = new maim::IMEngine();
+
+maim::IMEngine::IMEngine() {
+}
+
+maim::IMEngine::~IMEngine() {
+}
+
+/**
+* @brief Initializes our imlib context
+*
+* @return 0 on success, 1 on failure.
+*/
+int maim::IMEngine::init() {
+ if ( !xengine->m_good ) {
+ return EXIT_FAILURE;
+ }
+ imlib_set_cache_size( 2048 * 1024 );
+ imlib_context_set_display( xengine->m_display );
+ imlib_context_set_visual( xengine->m_visual );
+ imlib_context_set_colormap( xengine->m_colormap );
+ imlib_context_set_blend( 1 );
+ return EXIT_SUCCESS;
+}
+
+/**
+* @brief Takes a screenshot of the given window, and leaves the allocated image in the imlib context.
+*
+* @param id A window ID, for example the root id would take a full screenshot.
+*
+* @return 0 on success, 1 on failure.
+*/
+int maim::IMEngine::screenshot( Window id ) {
+ if ( id == None ) {
+ fprintf( stderr, "Error: Can't screenshot a window with id None!\n" );
+ return EXIT_FAILURE;
+ }
+ // Get the window's dimensions
+ Window root;
+ int x, y;
+ unsigned int w, h, b, d;
+ int status = XGetGeometry( xengine->m_display, id, &root, &x, &y, &w, &h, &b, &d );
+ if ( status == 0 ) {
+ fprintf( stderr, "Error: Failed to grab window geometry of window id: %lu\n", id );
+ return EXIT_FAILURE;
+ }
+ // Create an uninitialized image buffer of the same width and height as the window
+ Imlib_Image buffer = imlib_create_image( w, h );
+ imlib_context_set_image( buffer );
+ // Make sure that imlib knows that it's possible for the image to have alpha
+ // prevents blending issues in the future.
+ imlib_image_set_has_alpha( 1 );
+ imlib_context_set_drawable( id );
+ int destinationx = x < 0 ? -x : 0;
+ int destinationy = y < 0 ? -y : 0;
+ imlib_copy_drawable_to_image( 0, destinationx, destinationy, w, h, 0, 0, 0 );
+ // Screenshot image is now in the imlib context!
+ return EXIT_SUCCESS;
+}
+
+/**
+* @brief Similar to maim::IMEngine::screenshot( Window id ), but also crops the image.
+*
+* @param id The window to take a screenshot of.
+* @param x Starting X position of the crop.
+* @param y Starting Y position of the crop.
+* @param w Width of the final cropped image.
+* @param h Height of the final cropped image.
+*
+* @return 0 on success, 1 on failure.
+*/
+int maim::IMEngine::screenshot( Window id, int x, int y, unsigned int w, unsigned int h ) {
+ if ( id == None ) {
+ fprintf( stderr, "Error: Can't screenshot a window with id None!\n" );
+ return EXIT_FAILURE;
+ }
+ // Create an uninitialized image buffer of the same width and height as our selection.
+ Imlib_Image buffer = imlib_create_image( w, h );
+ imlib_context_set_image( buffer );
+ // Make sure that imlib knows that it's possible for the image to have alpha
+ // prevents blending issues in the future.
+ imlib_image_set_has_alpha( 1 );
+ imlib_context_set_drawable( id );
+ // This make sure negative x or y values actually affect the location
+ // of the drawable. Since asking for it to copy from a negative
+ // x or y position doesn't seem to do anything.
+ // Might be a bug, but if it's fixed it'll break my program as it is now. :v
+ int destinationx = x < 0 ? -x : 0;
+ int destinationy = y < 0 ? -y : 0;
+ imlib_copy_drawable_to_image( 0, x, y, w, h, destinationx, destinationy, 0 );
+ // Screenshot image is now in the imlib context!
+ return EXIT_SUCCESS;
+}
+
+/**
+* @brief Blends the system cursor onto the current image in the imlib context.
+*
+* @param id The window used to take the screenshot, this is used to grab the relative cursor position.
+* @param x X offset of the window to the image
+* @param y Y offset of the window to the image
+*
+* @return 0 on success, 1 on failure.
+*/
+int maim::IMEngine::blendCursor( Window id, int x, int y ) {
+ if ( id == None ) {
+ fprintf( stderr, "Error: Can't blend the cursor without a valid window (None given)!\n" );
+ return EXIT_FAILURE;
+ }
+ if ( imlib_context_get_image() == NULL ) {
+ fprintf( stderr, "Error: Can't blend the cursor to NULL image!\n" );
+ return EXIT_FAILURE;
+ }
+ // Grab the cursor image with XFixes
+ XFixesCursorImage* xcursor = XFixesGetCursorImage( xengine->m_display );
+ // If we failed don't do anything.
+ if ( !xcursor ) {
+ fprintf( stderr, "Warning: Failed to grab cursor image, it won't appear in screenshots!\n" );
+ return EXIT_FAILURE;
+ }
+ // For whatever reason, XFixes returns 32 bit ARGB colors with 64 bit longs?
+ // I'm guessing this is because some old AMD cpu's longs are actually 32 bits.
+ // Regardless this is how I convert it to the correct bit length.
+ uint32_t* pixels = new uint32_t[ xcursor->width * xcursor->height ];
+ for ( int i=0;i<xcursor->width*xcursor->height;i++ ) {
+ pixels[ i ] = (uint32_t)xcursor->pixels[ i ];
+ }
+ Imlib_Image cursor = imlib_create_image_using_data( xcursor->width, xcursor->height, pixels );
+ // First save the image that we'll be applying the cursor to.
+ Imlib_Image buffer = imlib_context_get_image();
+ // Make sure imlib knows that it has alpha
+ imlib_context_set_image( cursor );
+ imlib_image_set_has_alpha( 1 );
+ // Then we quickly set the old image back.
+ imlib_context_set_image( buffer );
+ // We grab the window's position with this, so we can find where the cursor would be located on our image.
+ Window root, junk;
+ int tx, ty;
+ unsigned int tw, th, tb, td;
+ int status = XGetGeometry( xengine->m_display, id, &root, &tx, &ty, &tw, &th, &tb, &td );
+ if ( status == 0 ) {
+ fprintf( stderr, "Error: Failed to grab window geometry of window id: %lu\n", id );
+ return EXIT_FAILURE;
+ }
+ // Make sure the window's position is in root coordinates
+ XTranslateCoordinates( xengine->m_display, id, root, -tb, -tb, &tx, &ty, &junk );
+ // Finally blend the cursor to the screenshot, we don't have to worry about the cursor not being visible as it would be a non-existant image if it was.
+ imlib_blend_image_onto_image( cursor, 0, 0, 0, xcursor->width, xcursor->height, xcursor->x-tx-xcursor->xhot-x, xcursor->y-ty-xcursor->yhot-y, xcursor->width, xcursor->height );
+ // Free the cursor image and delete its data.
+ imlib_context_set_image( cursor );
+ imlib_free_image();
+ imlib_context_set_image( buffer );
+ free( xcursor );
+ delete[] pixels;
+ return EXIT_SUCCESS;
+}
+
+/**
+* @brief This one is a doozy, it tries to mask off-screen pixels so they don't show up as garbage in screenshots.
+* It's highly situational in it's usage, and often yields zero noticable results as most people not only
+* don't have a multi-monitor setup, but the few people that do don't have them unevenly set up.
+*
+* @param x X offset of the image in buffer in relation to the physical monitors.
+* @param y Y offset of the image in buffer in relation to the physical monitors.
+* @param w Width of the image in buffer.
+* @param h Height of the image in buffer.
+*
+* @return 0 on success, 1 on failure.
+*/
+int maim::IMEngine::mask( int x, int y, unsigned int w, unsigned int h ) {
+ // If xengine couldn't find any physical screens. We don't do anything.
+ if ( !xengine->m_res ) {
+ return EXIT_FAILURE;
+ }
+ if ( imlib_context_get_image() == NULL ) {
+ fprintf( stderr, "Error: Can't mask a NULL image!\n" );
+ return EXIT_FAILURE;
+ }
+ // If no width or height arguments were given, we grab them ourselves.
+ if ( w == 0 && h == 0 && x == 0 && y == 0 ) {
+ w = imlib_image_get_width();
+ h = imlib_image_get_height();
+ } else if ( w == 0 || h == 0 ) {
+ fprintf( stderr, "Error: Tried to mask an image with 0 width or height!\n" );
+ return EXIT_FAILURE;
+ }
+ // So first we generate an image of the same exact size filled with the color 0,0,0,0
+ Imlib_Image mask = imlib_create_image( w, h );
+ // Save our original image.
+ Imlib_Image buffer = imlib_context_get_image();
+ imlib_context_set_image( mask );
+ imlib_image_set_has_alpha( 1 );
+ imlib_context_set_color( 0, 0, 0, 0 );
+ imlib_image_fill_rectangle( 0, 0, w, h );
+ // Grab our monitor information, (basically get pixel rectangles that are actually displaying).
+ std::vector<XRRCrtcInfo*> monitors = xengine->getCRTCS();
+ imlib_context_set_color( 0, 0, 0, 255 );
+ for ( unsigned int i=0;i<monitors.size();i++ ) {
+ XRRCrtcInfo* cmonitor = monitors[ i ];
+ // Then quickly block in our visible pixels on our mask
+ imlib_image_fill_rectangle( cmonitor->x - x, cmonitor->y - y, cmonitor->width, cmonitor->height );
+ }
+ xengine->freeCRTCS( monitors );
+ imlib_context_set_color( 255, 255, 255, 255 );
+ imlib_context_set_image( buffer );
+ // Then finally apply our mask to the original image, which should remove any garbage pixels that are off-screen.
+ imlib_image_copy_alpha_to_image( mask, 0, 0 );
+ imlib_context_set_image( mask );
+ imlib_free_image();
+ imlib_context_set_image( buffer );
+ // Then finally apply our mask to the original image, which should remove any garbage pixels that are off-screen.
+ // But unfortunately that doesn't actually delete the pixels, so we have to do one more pass.
+ // This whole thing just creates another blank image, and blends the masked image onto it.
+ // This is because all we did was copy the alpha channel, so formats like jpg wouldn't even care that we did all this
+ // work unless I add this extra pass.
+ Imlib_Image finalimage = imlib_create_image( w, h );
+ imlib_context_set_image( finalimage );
+ imlib_image_set_has_alpha( 1 );
+ imlib_context_set_color( 0, 0, 0, 0 );
+ imlib_image_fill_rectangle( 0, 0, w, h );
+ imlib_context_set_color( 255, 255, 255, 255 );
+ imlib_blend_image_onto_image( buffer, 1, 0, 0, w, h, 0, 0, w, h );
+ imlib_context_set_image( buffer );
+ imlib_free_image();
+ imlib_context_set_image( finalimage );
+ // Our final image is in the imlib context!
+ return EXIT_SUCCESS;
+}
+
+/**
+* @brief Simply saves the image in buffer to the given file, then frees the image from memory. Imlib handles formating (.png, .gif, etc).
+*
+* @param file The file path to save.
+*
+* @return 0 on success, 1 on failure.
+*/
+int maim::IMEngine::save( std::string file ) {
+ Imlib_Load_Error err;
+ imlib_save_image_with_error_return( file.c_str(), &err );
+ if ( err == IMLIB_LOAD_ERROR_NONE ) {
+ imlib_free_image();
+ return EXIT_SUCCESS;
+ }
+ fprintf( stderr, "Failed to save image %s: ", file.c_str() );
+ switch( err ) {
+ case IMLIB_LOAD_ERROR_UNKNOWN:
+ default: {
+ fprintf( stderr, "unknown error %d\n", (int)err );
+ break;
+ }
+ case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS:
+ fprintf( stderr, "out of file descriptors\n" );
+ break;
+ case IMLIB_LOAD_ERROR_OUT_OF_MEMORY:
+ fprintf( stderr, "out of memory\n" );
+ break;
+ case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS:
+ fprintf( stderr, "path contains too many symbolic links\n" );
+ break;
+ case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE:
+ fprintf( stderr, "path points outside address space\n" );
+ break;
+ case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY:
+ fprintf( stderr, "path component is not a directory\n" );
+ break;
+ case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT:
+ fprintf( stderr, "path component is non-existant (~ isn't expanded inside quotes!)\n" );
+ break;
+ case IMLIB_LOAD_ERROR_PATH_TOO_LONG:
+ fprintf( stderr, "path is too long\n" );
+ break;
+ case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT:
+ fprintf( stderr, "no loader for file format (unsupported format)\n" );
+ break;
+ case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE: {
+ fprintf( stderr, "not enough disk space\n" );
+ break;
+ }
+ case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: {
+ fprintf( stderr, "file does not exist\n" );
+ break;
+ }
+ case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY: {
+ fprintf( stderr, "file is a directory\n" );
+ break;
+ }
+ case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE:
+ case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: {
+ fprintf( stderr, "permission denied\n" );
+ break;
+ }
+ }
+ imlib_free_image();
+ return EXIT_FAILURE;
+}
diff --git a/src/im.hpp b/src/im.hpp
new file mode 100644
index 0000000..3129715
--- /dev/null
+++ b/src/im.hpp
@@ -0,0 +1,52 @@
+/* im.hpp: Handles starting and managing imlib2.
+ *
+ * Copyright (C) 2014: Dalton Nell, Maim Contributors (https://github.com/naelstrof/maim/graphs/contributors).
+ *
+ * This file is part of Maim.
+ *
+ * Maim is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Maim is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Maim. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAIM_IM_H_
+#define MAIM_IM_H_
+
+#include <Imlib2.h>
+#include <X11/extensions/Xfixes.h>
+#include <X11/extensions/Xrandr.h>
+#include <vector>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "x.hpp"
+
+namespace maim {
+
+class IMEngine {
+public:
+ IMEngine();
+ ~IMEngine();
+ int init();
+ int screenshot( Window id, int x, int y, unsigned int w, unsigned int h );
+ int screenshot( Window id );
+ int blendCursor( Window id, int x = 0, int y = 0 );
+ int mask( int x = 0, int y = 0, unsigned int w = 0, unsigned int h = 0 );
+ int save( std::string filename );
+private:
+};
+
+}
+
+extern maim::IMEngine* imengine;
+
+#endif // MAIM_IM_H_
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..a9a7b29
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,381 @@
+/* main.cpp
+ *
+ * Copyright (C) 2014: Dalton Nell, Maim Contributors (https://github.com/naelstrof/maim/graphs/contributors).
+ *
+ * This file is part of Maim.
+ *
+ * Maim is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Maim is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Maim. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cerrno>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <pwd.h>
+#include <string>
+#include <sstream>
+#include <time.h>
+
+#include "x.hpp"
+#include "im.hpp"
+#include "cmdline.h"
+
+// Executes a command and gets its output. Used for executing slop for selection.
+int exec( std::string cmd, std::string* ret ) {
+ FILE* pipe = popen( cmd.c_str(), "r" );
+ if ( !pipe ) {
+ return EXIT_FAILURE;
+ }
+ // Doesn't matter what size the buffer is, since it's grabbed in chunks.
+ char buffer[255];
+ std::string result = "";
+ while( !feof( pipe ) ) {
+ if( fgets( buffer, 255, pipe ) != NULL ) {
+ result += buffer;
+ }
+ }
+ *ret = result;
+ if ( pclose( pipe ) == -1 ) {
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
+
+// Parse geometry from a string, it's pretty simple really.
+int parseGeometry( std::string arg, int* x, int* y, int* w, int* h ) {
+ std::string copy = arg;
+ // Replace all x's and +'s with spaces. This is so that sscanf works properly, it just doesn't
+ // like using anything but spaces for delimiters.
+ int find = copy.find( "x" );
+ while( find != (int)copy.npos ) {
+ copy.at( find ) = ' ';
+ find = copy.find( "x" );
+ }
+ find = copy.find( "+" );
+ while( find != (int)copy.npos ) {
+ copy.at( find ) = ' ';
+ find = copy.find( "+" );
+ }
+ int num = sscanf( copy.c_str(), "%d %d %d %d", w, h, x, y );
+ if ( num != 4 ) {
+ fprintf( stderr, "Error parsing geometry from %s\n", arg.c_str() );
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
+
+// We use this to detect if we should enable masking or not.
+// This is really important because if a user tries to screenshot a window that's
+// slightly off-screen he probably wants the whole window, but if a user
+// takes a full screenshot, then he would most certainly want it masked, but
+// only if they have pixels that are offscreen.
+bool checkMask( std::string type, int x, int y, int w, int h, Window id ) {
+ int sw = WidthOfScreen( xengine->m_screen );
+ int sh = HeightOfScreen( xengine->m_screen );
+ if ( type == "auto" ) {
+ // First we check if there's even any offscreen pixels
+ int monitorArea = 0;
+ std::vector<XRRCrtcInfo*> monitors = xengine->getCRTCS();
+ for ( unsigned int i = 0;i<monitors.size();i++ ) {
+ XRRCrtcInfo* cmonitor = monitors[ i ];
+ monitorArea += cmonitor->height * cmonitor->width;
+ }
+ xengine->freeCRTCS( monitors );
+ // If our monitors cover the entire screen, masking won't do anything anyway.
+ if ( monitorArea >= sw * sh ) {
+ return false;
+ }
+ // If we specified an actual window we certainly don't want to mask anything.
+ if ( id != None && id != xengine->m_root ) {
+ return false;
+ }
+ // If our screenshot has > 80% of the screen covered, we probably want it masked by off-screen pixels.
+ if ( abs( (int)( (float)sw - (float)w ) ) / (float)sw < 0.2 &&
+ abs( (int)( (float)sh - (float)h ) ) / (float)sh < 0.2 &&
+ (float)x / (float)sw < 0.2 &&
+ (float)y / (float)sh < 0.2 ) {
+ return true;
+ }
+ // Otherwise we're probably taking a picture of a specific thing on the screen.
+ return false;
+ } else if ( type == "on" ) {
+ return true;
+ }
+ return false;
+}
+
+int slop( gengetopt_args_info options, int* x, int* y, int* w, int* h, Window* window ) {
+ std::stringstream slopcommand;
+ slopcommand << "slop";
+ if ( options.nokeyboard_flag ) {
+ slopcommand << " --nokeyboard ";
+ }
+ slopcommand << " -b " << options.bordersize_arg;
+ slopcommand << " -p " << options.padding_arg;
+ slopcommand << " -t " << options.tolerance_arg;
+ slopcommand << " -g " << options.gracetime_arg;
+ slopcommand << " -c " << options.color_arg;
+ if ( options.nodecorations_flag ) {
+ slopcommand << " -n";
+ }
+ slopcommand << " --min=" << options.min_arg;
+ slopcommand << " --max=" << options.max_arg;
+ if ( options.xdisplay_given ) {
+ slopcommand << " --xdisplay=" << options.xdisplay_arg;
+ }
+ if ( options.highlight_flag ) {
+ slopcommand << " -l";
+ }
+ slopcommand << "\n";
+ std::string result;
+ int err = exec( slopcommand.str(), &result );
+ if ( err != EXIT_SUCCESS ) {
+ return EXIT_FAILURE;
+ }
+ // From here we'll just be parsing the output of slop.
+ // Replace all ='s with spaces in the result, this is so sscanf works properly.
+ int find = result.find( "=" );
+ while( find != (int)result.npos ) {
+ result.at( find ) = ' ';
+ find = result.find( "=" );
+ }
+ Window test = None;
+ int num = sscanf( result.c_str(), "X %i\n Y %i\n W %i\n H %i\nG %*s\nID %lu", x, y, w, h, &test );
+ if ( num != 5 || ( *w == 0 && *h == 0 ) ) {
+ return EXIT_FAILURE;
+ }
+ // If we actually have a window selection, set the window and offset the coordinates to be
+ // localized to that particular window.
+ if ( test != None ) {
+ *window = test;
+ // If we get a window, make sure that slop's selection's origin is around it.
+ // Slop's selection's origin defaults to the root window, so we just use XTranslateCoordinates.
+ Window junk;
+ XTranslateCoordinates( xengine->m_display, xengine->m_root, test, *x, *y, x, y, &junk );
+ }
+ return EXIT_SUCCESS;
+}
+
+int app( int argc, char** argv ) {
+ // First parse any options and the filename we need.
+ gengetopt_args_info options;
+ int err = cmdline_parser( argc, argv, &options );
+ if ( err != EXIT_SUCCESS ) {
+ return EXIT_FAILURE;
+ }
+ // Then set up the x interface.
+ if ( options.xdisplay_given ) {
+ err = xengine->init( options.xdisplay_arg );
+ } else {
+ // If we weren't specifically given a xdisplay, we try
+ // to parse it from environment variables
+ char* display = getenv( "DISPLAY" );
+ if ( display ) {
+ err = xengine->init( display );
+ } else {
+ fprintf( stderr, "Warning: Failed to parse environment variable: DISPLAY. Using \":0\" instead.\n" );
+ err = xengine->init( ":0" );
+ }
+ }
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Failed to grab X display!\n" );
+ return EXIT_FAILURE;
+ }
+ // Then the imlib2 interface
+ err = imengine->init();
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Failed to initialize imlib2!\n" );
+ return EXIT_FAILURE;
+ }
+ // Grab all of our variables from the options.
+ bool gotGeometry = false;
+ bool gotSelectFlag = options.select_flag;
+ int x, y, w, h;
+ float delay;
+ err = sscanf( options.delay_arg, "%f", &delay );
+ if ( err != 1 ) {
+ fprintf( stderr, "Failed to parse %s as a float for delay!\n", options.delay_arg );
+ return EXIT_FAILURE;
+ }
+ struct timespec delayTime;
+ delayTime.tv_sec = delay;
+ delayTime.tv_nsec = 0;
+ // Get our geometry if we have any.
+ if ( options.x_given && options.y_given && options.w_given && options.h_given && !options.geometry_given ) {
+ x = options.x_arg;
+ y = options.y_arg;
+ w = options.w_arg;
+ h = options.h_arg;
+ gotGeometry = true;
+ } else if ( ( options.x_given || options.y_given || options.w_given || options.h_given ) && !options.geometry_given ) {
+ fprintf( stderr, "Partial geometry arguments were set, but it isn't enough data to take a screenshot!\n" );
+ fprintf( stderr, "Please give the geometry argument or give ALL of the following arguments: x, y, w, h.\n" );
+ cmdline_parser_free( &options );
+ return EXIT_FAILURE;
+ } else if ( options.geometry_given ) {
+ err = parseGeometry( options.geometry_arg, &x, &y, &w, &h );
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Failed to parse geometry %s, should be in format WxH+X+Y!\n", options.geometry_arg );
+ cmdline_parser_free( &options );
+ return EXIT_FAILURE;
+ }
+ gotGeometry = true;
+ }
+ // Get our window if we have one, default to the root window.
+ Window window = xengine->m_root;
+ if ( options.windowid_given ) {
+ window = (Window)options.windowid_arg;
+ // Since we have a window we need to turn root coords into our local window coords.
+ // but only if the user wants us to.
+ if ( !options.localize_flag && window != None ) {
+ Window junk;
+ XTranslateCoordinates( xengine->m_display, xengine->m_root, window, x, y, &x, &y, &junk );
+ }
+ }
+ // Get our file name
+ std::string file = "";
+ // If we don't have a file, default to writing to the home directory.
+ if ( options.inputs_num == 0 ) {
+ // Try as hard as we can to get the current directory.
+ int trycount = 0;
+ int length = MAXPATHLEN;
+ char* currentdir = new char[ length ];
+ char* error = getcwd( currentdir, length );
+ while ( error == NULL ) {
+ delete[] currentdir;
+ length *= 2;
+ currentdir = new char[ length ];
+ error = getcwd( currentdir, length );
+ trycount++;
+ // Ok someone's trying to be whacky with the current directory if we're going 8 times over
+ // the max path length.
+ if ( trycount > 3 ) {
+ fprintf( stderr, "Failed to grab the current directory!" );
+ cmdline_parser_free( &options );
+ return EXIT_FAILURE;
+ }
+ }
+ file = currentdir;
+ // Get unix timestamp
+ std::stringstream result;
+ result << (int)time( NULL );
+ file += "/" + result.str() + ".png";
+ printf( "No file specified, using %s\n", file.c_str() );
+ free( currentdir );
+ } else if ( options.inputs_num == 1 ) {
+ file = options.inputs[ 0 ];
+ } else {
+ fprintf( stderr, "Unexpected number of output files! There should only be one.\n" );
+ cmdline_parser_free( &options );
+ return EXIT_FAILURE;
+ }
+
+ // Finally we have all our information, now to use it.
+ if ( gotSelectFlag ) {
+ err = slop( options, &x, &y, &w, &h, &window );
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Selection was cancelled or slop failed to run. Make sure it's installed!\n" );
+ cmdline_parser_free( &options );
+ return EXIT_FAILURE;
+ }
+ err = nanosleep( &delayTime, NULL );
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Warning: Failed to delay the screenshot. Continuing anyway..." );
+ }
+ err = imengine->screenshot( window, x, y, w, h );
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Failed to take screenshot.\n" );
+ return EXIT_FAILURE;
+ }
+ if ( !options.hidecursor_flag ) {
+ imengine->blendCursor( window, x, y );
+ }
+ if ( checkMask( options.mask_arg, x, y, w, h, window ) ) {
+ imengine->mask( x, y, w, h );
+ }
+ err = imengine->save( file );
+ cmdline_parser_free( &options );
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Failed to take screenshot.\n" );
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+ }
+ if ( gotGeometry ) {
+ err = nanosleep( &delayTime, NULL );
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Warning: Failed to delay the screenshot. Continuing anyway..." );
+ }
+ err = imengine->screenshot( window, x, y, w, h );
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Failed to take screenshot.\n" );
+ return EXIT_FAILURE;
+ }
+ if ( !options.hidecursor_flag ) {
+ imengine->blendCursor( window, x, y );
+ }
+ if ( checkMask( options.mask_arg, x, y, w, h, window ) ) {
+ imengine->mask( x, y, w, h );
+ }
+ err = imengine->save( file );
+ cmdline_parser_free( &options );
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Failed to take screenshot.\n" );
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+ }
+ // If we didn't get any special options, just screenshot the specified window
+ // (Which defaults to the whole screen).
+ err = nanosleep( &delayTime, NULL );
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Warning: Failed to delay the screenshot. Continuing anyway..." );
+ }
+ err = imengine->screenshot( window );
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Failed to take screenshot.\n" );
+ return EXIT_FAILURE;
+ }
+ if ( !options.hidecursor_flag ) {
+ imengine->blendCursor( window );
+ }
+ if ( checkMask( options.mask_arg, 0, 0, WidthOfScreen( xengine->m_screen ), HeightOfScreen( xengine->m_screen ), window ) ) {
+ imengine->mask();
+ }
+ err = imengine->save( file );
+ cmdline_parser_free( &options );
+ if ( err != EXIT_SUCCESS ) {
+ fprintf( stderr, "Failed to take screenshot.\n" );
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
+
+int main( int argc, char** argv ) {
+ try {
+ return app( argc, argv );
+ } catch( std::bad_alloc const& exception ) {
+ fprintf( stderr, "Couldn't allocate enough memory! No space left in RAM." );
+ return EXIT_FAILURE;
+ } catch( std::exception const& exception ) {
+ fprintf( stderr, "Unhandled Exception Thrown: %s\n", exception.what() );
+ return EXIT_FAILURE;
+ } catch( ... ) {
+ fprintf( stderr, "Unknown Exception Thrown!\n" );
+ return EXIT_FAILURE;
+ }
+}
diff --git a/src/options.ggo b/src/options.ggo
new file mode 100644
index 0000000..c61ed24
--- /dev/null
+++ b/src/options.ggo
@@ -0,0 +1,125 @@
+package "maim"
+version "v@maim_VERSION_MAJOR@.@maim_VERSION_MINOR@.@maim_VERSION_PATCH@"
+purpose "Takes screenshots."
+usage "maim [options] [file]"
+description "maim (Make Image) is a utility that takes screenshots of your desktop using imlib2. It's meant to overcome shortcomings of scrot and performs better than scrot in several ways."
+versiontext "Copyright (C) 2014 Dalton Nell, Maim Contributors (https://github.com/naelstrof/maim/graphs/contributors)"
+
+args "--unamed-opts --file-name=cmdline"
+
+text "Options"
+
+option "xdisplay" - "Sets the x display."
+ string
+ typestr="hostname:number.screen_number"
+ optional
+
+option "select" s "Enables user region selection. Requires slop to be installed."
+ flag
+ off
+
+option "x" x "Sets the x coordinate for taking an image"
+ int
+ optional
+
+option "y" y "Sets the y coordinate for taking an image"
+ int
+ optional
+
+option "w" w "Sets the width for taking an image"
+ int
+ optional
+
+option "h" h "Sets the height for taking an image"
+ int
+ optional
+
+option "geometry" g "Set the region to capture"
+ string
+ typestr="WxH+X+Y"
+ optional
+
+option "delay" d "Set the amount of time to wait before taking an image."
+ string
+ typestr="FLOAT"
+ default="0.0"
+ optional
+
+option "windowid" i "Set the window to capture. Defaults to the root window id."
+ int
+ optional
+
+option "localize" - "Localizes given geometry to the given window. So \"maim -i $ID -g 100x100+0+0 --localize\" would screenshot the top-left 100x100 pixels of the given window, rather than the top-left 100x100 pixels of the root window."
+ flag
+ off
+
+option "hidecursor" - "Prevents the system cursor from showing up in screenshots."
+ flag
+ off
+
+option "mask" m "Masks off-screen pixels so they don't show up in screenshots."
+ string
+ values="auto","off","on"
+ default="auto"
+ optional
+
+text "\nSlop Options"
+
+option "nokeyboard" - "Disables the ability to cancel selections with the keyboard."
+ flag
+ off
+
+option "bordersize" b "Set the selection rectangle's thickness. Does nothing when --highlight is enabled."
+ int
+ default="5"
+ optional
+
+option "padding" p "Set the padding size of the selection. Can be negative."
+ int
+ default="0"
+ optional
+
+option "tolerance" t "How far in pixels the mouse can move after clicking and still be detected as a normal click instead of a click and drag. Setting this to 0 will disable window selections."
+ int
+ default="2"
+ optional
+
+option "gracetime" - "Set the amount of time before slop will check for keyboard cancellations in seconds."
+ string
+ typestr="FLOAT"
+ default="0.4"
+ optional
+
+option "color" c "Set the selection rectangle's color. Supports RGB or RGBA values."
+ string
+ typestr="FLOAT,FLOAT,FLOAT,FLOAT"
+ default="0.5,0.5,0.5,1"
+ optional
+
+option "nodecorations" n "Attempt to select child windows in order to avoid window decorations."
+ flag
+ off
+
+option "min" - "Set the minimum output of width or height values. This is useful to avoid outputting 0. Setting min and max to the same value disables drag selections."
+ int
+ default="0"
+ optional
+
+option "max" - "Set the maximum output of width or height values. Setting min and max to the same value disables drag selections."
+ int
+ default="0"
+ optional
+
+option "highlight" l "Instead of outlining selections, slop highlights it. This is only useful when --color is set to a transparent color."
+ flag
+ off
+
+text "\nExamples\n"
+text " $ # Screenshot the active window\n"
+text " $ maim -i $(xdotool getactivewindow)\n"
+text "\n"
+text " $ # Prompt a transparent red selection to screenshot.\n"
+text " $ maim -s -c 1,0,0,0.6\n"
+text "\n"
+text " $ # Save a dated screenshot.\n"
+text " $ maim ~/$(date +%F-%T).png\n"
diff --git a/src/x.cpp b/src/x.cpp
new file mode 100644
index 0000000..c31cd50
--- /dev/null
+++ b/src/x.cpp
@@ -0,0 +1,95 @@
+/* x.cpp: Handles starting and managing X
+ *
+ * Copyright (C) 2014: Dalton Nell, Maim Contributors (https://github.com/naelstrof/maim/graphs/contributors).
+ *
+ * This file is part of Maim.
+ *
+ * Maim is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Maim is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Maim. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "x.hpp"
+
+maim::XEngine* xengine = new maim::XEngine();
+
+maim::XEngine::XEngine() {
+ m_display = NULL;
+ m_visual = NULL;
+ m_screen = NULL;
+ m_good = false;
+}
+
+maim::XEngine::~XEngine() {
+ if ( !m_good ) {
+ return;
+ }
+ XCloseDisplay( m_display );
+}
+
+int maim::XEngine::init( std::string display ) {
+ // Initialize display
+ m_display = XOpenDisplay( display.c_str() );
+ if ( !m_display ) {
+ fprintf( stderr, "Error: Failed to open X display %s\n", display.c_str() );
+ return 1;
+ }
+ m_screen = ScreenOfDisplay( m_display, DefaultScreen( m_display ) );
+ m_visual = DefaultVisual ( m_display, XScreenNumberOfScreen( m_screen ) );
+ m_colormap = DefaultColormap( m_display, XScreenNumberOfScreen( m_screen ) );
+ m_root = RootWindow ( m_display, XScreenNumberOfScreen( m_screen ) );
+ //m_root = DefaultRootWindow( m_display );
+
+ // We ignore X errors since we don't care if we fail to get
+ // the physical monitor positions.
+ XErrorHandler originalHandler = XSetErrorHandler( maim::IgnoreErrorHandler );
+ m_res = XRRGetScreenResourcesCurrent( m_display, m_root);
+ XSetErrorHandler( originalHandler );
+ if ( !m_res ) {
+ fprintf( stderr, "Warning: Failed to get screen resources. Multi-monitor X screens won't have garbage visual data removed.\n" );
+ }
+
+ m_good = true;
+ return EXIT_SUCCESS;
+}
+
+Window maim::XEngine::getWindowByID( int id ) {
+ // There's actually no way to check if the id is valid...
+ return (Window)id;
+ // The only thing we can do is use it and see if we get a BadWindow error later.
+}
+
+// This stuff is used to detect which pixels we can actually see with
+// the physical monitor positions.
+// It's useful for people with multimonitor setups where the monitors
+// don't fit together well since we can black out the pixels that are
+// generally just garbage.
+std::vector<XRRCrtcInfo*> maim::XEngine::getCRTCS() {
+ std::vector<XRRCrtcInfo*> monitors;
+ if ( !m_res ) {
+ return monitors;
+ }
+ for ( int i=0;i<m_res->ncrtc;i++ ) {
+ monitors.push_back( XRRGetCrtcInfo( m_display, m_res, m_res->crtcs[ i ] ) );
+ }
+ return monitors;
+}
+
+void maim::XEngine::freeCRTCS( std::vector<XRRCrtcInfo*> monitors ) {
+ for ( unsigned int i=0;i<monitors.size();i++ ) {
+ XRRFreeCrtcInfo( monitors[ i ] );
+ }
+}
+
+int maim::IgnoreErrorHandler( Display* dpy, XErrorEvent* event ) {
+ return EXIT_SUCCESS;
+}
diff --git a/src/x.hpp b/src/x.hpp
new file mode 100644
index 0000000..d01e00e
--- /dev/null
+++ b/src/x.hpp
@@ -0,0 +1,56 @@
+/* x.hpp: Handles starting and managing X
+ *
+ * Copyright (C) 2014: Dalton Nell, Maim Contributors (https://github.com/naelstrof/maim/graphs/contributors).
+ *
+ * This file is part of Maim.
+ *
+ * Maim is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Maim is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Maim. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAIM_X_H_
+#define MAIM_X_H_
+
+#include <X11/Xlib.h>
+#include <X11/extensions/Xrandr.h>
+#include <cstdlib>
+#include <vector>
+#include <string>
+#include <cstdio>
+
+namespace maim {
+
+class XEngine {
+public:
+ XEngine();
+ ~XEngine();
+ int init( std::string display );
+ Display* m_display;
+ Visual* m_visual;
+ Screen* m_screen;
+ Colormap m_colormap;
+ Window m_root;
+ XRRScreenResources* m_res;
+ bool m_good;
+ Window getWindowByID( int id );
+ std::vector<XRRCrtcInfo*> getCRTCS();
+ void freeCRTCS( std::vector<XRRCrtcInfo*> monitors );
+};
+
+int IgnoreErrorHandler( Display* dpy, XErrorEvent* event );
+
+}
+
+extern maim::XEngine* xengine;
+
+#endif // MAIM_X_H_
diff --git a/unitTests.sh b/unitTests.sh
new file mode 100755
index 0000000..f9e907e
--- /dev/null
+++ b/unitTests.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+function test {
+ "$@"
+ local status=$?
+ if [ $status -ne 0 ]; then
+ echo "Error test \"$@\" failed with $status, should be 0!"
+ exit 1
+ fi
+}
+
+function test_fail {
+ "$@"
+ local status=$?
+ if [ $status -ne 1 ]; then
+ echo "Error test \"$@\" failed with $status, should be 1!"
+ exit 1
+ fi
+}
+
+echo "Starting unit tests..."
+test ./maim
+# Variable expansion tests.
+test ./maim ~/test.png
+test ./maim "/tmp/should be entire x screen.png"
+
+# Buffer overflow tests. Lots of characters depending on the username. With naelstrof it's over 2.5k which is over the default MAXPATHLENGTH of 1024.
+test ./maim ~/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/../$USER/test.png
+test ./maim "/tmp/should be 1920x1080+0+0.png" -g 1920x1080+0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000+-00000000000000000000000000000000000000000000000000000000000000000000000000000
+test ./maim "/tmp/should be 1920x1080+0+0 also.png" -x 0000000000000000000000000000000000000000000000000000 -y 0000000000000000000000000000000000000000000 -w 1920 -h 1080
+test ./maim "/tmp/should be what you selected first.png" -s -c 1.00000000000000000000000000000000000000000000,1.00000000000000000000000000000000000000000000000,1.0000000000000000000000000000000000000000000000000,1.0000000000000000000000000000000000000000000000000
+# Color RGB test (vs RGBA)
+test ./maim "/tmp/should be what you selected second.png" -s -c 1,0,0
+
+# Failure cases.
+test_fail ./maim "/tmp/$(date +%s-%N).png" "~/whyamihere.png" 2>/dev/null
+test_fail ./maim "/tmp/$(date +%s-%N).png" -x 0 -y 0 -w 100 2>/dev/null
+test_fail ./maim "/tmp/$(date +%s-%N).png" -g thisisntageo 2>/dev/null
+test_fail ./maim "/tmp/should.not.exist.extension" 2>/dev/null
+test_fail ./maim -d notafloat "/tmp/should.not.exist.png" 2>/dev/null
+
+rm ~/test.png
+
+echo "Unit tests finished without error! Check /tmp for any awkward/broken screenshots."