commit 48371bd9ee18df6330d0959cc1389e5e761cfe08 Author: craft Date: Mon Feb 23 00:02:30 2026 +0100 initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5bb53c2 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Tablet Mapper - PyQt6 application for mapping graphics tablet layouts + +
+ + + +
+ +This application makes it easy to configure keybindings for multi-monitor layouts with xsetwacom-compatible tablets. + +Integrates with xrandr for screen detection and xbindkeys for keybindings + +
+ +Created with Claude Sonnet 4.6 + diff --git a/docs/screenshot.png b/docs/screenshot.png new file mode 100644 index 0000000..a38f5af Binary files /dev/null and b/docs/screenshot.png differ diff --git a/tabletmapper.py b/tabletmapper.py new file mode 100644 index 0000000..878e4f0 --- /dev/null +++ b/tabletmapper.py @@ -0,0 +1,1347 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-3.0-or-later +# SPDX-FileCopyrightText: 2026 Martin Petersson martin-petersson-art@proton.me> +""" +Tablet Mapper - PyQt6 application for mapping graphics tablet layouts +Supports Wacom and other xsetwacom-compatible tablets +Integrates with xrandr for screen detection and xbindkeys for keybindings +""" + +import sys +import subprocess +import re +import json +import os +from dataclasses import dataclass, field, asdict +from typing import Optional +from PyQt6.QtWidgets import ( + QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, + QPushButton, QLabel, QLineEdit, QComboBox, QGroupBox, QScrollArea, + QSplitter, QTextEdit, QMessageBox, QDialog, QFormLayout, QSpinBox, + QDialogButtonBox, QFrame, QSizePolicy, QTabWidget, QListWidget, + QListWidgetItem, QCheckBox, QToolButton, QMenu +) +from PyQt6.QtCore import Qt, QRect, QPoint, QSize, pyqtSignal, QTimer +from PyQt6.QtGui import QPainter, QColor, QFont, QPen, QBrush, QFontMetrics, QAction, QKeySequence + + +# ───────────────────────────────────────────── +# Data classes +# ───────────────────────────────────────────── + +@dataclass +class Monitor: + name: str # e.g. "HDMI-1" + x: int + y: int + width: int + height: int + primary: bool = False + + @property + def rect(self) -> QRect: + return QRect(self.x, self.y, self.width, self.height) + + def __str__(self): + return f"{self.name} {self.width}x{self.height}+{self.x}+{self.y}" + + +TABLET_RATIO_W = 16 +TABLET_RATIO_H = 10 + + +@dataclass +class TabletMapping: + name: str # user label, e.g. "All Screens" + monitor_names: list[str] # empty = full desktop, else specific monitors + keybinding: str = "" # xbindkeys keycode string + tablet_device: str = "" # xsetwacom device name + + # Aspect ratio correction + aspect_correct: bool = False # whether to apply correction + aspect_expand: str = "width" # "width" or "height" — which dimension to expand + aspect_anchor: str = "top-left" # "top-left" or "center" + + def _bounding_box(self, monitors: list[Monitor]) -> tuple[int, int, int, int]: + """Return (x0, y0, w, h) bounding box for this mapping's target monitors.""" + if not self.monitor_names: + if not monitors: + return (0, 0, 0, 0) + x0 = min(m.x for m in monitors) + y0 = min(m.y for m in monitors) + x1 = max(m.x + m.width for m in monitors) + y1 = max(m.y + m.height for m in monitors) + return (x0, y0, x1 - x0, y1 - y0) + targets = [m for m in monitors if m.name in self.monitor_names] + if not targets: + return (0, 0, 0, 0) + x0 = min(m.x for m in targets) + y0 = min(m.y for m in targets) + x1 = max(m.x + m.width for m in targets) + y1 = max(m.y + m.height for m in targets) + return (x0, y0, x1 - x0, y1 - y0) + + def _apply_aspect_correction(self, x: int, y: int, w: int, h: int) -> tuple[int, int, int, int]: + """Expand one dimension so the geometry matches the tablet's 16:10 ratio. + + The screen pixels stay the same; the geometry rectangle grows so that + the tablet's full physical area corresponds to the expanded region — + meaning the stylus can reach pixels outside the mapped screen. + """ + if self.aspect_expand == "width": + # Derive width from height: w = h * 16/10 + new_w = round(h * TABLET_RATIO_W / TABLET_RATIO_H) + delta = new_w - w + if self.aspect_anchor == "center": + x = x - delta // 2 + # anchor top-left: x stays, expansion goes rightward + w = new_w + else: + # Derive height from width: h = w * 10/16 + new_h = round(w * TABLET_RATIO_H / TABLET_RATIO_W) + delta = new_h - h + if self.aspect_anchor == "center": + y = y - delta // 2 + h = new_h + return (x, y, w, h) + + def area_string(self, monitors: list[Monitor]) -> str: + """Return xsetwacom MapToOutput geometry string (WIDTHxHEIGHT+X+Y).""" + x, y, w, h = self._bounding_box(monitors) + if w == 0 or h == 0: + return "" + if self.aspect_correct: + x, y, w, h = self._apply_aspect_correction(x, y, w, h) + return f"{w}x{h}+{x}+{y}" + + def corrected_rect(self, monitors: list[Monitor]) -> Optional[QRect]: + """Return the aspect-corrected geometry as a QRect for preview drawing.""" + x, y, w, h = self._bounding_box(monitors) + if w == 0 or h == 0: + return None + if self.aspect_correct: + x, y, w, h = self._apply_aspect_correction(x, y, w, h) + return QRect(x, y, w, h) + + +@dataclass +class AppConfig: + tablet_device: str = "" + mappings: list[TabletMapping] = field(default_factory=list) + + def to_dict(self): + return { + "tablet_device": self.tablet_device, + "mappings": [asdict(m) for m in self.mappings], + } + + @classmethod + def from_dict(cls, d: dict) -> "AppConfig": + cfg = cls(tablet_device=d.get("tablet_device", "")) + for md in d.get("mappings", []): + md.setdefault("aspect_correct", False) + md.setdefault("aspect_expand", "width") + md.setdefault("aspect_anchor", "top-left") + cfg.mappings.append(TabletMapping(**md)) + return cfg + + +CONFIG_PATH = os.path.expanduser("~/.config/tablet_mapper.json") + + +# ───────────────────────────────────────────── +# xrandr / xsetwacom helpers +# ───────────────────────────────────────────── + +def parse_xrandr() -> list[Monitor]: + """Parse connected monitors from xrandr output.""" + monitors: list[Monitor] = [] + try: + out = subprocess.check_output(["xrandr", "--query"], text=True) + except Exception: + return monitors + + # Match lines like: HDMI-1 connected primary 1920x1080+0+0 ... + pattern = re.compile( + r"^(\S+) connected (primary )?(\d+)x(\d+)\+(\d+)\+(\d+)", + re.MULTILINE, + ) + for m in pattern.finditer(out): + monitors.append(Monitor( + name=m.group(1), + primary=bool(m.group(2)), + width=int(m.group(3)), + height=int(m.group(4)), + x=int(m.group(5)), + y=int(m.group(6)), + )) + return monitors + + +def list_wacom_devices() -> list[str]: + """Return list of xsetwacom device names.""" + devices = [] + try: + out = subprocess.check_output(["xsetwacom", "--list", "devices"], text=True) + for line in out.splitlines(): + # Format: "Wacom Intuos BT S Pen id: 12 type: STYLUS" + match = re.match(r"^(.+?)\s+id:\s+\d+", line) + if match: + devices.append(match.group(1).strip()) + except Exception: + pass + return devices + + +def apply_mapping(device: str, area: str) -> tuple[bool, str]: + """Apply xsetwacom MapToOutput. Returns (success, message).""" + if not device or not area: + return False, "No device or area specified." + try: + subprocess.run( + ["xsetwacom", "set", device, "MapToOutput", area], + check=True, capture_output=True, text=True + ) + return True, f"Mapped '{device}' → {area}" + except subprocess.CalledProcessError as e: + return False, e.stderr.strip() + except FileNotFoundError: + return False, "xsetwacom not found." + + +SENTINEL_BEGIN = "# >>> tablet-mapper begin <<<" +SENTINEL_END = "# >>> tablet-mapper end <<<" + + +def generate_xbindkeys_config(config: AppConfig, monitors: list[Monitor]) -> str: + """Generate xbindkeys config snippet wrapped in sentinel comments.""" + lines = [ + SENTINEL_BEGIN, + "# Generated by tablet-mapper — do not edit this block manually.", + "", + ] + for mapping in config.mappings: + if not mapping.keybinding: + continue + area = mapping.area_string(monitors) + if not area: + continue + device = mapping.tablet_device or config.tablet_device + cmd = f'xsetwacom set "{device}" MapToOutput {area}' + lines.append(f"# {mapping.name}") + lines.append(f'"{cmd}"') + lines.append(f"\t{mapping.keybinding}") + lines.append("") + lines.append(SENTINEL_END) + return "\n".join(lines) + + +def upsert_xbindkeysrc(new_block: str, rc_path: str) -> str: + """Insert or replace the tablet-mapper sentinel block in rc_path. + + - If the file doesn't exist it is created with just the block. + - If a previous sentinel block exists it is replaced in-place. + - Otherwise the block is appended with a blank line separator. + + Returns a short status string. + """ + if os.path.exists(rc_path): + with open(rc_path, "r") as f: + original = f.read() + else: + original = "" + + if SENTINEL_BEGIN in original and SENTINEL_END in original: + # Replace the existing block (including both sentinel lines) + before = original[:original.index(SENTINEL_BEGIN)] + after = original[original.index(SENTINEL_END) + len(SENTINEL_END):] + # Normalise surrounding whitespace: keep one blank line either side + updated = before.rstrip("\n") + "\n\n" + new_block + "\n" + after.lstrip("\n") + action = "updated" + else: + # Append — add blank line separator if file has content + sep = "\n\n" if original.strip() else "" + updated = original + sep + new_block + "\n" + action = "written" + + with open(rc_path, "w") as f: + f.write(updated) + + return action + + +# ───────────────────────────────────────────── +# Desktop preview widget +# ───────────────────────────────────────────── + +class DesktopPreview(QWidget): + """Visual representation of monitor layout with tablet mapping overlay. + + Clicking on a monitor selects the first mapping that covers it. + Clicking the desktop background (bounding box but outside all monitors) + selects the first all-screens mapping. + """ + + mapping_changed = pyqtSignal() + mapping_clicked = pyqtSignal(int) # emits mapping index, or -1 for none + + def __init__(self, parent=None): + super().__init__(parent) + self.monitors: list[Monitor] = [] + self.mappings: list[TabletMapping] = [] # kept in sync by MainWindow + self.active_mapping: Optional[TabletMapping] = None + self.setMinimumSize(400, 220) + self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) + self.setCursor(Qt.CursorShape.ArrowCursor) + self.setMouseTracking(True) + + self._colors = [ + QColor("#3a7bd5"), QColor("#e74c3c"), QColor("#2ecc71"), + QColor("#f39c12"), QColor("#9b59b6"), QColor("#1abc9c"), + ] + + # Cached layout geometry, recomputed in paintEvent + self._last_desktop: QRect = QRect() + self._last_target: QRect = QRect() + + def set_monitors(self, monitors: list[Monitor]): + self.monitors = monitors + self.update() + + def set_mappings(self, mappings: list[TabletMapping]): + self.mappings = mappings + + def set_active_mapping(self, mapping: Optional[TabletMapping]): + self.active_mapping = mapping + self.update() + + # ── Coordinate helpers ─────────────────── + + def _desktop_rect(self) -> QRect: + if not self.monitors: + return QRect(0, 0, 1920, 1080) + x0 = min(m.x for m in self.monitors) + y0 = min(m.y for m in self.monitors) + x1 = max(m.x + m.width for m in self.monitors) + y1 = max(m.y + m.height for m in self.monitors) + return QRect(x0, y0, x1 - x0, y1 - y0) + + def _compute_target(self) -> QRect: + """Return the screen-space rect the desktop is drawn into (aspect-corrected).""" + desktop = self._desktop_rect() + margin = 16 + target = QRect(margin, margin, self.width() - 2 * margin, self.height() - 2 * margin) + if desktop.width() > 0 and desktop.height() > 0: + asp = desktop.width() / desktop.height() + if target.width() / target.height() > asp: + new_w = int(target.height() * asp) + target = QRect(target.x() + (target.width() - new_w) // 2, + target.y(), new_w, target.height()) + else: + new_h = int(target.width() / asp) + target = QRect(target.x(), target.y() + (target.height() - new_h) // 2, + target.width(), new_h) + return target + + def _scale_rect(self, rect: QRect, desktop: QRect, target: QRect) -> QRect: + sx = target.width() / desktop.width() + sy = target.height() / desktop.height() + scale = min(sx, sy) + x = target.x() + (rect.x() - desktop.x()) * scale + y = target.y() + (rect.y() - desktop.y()) * scale + return QRect(int(x), int(y), int(rect.width() * scale), int(rect.height() * scale)) + + def _widget_to_desktop(self, px: int, py: int) -> QPoint: + """Convert widget pixel coordinates to desktop coordinate space.""" + desktop = self._last_desktop + target = self._last_target + if target.width() == 0 or target.height() == 0: + return QPoint(0, 0) + scale_x = desktop.width() / target.width() + scale_y = desktop.height() / target.height() + scale = max(scale_x, scale_y) # inverse of min(sx,sy) used in _scale_rect + dx = desktop.x() + (px - target.x()) * scale + dy = desktop.y() + (py - target.y()) * scale + return QPoint(int(dx), int(dy)) + + # ── Hit testing ────────────────────────── + + def _monitor_at(self, dp: QPoint) -> Optional[Monitor]: + """Return the monitor containing desktop point dp, or None.""" + for m in self.monitors: + if m.rect.contains(dp): + return m + return None + + def _in_desktop_bounding_box(self, dp: QPoint) -> bool: + return self._desktop_rect().contains(dp) + + def _best_mapping_for_click(self, dp: QPoint) -> int: + """Return index of the best matching mapping for a click at desktop point dp. + + Priority: + 1. Click inside a monitor → first mapping that covers exactly that monitor + (single-monitor mapping preferred over multi-monitor) + 2. Click in bounding box but outside all monitors → first all-screens mapping + 3. Nothing matched → -1 + """ + clicked_mon = self._monitor_at(dp) + + if clicked_mon: + # Prefer single-monitor mappings for this monitor + for i, m in enumerate(self.mappings): + if m.monitor_names == [clicked_mon.name]: + return i + # Fall back to any mapping that includes this monitor + for i, m in enumerate(self.mappings): + if clicked_mon.name in m.monitor_names: + return i + # Fall back to all-screens + for i, m in enumerate(self.mappings): + if not m.monitor_names: + return i + elif self._in_desktop_bounding_box(dp): + # Outside monitors but inside bounding box → all-screens + for i, m in enumerate(self.mappings): + if not m.monitor_names: + return i + + return -1 + + # ── Mouse events ───────────────────────── + + def mouseMoveEvent(self, event): + if not self.monitors or not self.mappings: + return + dp = self._widget_to_desktop(event.pos().x(), event.pos().y()) + if self._in_desktop_bounding_box(dp): + self.setCursor(Qt.CursorShape.PointingHandCursor) + else: + self.setCursor(Qt.CursorShape.ArrowCursor) + + def mousePressEvent(self, event): + if event.button() != Qt.MouseButton.LeftButton: + return + if not self.monitors or not self.mappings: + return + dp = self._widget_to_desktop(event.pos().x(), event.pos().y()) + idx = self._best_mapping_for_click(dp) + self.mapping_clicked.emit(idx) + + # ── Paint ──────────────────────────────── + + def paintEvent(self, event): + painter = QPainter(self) + painter.setRenderHint(QPainter.RenderHint.Antialiasing) + + desktop = self._desktop_rect() + self._last_desktop = desktop + target = self._compute_target() + self._last_target = target + + # Background + painter.fillRect(target, QColor("#1a1a2e")) + + # Draw monitors + for i, mon in enumerate(self.monitors): + r = self._scale_rect(mon.rect, desktop, target) + color = self._colors[i % len(self._colors)] + painter.fillRect(r, color.darker(150)) + painter.setPen(QPen(color, 2)) + painter.drawRect(r) + + # Label + painter.setPen(QColor("white")) + font = painter.font() + font.setPointSize(8) + painter.setFont(font) + label = f"{mon.name}\n{mon.width}×{mon.height}" + painter.drawText(r, Qt.AlignmentFlag.AlignCenter, label) + + # Draw mapping overlay + if self.active_mapping and self.monitors: + targets = [m for m in self.monitors if m.name in self.active_mapping.monitor_names] + if not targets and not self.active_mapping.monitor_names: + targets = self.monitors # all screens + + if targets: + x0 = min(m.x for m in targets) + y0 = min(m.y for m in targets) + x1 = max(m.x + m.width for m in targets) + y1 = max(m.y + m.height for m in targets) + mapping_rect = QRect(x0, y0, x1 - x0, y1 - y0) + sr = self._scale_rect(mapping_rect, desktop, target) + + # Raw mapping rect — yellow dashed + overlay = QColor("#f1c40f") + overlay.setAlpha(40) + painter.fillRect(sr, overlay) + painter.setPen(QPen(QColor("#f1c40f"), 2, Qt.PenStyle.DashLine)) + painter.drawRect(sr) + + # Aspect-corrected rect — cyan solid (only if correction enabled) + if self.active_mapping.aspect_correct: + corr = self.active_mapping.corrected_rect(self.monitors) + if corr: + cr = self._scale_rect(corr, desktop, target) + corr_overlay = QColor("#00d4ff") + corr_overlay.setAlpha(35) + painter.fillRect(cr, corr_overlay) + painter.setPen(QPen(QColor("#00d4ff"), 2)) + painter.drawRect(cr) + # Label on corrected rect + painter.setPen(QColor("#00d4ff")) + font = painter.font() + font.setPointSize(7) + font.setBold(True) + painter.setFont(font) + from math import gcd + g = gcd(corr.width(), corr.height()) if corr.height() > 0 else 1 + label = f"Tablet: {corr.width() // g}:{corr.height() // g} ({corr.width()}×{corr.height()})" + painter.drawText(cr.adjusted(4, 4, -4, -4), + Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignRight, + label) + else: + # Just show raw aspect ratio + painter.setPen(QColor("#f1c40f")) + font = painter.font() + font.setPointSize(7) + font.setBold(True) + painter.setFont(font) + from math import gcd + rw, rh = x1 - x0, y1 - y0 + g = gcd(rw, rh) if rh > 0 else 1 + label = f"{rw // g}:{rh // g} ({rw}×{rh})" + painter.drawText(sr.adjusted(4, 4, -4, -4), + Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignRight, + label) + + painter.end() + + +# ───────────────────────────────────────────── +# Key capture dialog (keycode-based) +# ───────────────────────────────────────────── + +# Keys that are modifiers only — not the primary key +_MODIFIER_KEYS = { + Qt.Key.Key_Control, Qt.Key.Key_Shift, Qt.Key.Key_Alt, + Qt.Key.Key_Meta, Qt.Key.Key_Super_L, Qt.Key.Key_Super_R, + Qt.Key.Key_AltGr, Qt.Key.Key_CapsLock, Qt.Key.Key_NumLock, + Qt.Key.Key_ScrollLock, Qt.Key.Key_Hyper_L, Qt.Key.Key_Hyper_R, +} + +CAPTURE_TIMEOUT_MS = 1500 + + +class KeyCaptureDialog(QDialog): + """Captures a key combination and stores it as an xbindkeys keycode string. + + Output format: m:0x58 + c:10 + m: hex modifier mask (as reported by the native X11 event) + c: X11 keycode (nativeScanCode from the Qt key event) + + This is the only format used — no human-readable conversion needed. + The display label shows a friendly representation while capturing, + but the stored string is always the keycode form. + """ + + def __init__(self, parent=None): + super().__init__(parent) + self.setWindowTitle("Capture Keybinding") + self.setFixedSize(400, 200) + self.setWindowFlags(self.windowFlags() | Qt.WindowType.WindowStaysOnTopHint) + + self._native_mods: int = 0 # raw X11 modifier mask + self._native_keycode: int = 0 # raw X11 keycode (scan code) + self._display_str: str = "" # human-friendly label (display only) + self._captured: str = "" # the actual xbindkeys keycode string + + self._timer = QTimer(self) + self._timer.setSingleShot(True) + self._timer.setInterval(CAPTURE_TIMEOUT_MS) + self._timer.timeout.connect(self._on_timeout) + + layout = QVBoxLayout(self) + layout.setSpacing(12) + + instr = QLabel("Hold down your key combination, then release…") + instr.setAlignment(Qt.AlignmentFlag.AlignCenter) + instr.setWordWrap(True) + layout.addWidget(instr) + + self._combo_label = QLabel("—") + self._combo_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + f = self._combo_label.font() + f.setPointSize(15) + f.setBold(True) + self._combo_label.setFont(f) + self._combo_label.setStyleSheet("color: #cba6f7;") + layout.addWidget(self._combo_label) + + self._code_label = QLabel("") + self._code_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + self._code_label.setStyleSheet("color: #6c7086; font-size: 11px; font-family: monospace;") + layout.addWidget(self._code_label) + + self._countdown_label = QLabel("") + self._countdown_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + self._countdown_label.setStyleSheet("color: #6c7086; font-size: 11px;") + layout.addWidget(self._countdown_label) + + btn_row = QHBoxLayout() + cancel_btn = QPushButton("Cancel") + cancel_btn.clicked.connect(self.reject) + btn_row.addWidget(cancel_btn) + self._accept_btn = QPushButton("Use this binding") + self._accept_btn.setEnabled(False) + self._accept_btn.setStyleSheet("background:#2ecc71;color:#000;font-weight:bold;") + self._accept_btn.clicked.connect(self.accept) + btn_row.addWidget(self._accept_btn) + layout.addLayout(btn_row) + + self._tick = QTimer(self) + self._tick.setInterval(50) + self._tick.timeout.connect(self._update_countdown) + self._tick.start() + + def result_string(self) -> str: + return self._captured + + # ── Qt key event → X11 keycode ─────────── + + def keyPressEvent(self, event): + if event.isAutoRepeat(): + return + + key = Qt.Key(event.key()) + if key in _MODIFIER_KEYS: + # Update modifier display but don't set a keycode yet + self._native_mods = event.nativeModifiers() + self._update_display() + return + + # Capture both the X11 modifier mask and keycode + self._native_mods = event.nativeModifiers() + self._native_keycode = event.nativeScanCode() + self._display_str = self._build_display(event) + self._captured = self._build_keycode_string() + self._timer.stop() + self._update_display() + + def keyReleaseEvent(self, event): + if event.isAutoRepeat(): + return + if self._captured: + self._timer.start() + + def _build_keycode_string(self) -> str: + """Build the xbindkeys keycode string: m:0xMM + c:CC""" + if not self._native_keycode: + return "" + return f"m:0x{self._native_mods:x} + c:{self._native_keycode}" + + def _build_display(self, event) -> str: + """Human-readable label shown during capture (not stored).""" + _MOD_DISPLAY = [ + (Qt.KeyboardModifier.MetaModifier, "Super"), + (Qt.KeyboardModifier.ControlModifier, "Ctrl"), + (Qt.KeyboardModifier.AltModifier, "Alt"), + (Qt.KeyboardModifier.ShiftModifier, "Shift"), + ] + parts = [label for mod, label in _MOD_DISPLAY if event.modifiers() & mod] + # Append key name + key = Qt.Key(event.key()) + if Qt.Key.Key_0 <= key <= Qt.Key.Key_9: + parts.append(str(key - Qt.Key.Key_0)) + elif Qt.Key.Key_A <= key <= Qt.Key.Key_Z: + parts.append(chr(key - Qt.Key.Key_A + ord('A'))) + elif Qt.Key.Key_F1 <= key <= Qt.Key.Key_F35: + parts.append(f"F{key - Qt.Key.Key_F1 + 1}") + else: + text = event.text() + parts.append(text.upper() if text.strip() else f"key:{self._native_keycode}") + return " + ".join(parts) + + def _update_display(self): + self._combo_label.setText(self._display_str or "—") + if self._captured: + self._code_label.setText(self._captured) + self._accept_btn.setEnabled(bool(self._captured)) + + def _update_countdown(self): + if self._timer.isActive(): + remaining = self._timer.remainingTime() + self._countdown_label.setText(f"Accepting in {remaining / 1000:.1f}s…") + else: + self._countdown_label.setText( + "Press keys, then release to confirm." if not self._captured else "" + ) + + def _on_timeout(self): + if self._captured: + self.accept() + + +# ───────────────────────────────────────────── +# Mapping editor dialog +# ───────────────────────────────────────────── + +class MappingDialog(QDialog): + def __init__(self, monitors: list[Monitor], mapping: Optional[TabletMapping] = None, + devices: list[str] = None, parent=None): + super().__init__(parent) + self.setWindowTitle("Edit Mapping" if mapping else "Add Mapping") + self.monitors = monitors + self.devices = devices or [] + self.resize(420, 380) + + layout = QVBoxLayout(self) + form = QFormLayout() + + self.name_edit = QLineEdit(mapping.name if mapping else "") + form.addRow("Name:", self.name_edit) + + self.key_edit = QLineEdit(mapping.keybinding if mapping else "") + self.key_edit.setPlaceholderText("e.g. m:0x58 + c:10 (use Capture button)") + key_widget = QWidget() + key_row = QHBoxLayout(key_widget) + key_row.setContentsMargins(0, 0, 0, 0) + key_row.addWidget(self.key_edit) + capture_btn = QPushButton("⌨ Capture keybinding") + capture_btn.setFixedWidth(165) + capture_btn.clicked.connect(self._capture_keybinding) + key_row.addWidget(capture_btn) + form.addRow("Keybinding:", key_widget) + + self.device_combo = QComboBox() + self.device_combo.addItem("(use global device)") + self.device_combo.addItems(self.devices) + if mapping and mapping.tablet_device: + idx = self.device_combo.findText(mapping.tablet_device) + if idx >= 0: + self.device_combo.setCurrentIndex(idx) + form.addRow("Device override:", self.device_combo) + + layout.addLayout(form) + + mon_group = QGroupBox("Monitor coverage") + mon_layout = QVBoxLayout(mon_group) + + self.all_check = QCheckBox("All screens (full desktop)") + mon_layout.addWidget(self.all_check) + + self.mon_checks: dict[str, QCheckBox] = {} + for mon in monitors: + cb = QCheckBox(f"{mon.name} ({mon.width}×{mon.height}+{mon.x}+{mon.y})") + if mapping and mon.name in mapping.monitor_names: + cb.setChecked(True) + self.mon_checks[mon.name] = cb + mon_layout.addWidget(cb) + + if mapping and not mapping.monitor_names: + self.all_check.setChecked(True) + + self.all_check.toggled.connect(self._all_toggled) + layout.addWidget(mon_group) + + # ── Aspect ratio correction ────────────── + asp_group = QGroupBox("Aspect ratio correction (tablet is 16:10)") + asp_layout = QVBoxLayout(asp_group) + + self.aspect_check = QCheckBox("Correct geometry to match tablet 16:10 aspect ratio") + self.aspect_check.setChecked(mapping.aspect_correct if mapping else False) + asp_layout.addWidget(self.aspect_check) + + asp_controls = QWidget() + asp_ctrl_layout = QHBoxLayout(asp_controls) + asp_ctrl_layout.setContentsMargins(0, 0, 0, 0) + + # Expand dimension toggle button + asp_ctrl_layout.addWidget(QLabel("Expand:")) + self._expand_val = (mapping.aspect_expand if mapping else "width") + self.expand_btn = QPushButton() + self.expand_btn.setFixedWidth(90) + self.expand_btn.setCheckable(False) + self._update_expand_btn() + self.expand_btn.clicked.connect(self._toggle_expand) + asp_ctrl_layout.addWidget(self.expand_btn) + + asp_ctrl_layout.addSpacing(16) + + # Anchor combo + asp_ctrl_layout.addWidget(QLabel("Anchor:")) + self.anchor_combo = QComboBox() + self.anchor_combo.addItem("Top-left (expand right/down)", "top-left") + self.anchor_combo.addItem("Center (expand both sides)", "center") + anchor_val = mapping.aspect_anchor if mapping else "top-left" + idx = self.anchor_combo.findData(anchor_val) + if idx >= 0: + self.anchor_combo.setCurrentIndex(idx) + asp_ctrl_layout.addWidget(self.anchor_combo) + asp_ctrl_layout.addStretch() + + asp_layout.addWidget(asp_controls) + + # Preview label showing computed geometry + self._asp_preview = QLabel("") + self._asp_preview.setStyleSheet("color: #89dceb; font-family: monospace; font-size: 11px;") + asp_layout.addWidget(self._asp_preview) + + self.aspect_check.toggled.connect(self._update_asp_preview) + self.expand_btn.clicked.connect(self._update_asp_preview) + self.anchor_combo.currentIndexChanged.connect(self._update_asp_preview) + for cb in self.mon_checks.values(): + cb.toggled.connect(self._update_asp_preview) + self.all_check.toggled.connect(self._update_asp_preview) + + layout.addWidget(asp_group) + self._update_asp_preview() + self._update_asp_controls(self.aspect_check.isChecked()) + self.aspect_check.toggled.connect(self._update_asp_controls) + + btns = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | + QDialogButtonBox.StandardButton.Cancel) + btns.accepted.connect(self.accept) + btns.rejected.connect(self.reject) + layout.addWidget(btns) + + self._all_toggled(self.all_check.isChecked()) + + def _all_toggled(self, checked: bool): + for cb in self.mon_checks.values(): + cb.setEnabled(not checked) + + def _toggle_expand(self): + self._expand_val = "height" if self._expand_val == "width" else "width" + self._update_expand_btn() + self._update_asp_preview() + + def _update_expand_btn(self): + if self._expand_val == "width": + self.expand_btn.setText("↔ Width") + self.expand_btn.setStyleSheet("background:#313244;") + else: + self.expand_btn.setText("↕ Height") + self.expand_btn.setStyleSheet("background:#313244;") + + def _update_asp_controls(self, enabled: bool): + self.expand_btn.setEnabled(enabled) + self.anchor_combo.setEnabled(enabled) + self._update_asp_preview() + + def _current_bounding_box(self) -> tuple[int, int, int, int]: + """Return (x, y, w, h) bounding box based on current dialog selections.""" + if self.all_check.isChecked(): + if not self.monitors: + return (0, 0, 0, 0) + x0 = min(m.x for m in self.monitors) + y0 = min(m.y for m in self.monitors) + x1 = max(m.x + m.width for m in self.monitors) + y1 = max(m.y + m.height for m in self.monitors) + return (x0, y0, x1 - x0, y1 - y0) + selected = [m for m in self.monitors if self.mon_checks.get(m.name, QCheckBox()).isChecked()] + if not selected: + return (0, 0, 0, 0) + x0 = min(m.x for m in selected) + y0 = min(m.y for m in selected) + x1 = max(m.x + m.width for m in selected) + y1 = max(m.y + m.height for m in selected) + return (x0, y0, x1 - x0, y1 - y0) + + def _update_asp_preview(self): + if not self.aspect_check.isChecked(): + self._asp_preview.setText("") + return + x, y, w, h = self._current_bounding_box() + if w == 0 or h == 0: + self._asp_preview.setText("No monitors selected.") + return + anchor = self.anchor_combo.currentData() + if self._expand_val == "width": + new_w = round(h * TABLET_RATIO_W / TABLET_RATIO_H) + delta = new_w - w + adj_x = x - delta // 2 if anchor == "center" else x + self._asp_preview.setText( + f"Raw: {w}×{h}+{x}+{y} → Corrected: {new_w}×{h}+{adj_x}+{y}" + f" (width +{delta}px)" + ) + else: + new_h = round(w * TABLET_RATIO_H / TABLET_RATIO_W) + delta = new_h - h + adj_y = y - delta // 2 if anchor == "center" else y + self._asp_preview.setText( + f"Raw: {w}×{h}+{x}+{y} → Corrected: {w}×{new_h}+{x}+{adj_y}" + f" (height +{delta}px)" + ) + + def _capture_keybinding(self): + dlg = KeyCaptureDialog(self) + if dlg.exec() and dlg.result_string(): + self.key_edit.setText(dlg.result_string()) + + def get_mapping(self) -> TabletMapping: + if self.all_check.isChecked(): + selected = [] + else: + selected = [n for n, cb in self.mon_checks.items() if cb.isChecked()] + + device = "" + if self.device_combo.currentIndex() > 0: + device = self.device_combo.currentText() + + return TabletMapping( + name=self.name_edit.text() or "Unnamed", + monitor_names=selected, + keybinding=self.key_edit.text().strip(), + tablet_device=device, + aspect_correct=self.aspect_check.isChecked(), + aspect_expand=self._expand_val, + aspect_anchor=self.anchor_combo.currentData(), + ) + + +# ───────────────────────────────────────────── +# Main window +# ───────────────────────────────────────────── + +class MainWindow(QMainWindow): + def __init__(self): + super().__init__() + self.setWindowTitle("Tablet Mapper") + self.resize(1000, 680) + + self.config = AppConfig() + self.monitors: list[Monitor] = [] + self.wacom_devices: list[str] = [] + + self._load_config() + self._build_ui() + self._refresh_monitors() + self._refresh_devices() + self._refresh_mapping_list() + + # ── UI construction ────────────────────── + + def _build_ui(self): + central = QWidget() + self.setCentralWidget(central) + root = QVBoxLayout(central) + root.setContentsMargins(8, 8, 8, 8) + + # Toolbar row + toolbar = QHBoxLayout() + + refresh_btn = QPushButton("⟳ Refresh Screens") + refresh_btn.clicked.connect(self._refresh_monitors) + toolbar.addWidget(refresh_btn) + + refresh_dev_btn = QPushButton("⟳ Refresh Devices") + refresh_dev_btn.clicked.connect(self._refresh_devices) + toolbar.addWidget(refresh_dev_btn) + + toolbar.addWidget(QLabel("Global device:")) + self.device_combo = QComboBox() + self.device_combo.setMinimumWidth(220) + self.device_combo.currentTextChanged.connect(self._on_global_device_changed) + toolbar.addWidget(self.device_combo) + + toolbar.addStretch() + + save_btn = QPushButton("Save Config") + save_btn.clicked.connect(self._save_config) + toolbar.addWidget(save_btn) + + root.addLayout(toolbar) + + # Splitter: left = preview+monitors, right = mappings+output + splitter = QSplitter(Qt.Orientation.Horizontal) + root.addWidget(splitter) + + # Left panel + left = QWidget() + left_layout = QVBoxLayout(left) + left_layout.setContentsMargins(0, 0, 0, 0) + + preview_group = QGroupBox("Desktop Layout Preview") + pg = QVBoxLayout(preview_group) + self.preview = DesktopPreview() + self.preview.mapping_clicked.connect(self._on_preview_clicked) + pg.addWidget(self.preview) + left_layout.addWidget(preview_group, 3) + + mon_group = QGroupBox("Detected Monitors (from xrandr)") + mg = QVBoxLayout(mon_group) + self.monitor_list = QListWidget() + mg.addWidget(self.monitor_list) + manual_row = QHBoxLayout() + manual_row.addWidget(QLabel("Manual input:")) + self.manual_xrandr = QLineEdit() + self.manual_xrandr.setPlaceholderText("Paste xrandr output or geometry, e.g. 1920x1080+0+0") + manual_row.addWidget(self.manual_xrandr) + parse_btn = QPushButton("Parse") + parse_btn.clicked.connect(self._parse_manual_xrandr) + manual_row.addWidget(parse_btn) + mg.addLayout(manual_row) + left_layout.addWidget(mon_group, 2) + + splitter.addWidget(left) + + # Right panel + right = QWidget() + right_layout = QVBoxLayout(right) + right_layout.setContentsMargins(0, 0, 0, 0) + + tabs = QTabWidget() + right_layout.addWidget(tabs) + + # ── Tab 1: Mappings ── + map_widget = QWidget() + map_layout = QVBoxLayout(map_widget) + + map_btn_row = QHBoxLayout() + add_btn = QPushButton("+ Add Mapping") + add_btn.clicked.connect(self._add_mapping) + map_btn_row.addWidget(add_btn) + edit_btn = QPushButton("✎ Edit") + edit_btn.clicked.connect(self._edit_mapping) + map_btn_row.addWidget(edit_btn) + del_btn = QPushButton("✕ Delete") + del_btn.clicked.connect(self._delete_mapping) + map_btn_row.addWidget(del_btn) + map_btn_row.addStretch() + apply_btn = QPushButton("▶ Apply Selected") + apply_btn.setStyleSheet("background:#2ecc71;color:#000;font-weight:bold;") + apply_btn.clicked.connect(self._apply_selected) + map_btn_row.addWidget(apply_btn) + map_layout.addLayout(map_btn_row) + + self.mapping_list = QListWidget() + self.mapping_list.currentRowChanged.connect(self._on_mapping_selected) + map_layout.addWidget(self.mapping_list) + + quick_group = QGroupBox("Quick-add per-monitor mappings") + qg = QHBoxLayout(quick_group) + quick_add_btn = QPushButton("Auto-generate monitor mappings + All-screens") + quick_add_btn.clicked.connect(self._quick_add_monitor_mappings) + qg.addWidget(quick_add_btn) + map_layout.addWidget(quick_group) + + tabs.addTab(map_widget, "Mappings") + + # ── Tab 2: xbindkeys output ── + bind_widget = QWidget() + bind_layout = QVBoxLayout(bind_widget) + bind_btn_row = QHBoxLayout() + gen_btn = QPushButton("Generate xbindkeys config") + gen_btn.clicked.connect(self._generate_xbindkeys) + bind_btn_row.addWidget(gen_btn) + + copy_btn = QPushButton("Copy to clipboard") + copy_btn.clicked.connect(self._copy_xbindkeys) + bind_btn_row.addWidget(copy_btn) + + write_btn = QPushButton("+ Apply to xbindkeys") + write_btn.setStyleSheet("background:#2ecc71;color:#000;font-weight:bold;") + write_btn.setToolTip( + "Writes the generated block to ~/.xbindkeysrc (replacing any previous\n" + "tablet-mapper block) then restarts xbindkeys." + ) + write_btn.clicked.connect(self._write_and_reload_xbindkeys) + bind_btn_row.addWidget(write_btn) + bind_layout.addLayout(bind_btn_row) + self.xbindkeys_output = QTextEdit() + self.xbindkeys_output.setFont(QFont("Monospace", 10)) + self.xbindkeys_output.setReadOnly(False) + bind_layout.addWidget(self.xbindkeys_output) + tabs.addTab(bind_widget, "xbindkeys Config") + + # ── Tab 3: xsetwacom commands ── + cmd_widget = QWidget() + cmd_layout = QVBoxLayout(cmd_widget) + gen_cmd_btn = QPushButton("Generate shell script") + gen_cmd_btn.clicked.connect(self._generate_shell_script) + cmd_layout.addWidget(gen_cmd_btn) + self.cmd_output = QTextEdit() + self.cmd_output.setFont(QFont("Monospace", 10)) + self.cmd_output.setReadOnly(False) + cmd_layout.addWidget(self.cmd_output) + tabs.addTab(cmd_widget, "Shell Commands") + + # Status bar + self.status_label = QLabel("Ready.") + self.status_label.setStyleSheet("color: #aaa; font-size: 11px;") + right_layout.addWidget(self.status_label) + + splitter.addWidget(right) + splitter.setSizes([480, 520]) + + # ── Refresh ────────────────────────────── + + def _refresh_monitors(self): + self.monitors = parse_xrandr() + self.monitor_list.clear() + for m in self.monitors: + self.monitor_list.addItem( + f"{'★ ' if m.primary else ' '}{m.name} {m.width}×{m.height} +{m.x}+{m.y}" + ) + self.preview.set_monitors(self.monitors) + n = len(self.monitors) + self._set_status(f"Found {n} monitor{'s' if n != 1 else ''} via xrandr." if n + else "No monitors detected. Try manual input.") + + def _refresh_devices(self): + self.wacom_devices = list_wacom_devices() + self.device_combo.blockSignals(True) + self.device_combo.clear() + self.device_combo.addItem("(none)") + self.device_combo.addItems(self.wacom_devices) + if self.config.tablet_device: + idx = self.device_combo.findText(self.config.tablet_device) + if idx >= 0: + self.device_combo.setCurrentIndex(idx) + self.device_combo.blockSignals(False) + self._set_status(f"Devices: {self.wacom_devices or ['none found']}") + + def _on_global_device_changed(self, text: str): + self.config.tablet_device = text if text != "(none)" else "" + + # ── Manual xrandr input ────────────────── + + def _parse_manual_xrandr(self): + text = self.manual_xrandr.text().strip() + if not text: + return + # Try full xrandr output + monitors = parse_xrandr() if not text else [] + # Also try simple geometry list + geo_pattern = re.compile(r"(\w[\w-]*)\s+(\d+)x(\d+)\+(\d+)\+(\d+)") + found = [] + for m in geo_pattern.finditer(text): + found.append(Monitor( + name=m.group(1), width=int(m.group(2)), height=int(m.group(3)), + x=int(m.group(4)), y=int(m.group(5)) + )) + if found: + self.monitors = found + self.monitor_list.clear() + for mon in self.monitors: + self.monitor_list.addItem(f" {mon.name} {mon.width}×{mon.height} +{mon.x}+{mon.y}") + self.preview.set_monitors(self.monitors) + self._set_status(f"Parsed {len(found)} monitors from input.") + else: + self._set_status("Could not parse monitor geometry from input.") + + # ── Mappings ───────────────────────────── + + def _refresh_mapping_list(self): + self.mapping_list.clear() + for i, m in enumerate(self.config.mappings): + kb = f" [{m.keybinding}]" if m.keybinding else "" + scr = ", ".join(m.monitor_names) if m.monitor_names else "All screens" + self.mapping_list.addItem(f"{m.name}{kb} → {scr}") + self.preview.set_mappings(self.config.mappings) + + def _on_mapping_selected(self, row: int): + if 0 <= row < len(self.config.mappings): + self.preview.set_active_mapping(self.config.mappings[row]) + else: + self.preview.set_active_mapping(None) + + def _on_preview_clicked(self, idx: int): + """Handle a click on the desktop preview — select the mapping in the list.""" + if idx < 0: + self.mapping_list.clearSelection() + self.preview.set_active_mapping(None) + return + # Block the list's signal briefly to avoid double-firing set_active_mapping + self.mapping_list.blockSignals(True) + self.mapping_list.setCurrentRow(idx) + self.mapping_list.blockSignals(False) + self.preview.set_active_mapping(self.config.mappings[idx]) + + def _add_mapping(self): + dlg = MappingDialog(self.monitors, devices=self.wacom_devices, parent=self) + if dlg.exec(): + self.config.mappings.append(dlg.get_mapping()) + self._refresh_mapping_list() + + def _edit_mapping(self): + row = self.mapping_list.currentRow() + if row < 0 or row >= len(self.config.mappings): + return + dlg = MappingDialog(self.monitors, self.config.mappings[row], + self.wacom_devices, self) + if dlg.exec(): + self.config.mappings[row] = dlg.get_mapping() + self._refresh_mapping_list() + + def _delete_mapping(self): + row = self.mapping_list.currentRow() + if row < 0 or row >= len(self.config.mappings): + return + name = self.config.mappings[row].name + if QMessageBox.question(self, "Delete", f"Delete mapping '{name}'?", + QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No + ) == QMessageBox.StandardButton.Yes: + self.config.mappings.pop(row) + self._refresh_mapping_list() + self.preview.set_active_mapping(None) + + def _apply_selected(self): + row = self.mapping_list.currentRow() + if row < 0 or row >= len(self.config.mappings): + self._set_status("No mapping selected.") + return + m = self.config.mappings[row] + device = m.tablet_device or self.config.tablet_device + area = m.area_string(self.monitors) + if not device: + self._set_status("No tablet device set.") + return + ok, msg = apply_mapping(device, area) + self._set_status(("✓ " if ok else "✗ ") + msg) + + def _quick_add_monitor_mappings(self): + if not self.monitors: + self._set_status("No monitors detected.") + return + existing_names = {m.name for m in self.config.mappings} + + # All-screens mapping + all_name = "All Screens" + if all_name not in existing_names: + self.config.mappings.append(TabletMapping( + name=all_name, monitor_names=[], keybinding="" + )) + + # Per-monitor mappings + for mon in self.monitors: + name = f"Monitor: {mon.name}" + if name not in existing_names: + self.config.mappings.append(TabletMapping( + name=name, monitor_names=[mon.name], keybinding="" + )) + + self._refresh_mapping_list() + self._set_status( + f"Generated mappings for {len(self.monitors)} monitors + all-screens. " + "Use the Capture button to set keybindings." + ) + + # ── Output generation ──────────────────── + + def _generate_xbindkeys(self): + text = generate_xbindkeys_config(self.config, self.monitors) + self.xbindkeys_output.setPlainText(text) + + def _copy_xbindkeys(self): + self._generate_xbindkeys() + QApplication.clipboard().setText(self.xbindkeys_output.toPlainText()) + self._set_status("Copied xbindkeys config to clipboard.") + + def _write_and_reload_xbindkeys(self): + self._generate_xbindkeys() + block = self.xbindkeys_output.toPlainText() + rc_path = os.path.expanduser("~/.xbindkeysrc") + try: + action = upsert_xbindkeysrc(block, rc_path) + self._set_status(f"✓ tablet-mapper block {action} in {rc_path} — reloading xbindkeys…") + except Exception as e: + self._set_status(f"✗ Write failed: {e}") + return + try: + subprocess.run(["pkill", "xbindkeys"], capture_output=True) + subprocess.Popen(["xbindkeys"]) + self._set_status( + f"✓ tablet-mapper block {action} in {rc_path} and xbindkeys reloaded." + ) + except FileNotFoundError: + self._set_status("✓ File written — but xbindkeys not found, is it installed?") + except Exception as e: + self._set_status(f"✓ File written — xbindkeys reload failed: {e}") + + def _generate_shell_script(self): + lines = ["#!/bin/bash", "# Tablet mapping commands", ""] + for m in self.config.mappings: + device = m.tablet_device or self.config.tablet_device + area = m.area_string(self.monitors) + if device and area: + lines.append(f"# {m.name}") + lines.append(f'xsetwacom --set "{device}" MapToOutput {area}') + lines.append("") + self.cmd_output.setPlainText("\n".join(lines)) + + # ── Config persistence ─────────────────── + + def _save_config(self): + self.config.tablet_device = ( + self.device_combo.currentText() + if self.device_combo.currentIndex() > 0 else "" + ) + try: + os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True) + with open(CONFIG_PATH, "w") as f: + json.dump(self.config.to_dict(), f, indent=2) + self._set_status(f"Config saved to {CONFIG_PATH}") + except Exception as e: + self._set_status(f"Save error: {e}") + + def _load_config(self): + if os.path.exists(CONFIG_PATH): + try: + with open(CONFIG_PATH) as f: + self.config = AppConfig.from_dict(json.load(f)) + except Exception: + pass + + def _set_status(self, msg: str): + self.status_label.setText(msg) + + +# ───────────────────────────────────────────── +# Dark stylesheet +# ───────────────────────────────────────────── + +DARK_STYLE = """ +QWidget { background-color: #1e1e2e; color: #cdd6f4; font-family: 'Segoe UI', sans-serif; font-size: 13px; } +QMainWindow { background-color: #1e1e2e; } +QGroupBox { border: 1px solid #45475a; border-radius: 6px; margin-top: 6px; padding-top: 8px; } +QGroupBox::title { subcontrol-origin: margin; left: 10px; color: #89b4fa; } +QPushButton { background-color: #313244; border: 1px solid #45475a; border-radius: 4px; padding: 5px 12px; } +QPushButton:hover { background-color: #45475a; } +QPushButton:pressed { background-color: #585b70; } +QLineEdit, QComboBox, QSpinBox { background-color: #181825; border: 1px solid #45475a; border-radius: 4px; padding: 4px 8px; } +QComboBox::drop-down { border: none; } +QComboBox::down-arrow { image: none; border: none; } +QListWidget { background-color: #181825; border: 1px solid #45475a; border-radius: 4px; } +QListWidget::item { padding: 4px 8px; } +QListWidget::item:selected { background-color: #45475a; color: #cba6f7; } +QListWidget::item:hover { background-color: #313244; } +QTabWidget::pane { border: 1px solid #45475a; border-radius: 4px; } +QTabBar::tab { background-color: #313244; border: 1px solid #45475a; padding: 6px 14px; margin-right: 2px; border-radius: 4px 4px 0 0; } +QTabBar::tab:selected { background-color: #45475a; color: #cba6f7; } +QTextEdit { background-color: #181825; border: 1px solid #45475a; border-radius: 4px; } +QCheckBox::indicator { width: 14px; height: 14px; border: 1px solid #45475a; border-radius: 3px; background: #181825; } +QCheckBox::indicator:checked { background: #89b4fa; } +QSplitter::handle { background: #45475a; } +QScrollBar:vertical { background: #181825; width: 8px; } +QScrollBar::handle:vertical { background: #45475a; border-radius: 4px; min-height: 20px; } +""" + + +# ───────────────────────────────────────────── +# Entry point +# ───────────────────────────────────────────── + +def main(): + app = QApplication(sys.argv) + app.setStyleSheet(DARK_STYLE) + app.setApplicationName("Tablet Mapper") + win = MainWindow() + win.show() + sys.exit(app.exec()) + + +if __name__ == "__main__": + main()