pax_global_header00006660000000000000000000000064127233511450014515gustar00rootroot0000000000000052 comment=59265f944585117cd1b0750067b3bee41af6eee8 gtk3-nocsd-3/000077500000000000000000000000001272335114500131755ustar00rootroot00000000000000gtk3-nocsd-3/.gitignore000066400000000000000000000000741272335114500151660ustar00rootroot00000000000000*.so.0 *.o *~ gtk3-nocsd testlibs/ test-static-tls test-now gtk3-nocsd-3/COPYING000066400000000000000000000636421272335114500142430ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 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. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, 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 and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, 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 library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete 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 distribute a copy of this License along with the Library. 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 Library or any portion of it, thus forming a work based on the Library, 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) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, 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 Library, 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 Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you 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. If distribution of 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 satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be 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. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library 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. 9. 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 Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library 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 with this License. 11. 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 Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library 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 Library. 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. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library 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. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser 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 Library 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 Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, 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 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "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 LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. 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 LIBRARY 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 LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), 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 Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. 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. Copyright (C) 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 Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! gtk3-nocsd-3/ChangeLog000066400000000000000000000032731272335114500147540ustar00rootroot00000000000000gtk3-nocsd ChangeLog ==================== New in version 3 ---------------- * Improvements to the documentation (Thanks to Bharat G) * Add bash completion support for gtk3-nocsd wrapper * Also override GtkDialog's GtkBuildable->add_child and the instance initializer of GtkShortcutsWindow; previously CSDs weren't removed from all windows because of that * Drop compositor trick in Gtk+3 3.16.1 or higher; we reimplement the set_titlebar function there anyway, and the compositor trick only causes problems with newer Gtk+3 versions * Selectively disable decorations: don't drop the application menu icon by using set_show_close_button (FALSE), but instead replace the decoration_layout string of header bars to remove the "icon", "minimize", "maximize" and "close" buttons * Add a test that verifies that no Glib/Gtk symbols are imported during link time (to make sure preloading works with BINDNOW binaries that don't use Gtk) * Apply custom CSS for cosmetic improvements of the header bar look when CSDs are disabled (should be largely theme-agnostic, but tested against Adwaita) * Thanks to Christoph Anton Mitterer for reporting many of these issues New in version 2 ---------------- * fix crash because the development SONAME for Glib/GObject was referenced, instead of the SONAME of the package itself (Thanks to Simon McVittie) * fix crash with some GDK2 applications * add wrapper script for starting applications without CSDs (Thanks to nandhp) * don't use compiler-supported TLS (__thread) but rather use pthread_(get|set)specific, to make sure no DTV overflow entry is used by this library (fixes GitHub issue #11) gtk3-nocsd-3/Makefile000066400000000000000000000062561272335114500146460ustar00rootroot00000000000000PKG_CONFIG ?= pkg-config CFLAGS ?= -O2 -g override CFLAGS += $(shell ${PKG_CONFIG} --cflags gtk+-3.0) $(shell ${PKG_CONFIG} --cflags gobject-introspection-1.0) -pthread -Wall LDLIBS = -ldl CFLAGS_LIB = $(filter-out -fPIE -fpie -pie,$(CFLAGS)) -fPIC LDFLAGS_LIB = $(filter-out -fPIE -fpie -pie,$(LDFLAGS)) -fPIC prefix ?= /usr/local libdir ?= $(prefix)/lib bindir ?= $(prefix)/bin datadir ?= ${prefix}/share mandir ?= $(datadir)/man bashcompletiondir ?= ${datadir}/bash-completion/completions all: libgtk3-nocsd.so.0 gtk3-nocsd clean: rm -f libgtk3-nocsd.so.0 *.o gtk3-nocsd test-static-tls test-now *~ [ ! -d testlibs ] || rm -r testlibs libgtk3-nocsd.so.0: gtk3-nocsd.o $(CC) -shared $(CFLAGS_LIB) $(LDFLAGS_LIB) -Wl,-soname,libgtk3-nocsd.so.0 -o $@ $^ $(LDLIBS) gtk3-nocsd.o: gtk3-nocsd.c $(CC) $(CPPFLAGS) $(CFLAGS_LIB) -o $@ -c $< gtk3-nocsd: gtk3-nocsd.in sed 's|@@libdir@@|$(libdir)|g' < $< > $@ chmod +x $@ install: install -D -m 0644 libgtk3-nocsd.so.0 $(DESTDIR)$(libdir)/libgtk3-nocsd.so.0 install -D -m 0755 gtk3-nocsd $(DESTDIR)$(bindir)/gtk3-nocsd install -D -m 0644 gtk3-nocsd.1 $(DESTDIR)$(mandir)/man1/gtk3-nocsd.1 install -D -m 0644 gtk3-nocsd.bash-completion $(DESTDIR)$(bashcompletiondir)/gtk3-nocsd check: libgtk3-nocsd.so.0 testlibs/stamp test-static-tls test-now @echo "RUNNING: test-symbols" @# Force LD_BIND_NOW to make sure we don't accidentally import @# any symbols from glib/gdk/gtk directly. (This ensures @# compatibility with software that is linked with -Wl,-z,now.) @LD_PRELOAD=./libgtk3-nocsd.so.0 LD_BIND_NOW=1 ./test-now @echo "RUNNING: test-static-tls" @[ "$$(LD_PRELOAD= ./test-static-tls none)" = "$$(LD_PRELOAD=./libgtk3-nocsd.so.0 ./test-static-tls gtk3-nocsd)" ] || \ { echo " Without any library preloaded: can dlopen() up to the following number of libraries with static TLS:" ; \ echo -n " " ; LD_PRELOAD= ./test-static-tls none ; \ echo " With libgtk3-nocsd preloaded, can dlopen() up to the following number of libraries with static TLS:"; \ echo -n " " ; LD_PRELOAD=./libgtk3-nocsd.so.0 ./test-static-tls gtk3-nocsd ; \ echo " These should match, but they don't." ; \ exit 1; \ } testlibs/stamp: test-dummylib.c @# Build a lot of dummy libraries. test-static-tls tries to load all @# of these libraries with dlopen(), which will fail at some point @# (because the DTV overflow entries are used up). Build a lot of @# them so even if the current default changes the cutoff point can @# be determined. mkdir -p testlibs for i in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \ a b c d e f g h i j k l m n o p q r s t u v w x y z \ 0 1 2 3 4 5 6 7 8 9 ; do \ $(CC) $(CPPFLAGS) $(CFLAGS_LIB) -ftls-model=initial-exec -DTESTLIB_NAME=$$i -c -o testlibs/libdummy-$$i.o test-dummylib.c ; \ $(CC) -shared $(CFLAGS_LIB) $(LDFLAGS_LIB) -Wl,-soname,libdummy-$$i.so.0 -o testlibs/libdummy-$$i.so.0 testlibs/libdummy-$$i.o $(LDLIBS) ; \ done touch testlibs/stamp test-static-tls: test-static-tls.o $(CC) $(CFLAGS) $(LDFLAGS) -o test-static-tls test-static-tls.o $(LDLIBS) test-now: test-now.o $(CC) $(CFLAGS) $(LDFLAGS) -o test-now test-now.o $(LDLIBS) gtk3-nocsd-3/README.md000066400000000000000000000072771272335114500144710ustar00rootroot00000000000000#gtk3-nocsd gtk3-nocsd is a small module used to disable the client side decoration of Gtk+ 3. ##Introduction: Since Gtk+ 3.10, its developers added a so-called header bar or custom title bar. With this and the client-side decoration, the original title bar and window border provided by the window manager are disabled by Gtk+. This makes all Gtk+ 3 programs look alike. Even worse, this may break some window manager or compositors. Unfortunately, the Gtk+ developers decided to be against the existing standards and provide "no option" to turn it off. Luckily, with gtk3-nocsd, we still have a way to (partially) turn it off. Window manager (title bar and window border) can be re-enabled. ##Preview: This is how the gtk3 windows look like before and after using `gtk3-nocsd`. ![Screenshot of gedit with CSDs still enabled](gedit-with-csd.png) ![Screenshot of gedit with CSDs disabled by gtk3-nocsd](gedit-without-csd.png) #How to use: * gtk3-nocsd should work with all Gtk+ 3 versions. * Install necessary packages: * On Debian-based systems (including Ubuntu and Mint), install `pkg-config`, `libgtk-3-dev`, `libgirepository1.0-dev`. * On Fedora-based distros (including RHEL, CentOS), install `pkgconfig`, `gtk3-devel`, `gtk+-devel`, `gobject-introspection-devel`. * Build the code. Run `make` from command line. After this you'll have the files `gtk3-nocsd`and `libgtk3-nocsd.so.0` in the same directory. * Now to run individual Gtk+ 3 apps (say gedit) using this hack, use the command `./gtk3-nocsd gedit` from the same directory. * To have all Gtk+ 3 apps (of current user) use this hack, export some environment variables in your `~/.bashrc`: export GTK_CSD=0 export LD_PRELOAD=<"full path" of your libgtk3-nocsd.so.0 file> * On Debian-based systems with graphical login, instead modify (or create) `~/.xsessionrc` and add the following code: if [ -n "$STARTUP" ]; then BASESTARTUP=${STARTUP%% *} BASESTARTUP=${BASESTARTUP##*/} if [ "$BASESTARTUP" = x-session-manager ]; then BASESTARTUP=$(basename $(readlink /etc/alternatives/x-session-manager)) fi if [ x"$BASESTARTUP" = x"${BASESTARTUP#gnome-session}" ] ; then export GTK_CSD=0 STARTUP="env LD_PRELOAD=/path/to/libgtk3-nocsd.so.0 $STARTUP" fi fi gtk3-nocsd is now packaged for Debian though (see below), so manual installation may not be necessary. * Re-login to make the environment variables take effect. * Hooray! GTK+ 3 client-side decorations are disabled now. #Distribution packages: gtk3-nocsd is packaged in Debian's unstable and testing distributions, see [gtk3-nocsd in Debian's package database](https://packages.debian.org/testing/gtk3-nocsd). The Debian package already comes with integration code to automatically disable CSDs when installed, so after package installation only a re-login is required to have CSDs disabled on non-GNOME desktops. #How it works: `$LD_PRELOAD` is used to override several Gdk and glib/gobject APIs to intercept related calls Gtk+ 3 uses to setup CSDs. For older versions of Gtk+ 3, while it is trying to initialize CSDs, it is led to believe that there is no compositor available, so CSDs are not added. For later Gtk+ 3 versions (3.16.1+), the `gtk_window_set_titlebar` method is reimplemented, as tricking Gtk+ 3 into thinking the compositor is disabled has side effects and is not sufficent anymore. Additionally, as gtk_window_set_titlebar is also called from Gtk+ internally (and LD_PRELOAD cannot override function calls within a library), several other places in Gtk+3 (e.g. buildable interfaces for GtkWindow and GtkDialog) are also overridden to ensure that CSDs are disabled. gtk3-nocsd-3/TODO000066400000000000000000000010531272335114500136640ustar00rootroot00000000000000gtk3-nocsd TODO --------------- - Investigate whether we should force gtk-dialogs-use-header to FALSE (the current default in non-GNOME environments) or not. - Potentially remove title from header bar (redundant, but might make header bar look too empty). - Hide header bar if it were to contain only the title. - Split source code into multiple files. - Use same code paths for all Gtk versions, remove compositing hack completely. - Potentially add support to selectively enable gtk3-nocsd only for specific applications. (How?) gtk3-nocsd-3/gedit-with-csd.png000066400000000000000000000464571272335114500165370ustar00rootroot00000000000000PNG  IHDRX\MsBITO IDATxw|Eǟ+J)E齉H/Rʋ ^&(`@D)^vu.ɕ-{%a%w>;3ggPܐ`O\)l Fs=q8p$/Si md/žrkCU_xϐ}w "*jXTa-X3nƉ۸puGHkm@so*6k;Ƽ>a 0N ;9-˝wEṫɤ$P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k3-nocsd-3/gtk3-nocsd.1000066400000000000000000000040011272335114500152260ustar00rootroot00000000000000.TH gtk3-nocsd 1 "October 2015" .SH NAME gtk3-nocsd \- transparently disable Gtk+3 client side decorations (CSD) .SH SYNOPSIS .B gtk3-nocsd \fIcommand\fR [ \fIcommand arguments\fR ... ] .TP .B symlinked-command [ \fIcommand arguments\fR ... ] .SH DESCRIPTION \fBgtk3-nocsd\fR runs a command in the environment where Gtk+3 client side decorations (CSD) are disabled, by using LD_PRELOAD to load the library \fBlibgtk3-nocsd.so.0\fR that overrides some GLib, GDK and Gtk API calls with customized variants. .SH OPTIONS .TP .I command The command to execute. It may be either a full path or the name of the command in PATH. In case command cannot be found in PATH, \fBgtk3-nocsd\fR will fail. .TP .I command arguments Arbitrary number of arguments to pass to the command being executed. .SH USAGE VIA SYMLINKS If a symlink to \fBgtk3-nocsd\fR under a different name is called, \fBgtk3-nocsd\fR will assume that the name it was called under is the name of the command that is supposed to be executed. It will look for the command in the PATH environment variable, excluding itself, and execute it with the proper environment variables set. This is useful when is not desirable to add gtk3-nocsd to the system-wide LD_PRELOAD or if it should be applied only to certain applications. .SH CAVEATS .P When using \fBgtk3-nocsd\fR with \fBsetarch\fR (including alias such as \fBlinux32\fR), or anyway with chroots with different architectures than the host's, make sure to install the matching architecture version of \fBlibgtk3-nocsd.so.0\fR both in the \fBsetarch\fR environment and the host's environment. Note that the \fBgtk3-nocsd\fR binary must then be installed in a system path (\fI/usr/bin\fR, \fI/usr/local/bin\fR, ...), so that it will set LD_PRELOAD to just the library name and let the dynamic linker find it automatically - allowing the dynamic linker to pick the version for the correct architecture. If \fBgtk3-nocsd\fR is not installed in a system path, it will use a full path, allowing only for a single version of the library to be used. gtk3-nocsd-3/gtk3-nocsd.bash-completion000066400000000000000000000024201272335114500201550ustar00rootroot00000000000000# gtk3-nocsd bash completion module # # Copyright (C) 2014 Hong Jen Yee (PCMan) # # http://lxqt.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 Street, Fifth Floor, Boston, MA 02110-1301 USA _gtk3_nocsd() { local cur=${COMP_WORDS[COMP_CWORD]} local OPTS='-h --help' for (( i=1; i <= COMP_CWORD; i++ )); do if [[ ${COMP_WORDS[i]} != -* ]]; then local command=${COMP_WORDS[i]} _command_offset $i return fi done COMPREPLY=( $(compgen -W "$OPTS" -- "$cur") ) return 0 } complete -F _gtk3_nocsd gtk3-nocsd gtk3-nocsd-3/gtk3-nocsd.c000066400000000000000000002013551272335114500153230ustar00rootroot00000000000000/* gtk3-nocsd, a module used to disable GTK+3 client side decoration. Copyright (C) 2014 Hong Jen Yee (PCMan) http://lxqt.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 Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include typedef void (*gtk_window_buildable_add_child_t) (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *type); typedef GObject* (*gtk_dialog_constructor_t) (GType type, guint n_construct_properties, GObjectConstructParam *construct_params); typedef char *(*gtk_check_version_t) (guint required_major, guint required_minor, guint required_micro); typedef void (*gtk_header_bar_set_property_t) (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); typedef void (*gtk_header_bar_realize_t) (GtkWidget *widget); typedef void (*gtk_header_bar_unrealize_t) (GtkWidget *widget); typedef void (*gtk_header_bar_hierarchy_changed_t) (GtkWidget *widget, GtkWidget *previous_toplevel); enum { GTK_LIBRARY, GDK_LIBRARY, GOBJECT_LIBRARY, GLIB_LIBRARY, GIREPOSITORY_LIBRARY, NUM_LIBRARIES }; #ifndef GTK_LIBRARY_SONAME #define GTK_LIBRARY_SONAME "libgtk-3.so.0" #endif #ifndef GDK_LIBRARY_SONAME #define GDK_LIBRARY_SONAME "libgdk-3.so.0" #endif #ifndef GDK_LIBRARY_SONAME_V2 #define GDK_LIBRARY_SONAME_V2 "libgdk-x11-2.0.so.0" #endif #ifndef GOBJECT_LIBRARY_SONAME #define GOBJECT_LIBRARY_SONAME "libgobject-2.0.so.0" #endif #ifndef GLIB_LIBRARY_SONAME #define GLIB_LIBRARY_SONAME "libglib-2.0.so.0" #endif #ifndef GIREPOSITORY_LIBRARY_SONAME #define GIREPOSITORY_LIBRARY_SONAME "libgirepository-1.0.so.1" #endif static const char *library_sonames[NUM_LIBRARIES] = { GTK_LIBRARY_SONAME, GDK_LIBRARY_SONAME, GOBJECT_LIBRARY_SONAME, GLIB_LIBRARY_SONAME, GIREPOSITORY_LIBRARY_SONAME }; static const char *library_sonames_v2[NUM_LIBRARIES] = { NULL, GDK_LIBRARY_SONAME_V2, NULL, NULL, NULL }; static void * volatile library_handles[NUM_LIBRARIES * 2] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; static pthread_key_t key_tls; static pthread_once_t key_tls_once = PTHREAD_ONCE_INIT; typedef struct gtk3_nocsd_tls_data_t { // When set to true, this override gdk_screen_is_composited() and let it // return FALSE temporarily. Then, client-side decoration (CSD) cannot be initialized. volatile int disable_composite; volatile int signal_capture_handler; volatile int fake_global_decoration_layout; volatile int in_info_collect; const char *volatile signal_capture_name; volatile gpointer signal_capture_instance; volatile gpointer signal_capture_data; volatile GCallback signal_capture_callback; } gtk3_nocsd_tls_data_t; static gtk3_nocsd_tls_data_t *tls_data_location(); #define TLSD (tls_data_location()) __attribute__((destructor)) static void cleanup_library_handles(void) { int i; for (i = 0; i < NUM_LIBRARIES * 2; i++) { if (library_handles[i]) (void) dlclose(library_handles[i]); } } static void *find_orig_function(int try_gtk2, int library_id, const char *symbol) { void *handle; void *symptr; /* This will work in most cases, and is completely thread-safe. */ handle = dlsym(RTLD_NEXT, symbol); if (handle) return handle; /* dlsym(RTLD_NEXT, ...) will fail if the library using the symbol * is dlopen()d itself (e.g. a python module or similar), so what * we need to do is load the corresponding library ourselves and * look for the symbol there. We keep a reference to that library * so that we may close it again in a destructor function once we * are unloaded. dlopen()/dlclose() are refcounted, so we need to * use a mutex to protect dlopen(), otherwise we possibly could * take out more than one reference on the library and the cleanup * function wouldn't completely free it. * * Note that we use RTLD_NOLOAD, since we don't want to mask * problems if plugins aren't properly linked against gtk itself. */ handle = library_handles[library_id]; if (!handle) { static pthread_mutex_t handle_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&handle_mutex); /* we need to check again inside the mutex-protected block */ handle = library_handles[library_id]; if (!handle) handle = dlopen(library_sonames[library_id], RTLD_LAZY | RTLD_NOLOAD); if (handle) library_handles[library_id] = handle; pthread_mutex_unlock(&handle_mutex); if (!handle) { if (try_gtk2) goto try_gtk2_version; return NULL; } } symptr = dlsym(handle, symbol); if (symptr || !try_gtk2) return symptr; try_gtk2_version: /* We overwrite some functions that are already available in GDK2. * So just trying to dlopen() the GDK3 library will not work here, * because GDK2 is going to be loaded instead. Therefore, retry * with the GDK2 library - but only do so if the try_gtk2 flag is * set, because we only want to do that for functions that were * already available in Gtk/GDK2. Functions that were introduced * in Gtk3 will not receive this treatment. * * We are very fortunate that the two relevant functions are * binary compatible between GDK2 and GDK3. */ /* try_gtk2 should not be set for functions were we don't have a * Gtk2 variant of the library. So this should always hold. * Nevertheless, be paranoid. */ if (!library_sonames_v2[library_id]) return NULL; /* Same logic as above, but we use an offset in the library * handles and use the v2 soname. */ handle = library_handles[NUM_LIBRARIES + library_id]; if (!handle) { static pthread_mutex_t handle_v2_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&handle_v2_mutex); /* we need to check again inside the mutex-protected block */ handle = library_handles[NUM_LIBRARIES + library_id]; if (!handle) handle = dlopen(library_sonames_v2[library_id], RTLD_LAZY | RTLD_NOLOAD); if (handle) library_handles[NUM_LIBRARIES + library_id] = handle; pthread_mutex_unlock(&handle_v2_mutex); if (!handle) return NULL; } return dlsym(handle, symbol); } /* If a binary is compiled with ELF flag NOW (corresponding to RTLD_NOW), * but is not linked against gtk, if we use symbols from gtk the binary * they will fail to load. But we can't link this library against gtk3, * because we don't want to pull that in to every program and that * would also be incompatible with gtk2. Therefore, make sure we import * every function, not just those that we override, at runtime. */ #define HIDDEN_NAME2(a,b) a ## b #define NAME2(a,b) HIDDEN_NAME2(a,b) #define RUNTIME_IMPORT_FUNCTION(try_gtk2, library, function_name, return_type, arg_def_list, arg_use_list) \ static return_type NAME2(rtlookup_, function_name) arg_def_list { \ static return_type (*orig_func) arg_def_list = NULL;\ if (!orig_func) \ orig_func = find_orig_function(try_gtk2, library, #function_name); \ return orig_func arg_use_list; \ } RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_css_provider_new, GtkCssProvider *, (), ()) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_css_provider_load_from_data, void, (GtkCssProvider *provider, const gchar *data, gssize length, GError **error), (provider, data, length, error)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_window_new, GtkWidget *, (GtkWindowType type), (type)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_header_bar_new, GtkWidget *, (), ()) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_window_get_type, GType, (), ()) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_header_bar_get_type, GType, (), ()) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_window_get_titlebar, GtkWidget *, (GtkWindow *window), (window)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_widget_get_type, GType, (), ()) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_buildable_get_type, GType, (), ()) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_window_set_titlebar, void, (GtkWindow *window, GtkWidget *titlebar), (window, titlebar)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_header_bar_set_show_close_button, void, (GtkHeaderBar *bar, gboolean setting), (bar, setting)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_header_bar_set_decoration_layout, void, (GtkHeaderBar *bar, const gchar *layout), (bar, layout)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_header_bar_get_decoration_layout, const gchar *, (GtkHeaderBar *bar), (bar)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_style_context_add_class, void, (GtkStyleContext *context, const gchar *class_name), (context, class_name)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_style_context_remove_class, void, (GtkStyleContext *context, const gchar *class_name), (context, class_name)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_style_context_add_provider, void, (GtkStyleContext *context, GtkStyleProvider *provider, guint priority), (context, provider, priority)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_style_provider_get_type, GType, (), ()) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_widget_destroy, void, (GtkWidget *widget), (widget)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_widget_get_mapped, gboolean, (GtkWidget *widget), (widget)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_widget_get_realized, gboolean, (GtkWidget *widget), (widget)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_widget_get_style_context, GtkStyleContext *, (GtkWidget *widget), (widget)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_widget_map, void, (GtkWidget *widget), (widget)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_widget_set_parent, void, (GtkWidget *widget, GtkWidget *parent), (widget, parent)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_widget_unrealize, void, (GtkWidget *widget), (widget)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_widget_realize, void, (GtkWidget *widget), (widget)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_widget_get_settings, GtkSettings *, (GtkWidget *widget), (widget)) RUNTIME_IMPORT_FUNCTION(0, GTK_LIBRARY, gtk_widget_get_toplevel, GtkWidget *, (GtkWidget *widget), (widget)) RUNTIME_IMPORT_FUNCTION(0, GDK_LIBRARY, gdk_window_get_user_data, void, (GdkWindow *window, gpointer *data), (window, data)) RUNTIME_IMPORT_FUNCTION(1, GDK_LIBRARY, gdk_screen_is_composited, gboolean, (GdkScreen *screen), (screen)) RUNTIME_IMPORT_FUNCTION(1, GDK_LIBRARY, gdk_window_set_decorations, void, (GdkWindow *window, GdkWMDecoration decorations), (window, decorations)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_object_get_data, gpointer, (GObject *object, const gchar *key), (object, key)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_object_set_data, void, (GObject *object, const gchar *key, gpointer data), (object, key, data)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_object_ref, gpointer, (gpointer object), (object)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_object_unref, void, (gpointer object), (object)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_type_check_class_cast, GTypeClass *, (GTypeClass *g_class, GType is_a_type), (g_class, is_a_type)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_type_check_instance_is_a, gboolean, (GTypeInstance *instance, GType iface_type), (instance, iface_type)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_type_check_instance_cast, GTypeInstance *, (GTypeInstance *instance, GType iface_type), (instance, iface_type)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_object_class_find_property, GParamSpec *, (GObjectClass *oclass, const gchar *property_name), (oclass, property_name)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_type_register_static_simple, GType, (GType parent_type, const gchar *type_name, guint class_size, GClassInitFunc class_init, guint instance_size, GInstanceInitFunc instance_init, GTypeFlags flags), (parent_type, type_name, class_size, class_init, instance_size, instance_init, flags)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_type_add_interface_static, void, (GType instance_type, GType interface_type, const GInterfaceInfo *info), (instance_type, interface_type, info)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_type_add_instance_private, gint, (GType class_type, gsize private_size), (class_type, private_size)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_type_instance_get_private, gpointer, (GTypeInstance *instance, GType private_type), (instance, private_type)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_type_value_table_peek, GTypeValueTable *, (GType type), (type)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_type_check_instance_is_fundamentally_a, gboolean, (GTypeInstance *instance, GType fundamental_type), (instance, fundamental_type)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_signal_connect_data, gulong, (gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags), (instance, detailed_signal, c_handler, data, destroy_data, connect_flags)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_signal_handlers_disconnect_matched, guint, (gpointer instance, GSignalMatchType mask, guint signal_id, GQuark detail, GClosure *closure, gpointer func, gpointer data), (instance, mask, signal_id, detail, closure, func, data)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_object_get_valist, void, (GObject *object, const gchar *first_property_name, va_list var_args), (object, first_property_name, var_args)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_object_get_property, void, (GObject *object, const gchar *property_name, GValue *value), (object, property_name, value)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_value_init, GValue *, (GValue *value, GType g_type), (value, g_type)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_value_unset, void, (GValue *value), (value)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_value_get_string, const gchar *, (const GValue *value), (value)) RUNTIME_IMPORT_FUNCTION(0, GOBJECT_LIBRARY, g_value_get_boolean, gboolean, (const GValue *value), (value)) RUNTIME_IMPORT_FUNCTION(0, GLIB_LIBRARY, g_getenv, gchar *, (const char *name), (name)) RUNTIME_IMPORT_FUNCTION(0, GLIB_LIBRARY, g_logv, void, (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args), (log_domain, log_level, format, args)) RUNTIME_IMPORT_FUNCTION(0, GLIB_LIBRARY, g_free, void, (gpointer mem), (mem)) RUNTIME_IMPORT_FUNCTION(0, GLIB_LIBRARY, g_strdup, gchar *, (const gchar *str), (str)) RUNTIME_IMPORT_FUNCTION(0, GLIB_LIBRARY, g_strfreev, void, (gchar **str_array), (str_array)) RUNTIME_IMPORT_FUNCTION(0, GLIB_LIBRARY, g_strlcat, gsize, (gchar *dest, const gchar *src, gsize dest_size), (dest, src, dest_size)) RUNTIME_IMPORT_FUNCTION(0, GLIB_LIBRARY, g_strlcpy, gsize, (gchar *dest, const gchar *src, gsize dest_size), (dest, src, dest_size)) RUNTIME_IMPORT_FUNCTION(0, GLIB_LIBRARY, g_strsplit, gchar **, (const gchar *string, const gchar *delimiter, gint max_tokens), (string, delimiter, max_tokens)) RUNTIME_IMPORT_FUNCTION(0, GLIB_LIBRARY, g_assertion_message_expr, void, (const char *domain, const char *file, int line, const char *func, const char *expr), (domain, file, line, func, expr)) RUNTIME_IMPORT_FUNCTION(0, GIREPOSITORY_LIBRARY, g_function_info_prep_invoker, gboolean, (GIFunctionInfo *info, GIFunctionInvoker *invoker, GError **error), (info, invoker, error)) /* All methods that we want to overwrite are named orig_, all methods * that we just want to call (either directly or indirectrly) */ #define gtk_css_provider_new rtlookup_gtk_css_provider_new #define gtk_css_provider_load_from_data rtlookup_gtk_css_provider_load_from_data #define gtk_window_new rtlookup_gtk_window_new #define gtk_header_bar_new rtlookup_gtk_header_bar_new #define gtk_window_get_type rtlookup_gtk_window_get_type #define gtk_header_bar_get_type rtlookup_gtk_header_bar_get_type #define gtk_widget_get_type rtlookup_gtk_widget_get_type #define gtk_buildable_get_type rtlookup_gtk_buildable_get_type #define gtk_window_get_titlebar rtlookup_gtk_window_get_titlebar #define orig_gtk_window_set_titlebar rtlookup_gtk_window_set_titlebar #define orig_gtk_header_bar_set_show_close_button rtlookup_gtk_header_bar_set_show_close_button #define orig_gtk_header_bar_set_decoration_layout rtlookup_gtk_header_bar_set_decoration_layout #define orig_gtk_header_bar_get_decoration_layout rtlookup_gtk_header_bar_get_decoration_layout #define gtk_style_context_add_class rtlookup_gtk_style_context_add_class #define gtk_style_context_remove_class rtlookup_gtk_style_context_remove_class #define gtk_style_context_add_provider rtlookup_gtk_style_context_add_provider #define gtk_style_provider_get_type rtlookup_gtk_style_provider_get_type #define gtk_widget_destroy rtlookup_gtk_widget_destroy #define gtk_widget_get_mapped rtlookup_gtk_widget_get_mapped #define gtk_widget_get_realized rtlookup_gtk_widget_get_realized #define gtk_widget_get_style_context rtlookup_gtk_widget_get_style_context #define gtk_widget_map rtlookup_gtk_widget_map #define gtk_widget_set_parent rtlookup_gtk_widget_set_parent #define gtk_widget_unrealize rtlookup_gtk_widget_unrealize #define gtk_widget_realize rtlookup_gtk_widget_realize #define gdk_window_get_user_data rtlookup_gdk_window_get_user_data #define orig_gdk_screen_is_composited rtlookup_gdk_screen_is_composited #define orig_gdk_window_set_decorations rtlookup_gdk_window_set_decorations #define g_object_get_data rtlookup_g_object_get_data #define g_object_set_data rtlookup_g_object_set_data #define g_type_check_class_cast rtlookup_g_type_check_class_cast #define g_type_check_instance_is_a rtlookup_g_type_check_instance_is_a #define g_type_check_instance_cast rtlookup_g_type_check_instance_cast #define g_object_class_find_property rtlookup_g_object_class_find_property #define g_object_get_valist rtlookup_g_object_get_valist #define g_object_get_property rtlookup_g_object_get_property #define g_object_ref rtlookup_g_object_ref #define g_object_unref rtlookup_g_object_unref #define g_value_init rtlookup_g_value_init #define g_value_unset rtlookup_g_value_unset #define g_value_get_string rtlookup_g_value_get_string #define g_value_get_boolean rtlookup_g_value_get_boolean #define orig_g_type_register_static_simple rtlookup_g_type_register_static_simple #define orig_g_type_add_interface_static rtlookup_g_type_add_interface_static #define orig_g_type_add_instance_private rtlookup_g_type_add_instance_private #define orig_g_signal_connect_data rtlookup_g_signal_connect_data #define g_signal_handlers_disconnect_matched rtlookup_g_signal_handlers_disconnect_matched #define g_type_instance_get_private rtlookup_g_type_instance_get_private #define g_type_value_table_peek rtlookup_g_type_value_table_peek #define g_type_check_instance_is_fundamentally_a rtlookup_g_type_check_instance_is_fundamentally_a #define g_getenv rtlookup_g_getenv #define g_logv rtlookup_g_logv #define g_log static_g_log #define g_free rtlookup_g_free #define g_strdup rtlookup_g_strdup #define g_strfreev rtlookup_g_strfreev #define g_strlcat rtlookup_g_strlcat #define g_strlcpy rtlookup_g_strlcpy #define g_strsplit rtlookup_g_strsplit #define gtk_widget_get_settings rtlookup_gtk_widget_get_settings #define gtk_widget_get_toplevel rtlookup_gtk_widget_get_toplevel #define g_assertion_message_expr rtlookup_g_assertion_message_expr #define orig_g_function_info_prep_invoker rtlookup_g_function_info_prep_invoker /* Forwarding of varadic functions is tricky. */ static void static_g_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...) { va_list args; va_start (args, format); g_logv (log_domain, log_level, format, args); va_end (args); } static gboolean is_gtk_version_larger_or_equal(guint major, guint minor, guint micro) { static gtk_check_version_t orig_func = NULL; if(!orig_func) orig_func = (gtk_check_version_t)find_orig_function(0, GTK_LIBRARY, "gtk_check_version"); /* We may have not been able to load the function IF a * gtk2-using plugin was loaded into a non-gtk application. In * that case, we don't want to do anything anyway, so just say * we aren't compatible. * * Note that if the application itself is using gtk2, RTLD_NEXT * will give us a reference to gtk_check_version. But since * that symbol is compatible with gtk3, this doesn't hurt. */ if (orig_func) return (orig_func(major, minor, micro) == NULL); return FALSE; } static gboolean are_csd_disabled() { static volatile int csd_disabled = -1; if (csd_disabled == -1) { const gchar *csd_env; csd_env = g_getenv ("GTK_CSD"); csd_disabled = csd_env != NULL && strcmp (csd_env, "1") != 0; } return csd_disabled; } static gboolean is_compatible_gtk_version() { /* Marking both as volatile here saves the trouble of caring about * memory barriers. */ static volatile gboolean checked = FALSE; static volatile gboolean compatible = FALSE; if(G_UNLIKELY(!checked)) { if (!is_gtk_version_larger_or_equal(3, 10, 0)) { /* CSD was introduced there */ compatible = FALSE; } else { compatible = TRUE; } checked = TRUE; } return compatible; } static void set_has_custom_title(GtkWindow* window, gboolean set) { g_object_set_data(G_OBJECT(window), "custom_title", set ? GINT_TO_POINTER(1) : NULL); } static gboolean has_custom_title(GtkWindow* window) { return (gboolean)GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "custom_title")); } typedef void (*on_titlebar_title_notify_t) (GtkHeaderBar *titlebar, GParamSpec *pspec, GtkWindow *self); typedef void (*update_window_buttons_t) (GtkHeaderBar *bar); typedef gboolean (*window_state_changed_t) (GtkWidget *widget, GdkEventWindowState *event, gpointer data); typedef struct gtk_window_private_info_t { gsize title_box_offset; on_titlebar_title_notify_t on_titlebar_title_notify; } gtk_window_private_info_t; typedef struct gtk_header_bar_private_info_t { gsize decoration_layout_offset; update_window_buttons_t update_window_buttons; window_state_changed_t window_state_changed; } gtk_header_bar_private_info_t; static GType gtk_window_type = -1; static GType gtk_header_bar_type = -1; static gtk_window_private_info_t gtk_window_private_info (); static gtk_header_bar_private_info_t gtk_header_bar_private_info (); static GtkStyleProvider *get_custom_css_provider () { static GtkStyleProvider *volatile provider = NULL; static pthread_mutex_t provider_mutex = PTHREAD_MUTEX_INITIALIZER; /* This CSS works around some design issues with the header bar * when used with gtk3-nocsd. We first disable the padding, else * the "drop shadow" (actually a bottom border) of the header bar * doesn't fill out the entire window and the edges look weird. * With CSD Gtk's CSS also disables the padding, so this should be * safe and relatively theme-agnostic. (There is additional padding * inside child widgets, this padding was only 1px or so anyway.) * Next, we make sure that the edges aren't rounded anymore, to * make sure that there are no small black pixels on the top left * and top right side of the window contents. This should also be * theme-agnostic. * IMPORTANT: The CSS selectors here have to have the same (or * higher) selectivity than the selectors used in the theme's CSS. * Otherwise the settings here will not take effect, even though * this CSS here has a higher priority. See * for details. */ static const char *custom_css = "window > .titlebar:not(headerbar) {\n" " padding: 0;\n" " border-style: none;\n" " border-color: transparent;\n" "}\n" ".background:not(.tiled):not(.maximized) .titlebar:backdrop,\n" ".background:not(.tiled):not(.maximized) .titlebar {\n" " border-top-left-radius: 0;\n" " border-top-right-radius: 0;\n" "}\n" ""; if (G_UNLIKELY (provider == NULL)) { GtkCssProvider *new_provider; pthread_mutex_lock(&provider_mutex); if (provider != NULL) { /* Handle race condition. */ pthread_mutex_unlock(&provider_mutex); return provider; } new_provider = gtk_css_provider_new (); gtk_css_provider_load_from_data (new_provider, custom_css, -1, NULL); provider = GTK_STYLE_PROVIDER (new_provider); pthread_mutex_unlock(&provider_mutex); } return provider; } static void add_custom_css (GtkWidget *widget) { GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkStyleProvider *my_provider = get_custom_css_provider (); if (!context || !my_provider) return; /* Use a higher priority than SETTINGS, but lower than APPLICATION. * add_provider will make sure a given provider is not added twice. */ gtk_style_context_add_provider (context, my_provider, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS + 50); } // This API exists since gtk+ 3.10 extern void gtk_window_set_titlebar (GtkWindow *window, GtkWidget *titlebar) { if(!is_compatible_gtk_version() || !are_csd_disabled()) { orig_gtk_window_set_titlebar(window, titlebar); return; } if (titlebar && is_gtk_version_larger_or_equal (3, 16, 1)) { /* We have to reimplement gtk_window_set_titlebar ourselves, since * those Gtk versions don't support turning CSD off anymore. * This mainly does the same things as the original function * (consisting of adding the title bar widget + connecting signals), * but it will not enable CSD and not set the client_decorated flag * in the window private space. (We wouldn't know which bit it is * anyway.) */ gtk_window_private_info_t private_info = gtk_window_private_info (); char *priv = G_TYPE_INSTANCE_GET_PRIVATE (window, gtk_window_type, char); gboolean was_mapped = FALSE; GtkWidget *widget = GTK_WIDGET (window); GtkWidget **title_box_ptr = NULL; /* Something went wrong, so just stick with the original * implementation. */ if (private_info.title_box_offset == (gsize)-1 || private_info.title_box_offset == (gsize)-2 || !priv) goto orig_impl; title_box_ptr = (GtkWidget **) &priv[private_info.title_box_offset]; if (!*title_box_ptr) { was_mapped = gtk_widget_get_mapped (widget); if (gtk_widget_get_realized (widget)) { g_warning ("gtk_window_set_titlebar() called on a realized window"); gtk_widget_unrealize (widget); } } /* Remove any potential old title bar. We can't call * the static unset_titlebar() directly (not available), * so we call the full function; that shouldn't have * any side effects. */ orig_gtk_window_set_titlebar (window, NULL); /* The solid-csd class is not removed when the titlebar * is unset in Gtk (it's probably a bug), so unset it * here explicitly, in case it's set. */ gtk_style_context_remove_class (gtk_widget_get_style_context (widget), "solid-csd"); /* We need to store the titlebar in priv->title_box, * which is where title_box_ptr points to. Then we * need to reparent the title bar and connect signals * if it's a GtkHeaderBar. Apart from CSD enablement, * this is what the original function boils down to. */ *title_box_ptr = titlebar; gtk_widget_set_parent (*title_box_ptr, widget); if (GTK_IS_HEADER_BAR (titlebar)) { g_signal_connect (titlebar, "notify::title", G_CALLBACK (private_info.on_titlebar_title_notify), window); private_info.on_titlebar_title_notify (GTK_HEADER_BAR (titlebar), NULL, window); } gtk_style_context_add_class (gtk_widget_get_style_context (titlebar), GTK_STYLE_CLASS_TITLEBAR); add_custom_css (titlebar); if (was_mapped) gtk_widget_map (widget); return; } orig_impl: ++(TLSD->disable_composite); orig_gtk_window_set_titlebar(window, titlebar); if(window && titlebar) set_has_custom_title(window, TRUE); --(TLSD->disable_composite); } static int _remove_buttons_from_layout (char *new_layout, const char *old_layout) { gchar **tokens; gchar **t; int i, j, k; /* Assumptions: new_layout fits 256 bytes (including NUL), so make sure * that the old layout will fit */ if (strlen (old_layout) > 255) return -1; new_layout[0] = '\0'; tokens = g_strsplit (old_layout, ":", 2); if (tokens) { for (i = 0; i < 2; i++) { if (tokens[i] == NULL) break; if (i) g_strlcat (new_layout, ":", 256); t = g_strsplit (tokens[i], ",", -1); for (j = 0, k = 0; t[j]; j++) { /* We want to remove all standard window icons, while retaining * custom stuff. */ if (!strcmp (t[j], "icon") || !strcmp (t[j], "minimize") || !strcmp (t[j], "maximize") || !strcmp (t[j], "close")) continue; if (k) g_strlcat (new_layout, ",", 256); g_strlcat (new_layout, t[j], 256); k++; } g_strfreev (t); } g_strfreev (tokens); } else { g_strlcpy (new_layout, ":", 256); } return 0; } static void _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar) { gtk_header_bar_private_info_t info = gtk_header_bar_private_info (); char *priv = G_TYPE_INSTANCE_GET_PRIVATE (bar, gtk_header_bar_type, char); gchar **decoration_layout_ptr = NULL; gchar *orig_layout = NULL; gchar new_layout[256]; int r; if (info.decoration_layout_offset == (gsize) -1 || info.decoration_layout_offset == (gsize) -2 || !priv) { return; } /* We shouldn't hit this case, but check nevertheless. */ if (!is_compatible_gtk_version() || !are_csd_disabled()) { info.update_window_buttons (bar); return; } decoration_layout_ptr = (gchar **) &priv[info.decoration_layout_offset]; if (*decoration_layout_ptr) { orig_layout = *decoration_layout_ptr; r = _remove_buttons_from_layout (new_layout, *decoration_layout_ptr); if (r == 0) *decoration_layout_ptr = new_layout; } else { TLSD->fake_global_decoration_layout = 1; } info.update_window_buttons (bar); if (*decoration_layout_ptr) { *decoration_layout_ptr = orig_layout; } else { TLSD->fake_global_decoration_layout = 0; } } static gboolean _gtk_header_bar_window_state_changed (GtkWidget *widget, GdkEventWindowState *event, gpointer data) { gtk_header_bar_private_info_t info = gtk_header_bar_private_info (); GtkHeaderBar *bar = GTK_HEADER_BAR (data); gboolean ret; /* We can only be called if info.decoration_layout_offset is >= 0, * see hierarchy_changed, where this signal is connected, so this * shouldn't happen. If it does, though, just ignore the event, * it's certainly better than crashing with a segfault. */ if (info.decoration_layout_offset == (gsize) -1 || info.decoration_layout_offset == (gsize) -2 || !info.window_state_changed) { return FALSE; } /* Technically, we don't actually need to run the current version of * window_state_changed, as the current Gtk+3 code does nothing more * than we do here. Unfortunately, we need to be future-proof, so * make call it anyway, and later override it again with our own code. */ ret = info.window_state_changed (widget, event, data); if (!is_compatible_gtk_version() || !are_csd_disabled()) return ret; if (event->changed_mask & (GDK_WINDOW_STATE_FULLSCREEN | GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_TILED)) _gtk_header_bar_update_window_buttons (bar); return ret; } extern void g_object_get (gpointer _object, const gchar *first_property_name, ...) { GObject *object = _object; va_list var_args; const gchar *name; char new_layout[256]; int r; if (!G_IS_OBJECT (_object)) return; /* This is a really, really awful hack, because of the variable arguments * that g_object_get takes. At least Gtk+3 defines g_object_get_valist, * so we can default back to the valist original implementation if we * currently are not faking this for the decoration layout. Unfortunately, * there's no C way of forwarding to other varargs functions, so any other * preloaded library can't override the same function as we do here... * Fortunately, it's not very likely someone else wants to override * g_object_get(). */ va_start (var_args, first_property_name); if (G_UNLIKELY (TLSD->fake_global_decoration_layout)) { name = first_property_name; while (name) { GValue value = G_VALUE_INIT; GParamSpec *spec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), name); gchar *error; if (!spec) break; g_value_init (&value, spec->value_type); g_object_get_property (object, name, &value); if (G_UNLIKELY (strcmp (name, "gtk-decoration-layout") == 0)) { gchar **v = va_arg (var_args, gchar **); const gchar *s = g_value_get_string (&value); r = _remove_buttons_from_layout (new_layout, s); if (r == 0) s = new_layout; *v = g_strdup (s); } else { G_VALUE_LCOPY (&value, var_args, 0, &error); if (error) { g_warning ("%s: %s", "g_object_get_valist", error); g_free (error); g_value_unset (&value); break; } } g_value_unset (&value); name = va_arg (var_args, gchar *); } } else { g_object_get_valist (object, first_property_name, var_args); } va_end (var_args); } extern void gtk_header_bar_set_show_close_button (GtkHeaderBar *bar, gboolean setting) { /* Ancient Gtk+3 versions: we fake it via disabling show_close_button, * but that has adverse consequences, so in newer versions, where the * API is more complete, call our own implemnetation of u_w_b after * the original routine to perform some fixups. */ if(is_compatible_gtk_version() && are_csd_disabled() && !is_gtk_version_larger_or_equal(3, 12, 0)) setting = FALSE; orig_gtk_header_bar_set_show_close_button (bar, setting); if (is_compatible_gtk_version () && are_csd_disabled () && is_gtk_version_larger_or_equal (3, 12, 0)) _gtk_header_bar_update_window_buttons (bar); } extern void gtk_header_bar_set_decoration_layout (GtkHeaderBar *bar, const gchar *layout) { /* We need to call the original routine here, because it modifies the * private data structures. We fixup afterwards. */ orig_gtk_header_bar_set_decoration_layout (bar, layout); if(is_compatible_gtk_version() && are_csd_disabled() && is_gtk_version_larger_or_equal(3, 12, 0)) { _gtk_header_bar_update_window_buttons (bar); } } extern gboolean gdk_screen_is_composited (GdkScreen *screen) { /* With Gtk+3 3.16.1+ we reimplement gtk_window_set_titlebar ourselves, hence * we don't want to re-use the compositing hack, especially since it causes * problems in newer Gtk versions. */ if(is_compatible_gtk_version() && are_csd_disabled() && !is_gtk_version_larger_or_equal(3, 16, 1)) { if(TLSD->disable_composite) return FALSE; } return orig_gdk_screen_is_composited (screen); } extern void gdk_window_set_decorations (GdkWindow *window, GdkWMDecoration decorations) { if(is_compatible_gtk_version() && are_csd_disabled()) { if(decorations == GDK_DECOR_BORDER) { GtkWidget* widget = NULL; gdk_window_get_user_data(window, (void**)&widget); if(widget && GTK_IS_WINDOW(widget)) { // if this GdkWindow is associated with a GtkWindow // if this window has custom title (not using CSD), turn on all decorations if(has_custom_title(GTK_WINDOW(widget))) decorations = GDK_DECOR_ALL; } } } orig_gdk_window_set_decorations (window, decorations); } typedef void (*gtk_window_realize_t)(GtkWidget* widget); static gtk_window_realize_t orig_gtk_window_realize = NULL; static void fake_gtk_window_realize(GtkWidget* widget) { ++(TLSD->disable_composite); orig_gtk_window_realize(widget); --(TLSD->disable_composite); } static gtk_dialog_constructor_t orig_gtk_dialog_constructor = NULL; static GClassInitFunc orig_gtk_dialog_class_init = NULL; static GType gtk_dialog_type = 0; static GObject *fake_gtk_dialog_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_params) { ++(TLSD->disable_composite); GObject* obj = orig_gtk_dialog_constructor(type, n_construct_properties, construct_params); --(TLSD->disable_composite); return obj; } static void fake_gtk_dialog_class_init (GtkDialogClass *klass, gpointer data) { orig_gtk_dialog_class_init(klass, data); // GDialogClass* dialog_class = GTK_DIALOG_CLASS(klass); GObjectClass* object_class = G_OBJECT_CLASS(klass); if(object_class) { orig_gtk_dialog_constructor = object_class->constructor; object_class->constructor = fake_gtk_dialog_constructor; } } static GClassInitFunc orig_gtk_window_class_init = NULL; static void fake_gtk_window_class_init (GtkWindowClass *klass, gpointer data) { orig_gtk_window_class_init(klass, data); GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(klass); if(widget_class) { orig_gtk_window_realize = widget_class->realize; widget_class->realize = fake_gtk_window_realize; } } static gtk_header_bar_set_property_t orig_gtk_header_bar_set_property = NULL; static volatile int PROP_SHOW_CLOSE_BUTTON = -1; static void fake_gtk_header_bar_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { /* We haven't determined the property yet... */ if (G_UNLIKELY(PROP_SHOW_CLOSE_BUTTON == -1)) { GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(object), "show-close-button"); if (spec) /* Technically, this is marked as internal in GParamSpec, * but it's the only way to access that trivially. It's * been stable in gobject for over a decade now. */ PROP_SHOW_CLOSE_BUTTON = spec->param_id; else /* We couldn't find out, for some reason. The value -2 * will never match a valid property id, so should be safe. */ PROP_SHOW_CLOSE_BUTTON = -2; } /* In theory, we shouldn't need to override this, since * set_property in the gtk3 source code just calls that function, * but with active compiler optimization, an inline version of it * may be copied into set_propery, so we also need to override * this here. */ if(G_UNLIKELY((int)prop_id == PROP_SHOW_CLOSE_BUTTON)) gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (object), g_value_get_boolean (value)); else orig_gtk_header_bar_set_property (object, prop_id, value, pspec); } static gtk_header_bar_realize_t orig_gtk_header_bar_realize = NULL; static void fake_gtk_header_bar_realize (GtkWidget *widget) { gtk_header_bar_private_info_t info; GtkSettings *settings; orig_gtk_header_bar_realize (widget); settings = gtk_widget_get_settings (widget); /* realize() is called from gtk_header_bar_private_info, so make sure * we special-case that. */ if (G_UNLIKELY (TLSD->in_info_collect)) return; info = gtk_header_bar_private_info (); if (info.decoration_layout_offset == (gsize) -1 || info.decoration_layout_offset == (gsize) -2) return; /* Replace signal handlers with our own */ g_signal_handlers_disconnect_by_func (settings, info.update_window_buttons, widget); g_signal_connect_swapped (settings, "notify::gtk-shell-shows-app-menu", G_CALLBACK (_gtk_header_bar_update_window_buttons), widget); g_signal_connect_swapped (settings, "notify::gtk-decoration-layout", G_CALLBACK (_gtk_header_bar_update_window_buttons), widget); _gtk_header_bar_update_window_buttons (GTK_HEADER_BAR (widget)); } static gtk_header_bar_unrealize_t orig_gtk_header_bar_unrealize = NULL; static void fake_gtk_header_bar_unrealize (GtkWidget *widget) { /* Disconnect our own signal handlers */ GtkSettings *settings = gtk_widget_get_settings (widget); g_signal_handlers_disconnect_by_func (settings, _gtk_header_bar_update_window_buttons, widget); orig_gtk_header_bar_unrealize (widget); } static gtk_header_bar_hierarchy_changed_t orig_gtk_header_bar_hierarchy_changed = NULL; static void fake_gtk_header_bar_hierarchy_changed (GtkWidget *widget, GtkWidget *previous_toplevel) { gtk_header_bar_private_info_t info; GtkWidget *toplevel; GtkHeaderBar *bar = GTK_HEADER_BAR (widget); /* Older Gtk+3 versions didn't set this, so just ignore the event. */ if (!orig_gtk_header_bar_hierarchy_changed) return; orig_gtk_header_bar_hierarchy_changed (widget, previous_toplevel); if (G_UNLIKELY (TLSD->in_info_collect)) return; toplevel = gtk_widget_get_toplevel (widget); /* We can always do this. */ if (previous_toplevel) g_signal_handlers_disconnect_by_func (previous_toplevel, _gtk_header_bar_window_state_changed, widget); info = gtk_header_bar_private_info (); if (info.decoration_layout_offset == (gsize) -1 && info.decoration_layout_offset == (gsize) -2) return; if (toplevel) { g_signal_handlers_disconnect_by_func (toplevel, info.window_state_changed, widget); g_signal_connect_after (toplevel, "window-state-event", G_CALLBACK (_gtk_header_bar_window_state_changed), widget); } _gtk_header_bar_update_window_buttons (bar); } static GClassInitFunc orig_gtk_header_bar_class_init = NULL; static void fake_gtk_header_bar_class_init (GtkWindowClass *klass, gpointer data) { orig_gtk_header_bar_class_init(klass, data); GObjectClass* object_class = G_OBJECT_CLASS(klass); GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); if(object_class) { orig_gtk_header_bar_set_property = object_class->set_property; object_class->set_property = fake_gtk_header_bar_set_property; } if (widget_class) { orig_gtk_header_bar_realize = widget_class->realize; orig_gtk_header_bar_unrealize = widget_class->unrealize; orig_gtk_header_bar_hierarchy_changed = widget_class->hierarchy_changed; widget_class->realize = fake_gtk_header_bar_realize; widget_class->unrealize = fake_gtk_header_bar_unrealize; widget_class->hierarchy_changed = fake_gtk_header_bar_hierarchy_changed; } } static GInstanceInitFunc orig_gtk_shortcuts_window_init = NULL; static void fake_gtk_shortcuts_window_init (GtkWindow *window, gpointer klass) { GtkHeaderBar *title_bar; orig_gtk_shortcuts_window_init ((GTypeInstance *) window, klass); /* call our own set_titlebar to make sure we disable CSDs * (the original Gtk function calls Gtk's internal set_titlebar) */ title_bar = GTK_HEADER_BAR (gtk_window_get_titlebar (window)); if (title_bar) { /* We need to take a reference out on the title_bar, because * unsetting it will unref() it indirectly via gtk_widget_unparent(), * which would otherwise call the destructor, because it's only * referenced once. */ g_object_ref (title_bar); orig_gtk_window_set_titlebar (window, NULL); gtk_window_set_titlebar (window, GTK_WIDGET (title_bar)); /* Drop our own reference (because it's not floating, and set_titlebar * calls ref_sink indirectly via set_parent) */ g_object_unref (title_bar); } } GType g_type_register_static_simple (GType parent_type, const gchar *type_name, guint class_size, GClassInitFunc class_init, guint instance_size, GInstanceInitFunc instance_init, GTypeFlags flags) { GType type; GType *save_type = NULL; if(!orig_gtk_window_class_init) { // GtkWindow is not overriden if(type_name && G_UNLIKELY(strcmp(type_name, "GtkWindow") == 0)) { // override GtkWindowClass orig_gtk_window_class_init = class_init; if(is_compatible_gtk_version() && are_csd_disabled()) { class_init = (GClassInitFunc)fake_gtk_window_class_init; save_type = >k_window_type; goto out; } } } if(!orig_gtk_dialog_class_init) { // GtkDialog::constructor is not overriden if(type_name && G_UNLIKELY(strcmp(type_name, "GtkDialog") == 0)) { // override GtkDialogClass orig_gtk_dialog_class_init = class_init; if(is_compatible_gtk_version() && are_csd_disabled()) { class_init = (GClassInitFunc)fake_gtk_dialog_class_init; save_type = >k_dialog_type; goto out; } } } if(!orig_gtk_header_bar_class_init) { // GtkHeaderBar::constructor is not overriden if(type_name && G_UNLIKELY(strcmp(type_name, "GtkHeaderBar") == 0)) { // override GtkHeaderBarClass orig_gtk_header_bar_class_init = class_init; if(is_compatible_gtk_version() && are_csd_disabled()) { class_init = (GClassInitFunc)fake_gtk_header_bar_class_init; save_type = >k_header_bar_type; goto out; } } } if(!orig_gtk_shortcuts_window_init) { // GtkShortcutsWindow::constructor is not overriden if(type_name && G_UNLIKELY(strcmp(type_name, "GtkShortcutsWindow") == 0)) { // override GtkShortcutsWindowClass orig_gtk_shortcuts_window_init = instance_init; if(is_compatible_gtk_version() && are_csd_disabled()) { instance_init = (GInstanceInitFunc) fake_gtk_shortcuts_window_init; goto out; } } } out: type = orig_g_type_register_static_simple (parent_type, type_name, class_size, class_init, instance_size, instance_init, flags); if (save_type) *save_type = type; return type; } static gtk_window_buildable_add_child_t orig_gtk_window_buildable_add_child = NULL; static gtk_window_buildable_add_child_t orig_gtk_dialog_buildable_add_child = NULL; static void fake_gtk_window_buildable_add_child (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *type) { if (type && strcmp (type, "titlebar") == 0) { gtk_window_set_titlebar (GTK_WINDOW (buildable), GTK_WIDGET (child)); return; } orig_gtk_window_buildable_add_child(buildable, builder, child, type); } static void fake_gtk_dialog_buildable_add_child (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *type) { if (type && strcmp (type, "titlebar") == 0) { gtk_window_set_titlebar (GTK_WINDOW (buildable), GTK_WIDGET (child)); return; } orig_gtk_dialog_buildable_add_child(buildable, builder, child, type); } static GInterfaceInitFunc orig_gtk_window_buildable_interface_init = NULL; static GInterfaceInitFunc orig_gtk_dialog_buildable_interface_init = NULL; static void fake_gtk_window_buildable_interface_init (GtkBuildableIface *iface, gpointer data) { orig_gtk_window_buildable_interface_init(iface, data); orig_gtk_window_buildable_add_child = iface->add_child; iface->add_child = fake_gtk_window_buildable_add_child; // printf("intercept gtk_window_buildable_interface_init!!\n"); // iface->set_buildable_property = gtk_window_buildable_set_buildable_property; } static void fake_gtk_dialog_buildable_interface_init (GtkBuildableIface *iface, gpointer data) { orig_gtk_dialog_buildable_interface_init(iface, data); orig_gtk_dialog_buildable_add_child = iface->add_child; iface->add_child = fake_gtk_dialog_buildable_add_child; } void g_type_add_interface_static (GType instance_type, GType interface_type, const GInterfaceInfo *info) { if(is_compatible_gtk_version() && are_csd_disabled() && (instance_type == gtk_window_type || instance_type == gtk_dialog_type)) { if(interface_type == GTK_TYPE_BUILDABLE) { // register GtkBuildable interface for GtkWindow/GtkDialog class GInterfaceInfo fake_info = *info; if (instance_type == gtk_window_type) { orig_gtk_window_buildable_interface_init = info->interface_init; fake_info.interface_init = (GInterfaceInitFunc)fake_gtk_window_buildable_interface_init; } else { orig_gtk_dialog_buildable_interface_init = info->interface_init; fake_info.interface_init = (GInterfaceInitFunc)fake_gtk_dialog_buildable_interface_init; } orig_g_type_add_interface_static (instance_type, interface_type, &fake_info); return; } } orig_g_type_add_interface_static (instance_type, interface_type, info); } static gsize gtk_window_private_size = 0; static gint gtk_window_private_offset = 0; static gsize gtk_header_bar_private_size = 0; static gint gtk_header_bar_private_offset = 0; gint g_type_add_instance_private (GType class_type, gsize private_size) { if (G_UNLIKELY (class_type == gtk_window_type && gtk_window_private_size == 0)) { gtk_window_private_size = private_size; gtk_window_private_offset = orig_g_type_add_instance_private (class_type, private_size); return gtk_window_private_offset; } else if (G_UNLIKELY (class_type == gtk_header_bar_type && gtk_header_bar_private_size == 0)) { gtk_header_bar_private_size = private_size; gtk_header_bar_private_offset = orig_g_type_add_instance_private (class_type, private_size); return gtk_window_private_offset; } return orig_g_type_add_instance_private (class_type, private_size); } gulong g_signal_connect_data (gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags) { if (G_UNLIKELY (TLSD->signal_capture_handler)) { const char *name = TLSD->signal_capture_name; if (instance != NULL && TLSD->signal_capture_instance == instance && strcmp (detailed_signal, name) == 0) TLSD->signal_capture_callback = c_handler; else if (data != NULL && TLSD->signal_capture_data == data && strcmp (detailed_signal, name) == 0) TLSD->signal_capture_callback = c_handler; } return orig_g_signal_connect_data (instance, detailed_signal, c_handler, data, destroy_data, connect_flags); } static int find_unique_pointer_in_region (const char *haystack, gsize haystack_size, const void *needle) { gsize i; int offset = -1; /* This is definitely not the most efficient algorithm, but * since this is only called twice per program, we're not * going to optimize it. */ for (i = 0; i <= haystack_size - sizeof (needle); i++) { if (memcmp (&haystack[i], (void *) &needle, sizeof (needle)) == 0) { /* The pointer should only occur once in this memory * region - if not, then something's gone wrong. */ if (offset != -1) return -2; offset = (int) i; } } return offset; } static gtk_window_private_info_t gtk_window_private_info () { static volatile gtk_window_private_info_t info = { (gsize) -1, NULL }; if (G_UNLIKELY (info.title_box_offset == (gsize) -1)) { if (gtk_window_private_size != 0) { /* We have to detect the offset of where the title_box pointer * is stored in a GtkWindowPrivate object. This is required * because we need to change the pointer inside * GtkWindowPrivate causing any side effects (especially * without enabling CSD) - and the set_titlebar function will * enable CSD (in >= 3.16.1) if any non-NULL titlebar is set. * Therefore, we need to find the pointer offset within the * private data at runtime (it's not guaranteed to be stable * ABI-wise, so we can't just hard-code things, that would * lead to crashes). Furthermore, we need to know the address * of the static callback function that's used to process the * notify::title signal emitted by header bars. * * The basic algorithm is as follows: create a dummy GtkWindow, * create a dummy GtkHeaderBar, call the original * gtk_window_set_titlebar function and then look for the pointer * in the private data region of the GtkWindow. The size of the * region was recorded by us when the type was registered, so we * will stay within the proper memory region. */ GtkWindow *dummy_window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL)); void *window_priv = NULL; GtkHeaderBar *dummy_bar = GTK_HEADER_BAR (gtk_header_bar_new ()); int offset = -1; /* We're collecting information, so make sure all hacks * are NOOPS. */ TLSD->in_info_collect = 1; if (!dummy_window || !dummy_bar) { g_warning ("libgtk3-nocsd: couldn't create dummy objects (GtkWindow, GtkHeaderBar) to determine this Gtk's runtime data structure layout"); goto out; } /* First let's try to make sure the pointer is not present in * the memory region. */ window_priv = G_TYPE_INSTANCE_GET_PRIVATE (dummy_window, gtk_window_type, void); offset = find_unique_pointer_in_region (window_priv, gtk_window_private_size, dummy_bar); /* Make sure the pointer isn't in there, else */ if (offset != -1) { g_warning ("libgtk3-nocsd: error trying to determine this Gtk's runtime data structure layout: GtkWindow private structure already contained a pointer to GtkHeaderBar before setting title bar"); goto out; } /* Set the title bar via the original title bar function. */ TLSD->signal_capture_callback = NULL; TLSD->signal_capture_handler = 1; TLSD->signal_capture_name = "notify::title"; TLSD->signal_capture_instance = dummy_bar; TLSD->signal_capture_data = NULL; orig_gtk_window_set_titlebar (dummy_window, GTK_WIDGET (dummy_bar)); TLSD->signal_capture_handler = 0; TLSD->signal_capture_instance = NULL; TLSD->signal_capture_name = NULL; /* Now find the pointer in memory. */ offset = find_unique_pointer_in_region (window_priv, gtk_window_private_size, dummy_bar); if (offset < 0) { g_warning ("libgtk3-nocsd: error trying to determine this Gtk's runtime data structure layout: GtkWindow private structure doesn't contain a pointer to GtkHeaderBar after setting title bar (error type %d)", -offset); goto out; } if (TLSD->signal_capture_callback == NULL) { g_warning ("libgtk3-nocsd: error trying to determine this Gtk's callback routine for GtkHeaderBar/GtkWindow interaction"); goto out; } info.on_titlebar_title_notify = (on_titlebar_title_notify_t) TLSD->signal_capture_callback; info.title_box_offset = offset; out: if (dummy_window) gtk_widget_destroy (GTK_WIDGET (dummy_window)); else if (dummy_bar) gtk_widget_destroy (GTK_WIDGET (dummy_bar)); TLSD->in_info_collect = 0; } } return info; } static gtk_header_bar_private_info_t gtk_header_bar_private_info () { static volatile gtk_header_bar_private_info_t info = { (gsize) -1, NULL }; if (G_UNLIKELY (info.decoration_layout_offset == (gsize) -1)) { /* Was only introduced in Gtk+3 >= 3.12. Unlikely that someone is * still using such an old version, but be safe nevertheless. */ if (G_UNLIKELY (!is_gtk_version_larger_or_equal(3, 12, 0))) { return info; } if (gtk_header_bar_private_size != 0) { /* We want to detect the offset of the pointer for the * decoration_layout string in the private structure, so we * create a header bar and set a decoration layout. As the * setter does g_strdup, we have to call the getter again, * because that will return the actual pointer that's stored. */ GtkWindow *dummy_window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL)); GtkHeaderBar *dummy_bar = GTK_HEADER_BAR (gtk_header_bar_new ()); void *header_bar_priv = NULL; const gchar *ptr = NULL; const gchar **ptr_in_priv; int offset = -1; gpointer ws_cb = NULL; /* We're collecting information, so make sure all hacks * are NOOPS. */ TLSD->in_info_collect = 1; if (!dummy_bar || !dummy_window) { g_warning ("libgtk3-nocsd: couldn't create dummy object (GtkHeaderBar) to determine this Gtk's runtime data structure layout"); goto out; } /* add it to our dummy window (we need a window here because * we want to realize the header bar, and that we can only * do if it's attached to a top-level window) */ TLSD->signal_capture_callback = NULL; TLSD->signal_capture_handler = 1; TLSD->signal_capture_name = "window-state-event"; TLSD->signal_capture_instance = dummy_window; TLSD->signal_capture_data = NULL; orig_gtk_window_set_titlebar (dummy_window, GTK_WIDGET (dummy_bar)); TLSD->signal_capture_handler = 0; TLSD->signal_capture_instance = NULL; TLSD->signal_capture_name = NULL; ws_cb = TLSD->signal_capture_callback; header_bar_priv = G_TYPE_INSTANCE_GET_PRIVATE (dummy_bar, gtk_header_bar_type, void); orig_gtk_header_bar_set_decoration_layout (dummy_bar, "menu:close"); ptr = orig_gtk_header_bar_get_decoration_layout (dummy_bar); offset = find_unique_pointer_in_region (header_bar_priv, gtk_header_bar_private_size, ptr); if (offset < 0) { g_warning ("libgtk3-nocsd: error trying to determine this Gtk's runtime data structure layout: GtkHeaderBar private structure doesn't contain a pointer to decoration_layout after setting it (error type %d)", -offset); goto out; } /* We now verify that the pointer is NULL */ orig_gtk_header_bar_set_decoration_layout (dummy_bar, NULL); ptr_in_priv = (const gchar **) &((char *)header_bar_priv)[offset]; if (*ptr_in_priv != NULL) { g_warning ("libgtk3-nocsd: error trying to determine this Gtk's runtime data structure layout: GtkHeaderBar's priv->decoration_layout pointer position sanity check failed (got pointer %p instead of NULL)", *ptr_in_priv); goto out; } /* realize the widget to capture the * _gtk_header_bar_update_window_buttons callback */ TLSD->signal_capture_callback = NULL; TLSD->signal_capture_handler = 1; TLSD->signal_capture_name = "notify::gtk-decoration-layout"; TLSD->signal_capture_instance = NULL; TLSD->signal_capture_data = dummy_bar; gtk_widget_realize (GTK_WIDGET (dummy_bar)); TLSD->signal_capture_handler = 0; TLSD->signal_capture_data = NULL; TLSD->signal_capture_name = NULL; if (TLSD->signal_capture_callback == NULL) { g_warning ("libgtk3-nocsd: error trying to determine this Gtk's callback routine for GtkHeaderBar's button update"); goto out; } info.decoration_layout_offset = offset; info.update_window_buttons = (update_window_buttons_t) TLSD->signal_capture_callback; /* Don't check ws_cb, it may be NULL, because older Gtk+3 versions didn't use that. */ info.window_state_changed = (window_state_changed_t) ws_cb; out: if (dummy_window) gtk_widget_destroy (GTK_WIDGET (dummy_window)); else if (dummy_bar) gtk_widget_destroy (GTK_WIDGET (dummy_bar)); TLSD->in_info_collect = 0; } } return info; } gboolean g_function_info_prep_invoker (GIFunctionInfo *info, GIFunctionInvoker *invoker, GError **error) { static gpointer orig_set_titlebar = NULL, orig_set_show_close_button = NULL, orig_set_decoration_layout = NULL; gboolean result; if (!orig_set_titlebar) orig_set_titlebar = (gpointer) find_orig_function (0, GTK_LIBRARY, "gtk_window_set_titlebar"); if (!orig_set_show_close_button) orig_set_show_close_button = (gpointer) find_orig_function (0, GTK_LIBRARY, "gtk_header_bar_set_show_close_button"); if (!orig_set_decoration_layout) orig_set_decoration_layout = (gpointer) find_orig_function (0, GTK_LIBRARY, "gtk_header_bar_set_decoration_layout"); result = orig_g_function_info_prep_invoker (info, invoker, error); if (result) { if (G_UNLIKELY (invoker->native_address == orig_set_titlebar)) invoker->native_address = gtk_window_set_titlebar; if (G_UNLIKELY (invoker->native_address == orig_set_show_close_button)) invoker->native_address = gtk_header_bar_set_show_close_button; if (G_UNLIKELY (invoker->native_address == orig_set_decoration_layout)) invoker->native_address = gtk_header_bar_set_decoration_layout; } return result; } static void create_key_tls() { int r; r = pthread_key_create (&key_tls, free); if (r < 0) g_error ("libgtk3-nocsd: unable to initialize TLS data: %s", strerror(errno)); } static gtk3_nocsd_tls_data_t *tls_data_location() { void *ptr; int r; (void) pthread_once (&key_tls_once, create_key_tls); if ((ptr = pthread_getspecific (key_tls)) == NULL) { ptr = calloc (1, sizeof (gtk3_nocsd_tls_data_t)); if (!ptr) g_error ("libgtk3-nocsd: unable to initialize TLS data: %s", strerror(errno)); r = pthread_setspecific (key_tls, ptr); if (r < 0) g_error ("libgtk3-nocsd: unable to initialize TLS data: %s", strerror(errno)); } return (gtk3_nocsd_tls_data_t *) ptr; } gtk3-nocsd-3/gtk3-nocsd.in000066400000000000000000000062061272335114500155050ustar00rootroot00000000000000#!/bin/sh # # gtk3-nocsd - Wrapper to apply gtk3-nocsd to application # # Usage: ln -s /path/to/gtk3-nocsd ~/bin/evince # Or: gtk3-nocsd evince # # Create a symlink to this wrapper script with the name of the program # you want run without client-side decorations. This wrapper script # will run the first matching executable in the PATH that is *not* a # symlink to gtk3-nocsd. This wrapper script is useful if you don't # want to add gtk3-nocsd to your system-wide LD_PRELOAD or if you only # want it applied to certain applications. # # Alternative mode of operation: call this wrapper directly with the # program to call as its arguments. # GTK3_NOCSD_NAME=libgtk3-nocsd.so.0 # Determine if this script are installed in the system path GTK3_NOCSD_BINARY="$(readlink -fe "$(which "$0")")" case "${GTK3_NOCSD_BINARY%/*}" in /sbin|/bin|/usr/bin|/usr/sbin|/usr/local/bin|/usr/local/sbin) IN_SYSTEM_PATH=1 ;; *) IN_SYSTEM_PATH=0 ;; esac # Determine if the library is in the system path. If that's the case, # just use the plain library name, because that way loading the library # on all architectures it's installed is supported (because the linker # will automatically pick out the right one). if [ $IN_SYSTEM_PATH -eq 1 ] ; then if LC_ALL=C LD_PRELOAD="${GTK3_NOCSD_NAME}" /bin/true 2>&1 | grep LD_PRELOAD | grep -qF "${GTK3_NOCSD_NAME}" ; then IN_SYSTEM_PATH=0 else GTK3_NOCSD="${GTK3_NOCSD_NAME}" fi fi if [ $IN_SYSTEM_PATH -eq 0 ] ; then # Figure out where the library is installed. First try the path # that was used when building gtk3-nocsd, then try the directory # the binary is installed. INSTALLED_PATH="@@libdir@@" BINARY_PATH="${GTK3_NOCSD_BINARY%/*}" GTK3_NOCSD="" for _path in "$INSTALLED_PATH" "$BINARY_PATH" "${BINARY_PATH%/bin}/lib" ; do if [ -e "${_path}/${GTK3_NOCSD_NAME}" ] ; then GTK3_NOCSD="${_path}/${GTK3_NOCSD_NAME}" break fi done if [ -z "$GTK3_NOCSD" ] ; then # this will _probably_ not work (unless the library is # installed in a system path, but the binary wasn't), but at # least the user will have a useful error message GTK3_NOCSD="${GTK3_NOCSD_NAME}" fi fi # This program was called directly, instead of via a symlink. if [ x"$(basename "$0")"x = x"gtk3-nocsd"x ] ; then if [ x"$1"x = x"-h"x ] || [ x"$1"x = x"--help"x ] ; then echo "Usage: $0 program [args]" exit 0 fi export GTK_CSD=0 export LD_PRELOAD="${GTK3_NOCSD}${LD_PRELOAD:+:$LD_PRELOAD}" exec "$@" fi # Find the real program (the first one that's not symlinked to get3-nocsd) APPNAME="$(basename "$0")" for APPPATH in $(which -a "$APPNAME") /bin/false; do APPPATH_LINK="$(readlink -fe "$APPPATH")" [ x"${APPPATH_LINK##*/}"x = x"gtk3-nocsd"x ] || break done # Provide error message at all if [ x"$APPNAME"x != x"false"x ] && [ x"${APPPATH}"x = x"/bin/false"x ] ; then APPPATH=/.gtk3-nocsd./"$APPNAME" fi # Run the program with CSD disabled export LD_PRELOAD="${GTK3_NOCSD}${LD_PRELOAD:+:$LD_PRELOAD}" export GTK_CSD=0 exec "$APPPATH" "$@" gtk3-nocsd-3/test-dummylib.c000066400000000000000000000005521272335114500161420ustar00rootroot00000000000000/* Dummy test library. * * This library will be dlopen()d by test-static-tls in multiple different * versions to see if libgtk3-nocsd.so uses up a static TLS entry, which * it shouldn't. */ static __thread int i = 0; #define NAME2_HIDDEN(a, b) a ## b #define NAME2(a, b) NAME2_HIDDEN(a,b) int *NAME2(testlib_dummy_get_, TESTLIB_NAME) () { return &i; } gtk3-nocsd-3/test-now.c000066400000000000000000000000331272335114500151150ustar00rootroot00000000000000int main() { return 0; } gtk3-nocsd-3/test-static-tls.c000066400000000000000000000043271272335114500164130ustar00rootroot00000000000000/* * test-static-tls: Verify that libgtk3-nocsd.so doesn't use up an * overflow DTV entry in the loaded program * * Logic is simple: try to dlopen() as many different libraries as * possible that contain static TLS entries (62 were built by the * Makefile), so that it can be determined what the cutoff is for * the case with and without LD_PRELOAD. (The cutoff is limited by * the number of overflow static DTV entries the dynamic linker * users by default.) * * This program will output the number of libraries it could load. * * Threading is necessary, otherwise the DTV will not be used. */ #include #include #include #include #include #include static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; static const char *preloaded = "none"; static void *doit(void *dummy) { char buf[] = "testlibs/libdummy-_.so.0"; /* replace char @ index 18 (_) */ char buf2[] = "testlib_dummy_get__"; /* replace char @ index 18 (_) */ void *hdl; int *(*fn)(); int c; int lastlib = -1; int *ptr; for (c = 0; c < sizeof(alphabet) - 1; c++) { buf[18] = alphabet[c]; buf2[18] = alphabet[c]; hdl = dlopen(buf, RTLD_NOW | RTLD_GLOBAL); if (!hdl) { if (lastlib < 0) { printf("ERROR[preloaded = %s]: couldn't load ANY library at all: %s\n", preloaded, dlerror()); break; } printf("%d\n", lastlib + 1); break; } fn = (int *(*)())dlsym(hdl, buf2); if (!fn) { printf("ERROR[preloaded = %s]: symbol %s not found: %s\n", preloaded, buf2, dlerror()); break; } ptr = fn(); if (*ptr != 0) { printf("ERROR[preloaded = %s]: function %s did not give expected result\n", preloaded, buf2); break; } lastlib = c; } if (c == sizeof(alphabet) - 1) printf("%d\n", lastlib + 1); return dummy; } int main(int argc, char **argv) { int r; pthread_t thread; if (argc >= 2) preloaded = argv[1]; r = pthread_create(&thread, NULL, doit, NULL); if (r < 0) { printf("ERROR[preloaded = %s]: could not create thread: %s\n", preloaded, strerror(errno)); return 1; } (void) pthread_join(thread, NULL); return 0; }