macro_optional_add_subdirectory(kfilemetadata)
macro_optional_add_subdirectory(lokalize)
macro_optional_add_subdirectory(libksane)
-macro_optional_add_subdirectory(libkscreen)
macro_optional_add_subdirectory(kcolorchooser)
macro_optional_add_subdirectory(kfloppy)
macro_optional_add_subdirectory(kget)
+++ /dev/null
-project(libkscreen)
-set(libkscreen_VERSION_MAJOR 1)
-set(libkscreen_VERSION_MINOR 0)
-set(libkscreen_VERSION_RELEASE 4)
-set(libkscreen_VERSION "${libkscreen_VERSION_MAJOR}.${libkscreen_VERSION_MINOR}.${libkscreen_VERSION_RELEASE}")
-set(LIBKSCREEN_VERSION "${libkscreen_VERSION}")
-
-configure_file(
- ${CMAKE_CURRENT_SOURCE_DIR}/libkscreen-config.h.cmake
- ${CMAKE_CURRENT_BINARY_DIR}/libkscreen-config.h
- @ONLY
-)
-
-if(POLICY CMP0017)
- cmake_policy(SET CMP0017 NEW)
-endif()
-
-enable_testing()
-add_definitions(${KDE4_DEFINITIONS})
-include(CheckCXXCompilerFlag)
-
-macro_optional_find_package(XCB)
-set_package_properties(XCB PROPERTIES DESCRIPTION "The X protocol C-language Binding (XCB) is a replacement for Xlib"
- URL "http://xcb.freedesktop.org/"
- TYPE OPTIONAL
- PURPOSE "Needed to build XRandR 1.1 backend"
-)
-
-macro_optional_find_package(X11_XCB)
-set_package_properties(X11_XCB PROPERTIES DESCRIPTION "XCB extension to work with X11"
- URL "http://xcb.freedesktop.org/"
- TYPE OPTIONAL
- PURPOSE "Needed to build XRandR 1.1 backend"
-)
-
-check_cxx_compiler_flag(-fvisibility=hidden _HAVE_VISIBILITY)
-if (_HAVE_VISIBILITY AND NOT WIN32)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
-
- check_cxx_compiler_flag(-fvisibility-inlines-hidden _HAVE_VISIBILITY_INLINES)
- if (_HAVE_VISIBILITY_INLINES)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
- endif (_HAVE_VISIBILITY_INLINES)
-endif (_HAVE_VISIBILITY AND NOT WIN32)
-
-#
-### lib64/32 support kde like
-#
-set(LIB_SUFFIX "" CACHE STRING "Define suffix for lib directory (32/64)")
-
-set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
-set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
-
-set(INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "${BIN_INSTALL_DIR}"
- LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
- ARCHIVE DESTINATION "${LIB_INSTALL_DIR}" COMPONENT Devel )
-
-include_directories(${PROJECT_SOURCE_DIR}/src ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDES} ${KDE4_INCLUDES})
-
-add_subdirectory(src)
-add_subdirectory(backends)
-if(ENABLE_TESTING)
- add_subdirectory(tests)
-endif()
-
-configure_file(${libkscreen_SOURCE_DIR}/LibKScreenConfig.cmake.in
- ${libkscreen_BINARY_DIR}/LibKScreenConfig.cmake
- @ONLY
-)
-# this file is used by to check if the installed version can be used.
-macro_write_basic_cmake_version_file(${libkscreen_BINARY_DIR}/LibKScreenConfigVersion.cmake
- ${libkscreen_VERSION_MAJOR} ${libkscreen_VERSION_MINOR} ${libkscreen_VERSION_RELEASE})
-
-install(FILES ${libkscreen_BINARY_DIR}/LibKScreenConfig.cmake ${libkscreen_BINARY_DIR}/LibKScreenConfigVersion.cmake
- DESTINATION ${LIB_INSTALL_DIR}/cmake/LibKScreen)
-
-# Install the file with the exported targets
-install(EXPORT kscreenLibraryTargets
- DESTINATION ${LIB_INSTALL_DIR}/cmake/LibKScreen
- FILE LibKScreenTargetsWithPrefix.cmake)
-
+++ /dev/null
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) 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
-this service 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 make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. 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.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-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
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the 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 a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE 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.
-
- 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
-convey 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 2 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, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision 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, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This 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.
+++ /dev/null
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) 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
-this service 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 make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. 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.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-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
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the 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 a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE 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.
-
- 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
-convey 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 2 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, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision 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, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This 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.
+++ /dev/null
-# Do not modify this file. Any change will be overwritten by CMake.
-
-# Config file for LibKScreen. This file will define:
-# LibKScreen_INCLUDE_DIR - The LibKScreen include directory
-# LibKScreen_LIBRARY - The library needed to use LibKScreen
-# LibKScreen_VERSION - The LibKScreen version
-
-get_filename_component(_currentDir ${CMAKE_CURRENT_LIST_FILE} PATH) # The current directory
-get_filename_component(rootDir ${_currentDir}/@relInstallDir@ ABSOLUTE) # The install prefix
-
-# The library version
-set(LibKScreen_VERSION_MAJOR @LIBKSCREEN_VERSION_MAJOR@)
-set(LibKScreen_VERSION_MINOR @LIBKSCREEN_VERSION_MINOR@)
-set(LibKScreen_VERSION_RELEASE @LIBKSCREEN_VERSION_RELEASE@)
-set(LibKScreen_VERSION ${LibKScreen_VERSION_MAJOR}.${LibKScreen_VERSION_MINOR}.${LibKScreen_VERSION_RELEASE})
-
-# Include directory
-set(LibKScreen_INSTALL_PREFIX "${rootDir}")
-set(LibKScreen_INCLUDE_DIR "@INCLUDE_INSTALL_DIR@")
-
-# import the exported targets
-include(${_currentDir}/LibKScreenTargetsWithPrefix.cmake)
-
-# Set the library variable
-set(LibKScreen_LIBRARY kscreen)
+++ /dev/null
-if(ENABLE_TESTING)
- add_subdirectory(fake)
-endif()
-add_subdirectory(xrandr)
-if (XCB_FOUND AND X11_XCB_FOUND)
- add_subdirectory(xrandr1.1)
-endif()
\ No newline at end of file
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef ABSTRACT_BACKEND_H
-#define ABSTRACT_BACKEND_H
-
-#include <QtCore/QString>
-#include <QtCore/QObject>
-
-namespace KScreen {
- class Config;
- class Edid;
-}
-
-class AbstractBackend
-{
- public:
- virtual ~AbstractBackend() {}
- virtual QString name() const = 0;
- virtual KScreen::Config* config() const = 0;
- virtual void setConfig(KScreen::Config* config) const = 0;
- virtual bool isValid() const = 0;
- virtual KScreen::Edid* edid(int outputId) const = 0;
- virtual void updateConfig(KScreen::Config* config) const = 0;
-};
-
-Q_DECLARE_INTERFACE(AbstractBackend, "org.kde.libkscreen")
-#endif //ABSTRACT_BACKEND_H
+++ /dev/null
-include_directories(
- ${CMAKE_SOURCE_DIR}/src
- ${CMAKE_BUILD_DIR}
- ${QT_INCLUDES}
-)
-
-set(fake_SRCS
- fake.cpp
- parser.cpp
-)
-
-add_library(KSC_Fake MODULE ${fake_SRCS})
-
-set_target_properties(KSC_Fake PROPERTIES PREFIX "")
-target_link_libraries(KSC_Fake
- ${QT_QTCORE_LIBRARY}
- kscreen
-)
-
-install(
- TARGETS KSC_Fake
- DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/kscreen/
-)
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "fake.h"
-#include "parser.h"
-
-#include "config.h"
-#include "edid.h"
-
-#include <stdlib.h>
-
-#include <QtCore/QFile>
-#include <QtCore/qplugin.h>
-
-#ifndef QT_KATIE
-# include <qjson/parser.h>
-#else
-# include <QJsonDocument>
-#endif
-
-Q_EXPORT_PLUGIN2(Fake, Fake)
-
-using namespace KScreen;
-
-Fake::Fake(QObject* parent): QObject(parent)
-{
-
-}
-
-Fake::~Fake()
-{
-
-}
-
-QString Fake::name() const
-{
- return QString("Fake");
-}
-
-Config* Fake::config() const
-{
- return Parser::fromJson(QString(qgetenv("TEST_DATA")));
-}
-
-void Fake::setConfig(Config* config) const
-{
- Q_UNUSED(config)
-}
-
-bool Fake::isValid() const
-{
- return true;
-}
-
-Edid *Fake::edid(int outputId) const
-{
- Q_UNUSED(outputId);
- QFile file(QString(qgetenv("TEST_DATA")));
- file.open(QIODevice::ReadOnly);
-
-#ifndef QT_KATIE
- QJson::Parser parser;
- QVariantMap json = parser.parse(file.readAll()).toMap();
-#else
- QVariantMap json = QJsonDocument::fromJson(file.readAll()).toVariant().toMap();
-#endif
-
- QList <QVariant> outputs = json["outputs"].toList();
- Q_FOREACH(const QVariant &value, outputs) {
- QMap <QString, QVariant > output = value.toMap();
- if (output["id"].toInt() != outputId) {
- continue;
- }
-
- QByteArray data = QByteArray::fromBase64(output["edid"].toByteArray());
- return new Edid((quint8*)data.data(), data.length());
- }
- return 0;
-}
-
-void Fake::updateConfig(Config *config) const
-{
- Q_UNUSED(config);
-}
-
-#include "moc_fake.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef FAKE_BACKEND_H
-#define FAKE_BACKEND_H
-
-#include "../abstractbackend.h"
-#include <QtCore/QObject>
-
-class Fake : public QObject, public AbstractBackend
-{
- Q_OBJECT
- Q_INTERFACES(AbstractBackend)
-
- public:
- explicit Fake(QObject* parent = 0);
- virtual ~Fake();
-
- virtual QString name() const;
- virtual KScreen::Config* config() const;
- virtual void setConfig(KScreen::Config* config) const;
- virtual bool isValid() const;
- virtual KScreen::Edid *edid(int outputId) const;
- virtual void updateConfig(KScreen::Config *config) const;
-};
-
-#endif //FAKE_BACKEND_H
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "parser.h"
-
-#include <config.h>
-
-#include <QtCore/QFile>
-#include <KDebug>
-
-#ifndef QT_KATIE
-# include <qjson/parser.h>
-# include <qjson/qobjecthelper.h>
-#else
-# include <QJsonDocument>
-# include <QMetaProperty>
-#endif
-
-using namespace KScreen;
-
-#ifdef QT_KATIE
-static void qvariant2qobject(const QVariantMap &map, QObject *object)
-{
- const QMetaObject *metaobject = object->metaObject();
-
- for (QVariantMap::const_iterator iter = map.constBegin(),
- end = map.constEnd(); iter != end; iter++) {
- int pIdx = metaobject->indexOfProperty(iter.key().toLatin1());
-
- if ( pIdx < 0 ) {
- continue;
- }
-
- QMetaProperty metaproperty = metaobject->property( pIdx );
- QVariant::Type type = metaproperty.type();
- QVariant v(iter.value());
- if (v.canConvert(type)) {
- v.convert(type);
- metaproperty.write(object, v);
- } else if (metaproperty.typeName() == QLatin1String("QVariant")) {
- metaproperty.write(object, v);
- }
- }
-}
-#endif
-
-Config* Parser::fromJson(const QByteArray& data)
-{
- Config *config = new Config();
-
-#ifndef QT_KATIE
- QJson::Parser parser;
- QVariantMap json = parser.parse(data).toMap();
-#else
- QVariantMap json = QJsonDocument::fromJson(data).toVariant().toMap();
-#endif
-
- Screen* screen = Parser::screenFromJson(json["screen"].toMap());
-
- QList <QVariant> outputs = json["outputs"].toList();
- if (outputs.isEmpty()) {
- return config;
- }
-
- Output *output;
- OutputList outputList;
- Q_FOREACH(const QVariant &value, outputs) {
- output = Parser::outputFromJson(value);
- outputList.insert(output->id(), output);
- }
-
- config->setScreen(screen);
- config->setOutputs(outputList);
- return config;
-}
-
-Config* Parser::fromJson(const QString& path)
-{
- QFile file(path);
- file.open(QIODevice::ReadOnly);
-
- return Parser::fromJson(file.readAll());
-}
-
-Screen* Parser::screenFromJson(const QMap< QString, QVariant >& data)
-{
- Screen* screen = new Screen;
- screen->setId(data["id"].toInt());
- screen->setMinSize(Parser::sizeFromJson(data["minSize"].toMap()));
- screen->setMaxSize(Parser::sizeFromJson(data["maxSize"].toMap()));
- screen->setCurrentSize(Parser::sizeFromJson(data["currentSize"].toMap()));
- screen->setMaxActiveOutputsCount(data["maxActiveOutputsCount"].toInt());
-
- return screen;
-}
-
-Output* Parser::outputFromJson(const QVariant& data)
-{
- QVariantMap map = data.toMap();
- Output *output = new Output;
- output->setId(map["id"].toInt());
-
- QStringList preferredModes;
- QVariantList modes = map["preferredModes"].toList();
- Q_FOREACH(const QVariant &mode, modes) {
- preferredModes.append(mode.toString());
- }
- output->setPreferredModes(preferredModes);
-
-#ifndef QT_KATIE
- QJson::QObjectHelper::qvariant2qobject(map, output);
-#else
- qvariant2qobject(map, output);
-#endif
-
- Mode *mode;
- ModeList modelist;
- modes = map["modes"].toList();
- Q_FOREACH(const QVariant &modeValue, modes) {
- mode = Parser::modeFromJson(modeValue);
- modelist.insert(mode->id(), mode);
- }
- output->setModes(modelist);
-
- if(map.contains("clones")) {
- QList<int> clones;
- Q_FOREACH(const QVariant &id, map["clones"].toList()) {
- clones.append(id.toInt());
- }
-
- output->setClones(clones);
- }
-
- QString type = map["type"].toByteArray().toUpper();
- if (type.contains("LVDS") || type.contains("EDP") || type.contains("IDP")) {
- output->setType(Output::Panel);
- } else if (type.contains("VGA")) {
- output->setType(Output::VGA);
- } else if (type.contains("DVI")) {
- output->setType(Output::DVI);
- } else if (type.contains("DVI-I")) {
- output->setType(Output::DVII);
- } else if (type.contains("DVI-A")) {
- output->setType(Output::DVIA);
- } else if (type.contains("DVI-D")) {
- output->setType(Output::DVID);
- } else if (type.contains("HDMI")) {
- output->setType(Output::HDMI);
- } else if (type.contains("Panel")) {
- output->setType(Output::Panel);
- } else if (type.contains("TV")) {
- output->setType(Output::TV);
- } else if (type.contains("TV-Composite")) {
- output->setType(Output::TVComposite);
- } else if (type.contains("TV-SVideo")) {
- output->setType(Output::TVSVideo);
- } else if (type.contains("TV-Component")) {
- output->setType(Output::TVComponent);
- } else if (type.contains("TV-SCART")) {
- output->setType(Output::TVSCART);
- } else if (type.contains("TV-C4")) {
- output->setType(Output::TVC4);
- } else if (type.contains("DisplayPort")) {
- output->setType(Output::DisplayPort);
- } else if (type.contains("Unknown")) {
- output->setType(Output::Unknown);
- } else {
- kDebug() << "Output Type not translated:" << type;
- }
- return output;
-}
-
-Mode* Parser::modeFromJson(const QVariant& data)
-{
- QVariantMap map = data.toMap();
- Mode *mode = new Mode;
- mode->setId(map["id"].toString());
-
-#ifndef QT_KATIE
- QJson::QObjectHelper::qvariant2qobject(map, mode);
-#else
- qvariant2qobject(map, mode);
-#endif
-
- mode->setSize(Parser::sizeFromJson(map["size"].toMap()));
-
- return mode;
-}
-
-QSize Parser::sizeFromJson(const QVariant& data)
-{
- QVariantMap map = data.toMap();
-
- QSize size;
- size.setWidth(map["width"].toInt());
- size.setHeight(map["height"].toInt());
-
- return size;
-}
-
-QPoint Parser::pointFromJson(const QVariant& data)
-{
- QVariantMap map = data.toMap();
-
- QPoint point;
- point.setX(map["x"].toInt());
- point.setY(map["y"].toInt());
-
- return point;
-}
-
-QRect Parser::rectFromJson(const QVariant& data)
-{
- QRect rect;
- rect.setSize(Parser::sizeFromJson(data));
- rect.setBottomLeft(Parser::pointFromJson(data));
-
- return rect;
-}
-
-bool Parser::validate(const QByteArray& data)
-{
- Q_UNUSED(data);
- return true;
-}
-
-bool Parser::validate(const QString& data)
-{
- Q_UNUSED(data);
- return true;
-}
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef PARSER_H
-#define PARSER_H
-
-#include <QtCore/QByteArray>
-#include <QtCore/QString>
-#include <QtCore/QVariant>
-#include <QtCore/QSize>
-#include <QtCore/QRect>
-#include <QtCore/QPoint>
-
-namespace KScreen {
- class Config;
- class Screen;
- class Output;
- class Mode;
-}
-class Parser
-{
- public:
- static KScreen::Config* fromJson(const QByteArray &data);
- static KScreen::Config* fromJson(const QString &path);
- static bool validate(const QByteArray &data);
- static bool validate(const QString &data);
-
- private:
- static KScreen::Screen* screenFromJson(const QMap<QString, QVariant>& data);
- static KScreen::Output* outputFromJson(const QVariant& data);
- static KScreen::Mode* modeFromJson(const QVariant& data);
- static QSize sizeFromJson(const QVariant& data);
- static QRect rectFromJson(const QVariant& data);
- static QPoint pointFromJson(const QVariant& data);
-};
-
-#endif //PARSER_H
+++ /dev/null
-include_directories(${CMAKE_SOURCE_DIR}/src
- ${KDE4_INCLUDES}
- ${CMAKE_BUILD_DIR}
- ${QT_INCLUDES}
- ${X11_Xrandr_INCLUDE_PATH}
-)
-
-set(xrandr_SRCS
- xrandr.cpp
- xrandrx11helper.cpp
- xrandrconfig.cpp
- xrandroutput.cpp
- xrandrmode.cpp
- xrandrscreen.cpp
-)
-
-add_library(KSC_XRandR MODULE ${xrandr_SRCS})
-
-set_target_properties(KSC_XRandR PROPERTIES PREFIX "")
-target_link_libraries(KSC_XRandR ${QT_QTCORE_LIBRARY}
- ${QT_QTGUI_LIBRARY} #XrandrX11Helper is a QWidget
- ${KDE4_KDECORE_LIBS}
- ${KDE4_KDEUI_LIBS}
- ${X11_Xrandr_LIB}
- ${X11_LIBRARIES}
- ${XCB_RANDR_LIBRARIES}
- ${XCB_XCB_LIBRARIES}
- kscreen
-)
-
-install(TARGETS KSC_XRandR DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/kscreen/)
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef XLIBANDXRANDR_H
-#define XLIBANDXRANDR_H
-
-extern "C"
-{
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#define INT8 _X11INT8
-#define INT32 _X11INT32
-#include <X11/Xproto.h>
-#undef INT8
-#undef INT32
-#include <X11/extensions/Xrandr.h>
-}
-
-#include <fixx11h.h>
-
-#endif // XLIBANDXRANDR
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * Copyright (C) 2012, 2013 by Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "xrandr.h"
-#include "xrandrconfig.h"
-#include "xrandrx11helper.h"
-
-#include "config.h"
-#include "output.h"
-#include "edid.h"
-#include "configmonitor.h"
-
-#include <QtCore/QFile>
-#include <QtCore/qplugin.h>
-#include <QtCore/QRect>
-#include <QAbstractEventDispatcher>
-
-#include <QtGui/QX11Info>
-#include <QApplication>
-
-#include <xcb/randr.h>
-
-#include <kdebug.h>
-
-Q_EXPORT_PLUGIN2(XRandR, XRandR)
-
-Display* XRandR::s_display = 0;
-int XRandR::s_screen = 0;
-Window XRandR::s_rootWindow = 0;
-XRandRConfig* XRandR::s_internalConfig = 0;
-int XRandR::s_randrBase = 0;
-int XRandR::s_randrError = 0;
-bool XRandR::s_monitorInitialized = false;
-bool XRandR::s_has_1_3 = false;
-bool XRandR::s_xorgCacheInitialized = false;
-
-using namespace KScreen;
-
-XRandR::XRandR(QObject* parent)
- : QObject(parent)
- , m_x11Helper(0)
- , m_isValid(false)
-{
- // Use our own connection to make sure that we won't mess up Qt's connection
- // if something goes wrong on our side.
- xcb_generic_error_t *error = 0;
- xcb_randr_query_version_reply_t* version;
- xcb_connection_t *connection = xcb_connect(0, 0);
- version = xcb_randr_query_version_reply(connection, xcb_randr_query_version(connection, XCB_RANDR_MAJOR_VERSION, XCB_RANDR_MINOR_VERSION), &error);
- xcb_disconnect(connection);
-
- if (!version || error) {
- free(error);
- return;
- }
-
- if ((version->major_version > 1) || ((version->major_version == 1) && (version->minor_version >= 2))) {
- m_isValid = true;
- } else {
- kDebug() << "XRandR extension not available or unsupported version";
- return;
- }
-
- if (s_display == 0) {
- s_display = QX11Info::display();
- s_screen = DefaultScreen(s_display);
- s_rootWindow = XRootWindow(s_display, s_screen);
-
- XRRQueryExtension(s_display, &s_randrBase, &s_randrError);
- }
-
- XRandR::s_has_1_3 = (version->major_version > 1 || (version->major_version == 1 && version->minor_version >= 3));
-
- if (s_internalConfig == 0) {
- s_internalConfig = new XRandRConfig();
- }
-
- if (!s_monitorInitialized) {
- m_x11Helper = new XRandRX11Helper();
- /* In case of XRandR 1.0 or 1.1 */
- connect(m_x11Helper, SIGNAL(outputsChanged()), SLOT(updateConfig()));
-
- /* XRandR >= 1.2 */
- connect(m_x11Helper, SIGNAL(outputChanged(RROutput)), SLOT(updateOutput(RROutput)));
- connect(m_x11Helper, SIGNAL(crtcChanged(RRCrtc)), SLOT(updateCrtc(RRCrtc)));
- connect(s_internalConfig, SIGNAL(outputRemoved(int)), SLOT(outputRemovedSlot()));
-
- s_monitorInitialized = true;
- }
-}
-
-XRandR::~XRandR()
-{
- delete m_x11Helper;
-}
-
-QString XRandR::name() const
-{
- return QString("XRandR");
-}
-
-void XRandR::updateConfig()
-{
- s_internalConfig->update();
- KScreen::ConfigMonitor::instance()->notifyUpdate();
-}
-
-void XRandR::outputRemovedSlot()
-{
- KScreen::ConfigMonitor::instance()->notifyUpdate();
-}
-
-void XRandR::updateOutput(RROutput output)
-{
- XRandROutput *xOutput = s_internalConfig->outputs().value(output);
- if (!xOutput) {
- s_internalConfig->addNewOutput(output);
- } else {
- RROutput primary = XRRGetOutputPrimary(XRandR::display(), XRandR::rootWindow());
- xOutput->update((output == primary) ? XRandROutput::SetPrimary : XRandROutput::UnsetPrimary);
- if (output == primary) {
- s_internalConfig->m_primaryOutput = output;
- }
- }
-
- KScreen::ConfigMonitor::instance()->notifyUpdate();
-}
-
-void XRandR::updateCrtc(RRCrtc crtc)
-{
- XRRCrtcInfo* crtcInfo = XRRCrtc(crtc);
- for (int i = 0; i < crtcInfo->noutput; ++i) {
- XRandROutput *xOutput = s_internalConfig->outputs().value(crtcInfo->outputs[i]);
- xOutput->update();
- }
- XRRFreeCrtcInfo(crtcInfo);
-
- KScreen::ConfigMonitor::instance()->notifyUpdate();
-}
-
-Config* XRandR::config() const
-{
- return s_internalConfig->toKScreenConfig();
-}
-
-void XRandR::setConfig(Config* config) const
-{
- if (!config) {
- return;
- }
-
- s_internalConfig->applyKScreenConfig(config);
-}
-
-Edid *XRandR::edid(int outputId) const
-{
- XRandROutput::Map outputs = s_internalConfig->outputs();
- XRandROutput *output = outputs.value(outputId);
- if (!output) {
- return 0;
- }
-
- return output->edid();
-}
-
-bool XRandR::isValid() const
-{
- return m_isValid;
-}
-
-void XRandR::updateConfig(Config *config) const
-{
- Q_ASSERT(config != 0);
-
- s_internalConfig->updateKScreenConfig(config);
-}
-
-quint8* XRandR::getXProperty(Display *dpy, RROutput output, Atom atom, size_t &len)
-{
- unsigned char *prop = 0;
- int actual_format;
- unsigned long nitems, bytes_after;
- Atom actual_type;
- quint8 *result;
-
- XRRGetOutputProperty(dpy, output, atom,
- 0, 100, false, false,
- AnyPropertyType,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &prop);
-
- if (actual_type == XA_INTEGER && actual_format == 8) {
- result = new quint8[nitems];
- memcpy(result, prop, nitems);
- len = nitems;
- } else {
- result = NULL;
- }
-
- XFree (prop);
- return result;
-}
-
-quint8 *XRandR::outputEdid(int outputId, size_t &len)
-{
- Atom edid_atom;
- quint8 *result;
-
- edid_atom = XInternAtom(QX11Info::display(), RR_PROPERTY_RANDR_EDID, false);
- result = XRandR::getXProperty(QX11Info::display(), outputId, edid_atom, len);
- if (result == NULL) {
- edid_atom = XInternAtom(QX11Info::display(), "EDID_DATA", false);
- result = XRandR::getXProperty(QX11Info::display(), outputId, edid_atom, len);
- }
-
- if (result == NULL) {
- edid_atom = XInternAtom(QX11Info::display(), "XFree86_DDC_EDID1_RAWDATA", false);
- result = XRandR::getXProperty(QX11Info::display(), outputId, edid_atom, len);
- }
-
- if (result) {
- if (len % 128 == 0) {
- return result;
- } else {
- len = 0;
- delete[] result;
- }
- }
-
- return 0;
-}
-
-RRCrtc XRandR::outputCrtc(int outputId)
-{
- RRCrtc crtcId;
- XRROutputInfo* outputInfo = XRROutput(outputId);
- kDebug(dXndr()) << "Output" << outputId << "has CRTC" << outputInfo->crtc;
-
- crtcId = outputInfo->crtc;
- XRRFreeOutputInfo(outputInfo);
-
- return crtcId;
-}
-
-RRCrtc XRandR::freeCrtc(int outputId)
-{
- XRROutputInfo* outputInfo = XRROutput(outputId);
-
- XRRCrtcInfo *crtc;
- for (int i = 0; i < outputInfo->ncrtc; ++i)
- {
- RRCrtc crtcId = outputInfo->crtcs[i];
- crtc = XRRCrtc(crtcId);
- if (!crtc->noutput) {
- kDebug(dXndr()) << "Found free CRTC" << crtcId;
- XRRFreeCrtcInfo(crtc);
- return crtcId;
- }
- XRRFreeCrtcInfo(crtc);
- }
-
- kDebug(dXndr()) << "No free CRTC found!";
- return 0;
-}
-
-XRRScreenResources* XRandR::screenResources()
-{
- XRRScreenResources *resources;
-
- if (XRandR::s_has_1_3) {
- if (XRandR::s_xorgCacheInitialized) {
- resources = XRRGetScreenResourcesCurrent(s_display, s_rootWindow);
- } else {
- /* XRRGetScreenResourcesCurrent is faster then XRRGetScreenResources
- * because it returns cached values. However the cached values are not
- * available until someone calls XRRGetScreenResources first. In case
- * we happen to be the first ones, we need to fill the cache first. */
- resources = XRRGetScreenResources(s_display, s_rootWindow);
- XRandR::s_xorgCacheInitialized = true;
- }
- } else {
- resources = XRRGetScreenResources(s_display, s_rootWindow);
- }
-
- return resources;
-}
-
-XRROutputInfo* XRandR::XRROutput(int outputId)
-{
- XRRScreenResources *resources = screenResources();
- XRROutputInfo *info = XRRGetOutputInfo(s_display, resources, outputId);
- XRRFreeScreenResources(resources);
-
- return info;
-}
-
-XRRCrtcInfo* XRandR::XRRCrtc(int crtcId)
-{
- XRRScreenResources *resources = screenResources();
- XRRCrtcInfo *info = XRRGetCrtcInfo(s_display, resources, crtcId);
- XRRFreeScreenResources(resources);
-
- return info;
-
-}
-
-Display *XRandR::display()
-{
- return s_display;
-}
-
-Window XRandR::rootWindow()
-{
- return s_rootWindow;
-}
-
-int XRandR::screen()
-{
- return s_screen;
-}
-
-extern int dXndr() { static int s_area = KDebug::registerArea("KSRandr", false); return s_area; }
-
-#include "moc_xrandr.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * Copyright (C) 2012, 2013 by Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef XRANDR_BACKEND_H
-#define XRANDR_BACKEND_H
-
-#include "xlibandxrandr.h"
-#include "../abstractbackend.h"
-
-#include <QtCore/QSize>
-
-class XRandRX11Helper;
-class XRandRConfig;
-namespace KScreen {
- class Output;
-}
-
-class XRandR : public QObject, public AbstractBackend
-{
- Q_OBJECT
- Q_INTERFACES(AbstractBackend)
-
- public:
- explicit XRandR(QObject* parent = 0);
- virtual ~XRandR();
-
- virtual QString name() const;
- virtual KScreen::Config* config() const;
- virtual void setConfig(KScreen::Config* config) const;
- virtual bool isValid() const;
- virtual KScreen::Edid *edid(int outputId) const;
- virtual void updateConfig(KScreen::Config *config) const;
-
- static RRCrtc outputCrtc(int outputId);
- static quint8 *outputEdid(int outputId, size_t &len);
- static RRCrtc freeCrtc(int outputId);
- static XRRScreenResources* screenResources();
- static XRROutputInfo* XRROutput(int outputId);
- static XRRCrtcInfo* XRRCrtc(int crtcId);
- static Display* display();
- static int screen();
- static Window rootWindow();
-
- private Q_SLOTS:
- void updateConfig();
- void outputRemovedSlot();
-
- void updateOutput(RROutput output);
- void updateCrtc(RRCrtc crtc);
-
- private:
- static quint8* getXProperty(Display *dpy, RROutput output, Atom atom, size_t &len);
-
- static Display* s_display;
- static int s_screen;
- static Window s_rootWindow;
- static XRandRConfig *s_internalConfig;
- static int s_randrBase;
- static int s_randrError;
- static bool s_monitorInitialized;
- static bool s_has_1_3;
- static bool s_xorgCacheInitialized;
-
- XRandRX11Helper *m_x11Helper;
- bool m_isValid;
-};
-
-extern int dXndr();
-#endif //XRandR_BACKEND_H
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * Copyright (C) 2012, 2013 by Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "xrandrconfig.h"
-#include "xrandrscreen.h"
-#include "xrandr.h"
-#include "xrandrmode.h"
-#include "xrandroutput.h"
-#include "config.h"
-#include "output.h"
-#include "edid.h"
-
-#include <QX11Info>
-#include <QRect>
-
-#include <kdebug.h>
-
-#include "libkscreen-config.h"
-
-using namespace KScreen;
-
-XRandRConfig::XRandRConfig()
- : QObject()
- , m_primaryOutput(-1)
- , m_screen(new XRandRScreen(this))
-{
- XRRScreenResources* resources = XRandR::screenResources();
-
- RROutput id, primary;
- primary = XRRGetOutputPrimary(XRandR::display(), XRandR::rootWindow());
-
- XRandROutput::Map outputs;
- for (int i = 0; i < resources->noutput; ++i)
- {
- id = resources->outputs[i];
-
- XRandROutput *output = createNewOutput(id, (id == primary));
- m_outputs.insert(id, output);
- if (id == primary) {
- m_primaryOutput = output->id();
- }
- }
-
- XRRFreeScreenResources(resources);
-}
-
-XRandRConfig::~XRandRConfig()
-{
-}
-
-void XRandRConfig::update()
-{
- m_screen->update();
-
- RROutput primary = XRRGetOutputPrimary(XRandR::display(), XRandR::rootWindow());
-
- m_primaryOutput = -1;
- XRandROutput::Map::Iterator iter;
- for (iter = m_outputs.begin(); iter != m_outputs.end(); ++iter) {
- XRandROutput *output = iter.value();
- output->update((iter.key() == (int) primary) ? XRandROutput::SetPrimary : XRandROutput::UnsetPrimary);
- if (iter.key() == (int) primary) {
- m_primaryOutput = output->id();
- }
- }
-}
-
-XRandROutput::Map XRandRConfig::outputs() const
-{
- return m_outputs;
-}
-
-void XRandRConfig::addNewOutput(const RROutput id)
-{
- RROutput primary;
- primary = XRRGetOutputPrimary(XRandR::display(), XRandR::rootWindow());
- XRandROutput *output = createNewOutput(id, (id == primary));
- m_outputs.insert(id, output);
- if (id == primary) {
- m_primaryOutput = id;
- }
-}
-
-XRandROutput* XRandRConfig::createNewOutput(RROutput id, bool primary)
-{
- XRandROutput *xOutput = new XRandROutput(id, primary, this);
- connect(xOutput, SIGNAL(outputRemoved(int)), SLOT(outputRemovedSlot(int)));
-
- return xOutput;
-}
-
-void XRandRConfig::outputRemovedSlot(int id)
-{
- m_outputs.remove(id);
- Q_EMIT outputRemoved(id);
-}
-
-KScreen::Config *XRandRConfig::toKScreenConfig() const
-{
- KScreen::Config *config = new KScreen::Config();
- KScreen::OutputList kscreenOutputs;
-
- XRandROutput::Map::ConstIterator iter;
- for (iter = m_outputs.constBegin(); iter != m_outputs.constEnd(); ++iter) {
- XRandROutput *output = iter.value();
- //FIXME XRandR backend should keep updated itself
- output->update(XRandROutput::NoChange);
- KScreen::Output *kscreenOutput = output->toKScreenOutput(config);
- kscreenOutputs.insert(kscreenOutput->id(), kscreenOutput);
- }
-
- config->setOutputs(kscreenOutputs);
- config->setScreen(m_screen->toKScreenScreen(config));
- if (m_primaryOutput != -1 && (!config->primaryOutput() || config->primaryOutput()->id() != m_primaryOutput)) {
- config->setPrimaryOutput(kscreenOutputs.value(m_primaryOutput));
- }
-
- return config;
-}
-
-void XRandRConfig::updateKScreenConfig(Config *config) const
-{
- KScreen::Screen *kscreenScreen = config->screen();
- m_screen->updateKScreenScreen(kscreenScreen);
-
- //Removing removed outputs
- KScreen::OutputList outputs = config->outputs();
- Q_FOREACH(KScreen::Output *output, outputs) {
- if (!m_outputs.contains(output->id())) {
- config->removeOutput(output->id());
- }
- }
-
- XRandROutput::Map::ConstIterator iter;
- for (iter = m_outputs.constBegin(); iter != m_outputs.constEnd(); ++iter) {
- XRandROutput *output = iter.value();
- KScreen::Output *kscreenOutput = config->output(output->id());
-
- if (!kscreenOutput) {
- config->addOutput(output->toKScreenOutput(config));
- continue;
- }
- output->updateKScreenOutput(kscreenOutput);
- }
-
- if (!config->primaryOutput() || config->primaryOutput()->id() != m_primaryOutput) {
- config->setPrimaryOutput(config->output(m_primaryOutput));
- }
-}
-
-void XRandRConfig::applyKScreenConfig(KScreen::Config *config)
-{
- KDebug::Block apply("Applying KScreen Config", dXndr());
- KScreen::OutputList outputs = config->outputs();
- QSize newSize = screenSize(config);
-
- int neededCrtc = 0;
- int primaryOutput = 0;
- KScreen::OutputList toDisable, toEnable, toChange;
- QHash<int, int> currentCrtc;
- Q_FOREACH(KScreen::Output *output, outputs) {
- XRandROutput *currentOutput = m_outputs.value(output->id());
- currentOutput->update(currentOutput->isPrimary() ? XRandROutput::SetPrimary : XRandROutput::UnsetPrimary);
-
- //Only set the output as primary if it is enabled.
- if (output->isPrimary() && output->isEnabled()) {
- primaryOutput = currentOutput->id();
- }
-
- bool currentEnabled = currentOutput->isEnabled();
- if (!output->isEnabled() && currentEnabled) {
- toDisable.insert(output->id(), output);
- continue;
- } else if (output->isEnabled() && !currentEnabled) {
- toEnable.insert(output->id(), output);
- neededCrtc ++;
- continue;
- } else if (!output->isEnabled() && !currentEnabled) {
- continue;
- }
-
- neededCrtc ++;
-
- if (output->currentModeId() != currentOutput->currentModeId()) {
- if (!toChange.contains(output->id())) {
- currentCrtc.insert(output->id(), XRandR::outputCrtc(output->id()));
- toChange.insert(output->id(), output);
- }
- }
-
- if (output->pos() != currentOutput->position()) {
- if (!toChange.contains(output->id())) {
- currentCrtc.insert(output->id(), XRandR::outputCrtc(output->id()));
- toChange.insert(output->id(), output);
- }
- }
-
- if (output->rotation() != currentOutput->rotation()) {
- if( !toChange.contains(output->id())) {
- currentCrtc.insert(output->id(), XRandR::outputCrtc(output->id()));
- toChange.insert(output->id(), output);
- }
- }
-
- XRandRMode* currentMode = currentOutput->currentMode();
-
- // For some reason, in some environments currentMode is null
- // which doesn't make sense because it is the *current* mode...
- // Since we haven't been able to figure out the reason why
- // this happens, we are adding this debug code to try to
- // figure out how this happened.
- if (!currentMode) {
- kWarning() << "Current mode is null:"
- << "ModeId:" << currentOutput->currentModeId()
- << "Mode: " << currentOutput->currentMode()
- << "Output: " << currentOutput->id();
- kDebug() << kBacktrace(256);
- printConfig(config);
- printInternalCond();
- return;
- }
-
- const QSize size = currentMode->size();
- int x, y;
-
- //TODO: Move this code within libkscreen
- y = currentOutput->position().y();
- if (currentOutput->isHorizontal()) {
- y += size.height();
- } else {
- y += size.width();
- }
-
- x = currentOutput->position().x();
- if (currentOutput->isHorizontal()) {
- x += size.width();
- } else {
- x += size.height();
- }
-
- if (x > newSize.width() || y > newSize.height()) {
- if (!toDisable.contains(output->id())) {
- kDebug(dXndr()) << "Output doesn't fit: " << x << "x" << y << newSize;
- toDisable.insert(output->id(), output);
- }
- }
- }//Q_FOREACH(KScreen::Output *output, outputs)
-
- KScreen::Screen* screen = config->screen();
- if (newSize.width() > screen->maxSize().width() ||
- newSize.height() > screen->maxSize().height()) {
- kDebug(dXndr()) << "The new size is too big: " << newSize << " - " << screen->maxSize();
- return;//Too big
- }
-
- kDebug(dXndr()) << neededCrtc;
- XRRScreenResources *screenResources = XRandR::screenResources();
- if (neededCrtc > screenResources->ncrtc) {
- kDebug(dXndr()) << "We need more crtc than we have: " << neededCrtc << " - " << screenResources->ncrtc;
- XRRFreeScreenResources(screenResources);
- return;//We don't have enough crtc
- }
- XRRFreeScreenResources(screenResources);
-
- kDebug(dXndr()) << "Actions to perform: ";
- kDebug(dXndr()) << "\t Primary Output: " << primaryOutput;
- kDebug(dXndr()) << "\t Screen Size: " << (newSize != m_screen->currentSize());
- if (newSize != m_screen->currentSize()) {
- kDebug(dXndr()) << "\t Old: " << m_screen->currentSize();
- kDebug(dXndr()) << "\t New: " << newSize;
- }
- kDebug(dXndr()) << "\t Disable outputs: " << !toDisable.isEmpty();
- if (!toDisable.isEmpty()) {
- kDebug(dXndr()) << "\t\t" << toDisable.keys();
- }
- kDebug(dXndr()) << "\t Change outputs: " << !toChange.isEmpty();
- if (!toChange.isEmpty()) {
- kDebug(dXndr()) << "\t\t" << toChange.keys();
- }
- kDebug(dXndr()) << "\t Enable outputs: " << !toEnable.isEmpty();
- if (!toEnable.isEmpty()) {
- kDebug(dXndr()) << "\t\t" << toEnable.keys();
- }
-
- setPrimaryOutput(primaryOutput);
-
- //If there is nothing to do, not even bother
- if (toDisable.isEmpty() && toEnable.isEmpty() && toChange.isEmpty()) {
- if (newSize != m_screen->currentSize()) {
- setScreenSize(newSize);
- }
- return;
- }
-
- Q_FOREACH(KScreen::Output* output, toDisable) {
- disableOutput(output);
- }
-
- if (newSize != m_screen->currentSize()) {
- setScreenSize(newSize);
- }
-
- bool forceScreenSizeUpdate = false;
- Q_FOREACH(KScreen::Output* output, toChange) {
- if (!changeOutput(output, currentCrtc[output->id()])) {
-
- /* If we disabled the output before changing it and XRandR failed
- * to re-enable it, then update screen size too */
- if (toDisable.contains(output->id())) {
- output->setEnabled(false);
- kDebug() << "Output failed to change: " << output->name();
- forceScreenSizeUpdate = true;
- }
- }
- }
-
- Q_FOREACH(KScreen::Output* output, toEnable) {
- if (!enableOutput(output)) {
- output->setEnabled(false);
- kDebug() << "Output failed to be Enabled: " << output->name();
- forceScreenSizeUpdate = true;
- }
- }
-
-
- if (forceScreenSizeUpdate) {
- newSize = screenSize(config);
- kDebug() << "forced to change screen Size: " << newSize;
- setScreenSize(newSize);
- }
-}
-
-void XRandRConfig::printConfig(Config* config) const
-{
- kDebug() << "KScreen version:" << LIBKSCREEN_VERSION;
-
- if (!config) {
- kDebug() << "Config is invalid";
- return;
- }
- if (!config->screen()) {
- kDebug() << "No screen in the configuration, broken backend";
- return;
- }
-
- kDebug() << "Screen:";
- kDebug() << "\tmaxSize:" << config->screen()->maxSize();
- kDebug() << "\tminSize:" << config->screen()->minSize();
- kDebug() << "\tcurrentSize:" << config->screen()->currentSize();
-
- OutputList outputs = config->outputs();
- Q_FOREACH(Output *output, outputs) {
- kDebug() << "\n-----------------------------------------------------\n";
- kDebug() << "Id: " << output->id();
- kDebug() << "Name: " << output->name();
- kDebug() << "Type: " << output->type();
- kDebug() << "Connected: " << output->isConnected();
- if (!output->isConnected()) {
- continue;
- }
- kDebug() << "Enabled: " << output->isEnabled();
- kDebug() << "Primary: " << output->isPrimary();
- kDebug() << "Rotation: " << output->rotation();
- kDebug() << "Pos: " << output->pos();
- kDebug() << "MMSize: " << output->sizeMm();
- if (output->currentMode()) {
- kDebug() << "Size: " << output->currentMode()->size();
- }
- if (output->clones().isEmpty()) {
- kDebug() << "Clones: " << "None";
- } else {
- kDebug() << "Clones: " << output->clones().count();
- }
- kDebug() << "Mode: " << output->currentModeId();
- kDebug() << "Preferred Mode: " << output->preferredModeId();
- kDebug() << "Preferred modes: " << output->preferredModes();
- kDebug() << "Modes: ";
-
- ModeList modes = output->modes();
- Q_FOREACH(Mode* mode, modes) {
- kDebug() << "\t" << mode->id() << " " << mode->name() << " " << mode->size() << " " << mode->refreshRate();
- }
-
- Edid* edid = output->edid();
- kDebug() << "EDID Info: ";
- if (edid && edid->isValid()) {
- kDebug() << "\tDevice ID: " << edid->deviceId();
- kDebug() << "\tName: " << edid->name();
- kDebug() << "\tVendor: " << edid->vendor();
- kDebug() << "\tSerial: " << edid->serial();
- kDebug() << "\tEISA ID: " << edid->eisaId();
- kDebug() << "\tHash: " << edid->hash();
- kDebug() << "\tWidth: " << edid->width();
- kDebug() << "\tHeight: " << edid->height();
- kDebug() << "\tGamma: " << edid->gamma();
- kDebug() << "\tRed: " << edid->red();
- kDebug() << "\tGreen: " << edid->green();
- kDebug() << "\tBlue: " << edid->blue();
- kDebug() << "\tWhite: " << edid->white();
- } else {
- kDebug() << "\tUnavailable";
- }
- }
-}
-
-void XRandRConfig::printInternalCond() const
-{
- kDebug() << "Internal config in xrandr";
- Q_FOREACH(XRandROutput *output, m_outputs) {
- kDebug() << "Id: " << output->id();
- kDebug() << "Current Mode: " << output->currentMode();
- kDebug() << "Current mode id: " << output->currentModeId();
- kDebug() << "Connected: " << output->isConnected();
- kDebug() << "Enabled: " << output->isEnabled();
- kDebug() << "Primary: " << output->isPrimary();
- if (!output->isEnabled()) {
- continue;
- }
- XRandRMode::Map modes = output->modes();
- Q_FOREACH(XRandRMode *mode, modes) {
- kDebug() << "\t" << mode->id();
- kDebug() << "\t" << mode->name();
- kDebug() << "\t" << mode->size() << mode->refreshRate();
- }
- }
-}
-
-QSize XRandRConfig::screenSize(KScreen::Config* config) const
-{
- KDebug::Block screenBlock("Calculating screen size", dXndr());
- QRect rect;
- QSize outputSize;
- Q_FOREACH(const KScreen::Output* output, config->outputs()) {
- if (!output->isEnabled() || !output->isConnected()) {
- kDebug(dXndr()) << "Disabled/Disconnected output: " << output->name();
- continue;
- }
-
- Mode *currentMode = output->currentMode();
- if (!currentMode) {
- kDebug(dXndr()) << "Output: " << output->name() << " has no current Mode";
- continue;
- }
-
- QSize outputSize = currentMode->size();
-
- kDebug(dXndr()) << "Output: " << output->name() << " Size: " << outputSize << " Pos: " << output->pos();
- if (output->pos().x() < rect.x()) {
- rect.setX(output->pos().x());
- }
-
- if (output->pos().y() < rect.y()) {
- rect.setY(output->pos().y());
- }
-
- QPoint bottomRight;
- if (output->isHorizontal()) {
- bottomRight = QPoint(output->pos().x() + outputSize.width(),
- output->pos().y() + outputSize.height());
- } else {
- bottomRight = QPoint(output->pos().x() + outputSize.height(),
- output->pos().y() + outputSize.width());
- }
-
- if (bottomRight.x() > rect.width()) {
- rect.setWidth(bottomRight.x());
- }
-
- if (bottomRight.y() > rect.height()) {
- rect.setHeight(bottomRight.y());
- }
-
- }
-
- QSize size = QSize(rect.width(), rect.height());
- kDebug(dXndr()) << "Requested screen size is" << size;
- return size;
-}
-
-bool XRandRConfig::setScreenSize(const QSize& size) const
-{
- KDebug::Block setBlock("Setting screen size", dXndr());
- double dpi;
- int widthMM, heightMM;
- dpi = (25.4 * DisplayHeight(XRandR::display(), XRandR::screen())) / DisplayHeightMM(XRandR::display(), XRandR::screen());
-
- kDebug(dXndr()) << "DPI: " << dpi;
- kDebug(dXndr()) << "Size: " << size;
-
- widthMM = ((25.4 * size.width()) / dpi);
- heightMM = ((25.4 * size.height()) / dpi);
-
- kDebug(dXndr()) << size << " " << widthMM << "x" << heightMM;
- XRRSetScreenSize(XRandR::display(), XRandR::rootWindow(),
- size.width(), size.height(), widthMM, heightMM);
-
- return true;
-}
-
-void XRandRConfig::setPrimaryOutput(int outputId) const
-{
- XRRSetOutputPrimary(XRandR::display(), XRandR::rootWindow(), outputId);
-}
-
-bool XRandRConfig::disableOutput(Output* output) const
-{
- KDebug::Block disablock("Disable output", dXndr());
- int crtcId = XRandR::outputCrtc(output->id());
- kDebug(dXndr()) << "Disabling: " << output->id() << "(CRTC" << crtcId << ")";
- Status s = XRRSetCrtcConfig (XRandR::display(), XRandR::screenResources(), crtcId, CurrentTime,
- 0, 0, None, RR_Rotate_0, NULL, 0);
-
- kDebug(dXndr()) << "XRRSetCrtcConfig() returned" << s;
-
- // Update the cached output now, otherwise we get RRNotify_CrtcChange notification
- // for an outdated output, which can lead to a crash.
- if (s == RRSetConfigSuccess) {
- m_outputs.value(output->id())->update();
- }
- return (s == RRSetConfigSuccess);
-}
-
-bool XRandRConfig::enableOutput(Output* output) const
-{
- KDebug::Block disablock("Enable output", dXndr());
- kDebug(dXndr()) << "Enabling: " << output->id();
- RROutput *outputs = new RROutput[1];
- outputs[0] = output->id();
- Status s = XRRSetCrtcConfig(XRandR::display(), XRandR::screenResources(), XRandR::freeCrtc(output->id()),
- CurrentTime, output->pos().rx(), output->pos().ry(), output->currentModeId().toInt(),
- output->rotation(), outputs, 1);
-
- kDebug(dXndr()) << "XRRSetCrtcConfig() returned" << s;
- return (s == RRSetConfigSuccess);
-}
-
-bool XRandRConfig::changeOutput(Output* output, int crtcId) const
-{
- KDebug::Block disablock("Change output", dXndr());
- kDebug(dXndr()) << "Updating: " << output->id() << "with CRTC" << crtcId;
-
- RROutput *outputs = new RROutput[1];
- outputs[0] = output->id();
- Status s = XRRSetCrtcConfig(XRandR::display(), XRandR::screenResources(), crtcId,
- CurrentTime, output->pos().rx(), output->pos().ry(), output->currentModeId().toInt(),
- output->rotation(), outputs, 1);
-
- kDebug(dXndr()) << "XRRSetCrtcConfig() returned" << s;
- return (s == RRSetConfigSuccess);
-}
-
-#include "moc_xrandrconfig.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright 2012, 2013 Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef XRANDRCONFIG_H
-#define XRANDRCONFIG_H
-
-#include <QObject>
-
-#include "xrandr.h"
-#include "xrandroutput.h"
-
-class XRandRScreen;
-namespace KScreen {
-class Config;
-}
-
-class XRandRConfig : public QObject
-{
- Q_OBJECT
-
-public:
- explicit XRandRConfig();
- virtual ~XRandRConfig();
-
- void update();
-
- XRandROutput::Map outputs() const;
- void addNewOutput(const RROutput id);
-
- KScreen::Config *toKScreenConfig() const;
- void updateKScreenConfig(KScreen::Config *config) const;
- void applyKScreenConfig(KScreen::Config *config);
-
- int m_primaryOutput;
-private:
- /**
- * We need to print stuff to discover the damn bug
- * where currentMode is null
- */
- void printConfig(KScreen::Config* config) const;
- void printInternalCond() const;
- QSize screenSize(KScreen::Config* config) const;
- bool setScreenSize(const QSize& size) const;
- void setPrimaryOutput(int outputId) const;
- bool disableOutput(KScreen::Output* output) const;
- bool enableOutput(KScreen::Output* output) const;
- bool changeOutput(KScreen::Output* output, int crtcId) const;
- XRandROutput* createNewOutput(RROutput id, bool primary);
- XRandROutput::Map m_outputs;
- XRandRScreen *m_screen;
-
-Q_SIGNALS:
- void outputRemoved(int id);
-
-private Q_SLOTS:
- void outputRemovedSlot(int id);
-};
-
-#endif // XRANDRCONFIG_H
+++ /dev/null
-/*************************************************************************************
- * Copyright 2012, 2013 Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "xrandrmode.h"
-#include "xrandroutput.h"
-#include "mode.h"
-#include "output.h"
-
-XRandRMode::XRandRMode(XRRModeInfo *modeInfo, XRandROutput *output)
- : QObject(output)
-{
- m_id = modeInfo->id;
- m_name = QString::fromUtf8(modeInfo->name);
- m_size = QSize(modeInfo->width, modeInfo->height);
- m_refreshRate = ((float) modeInfo->dotClock / ((float) modeInfo->hTotal * (float) modeInfo->vTotal));
-}
-
-
-XRandRMode::~XRandRMode()
-{
-}
-
-KScreen::Mode *XRandRMode::toKScreenMode(KScreen::Output *parent)
-{
- KScreen::Mode *kscreenMode = new KScreen::Mode(parent);
-
- kscreenMode->setId(QString::number(m_id));
- kscreenMode->setName(m_name);
- kscreenMode->setSize(m_size);
- kscreenMode->setRefreshRate(m_refreshRate);
-
- return kscreenMode;
-}
-
-int XRandRMode::id() const
-{
- return m_id;
-}
-
-QSize XRandRMode::size() const
-{
- return m_size;
-}
-
-float XRandRMode::refreshRate() const
-{
- return m_refreshRate;
-}
-
-QString XRandRMode::name() const
-{
- return m_name;
-}
-
-#include "moc_xrandrmode.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright 2012, 2013 Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef XRANDRMODE_H
-#define XRANDRMODE_H
-
-#include <QObject>
-#include <QMap>
-#include <QVariant>
-#include <QSize>
-
-#include "xlibandxrandr.h"
-
-class XRandROutput;
-namespace KScreen
-{
-class Output;
-class Mode;
-}
-
-class XRandRMode : public QObject
-{
- Q_OBJECT
-
-public:
- typedef QMap<int, XRandRMode*> Map;
-
- explicit XRandRMode(XRRModeInfo* modeInfo, XRandROutput *output);
- virtual ~XRandRMode();
-
- KScreen::Mode* toKScreenMode(KScreen::Output *parent);
-
- int id() const;
- QSize size() const;
- float refreshRate() const;
- QString name() const;
-
-private:
- int m_id;
- QString m_name;
- QSize m_size;
- float m_refreshRate;
-};
-
-Q_DECLARE_METATYPE(XRandRMode::Map)
-
-#endif // XRANDRMODE_H
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * Copyright (C) 2012, 2013 by Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "xrandroutput.h"
-#include "xrandrmode.h"
-#include "xrandrconfig.h"
-#include "xrandr.h"
-#include "output.h"
-#include "config.h"
-#include "edid.h"
-
-#include <QRect>
-
-#include <KDebug>
-
-Q_DECLARE_METATYPE(QList<int>)
-
-XRandROutput::XRandROutput(int id, bool primary, XRandRConfig *config)
- : QObject(config)
- , m_id(id)
- , m_type(KScreen::Output::Unknown)
- , m_rotation(KScreen::Output::None)
- , m_connected(0)
- , m_enabled(0)
- , m_primary(0)
- , m_edid(0)
- , m_changedProperties(0)
-{
- XRROutputInfo *outputInfo = XRandR::XRROutput(m_id);
- updateOutput(outputInfo);
- updateModes(outputInfo);
- fetchType();
- m_primary = primary;
- m_widthMm = outputInfo->mm_width;
- m_heightMm = outputInfo->mm_height;
-
- XRRFreeOutputInfo(outputInfo);
-}
-
-
-XRandROutput::~XRandROutput()
-{
- delete m_edid;
-}
-
-int XRandROutput::id() const
-{
- return m_id;
-}
-
-bool XRandROutput::isConnected() const
-{
- return m_connected;
-}
-
-bool XRandROutput::isEnabled() const
-{
- return m_enabled;
-}
-
-bool XRandROutput::isPrimary() const
-{
- return m_primary;
-}
-
-QPoint XRandROutput::position() const
-{
- return m_position;
-}
-
-XRandRMode::Map XRandROutput::modes() const
-{
- return m_modes;
-}
-
-QString XRandROutput::currentModeId() const
-{
- return m_currentMode;
-}
-
-XRandRMode* XRandROutput::currentMode() const
-{
- int modeId = m_currentMode.toInt();
- if (!m_modes.contains(modeId)) {
- return 0;
- }
-
- return m_modes[modeId];
-}
-
-KScreen::Output::Rotation XRandROutput::rotation() const
-{
- return m_rotation;
-}
-
-KScreen::Edid *XRandROutput::edid() const
-{
- if (!m_edid) {
- size_t len;
- quint8 *data = XRandR::outputEdid(m_id, len);
- if (data) {
- m_edid = new KScreen::Edid(data, len, 0);
- delete[] data;
- } else {
- m_edid = new KScreen::Edid(0, 0, 0);
- }
- }
-
- return m_edid;
-}
-
-void XRandROutput::update(PrimaryChange primary)
-{
- XRROutputInfo *outputInfo = XRandR::XRROutput(m_id);
- if (!outputInfo) {
- Q_EMIT outputRemoved(m_id);
- deleteLater();
- return;
- }
-
- m_changedProperties = 0;
- updateOutput(outputInfo);
-
- if (primary != NoChange) {
- bool setPrimary = (primary == SetPrimary);
- if (m_primary != setPrimary) {
- m_primary = setPrimary;
- m_changedProperties |= PropertyPrimary;
- }
- }
-
- if (m_changedProperties == 0) {
- m_changedProperties = PropertyNone;
- }
-
- XRRFreeOutputInfo(outputInfo);
-}
-
-void XRandROutput::updateOutput(const XRROutputInfo *outputInfo)
-{
- bool isConnected = (outputInfo->connection == RR_Connected);
-
- if (m_name != outputInfo->name) {
- m_name = outputInfo->name;
- m_changedProperties |= PropertyName;
- }
-
- if (m_enabled != (outputInfo->crtc != None)) {
- m_enabled = outputInfo->crtc != None;
- m_changedProperties |= PropertyEnabled;
- }
-
- QList<int> clones;
- for (int i = 0; i < outputInfo->nclone; i++) {
- clones << outputInfo->clones[i];
- }
- if (isConnected && (m_clones != clones)) {
- m_clones = clones;
- m_changedProperties |= PropertyClones;
- }
-
- /* Don't update modes on disconnected output */
- if (isConnected && (outputInfo->crtc)) {
- XRRCrtcInfo* crtcInfo = XRandR::XRRCrtc(outputInfo->crtc);
- QRect rect;
- rect.setRect(crtcInfo->x, crtcInfo->y, crtcInfo->width, crtcInfo->height);
- if (m_position != rect.topLeft()) {
- m_position = rect.topLeft();
- m_changedProperties |= PropertyPos;
- }
-
- if (crtcInfo->mode) {
- if (m_currentMode != QString::number(crtcInfo->mode)) {
- m_currentMode = QString::number(crtcInfo->mode);
- m_changedProperties |= PropertyCurrentMode;
- }
-
- if (m_rotation != crtcInfo->rotation) {
- m_rotation = (KScreen::Output::Rotation) crtcInfo->rotation;
- m_changedProperties |= PropertyRotation;
- }
- }
- XRRFreeCrtcInfo(crtcInfo);
- }
-
- /* When an output is disconnected then force reset most properties */
- if (m_connected != isConnected) {
- m_connected = isConnected;
- if (!m_connected) {
- m_preferredModes.clear();
- qDeleteAll(m_modes);
- m_modes.clear();
- delete m_edid;
- m_changedProperties |= PropertyConnected | PropertyModes | PropertyEdid | PropertyPreferredMode;
- } else {
- updateModes(outputInfo);
- m_changedProperties |= PropertyConnected | PropertyModes | PropertyPreferredMode;
- }
- }
-}
-
-void XRandROutput::updateModes(const XRROutputInfo *outputInfo)
-{
- /* Init modes */
- XRRModeInfo* modeInfo;
- XRRScreenResources *resources = XRandR::screenResources();
-
- m_preferredModes.clear();
- qDeleteAll(m_modes);
- m_modes.clear();
- for (int i = 0; i < outputInfo->nmode; ++i)
- {
- /* Resources->modes contains all possible modes, we are only interested
- * in those listed in outputInfo->modes. */
- for (int j = 0; j < resources->nmode; ++j) {
- modeInfo = &resources->modes[j];
- if (modeInfo->id != outputInfo->modes[i]) {
- continue;
- }
-
- XRandRMode *mode = new XRandRMode(modeInfo, this);
- m_modes.insert(modeInfo->id, mode);
-
- if (i < outputInfo->npreferred) {
- m_preferredModes.append(QString::number(modeInfo->id));
- }
- }
- }
- XRRFreeScreenResources(resources);
-}
-
-void XRandROutput::fetchType()
-{
- QByteArray type = typeFromProperty();
- if (type.isEmpty()) {
- m_type = typeFromName();
- return;
- }
-
- if (type.contains("VGA")) {
- m_type = KScreen::Output::VGA;
- } else if (type.contains("DVI")) {
- m_type = KScreen::Output::DVI;
- } else if (type.contains("DVI-I")) {
- m_type = KScreen::Output::DVII;
- } else if (type.contains("DVI-A")) {
- m_type = KScreen::Output::DVIA;
- } else if (type.contains("DVI-D")) {
- m_type = KScreen::Output::DVID;
- } else if (type.contains("HDMI")) {
- m_type = KScreen::Output::HDMI;
- } else if (type.contains("Panel")) {
- m_type = KScreen::Output::Panel;
- } else if (type.contains("TV")) {
- m_type = KScreen::Output::TV;
- } else if (type.contains("TV-Composite")) {
- m_type = KScreen::Output::TVComposite;
- } else if (type.contains("TV-SVideo")) {
- m_type = KScreen::Output::TVSVideo;
- } else if (type.contains("TV-Component")) {
- m_type = KScreen::Output::TVComponent;
- } else if (type.contains("TV-SCART")) {
- m_type = KScreen::Output::TVSCART;
- } else if (type.contains("TV-C4")) {
- m_type = KScreen::Output::TVC4;
- } else if (type.contains("DisplayPort")) {
- m_type = KScreen::Output::DisplayPort;
- } else if (type.contains("unknown")) {
- m_type = KScreen::Output::Unknown;
- } else {
-// kDebug() << "Output Type not translated:" << type;
- }
-
-}
-
-KScreen::Output::Type XRandROutput::typeFromName()
-{
- QStringList embedded;
- embedded << "LVDS";
- embedded << "IDP";
- embedded << "EDP";
- embedded << "LCD";
-
- Q_FOREACH(const QString &pre, embedded) {
- if (m_name.toUpper().startsWith(pre)) {
- return KScreen::Output::Panel;
- }
- }
-
- return KScreen::Output::Unknown;
-}
-
-QByteArray XRandROutput::typeFromProperty() const
-{
- QByteArray type;
-
- Atom atomType = XInternAtom (XRandR::display(), RR_PROPERTY_CONNECTOR_TYPE, True);
- if (atomType == None) {
- return type;
- }
-
- unsigned char *prop;
- int actualFormat;
- unsigned long nitems, bytes_after;
- Atom actualType;
- char *connectorType;
-
- if (XRRGetOutputProperty (XRandR::display(), m_id, atomType, 0, 100, False,
- False, AnyPropertyType, &actualType, &actualFormat, &nitems,
- &bytes_after, &prop) != Success) {
-
- return type;
- }
-
- if (!(actualType == XA_ATOM && actualFormat == 32 && nitems == 1)) {
- return type;
- }
-
- connectorType = XGetAtomName (XRandR::display(), *((Atom *) prop));
- if (!connectorType) {
- return type;
- }
-
- type = connectorType;
- XFree (connectorType);
-
-
- return type;
-}
-
-KScreen::Output *XRandROutput::toKScreenOutput(KScreen::Config *parent) const
-{
- KScreen::Output *kscreenOutput = new KScreen::Output(parent);
-
- m_changedProperties = 0;
- kscreenOutput->setId(m_id);
- kscreenOutput->setType(m_type);
- kscreenOutput->setSizeMm(QSize(m_widthMm, m_heightMm));
- updateKScreenOutput(kscreenOutput);
-
- return kscreenOutput;
-}
-
-void XRandROutput::updateKScreenOutput(KScreen::Output *output) const
-{
- if (!m_changedProperties || (m_changedProperties & PropertyName)) {
- output->setName(m_name);
- }
-
- if (!m_changedProperties || (m_changedProperties & PropertyIcon)) {
- output->setIcon(m_icon);
- }
-
- if (!m_changedProperties || (m_changedProperties & PropertyPos)) {
- output->setPos(m_position);
- }
-
- if (!m_changedProperties || (m_changedProperties & PropertyRotation)) {
- output->setRotation(m_rotation);
- }
-
- if (!m_changedProperties || (m_changedProperties & PropertyCurrentMode)) {
- output->setCurrentModeId(m_currentMode);
- }
-
- if (!m_changedProperties || (m_changedProperties & PropertyPreferredMode)) {
- output->setPreferredModes(m_preferredModes);
- }
-
- if (!m_changedProperties || (m_changedProperties & PropertyModes)) {
- output->setModes(KScreen::ModeList());
- }
-
- if (!m_changedProperties || (m_changedProperties & PropertyConnected)) {
- output->setConnected(m_connected);
- }
-
- if (!m_changedProperties || (m_changedProperties & PropertyEnabled)) {
- output->setEnabled(m_enabled);
- }
-
- if (!m_changedProperties || (m_changedProperties & PropertyPrimary)) {
- output->setPrimary(m_primary);
- }
-
- if (!m_changedProperties || (m_changedProperties & PropertyClones)) {
- output->setClones(m_clones);
- }
-
- if (!m_changedProperties || (m_changedProperties & PropertyModes)) {
- XRandRMode::Map::ConstIterator iter;
- KScreen::ModeList kscreenModes;
- for (iter = m_modes.constBegin(); iter != m_modes.constEnd(); ++iter) {
- XRandRMode *mode = iter.value();
- KScreen::Mode *kscreenMode = mode->toKScreenMode(output);
- kscreenModes.insert(QString::number(iter.key()), kscreenMode);
- }
- output->setModes(kscreenModes);
- }
-}
-
-#include "moc_xrandroutput.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright 2012, 2013 Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef XRANDROUTPUT_H
-#define XRANDROUTPUT_H
-
-#include <QObject>
-#include <QMap>
-#include <QVariant>
-#include <QPointer>
-
-#include "xlibandxrandr.h"
-#include "xrandrmode.h"
-#include "output.h"
-
-class XRandRConfig;
-namespace KScreen
-{
-class Config;
-class Output;
-class Edid;
-}
-
-class XRandROutput : public QObject
-{
- Q_OBJECT
- Q_FLAGS(Property Properties)
-
-public:
- typedef QMap<int, XRandROutput*> Map;
-
- enum Property {
- PropertyNone = 1 << 0,
- PropertyId = 1 << 1,
- PropertyName = 1 << 2,
- PropertyIcon = 1 << 3,
- PropertyModes = 1 << 4,
- PropertyPos = 1 << 5,
- PropertyRotation = 1 << 6,
- PropertyCurrentMode = 1 << 7,
- PropertyConnected = 1 << 8,
- PropertyEnabled = 1 << 9,
- PropertyPrimary = 1 << 10,
- PropertyClones = 1 << 11,
- PropertyEdid = 1 << 12,
- PropertyPreferredMode = 1 << 13
- };
-
- enum PrimaryChange {
- NoChange = 0,
- SetPrimary = 1,
- UnsetPrimary = 2,
- };
-
- Q_DECLARE_FLAGS(Properties, Property)
-
- explicit XRandROutput(int id, bool primary, XRandRConfig *config = 0);
- virtual ~XRandROutput();
-
- void update(PrimaryChange primary = NoChange);
-
- int id() const;
- bool isEnabled() const;
- bool isConnected() const;
- bool isPrimary() const;
- QPoint position() const;
- QString currentModeId() const;
- XRandRMode::Map modes() const;
- XRandRMode* currentMode() const;
- KScreen::Output::Rotation rotation() const;
- inline bool isHorizontal() const { return ((m_rotation == KScreen::Output::None) || (m_rotation == KScreen::Output::Inverted)); }
- KScreen::Edid* edid() const;
-
- KScreen::Output* toKScreenOutput(KScreen::Config *parent) const;
- void updateKScreenOutput(KScreen::Output *output) const;
-
- void updateModes(const XRROutputInfo *outputInfo);
- void addNewOutput(const RROutput output);
-
-Q_SIGNALS:
- void outputRemoved(int id);
-
-private:
- void updateOutput(const XRROutputInfo *outputInfo);
- void fetchType();
- KScreen::Output::Type typeFromName();
- QByteArray typeFromProperty() const;
-
- int m_id;
- QString m_name;
- KScreen::Output::Type m_type;
- QString m_icon;
- XRandRMode::Map m_modes;
- QPoint m_position;
- KScreen::Output::Rotation m_rotation;
- QString m_currentMode;
- QStringList m_preferredModes;
- bool m_connected;
- bool m_enabled;
- bool m_primary;
- QList<int> m_clones;
- mutable QPointer<KScreen::Edid> m_edid;
- unsigned int m_widthMm;
- unsigned int m_heightMm;
-
- mutable int m_changedProperties;
-};
-
-Q_DECLARE_METATYPE(XRandROutput::Map)
-
-#endif // XRANDROUTPUT_H
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * Copyright (C) 2012, 2013 by Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "xrandrscreen.h"
-#include "xrandrconfig.h"
-#include "xlibandxrandr.h"
-
-#include "screen.h"
-#include "config.h"
-#include <QX11Info>
-
-XRandRScreen::XRandRScreen(XRandRConfig *config)
- : QObject(config)
-{
- update();
-}
-
-XRandRScreen::~XRandRScreen()
-{
-}
-
-void XRandRScreen::update()
-{
- Display *display = QX11Info::display();
- int screen = DefaultScreen(display);
- Window rootWindow = XRootWindow(display, screen);
-
- XRRGetScreenSizeRange (display, rootWindow,
- &m_minSize.rwidth(), &m_minSize.rheight(),
- &m_maxSize.rwidth(), &m_maxSize.rheight());
- m_currentSize = QSize(DisplayWidth(display, screen),DisplayHeight(display, screen));
-}
-
-QSize XRandRScreen::currentSize()
-{
- update();
- return m_currentSize;
-}
-
-KScreen::Screen *XRandRScreen::toKScreenScreen(KScreen::Config *parent) const
-{
- KScreen::Screen *kscreenScreen = new KScreen::Screen(parent);
- kscreenScreen->setId(m_id);
- kscreenScreen->setMaxSize(m_maxSize);
- kscreenScreen->setMinSize(m_minSize);
- kscreenScreen->setCurrentSize(m_currentSize);
- kscreenScreen->setMaxActiveOutputsCount(XRandR::screenResources()->ncrtc);
-
- return kscreenScreen;
-}
-
-void XRandRScreen::updateKScreenScreen(KScreen::Screen *screen) const
-{
- screen->setCurrentSize(m_currentSize);
-}
-
-
-#include "moc_xrandrscreen.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright 2012, 2013 Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef XRANDRSCREEN_H
-#define XRANDRSCREEN_H
-
-#include <QObject>
-#include <QSize>
-
-class XRandRConfig;
-namespace KScreen
-{
-class Screen;
-class Config;
-}
-
-class XRandRScreen : public QObject
-{
- Q_OBJECT
-
-public:
- explicit XRandRScreen(XRandRConfig *config = 0);
- virtual ~XRandRScreen();
-
- KScreen::Screen *toKScreenScreen(KScreen::Config *parent) const;
- void updateKScreenScreen(KScreen::Screen *screen) const;
-
- void update();
- QSize currentSize();
-
-private:
- int m_id;
- QSize m_minSize;
- QSize m_maxSize;
- QSize m_currentSize;
-};
-
-#endif // XRANDRSCREEN_H
+++ /dev/null
-/*************************************************************************************
- * Copyright 2012, 2013 Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "xrandrx11helper.h"
-#include "xrandr.h"
-#include "xlibandxrandr.h"
-
-#include <QX11Info>
-
-#include <KSystemEventFilter>
-#include <kdebug.h>
-
-XRandRX11Helper::XRandRX11Helper():
- QWidget(),
- m_randrBase(0),
- m_randrError(0),
- m_versionMajor(0),
- m_versionMinor(0),
- m_window(0)
-{
- XRRQueryVersion (QX11Info::display(), &m_versionMajor, &m_versionMinor);
-
- kDebug(dXndr()).nospace() << "Detected XRandR " << m_versionMajor << "." << m_versionMinor;
-
- XRRQueryExtension(QX11Info::display(), &m_randrBase, &m_randrError);
-
- kDebug(dXndr()) << "Event Base: " << m_randrBase;
- kDebug(dXndr()) << "Event Error: "<< m_randrError;
-
-
-
- m_window = XCreateSimpleWindow(QX11Info::display(),
- XRootWindow(QX11Info::display(), DefaultScreen(QX11Info::display()))
- , 0, 0, 1, 1, 0, 0, 0 );
-
- XRRSelectInput(QX11Info::display(), m_window,
- RRScreenChangeNotifyMask | RRCrtcChangeNotifyMask |
- RROutputChangeNotifyMask | RROutputPropertyNotifyMask);
-
- KSystemEventFilter::installEventFilter(this);
-}
-
-XRandRX11Helper::~XRandRX11Helper()
-{
- KSystemEventFilter::removeEventFilter(this);
- if (m_window) {
- XDestroyWindow(QX11Info::display(), m_window);
- }
-}
-
-QString XRandRX11Helper::rotationToString(Rotation rotation)
-{
- switch (rotation) {
- case RR_Rotate_0:
- return "RR_Rotate_0";
- case RR_Rotate_90:
- return "RR_Rotate_90";
- case RR_Rotate_180:
- return "RR_Rotate_180";
- case RR_Rotate_270:
- return "RR_Rotate_270";
- }
-
- return QString("invalid value (%1)").arg(rotation);
-}
-
-QString XRandRX11Helper::connectionToString(Connection connection)
-{
- switch (connection) {
- case RR_Connected:
- return "RR_Connected";
- case RR_Disconnected:
- return "RR_Disconnected";
- case RR_UnknownConnection:
- return "RR_UnknownConnection";
- }
-
- return QString("invalid value (%1)").arg(connection);
-}
-
-
-
-bool XRandRX11Helper::x11Event(XEvent *event)
-{
- /* XRandR <= 1.1 */
- if (m_versionMajor == 1 && m_versionMinor <= 1) {
- if (event->xany.type == m_randrBase + RRScreenChangeNotify) {
- KDebug::Block changeNotify("RRScreenChangeNotify", dXndr());
-
- XRRScreenChangeNotifyEvent* e2 = reinterpret_cast< XRRScreenChangeNotifyEvent* >(event);
-
- kDebug(dXndr()) << "Timestamp: " << e2->timestamp;
- kDebug(dXndr()) << "Window: " << e2->window;
- kDebug(dXndr()) << "Root: "<< e2->root;
- kDebug(dXndr()) << "Size Index: " << e2->size_index;
- kDebug(dXndr()) << "Subpixel Order:" << e2->subpixel_order;
- kDebug(dXndr()) << "Rotation: " << rotationToString(e2->rotation);
- kDebug(dXndr()) << "Size: " << e2->width << e2->height;
- kDebug(dXndr()) << "SizeMM: " << e2->mwidth << e2->mheight;
-
- Q_EMIT outputsChanged();
- }
-
- return false;
- }
-
- /* XRandR >= 1.2 */
- if (event->xany.type == m_randrBase + RRNotify) {
- XRRNotifyEvent* e2 = reinterpret_cast< XRRNotifyEvent* >(event);
- if (e2->subtype == RRNotify_CrtcChange) {
- XRRCrtcChangeNotifyEvent* e2 = reinterpret_cast< XRRCrtcChangeNotifyEvent* >(event);
-
- KDebug::Block crtcChange("RRNotify_CrtcChange", dXndr());
- kDebug(dXndr()) << "CRTC: " << e2->crtc;
- kDebug(dXndr()) << "Mode: " << e2->mode;
- kDebug(dXndr()) << "Rotation: " << rotationToString(e2->rotation);
- kDebug(dXndr()) << "Geometry: " << e2->x << e2->y << e2->width << e2->height;
-
- Q_EMIT crtcChanged(e2->crtc);
-
- } else if (e2->subtype == RRNotify_OutputChange) {
- XRROutputChangeNotifyEvent* e2 = reinterpret_cast< XRROutputChangeNotifyEvent* >(event);
-
- KDebug::Block outputChange("RRNotify_OutputChange", dXndr());
- kDebug(dXndr()) << "Output: " << e2->output;
- kDebug(dXndr()) << "CRTC: " << e2->crtc;
- kDebug(dXndr()) << "Mode: " << e2->mode;
- kDebug(dXndr()) << "Rotation: " << rotationToString(e2->rotation);
- kDebug(dXndr()) << "Connection: " << connectionToString(e2->connection);
- kDebug(dXndr()) << "Subpixel Order: " << e2->subpixel_order;
-
- Q_EMIT outputChanged(e2->output);
-
- } else if (e2->subtype == RRNotify_OutputProperty) {
- XRROutputPropertyNotifyEvent* e2 = reinterpret_cast< XRROutputPropertyNotifyEvent* >(event);
-
- char *atom_name = XGetAtomName(QX11Info::display(), e2->property);
- KDebug::Block changeProperty("RRNotify_Property", dXndr());
- kDebug(dXndr()) << "Timestamp: " << e2->timestamp;
- kDebug(dXndr()) << "Output: " << e2->output;
- kDebug(dXndr()) << "Property: " << XGetAtomName(QX11Info::display(), e2->property);
- kDebug(dXndr()) << "State (newValue, Deleted): " << e2->state;
- XFree(atom_name);
- }
- }
-
- return false;
-}
-
-#include "moc_xrandrx11helper.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright 2012, 2013 Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef XRANDRX11HELPER_H
-#define XRANDRX11HELPER_H
-
-#include <QWidget>
-#include "xlibandxrandr.h"
-
-class XRandRX11Helper : public QWidget
-{
- Q_OBJECT
-
- public:
- XRandRX11Helper();
- virtual ~XRandRX11Helper();
-
- Q_SIGNALS:
- /* Emitted when only XRandR 1.1 or older is available */
- void outputsChanged();
-
- /* Emitted only when XRandR 1.2 or newer is available */
- void crtcChanged(RRCrtc crtc);
- void outputChanged(RROutput output);
- void outputPropertyChanged(RROutput output);
-
- private:
- QString rotationToString(Rotation rotation);
- QString connectionToString(Connection connection);
-
- protected:
- virtual bool x11Event(XEvent *);
-
- int m_randrBase;
- int m_randrError;
- int m_versionMajor;
- int m_versionMinor;
-
- Window m_window;
-};
-
-#endif // XRANDRX11HELPER_H
+++ /dev/null
-find_package(XCB REQUIRED)
-
-include_directories(${CMAKE_SOURCE_DIR}/src
- ${KDE4_INCLUDES}
- ${CMAKE_BUILD_DIR}
- ${QT_INCLUDES}
- ${X11_Xrandr_INCLUDE_PATH}
-)
-
-set(xrandr11_SRCS
- xrandr11.cpp
- ../xrandr/xrandrx11helper.cpp
-)
-
-add_library(KSC_XRandR11 MODULE ${xrandr11_SRCS})
-
-set_target_properties(KSC_XRandR11 PROPERTIES PREFIX "")
-target_link_libraries(KSC_XRandR11 ${QT_QTCORE_LIBRARY}
- ${QT_QTGUI_LIBRARY} # XRandrX11Helper is a QWidget
- ${KDE4_KDECORE_LIBS}
- ${KDE4_KDEUI_LIBS}
- ${X11_LIBRARIES}
- ${X11_Xrandr_LIB}
- ${XCB_XCB_LIBRARIES}
- ${X11_XCB_LIBRARIES}
- ${XCB_RANDR_LIBRARIES}
- kscreen
-)
-
-install(TARGETS KSC_XRandR11 DESTINATION ${PLUGIN_INSTALL_DIR}/plugins/kscreen/)
+++ /dev/null
-/********************************************************************
- K Win - the KDE window manager
- This file is part of the KDE project.
-
-Copyright (C) 2012, 2013 Martin Gräßlin <mgraesslin@kde.org>
-
-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 2 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/>.
-*********************************************************************/
-
-#include "xlibandxcb.h"
-
-#include <xcb/randr.h>
-
-#include <QtGui/QX11Info>
-
-static xcb_connection_t *XRandR11XCBConnection = 0;
-
-xcb_connection_t *connection()
-{
- // Use our own connection to make sure that we won't mess up Qt's connection
- // if something goes wrong on our side.
- if (XRandR11XCBConnection == 0) {
- XRandR11XCBConnection = xcb_connect(0, 0);
- }
- return XRandR11XCBConnection;
-}
-
-void closeConnection()
-{
- xcb_disconnect(XRandR11XCBConnection);
- XRandR11XCBConnection = 0;
-}
-
-xcb_screen_t *screen_of_display (xcb_connection_t *c, int screen)
-{
- xcb_screen_iterator_t iter;
-
- iter = xcb_setup_roots_iterator (xcb_get_setup (c));
- for (; iter.rem; --screen, xcb_screen_next (&iter))
- if (screen == 0)
- return iter.data;
-
- return NULL;
-}
-
-typedef xcb_window_t WindowId;
-
-template <typename Reply,
-typename Cookie,
-Reply *(*replyFunc)(xcb_connection_t*, Cookie, xcb_generic_error_t**),
-Cookie (*requestFunc)(xcb_connection_t*, xcb_window_t)>
-class Wrapper
-{
-public:
- Wrapper()
- : m_retrieved(false)
- , m_window(XCB_WINDOW_NONE)
- , m_reply(NULL)
- {
- m_cookie.sequence = 0;
- }
- explicit Wrapper(WindowId window)
- : m_retrieved(false)
- , m_cookie(requestFunc(connection(), window))
- , m_window(window)
- , m_reply(NULL)
- {
- }
- explicit Wrapper(const Wrapper &other)
- : m_retrieved(other.m_retrieved)
- , m_cookie(other.m_cookie)
- , m_window(other.m_window)
- , m_reply(NULL)
- {
- takeFromOther(const_cast<Wrapper&>(other));
- }
- virtual ~Wrapper() {
- cleanup();
- }
- inline Wrapper &operator=(const Wrapper &other) {
- if (this != &other) {
- // if we had managed a reply, free it
- cleanup();
- // copy members
- m_retrieved = other.m_retrieved;
- m_cookie = other.m_cookie;
- m_window = other.m_window;
- m_reply = other.m_reply;
- // take over the responsibility for the reply pointer
- takeFromOther(const_cast<Wrapper&>(other));
- }
- return *this;
- }
-
- inline const Reply *operator->() {
- getReply();
- return m_reply;
- }
- inline bool isNull() {
- getReply();
- return m_reply == NULL;
- }
- inline operator bool() {
- return !isNull();
- }
- inline const Reply *data() {
- getReply();
- return m_reply;
- }
- inline WindowId window() const {
- return m_window;
- }
- inline bool isRetrieved() const {
- return m_retrieved;
- }
- /**
- * Returns the value of the reply pointer referenced by this object. The reply pointer of
- * this object will be reset to null. Calling any method which requires the reply to be valid
- * will crash.
- *
- * Callers of this function take ownership of the pointer.
- **/
- inline Reply *take() {
- getReply();
- Reply *ret = m_reply;
- m_reply = NULL;
- m_window = XCB_WINDOW_NONE;
- return ret;
- }
-
-protected:
- void getReply() {
- if (m_retrieved || !m_cookie.sequence) {
- return;
- }
- m_reply = replyFunc(connection(), m_cookie, NULL);
- m_retrieved = true;
- }
-
-private:
- inline void cleanup() {
- if (!m_retrieved && m_cookie.sequence) {
- xcb_discard_reply(connection(), m_cookie.sequence);
- } else if (m_reply) {
- free(m_reply);
- }
- }
- inline void takeFromOther(Wrapper &other) {
- if (m_retrieved) {
- m_reply = other.take();
- } else {
- //ensure that other object doesn't try to get the reply or discards it in the dtor
- other.m_retrieved = true;
- other.m_window = XCB_WINDOW_NONE;
- }
- }
- bool m_retrieved;
- Cookie m_cookie;
- WindowId m_window;
- Reply *m_reply;
-};
-
-typedef Wrapper<xcb_randr_get_screen_size_range_reply_t, xcb_randr_get_screen_size_range_cookie_t, &xcb_randr_get_screen_size_range_reply, &xcb_randr_get_screen_size_range> ScreenSize;
-typedef Wrapper<xcb_randr_get_screen_info_reply_t, xcb_randr_get_screen_info_cookie_t, &xcb_randr_get_screen_info_reply, &xcb_randr_get_screen_info> ScreenInfo;
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef XLIBANDXCB_H
-#define XLIBANDXCB_H
-
-extern "C"
-{
- #include <X11/Xlib.h>
- #include <X11/Xatom.h>
- #include <X11/Xlib-xcb.h>
- #define INT8 _X11INT8
- #define INT32 _X11INT32
- #include <X11/Xproto.h>
- #undef INT8
- #undef INT32
-
- #include <xcb/xcb.h>
-}
-
-#include <fixx11h.h>
-
-#endif // XLIBANDXCB_H
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "xrandr11.h"
-#include "wrapper.h"
-#include "../xrandr/xrandrx11helper.h"
-
-#include "config.h"
-#include "edid.h"
-#include "configmonitor.h"
-
-#include <xcb/xcb.h>
-#include <xcb/randr.h>
-
-#include <QtCore/QString>
-#include <QtCore/QDebug>
-#include <QtCore/qplugin.h>
-
-#include <KDebug>
-
-Q_EXPORT_PLUGIN2(XRandR11, XRandR11)
-
-XRandR11::XRandR11(QObject* parent)
- : QObject(parent)
- , m_valid(false)
- , m_x11Helper(0)
- , m_currentConfig(0)
- , m_currentTimestamp(0)
-{
- xcb_generic_error_t *error = 0;
- xcb_randr_query_version_reply_t* version;
- version = xcb_randr_query_version_reply(connection(), xcb_randr_query_version(connection(), XCB_RANDR_MAJOR_VERSION, XCB_RANDR_MINOR_VERSION), &error);
-
- if (!version || error) {
- free(error);
- qDebug() << "Can't get XRandR version";
- return;
- }
-
- if (version->major_version != 1 || version->minor_version != 1) {
- qDebug() << "This backend is only for XRandR 1.1, your version is: " << version->major_version << "." << version->minor_version;
- return;
- }
-
- m_x11Helper = new XRandRX11Helper();
-
- connect(m_x11Helper, SIGNAL(outputsChanged()), SLOT(updateConfig()));
-
- m_valid = true;
-}
-
-XRandR11::~XRandR11()
-{
- closeConnection();
- delete m_currentConfig;
- delete m_x11Helper;
-}
-
-QString XRandR11::name() const
-{
- return "XRandR 1.1";
-}
-
-bool XRandR11::isValid() const
-{
- return m_valid;
-}
-
-KScreen::Config* XRandR11::config() const
-{
- KScreen::Config* config = new KScreen::Config();
-
- int screenId = QX11Info().screen();
- xcb_screen_t* xcbScreen = screen_of_display(connection(), screenId);
- ScreenInfo info(xcbScreen->root);
- ScreenSize size(xcbScreen->root);
-
- if (info->config_timestamp == m_currentTimestamp) {
- return m_currentConfig;
- }
-
- KScreen::Screen* screen = new KScreen::Screen();
- screen->setId(screenId);
- screen->setCurrentSize(QSize(xcbScreen->width_in_pixels, xcbScreen->height_in_pixels));
- screen->setMaxSize(QSize(size->max_width, size->max_height));
- screen->setMinSize(QSize(size->min_width, size->min_height));
- screen->setMaxActiveOutputsCount(1);
-
- config->setScreen(screen);
-
- KScreen::OutputList outputs;
- KScreen::Output* output = new KScreen::Output();
- output->setId(1);
-
- output->setConnected(true);
- output->setEnabled(true);
- output->setName(QLatin1String("Default"));
- output->setPos(QPoint(0,0));
- output->setPrimary(true);
- output->setRotation((KScreen::Output::Rotation) info->rotation);
- output->setSizeMm(QSize(xcbScreen->width_in_millimeters, xcbScreen->height_in_millimeters));
-
- outputs.insert(1, output);
- config->setOutputs(outputs);
-
- KScreen::Mode *mode = 0;
- KScreen::ModeList modes;
-
- int nrates;
- uint16_t* rates;
- xcb_randr_refresh_rates_iterator_t ite = xcb_randr_get_screen_info_rates_iterator(info.data());
- xcb_randr_screen_size_t* sizes = xcb_randr_get_screen_info_sizes(info.data());
- for (int x = 0; x < info->nSizes; x++) {
- rates = xcb_randr_refresh_rates_rates(ite.data);
- nrates = xcb_randr_refresh_rates_rates_length(ite.data);
-
- for (int j = 0; j < nrates; j++) {
- mode = new KScreen::Mode();
- mode->setId(QString::number(x) + "-" + QString::number(j));
- mode->setSize(QSize(sizes[x].width, sizes[x].height));
- mode->setRefreshRate((float) rates[j]);
- mode->setName(QString(QString::number(sizes[x].width) + "x" + QString::number(sizes[x].height)));
-
- if (x == info->sizeID && rates[j] == info->rate) {
- output->setCurrentModeId(mode->id());
- }
- modes.insert(mode->id(), mode);
- }
-
- xcb_randr_refresh_rates_next(&ite);
- }
-
- output->setModes(modes);
- return config;
-}
-
-void XRandR11::setConfig(KScreen::Config* config) const
-{
- KScreen::Output* output = config->outputs().take(1);
- KScreen::Mode *mode = output->currentMode();
-
- int screenId = QX11Info().screen();
- xcb_screen_t* xcbScreen = screen_of_display(connection(), screenId);
-
- ScreenInfo info(xcbScreen->root);
- xcb_generic_error_t *err;
- xcb_randr_set_screen_config_cookie_t cookie;
- xcb_randr_set_screen_config_reply_t *result;
- int sizeId = mode->id().split("-").first().toInt();
- cookie = xcb_randr_set_screen_config(connection(), xcbScreen->root, CurrentTime, info->config_timestamp, sizeId,
- (short) output->rotation(), mode->refreshRate());
- result = xcb_randr_set_screen_config_reply(connection(), cookie, &err);
-
- delete result;
-}
-
-KScreen::Edid* XRandR11::edid(int outputId) const
-{
- Q_UNUSED(outputId)
- return new KScreen::Edid();
-}
-
-void XRandR11::updateConfig(KScreen::Config* config) const
-{
- KScreen::Output* output = config->output(1);
- KScreen::Output *current = m_currentConfig->output(1);
- output->setCurrentModeId(current->currentModeId());
- output->setRotation(current->rotation());
-}
-
-void XRandR11::updateConfig()
-{
- delete m_currentConfig;
- m_currentConfig = config();
- KScreen::ConfigMonitor::instance()->notifyUpdate();
-}
-
-extern int dXndr() { static int s_area = KDebug::registerArea("KSRandr11", false); return s_area; }
-#include "moc_xrandr11.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef XRANDR11_BACKEND_H
-#define XRANDR11_BACKEND_H
-
-#include "xlibandxcb.h"
-#include "../abstractbackend.h"
-#include <QtCore/QObject>
-
-class XRandRX11Helper;
-
-class XRandR11 : public QObject, public AbstractBackend
-{
- Q_OBJECT
- Q_INTERFACES(AbstractBackend)
-
-public:
- explicit XRandR11(QObject* parent = 0);
- virtual ~XRandR11();
-
- virtual QString name() const;
- virtual KScreen::Config* config() const;
- virtual void setConfig(KScreen::Config* config) const;
- virtual bool isValid() const;
- virtual KScreen::Edid *edid(int outputId) const;
- virtual void updateConfig(KScreen::Config *config) const;
-
-private Q_SLOTS:
- void updateConfig();
-
-private:
- bool m_valid;
- XRandRX11Helper* m_x11Helper;
- KScreen::Config* m_currentConfig;
- xcb_timestamp_t m_currentTimestamp;
-};
-
-extern int dXndr();
-#endif //FAKE_BACKEND_H
+++ /dev/null
-#cmakedefine LIBKSCREEN_VERSION "@LIBKSCREEN_VERSION@"
+++ /dev/null
-include_directories(${PROJECT_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDES})
-
-set(libkscreen_SRCS
- backendloader.cpp
- config.cpp
- configmonitor.cpp
- screen.cpp
- output.cpp
- edid.cpp
- mode.cpp
-)
-
-add_library(kscreen SHARED ${libkscreen_SRCS})
-
-target_link_libraries(kscreen ${QT_QTCORE_LIBRARY} ${KDE4_KDECORE_LIBS})
-
-set_target_properties(kscreen PROPERTIES
- VERSION ${libkscreen_VERSION}
- SOVERSION ${libkscreen_VERSION_MAJOR}
-)
-
-install(TARGETS kscreen EXPORT kscreenLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS})
-
-install(FILES kscreen_export.h
- mode.h
- output.h
- edid.h
- screen.h
- config.h
- configmonitor.h
- DESTINATION ${INCLUDE_INSTALL_DIR}/kscreen)
-
-if(NOT WIN32)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/kscreen.pc.in ${CMAKE_CURRENT_BINARY_DIR}/kscreen.pc @ONLY)
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kscreen.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-endif(NOT WIN32)
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "backendloader.h"
-#include "backends/abstractbackend.h"
-
-#include <QtCore/QStringList>
-#include <QtCore/QCoreApplication>
-#include <QtCore/QPluginLoader>
-#include <QDir>
-#include <kdebug.h>
-
-AbstractBackend* BackendLoader::s_backend = 0;
-
-
-bool BackendLoader::init()
-{
- if (s_backend) {
- return true;
- }
-
- KDebug::Block block("Loading backend");
-
- const QString backend = qgetenv("KSCREEN_BACKEND").constData();
- const QString backendFilter = QString::fromLatin1("KSC_%1*").arg(backend);
-
- const QStringList paths = QCoreApplication::libraryPaths();
- Q_FOREACH (const QString &path, paths) {
- const QDir dir(path + QDir::separator() + QLatin1String("kscreen"),
- backendFilter,
- QDir::SortFlags(QDir::QDir::NoSort),
- QDir::NoDotAndDotDot | QDir::Files);
- const QFileInfoList finfos = dir.entryInfoList();
- Q_FOREACH (const QFileInfo &finfo, finfos) {
- // Skip "Fake" backend unless explicitly specified via KSCREEN_BACKEND
- if (backend.isEmpty() && finfo.fileName().contains(QLatin1String("KSC_Fake"))) {
- continue;
- }
-
- QPluginLoader loader(finfo.filePath());
- loader.load();
- QObject *instance = loader.instance();
- if (!instance) {
- loader.unload();
- continue;
- }
-
- s_backend = qobject_cast< AbstractBackend* >(instance);
- if (s_backend) {
- if (!s_backend->isValid()) {
- kDebug() << "Skipping" << s_backend->name() << "backend";
- delete s_backend;
- s_backend = 0;
- loader.unload();
- continue;
- }
- kDebug() << "Loading" << s_backend->name() << "backend";
- return true;
- }
- }
- }
-
- kDebug() << "No backend found!";
- return false;
-}
-
-AbstractBackend* BackendLoader::backend()
-{
- return s_backend;
-}
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef BACKEND_LOADER_H
-#define BACKEND_LOADER_H
-
-class AbstractBackend;
-
-class BackendLoader
-{
- public:
- static bool init();
- static AbstractBackend* backend();
-
- private:
- static AbstractBackend* s_backend;
-};
-
-#endif //BACKEND_LOADER_H
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "config.h"
-#include "output.h"
-#include "backendloader.h"
-#include "backends/abstractbackend.h"
-
-#include <QtCore/QDebug>
-#include <QtCore/QRect>
-
-namespace KScreen {
-
-class Config::Private
-{
- public:
- Private():
- valid(true),
- screen(0),
- primaryOutput(0)
- { }
-
- Private(const Private &other):
- valid(other.valid),
- primaryOutput(other.primaryOutput)
- {
- screen = other.screen->clone();
- Q_FOREACH (Output *otherOutput, other.outputs) {
- outputs.insert(otherOutput->id(), otherOutput->clone());
- }
- }
-
- bool valid;
- Screen* screen;
- Output* primaryOutput;
- OutputList outputs;
-};
-
-bool Config::loadBackend()
-{
- return BackendLoader::init();
-}
-
-Config* Config::current()
-{
- if (!BackendLoader::init()) {
- return 0;
- }
-
- return BackendLoader::backend()->config();
-}
-
-bool Config::setConfig(Config* config)
-{
- if (!BackendLoader::init()) {
- return false;
- }
-
- if (!Config::canBeApplied(config)) {
- return false;
- }
-
- BackendLoader::backend()->setConfig(config);
- return true;
-}
-
-bool Config::canBeApplied(Config* config)
-{
- Config* currentConfig = BackendLoader::backend()->config();
- QRect rect;
- QSize outputSize;
- Output* currentOutput = 0;
- OutputList outputs = config->outputs();
- int enabledOutputsCount = 0;
- Q_FOREACH(Output *output, outputs) {
- if (!output->isEnabled()) {
- continue;
- }
-
- ++enabledOutputsCount;
-
- currentOutput = currentConfig->output(output->id());
- //If there is no such output
- if (!currentOutput) {
- qDebug() << "The output:" << output->id() << "does not exists";
- return false;
- }
- //If the output is not connected
- if (!currentOutput->isConnected()) {
- qDebug() << "The output:" << output->id() << "is not connected";
- return false;
- }
- //if there is no currentMode
- if (output->currentModeId().isEmpty()) {
- qDebug() << "The output:" << output->id() << "has no currentModeId";
- return false;
- }
- //If the mode is not found in the current output
- if (!currentOutput->mode(output->currentModeId())) {
- qDebug() << "The output:" << output->id() << "has no mode:" << output->currentModeId();
- return false;
- }
-
-
- Mode *currentMode = output->currentMode();
-
- QSize outputSize = currentMode->size();
-
- if (output->pos().x() < rect.x()) {
- rect.setX(output->pos().x());
- }
-
- if (output->pos().y() < rect.y()) {
- rect.setY(output->pos().y());
- }
-
- QPoint bottomRight;
- if (output->isHorizontal()) {
- bottomRight = QPoint(output->pos().x() + outputSize.width(),
- output->pos().y() + outputSize.height());
- } else {
- bottomRight = QPoint(output->pos().x() + outputSize.height(),
- output->pos().y() + outputSize.width());
- }
-
- if (bottomRight.x() > rect.width()) {
- rect.setWidth(bottomRight.x());
- }
-
- if (bottomRight.y() > rect.height()) {
- rect.setHeight(bottomRight.y());
- }
- }
-
- const int maxEnabledOutputsCount = config->screen()->maxActiveOutputsCount();
- if (enabledOutputsCount > maxEnabledOutputsCount) {
- qDebug() << "Too many active screens. Requested: " << enabledOutputsCount << ", Max: " << maxEnabledOutputsCount;
- return false;
- }
-
- if (rect.width() > config->screen()->maxSize().width()) {
- qDebug() << "The configuration has too much width:" << rect.width();
- return false;
- }
- if (rect.height() > config->screen()->maxSize().height()) {
- qDebug() << "The configuration has too much height:" << rect.height();
- return false;
- }
-
- return true;
-}
-
-Config::Config(QObject* parent)
- : QObject(parent)
- , d(new Private())
-{
-}
-
-Config::Config(Config::Private *dd)
- : QObject()
- , d(dd)
-{
-}
-
-
-Config::~Config()
-{
- delete d;
-}
-
-Config *Config::clone() const
-{
- Config *config = new Config(new Private(*d));
- // Set parent of the newly copied items
- config->d->screen->setParent(config);
- Q_FOREACH (Output *output, config->d->outputs) {
- output->setParent(config);
- }
-
- return config;
-}
-
-
-Screen* Config::screen() const
-{
- return d->screen;
-}
-
-void Config::setScreen(Screen* screen)
-{
- d->screen = screen;
-}
-
-Output* Config::output(int outputId) const
-{
- if (!d->outputs.contains(outputId)) {
- return 0;
- }
-
- return d->outputs[outputId];
-}
-
-QHash< int, Output* > Config::outputs() const
-{
- return d->outputs;
-}
-
-QHash< int, Output* > Config::connectedOutputs() const
-{
- QHash< int, Output* > outputs;
- Q_FOREACH(Output* output, d->outputs) {
- if (!output->isConnected()) {
- continue;
- }
- outputs.insert(output->id(), output);
- }
-
- return outputs;
-}
-
-Output* Config::primaryOutput() const
-{
- if (d->primaryOutput) {
- return d->primaryOutput;
- }
-
- Q_FOREACH(Output* output, d->outputs) {
- if (output->isPrimary()) {
- d->primaryOutput = output;
- return d->primaryOutput;
- }
- }
-
- return 0;
-}
-
-void Config::setPrimaryOutput(Output* output)
-{
- d->primaryOutput = output;
-
- Q_EMIT primaryOutputChanged(output);
-}
-
-void Config::addOutput(Output* output)
-{
- d->outputs.insert(output->id(), output);
-
- Q_EMIT outputAdded(output);
-}
-
-void Config::removeOutput(int outputId)
-{
- Output *output = d->outputs.take(outputId);
- if (output) {
- output->deleteLater();
- if (d->primaryOutput == output) {
- setPrimaryOutput(0);
- }
- }
-
- Q_EMIT outputRemoved(outputId);
-}
-
-void Config::setOutputs(OutputList outputs)
-{
- d->outputs = outputs;
-}
-
-bool Config::isValid() const
-{
- return d->valid;
-}
-
-void Config::setValid(bool valid)
-{
- d->valid = valid;
-}
-
-} //KScreen namespace
-
-#include "moc_config.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef KSCREEN_CONFIG_H
-#define KSCREEN_CONFIG_H
-
-#include "screen.h"
-#include "output.h"
-#include "kscreen_export.h"
-
-#include <QtCore/QHash>
-#include <QtCore/QObject>
-#include <QtCore/QMetaType>
-
-namespace KScreen {
-
-/**
- * Represents a (or the) screen configuration.
- *
- * This is the main class of KScreen, with it you can use
- * the static methods current() to get the systems config and
- * setConfig() to apply a config to the system.
- *
- * Also, you can instance an empty Config, this is usualy done
- * to create a config (with the objective of setting it) from scratch
- * and for example unserialize a saved config to it.
- *
- */
-class KSCREEN_EXPORT Config : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(Screen* screen READ screen)
- Q_PROPERTY(OutputList outputs READ outputs)
-
- public:
- /**
- * Tries to load a backend (it might be already loaded)
- *
- * @return true if there is a working backend, false if none are found or work
- */
- static bool loadBackend();
-
- /**
- * Gets the current system configuration
- *
- * The returned config is a representation of the current system setup, for
- * example if your screens a currently cloned, it will show that.
- *
- * @return the current system config, or null on error
- */
- static Config* current();
-
- /**
- * Sets the given config to the system
- *
- * The config will first be validated via canBeApplied(), then
- * it will be applied to the system.
- *
- * @arg config to be applied
- * @return true if everything went well, false if something failed
- */
- static bool setConfig(Config* config);
-
- /**
- * Validates that a config can be applied in the current system
- *
- * Each system has different constrains, this method will test
- * the given config with those constrains to see if it
- * can be applied.
- *
- * @arg config to be checked
- * @return true if the configuration can be applied, false if not.
- */
- static bool canBeApplied(Config* config);
-
- /**
- * Instance an empty config
- *
- * Usually you never want to use this constructor since there are some
- * values that make no sense to set (for example you want the Screen of
- * the current systme).
- *
- * So usually what you do is call current() and then modify
- * whatever you need.
- */
- explicit Config(QObject *parent = 0);
- virtual ~Config();
-
- /**
- * Duplicates the config
- *
- * @return a new Config instance with same property values
- */
- Config* clone() const;
-
- Screen* screen() const;
- void setScreen(Screen* screen);
-
- Output* output(int outputId) const;
- QHash<int, Output*> outputs() const;
- QHash<int, Output*> connectedOutputs() const;
- Output* primaryOutput() const;
- void setPrimaryOutput(Output *output);
- void addOutput(Output *output);
- void removeOutput(int outputId);
- void setOutputs(OutputList outputs);
-
- bool isValid() const;
- void setValid(bool valid);
-
- Q_SIGNALS:
- void outputAdded(Output *output);
- void outputRemoved(int outputId);
- void primaryOutputChanged(KScreen::Output *output);
- private:
- Q_DISABLE_COPY(Config)
-
- class Private;
- Private * const d;
-
- Config(Private *dd);
-};
-
-} //KScreen namespace
-
-#endif //KSCREEN_CONFIG_H
+++ /dev/null
-/*************************************************************************************
- * Copyright 2012, 2013 Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "configmonitor.h"
-#include "backendloader.h"
-#include "backends/abstractbackend.h"
-
-using namespace KScreen;
-
-
-class ConfigMonitor::Private
-{
- public:
- Private(ConfigMonitor *q)
- : backend(BackendLoader::backend())
- , m_q(q)
- { }
-
- void updateConfigs();
- void _k_configurationDestroyed(QObject* removedConfig);
-
- QList< KScreen::Config* > watchedConfigs;
- AbstractBackend* backend;
- ConfigMonitor *m_q;
-};
-
-void ConfigMonitor::Private::updateConfigs()
-{
- Q_FOREACH( Config *config, watchedConfigs) {
- if (config) {
- backend->updateConfig(config);
- }
- }
-}
-
-void ConfigMonitor::Private::_k_configurationDestroyed(QObject *removedConfig)
-{
- m_q->removeConfig(static_cast<Config*>(removedConfig));
-}
-
-ConfigMonitor *ConfigMonitor::instance()
-{
- static ConfigMonitor *s_instance;
-
- if (s_instance == 0) {
- s_instance = new ConfigMonitor();
- }
-
- return s_instance;
-}
-
-ConfigMonitor::ConfigMonitor():
- QObject(),
- d(new Private(this))
-{
-}
-
-ConfigMonitor::~ConfigMonitor()
-{
- delete d;
-}
-
-void ConfigMonitor::addConfig(Config *config)
-{
- if (!d->watchedConfigs.contains(config)) {
- connect(config, SIGNAL(destroyed(QObject*)), SLOT(_k_configurationDestroyed(QObject*)));
- d->watchedConfigs << config;
- }
-}
-
-void ConfigMonitor::removeConfig(Config *config)
-{
- if (d->watchedConfigs.contains(config)) {
- disconnect(config, SIGNAL(destroyed(QObject*)), this, SLOT(_k_configurationDestroyed(QObject*)));
- d->watchedConfigs.removeAll(config);
- }
-}
-
-void ConfigMonitor::notifyUpdate()
-{
- d->updateConfigs();
-
- Q_EMIT configurationChanged();
-}
-
-
-#include "moc_configmonitor.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright 2012, 2013 Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef KSCREEN_CONFIGMONITOR_H
-#define KSCREEN_CONFIGMONITOR_H
-
-#include <QtCore/QObject>
-#include <QtCore/QPointer>
-
-#include "config.h"
-#include "kscreen_export.h"
-
-
-namespace KScreen
-{
-
-class KSCREEN_EXPORT ConfigMonitor : public QObject
-{
- Q_OBJECT
-
-public:
- static ConfigMonitor* instance();
-
- void addConfig(KScreen::Config *config);
- void removeConfig(KScreen::Config *config);
-
-public Q_SLOTS:
- void notifyUpdate();
-
-Q_SIGNALS:
- void configurationChanged();
-
-private:
- explicit ConfigMonitor();
- virtual ~ConfigMonitor();
-
- Q_DISABLE_COPY(ConfigMonitor)
-
- class Private;
- Private * const d;
- Q_PRIVATE_SLOT(d, void _k_configurationDestroyed(QObject *))
-};
-
-} /* namespace KScreen */
-
-#endif // KSCREEN_CONFIGMONITOR_H
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Daniel Nicoletti <dantti12@gmail.com> *
- * (C) 2012, 2013 by Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "edid.h"
-
-#include <math.h>
-
-#include <QCryptographicHash>
-#include <QFile>
-#include <QStringList>
-
-#include <kdebug.h>
-
-#define GCM_EDID_OFFSET_PNPID 0x08
-#define GCM_EDID_OFFSET_SERIAL 0x0c
-#define GCM_EDID_OFFSET_SIZE 0x15
-#define GCM_EDID_OFFSET_GAMMA 0x17
-#define GCM_EDID_OFFSET_DATA_BLOCKS 0x36
-#define GCM_EDID_OFFSET_LAST_BLOCK 0x6c
-#define GCM_EDID_OFFSET_EXTENSION_BLOCK_COUNT 0x7e
-
-#define GCM_DESCRIPTOR_DISPLAY_PRODUCT_NAME 0xfc
-#define GCM_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER 0xff
-#define GCM_DESCRIPTOR_COLOR_MANAGEMENT_DATA 0xf9
-#define GCM_DESCRIPTOR_ALPHANUMERIC_DATA_STRING 0xfe
-#define GCM_DESCRIPTOR_COLOR_POINT 0xfb
-
-#define PNP_IDS "/usr/share/hwdata/pnp.ids"
-
-namespace KScreen {
-
-
-class Edid::Private
-{
- public:
- Private():
- valid(false),
- width(0),
- height(0),
- gamma(0)
- { }
-
- Private(const Private &other):
- valid(other.valid),
- monitorName(other.monitorName),
- vendorName(other.vendorName),
- serialNumber(other.serialNumber),
- eisaId(other.eisaId),
- checksum(other.checksum),
- pnpId(other.pnpId),
- width(other.width),
- height(other.height),
- gamma(other.gamma),
- red(other.red),
- green(other.green),
- blue(other.blue),
- white(other.white)
- {
- }
-
- bool parse(const quint8 *data, size_t length);
- int edidGetBit(int in, int bit) const;
- int edidGetBits(int in, int begin, int end) const;
- double edidDecodeFraction(int high, int low) const;
- QString edidParseString(const quint8 *data) const;
-
- bool valid;
- QString monitorName;
- QString vendorName;
- QString serialNumber;
- QString eisaId;
- QString checksum;
- QString pnpId;
- uint width;
- uint height;
- qreal gamma;
- QQuaternion red;
- QQuaternion green;
- QQuaternion blue;
- QQuaternion white;
-};
-
-
-Edid::Edid()
- : QObject()
- , d(new Private())
-{
-}
-
-Edid::Edid(const quint8 *data, size_t length, QObject *parent)
- : QObject(parent)
- , d(new Private())
-{
- d->parse(data, length);
-}
-
-Edid::Edid(Edid::Private *dd)
- : QObject()
- , d(dd)
-{
-}
-
-Edid::~Edid()
-{
- delete d;
-}
-
-Edid *Edid::clone() const
-{
- return new Edid(new Private(*d));
-}
-
-bool Edid::isValid() const
-{
- return d->valid;
-}
-
-QString Edid::deviceId(const QString &fallbackName) const
-{
- QString id = QLatin1String("xrandr");
- // if no info was added check if the fallbacName is provided
- if (vendor().isNull() && name().isNull() && serial().isNull()) {
- if (!fallbackName.isEmpty()) {
- id.append(QLatin1Char('-') + fallbackName);
- } else {
- // all info we have are empty strings
- id.append(QLatin1String("-unknown"));
- }
- } else if (d->valid) {
- if (!vendor().isNull()) {
- id.append(QLatin1Char('-') + vendor());
- }
- if (!name().isNull()) {
- id.append(QLatin1Char('-') + name());
- }
- if (!serial().isNull()) {
- id.append(QLatin1Char('-') + serial());
- }
- }
-
- return id;
-}
-
-QString Edid::name() const
-{
- if (d->valid) {
- return d->monitorName;
- }
- return QString();
-}
-
-QString Edid::vendor() const
-{
- if (d->valid) {
- return d->vendorName;
- }
- return QString();
-}
-
-QString Edid::serial() const
-{
- if (d->valid) {
- return d->serialNumber;
- }
- return QString();
-}
-
-QString Edid::eisaId() const
-{
- if (d->valid) {
- return d->eisaId;
- }
- return QString();
-}
-
-QString Edid::hash() const
-{
- if (d->valid) {
- return d->checksum;
- }
- return QString();
-}
-
-QString Edid::pnpId() const
-{
- if (d->valid) {
- return d->pnpId;
- }
- return QString();
-}
-
-uint Edid::width() const
-{
- return d->width;
-}
-
-uint Edid::height() const
-{
- return d->height;
-}
-
-qreal Edid::gamma() const
-{
- return d->gamma;
-}
-
-QQuaternion Edid::red() const
-{
- return d->red;
-}
-
-QQuaternion Edid::green() const
-{
- return d->green;
-}
-
-QQuaternion Edid::blue() const
-{
- return d->blue;
-}
-
-QQuaternion Edid::white() const
-{
- return d->white;
-}
-
-bool Edid::Private::parse(const quint8 *data, size_t length)
-{
- quint32 serial;
-
- /* check header */
- if (length < 128) {
- if (length > 0) {
- kWarning() << "Invalid EDID length (" << length << " bytes)";
- }
- valid = false;
- return valid;
- }
- if (data[0] != 0x00 || data[1] != 0xff) {
- kWarning() << "Failed to parse EDID header";
- valid = false;
- return valid;
- }
-
- /* decode the PNP ID from three 5 bit words packed into 2 bytes
- * /--08--\/--09--\
- * 7654321076543210
- * |\---/\---/\---/
- * R C1 C2 C3 */
- pnpId[0] = 'A' + ((data[GCM_EDID_OFFSET_PNPID + 0] & 0x7c) / 4) - 1;
- pnpId[1] = 'A' + ((data[GCM_EDID_OFFSET_PNPID + 0] & 0x3) * 8) + ((data[GCM_EDID_OFFSET_PNPID+1] & 0xe0) / 32) - 1;
- pnpId[2] = 'A' + (data[GCM_EDID_OFFSET_PNPID + 1] & 0x1f) - 1;
-
- // load the PNP_IDS file and load the vendor name
- if (!pnpId.isEmpty()) {
- QFile pnpIds(PNP_IDS);
- if (pnpIds.open(QIODevice::ReadOnly)) {
- while (!pnpIds.atEnd()) {
- QString line = pnpIds.readLine();
- if (line.startsWith(pnpId)) {
- QStringList parts = line.split(QLatin1Char('\t'));
- if (parts.size() == 2) {
- vendorName = line.split(QLatin1Char('\t')).at(1).simplified();
- }
- break;
- }
- }
- }
- }
-
- /* maybe there isn't a ASCII serial number descriptor, so use this instead */
- serial = static_cast<quint32>(data[GCM_EDID_OFFSET_SERIAL + 0]);
- serial += static_cast<quint32>(data[GCM_EDID_OFFSET_SERIAL + 1] * 0x100);
- serial += static_cast<quint32>(data[GCM_EDID_OFFSET_SERIAL + 2] * 0x10000);
- serial += static_cast<quint32>(data[GCM_EDID_OFFSET_SERIAL + 3] * 0x1000000);
- if (serial > 0) {
- serialNumber = QString::number(serial);
- }
-
- /* get the size */
- width = data[GCM_EDID_OFFSET_SIZE + 0];
- height = data[GCM_EDID_OFFSET_SIZE + 1];
-
- /* we don't care about aspect */
- if (width == 0 || height == 0) {
- width = 0;
- height = 0;
- }
-
- /* get gamma */
- if (data[GCM_EDID_OFFSET_GAMMA] == 0xff) {
- gamma = 1.0f;
- } else {
- gamma = (static_cast<float>(data[GCM_EDID_OFFSET_GAMMA] / 100) + 1);
- }
-
- /* get color red */
- red.setX(edidDecodeFraction(data[0x1b], edidGetBits(data[0x19], 6, 7)));
- red.setY(edidDecodeFraction(data[0x1c], edidGetBits(data[0x19], 5, 4)));
-
- /* get color green */
- green.setX(edidDecodeFraction(data[0x1d], edidGetBits(data[0x19], 2, 3)));
- green.setY(edidDecodeFraction(data[0x1e], edidGetBits(data[0x19], 0, 1)));
-
- /* get color blue */
- blue.setX(edidDecodeFraction(data[0x1f], edidGetBits(data[0x1a], 6, 7)));
- blue.setY(edidDecodeFraction(data[0x20], edidGetBits(data[0x1a], 4, 5)));
-
- /* get color white */
- white.setX(edidDecodeFraction(data[0x21], edidGetBits(data[0x1a], 2, 3)));
- white.setY(edidDecodeFraction(data[0x22], edidGetBits(data[0x1a], 0, 1)));
-
- /* parse EDID data */
- for (uint i = GCM_EDID_OFFSET_DATA_BLOCKS;
- i <= GCM_EDID_OFFSET_LAST_BLOCK;
- i += 18) {
- /* ignore pixel clock data */
- if (data[i] != 0) {
- continue;
- }
- if (data[i+2] != 0) {
- continue;
- }
-
- /* any useful blocks? */
- if (data[i+3] == GCM_DESCRIPTOR_DISPLAY_PRODUCT_NAME) {
- QString tmp = edidParseString(&data[i+5]);
- if (!tmp.isEmpty()) {
- monitorName = tmp;
- }
- } else if (data[i+3] == GCM_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER) {
- QString tmp = edidParseString(&data[i+5]);
- if (!tmp.isEmpty()) {
- serialNumber = tmp;
- }
- } else if (data[i+3] == GCM_DESCRIPTOR_COLOR_MANAGEMENT_DATA) {
- kWarning() << "failing to parse color management data";
- } else if (data[i+3] == GCM_DESCRIPTOR_ALPHANUMERIC_DATA_STRING) {
- QString tmp = edidParseString(&data[i+5]);
- if (!tmp.isEmpty()) {
- eisaId = tmp;
- }
- } else if (data[i+3] == GCM_DESCRIPTOR_COLOR_POINT) {
- if (data[i+3+9] != 0xff) {
- /* extended EDID block(1) which contains
- * a better gamma value */
- gamma = ((float) data[i+3+9] / 100) + 1;
- }
- if (data[i+3+14] != 0xff) {
- /* extended EDID block(2) which contains
- * a better gamma value */
- gamma = ((float) data[i+3+9] / 100) + 1;
- }
- }
- }
-
- // calculate checksum
- QCryptographicHash hash(QCryptographicHash::Md5);
- hash.addData(reinterpret_cast<const char *>(data), length);
- checksum = hash.result().toHex();
-
- valid = true;
- return valid;
-}
-
-int Edid::Private::edidGetBit(int in, int bit) const
-{
- return (in & (1 << bit)) >> bit;
-}
-
-int Edid::Private::edidGetBits(int in, int begin, int end) const
-{
- int mask = (1 << (end - begin + 1)) - 1;
-
- return (in >> begin) & mask;
-}
-
-double Edid::Private::edidDecodeFraction(int high, int low) const
-{
- double result = 0.0;
- int i;
-
- high = (high << 2) | low;
- for (i = 0; i < 10; ++i) {
- result += edidGetBit(high, i) * pow(2, i - 10);
- }
- return result;
-}
-
-QString Edid::Private::edidParseString(const quint8 *data) const
-{
- QString text;
-
- /* this is always 12 bytes, but we can't guarantee it's null
- * terminated or not junk. */
- text = QString::fromLocal8Bit((const char*) data, 12);
-
- // Remove newlines, extra spaces and stuff
- text = text.simplified();
-
- return text;
-}
-
-} /* namespace KScreen */
-
-#include "moc_edid.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Daniel Nicoletti <dantti12@gmail.com> *
- * (C) 2012, 2013 by Daniel Vrátil <dvratil@redhat.com> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-
-#ifndef KSCREEN_EDID_H
-#define KSCREEN_EDID_H
-
-#include "kscreen_export.h"
-
-#include <QtCore/QObject>
-#include <QtCore/QtGlobal>
-#include <QtGui/QQuaternion>
-
-namespace KScreen
-{
-
-class KSCREEN_EXPORT Edid: public QObject
-{
- Q_OBJECT
-
- Q_PROPERTY(QString deviceId READ deviceId CONSTANT)
- Q_PROPERTY(QString name READ name CONSTANT)
- Q_PROPERTY(QString vendor READ vendor CONSTANT)
- Q_PROPERTY(QString serial READ serial CONSTANT)
- Q_PROPERTY(QString eisaId READ eisaId CONSTANT)
- Q_PROPERTY(QString hash READ hash CONSTANT)
- Q_PROPERTY(uint width READ width CONSTANT)
- Q_PROPERTY(uint height READ height CONSTANT)
- Q_PROPERTY(qreal gamma READ gamma CONSTANT)
- Q_PROPERTY(QQuaternion red READ red CONSTANT)
- Q_PROPERTY(QQuaternion green READ green CONSTANT)
- Q_PROPERTY(QQuaternion blue READ blue CONSTANT)
- Q_PROPERTY(QQuaternion white READ white CONSTANT)
-
- public:
- explicit Edid();
- explicit Edid(const quint8 *data, size_t length, QObject *parent = 0);
- virtual ~Edid();
-
- Edid* clone() const;
-
- bool isValid() const;
-
- QString deviceId(const QString &fallbackName = QString()) const;
- QString name() const;
- QString vendor() const;
- QString serial() const;
- QString eisaId() const;
- QString hash() const;
- QString pnpId() const;
- uint width() const;
- uint height() const;
- qreal gamma() const;
- QQuaternion red() const;
- QQuaternion green() const;
- QQuaternion blue() const;
- QQuaternion white() const;
-
- private:
- Q_DISABLE_COPY(Edid);
-
- class Private;
- Private * const d;
-
- Edid(Private *dd);
-};
-
-}
-
-Q_DECLARE_METATYPE(KScreen::Edid*)
-
-#endif // EDID_H
+++ /dev/null
-prefix=@CMAKE_INSTALL_PREFIX@
-libdir=@LIB_INSTALL_DIR@
-includedir=@CMAKE_INSTALL_PREFIX@/include
-
-Name: kscreen
-Description: Qt Based library to manage screens with backends (xrandr, whatevercomesnext)
-Version: @libkscreen_VERSION@
-
-Libs: -L${libdir} -lkscreen
-Cflags: -I${includedir}
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef KSCREEN_EXPORT_H
-#define KSCREEN_EXPORT_H
-
-#include <QtCore/QtGlobal>
-
-#define KSCREEN_EXPORT Q_DECL_EXPORT
-
-#endif // KSCREEN_EXPORT_H
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "mode.h"
-
-namespace KScreen {
-
-class Mode::Private
-{
- public:
- Private():
- rate(0)
- { }
-
- Private(const Private &other):
- id(other.id),
- name(other.name),
- size(other.size),
- rate(other.rate)
- {
- }
-
- QString id;
- QString name;
- QSize size;
- float rate;
-};
-
-Mode::Mode(QObject *parent)
- : QObject(parent)
- , d(new Private())
-{
-
-}
-
-Mode::Mode(Mode::Private *dd)
- : QObject()
- , d(dd)
-{
-}
-
-Mode::~Mode()
-{
- delete d;
-}
-
-Mode *Mode::clone() const
-{
- return new Mode(new Private(*d));
-}
-
-const QString Mode::id() const
-{
- return d->id;
-}
-
-void Mode::setId(const QString& id)
-{
- if (d->id == id) {
- return;
- }
-
- d->id = id;
-
- Q_EMIT modeChanged();
-}
-
-QString Mode::name() const
-{
- return d->name;
-}
-
-void Mode::setName(const QString& name)
-{
- if (d->name == name) {
- return;
- }
-
- d->name = name;
-
- Q_EMIT modeChanged();
-}
-
-
-QSize Mode::size() const
-{
- return d->size;
-}
-
-void Mode::setSize(const QSize& size)
-{
- if (d->size == size) {
- return;
- }
-
- d->size = size;
-
- Q_EMIT modeChanged();
-}
-
-float Mode::refreshRate() const
-{
- return d->rate;
-}
-
-void Mode::setRefreshRate(float refresh)
-{
- if (d->rate == refresh) {
- return;
- }
-
- d->rate = refresh;
-
- Q_EMIT modeChanged();
-}
-
-} //KScreen namespace
-
-QDebug operator<<(QDebug dbg, const KScreen::Mode *mode)
-{
- dbg << "KScreen::Mode(Id:" << mode->id() << ", Size:" << mode->size() << ")";
- return dbg;
-}
-
-
-#include "moc_mode.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef MODE_CONFIG_H
-#define MODE_CONFIG_H
-
-#include "kscreen_export.h"
-
-#include <QtCore/QSize>
-#include <QtCore/QHash>
-#include <QtCore/QObject>
-#include <QtCore/QMetaType>
-#include <QtCore/QDebug>
-
-namespace KScreen {
-
-class KSCREEN_EXPORT Mode : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QString id READ id NOTIFY modeChanged)
- Q_PROPERTY(QString name READ name WRITE setName NOTIFY modeChanged)
- Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY modeChanged)
- Q_PROPERTY(float refreshRate READ refreshRate WRITE setRefreshRate NOTIFY modeChanged)
-
- public:
- explicit Mode(QObject *parent = 0);
- virtual ~Mode();
-
- Mode* clone() const;
-
- const QString id() const;
- void setId(const QString &id);
-
- QString name() const;
- void setName(const QString& name);
-
- QSize size() const;
- void setSize(const QSize& size);
-
- float refreshRate() const;
- void setRefreshRate(float refresh);
-
- Q_SIGNALS:
- void modeChanged();
-
- private:
- class Private;
- Private * const d;
-
- Mode(Private *dd);
-};
-
-typedef QHash<QString, Mode*> ModeList;
-
-} //KSCreen namespace
-
-KSCREEN_EXPORT QDebug operator<<(QDebug dbg, const KScreen::Mode *mode);
-
-Q_DECLARE_METATYPE(KScreen::ModeList)
-
-#endif //MODE_H
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "output.h"
-#include "mode.h"
-#include "edid.h"
-#include "backendloader.h"
-#include <backends/abstractbackend.h>
-
-#include <QtCore/QStringList>
-
-namespace KScreen {
-
-class Output::Private
-{
- public:
- Private():
- id(0),
- type(Unknown),
- rotation(None),
- connected(false),
- enabled(false),
- primary(false),
- edid(0)
- {}
-
- Private(const Private &other):
- id(other.id),
- name(other.name),
- type(other.type),
- icon(other.icon),
- clones(other.clones),
- currentMode(other.currentMode),
- preferredMode(other.preferredMode),
- preferredModes(other.preferredModes),
- size(other.size),
- sizeMm(other.sizeMm),
- pos(other.pos),
- rotation(other.rotation),
- connected(other.connected),
- enabled(other.enabled),
- primary(other.primary)
- {
- Q_FOREACH (Mode *otherMode, other.modeList) {
- modeList.insert(otherMode->id(), otherMode->clone());
- }
- if (other.edid) {
- edid = other.edid->clone();
- }
- }
-
- QString biggestMode(const ModeList& modes) const;
-
- int id;
- QString name;
- Type type;
- QString icon;
- ModeList modeList;
- QList<int> clones;
- QString currentMode;
- QString preferredMode;
- QStringList preferredModes;
- QSize size;
- QSize sizeMm;
- QPoint pos;
- Rotation rotation;
- bool connected;
- bool enabled;
- bool primary;
-
- mutable QPointer<Edid> edid;
-};
-
-QString Output::Private::biggestMode(const ModeList& modes) const
-{
- int area, total = 0;
- KScreen::Mode* biggest = 0;
- Q_FOREACH(KScreen::Mode* mode, modes) {
- area = mode->size().width() * mode->size().height();
- if (area < total) {
- continue;
- }
- if (area == total && mode->refreshRate() < biggest->refreshRate()) {
- continue;
- }
- if (area == total && mode->refreshRate() > biggest->refreshRate()) {
- biggest = mode;
- continue;
- }
-
- total = area;
- biggest = mode;
- }
-
- if (!biggest) {
- return QString();
- }
-
- return biggest->id();
-}
-
-Output::Output(QObject *parent)
- : QObject(parent)
- , d(new Private())
-{
-
-}
-
-Output::Output(Output::Private *dd)
- : QObject()
- , d(dd)
-{
-}
-
-Output::~Output()
-{
- delete d;
-}
-
-Output *Output::clone() const
-{
- Output *output = new Output(new Private(*d));
- // Make sure the new output takes ownership of the cloned modes
- Q_FOREACH (Mode *mode, output->d->modeList) {
- mode->setParent(output);
- }
- if (output->d->edid) {
- output->d->edid->setParent(output);
- }
-
- return output;
-}
-
-int Output::id() const
-{
- return d->id;
-}
-
-void Output::setId(int id)
-{
- if (d->id == id) {
- return;
- }
-
- d->id = id;
-
- Q_EMIT outputChanged();
-}
-
-QString Output::name() const
-{
- return d->name;
-}
-
-void Output::setName(const QString& name)
-{
- if (d->name == name) {
- return;
- }
-
- d->name = name;
-
- Q_EMIT outputChanged();
-}
-
-Output::Type Output::type() const
-{
- return d->type;
-}
-
-void Output::setType(Type type)
-{
- if (d->type == type) {
- return;
- }
-
- d->type = type;
-
- Q_EMIT outputChanged();
-}
-
-QString Output::icon() const
-{
- return d->icon;
-}
-
-void Output::setIcon(const QString& icon)
-{
- if (d->icon == icon) {
- return;
- }
-
- d->icon = icon;
-
- Q_EMIT outputChanged();
-}
-
-Mode* Output::mode(const QString& id) const
-{
- if (!d->modeList.contains(id)) {
- return 0;
- }
-
- return d->modeList[id];
-}
-
-QHash< QString, Mode* > Output::modes() const
-{
- return d->modeList;
-}
-
-void Output::setModes(ModeList modes)
-{
- if (!d->modeList.isEmpty()) {
- qDeleteAll(d->modeList);
- }
- d->modeList = modes;
-}
-
-QString Output::currentModeId() const
-{
- return d->currentMode;
-}
-
-void Output::setCurrentModeId(const QString& mode)
-{
- if (d->currentMode == mode) {
- return;
- }
-
- d->currentMode = mode;
-
- Q_EMIT currentModeIdChanged();
-}
-
-Mode *Output::currentMode() const
-{
- return d->modeList.value(d->currentMode);
-}
-
-void Output::setPreferredModes(const QStringList &modes)
-{
- d->preferredMode = QString();
- d->preferredModes = modes;
-}
-
-QStringList Output::preferredModes() const
-{
- return d->preferredModes;
-}
-
-QString Output::preferredModeId() const
-{
- if (!d->preferredMode.isEmpty()) {
- return d->preferredMode;
- }
- if (d->preferredModes.isEmpty()) {
- return d->biggestMode(modes());
- }
-
- int area, total = 0;
- KScreen::Mode* biggest = 0;
- KScreen::Mode* candidateMode = 0;
- Q_FOREACH(const QString &modeId, d->preferredModes) {
- candidateMode = mode(modeId);
- area = candidateMode->size().width() * candidateMode->size().height();
- if (area < total) {
- continue;
- }
- if (area == total && biggest && candidateMode->refreshRate() < biggest->refreshRate()) {
- continue;
- }
- if (area == total && biggest && candidateMode->refreshRate() > biggest->refreshRate()) {
- biggest = candidateMode;
- continue;
- }
-
- total = area;
- biggest = candidateMode;
- }
-
- Q_ASSERT_X(biggest, "preferredModeId", "biggest mode must exists");
-
- d->preferredMode = biggest->id();
- return d->preferredMode;
-}
-
-Mode* Output::preferredMode() const
-{
- return d->modeList.value(preferredModeId());
-}
-
-QPoint Output::pos() const
-{
- return d->pos;
-}
-
-void Output::setPos(const QPoint& pos)
-{
- if (d->pos == pos) {
- return;
- }
-
- d->pos = pos;
-
- Q_EMIT posChanged();
-}
-
-Output::Rotation Output::rotation() const
-{
- return d->rotation;
-}
-
-void Output::setRotation(Output::Rotation rotation)
-{
- if (d->rotation == rotation) {
- return;
- }
-
- d->rotation = rotation;
-
- Q_EMIT rotationChanged();
-}
-
-bool Output::isConnected() const
-{
- return d->connected;
-}
-
-void Output::setConnected(bool connected)
-{
- if (d->connected == connected) {
- return;
- }
-
- d->connected = connected;
-
- Q_EMIT isConnectedChanged();
-}
-
-bool Output::isEnabled() const
-{
- return d->enabled;
-}
-
-void Output::setEnabled(bool enabled)
-{
- if (d->enabled == enabled) {
- return;
- }
-
- d->enabled = enabled;
-
- Q_EMIT isEnabledChanged();
-}
-
-bool Output::isPrimary() const
-{
- return d->primary;
-}
-
-void Output::setPrimary(bool primary)
-{
- if (d->primary == primary) {
- return;
- }
-
- d->primary = primary;
-
- Q_EMIT isPrimaryChanged();
-}
-
-QList<int> Output::clones() const
-{
- return d->clones;
-}
-
-void Output::setClones(QList<int> outputlist)
-{
- if (d->clones == outputlist) {
- return;
- }
-
- d->clones = outputlist;
-
- Q_EMIT clonesChanged();
-}
-
-Edid *Output::edid() const
-{
- if (d->edid == 0) {
- AbstractBackend *backend = BackendLoader::backend();
- d->edid = backend->edid(d->id);
- }
-
- return d->edid;
-}
-
-QSize Output::sizeMm() const
-{
- return d->sizeMm;
-}
-
-void Output::setSizeMm(const QSize &size)
-{
- d->sizeMm = size;
-}
-
-} //KScreen namespace
-
-QDebug operator<<(QDebug dbg, const KScreen::Output *output)
-{
- if(output) {
- dbg << "KScreen::Output(Id:" << output->id() <<", Name:" << output->name() << ")";
- } else {
- dbg << "KScreen::Output(NULL)";
- }
- return dbg;
-}
-
-#include "moc_output.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef OUTPUT_CONFIG_H
-#define OUTPUT_CONFIG_H
-
-#include "mode.h"
-#include "kscreen_export.h"
-
-#include <QtCore/QSize>
-#include <QtCore/QPoint>
-#include <QtCore/QObject>
-#include <QtCore/QMetaType>
-#include <QtCore/QPointer>
-#include <QtCore/QStringList>
-#include <QtCore/QDebug>
-
-namespace KScreen {
-
-class Edid;
-
-class KSCREEN_EXPORT Output : public QObject
-{
- Q_OBJECT
-
- public:
- Q_ENUMS(Rotation)
- Q_ENUMS(Type)
- Q_PROPERTY(int id READ id NOTIFY outputChanged)
- Q_PROPERTY(QString name READ name WRITE setName NOTIFY outputChanged)
- Q_PROPERTY(Type type READ type WRITE setType NOTIFY outputChanged)
- Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY outputChanged)
- Q_PROPERTY(ModeList modes READ modes CONSTANT)
- Q_PROPERTY(QPoint pos READ pos WRITE setPos NOTIFY posChanged)
- Q_PROPERTY(Rotation rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
- Q_PROPERTY(QString currentModeId READ currentModeId WRITE setCurrentModeId NOTIFY currentModeIdChanged)
- Q_PROPERTY(QString preferredModeId READ preferredModeId CONSTANT)
- Q_PROPERTY(bool connected READ isConnected WRITE setConnected NOTIFY isConnectedChanged)
- Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY isEnabledChanged)
- Q_PROPERTY(bool primary READ isPrimary WRITE setPrimary NOTIFY isPrimaryChanged)
- Q_PROPERTY(QList<int> clones READ clones WRITE setClones NOTIFY clonesChanged)
- Q_PROPERTY(KScreen::Edid* edid READ edid CONSTANT)
- Q_PROPERTY(QSize sizeMm READ sizeMm CONSTANT)
-
- enum Type {
- Unknown,
- VGA,
- DVI,
- DVII,
- DVIA,
- DVID,
- HDMI,
- Panel,
- TV,
- TVComposite,
- TVSVideo,
- TVComponent,
- TVSCART,
- TVC4,
- DisplayPort
- };
-
- enum Rotation {
- None = 1,
- Left = 2,
- Inverted = 4,
- Right = 8
- };
-
- explicit Output(QObject *parent = 0);
- virtual ~Output();
-
- Output* clone() const;
-
- int id() const;
- void setId(int id);
-
- QString name() const;
- void setName(const QString& name);
-
- Type type() const;
- void setType(Type type);
-
- QString icon() const;
- void setIcon(const QString& icon);
-
- Q_INVOKABLE Mode* mode(const QString &id) const;
- QHash<QString, Mode*> modes() const;
- void setModes(ModeList modes);
-
- QString currentModeId() const;
- void setCurrentModeId(const QString& mode);
- Q_INVOKABLE Mode* currentMode() const;
-
- void setPreferredModes(const QStringList &modes);
- QStringList preferredModes() const;
- /**
- * Returns the preferred mode with higer resolution and refresh
- */
- Q_INVOKABLE QString preferredModeId() const;
- /**
- * Returns KScreen::Mode associated with preferredModeId()
- */
- Q_INVOKABLE Mode* preferredMode() const;
-
- QPoint pos() const;
- void setPos(const QPoint& pos);
-
- Rotation rotation() const;
- void setRotation(Rotation rotation);
- /**
- * A comfortable function that returns true when output is not rotated
- * or is rotated upside down.
- */
- Q_INVOKABLE inline bool isHorizontal() const {
- return ((rotation() == Output::None) || (rotation() == Output::Inverted));
- }
-
- bool isConnected() const;
- void setConnected(bool connected);
-
- bool isEnabled() const;
- void setEnabled(bool enabled);
-
- bool isPrimary() const;
- void setPrimary(bool primary);
-
- QList<int> clones() const;
- void setClones(QList<int> outputlist);
-
- Edid* edid() const;
-
- QSize sizeMm() const;
- void setSizeMm(const QSize &size);
- Q_SIGNALS:
- void outputChanged();
- void posChanged();
- void currentModeIdChanged();
- void rotationChanged();
- void isConnectedChanged();
- void isEnabledChanged();
- void isPrimaryChanged();
- void clonesChanged();
-
- private:
- Q_DISABLE_COPY(Output)
-
- class Private;
- Private * const d;
-
- Output(Private *dd);
-
-};
-
-typedef QHash<int, Output*> OutputList;
-
-} //KScreen namespace
-
-KSCREEN_EXPORT QDebug operator<<(QDebug dbg, const KScreen::Output *output);
-
-Q_DECLARE_METATYPE(KScreen::OutputList)
-Q_DECLARE_METATYPE(KScreen::Output::Rotation)
-Q_DECLARE_METATYPE(KScreen::Output::Type)
-
-#endif //OUTPUT_H
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include "screen.h"
-
-namespace KScreen {
-
-class Screen::Private
-{
- public:
- Private():
- id(0),
- maxActiveOutputsCount(0)
- { }
-
- Private(const Private &other):
- id(other.id),
- maxActiveOutputsCount(other.maxActiveOutputsCount),
- currentSize(other.currentSize),
- minSize(other.minSize),
- maxSize(other.maxSize)
- {
- }
-
- int id;
- int maxActiveOutputsCount;
- QSize currentSize;
- QSize minSize;
- QSize maxSize;
-};
-
-Screen::Screen(QObject *parent)
- : QObject(parent)
- , d(new Private())
-{
-}
-
-Screen::Screen(Screen::Private *dd)
- : QObject()
- , d(dd)
-{
-}
-
-
-Screen::~Screen()
-{
- delete d;
-}
-
-Screen *Screen::clone() const
-{
- return new Screen(new Private(*d));
-}
-
-
-int Screen::id() const
-{
- return d->id;
-}
-
-void Screen::setId(int id)
-{
- d->id = id;
-}
-
-QSize Screen::currentSize() const
-{
- return d->currentSize;
-}
-
-void Screen::setCurrentSize(const QSize& currentSize)
-{
- if (d->currentSize == currentSize) {
- return;
- }
-
- d->currentSize = currentSize;
-
- Q_EMIT currentSizeChanged();
-}
-
-QSize Screen::maxSize() const
-{
- return d->maxSize;
-}
-
-void Screen::setMaxSize(const QSize& maxSize)
-{
- d->maxSize = maxSize;
-}
-
-QSize Screen::minSize() const
-{
- return d->minSize;
-}
-
-void Screen::setMinSize(const QSize& minSize)
-{
- d->minSize = minSize;
-}
-
-int Screen::maxActiveOutputsCount() const
-{
- return d->maxActiveOutputsCount;
-}
-
-void Screen::setMaxActiveOutputsCount(int maxActiveOutputsCount)
-{
- d->maxActiveOutputsCount = maxActiveOutputsCount;
-}
-
-} //KScreen namespace
-
-#include "moc_screen.cpp"
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#ifndef SCREEN_CONFIG_H
-#define SCREEN_CONFIG_H
-
-#include "kscreen_export.h"
-
-#include <QtCore/QSize>
-#include <QtCore/QObject>
-
-namespace KScreen {
-
-class KSCREEN_EXPORT Screen : public QObject
-{
- Q_OBJECT
-
- public:
- Q_PROPERTY(int id READ id CONSTANT)
- Q_PROPERTY(QSize currentSize READ currentSize WRITE setCurrentSize NOTIFY currentSizeChanged)
- Q_PROPERTY(QSize minSize READ minSize CONSTANT)
- Q_PROPERTY(QSize maxSize READ maxSize CONSTANT)
- Q_PROPERTY(int maxActiveOutputsCount READ maxActiveOutputsCount CONSTANT)
-
- explicit Screen(QObject *parent = 0);
- virtual ~Screen();
-
- Screen* clone() const;
-
- int id() const;
- void setId(int id);
-
- QSize currentSize() const;
- void setCurrentSize(const QSize& currentSize);
-
- QSize minSize() const;
- void setMinSize(const QSize& minSize);
-
- QSize maxSize() const;
- void setMaxSize(const QSize& maxSize);
-
- int maxActiveOutputsCount() const;
- void setMaxActiveOutputsCount(int maxActiveOutputsCount);
-
- Q_SIGNALS:
- void currentSizeChanged();
-
- private:
- Q_DISABLE_COPY(Screen)
-
- class Private;
- Private * const d;
-
- Screen(Private *dd);
-};
-
-} //KScreen namespace
-#endif //SCREEN_H
+++ /dev/null
-cmake_policy(SET CMP0005 NEW)
-add_definitions(-DTEST_DATA="${CMAKE_CURRENT_SOURCE_DIR}/configs/")
-
-include_directories(${CMAKE_CURRENT_BINARY_DIR} ${X11_Xrandr_INCLUDE_PATH})
-
-macro(KSCREEN_TESTS)
- foreach(_testname ${ARGN})
- kde4_add_test(libkscreen-${_testname} ${_testname}.cpp)
- target_link_libraries(libkscreen-${_testname} ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} kscreen)
- endforeach(_testname)
-endmacro(KSCREEN_TESTS)
-
-
-KSCREEN_TESTS(testscreenconfig)
-
-if (ENABLE_XRANDR_TESTS)
- KSCREEN_TESTS(testxrandr)
-endif()
+++ /dev/null
-{
- "screen" :
- {
- "id" : 1,
- "maxSize" : {
- "width" : 8192,
- "height" : 8192
- },
- "minSize" : {
- "width" : 320,
- "height" : 200
- },
- "currentSize" : {
- "width" : 1024,
- "height" : 768
- },
- "maxActiveOutputsCount": 2
- },
- "outputs" :
- [
- {
- "id" : 1,
- "name" : "LVDS1",
- "type" : "LVDS",
- "modes" :
- [
- {
- "id" : 3,
- "name" : "1280x800",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1280,
- "height" : 800
- }
- },
- {
- "id" : 2,
- "name" : "1024x768",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1024,
- "height" : 768
- }
- },
- {
- "id" : 1,
- "name" : "800x600",
- "refreshRate" : 60,
- "size" : {
- "width" : 800,
- "height" : 600
- }
- }
- ],
- "pos" : {
- "x" : 0,
- "y" : 0
- },
- "clones" : [2],
- "currentModeId" : 2,
- "preferredModes" : [2],
- "rotation" : 1,
- "connected" : true,
- "enabled" : true,
- "primary" : true,
- "edid" : "AP///////wBMLcMFMzJGRQkUAQMOMx14Ku6Ro1RMmSYPUFQjCACBAIFAgYCVAKlAswABAQEBAjqAGHE4LUBYLEUA/h8RAAAeAAAA/QA4PB5REQAKICAgICAgAAAA/ABTeW5jTWFzdGVyCiAgAAAA/wBIOU1aMzAyMTk2CiAgAC4="
- },
- {
- "id" : 2,
- "name" : "HDMI1",
- "type" : "HDMI",
- "modes" :
- [
- {
- "id" : 4,
- "name" : "1920x1080",
- "refreshRate" : 60,
- "size" : {
- "width" : 1920,
- "height" : 1080
- }
- },
- {
- "id" : 3,
- "name" : "1600x1200",
- "refreshRate" : 60,
- "size" : {
- "width" : 1600,
- "height" : 1200
- }
- },
- {
- "id" : 2,
- "name" : "1024x768",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1024,
- "height" : 768
- }
- },
- {
- "id" : 1,
- "name" : "800x600",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 800,
- "height" : 600
- }
- }
- ],
- "pos" : {
- "x" : 1280,
- "y" : 0
- },
- "currentModeId" : 2,
- "preferredModes" : [2],
- "rotation" : 1,
- "connected" : true,
- "enabled" : true,
- "primary" : false,
- "edid" : "AP///////wAQrBbwTExLQQ4WAQOANCB46h7Frk80sSYOUFSlSwCBgKlA0QBxTwEBAQEBAQEBKDyAoHCwI0AwIDYABkQhAAAaAAAA/wBGNTI1TTI0NUFLTEwKAAAA/ABERUxMIFUyNDEwCiAgAAAA/QA4TB5REQAKICAgICAgAToCAynxUJAFBAMCBxYBHxITFCAVEQYjCQcHZwMMABAAOC2DAQAA4wUDAQI6gBhxOC1AWCxFAAZEIQAAHgEdgBhxHBYgWCwlAAZEIQAAngEdAHJR0B4gbihVAAZEIQAAHowK0Iog4C0QED6WAAZEIQAAGAAAAAAAAAAAAAAAAAAAPg=="
- }
- ]
-}
+++ /dev/null
-{
- "screen" :
- {
- "id" : 1,
- "maxSize" : {
- "width" : 8192,
- "height" : 8192
- },
- "minSize" : {
- "width" : 320,
- "height" : 200
- },
- "currentSize" : {
- "width" : 3200,
- "height" : 1880
- },
- "maxActiveOutputsCount": 2
- },
- "outputs" :
- [
- {
- "id" : 1,
- "name" : "LVDS1",
- "type" : "LVDS",
- "modes" :
- [
- {
- "id" : 3,
- "name" : "1280x800",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1280,
- "height" : 800
- }
- },
- {
- "id" : 2,
- "name" : "1024x768",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1024,
- "height" : 768
- }
- },
- {
- "id" : 1,
- "name" : "800x600",
- "refreshRate" : 60,
- "size" : {
- "width" : 800,
- "height" : 600
- }
- }
- ],
- "pos" : {
- "x" : 0,
- "y" : 0
- },
- "currentModeId" : 3,
- "preferredModes" : [2],
- "rotation" : 1,
- "connected" : true,
- "enabled" : true,
- "primary" : true,
- "edid" : "AP///////wBMLcMFMzJGRQkUAQMOMx14Ku6Ro1RMmSYPUFQjCACBAIFAgYCVAKlAswABAQEBAjqAGHE4LUBYLEUA/h8RAAAeAAAA/QA4PB5REQAKICAgICAgAAAA/ABTeW5jTWFzdGVyCiAgAAAA/wBIOU1aMzAyMTk2CiAgAC4="
- },
- {
- "id" : 2,
- "name" : "HDMI1",
- "type" : "HDMI",
- "modes" :
- [
- {
- "id" : 4,
- "name" : "1920x1080",
- "refreshRate" : 60,
- "size" : {
- "width" : 1920,
- "height" : 1080
- }
- },
- {
- "id" : 3,
- "name" : "1600x1200",
- "refreshRate" : 60,
- "size" : {
- "width" : 1600,
- "height" : 1200
- }
- },
- {
- "id" : 2,
- "name" : "1024x768",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1024,
- "height" : 768
- }
- },
- {
- "id" : 1,
- "name" : "800x600",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 800,
- "height" : 600
- }
- }
- ],
- "pos" : {
- "x" : 1280,
- "y" : 0
- },
- "currentModeId" : 4,
- "preferredModes" : [4],
- "rotation" : 1,
- "connected" : true,
- "enabled" : true,
- "primary" : false,
- "edid" : "AP///////wAQrBbwTExLQQ4WAQOANCB46h7Frk80sSYOUFSlSwCBgKlA0QBxTwEBAQEBAQEBKDyAoHCwI0AwIDYABkQhAAAaAAAA/wBGNTI1TTI0NUFLTEwKAAAA/ABERUxMIFUyNDEwCiAgAAAA/QA4TB5REQAKICAgICAgAToCAynxUJAFBAMCBxYBHxITFCAVEQYjCQcHZwMMABAAOC2DAQAA4wUDAQI6gBhxOC1AWCxFAAZEIQAAHgEdgBhxHBYgWCwlAAZEIQAAngEdAHJR0B4gbihVAAZEIQAAHowK0Iog4C0QED6WAAZEIQAAGAAAAAAAAAAAAAAAAAAAPg=="
- }
- ]
-}
+++ /dev/null
-{
- "screen" :
- {
- "id" : 1,
- "maxSize" : {
- "width" : 8192,
- "height" : 8192
- },
- "minSize" : {
- "width" : 320,
- "height" : 200
- },
- "currentSize" : {
- "width" : 1280,
- "height" : 800
- },
- "maxActiveOutputsCount": 2
- },
- "outputs" :
- [
- {
- "id" : 1,
- "name" : "LVDS1",
- "type" : "LVDS",
- "modes" :
- [
- {
- "id" : 3,
- "name" : "1280x800",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1280,
- "height" : 800
- }
- },
- {
- "id" : 2,
- "name" : "1024x768",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1024,
- "height" : 768
- }
- },
- {
- "id" : 1,
- "name" : "800x600",
- "refreshRate" : 60,
- "size" : {
- "width" : 800,
- "height" : 600
- }
- }
- ],
- "pos" : {
- "x" : 0,
- "y" : 0
- },
- "currentModeId" : 3,
- "preferredModes" : [],
- "rotation" : 1,
- "connected" : true,
- "enabled" : true,
- "primary" : true,
- "edid" : "AP///////wBMLcMFMzJGRQkUAQMOMx14Ku6Ro1RMmSYPUFQjCACBAIFAgYCVAKlAswABAQEBAjqAGHE4LUBYLEUA/h8RAAAeAAAA/QA4PB5REQAKICAgICAgAAAA/ABTeW5jTWFzdGVyCiAgAAAA/wBIOU1aMzAyMTk2CiAgAC4="
- }
- ]
-}
+++ /dev/null
-{
- "screen" :
- {
- "id" : 1,
- "maxSize" : {
- "width" : 8192,
- "height" : 8192
- },
- "minSize" : {
- "width" : 320,
- "height" : 200
- },
- "currentSize" : {
- "width" : 1280,
- "height" : 800
- },
- "maxActiveOutputsCount": 2
- },
- "outputs" :
- [
- {
- "id" : 1,
- "name" : "LVDS1",
- "type" : "LVDS",
- "modes" :
- [
- {
- "id" : 3,
- "name" : "1280x800",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1280,
- "height" : 800
- }
- },
- {
- "id" : 2,
- "name" : "1024x768",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1024,
- "height" : 768
- }
- },
- {
- "id" : 1,
- "name" : "800x600",
- "refreshRate" : 60,
- "size" : {
- "width" : 800,
- "height" : 600
- }
- }
- ],
- "pos" : {
- "x" : 0,
- "y" : 0
- },
- "currentModeId" : 3,
- "preferredModes" : [3],
- "rotation" : 1,
- "connected" : true,
- "enabled" : true,
- "primary" : true,
- "edid" : "AP///////wBMLcMFMzJGRQkUAQMOMx14Ku6Ro1RMmSYPUFQjCACBAIFAgYCVAKlAswABAQEBAjqAGHE4LUBYLEUA/h8RAAAeAAAA/QA4PB5REQAKICAgICAgAAAA/ABTeW5jTWFzdGVyCiAgAAAA/wBIOU1aMzAyMTk2CiAgAC4="
- }
- ]
-}
+++ /dev/null
-{
- "screen" :
- {
- "id" : 1,
- "maxSize" : {
- "width" : 8192,
- "height" : 8192
- },
- "minSize" : {
- "width" : 320,
- "height" : 200
- },
- "currentSize" : {
- "width" : 1280,
- "height" : 800
- },
- "maxActiveOutputsCount": 2
- },
- "outputs" :
- [
- {
- "id" : 2,
- "name" : "LVDS1",
- "type" : "LVDS",
- "modes" :
- [
- {
- "id" : 3,
- "name" : "128000x80000",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 128000,
- "height" : 80000
- }
- },
- {
- "id" : 42,
- "name" : "1280x800",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1280,
- "height" : 800
- }
- },
- {
- "id" : 2,
- "name" : "1024x768",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1024,
- "height" : 768
- }
- },
- {
- "id" : 1,
- "name" : "800x600",
- "refreshRate" : 60,
- "size" : {
- "width" : 800,
- "height" : 600
- }
- }
- ],
- "pos" : {
- "x" : 0,
- "y" : 0
- },
- "preferredModes" : [42],
- "rotation" : 1,
- "connected" : true,
- "enabled" : true,
- "primary" : true,
- "edid" : "AP///////wBMLcMFMzJGRQkUAQMOMx14Ku6Ro1RMmSYPUFQjCACBAIFAgYCVAKlAswABAQEBAjqAGHE4LUBYLEUA/h8RAAAeAAAA/QA4PB5REQAKICAgICAgAAAA/ABTeW5jTWFzdGVyCiAgAAAA/wBIOU1aMzAyMTk2CiAgAC4="
- }
- ]
-}
+++ /dev/null
-{
- "screen" :
- {
- "id" : 1,
- "maxSize" : {
- "width" : 8192,
- "height" : 8192
- },
- "minSize" : {
- "width" : 320,
- "height" : 200
- },
- "currentSize" : {
- "width" : 3200,
- "height" : 1880
- },
- "maxActiveOutputsCount": 1
- },
- "outputs" :
- [
- {
- "id" : 1,
- "name" : "LVDS1",
- "type" : "LVDS",
- "modes" :
- [
- {
- "id" : 3,
- "name" : "1280x800",
- "refreshRate" : 59.9,
- "size" : {
- "width" : 1280,
- "height" : 800
- }
- }
- ],
- "pos" : {
- "x" : 0,
- "y" : 0
- },
- "currentModeId" : 3,
- "preferredModes" : [3],
- "rotation" : 1,
- "connected" : true,
- "enabled" : true,
- "primary" : true,
- "edid" : "AP///////wBMLcMFMzJGRQkUAQMOMx14Ku6Ro1RMmSYPUFQjCACBAIFAgYCVAKlAswABAQEBAjqAGHE4LUBYLEUA/h8RAAAeAAAA/QA4PB5REQAKICAgICAgAAAA/ABTeW5jTWFzdGVyCiAgAAAA/wBIOU1aMzAyMTk2CiAgAC4="
- },
- {
- "id" : 2,
- "name" : "HDMI1",
- "type" : "HDMI",
- "modes" :
- [
- {
- "id" : 4,
- "name" : "1920x1080",
- "refreshRate" : 60,
- "size" : {
- "width" : 1920,
- "height" : 1080
- }
- }
- ],
- "pos" : {
- "x" : 1280,
- "y" : 0
- },
- "currentModeId" : 4,
- "preferredModes" : [4],
- "rotation" : 1,
- "connected" : true,
- "enabled" : true,
- "primary" : false,
- "edid" : "AP///////wAQrBbwTExLQQ4WAQOANCB46h7Frk80sSYOUFSlSwCBgKlA0QBxTwEBAQEBAQEBKDyAoHCwI0AwIDYABkQhAAAaAAAA/wBGNTI1TTI0NUFLTEwKAAAA/ABERUxMIFUyNDEwCiAgAAAA/QA4TB5REQAKICAgICAgAToCAynxUJAFBAMCBxYBHxITFCAVEQYjCQcHZwMMABAAOC2DAQAA4wUDAQI6gBhxOC1AWCxFAAZEIQAAHgEdgBhxHBYgWCwlAAZEIQAAngEdAHJR0B4gbihVAAZEIQAAHowK0Iog4C0QED6WAAZEIQAAGAAAAAAAAAAAAAAAAAAAPg=="
- }
- ]
-}
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#include <QtTest/QtTest>
-#include <QtCore/QObject>
-
-#include "../src/screen.h"
-#include "../src/config.h"
-#include "../src/output.h"
-#include "../src/mode.h"
-
-using namespace KScreen;
-
-class testScreenConfig : public QObject
-{
- Q_OBJECT
-
-private Q_SLOTS:
- void initTestCase();
- void singleOutput();
- void singleOutputWithoutPreferred();
- void multiOutput();
- void clonesOutput();
- void configCanBeApplied();
-};
-
-void testScreenConfig::initTestCase()
-{
- setenv("KSCREEN_BACKEND", "Fake", 1);
-}
-
-void testScreenConfig::singleOutput()
-{
- //json file for the fake backend
- QByteArray path(TEST_DATA);
- path.append("/singleoutput.json");
- setenv("TEST_DATA", path, 1);
-
-// QVERIFY2(kscreen, KScreen::errorString().toLatin1());
-
-// QVERIFY2(!kscreen->backend().isEmpty(), "No backend loaded");
-
- Config *config = Config::current();
-
- Screen* screen = config->screen();
-
- QCOMPARE(screen->minSize(), QSize(320, 200));
- QCOMPARE(screen->maxSize(), QSize(8192, 8192));
- QCOMPARE(screen->currentSize(), QSize(1280, 800));
-
- QCOMPARE(config->outputs().count(), 1);
-
- Output *output = config->outputs().take(1);
-
- QCOMPARE(output->name(), QString("LVDS1"));
- QCOMPARE(output->type(), Output::Panel);
- QCOMPARE(output->modes().count(), 3);
- QCOMPARE(output->pos(), QPoint(0, 0));
- QCOMPARE(output->currentModeId(), QLatin1String("3"));
- QCOMPARE(output->preferredModeId(), QLatin1String("3"));
- QCOMPARE(output->rotation(), Output::None);
- QCOMPARE(output->isConnected(), true);
- QCOMPARE(output->isEnabled(), true);
- QCOMPARE(output->isPrimary(), true);
- //QCOMPARE(output->isEmbedded(), true);
- QVERIFY2(output->clones().isEmpty(), "In singleOutput is impossible to have clones");
-
- Mode* mode = output->currentMode();
- QCOMPARE(mode->size(), QSize(1280, 800));
- QCOMPARE(mode->refreshRate(), (float)59.9);
-}
-
-void testScreenConfig::singleOutputWithoutPreferred()
-{
- QByteArray path(TEST_DATA);
- path.append("/singleOutputWithoutPreferred.json");
- setenv("TEST_DATA", path, 1);
-
- Config* config = Config::current();
- Output* output = config->outputs().take(1);
-
- QVERIFY(output->preferredModes().isEmpty());
- QCOMPARE(output->preferredModeId(), QLatin1String("3"));
-}
-
-void testScreenConfig::multiOutput()
-{
- QByteArray path(TEST_DATA);
- path.append("/multipleoutput.json");
- setenv("TEST_DATA", path, 1);
-
- Config *config = Config::current();
-
- Screen* screen = config->screen();
-
- QCOMPARE(screen->minSize(), QSize(320, 200));
- QCOMPARE(screen->maxSize(), QSize(8192, 8192));
- QCOMPARE(screen->currentSize(), QSize(3200, 1880));
-
- QCOMPARE(config->outputs().count(), 2);
-
- Output *output = config->outputs().take(2);
-
- QCOMPARE(output->name(), QString("HDMI1"));
- QCOMPARE(output->type(), Output::HDMI);
- QCOMPARE(output->modes().count(), 4);
- QCOMPARE(output->pos(), QPoint(0, 0));
- QCOMPARE(output->currentModeId(), QLatin1String("4"));
- QCOMPARE(output->preferredModeId(), QLatin1String("4"));
- QCOMPARE(output->rotation(), Output::None);
- QCOMPARE(output->isConnected(), true);
- QCOMPARE(output->isEnabled(), true);
- QCOMPARE(output->isPrimary(), false);
- QVERIFY2(output->clones().isEmpty(), "This simulates extended output, no clones");
-
- Mode* mode = output->currentMode();
- QCOMPARE(mode->size(), QSize(1920, 1080));
- QCOMPARE(mode->refreshRate(), (float)60.0);
-}
-
-void testScreenConfig::clonesOutput()
-{
- QByteArray path(TEST_DATA);
- path.append("/multipleclone.json");
- setenv("TEST_DATA", path, 1);
-
- Config *config = Config::current();
- Screen* screen = config->screen();
-
- QCOMPARE(screen->minSize(), QSize(320, 200));
- QCOMPARE(screen->maxSize(), QSize(8192, 8192));
- QCOMPARE(screen->currentSize(), QSize(1024, 768));
-
- Output* one = config->outputs()[1];
- Output* two = config->outputs()[2];
-
- QCOMPARE(one->currentMode()->size(), two->currentMode()->size());
- QCOMPARE(one->clones().count(), 1);
- QCOMPARE(one->clones().first(), two->id());
- QVERIFY2(two->clones().isEmpty(), "Output two should have no clones");
-}
-
-void testScreenConfig::configCanBeApplied()
-{
- QByteArray path(TEST_DATA);
- path.append("/singleoutputBroken.json");
- setenv("TEST_DATA", path, 1);
- Config* brokenConfig = Config::current();
-
- path = TEST_DATA;
- path.append("/singleoutput.json");
- setenv("TEST_DATA", path, 1);
- Config* currentConfig = Config::current();
-
- Output* primaryBroken = brokenConfig->outputs()[2];
- Output* currentPrimary = currentConfig->outputs()[1];
-
- QVERIFY(!Config::canBeApplied(brokenConfig));
- primaryBroken->setId(currentPrimary->id());
- QVERIFY(!Config::canBeApplied(brokenConfig));
- primaryBroken->setConnected(currentPrimary->isConnected());
- QVERIFY(!Config::canBeApplied(brokenConfig));
- primaryBroken->setCurrentModeId(QLatin1String("42"));
- QVERIFY(!Config::canBeApplied(brokenConfig));
- primaryBroken->setCurrentModeId(currentPrimary->currentModeId());
- QVERIFY(!Config::canBeApplied(brokenConfig));
- primaryBroken->mode(QLatin1String("3"))->setSize(QSize(1280, 800));
- QVERIFY(Config::canBeApplied(brokenConfig));
-
-
- path = TEST_DATA;
- path.append("/tooManyOutputs.json");
- setenv("TEST_DATA", path, 1);
- brokenConfig = Config::current();
-
- int enabledOutputsCount = 0;
- Q_FOREACH (Output *output, brokenConfig->outputs()) {
- if (output->isEnabled()) {
- ++enabledOutputsCount;
- }
- }
- QVERIFY(brokenConfig->screen()->maxActiveOutputsCount() < enabledOutputsCount);
- QVERIFY(!Config::canBeApplied(brokenConfig));
-}
-
-QTEST_MAIN(testScreenConfig)
-
-#include "testscreenconfig.moc"
+++ /dev/null
-/*************************************************************************************
- * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> *
- * *
- * This library is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public *
- * License as published by the Free Software Foundation; either *
- * version 2.1 of the License, or (at your option) any later version. *
- * *
- * This library 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 *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
- *************************************************************************************/
-
-#define QT_GUI_LIB
-
-#include <QtTest/QtTest>
-#include <QtCore/QObject>
-
-#include "../src/config.h"
-#include "../src/output.h"
-#include "../src/mode.h"
-
-using namespace KScreen;
-
-class testXRandR : public QObject
-{
- Q_OBJECT
-
-private Q_SLOTS:
- void initTestCase();
- void singleOutput();
-
-private:
- QProcess m_process;
-};
-
-void testXRandR::initTestCase()
-{
-}
-
-void testXRandR::singleOutput()
-{
- setenv("KSCREEN_BACKEND", "XRandR", 1);
- Config *config = Config::current();
- if (!config) {
- QSKIP("XRandR X extension is not available", SkipAll);
- }
-
- QCOMPARE(config->outputs().count(), 1);
-
- Output *output = config->outputs().take(327);
-
- QCOMPARE(output->name(), QString("default"));
- QCOMPARE(output->type(), Output::Unknown);
- QCOMPARE(output->modes().count(), 15);
- QCOMPARE(output->pos(), QPoint(0, 0));
- QCOMPARE(output->currentModeId(), QLatin1String("338"));
- QCOMPARE(output->rotation(), Output::None);
- QCOMPARE(output->isConnected(), true);
- QCOMPARE(output->isEnabled(), true);
- QCOMPARE(output->isPrimary(), false);
- QVERIFY2(output->clones().isEmpty(), "In singleOutput is impossible to have clones");
-}
-
-QTEST_MAIN(testXRandR)
-
-#include "testxrandr.moc"
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${KDE4_INCLUDES}
- ${CMAKE_SOURCE_DIR}/libkscreen
${CMAKE_SOURCE_DIR}
)
target_link_libraries(okularcore
${KDE4_KIO_LIBS}
- ${KDE4_PHONON_LIBRARY}
${MATH_LIB}
KDE4::kmediaplayer
- kscreen
)
set_target_properties(okularcore PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION})
kde4_add_plugin(okularpart SHARED ${okularpart_SRCS})
-target_link_libraries(okularpart okularcore ${KDE4_KPARTS_LIBS} ${KDE4_KPRINTUTILS_LIBS} ${MATH_LIB} ${KDE4_PHONON_LIBRARY} ${KDE4_SOLID_LIBRARY})
+target_link_libraries(okularpart okularcore ${KDE4_KPARTS_LIBS} ${KDE4_KPRINTUTILS_LIBS} ${MATH_LIB} ${KDE4_SOLID_LIBRARY})
install(TARGETS okularpart DESTINATION ${PLUGIN_INSTALL_DIR})
#include <QIODevice>
#ifdef Q_WS_X11
- #include "config-okular.h"
- #include <libkscreen/src/config.h>
- #include <libkscreen/src/edid.h>
#include <QX11Info>
#endif
-#ifdef Q_WS_MAC
-#include <ApplicationServices/ApplicationServices.h>
-#include <IOKit/graphics/IOGraphicsLib.h>
-#endif
-
-
using namespace Okular;
}
#if defined(Q_WS_X11)
-
double Utils::dpiX()
{
return QX11Info::appDpiX();
{
if (widgetOnScreen)
{
- // Firstly try to retrieve DPI via LibKScreen
- KScreen::Config* config = KScreen::Config::current();
- if (config) {
- KScreen::OutputList outputs = config->outputs();
- QPoint globalPos = widgetOnScreen->parentWidget() ?
- widgetOnScreen->mapToGlobal(widgetOnScreen->pos()):
- widgetOnScreen->pos();
- QRect widgetRect(globalPos, widgetOnScreen->size());
-
- KScreen::Output* selectedOutput = 0;
- int maxArea = 0;
- Q_FOREACH(KScreen::Output *output, outputs)
- {
- if (output->currentMode())
- {
- QRect outputRect(output->pos(),output->currentMode()->size());
- QRect intersection = outputRect.intersected(widgetRect);
- int area = intersection.width()*intersection.height();
- if (area > maxArea)
- {
- maxArea = area;
- selectedOutput = output;
- }
- }
- }
-
- if (selectedOutput)
- {
- kDebug() << "Found widget at output #" << selectedOutput->id();
- QRect outputRect(selectedOutput->pos(),selectedOutput->currentMode()->size());
- QSize szMM = selectedOutput->sizeMm();
- kDebug() << "Output size is (mm) " << szMM;
- kDebug() << "Output rect is " << outputRect;
- if (selectedOutput->edid()) {
- kDebug() << "EDID WxH (cm): " << selectedOutput->edid()->width() << 'x' << selectedOutput->edid()->height();
- }
- if (szMM.width() > 0 && szMM.height() > 0 && outputRect.width() > 0 && outputRect.height() > 0
- && selectedOutput->edid()
- && qAbs(static_cast<int>(selectedOutput->edid()->width()*10) - szMM.width()) < 10
- && qAbs(static_cast<int>(selectedOutput->edid()->height()*10) - szMM.height()) < 10)
- {
- // sizes in EDID seem to be consistent
- QSizeF res(static_cast<qreal>(outputRect.width())*25.4/szMM.width(),
- static_cast<qreal>(outputRect.height())*25.4/szMM.height());
- if (!selectedOutput->isHorizontal())
- {
- kDebug() << "Output is vertical, transposing DPI rect";
- res.transpose();
- }
- if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
- return res;
- } else {
- kDebug() << "KScreen calculation returned a non square dpi." << res << ". Falling back";
- }
- }
- }
- else
- {
- kDebug() << "Didn't find a KScreen selectedOutput to calculate DPI. Falling back";
- }
- }
- else
- {
- kDebug() << "Didn't find a KScreen config to calculate DPI. Falling back";
+ // Firstly try to retrieve DPI via QWidget::x11Info()
+ const QX11Info &info = widgetOnScreen->x11Info();
+ QSizeF res = QSizeF(info.appDpiX(info.screen()), info.appDpiY(info.screen()));
+ if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
+ return res;
+ } else {
+ kDebug() << "QX11Info calculation from widget returned a non square dpi." << res << ". Falling back";
}
}
- // this is also fallback for LibKScreen branch if KScreen::Output
- // for particular widget was not found
+ // Fallback if particular widget is invalid or calculation was not square
QSizeF res = QSizeF(realDpiX(), realDpiY());
if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
return res;
res = QSizeF(72, 72);
return res;
}
-
-#elif defined(Q_WS_MAC)
- /*
- * Code copied from http://developer.apple.com/qa/qa2001/qa1217.html
- */
- // Handy utility function for retrieving an int from a CFDictionaryRef
- static int GetIntFromDictionaryForKey( CFDictionaryRef desc, CFStringRef key )
- {
- CFNumberRef value;
- int num = 0;
- if ( (value = (CFNumberRef)CFDictionaryGetValue(desc, key)) == NULL || CFGetTypeID(value) != CFNumberGetTypeID())
- return 0;
- CFNumberGetValue(value, kCFNumberIntType, &num);
- return num;
- }
-
- static CGDisplayErr GetDisplayDPI( CFDictionaryRef displayModeDict, CGDirectDisplayID displayID,
- double *horizontalDPI, double *verticalDPI )
- {
- CGDisplayErr err = kCGErrorFailure;
- io_connect_t displayPort;
- CFDictionaryRef displayDict;
-
- // Grab a connection to IOKit for the requested display
- displayPort = CGDisplayIOServicePort( displayID );
- if ( displayPort != MACH_PORT_NULL )
- {
- // Find out what IOKit knows about this display
- displayDict = IODisplayCreateInfoDictionary(displayPort, 0);
- if ( displayDict != NULL )
- {
- const double mmPerInch = 25.4;
- double horizontalSizeInInches =
- (double)GetIntFromDictionaryForKey(displayDict,
- CFSTR(kDisplayHorizontalImageSize)) / mmPerInch;
- double verticalSizeInInches =
- (double)GetIntFromDictionaryForKey(displayDict,
- CFSTR(kDisplayVerticalImageSize)) / mmPerInch;
-
- // Make sure to release the dictionary we got from IOKit
- CFRelease(displayDict);
-
- // Now we can calculate the actual DPI
- // with information from the displayModeDict
- *horizontalDPI =
- (double)GetIntFromDictionaryForKey( displayModeDict, kCGDisplayWidth )
- / horizontalSizeInInches;
- *verticalDPI = (double)GetIntFromDictionaryForKey( displayModeDict,
- kCGDisplayHeight ) / verticalSizeInInches;
- err = CGDisplayNoErr;
- }
- }
- return err;
- }
-
-double Utils::dpiX()
-{
- double x,y;
- CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay),
- kCGDirectMainDisplay,
- &x, &y );
-
- return err == CGDisplayNoErr ? x : 72.0;
-}
-
-double Utils::dpiY()
-{
- double x,y;
- CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay),
- kCGDirectMainDisplay,
- &x, &y );
-
- return err == CGDisplayNoErr ? y : 72.0;
-}
-
-double Utils::realDpiX()
-{
- return dpiX();
-}
-
-double Utils::realDpiY()
-{
- return dpiY();
-}
-
-QSizeF Utils::realDpi(QWidget*)
-{
- return QSizeF(realDpiX(), realDpiY());
-}
#else
double Utils::dpiX()
{
return QSizeF(realDpiX(), realDpiY());
}
-#endif
+#endif // Q_WS_X11
inline static bool isWhite( QRgb argb ) {
return ( argb & 0xFFFFFF ) == 0xFFFFFF; // ignore alpha