windowlab-1.40/0000777000175000017500000000000011356155554012074 5ustar nicknickwindowlab-1.40/Makefile0000666000175000017500000000422511274636755013545 0ustar nicknick# Makefile for WindowLab # Comment out to remove shape support (for X11R5 or just a tiny bin) DEFINES += -DSHAPE EXTRA_LIBS += -lXext # Set this to the hardcoded location of all files if it's not / PREFIX = /usr/local # Set this to the directory, below PREFIX, where man pages # are expected. Below this directory, the target "install" # will put "windowlab.1x" in section "man1". MANBASE = /man # Set this to the location of the X installation you want to compile against XROOT = /usr/X11R6 # Some flexibility for configuration location CONFPREFIX = $(PREFIX) CONFDIR = /etc/X11/windowlab # Set this to the location of the global configuration files SYSCONFDIR = $(CONFPREFIX)$(CONFDIR) # Information about the location of the menurc file ifndef MENURC MENURC = $(SYSCONFDIR)/windowlab.menurc endif DEFINES += -DDEF_MENURC="\"$(MENURC)\"" # Uncomment to add MWM hints support #DEFINES += -DMWM_HINTS # Uncomment to add freetype support (requires XFree86 4.0.2 or later) # This needs -lXext above, even if you have disabled shape support #DEFINES += -DXFT #EXTRA_INC += `pkg-config --cflags xft` #EXTRA_LIBS += `pkg-config --libs xft` # Uncomment for debugging info (abandon all hope, ye who enter here) #DEFINES += -DDEBUG # -------------------------------------------------------------------- CC = gcc ifndef CFLAGS CFLAGS = -g -O2 -Wall -W endif BINDIR = $(DESTDIR)$(PREFIX)/bin MANDIR = $(DESTDIR)$(PREFIX)$(MANBASE)/man1 CFGDIR = $(DESTDIR)$(SYSCONFDIR) INCLUDES = -I$(XROOT)/include $(EXTRA_INC) LDPATH = -L$(XROOT)/lib LIBS = -lX11 $(EXTRA_LIBS) PROG = windowlab MANPAGE = windowlab.1x OBJS = main.o events.o client.o new.o manage.o misc.o taskbar.o menufile.o HEADERS = windowlab.h all: $(PROG) $(PROG): $(OBJS) $(CC) $(OBJS) $(LDPATH) $(LIBS) -o $@ $(OBJS): %.o: %.c $(HEADERS) $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c $< -o $@ install: all mkdir -p $(BINDIR) && install -m 755 -s $(PROG) $(BINDIR) mkdir -p $(MANDIR) && install -m 644 $(MANPAGE) $(MANDIR) && gzip -9vfn $(MANDIR)/$(MANPAGE) mkdir -p $(CFGDIR) && cp -i windowlab.menurc $(CFGDIR)/windowlab.menurc && chmod 644 $(CFGDIR)/windowlab.menurc clean: rm -f $(PROG) $(OBJS) .PHONY: all install clean windowlab-1.40/windowlab.menurc0000666000175000017500000000046711261201632015264 0ustar nicknick# make sure each line ends in LF not CRLF! xterm:xterm gedit:gedit Nautilus:nautilus Firefox:firefox Pidgin:pidgin XChat:xchat Rhythmbox:rhythmbox Totem:totem GIMP:gimp Edit menu:gvim /etc/X11/windowlab/windowlab.menurc About:windowlab -about | xmessage -file - Reload:pkill -HUP windowlab Quit:skill windowlab windowlab-1.40/README0000666000175000017500000002712211261175266012755 0ustar nicknickWINDOWLAB Copyright (c) 2001-2009 Nick Gravgaard WHAT IS WINDOWLAB? WindowLab is a small and simple window manager of novel design. It has a click-to-focus but not raise-on-focus policy, a window resizing mechanism that allows one or many edges of a window to be changed in one action, and an innovative menubar that shares the same part of the screen as the taskbar. Window titlebars are prevented from going off the edge of the screen by constraining the mouse pointer, and when appropriate the pointer is also constrained to the taskbar/menubar in order to make target menu items easier to hit. WHY USE WINDOWLAB? * It allows the focused window to be below other windows that you still need to look at (click-to-focus but not raise-on-focus) without using a convoluted Windows style always-on-top mode * One or many edges of a window can be changed in one action without having to click on thin window borders. As with much in WindowLab this allows faster use with less accuracy * It's very quick and easy to launch an application from the menu - it's easier to slam the pointer to the top of the screen and then make small adjustments to hit the target then it is to use a Windows style hierarchical "start" menu or a Blackbox style popup menu, and by constraining the pointer to the menu bar you can be less accurate (and thus faster) because once the pointer is in the menu bar you don't have to worry about vertical movements * You can quickly access a window and bring it to the front by clicking on it in the taskbar - this solves the only problem with the click-to-focus but not raise-on-focus model - having to slide partially obscured windows around to get to their toggle-depth buttons * When you have many windows open and lose track of which window you want next you can click on a taskbar item, and if it's not the right one, slide the pointer over the other items in the taskbar (with the mouse button still depressed) to see the other windows. As with the menubar, the pointer's constrained to the taskbar so that you can make faster and less careful mouse movements. With many windows open this is faster than CoolSwitch (alt-tabbing) in Windows (although WindowLab does have a similar keyboard shortcut in alt-tab/alt-q) and some Mac OS X users have told me that it beats Exposé too * Constraining windows titlebars to the screen makes it feel snappier and more responsive - try flinging a window around the screen. This also means that you'll never have only a tiny part of a window remaining on screen WHERE CAN I GET WINDOWLAB? The latest version of WindowLab is held at http://nickgravgaard.com/windowlab/ AUTHOR WindowLab was written by Nick Gravgaard (me@nickgravgaard.com) LICENCE WindowLab is Free Software and has been released under the GPL. Please see the LICENCE file for more information. The licence for aewm (which includes that of 9wm) from which this code has been derived is included at the end of this README document. HOW DO I INSTALL WINDOWLAB? Before compiling, check the default (DEF_foo) options in windowlab.h, and the defines in the Makefile. DEF_FONT is of particular interest; make sure that it is defined to something that exists on your system. You can turn -DSHAPE off if you don't have the Shape extension, and -DMWM_HINTS on if you have the Lesstif or Motif headers installed. "make" will compile everything, and "make install" will install it. To make WindowLab your default window manager, edit ~/.xinitrc (if you start X from the console by typing "startx") or ~/.xsession (if you start with a graphical login manager) and change the last line to "exec windowlab". If you use FreeBSD, you can get WindowLab from /usr/ports/x11-wm/windowlab/ HOW DO I USE WINDOWLAB? WindowLab places a taskbar at the top of the screen and adds a titlebar to the top of each window. These titlebars consist of a draggable area, and three icons on the right hand side. When left clicked, these icons: * hide the window * toggle the window's Z order Amiga style (if it's not at the front, bring it to the front, otherwise send it to the back) * close the window Another way of toggling a window's Z order (depth) is by double left clicking on the draggable part of its titlebar. Windows' titlebars are prevented from leaving the screen and cannot overlap the taskbar. The taskbar should list all windows currently in use. Left clicking on a window's taskbar item will give that window focus and toggle its Z order (depth). To resize the active window hold down alt and push against the window's edges with the left mouse button down. If you right click outside a client window, WindowLab's taskbar becomes a menubar. Releasing the right mouse button over a selected menu item will start a corresponding external program. WindowLab will look in each of the following files in turn for definitions of the menu labels and commands: * ~/.windowlab/windowlab.menurc * ../etc/windowlab.menurc (from the directory containing the executable) * /etc/X11/windowlab/windowlab.menurc Each line in the menurc file should have the menu label, a colon, and then the corresponding command, eg: The GIMP:gimp New windows (that don't specify their location) are positioned according to the coordinates of the mouse - the top-left hand corner of a new window is set to the location of the mouse pointer (if necessary the window will be moved to ensure that all of it is on the screen). WindowLab has the following keyboard controls. Hold down alt and press: * tab to give focus to the previous window * q to give focus to the next window * F11 to toggle fullscreen mode on and off for non transient windows * F12 to toggle the windows depth. This is the same as left clicking a window's middle icon HOW CAN I HELP? If you find a bug please tell me about it by emailing me@nickgravgaard.com (if you know how to fix it, even better). If you really like WindowLab, please tell others about it so that the number of potential users/contributors may increase. DESIGN RATIONALE Before I started WindowLab, I'd been an Amiga user who had switched to Linux around 1998. To my mind, window managers (like text editors and file managers) are one of the most important parts of any system for the user, and I wasn't satisfied with those that already existed. At that time FVWM2 was the most commonly used Linux window manager but it was far too large for my tastes, and I suspected that one of the reasons for this was that it was designed to handle so many different options. So I started work on my own window manager, basing it on aewm. The most important feature to my mind was to implement the Amiga's click-to-focus but not raise-on-focus behaviour, where a focused window is not necessarily in front of other windows. Realising that it can be hard to get to a windows buttons if it is behind another window, I added a simplified Windows 95 style taskbar so that users could easily access each window. Another neat feature of the Amiga's GUI that had not been done before in an X window manager was the constraining of the pointer when the user tried to drag a window beyond the edge of the screen. In this way, WindowLab treats windows like they are Amiga screens in that a window's titlebar is constrained to the physical screen. At this point I started to think about the issue of launching programs from WindowLab. aewm's approach was that taskbars and launching files was not part of the window manager's job, and I respected the minimalist reasoning behind this, but since my constrained windows took it for granted that a taskbar existed at the top of the screen, I reasoned that the taskbar was best kept within the window manager. With the taskbar taking up as much space as a menu bar would, I realised that I could reuse space just like the Amiga had done by making a menu bar available when the right mouse button is held down. My twist was that rather than have drop down menus, my menubar would consist of "bang" menu items a little like the "Quick Launch" toolbar in Windows 98, and by keeping the menu one level deep, I could reuse the constrained mouse pointer trick to make target menu items easier to hit (infinitely tall according to Fitts's law). I also wanted windows to be able to act like screens on the Amiga (where the title bar and client area can take up all of the screen), and this forced me to rule out any useful kind of draggable window borders. Earlier versions (up to 1.20) used an 8½ (from Plan 9) style resizing mechanism, but some users complained that it meant that each edge of the window changed even if only a small resize was intended. The mechanism that replaced it is completely original, and quicker and easier to use than traditional draggable borders (allowing one or many edges of a window to be changed in one action without the user having to click on thin window borders). TIPS AND TRICKS * It is not the window manager's job to set the root window's pointer cursor or background image but you can use "xsetroot -cursor_name top_left_arrow" to set the pointer and xv, xloadimage or xpmroot to set a background image. * WindowLab does not have virtual desktops, but you can use vdesk, a command-line driven virtual workspace manager that I've been told works acceptably. This can be combined with a separate application launcher (or WindowLab's built-in menubar) to give most of the functionality needed. * If you are locked into the menubar and want to get out of it, click the left mouse button * Use Alt + F11 to toggle fullscreen mode on before watching video applications * Chris Turkel (zizban (at) adelphia (dot) net) managed to get WindowLab working on Solaris 10 x86. You can get his notes at http://nickgravgaard.com/windowlab/solaris.txt If you know any other tips for use with WindowLab, please get in contact with me so that I can list them here. ACKNOWLEDGEMENTS Thanks to Decklin Foster who wrote the original aewm (v1.1.2 to be precise) on which WindowLab is based. He's done a superb job of writing a minimal window manager and was good enough to release it under a liberal licence that allows anyone to add their favourite GPL or BSD flavour as they see fit. INHERITED LICENCES aewm > Copyright (c) 1998-2001 Decklin Foster. > > THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS", WITHOUT ANY EXPRESS > OR IMPLIED WARRANTIES OF ANY KIND. IN NO EVENT SHALL THE AUTHOR BE > HELD LIABLE FOR ANY DAMAGES CONNECTED WITH THE USE OF THIS PROGRAM. > > You are granted permission to copy, publish, distribute, and/or sell > copies of this program and any modified versions or derived works, > provided that this copyright and notice are not removed or altered. 9wm > Copyright (c) 1994 David Hogan > Copyright (c) 2009 The Estate of David Hogan > > Permission is hereby granted, free of charge, to any person obtaining a copy > of this software and associated documentation files (the "Software"), to deal > in the Software without restriction, including without limitation the rights > to use, copy, modify, merge, publish, distribute, sublicence, and/or sell > copies of the Software, and to permit persons to whom the Software is > furnished to do so, subject to the following conditions: > > The above copyright notice and this permission notice shall be included in > all copies or substantial portions of the Software. > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN > THE SOFTWARE. windowlab-1.40/TODO0000666000175000017500000000023410324462540012551 0ustar nicknickTODO * add EWMH support (back port it from aewm?) * allow right clicks on client windows to show WindowLab's menubar as well as being passed to the client windowlab-1.40/windowlab.1x0000666000175000017500000000706310467660430014336 0ustar nicknick.\" WindowLab - an X11 window manager .\" by Nick Gravgaard (me at nickgravgaard.com) .TH WINDOWLAB 1x .SH "NAME" windowlab \- a window manager for X11 .SH "SYNOPSIS" .B windowlab \fI[options...]\fP .SH DESCRIPTION .B windowlab is a small and simple window manager of novel design. .PP It has a click-to-focus but not raise-on-focus policy, a window resizing mechanism that allows one or many edges of a window to be changed in one action, and an innovative menubar that shares the same part of the screen as the taskbar. Window titlebars are prevented from going off the edge of the screen by constraining the mouse pointer, and when appropriate the pointer is also constrained to the taskbar/menubar in order to make target menu items easier to hit. .PP WindowLab places a taskbar at the top of the screen and adds a titlebar to the top of each window. These titlebars consist of a draggable area, and three icons on the right hand side. When left clicked, these icons: .PP * hide the window .br * toggle the window's Z order Amiga style (if it's not at the front, bring it to the front, otherwise send it to the back) .br * close the window .PP Another way of toggling a window's Z order (depth) is by double left clicking on the draggable part of its titlebar. .PP Windows' titlebars are prevented from leaving the screen and cannot overlap the taskbar. .PP The taskbar should list all windows currently in use. Left clicking on a window's taskbar item will give that window focus and toggle its Z order (depth). .PP To resize the active window hold down alt and push against the window's edges with the left mouse button down. .PP If you right click outside a client window, WindowLab's taskbar becomes a menubar. Releasing the right mouse button over a selected menu item will start a corresponding external program. WindowLab will look in each of the following files in turn for definitions of the menu labels and commands: .PP * ~/\.windowlab/windowlab\.menurc .br * \.\./etc/windowlab\.menurc (from the directory containing the executable) .br * /etc/X11/windowlab/windowlab\.menurc .PP Each line in the menurc file should have the menu label, a colon, and then the corresponding command, eg: .PP The GIMP:gimp .PP New windows (that don't specify their location) are positioned according to the coordinates of the mouse - the top-left hand corner of a new window is set to the location of the mouse pointer (if necessary the window will be moved to ensure that all of it is on the screen). .PP WindowLab has the following keyboard controls. Hold down alt and press: .PP * .B tab to give focus to the previous window .br * .B q to give focus to the next window .br * .B F11 to toggle fullscreen mode on and off for non transient windows .br * .B F12 to toggle the window's depth. This is the same as left clicking a window's middle icon .SH OPTIONS .TP .B -font \fIfont-spec\fP Draw window titles with the font defined by .IR font-spec . .TP .B -border \fIcolor\fP, -text \fIcolor\fP, -active \fIcolor\fP, -inactive \fIcolor\fP, -menu \fIcolor\fP, -selected \fIcolor\fP, -empty \fIcolor\fP Use .I color for the borders, the text, the active background, the inactive background, the menubar, the selected menu item and empty parts of the screen. .TP .B -about Print information to stdout and exit. .TP .B -display Sets which X display will be managed by .BR windowlab . .SH ENVIRONMENT VARIABLES .B DISPLAY Sets which X display will be managed by .BR windowlab . .SH "SEE ALSO" .BR X (7), .I The Inter-Client Communication Conventions Manual (from the X11R6 documentation). .SH "AUTHOR" Nick Gravgaard (me at nickgravgaard.com) windowlab-1.40/LICENCE0000666000175000017500000004307111255473332013061 0ustar nicknick GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. windowlab-1.40/taskbar.c0000666000175000017500000002401711356155352013667 0ustar nicknick/* WindowLab - an X11 window manager * Copyright (c) 2001-2010 Nick Gravgaard * me at nickgravgaard.com * http://nickgravgaard.com/windowlab/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "windowlab.h" static void draw_menubar(void); static unsigned int update_menuitem(int); static void draw_menuitem(unsigned int, unsigned int); Window taskbar; #ifdef XFT XftDraw *tbxftdraw; #endif void make_taskbar(void) { XSetWindowAttributes pattr; pattr.override_redirect = True; pattr.background_pixel = empty_col.pixel; pattr.border_pixel = border_col.pixel; pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; taskbar = XCreateWindow(dsply, root, 0 - DEF_BORDERWIDTH, 0 - DEF_BORDERWIDTH, DisplayWidth(dsply, screen), BARHEIGHT() - DEF_BORDERWIDTH, DEF_BORDERWIDTH, DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &pattr); XMapWindow(dsply, taskbar); #ifdef XFT tbxftdraw = XftDrawCreate(dsply, (Drawable) taskbar, DefaultVisual(dsply, DefaultScreen(dsply)), DefaultColormap(dsply, DefaultScreen(dsply))); #endif } void remember_hidden(void) { Client *c; for (c = head_client; c != NULL; c = c->next) { c->was_hidden = c->hidden; } } void forget_hidden(void) { Client *c; for (c = head_client; c != NULL; c = c->next) { if (c == focused_client) { c->was_hidden = c->hidden; } else { c->was_hidden = 0; } } } void lclick_taskbutton(Client *old_c, Client *c) { if (old_c != NULL) { if (old_c->was_hidden) { hide(old_c); } } if (c->hidden) { unhide(c); } else { if (c->was_hidden) { hide(c); } else { raise_lower(c); } } check_focus(c); } void lclick_taskbar(int x) { XEvent ev; int mousex, mousey; Rect bounddims; Window constraint_win; XSetWindowAttributes pattr; float button_width; unsigned int button_clicked, old_button_clicked, i; Client *c, *exposed_c, *old_c; if (head_client != NULL) { remember_hidden(); get_mouse_position(&mousex, &mousey); bounddims.x = 0; bounddims.y = 0; bounddims.width = DisplayWidth(dsply, screen); bounddims.height = BARHEIGHT(); constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); XMapWindow(dsply, constraint_win); if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) { XDestroyWindow(dsply, constraint_win); return; } button_width = get_button_width(); button_clicked = (unsigned int)(x / button_width); for (i = 0, c = head_client; i < button_clicked; i++) { c = c->next; } lclick_taskbutton(NULL, c); do { XMaskEvent(dsply, ExposureMask|MouseMask|KeyMask, &ev); switch (ev.type) { case Expose: exposed_c = find_client(ev.xexpose.window, FRAME); if (exposed_c) { redraw(exposed_c); } break; case MotionNotify: old_button_clicked = button_clicked; button_clicked = (unsigned int)(ev.xmotion.x / button_width); if (button_clicked != old_button_clicked) { old_c = c; for (i = 0, c = head_client; i < button_clicked; i++) { c = c->next; } lclick_taskbutton(old_c, c); } break; case KeyPress: XPutBackEvent(dsply, &ev); break; } } while (ev.type != ButtonPress && ev.type != ButtonRelease && ev.type != KeyPress); XUnmapWindow(dsply, constraint_win); XDestroyWindow(dsply, constraint_win); ungrab(); forget_hidden(); } } void rclick_taskbar(int x) { XEvent ev; int mousex, mousey; Rect bounddims; unsigned int current_item = UINT_MAX; Window constraint_win; XSetWindowAttributes pattr; get_mouse_position(&mousex, &mousey); bounddims.x = 0; bounddims.y = 0; bounddims.width = DisplayWidth(dsply, screen); bounddims.height = BARHEIGHT(); constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); XMapWindow(dsply, constraint_win); if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) { XDestroyWindow(dsply, constraint_win); return; } draw_menubar(); update_menuitem(INT_MAX); // force initial highlight current_item = update_menuitem(x); do { XMaskEvent(dsply, MouseMask|KeyMask, &ev); switch (ev.type) { case MotionNotify: current_item = update_menuitem(ev.xmotion.x); break; case ButtonRelease: if (current_item != UINT_MAX) { fork_exec(menuitems[current_item].command); } break; case KeyPress: XPutBackEvent(dsply, &ev); break; } } while (ev.type != ButtonPress && ev.type != ButtonRelease && ev.type != KeyPress); redraw_taskbar(); XUnmapWindow(dsply, constraint_win); XDestroyWindow(dsply, constraint_win); ungrab(); } void rclick_root(void) { XEvent ev; if (!grab(root, MouseMask, None)) { return; } draw_menubar(); do { XMaskEvent(dsply, MouseMask|KeyMask, &ev); switch (ev.type) { case MotionNotify: if (ev.xmotion.y < BARHEIGHT()) { ungrab(); rclick_taskbar(ev.xmotion.x); return; } break; case KeyPress: XPutBackEvent(dsply, &ev); break; } } while (ev.type != ButtonRelease && ev.type != KeyPress); redraw_taskbar(); ungrab(); } void redraw_taskbar(void) { unsigned int i; int button_startx, button_iwidth; float button_width; Client *c; button_width = get_button_width(); XClearWindow(dsply, taskbar); if (showing_taskbar == 0) { return; } for (c = head_client, i = 0; c != NULL; c = c->next, i++) { button_startx = (int)(i * button_width); button_iwidth = (unsigned int)(((i + 1) * button_width) - button_startx); if (button_startx != 0) { XDrawLine(dsply, taskbar, border_gc, button_startx - 1, 0, button_startx - 1, BARHEIGHT() - DEF_BORDERWIDTH); } if (c == focused_client) { XFillRectangle(dsply, taskbar, active_gc, button_startx, 0, button_iwidth, BARHEIGHT() - DEF_BORDERWIDTH); } else { XFillRectangle(dsply, taskbar, inactive_gc, button_startx, 0, button_iwidth, BARHEIGHT() - DEF_BORDERWIDTH); } if (!c->trans && c->name != NULL) { #ifdef XFT XftDrawString8(tbxftdraw, &xft_detail, xftfont, button_startx + SPACE, SPACE + xftfont->ascent, (unsigned char *)c->name, strlen(c->name)); #else XDrawString(dsply, taskbar, text_gc, button_startx + SPACE, SPACE + font->ascent, c->name, strlen(c->name)); #endif } } } void draw_menubar(void) { unsigned int i, dw; dw = DisplayWidth(dsply, screen); XFillRectangle(dsply, taskbar, menu_gc, 0, 0, dw, BARHEIGHT() - DEF_BORDERWIDTH); for (i = 0; i < num_menuitems; i++) { if (menuitems[i].label && menuitems[i].command) { #ifdef XFT XftDrawString8(tbxftdraw, &xft_detail, xftfont, menuitems[i].x + (SPACE * 2), xftfont->ascent + SPACE, (unsigned char *)menuitems[i].label, strlen(menuitems[i].label)); #else XDrawString(dsply, taskbar, text_gc, menuitems[i].x + (SPACE * 2), font->ascent + SPACE, menuitems[i].label, strlen(menuitems[i].label)); #endif } } } unsigned int update_menuitem(int mousex) { static unsigned int last_item; // retain value from last call unsigned int i; if (mousex == INT_MAX) // entered function to set last_item { last_item = num_menuitems; return UINT_MAX; } for (i = 0; i < num_menuitems; i++) { if ((mousex >= menuitems[i].x) && (mousex <= (menuitems[i].x + menuitems[i].width))) { break; } } if (i != last_item) // don't redraw if same { if (last_item != num_menuitems) { draw_menuitem(last_item, 0); } if (i != num_menuitems) { draw_menuitem(i, 1); } last_item = i; // set to new menu item } if (i != num_menuitems) { return i; } else // no item selected { return UINT_MAX; } } void draw_menuitem(unsigned int index, unsigned int active) { if (active) { XFillRectangle(dsply, taskbar, selected_gc, menuitems[index].x, 0, menuitems[index].width, BARHEIGHT() - DEF_BORDERWIDTH); } else { XFillRectangle(dsply, taskbar, menu_gc, menuitems[index].x, 0, menuitems[index].width, BARHEIGHT() - DEF_BORDERWIDTH); } #ifdef XFT XftDrawString8(tbxftdraw, &xft_detail, xftfont, menuitems[index].x + (SPACE * 2), xftfont->ascent + SPACE, (unsigned char *)menuitems[index].label, strlen(menuitems[index].label)); #else XDrawString(dsply, taskbar, text_gc, menuitems[index].x + (SPACE * 2), font->ascent + SPACE, menuitems[index].label, strlen(menuitems[index].label)); #endif } float get_button_width(void) { unsigned int nwins = 0; Client *c = head_client; while (c != NULL) { nwins++; c = c->next; } return ((float)(DisplayWidth(dsply, screen) + DEF_BORDERWIDTH)) / nwins; } void cycle_previous(void) { Client *c = focused_client; Client *original_c = c; if (head_client != NULL && head_client->next != NULL) // at least 2 windows exist { if (c == NULL) { c = head_client; } if (c == head_client) { original_c = NULL; } do { if (c->next == NULL) { c = head_client; } else { c = c->next; } } while (c->next != original_c); lclick_taskbutton(NULL, c); } } void cycle_next(void) { Client *c = focused_client; if (head_client != NULL && head_client->next != NULL) // at least 2 windows exist { if (c == NULL || c->next == NULL) { c = head_client; } else c = c->next; lclick_taskbutton(NULL, c); } } windowlab-1.40/new.c0000666000175000017500000001406611356155344013035 0ustar nicknick/* WindowLab - an X11 window manager * Copyright (c) 2001-2010 Nick Gravgaard * me at nickgravgaard.com * http://nickgravgaard.com/windowlab/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "windowlab.h" static void init_position(Client *); static void reparent(Client *); #ifdef MWM_HINTS static PropMwmHints *get_mwm_hints(Window); #endif /* Set up a client structure for the new (not-yet-mapped) window. The * confusing bit is that we have to ignore 2 unmap events if the * client was already mapped but has IconicState set (for instance, * when we are the second window manager in a session). That's * because there's one for the reparent (which happens on all viewable * windows) and then another for the unmapping itself. */ void make_new_client(Window w) { Client *c, *p; XWindowAttributes attr; XWMHints *hints; #ifdef MWM_HINTS PropMwmHints *mhints; #endif long dummy; c = (Client *)malloc(sizeof *c); if (head_client == NULL) { head_client = c; } else { p = head_client; while (p->next != NULL) { p = p->next; } p->next = c; } c->next = NULL; XGrabServer(dsply); XGetTransientForHint(dsply, w, &c->trans); XFetchName(dsply, w, &c->name); XGetWindowAttributes(dsply, w, &attr); c->window = w; c->ignore_unmap = 0; c->hidden = 0; c->was_hidden = 0; #ifdef SHAPE c->has_been_shaped = 0; #endif c->x = attr.x; c->y = attr.y; c->width = attr.width; c->height = attr.height; c->cmap = attr.colormap; c->size = XAllocSizeHints(); XGetWMNormalHints(dsply, c->window, c->size, &dummy); #ifdef MWM_HINTS c->has_title = 1; c->has_border = 1; if ((mhints = get_mwm_hints(c->window))) { if (mhints->flags & MWM_HINTS_DECORATIONS && !(mhints->decorations & MWM_DECOR_ALL)) { c->has_title = mhints->decorations & MWM_DECOR_TITLE; c->has_border = mhints->decorations & MWM_DECOR_BORDER; } XFree(mhints); } #endif // XReparentWindow seems to try an XUnmapWindow, regardless of whether the reparented window is mapped or not c->ignore_unmap++; if (attr.map_state != IsViewable) { init_position(c); set_wm_state(c, NormalState); if ((hints = XGetWMHints(dsply, w))) { if (hints->flags & StateHint) { set_wm_state(c, hints->initial_state); } XFree(hints); } } fix_position(c); gravitate(c, APPLY_GRAVITY); reparent(c); #ifdef XFT c->xftdraw = XftDrawCreate(dsply, (Drawable) c->frame, DefaultVisual(dsply, DefaultScreen(dsply)), DefaultColormap(dsply, DefaultScreen(dsply))); #endif if (get_wm_state(c) != IconicState) { XMapWindow(dsply, c->window); XMapRaised(dsply, c->frame); topmost_client = c; } else { c->hidden = 1; if(attr.map_state == IsViewable) { c->ignore_unmap++; XUnmapWindow(dsply, c->window); } } // if no client has focus give focus to the new client if (focused_client == NULL) { check_focus(c); focused_client = c; } XSync(dsply, False); XUngrabServer(dsply); redraw_taskbar(); } /* This one does *not* free the data coming back from Xlib; it just * sends back the pointer to what was allocated. */ #ifdef MWM_HINTS static PropMwmHints *get_mwm_hints(Window w) { Atom real_type; int real_format; unsigned long items_read, items_left; unsigned char *data; if (XGetWindowProperty(dsply, w, mwm_hints, 0L, 20L, False, mwm_hints, &real_type, &real_format, &items_read, &items_left, &data) == Success && items_read >= PROP_MWM_HINTS_ELEMENTS) { return (PropMwmHints *)data; } else { return NULL; } } #endif /* Figure out where to map the window. c->x, c->y, c->width, and * c->height actually start out with values in them (whatever the * client passed to XCreateWindow). * * The ICCM says that there are no position/size fields anymore and * the SetWMNormalHints says that they are obsolete, so we use the values * we got from the window attributes * We honour both program and user preferences * * If we can't find a reasonable position hint, we make up a position * using the relative mouse co-ordinates and window size. To account * for window gravity while doing this, we add BARHEIGHT() into the * calculation and then degravitate. Don't think about it too hard, or * your head will explode. */ static void init_position(Client *c) { int mousex, mousey; // make sure it's big enough for the 3 buttons and a bit of bar if (c->width < 4 * BARHEIGHT()) { c->width = 4 * BARHEIGHT(); } if (c->height < BARHEIGHT()) { c->height = BARHEIGHT(); } if (c->x == 0 && c->y == 0) { get_mouse_position(&mousex, &mousey); c->x = mousex; c->y = mousey + BARHEIGHT(); gravitate(c, REMOVE_GRAVITY); } } static void reparent(Client *c) { XSetWindowAttributes pattr; pattr.override_redirect = True; pattr.background_pixel = empty_col.pixel; pattr.border_pixel = border_col.pixel; pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; c->frame = XCreateWindow(dsply, root, c->x, c->y - BARHEIGHT(), c->width, c->height + BARHEIGHT(), BORDERWIDTH(c), DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &pattr); #ifdef SHAPE if (shape) { XShapeSelectInput(dsply, c->window, ShapeNotifyMask); set_shape(c); } #endif XAddToSaveSet(dsply, c->window); XSelectInput(dsply, c->window, ColormapChangeMask|PropertyChangeMask); XSetWindowBorderWidth(dsply, c->window, 0); XResizeWindow(dsply, c->window, c->width, c->height); XReparentWindow(dsply, c->window, c->frame, 0, BARHEIGHT()); send_config(c); } windowlab-1.40/misc.c0000666000175000017500000002000011356155336013161 0ustar nicknick/* WindowLab - an X11 window manager * Copyright (c) 2001-2010 Nick Gravgaard * me at nickgravgaard.com * http://nickgravgaard.com/windowlab/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include "windowlab.h" static void quit_nicely(void); void err(const char *fmt, ...) { va_list argp; fprintf(stderr, "windowlab: "); va_start(argp, fmt); vfprintf(stderr, fmt, argp); va_end(argp); fprintf(stderr, "\n"); } void fork_exec(char *cmd) { char *envshell, *envshellname; pid_t pid = fork(); switch (pid) { case 0: setsid(); envshell = getenv("SHELL"); if (envshell == NULL) { envshell = "/bin/sh"; } envshellname = strrchr(envshell, '/'); if (envshellname == NULL) { envshellname = envshell; } else { /* move to the character after the slash */ envshellname++; } execlp(envshell, envshellname, "-c", cmd, NULL); err("exec failed, cleaning up child"); exit(1); break; case -1: err("can't fork"); break; } } void sig_handler(int signal) { pid_t pid; int status; switch (signal) { case SIGINT: case SIGTERM: quit_nicely(); break; case SIGHUP: do_menuitems = 1; break; case SIGCHLD: while ((pid = waitpid(-1, &status, WNOHANG)) != 0) { if ((pid == -1) && (errno != EINTR)) { break; } else { continue; } } break; } } int handle_xerror(Display *dsply, XErrorEvent *e) { Client *c = find_client(e->resourceid, WINDOW); if (e->error_code == BadAccess && e->resourceid == root) { err("root window unavailable (maybe another wm is running?)"); exit(1); } else { char msg[255]; XGetErrorText(dsply, e->error_code, msg, sizeof msg); err("X error (%#lx): %s", e->resourceid, msg); } if (c != NULL) { remove_client(c, WITHDRAW); } return 0; } /* Ick. Argh. You didn't see this function. */ int ignore_xerror(Display *dsply, XErrorEvent *e) { (void) dsply; (void) e; return 0; } /* Currently, only send_wm_delete uses this one... */ int send_xmessage(Window w, Atom a, long x) { XClientMessageEvent e; e.type = ClientMessage; e.window = w; e.message_type = a; e.format = 32; e.data.l[0] = x; e.data.l[1] = CurrentTime; return XSendEvent(dsply, w, False, NoEventMask, (XEvent *)&e); } void get_mouse_position(int *x, int *y) { Window mouse_root, mouse_win; int win_x, win_y; unsigned int mask; XQueryPointer(dsply, root, &mouse_root, &mouse_win, x, y, &win_x, &win_y, &mask); } /* If this is the fullscreen client we don't take BARHEIGHT() into account * because the titlebar isn't being drawn on the window. */ void fix_position(Client *c) { int xmax = DisplayWidth(dsply, screen); int ymax = DisplayHeight(dsply, screen); int titlebarheight; #ifdef DEBUG fprintf(stderr, "fix_position(): client was (%d, %d)-(%d, %d)\n", c->x, c->y, c->x + c->width, c->y + c->height); #endif titlebarheight = (fullscreen_client == c) ? 0 : BARHEIGHT(); if (c->width < MINWINWIDTH) { c->width = MINWINWIDTH; } if (c->height < MINWINHEIGHT) { c->height = MINWINHEIGHT; } if (c->width > xmax) { c->width = xmax; } if (c->height + (BARHEIGHT() + titlebarheight) > ymax) { c->height = ymax - (BARHEIGHT() + titlebarheight); } if (c->x < 0) { c->x = 0; } if (c->y < BARHEIGHT()) { c->y = BARHEIGHT(); } if (c->x + c->width + BORDERWIDTH(c) >= xmax) { c->x = xmax - c->width; } if (c->y + c->height + BARHEIGHT() >= ymax) { c->y = (ymax - c->height) - BARHEIGHT(); } #ifdef DEBUG fprintf(stderr, "fix_position(): client is (%d, %d)-(%d, %d)\n", c->x, c->y, c->x + c->width, c->y + c->height); #endif c->x -= BORDERWIDTH(c); c->y -= BORDERWIDTH(c); } void refix_position(Client *c, XConfigureRequestEvent *e) { Rect olddims; olddims.x = c->x - BORDERWIDTH(c); olddims.y = c->y - BORDERWIDTH(c); olddims.width = c->width; olddims.height = c->height; fix_position(c); if (olddims.x != c->x) { e->value_mask |= CWX; } if (olddims.y != c->y) { e->value_mask |= CWY; } if (olddims.width != c->width) { e->value_mask |= CWWidth; } if (olddims.height != c->height) { e->value_mask |= CWHeight; } } void copy_dims(Rect *sourcedims, Rect *destdims) { destdims->x = sourcedims->x; destdims->y = sourcedims->y; destdims->width = sourcedims->width; destdims->height = sourcedims->height; } #ifdef DEBUG /* Bleh, stupid macro names. I'm not feeling creative today. */ #define SHOW_EV(name, memb) \ case name: \ s = #name; \ w = e.memb.window; \ break; #define SHOW(name) \ case name: \ return #name; void show_event(XEvent e) { char *s, buf[20]; Window w; Client *c; switch (e.type) { SHOW_EV(ButtonPress, xbutton) SHOW_EV(ButtonRelease, xbutton) SHOW_EV(ClientMessage, xclient) SHOW_EV(ColormapNotify, xcolormap) SHOW_EV(ConfigureNotify, xconfigure) SHOW_EV(ConfigureRequest, xconfigurerequest) SHOW_EV(CreateNotify, xcreatewindow) SHOW_EV(DestroyNotify, xdestroywindow) SHOW_EV(EnterNotify, xcrossing) SHOW_EV(Expose, xexpose) SHOW_EV(MapNotify, xmap) SHOW_EV(MapRequest, xmaprequest) SHOW_EV(MappingNotify, xmapping) SHOW_EV(MotionNotify, xmotion) SHOW_EV(PropertyNotify, xproperty) SHOW_EV(ReparentNotify, xreparent) SHOW_EV(ResizeRequest, xresizerequest) SHOW_EV(UnmapNotify, xunmap) default: if (shape && e.type == shape_event) { s = "ShapeNotify"; w = ((XShapeEvent *)&e)->window; } else { s = "unknown event"; w = None; } break; } c = find_client(w, WINDOW); snprintf(buf, sizeof buf, c != NULL ? c->name : "(none)"); err("%#-10lx: %-20s: %s", w, buf, s); } static const char *show_state(Client *c) { switch (get_wm_state(c)) { SHOW(WithdrawnState) SHOW(NormalState) SHOW(IconicState) default: return "unknown state"; } } static const char *show_grav(Client *c) { if (c->size == NULL || !(c->size->flags & PWinGravity)) { return "no grav (NW)"; } switch (c->size->win_gravity) { SHOW(UnmapGravity) SHOW(NorthWestGravity) SHOW(NorthGravity) SHOW(NorthEastGravity) SHOW(WestGravity) SHOW(CenterGravity) SHOW(EastGravity) SHOW(SouthWestGravity) SHOW(SouthGravity) SHOW(SouthEastGravity) SHOW(StaticGravity) default: return "unknown grav"; } } void dump(Client *c) { if (c != NULL) { err("%s\n\t%s, %s, ignore %d, was_hidden %d\n\tframe %#lx, win %#lx, geom %dx%d+%d+%d", c->name, show_state(c), show_grav(c), c->ignore_unmap, c->was_hidden, c->frame, c->window, c->width, c->height, c->x, c->y); } } void dump_clients(void) { Client *c = head_client; while (c != NULL) { dump(c); c = c->next; } } #endif /* We use XQueryTree here to preserve the window stacking order, * since the order in our linked list is different. */ static void quit_nicely(void) { unsigned int nwins, i; Window dummyw1, dummyw2, *wins; Client *c; free_menuitems(); XQueryTree(dsply, root, &dummyw1, &dummyw2, &wins, &nwins); for (i = 0; i < nwins; i++) { c = find_client(wins[i], FRAME); if (c != NULL) { remove_client(c, REMAP); } } XFree(wins); if (font) { XFreeFont(dsply, font); } #ifdef XFT if (xftfont) { XftFontClose(dsply, xftfont); } #endif XFreeCursor(dsply, resize_curs); XFreeGC(dsply, border_gc); XFreeGC(dsply, text_gc); XInstallColormap(dsply, DefaultColormap(dsply, screen)); XSetInputFocus(dsply, PointerRoot, RevertToNone, CurrentTime); XCloseDisplay(dsply); exit(0); } windowlab-1.40/menufile.c0000666000175000017500000001205111356155327014041 0ustar nicknick/* WindowLab - an X11 window manager * Copyright (c) 2001-2010 Nick Gravgaard * me at nickgravgaard.com * http://nickgravgaard.com/windowlab/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "windowlab.h" // semaphor activated by SIGHUP int do_menuitems; static int parseline(char *, char *, char *); MenuItem *menuitems = NULL; unsigned int num_menuitems; #ifdef XFT XGlyphInfo extents; #endif void get_menuitems(void) { unsigned int i, button_startx = 0; FILE *menufile = NULL; char menurcpath[PATH_MAX], *c; extern int errno; menuitems = (MenuItem *)malloc(MAX_MENUITEMS_SIZE); if (menuitems == NULL) { err("Unable to allocate menu items array."); return; } memset(menuitems, 0, MAX_MENUITEMS_SIZE); snprintf(menurcpath, sizeof(menurcpath), "%s/.windowlab/windowlab.menurc", getenv("HOME")); #ifdef DEBUG printf("trying to open: %s\n", menurcpath); #endif if ((menufile = fopen(menurcpath, "r")) == NULL) { ssize_t len; // get location of the executable if ((len = readlink("/proc/self/exe", menurcpath, PATH_MAX - 1)) == -1) { err("readlink() /proc/self/exe failed: %s\n", strerror(errno)); menurcpath[0] = '.'; menurcpath[1] = '\0'; } else { // insert null to end the file path properly menurcpath[len] = '\0'; } if ((c = strrchr(menurcpath, '/')) != NULL) { *c = '\0'; } if ((c = strrchr(menurcpath, '/')) != NULL) { *c = '\0'; } strncat(menurcpath, "/etc/windowlab.menurc", PATH_MAX - strlen(menurcpath) - 1); #ifdef DEBUG printf("trying to open: %s\n", menurcpath); #endif if ((menufile = fopen(menurcpath, "r")) == NULL) { #ifdef DEBUG printf("trying to open: %s\n", DEF_MENURC); #endif menufile = fopen(DEF_MENURC, "r"); } } if (menufile != NULL) { num_menuitems = 0; while ((!feof(menufile)) && (!ferror(menufile)) && (num_menuitems < MAX_MENUITEMS)) { char menustr[STR_SIZE] = ""; fgets(menustr, STR_SIZE, menufile); if (strlen(menustr) != 0) { char *pmenustr = menustr; while (pmenustr[0] == ' ' || pmenustr[0] == '\t') { pmenustr++; } if (pmenustr[0] != '#') { char labelstr[STR_SIZE] = "", commandstr[STR_SIZE] = ""; if (parseline(pmenustr, labelstr, commandstr)) { menuitems[num_menuitems].label = (char *)malloc(strlen(labelstr) + 1); menuitems[num_menuitems].command = (char *)malloc(strlen(commandstr) + 1); strcpy(menuitems[num_menuitems].label, labelstr); strcpy(menuitems[num_menuitems].command, commandstr); num_menuitems++; } } } } fclose(menufile); } else { // one menu item - xterm err("can't find ~/.windowlab/windowlab.menurc, %s or %s\n", menurcpath, DEF_MENURC); menuitems[0].command = (char *)malloc(strlen(NO_MENU_COMMAND) + 1); strcpy(menuitems[0].command, NO_MENU_COMMAND); menuitems[0].label = (char *)malloc(strlen(NO_MENU_LABEL) + 1); strcpy(menuitems[0].label, NO_MENU_LABEL); num_menuitems = 1; } for (i = 0; i < num_menuitems; i++) { menuitems[i].x = button_startx; #ifdef XFT XftTextExtents8(dsply, xftfont, (unsigned char *)menuitems[i].label, strlen(menuitems[i].label), &extents); menuitems[i].width = extents.width + (SPACE * 4); #else menuitems[i].width = XTextWidth(font, menuitems[i].label, strlen(menuitems[i].label)) + (SPACE * 4); #endif button_startx += menuitems[i].width + 1; } // menu items have been built do_menuitems = 0; } int parseline(char *menustr, char *labelstr, char *commandstr) { int success = 0; int menustrlen = strlen(menustr); char *ptemp = NULL; char *menustrcpy = (char *)malloc(menustrlen + 1); if (menustrcpy == NULL) { return 0; } strcpy(menustrcpy, menustr); ptemp = strtok(menustrcpy, ":"); if (ptemp != NULL) { strcpy(labelstr, ptemp); ptemp = strtok(NULL, "\n"); if (ptemp != NULL) // right of ':' is not empty { while (*ptemp == ' ' || *ptemp == '\t') { ptemp++; } if (*ptemp != '\0' && *ptemp != '\r' && *ptemp != '\n') { strcpy(commandstr, ptemp); success = 1; } } } if (menustrcpy != NULL) { free(menustrcpy); } return success; } void free_menuitems(void) { unsigned int i; if (menuitems != NULL) { for (i = 0; i < num_menuitems; i++) { if (menuitems[i].label != NULL) { free(menuitems[i].label); menuitems[i].label = NULL; } if (menuitems[i].command != NULL) { free(menuitems[i].command); menuitems[i].command = NULL; } } free(menuitems); menuitems = NULL; } } windowlab-1.40/manage.c0000666000175000017500000004224711356155313013472 0ustar nicknick/* WindowLab - an X11 window manager * Copyright (c) 2001-2010 Nick Gravgaard * me at nickgravgaard.com * http://nickgravgaard.com/windowlab/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "windowlab.h" static void limit_size(Client *, Rect *); static int get_incsize(Client *, unsigned int *, unsigned int *, Rect *, int); void raise_lower(Client *c) { if (c != NULL) { if (c == topmost_client) { lower_win(c); topmost_client = NULL; // lazy but amiwm does similar } else { raise_win(c); topmost_client = c; } } } /* increment ignore_unmap here and decrement it in handle_unmap_event in events.c */ void hide(Client *c) { if (c != NULL) { if (!c->hidden) { c->ignore_unmap++; c->hidden = 1; if (c == topmost_client) { topmost_client = NULL; } XUnmapWindow(dsply, c->frame); XUnmapWindow(dsply, c->window); set_wm_state(c, IconicState); check_focus(get_prev_focused()); } } } void unhide(Client *c) { if (c != NULL) { if (c->hidden) { c->hidden = 0; topmost_client = c; XMapWindow(dsply, c->window); XMapRaised(dsply, c->frame); set_wm_state(c, NormalState); } } } void toggle_fullscreen(Client *c) { int xoffset, yoffset, maxwinwidth, maxwinheight; if (c != NULL && !c->trans) { if (c == fullscreen_client) // reset to original size { c->x = fs_prevdims.x; c->y = fs_prevdims.y; c->width = fs_prevdims.width; c->height = fs_prevdims.height; XMoveResizeWindow(dsply, c->frame, c->x, c->y - BARHEIGHT(), c->width, c->height + BARHEIGHT()); XMoveResizeWindow(dsply, c->window, 0, BARHEIGHT(), c->width, c->height); send_config(c); fullscreen_client = NULL; showing_taskbar = 1; } else // make fullscreen { xoffset = yoffset = 0; maxwinwidth = DisplayWidth(dsply, screen); maxwinheight = DisplayHeight(dsply, screen) - BARHEIGHT(); if (fullscreen_client != NULL) // reset existing fullscreen window to original size { fullscreen_client->x = fs_prevdims.x; fullscreen_client->y = fs_prevdims.y; fullscreen_client->width = fs_prevdims.width; fullscreen_client->height = fs_prevdims.height; XMoveResizeWindow(dsply, fullscreen_client->frame, fullscreen_client->x, fullscreen_client->y - BARHEIGHT(), fullscreen_client->width, fullscreen_client->height + BARHEIGHT()); XMoveResizeWindow(dsply, fullscreen_client->window, 0, BARHEIGHT(), fullscreen_client->width, fullscreen_client->height); send_config(fullscreen_client); } fs_prevdims.x = c->x; fs_prevdims.y = c->y; fs_prevdims.width = c->width; fs_prevdims.height = c->height; c->x = 0 - BORDERWIDTH(c); c->y = BARHEIGHT() - BORDERWIDTH(c); c->width = maxwinwidth; c->height = maxwinheight; if (c->size->flags & PMaxSize || c->size->flags & PResizeInc) { if (c->size->flags & PResizeInc) { Rect maxwinsize; maxwinsize.x = xoffset; maxwinsize.width = maxwinwidth; maxwinsize.y = yoffset; maxwinsize.height = maxwinheight; get_incsize(c, (unsigned int *)&c->size->max_width, (unsigned int *)&c->size->max_height, &maxwinsize, PIXELS); } if (c->size->max_width < maxwinwidth) { c->width = c->size->max_width; xoffset = (maxwinwidth - c->width) / 2; } if (c->size->max_height < maxwinheight) { c->height = c->size->max_height; yoffset = (maxwinheight - c->height) / 2; } } XMoveResizeWindow(dsply, c->frame, c->x, c->y, maxwinwidth, maxwinheight); XMoveResizeWindow(dsply, c->window, xoffset, yoffset, c->width, c->height); send_config(c); fullscreen_client = c; showing_taskbar = in_taskbar; } redraw_taskbar(); } } /* The name of this function is a bit misleading: if the client * doesn't listen to WM_DELETE then we just terminate it with extreme * prejudice. */ void send_wm_delete(Client *c) { int i, n, found = 0; Atom *protocols; if (XGetWMProtocols(dsply, c->window, &protocols, &n)) { for (i = 0; i < n; i++) { if (protocols[i] == wm_delete) { found++; } } XFree(protocols); } if (found) { send_xmessage(c->window, wm_protos, wm_delete); } else { XKillClient(dsply, c->window); } } void move(Client *c) { XEvent ev; int old_cx = c->x; int old_cy = c->y; int mousex, mousey, dw, dh; Client *exposed_c; Rect bounddims; Window constraint_win; XSetWindowAttributes pattr; dw = DisplayWidth(dsply, screen); dh = DisplayHeight(dsply, screen); get_mouse_position(&mousex, &mousey); bounddims.x = (mousex - c->x) - BORDERWIDTH(c); bounddims.width = (dw - bounddims.x - (c->width - bounddims.x)) + 1; bounddims.y = mousey - c->y; bounddims.height = (dh - bounddims.y - (c->height - bounddims.y)) + 1; bounddims.y += (BARHEIGHT() * 2) - BORDERWIDTH(c); bounddims.height += c->height - ((BARHEIGHT() * 2) - DEF_BORDERWIDTH); constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); #ifdef DEBUG fprintf(stderr, "move() : constraint_win is (%d, %d)-(%d, %d)\n", bounddims.x, bounddims.y, bounddims.x + bounddims.width, bounddims.y + bounddims.height); #endif XMapWindow(dsply, constraint_win); if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) { XDestroyWindow(dsply, constraint_win); return; } do { XMaskEvent(dsply, ExposureMask|MouseMask, &ev); switch (ev.type) { case Expose: exposed_c = find_client(ev.xexpose.window, FRAME); if (exposed_c != NULL) { redraw(exposed_c); } break; case MotionNotify: c->x = old_cx + (ev.xmotion.x - mousex); c->y = old_cy + (ev.xmotion.y - mousey); XMoveWindow(dsply, c->frame, c->x, c->y - BARHEIGHT()); send_config(c); break; } } while (ev.type != ButtonRelease); ungrab(); XDestroyWindow(dsply, constraint_win); } void resize(Client *c, int x, int y) { XEvent ev; Client *exposed_c; Rect newdims, recalceddims, bounddims; unsigned int dragging_outwards, dw, dh; Window constraint_win, resize_win, resizebar_win; XSetWindowAttributes pattr, resize_pattr, resizebar_pattr; if (x > c->x + BORDERWIDTH(c) && x < (c->x + c->width) - BORDERWIDTH(c) && y > (c->y - BARHEIGHT()) + BORDERWIDTH(c) && y < (c->y + c->height) - BORDERWIDTH(c)) { // inside the window, dragging outwards dragging_outwards = 1; } else { // outside the window, dragging inwards dragging_outwards = 0; } dw = DisplayWidth(dsply, screen); dh = DisplayHeight(dsply, screen); bounddims.x = 0; bounddims.width = dw; bounddims.y = 0; bounddims.height = dh; constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); XMapWindow(dsply, constraint_win); if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, resize_curs, CurrentTime) == GrabSuccess)) { XDestroyWindow(dsply, constraint_win); return; } newdims.x = c->x; newdims.y = c->y - BARHEIGHT(); newdims.width = c->width; newdims.height = c->height + BARHEIGHT(); copy_dims(&newdims, &recalceddims); // create and map resize window resize_pattr.override_redirect = True; resize_pattr.background_pixel = menu_col.pixel; resize_pattr.border_pixel = border_col.pixel; resize_pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; resize_win = XCreateWindow(dsply, root, newdims.x, newdims.y, newdims.width, newdims.height, DEF_BORDERWIDTH, DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &resize_pattr); XMapRaised(dsply, resize_win); resizebar_pattr.override_redirect = True; resizebar_pattr.background_pixel = active_col.pixel; resizebar_pattr.border_pixel = border_col.pixel; resizebar_pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; resizebar_win = XCreateWindow(dsply, resize_win, -DEF_BORDERWIDTH, -DEF_BORDERWIDTH, newdims.width, BARHEIGHT() - DEF_BORDERWIDTH, DEF_BORDERWIDTH, DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &resizebar_pattr); XMapRaised(dsply, resizebar_win); #ifdef XFT // temporarily swap drawables in order to draw on the resize window's XFT context XftDrawChange(c->xftdraw, (Drawable) resizebar_win); #endif // hide real window's frame XUnmapWindow(dsply, c->frame); do { XMaskEvent(dsply, ExposureMask|MouseMask, &ev); switch (ev.type) { case Expose: if (ev.xexpose.window == resizebar_win) { write_titletext(c, resizebar_win); } else { exposed_c = find_client(ev.xexpose.window, FRAME); if (exposed_c) { redraw(exposed_c); } } break; case MotionNotify: { unsigned int in_taskbar = 1, leftedge_changed = 0, rightedge_changed = 0, topedge_changed = 0, bottomedge_changed = 0; int newwidth, newheight; // warping the pointer is wrong - wait until it leaves the taskbar if (ev.xmotion.y < BARHEIGHT()) { in_taskbar = 1; } else { if (in_taskbar == 1) // first time outside taskbar { in_taskbar = 0; bounddims.x = 0; bounddims.width = dw; bounddims.y = BARHEIGHT(); bounddims.height = dh - BARHEIGHT(); XMoveResizeWindow(dsply, constraint_win, bounddims.x, bounddims.y, bounddims.width, bounddims.height); in_taskbar = 0; } // inside the window, dragging outwards if (dragging_outwards) { if (ev.xmotion.x < newdims.x + BORDERWIDTH(c)) { newdims.width += newdims.x + BORDERWIDTH(c) - ev.xmotion.x; newdims.x = ev.xmotion.x - BORDERWIDTH(c); leftedge_changed = 1; } else if (ev.xmotion.x > newdims.x + newdims.width + BORDERWIDTH(c)) { newdims.width = (ev.xmotion.x - newdims.x - BORDERWIDTH(c)) + 1; // add 1 to allow window to be flush with edge of screen rightedge_changed = 1; } if (ev.xmotion.y < newdims.y + BORDERWIDTH(c)) { newdims.height += newdims.y + BORDERWIDTH(c) - ev.xmotion.y; newdims.y = ev.xmotion.y - BORDERWIDTH(c); topedge_changed = 1; } else if (ev.xmotion.y > newdims.y + newdims.height + BORDERWIDTH(c)) { newdims.height = (ev.xmotion.y - newdims.y - BORDERWIDTH(c)) + 1; // add 1 to allow window to be flush with edge of screen bottomedge_changed = 1; } } // outside the window, dragging inwards else { unsigned int above_win, below_win, leftof_win, rightof_win; unsigned int in_win; above_win = (ev.xmotion.y < newdims.y + BORDERWIDTH(c)); below_win = (ev.xmotion.y > newdims.y + newdims.height + BORDERWIDTH(c)); leftof_win = (ev.xmotion.x < newdims.x + BORDERWIDTH(c)); rightof_win = (ev.xmotion.x > newdims.x + newdims.width + BORDERWIDTH(c)); in_win = ((!above_win) && (!below_win) && (!leftof_win) && (!rightof_win)); if (in_win) { unsigned int from_left, from_right, from_top, from_bottom; from_left = ev.xmotion.x - newdims.x - BORDERWIDTH(c); from_right = newdims.x + newdims.width + BORDERWIDTH(c) - ev.xmotion.x; from_top = ev.xmotion.y - newdims.y - BORDERWIDTH(c); from_bottom = newdims.y + newdims.height + BORDERWIDTH(c) - ev.xmotion.y; if (from_left < from_right && from_left < from_top && from_left < from_bottom) { newdims.width -= ev.xmotion.x - newdims.x - BORDERWIDTH(c); newdims.x = ev.xmotion.x - BORDERWIDTH(c); leftedge_changed = 1; } else if (from_right < from_top && from_right < from_bottom) { newdims.width = ev.xmotion.x - newdims.x - BORDERWIDTH(c); rightedge_changed = 1; } else if (from_top < from_bottom) { newdims.height -= ev.xmotion.y - newdims.y - BORDERWIDTH(c); newdims.y = ev.xmotion.y - BORDERWIDTH(c); topedge_changed = 1; } else { newdims.height = ev.xmotion.y - newdims.y - BORDERWIDTH(c); bottomedge_changed = 1; } } } // coords have changed if (leftedge_changed || rightedge_changed || topedge_changed || bottomedge_changed) { copy_dims(&newdims, &recalceddims); recalceddims.height -= BARHEIGHT(); if (get_incsize(c, (unsigned int *)&newwidth, (unsigned int *)&newheight, &recalceddims, PIXELS)) { if (leftedge_changed) { recalceddims.x = (recalceddims.x + recalceddims.width) - newwidth; recalceddims.width = newwidth; } else if (rightedge_changed) { recalceddims.width = newwidth; } if (topedge_changed) { recalceddims.y = (recalceddims.y + recalceddims.height) - newheight; recalceddims.height = newheight; } else if (bottomedge_changed) { recalceddims.height = newheight; } } recalceddims.height += BARHEIGHT(); limit_size(c, &recalceddims); XMoveResizeWindow(dsply, resize_win, recalceddims.x, recalceddims.y, recalceddims.width, recalceddims.height); XResizeWindow(dsply, resizebar_win, recalceddims.width, BARHEIGHT() - DEF_BORDERWIDTH); } } } break; } } while (ev.type != ButtonRelease); XUngrabServer(dsply); ungrab(); c->x = recalceddims.x; c->y = recalceddims.y + BARHEIGHT(); c->width = recalceddims.width; c->height = recalceddims.height - BARHEIGHT(); XMoveResizeWindow(dsply, c->frame, c->x, c->y - BARHEIGHT(), c->width, c->height + BARHEIGHT()); XResizeWindow(dsply, c->window, c->width, c->height); // unhide real window's frame XMapWindow(dsply, c->frame); XSetInputFocus(dsply, c->window, RevertToNone, CurrentTime); send_config(c); XDestroyWindow(dsply, constraint_win); #ifdef XFT // reset the drawable XftDrawChange(c->xftdraw, (Drawable) c->frame); #endif XDestroyWindow(dsply, resizebar_win); XDestroyWindow(dsply, resize_win); } static void limit_size(Client *c, Rect *newdims) { int dw, dh; dw = DisplayWidth(dsply, screen); dh = DisplayHeight(dsply, screen); if (c->size->flags & PMinSize) { if (newdims->width < c->size->min_width) { newdims->width = c->size->min_width; } if (newdims->height < c->size->min_height) { newdims->height = c->size->min_height; } } if (c->size->flags & PMaxSize) { if (newdims->width > c->size->max_width) { newdims->width = c->size->max_width; } if (newdims->height > c->size->max_height) { newdims->height = c->size->max_height; } } if (newdims->width < MINWINWIDTH) { newdims->width = MINWINWIDTH; } if (newdims->height < MINWINHEIGHT) { newdims->height = MINWINHEIGHT; } if (newdims->width > dw) { newdims->width = dw; } if (newdims->height > (dh - BARHEIGHT())) { newdims->height = (dh - BARHEIGHT()); } } /* If the window in question has a ResizeInc int, then it wants to be * resized in multiples of some (x,y). Here we set x_ret and y_ret to * the number of multiples (if mode == INCREMENTS) or the correct size * in pixels for said multiples (if mode == PIXELS). */ static int get_incsize(Client *c, unsigned int *x_ret, unsigned int *y_ret, Rect *newdims, int mode) { int basex, basey; if (c->size->flags & PResizeInc) { basex = (c->size->flags & PBaseSize) ? c->size->base_width : (c->size->flags & PMinSize) ? c->size->min_width : 0; basey = (c->size->flags & PBaseSize) ? c->size->base_height : (c->size->flags & PMinSize) ? c->size->min_height : 0; // work around broken apps that set their resize increments to 0 if (mode == PIXELS) { if (c->size->width_inc != 0) { *x_ret = newdims->width - ((newdims->width - basex) % c->size->width_inc); } if (c->size->height_inc != 0) { *y_ret = newdims->height - ((newdims->height - basey) % c->size->height_inc); } } else // INCREMENTS { if (c->size->width_inc != 0) { *x_ret = (newdims->width - basex) / c->size->width_inc; } if (c->size->height_inc != 0) { *y_ret = (newdims->height - basey) / c->size->height_inc; } } return 1; } return 0; } void write_titletext(Client *c, Window bar_win) { #ifdef MWM_HINTS if (!c->has_title) { return; } #endif if (!c->trans && c->name != NULL) { #ifdef XFT (void) bar_win; // fixes a warning XftDrawString8(c->xftdraw, &xft_detail, xftfont, SPACE, SPACE + xftfont->ascent, (unsigned char *)c->name, strlen(c->name)); #else XDrawString(dsply, bar_win, text_gc, SPACE, SPACE + font->ascent, c->name, strlen(c->name)); #endif } } windowlab-1.40/main.c0000666000175000017500000002014611356155277013171 0ustar nicknick/* WindowLab - an X11 window manager * Copyright (c) 2001-2010 Nick Gravgaard * me at nickgravgaard.com * http://nickgravgaard.com/windowlab/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include "windowlab.h" Display *dsply = NULL; Window root; int screen; XFontStruct *font = NULL; #ifdef XFT XftFont *xftfont = NULL; XftColor xft_detail; #endif GC string_gc, border_gc, text_gc, active_gc, depressed_gc, inactive_gc, menu_gc, selected_gc, empty_gc; XColor border_col, text_col, active_col, depressed_col, inactive_col, menu_col, selected_col, empty_col; Cursor resize_curs; Atom wm_state, wm_change_state, wm_protos, wm_delete, wm_cmapwins; #ifdef MWM_HINTS Atom mwm_hints; #endif Client *head_client = NULL, *focused_client = NULL, *topmost_client = NULL, *fullscreen_client = NULL; unsigned int in_taskbar = 0; // actually, we don't know yet unsigned int showing_taskbar = 1; unsigned int focus_count = 0; Rect fs_prevdims; char *opt_font = DEF_FONT; char *opt_border = DEF_BORDER; char *opt_text = DEF_TEXT; char *opt_active = DEF_ACTIVE; char *opt_inactive = DEF_INACTIVE; char *opt_menu = DEF_MENU; char *opt_selected = DEF_SELECTED; char *opt_empty = DEF_EMPTY; char *opt_display = NULL; #ifdef SHAPE Bool shape; int shape_event; #endif unsigned int numlockmask = 0; static void scan_wins(void); static void setup_display(void); int main(int argc, char **argv) { int i; struct sigaction act; #define OPT_STR(name, variable) \ if (strcmp(argv[i], name) == 0 && i + 1 < argc) \ { \ variable = argv[++i]; \ continue; \ } for (i = 1; i < argc; i++) { OPT_STR("-font", opt_font) OPT_STR("-border", opt_border) OPT_STR("-text", opt_text) OPT_STR("-active", opt_active) OPT_STR("-inactive", opt_inactive) OPT_STR("-menu", opt_menu) OPT_STR("-selected", opt_selected) OPT_STR("-empty", opt_empty) OPT_STR("-display", opt_display) if (strcmp(argv[i], "-about") == 0) { printf("WindowLab " VERSION " (" RELEASEDATE "), Copyright (c) 2001-2009 Nick Gravgaard\nWindowLab comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it\nunder certain conditions; view the LICENCE file for details.\n"); exit(0); } // shouldn't get here; must be a bad option err("usage:\n windowlab [options]\n\noptions are:\n -font \n -border|-text|-active|-inactive|-menu|-selected|-empty \n -about\n -display "); return 2; } act.sa_handler = sig_handler; act.sa_flags = 0; sigaction(SIGTERM, &act, NULL); sigaction(SIGINT, &act, NULL); sigaction(SIGHUP, &act, NULL); sigaction(SIGCHLD, &act, NULL); setup_display(); get_menuitems(); make_taskbar(); scan_wins(); do_event_loop(); return 1; // just another brick in the -Wall } static void scan_wins(void) { unsigned int nwins, i; Window dummyw1, dummyw2, *wins; XWindowAttributes attr; XQueryTree(dsply, root, &dummyw1, &dummyw2, &wins, &nwins); for (i = 0; i < nwins; i++) { XGetWindowAttributes(dsply, wins[i], &attr); if (!attr.override_redirect && attr.map_state == IsViewable) { make_new_client(wins[i]); } } XFree(wins); } static void setup_display(void) { XColor dummyc; XGCValues gv; XSetWindowAttributes sattr; XModifierKeymap *modmap; int i, j; #ifdef SHAPE int dummy; #endif dsply = XOpenDisplay(opt_display); if (dsply == NULL) { err("can't open display! check your DISPLAY variable."); exit(1); } XSetErrorHandler(handle_xerror); screen = DefaultScreen(dsply); root = RootWindow(dsply, screen); wm_state = XInternAtom(dsply, "WM_STATE", False); wm_change_state = XInternAtom(dsply, "WM_CHANGE_STATE", False); wm_protos = XInternAtom(dsply, "WM_PROTOCOLS", False); wm_delete = XInternAtom(dsply, "WM_DELETE_WINDOW", False); wm_cmapwins = XInternAtom(dsply, "WM_COLORMAP_WINDOWS", False); #ifdef MWM_HINTS mwm_hints = XInternAtom(dsply, _XA_MWM_HINTS, False); #endif XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_border, &border_col, &dummyc); XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_text, &text_col, &dummyc); XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_active, &active_col, &dummyc); XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_inactive, &inactive_col, &dummyc); XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_menu, &menu_col, &dummyc); XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_selected, &selected_col, &dummyc); XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_empty, &empty_col, &dummyc); depressed_col.pixel = active_col.pixel; depressed_col.red = active_col.red - ACTIVE_SHADOW; depressed_col.green = active_col.green - ACTIVE_SHADOW; depressed_col.blue = active_col.blue - ACTIVE_SHADOW; depressed_col.red = depressed_col.red <= (USHRT_MAX - ACTIVE_SHADOW) ? depressed_col.red : 0; depressed_col.green = depressed_col.green <= (USHRT_MAX - ACTIVE_SHADOW) ? depressed_col.green : 0; depressed_col.blue = depressed_col.blue <= (USHRT_MAX - ACTIVE_SHADOW) ? depressed_col.blue : 0; XAllocColor(dsply, DefaultColormap(dsply, screen), &depressed_col); #ifdef XFT xft_detail.color.red = text_col.red; xft_detail.color.green = text_col.green; xft_detail.color.blue = text_col.blue; xft_detail.color.alpha = 0xffff; xft_detail.pixel = text_col.pixel; xftfont = XftFontOpenXlfd(dsply, DefaultScreen(dsply), opt_font); if (xftfont == NULL) { err("font '%s' not found", opt_font); exit(1); } #else font = XLoadQueryFont(dsply, opt_font); if (font == NULL) { err("XLoadQueryFont(): font '%s' not found", opt_font); exit(1); } #endif #ifdef SHAPE shape = XShapeQueryExtension(dsply, &shape_event, &dummy); #endif resize_curs = XCreateFontCursor(dsply, XC_fleur); /* find out which modifier is NumLock - we'll use this when grabbing every combination of modifiers we can think of */ modmap = XGetModifierMapping(dsply); for (i = 0; i < 8; i++) { for (j = 0; j < modmap->max_keypermod; j++) { if (modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dsply, XK_Num_Lock)) { numlockmask = (1 << i); #ifdef DEBUG fprintf(stderr, "setup_display() : XK_Num_Lock is (1<<0x%02x)\n", i); #endif } } } XFree(modmap); gv.function = GXcopy; gv.foreground = border_col.pixel; gv.line_width = DEF_BORDERWIDTH; border_gc = XCreateGC(dsply, root, GCFunction|GCForeground|GCLineWidth, &gv); gv.foreground = text_col.pixel; gv.line_width = 1; #ifdef XFT text_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); #else gv.font = font->fid; text_gc = XCreateGC(dsply, root, GCFunction|GCForeground|GCFont, &gv); #endif gv.foreground = active_col.pixel; active_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); gv.foreground = depressed_col.pixel; depressed_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); gv.foreground = inactive_col.pixel; inactive_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); gv.foreground = menu_col.pixel; menu_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); gv.foreground = selected_col.pixel; selected_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); gv.foreground = empty_col.pixel; empty_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); sattr.event_mask = ChildMask|ColormapChangeMask|ButtonMask; XChangeWindowAttributes(dsply, root, CWEventMask, &sattr); grab_keysym(root, MODIFIER, KEY_CYCLEPREV); grab_keysym(root, MODIFIER, KEY_CYCLENEXT); grab_keysym(root, MODIFIER, KEY_FULLSCREEN); grab_keysym(root, MODIFIER, KEY_TOGGLEZ); } windowlab-1.40/events.c0000666000175000017500000003652211356155266013554 0ustar nicknick/* WindowLab - an X11 window manager * Copyright (c) 2001-2010 Nick Gravgaard * me at nickgravgaard.com * http://nickgravgaard.com/windowlab/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include "windowlab.h" static void handle_key_press(XKeyEvent *); static void handle_button_press(XButtonEvent *); static void handle_windowbar_click(XButtonEvent *, Client *); static unsigned int box_clicked(Client *, int); static void draw_button(Client *, GC *, GC *, unsigned int); static void handle_configure_request(XConfigureRequestEvent *); static void handle_map_request(XMapRequestEvent *); static void handle_unmap_event(XUnmapEvent *); static void handle_destroy_event(XDestroyWindowEvent *); static void handle_client_message(XClientMessageEvent *); static void handle_property_change(XPropertyEvent *); static void handle_enter_event(XCrossingEvent *); static void handle_colormap_change(XColormapEvent *); static void handle_expose_event(XExposeEvent *); #ifdef SHAPE static void handle_shape_change(XShapeEvent *); #endif static int interruptible_XNextEvent(XEvent *event); /* We may want to put in some sort of check for unknown events at some * point. TWM has an interesting and different way of doing this... */ void do_event_loop(void) { XEvent ev; for (;;) { interruptible_XNextEvent(&ev); #ifdef DEBUG show_event(ev); #endif /* check to see if menu rebuild has been requested */ if (do_menuitems) { free_menuitems(); get_menuitems(); } switch (ev.type) { case KeyPress: handle_key_press(&ev.xkey); break; case ButtonPress: handle_button_press(&ev.xbutton); break; case ConfigureRequest: handle_configure_request(&ev.xconfigurerequest); break; case MapRequest: handle_map_request(&ev.xmaprequest); break; case UnmapNotify: handle_unmap_event(&ev.xunmap); break; case DestroyNotify: handle_destroy_event(&ev.xdestroywindow); break; case ClientMessage: handle_client_message(&ev.xclient); break; case ColormapNotify: handle_colormap_change(&ev.xcolormap); break; case PropertyNotify: handle_property_change(&ev.xproperty); break; case EnterNotify: handle_enter_event(&ev.xcrossing); break; case Expose: handle_expose_event(&ev.xexpose); break; #ifdef SHAPE default: if (shape && ev.type == shape_event) { handle_shape_change((XShapeEvent *)&ev); } #endif } } } static void handle_key_press(XKeyEvent *e) { KeySym key = XKeycodeToKeysym(dsply, e->keycode, 0); switch (key) { case KEY_CYCLEPREV: cycle_previous(); break; case KEY_CYCLENEXT: cycle_next(); break; case KEY_FULLSCREEN: toggle_fullscreen(focused_client); break; case KEY_TOGGLEZ: raise_lower(focused_client); break; } } /* Someone clicked a button. If it was on the root, we get the click * by default. If it's on a window frame, we get it as well. If it's * on a client window, it may still fall through to us if the client * doesn't select for mouse-click events. */ static void handle_button_press(XButtonEvent *e) { Client *c; if (e->state & MODIFIER) { if (focused_client != NULL && focused_client != fullscreen_client) { resize(focused_client, e->x_root, e->y_root); } else { // pass event on XAllowEvents(dsply, ReplayPointer, CurrentTime); } } else if (e->window == root) { #ifdef DEBUG dump_clients(); #endif if (e->button == Button3) { rclick_root(); } } else if (e->window == taskbar) { switch (e->button) { case Button1: // left mouse button lclick_taskbar(e->x); break; case Button3: // right mouse button rclick_taskbar(e->x); break; case Button4: // mouse wheel up cycle_previous(); break; case Button5: // mouse wheel down cycle_next(); break; } } else { // pass event on XAllowEvents(dsply, ReplayPointer, CurrentTime); if (e->button == Button1) { c = find_client(e->window, FRAME); if (c != NULL) { // click-to-focus check_focus(c); if (e->y < BARHEIGHT() && c != fullscreen_client) { handle_windowbar_click(e, c); } } } else if (e->button == Button3) { rclick_root(); } } } static void handle_windowbar_click(XButtonEvent *e, Client *c) { static Client * first_click_c; static Time first_click_time; unsigned int in_box, in_box_down, in_box_up; int win_ypos; XEvent ev; in_box_down = box_clicked(c, e->x); if (in_box_down <= 2) { if (!grab(root, MouseMask, None)) { return; } XGrabServer(dsply); in_box = 1; draw_button(c, &text_gc, &depressed_gc, in_box_down); do { XMaskEvent(dsply, MouseMask, &ev); in_box_up = box_clicked(c, ev.xbutton.x - (c->x + DEF_BORDERWIDTH)); win_ypos = (ev.xbutton.y - c->y) + BARHEIGHT(); if (ev.type == MotionNotify) { if ((win_ypos <= BARHEIGHT()) && (win_ypos >= DEF_BORDERWIDTH) && (in_box_up == in_box_down)) { in_box = 1; draw_button(c, &text_gc, &depressed_gc, in_box_down); } else { in_box = 0; draw_button(c, &text_gc, &active_gc, in_box_down); } } } while (ev.type != ButtonRelease); draw_button(c, &text_gc, &active_gc, in_box_down); XUngrabServer(dsply); ungrab(); if (in_box) { switch (in_box_up) { case 0: send_wm_delete(c); break; case 1: raise_lower(c); break; case 2: hide(c); break; } } } else if (in_box_down != UINT_MAX) { if (first_click_c == c && (e->time - first_click_time) < DEF_DBLCLKTIME) { raise_lower(c); first_click_c = NULL; // prevent 3rd clicks counting as double clicks } else { first_click_c = c; } first_click_time = e->time; move(c); } } /* Return which button was clicked - this is a multiple of BARHEIGHT() * from the right hand side. We only care about 0, 1 and 2. */ static unsigned int box_clicked(Client *c, int x) { int pix_from_right = c->width - x; if (pix_from_right < 0) { return UINT_MAX; // outside window } else { return (pix_from_right / (BARHEIGHT() - DEF_BORDERWIDTH)); } } static void draw_button(Client *c, GC *detail_gc, GC *background_gc, unsigned int which_box) { switch (which_box) { case 0: draw_close_button(c, detail_gc, background_gc); break; case 1: draw_toggledepth_button(c, detail_gc, background_gc); break; case 2: draw_hide_button(c, detail_gc, background_gc); break; } } /* Because we are redirecting the root window, we get ConfigureRequest * events from both clients we're handling and ones that we aren't. * For clients we manage, we need to fiddle with the frame and the * client window, and for unmanaged windows we have to pass along * everything unchanged. Thankfully, we can reuse (a) the * XWindowChanges struct and (b) the code to configure the client * window in both cases. * * Most of the assignments here are going to be garbage, but only the * ones that are masked in by e->value_mask will be looked at by the X * server. * * We ignore managed clients that want their z-order changed and * managed fullscreen clients that want their size and/or position * changed (except to update their size and/or position for when * fullscreen mode is toggled off). From what I can remember, clients * are supposed to have been written so that they are aware that their * requirements may not be met by the window manager. */ static void handle_configure_request(XConfigureRequestEvent *e) { Client *c = find_client(e->window, WINDOW); XWindowChanges wc; if (fullscreen_client != NULL && c == fullscreen_client) { if (e->value_mask & CWX) { fs_prevdims.x = e->x; } if (e->value_mask & CWY) { fs_prevdims.y = e->y; } if (e->value_mask & CWWidth) { fs_prevdims.width = e->width; } if (e->value_mask & CWHeight) { fs_prevdims.height = e->height; } return; } if (c != NULL) { gravitate(c, REMOVE_GRAVITY); if (e->value_mask & CWX) { c->x = e->x; } if (e->value_mask & CWY) { c->y = e->y; } if (e->value_mask & CWWidth) { c->width = e->width; } if (e->value_mask & CWHeight) { c->height = e->height; } refix_position(c, e); gravitate(c, APPLY_GRAVITY); // configure the frame wc.x = c->x; wc.y = c->y - BARHEIGHT(); wc.width = c->width; wc.height = c->height + BARHEIGHT(); wc.border_width = DEF_BORDERWIDTH; //wc.sibling = e->above; //wc.stack_mode = e->detail; XConfigureWindow(dsply, c->frame, e->value_mask, &wc); #ifdef SHAPE if (e->value_mask & (CWWidth|CWHeight)) { set_shape(c); } #endif send_config(c); // start setting up the next call wc.x = 0; wc.y = BARHEIGHT(); } else { wc.x = e->x; wc.y = e->y; } wc.width = e->width; wc.height = e->height; //wc.sibling = e->above; //wc.stack_mode = e->detail; XConfigureWindow(dsply, e->window, e->value_mask, &wc); } /* Two possibilities if a client is asking to be mapped. One is that * it's a new window, so we handle that if it isn't in our clients * list anywhere. The other is that it already exists and wants to * de-iconify, which is simple to take care of. */ static void handle_map_request(XMapRequestEvent *e) { Client *c = find_client(e->window, WINDOW); if (c != NULL) { unhide(c); } else { make_new_client(e->window); } } /* See windowlab.h for the intro to this one. If this is a window we * unmapped ourselves, decrement c->ignore_unmap and casually go on as * if nothing had happened. If the window unmapped itself from under * our feet, however, get rid of it. * * If you spend a lot of time with -DDEBUG on, you'll realize that * because most clients unmap and destroy themselves at once, they're * gone before we even get the Unmap event, never mind the Destroy * one. This will necessitate some extra caution in remove_client. * * Personally, I think that if Map events are intercepted, Unmap * events should be intercepted too. No use arguing with a standard * that's almost as old as I am though. :-( */ static void handle_unmap_event(XUnmapEvent *e) { Client *c = find_client(e->window, WINDOW); if (c != NULL) { if (c->ignore_unmap) { c->ignore_unmap--; } else { remove_client(c, WITHDRAW); } } } /* This happens when a window is iconified and destroys itself. An * Unmap event wouldn't happen in that case because the window is * already unmapped. */ static void handle_destroy_event(XDestroyWindowEvent *e) { Client *c = find_client(e->window, WINDOW); if (c != NULL) { remove_client(c, WITHDRAW); } } /* If a client wants to iconify itself (boo! hiss!) it must send a * special kind of ClientMessage. We might set up other handlers here * but there's nothing else required by the ICCCM. */ static void handle_client_message(XClientMessageEvent *e) { Client *c = find_client(e->window, WINDOW); if (c != NULL && e->message_type == wm_change_state && e->format == 32 && e->data.l[0] == IconicState) { hide(c); } } /* All that we have cached is the name and the size hints, so we only * have to check for those here. A change in the name means we have to * immediately wipe out the old name and redraw; size hints only get * used when we need them. */ static void handle_property_change(XPropertyEvent *e) { Client *c = find_client(e->window, WINDOW); long dummy; if (c != NULL) { switch (e->atom) { case XA_WM_NAME: if (c->name) { XFree(c->name); c->name = NULL; } XFetchName(dsply, c->window, &c->name); redraw(c); redraw_taskbar(); break; case XA_WM_NORMAL_HINTS: XGetWMNormalHints(dsply, c->window, c->size, &dummy); break; } } } /* X's default focus policy is follows-mouse, but we have to set it * anyway because some sloppily written clients assume that (a) they * can set the focus whenever they want or (b) that they don't have * the focus unless the keyboard is grabbed to them. OTOH it does * allow us to keep the previous focus when pointing at the root, * which is nice. * * We also implement a colormap-follows-mouse policy here. That, on * the third hand, is *not* X's default. */ static void handle_enter_event(XCrossingEvent *e) { Client *c = NULL; if (e->window == taskbar) { in_taskbar = 1; if (showing_taskbar == 0) { showing_taskbar = 1; redraw_taskbar(); } } else { in_taskbar = 0; if (fullscreen_client != NULL) { if (showing_taskbar == 1) { showing_taskbar = 0; redraw_taskbar(); } } else // no fullscreen client { if (showing_taskbar == 0) { showing_taskbar = 1; redraw_taskbar(); } } c = find_client(e->window, FRAME); if (c != NULL) { XGrabButton(dsply, AnyButton, AnyModifier, c->frame, False, ButtonMask, GrabModeSync, GrabModeSync, None, None); } } } /* Here's part 2 of our colormap policy: when a client installs a new * colormap on itself, set the display's colormap to that. Arguably, * this is bad, because we should only set the colormap if that client * has the focus. However, clients don't usually set colormaps at * random when you're not interacting with them, so I think we're * safe. If you have an 8-bit display and this doesn't work for you, * by all means yell at me, but very few people have 8-bit displays * these days. */ static void handle_colormap_change(XColormapEvent *e) { Client *c = find_client(e->window, WINDOW); //if (c != NULL && e->c_new) // use c_new for c++ if (c != NULL && e->new) { c->cmap = e->colormap; XInstallColormap(dsply, c->cmap); } } /* If we were covered by multiple windows, we will usually get * multiple expose events, so ignore them unless e->count (the number * of outstanding exposes) is zero. */ static void handle_expose_event(XExposeEvent *e) { if (e->window == taskbar) { if (e->count == 0) { redraw_taskbar(); } } else { Client *c = find_client(e->window, FRAME); if (c != NULL && e->count == 0) { redraw(c); } } } #ifdef SHAPE static void handle_shape_change(XShapeEvent *e) { Client *c = find_client(e->window, WINDOW); if (c != NULL) { set_shape(c); } } #endif /* interruptibleXNextEvent() was originally taken from Blender's source code * and came with the following copyright notice: */ /* Copyright (c) Mark J. Kilgard, 1994, 1995, 1996. */ /* This program is freely distributable without licensing fees * and is provided without guarantee or warrantee expressed or * implied. This program is -not- in the public domain. */ /* Unlike XNextEvent, if a signal arrives, interruptibleXNextEvent will * return zero. */ static int interruptible_XNextEvent(XEvent *event) { fd_set fds; int rc; int dsply_fd = ConnectionNumber(dsply); for (;;) { if (XPending(dsply)) { XNextEvent(dsply, event); return 1; } FD_ZERO(&fds); FD_SET(dsply_fd, &fds); rc = select(dsply_fd + 1, &fds, NULL, NULL, NULL); if (rc < 0) { if (errno == EINTR) { return 0; } return 1; } } } windowlab-1.40/client.c0000666000175000017500000002720611356155252013520 0ustar nicknick/* WindowLab - an X11 window manager * Copyright (c) 2001-2010 Nick Gravgaard * me at nickgravgaard.com * http://nickgravgaard.com/windowlab/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "windowlab.h" Client *find_client(Window w, int mode) { Client *c = head_client; if (mode == FRAME) { while (c != NULL) { if (c->frame == w) { return c; } c = c->next; } } else // WINDOW { while (c != NULL) { if (c->window == w) { return c; } c = c->next; } } return NULL; } /* Attempt to follow the ICCCM by explicitly specifying 32 bits for * this property. Does this goof up on 64 bit systems? */ void set_wm_state(Client *c, int state) { CARD32 data[2]; data[0] = state; data[1] = None; //Icon? We don't need no steenking icon. XChangeProperty(dsply, c->window, wm_state, wm_state, 32, PropModeReplace, (unsigned char *)data, 2); } /* If we can't find a WM_STATE we're going to have to assume * Withdrawn. This is not exactly optimal, since we can't really * distinguish between the case where no WM has run yet and when the * state was explicitly removed (Clients are allowed to either set the * atom to Withdrawn or just remove it... yuck.) */ long get_wm_state(Client *c) { Atom real_type; int real_format; long state = WithdrawnState; unsigned long items_read, items_left; unsigned char *data; if (XGetWindowProperty(dsply, c->window, wm_state, 0L, 2L, False, wm_state, &real_type, &real_format, &items_read, &items_left, &data) == Success && items_read) { state = *(long *)data; XFree(data); } return state; } /* This will need to be called whenever we update our Client stuff. * Yeah, yeah, stop yelling at me about OO. */ void send_config(Client *c) { XConfigureEvent ce; ce.type = ConfigureNotify; ce.event = c->window; ce.window = c->window; ce.x = c->x; ce.y = c->y; ce.width = c->width; ce.height = c->height; ce.border_width = 0; ce.above = None; ce.override_redirect = 0; XSendEvent(dsply, c->window, False, StructureNotifyMask, (XEvent *)&ce); } /* After pulling my hair out trying to find some way to tell if a * window is still valid, I've decided to instead carefully ignore any * errors raised by this function. We know that the X calls are, and * we know the only reason why they could fail -- a window has removed * itself completely before the Unmap and Destroy events get through * the queue to us. It's not absolutely perfect, but it works. * * The 'withdrawing' argument specifies if the client is actually * (destroying itself||being destroyed by us) or if we are merely * cleaning up its data structures when we exit mid-session. */ void remove_client(Client *c, int mode) { Client *p; XGrabServer(dsply); XSetErrorHandler(ignore_xerror); #ifdef DEBUG err("removing %s, %d: %d left", c->name, mode, XPending(dsply)); #endif if (mode == WITHDRAW) { set_wm_state(c, WithdrawnState); } else //REMAP { XMapWindow(dsply, c->window); } gravitate(c, REMOVE_GRAVITY); XReparentWindow(dsply, c->window, root, c->x, c->y); #ifdef MWM_HINTS if (c->has_border) { XSetWindowBorderWidth(dsply, c->window, 1); } #else XSetWindowBorderWidth(dsply, c->window, 1); #endif #ifdef XFT XftDrawDestroy(c->xftdraw); #endif XRemoveFromSaveSet(dsply, c->window); XDestroyWindow(dsply, c->frame); if (head_client == c) { head_client = c->next; } else { for (p = head_client; p && p->next; p = p->next) { if (p->next == c) { p->next = c->next; } } } if (c->name != NULL) { XFree(c->name); } if (c->size) { XFree(c->size); } if (c == fullscreen_client) { fullscreen_client = NULL; } if (c == focused_client) { focused_client = NULL; check_focus(get_prev_focused()); } free(c); XSync(dsply, False); XSetErrorHandler(handle_xerror); XUngrabServer(dsply); redraw_taskbar(); } void redraw(Client *c) { if (c == fullscreen_client) { return; } #ifdef MWM_HINTS if (!c->has_title) { return; } #endif XDrawLine(dsply, c->frame, border_gc, 0, BARHEIGHT() - DEF_BORDERWIDTH + DEF_BORDERWIDTH / 2, c->width, BARHEIGHT() - DEF_BORDERWIDTH + DEF_BORDERWIDTH / 2); // clear text part of bar if (c == focused_client) { XFillRectangle(dsply, c->frame, active_gc, 0, 0, c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 3), BARHEIGHT() - DEF_BORDERWIDTH); } else { XFillRectangle(dsply, c->frame, inactive_gc, 0, 0, c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 3), BARHEIGHT() - DEF_BORDERWIDTH); } if (!c->trans && c->name != NULL) { #ifdef XFT XftDrawString8(c->xftdraw, &xft_detail, xftfont, SPACE, SPACE + xftfont->ascent, (unsigned char *)c->name, strlen(c->name)); #else XDrawString(dsply, c->frame, text_gc, SPACE, SPACE + font->ascent, c->name, strlen(c->name)); #endif } if (c == focused_client) { draw_hide_button(c, &text_gc, &active_gc); draw_toggledepth_button(c, &text_gc, &active_gc); draw_close_button(c, &text_gc, &active_gc); } else { draw_hide_button(c, &text_gc, &inactive_gc); draw_toggledepth_button(c, &text_gc, &inactive_gc); draw_close_button(c, &text_gc, &inactive_gc); } } /* Window gravity is a mess to explain, but we don't need to do much * about it since we're using X borders. For NorthWest et al, the top * left corner of the window when there is no WM needs to match up * with the top left of our fram once we manage it, and likewise with * SouthWest and the bottom right (these are the only values I ever * use, but the others should be obvious). Our titlebar is on the top * so we only have to adjust in the first case. */ void gravitate(Client *c, int multiplier) { int dy = 0; int gravity = (c->size->flags & PWinGravity) ? c->size->win_gravity : NorthWestGravity; switch (gravity) { case NorthWestGravity: case NorthEastGravity: case NorthGravity: dy = BARHEIGHT(); break; case CenterGravity: dy = BARHEIGHT()/2; break; } c->y += multiplier * dy; } /* Well, the man pages for the shape extension say nothing, but I was * able to find a shape.PS.Z on the x.org FTP site. What we want to do * here is make the window shape be a boolean OR (or union, if you * prefer) of the client's shape and our titlebar. The titlebar * requires both a bound and a clip because it has a border -- the X * server will paint the border in the region between the two. (I knew * that using X borders would get me eventually... ;-)) */ #ifdef SHAPE void set_shape(Client *c) { int n, order; XRectangle temp, *dummy; dummy = XShapeGetRectangles(dsply, c->window, ShapeBounding, &n, &order); if (n > 1) { XShapeCombineShape(dsply, c->frame, ShapeBounding, 0, BARHEIGHT(), c->window, ShapeBounding, ShapeSet); temp.x = -BORDERWIDTH(c); temp.y = -BORDERWIDTH(c); temp.width = c->width + (2 * BORDERWIDTH(c)); temp.height = BARHEIGHT() + BORDERWIDTH(c); XShapeCombineRectangles(dsply, c->frame, ShapeBounding, 0, 0, &temp, 1, ShapeUnion, YXBanded); temp.x = 0; temp.y = 0; temp.width = c->width; temp.height = BARHEIGHT() - BORDERWIDTH(c); XShapeCombineRectangles(dsply, c->frame, ShapeClip, 0, BARHEIGHT(), &temp, 1, ShapeUnion, YXBanded); c->has_been_shaped = 1; } else { if (c->has_been_shaped) { // I can't find a 'remove all shaping' function... temp.x = -BORDERWIDTH(c); temp.y = -BORDERWIDTH(c); temp.width = c->width + (2 * BORDERWIDTH(c)); temp.height = c->height + BARHEIGHT() + (2 * BORDERWIDTH(c)); XShapeCombineRectangles(dsply, c->frame, ShapeBounding, 0, 0, &temp, 1, ShapeSet, YXBanded); } } XFree(dummy); } #endif void check_focus(Client *c) { if (c != NULL) { XSetInputFocus(dsply, c->window, RevertToNone, CurrentTime); XInstallColormap(dsply, c->cmap); } if (c != focused_client) { Client *old_focused = focused_client; focused_client = c; focus_count++; if (c != NULL) { c->focus_order = focus_count; redraw(c); } if (old_focused != NULL) { redraw(old_focused); } redraw_taskbar(); } } Client *get_prev_focused(void) { Client *c = head_client; Client *prev_focused = NULL; unsigned int highest = 0; while (c != NULL) { if (!c->hidden && c->focus_order > highest) { highest = c->focus_order; prev_focused = c; } c = c->next; } return prev_focused; } void draw_hide_button(Client *c, GC *detail_gc, GC *background_gc) { int x, topleft_offset; x = c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 3); topleft_offset = (BARHEIGHT() / 2) - 5; // 5 being ~half of 9 XFillRectangle(dsply, c->frame, *background_gc, x, 0, BARHEIGHT() - DEF_BORDERWIDTH, BARHEIGHT() - DEF_BORDERWIDTH); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 4, topleft_offset + 2, x + topleft_offset + 4, topleft_offset + 0); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 6, topleft_offset + 2, x + topleft_offset + 7, topleft_offset + 1); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 6, topleft_offset + 4, x + topleft_offset + 8, topleft_offset + 4); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 6, topleft_offset + 6, x + topleft_offset + 7, topleft_offset + 7); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 4, topleft_offset + 6, x + topleft_offset + 4, topleft_offset + 8); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 2, topleft_offset + 6, x + topleft_offset + 1, topleft_offset + 7); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 2, topleft_offset + 4, x + topleft_offset + 0, topleft_offset + 4); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 2, topleft_offset + 2, x + topleft_offset + 1, topleft_offset + 1); } void draw_toggledepth_button(Client *c, GC *detail_gc, GC *background_gc) { int x, topleft_offset; x = c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 2); topleft_offset = (BARHEIGHT() / 2) - 6; // 6 being ~half of 11 XFillRectangle(dsply, c->frame, *background_gc, x, 0, BARHEIGHT() - DEF_BORDERWIDTH, BARHEIGHT() - DEF_BORDERWIDTH); XDrawRectangle(dsply, c->frame, *detail_gc, x + topleft_offset, topleft_offset, 7, 7); XDrawRectangle(dsply, c->frame, *detail_gc, x + topleft_offset + 3, topleft_offset + 3, 7, 7); } void draw_close_button(Client *c, GC *detail_gc, GC *background_gc) { int x, topleft_offset; x = c->width - (BARHEIGHT() - DEF_BORDERWIDTH); topleft_offset = (BARHEIGHT() / 2) - 5; // 5 being ~half of 9 XFillRectangle(dsply, c->frame, *background_gc, x, 0, BARHEIGHT() - DEF_BORDERWIDTH, BARHEIGHT() - DEF_BORDERWIDTH); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset, x + topleft_offset + 8, topleft_offset + 7); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset + 1, x + topleft_offset + 7, topleft_offset + 7); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset, topleft_offset + 1, x + topleft_offset + 7, topleft_offset + 8); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset, topleft_offset + 7, x + topleft_offset + 7, topleft_offset); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset + 7, x + topleft_offset + 7, topleft_offset + 1); XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset + 8, x + topleft_offset + 8, topleft_offset + 1); } windowlab-1.40/windowlab.h0000666000175000017500000002325311356155212014227 0ustar nicknick/* WindowLab - an X11 window manager * Copyright (c) 2001-2010 Nick Gravgaard * me at nickgravgaard.com * http://nickgravgaard.com/windowlab/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef WINDOWLAB_H #define WINDOWLAB_H #define VERSION "1.40" #define RELEASEDATE "2010-04-04" #include #include #include #include #include #include #include #include #include #include #include #include #ifdef SHAPE #include #endif #ifdef XFT #include #endif #ifdef MWM_HINTS // These definitions are taken from LessTif 0.95.0's MwmUtil.h. #define MWM_HINTS_FUNCTIONS (1L << 0) #define MWM_HINTS_DECORATIONS (1L << 1) #define MWM_HINTS_INPUT_MODE (1L << 2) #define MWM_HINTS_STATUS (1L << 3) #define MWM_DECOR_ALL (1L << 0) #define MWM_DECOR_BORDER (1L << 1) #define MWM_DECOR_RESIZEH (1L << 2) #define MWM_DECOR_TITLE (1L << 3) #define MWM_DECOR_MENU (1L << 4) #define MWM_DECOR_MINIMIZE (1L << 5) #define MWM_DECOR_MAXIMIZE (1L << 6) #define _XA_MWM_HINTS "_MOTIF_WM_HINTS" #define PROP_MWM_HINTS_ELEMENTS 5 typedef struct PropMwmHints { CARD32 flags; CARD32 functions; CARD32 decorations; INT32 inputMode; CARD32 status; } PropMwmHints; #endif #ifndef PATH_MAX #define PATH_MAX 4096 #endif // here are the default settings - change to suit your taste // if you aren't sure about DEF_FONT, change it to "fixed"; almost all X installations will have that available #ifdef XFT #define DEF_FONT "-bitstream-bitstream vera sans-medium-r-*-*-*-100-*-*-*-*-*-*" #else #define DEF_FONT "-b&h-lucida-medium-r-*-*-10-*-*-*-*-*-*-*" #endif // use named colours, #rgb, #rrggbb or #rrrgggbbb format #define DEF_BORDER "#000" #define DEF_TEXT "#000" #define DEF_ACTIVE "#fd0" #define DEF_INACTIVE "#aaa" #define DEF_MENU "#ddd" #define DEF_SELECTED "#aad" #define DEF_EMPTY "#000" #define DEF_BORDERWIDTH 2 #define ACTIVE_SHADOW 0x2000 // eg #fff becomes #ddd #define SPACE 3 // change MODIFIER to None to remove the need to hold down a modifier key // the Windows key should be Mod4Mask and the Alt key is Mod1Mask #define MODIFIER Mod1Mask // keys may be used by other apps, so change them here #define KEY_CYCLEPREV XK_Tab #define KEY_CYCLENEXT XK_q #define KEY_FULLSCREEN XK_F11 #define KEY_TOGGLEZ XK_F12 // max time between clicks in double click #define DEF_DBLCLKTIME 400 // a few useful masks made up out of X's basic ones. `ChildMask' is a silly name, but oh well. #define ChildMask (SubstructureRedirectMask|SubstructureNotifyMask) #define ButtonMask (ButtonPressMask|ButtonReleaseMask) #define MouseMask (ButtonMask|PointerMotionMask) #define KeyMask (KeyPressMask|KeyReleaseMask) #define ABS(x) (((x) < 0) ? -(x) : (x)) // shorthand for wordy function calls #define setmouse(w, x, y) XWarpPointer(dsply, None, w, 0, 0, 0, 0, x, y) #define ungrab() XUngrabPointer(dsply, CurrentTime) #define grab(w, mask, curs) \ (XGrabPointer(dsply, w, False, mask, GrabModeAsync, GrabModeAsync, None, curs, CurrentTime) == GrabSuccess) #define grab_keysym(w, mask, keysym) \ XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), mask, w, True, GrabModeAsync, GrabModeAsync); \ XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), LockMask|mask, w, True, GrabModeAsync, GrabModeAsync); \ if (numlockmask) \ { \ XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), numlockmask|mask, w, True, GrabModeAsync, GrabModeAsync); \ XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), numlockmask|LockMask|mask, w, True, GrabModeAsync, GrabModeAsync); \ } // I wanna know who the morons who prototyped these functions as implicit int are... #define lower_win(c) ((void) XLowerWindow(dsply, (c)->frame)) #define raise_win(c) ((void) XRaiseWindow(dsply, (c)->frame)) // border width accessor to handle hints/no hints #ifdef MWM_HINTS #define BORDERWIDTH(c) ((c)->has_border ? DEF_BORDERWIDTH : 0) #else #define BORDERWIDTH(c) (DEF_BORDERWIDTH) #endif // bar height #ifdef XFT #define BARHEIGHT() (xftfont->ascent + xftfont->descent + 2*SPACE + 2) #else #define BARHEIGHT() (font->ascent + font->descent + 2*SPACE + 2) #endif // minimum window width and height, enough for 3 buttons and a bit of titlebar #define MINWINWIDTH (BARHEIGHT() * 4) #define MINWINHEIGHT (BARHEIGHT() * 4) // multipliers for calling gravitate #define APPLY_GRAVITY 1 #define REMOVE_GRAVITY -1 // modes to call get_incsize with #define PIXELS 0 #define INCREMENTS 1 // modes for find_client #define WINDOW 0 #define FRAME 1 // modes for remove_client #define WITHDRAW 0 #define REMAP 1 // stuff for the menu file #define MAX_MENUITEMS 24 #define MAX_MENUITEMS_SIZE (sizeof(MenuItem) * MAX_MENUITEMS) #define STR_SIZE 128 #define NO_MENU_LABEL "xterm" #define NO_MENU_COMMAND "xterm" /* This structure keeps track of top-level windows (hereinafter * 'clients'). The clients we know about (i.e. all that don't set * override-redirect) are kept track of in linked list starting at the * global pointer called, appropriately, 'clients'. * * window and parent refer to the actual client window and the larger * frame into which we will reparent it respectively. trans is set to * None for regular windows, and the window's 'owner' for a transient * window. Currently, we don't actually do anything with the owner for * transients; it's just used as a boolean. * * ignore_unmap is for our own purposes and doesn't reflect anything * from X. Whenever we unmap a window intentionally, we increment * ignore_unmap. This way our unmap event handler can tell when it * isn't supposed to do anything. */ typedef struct Client { struct Client *next; char *name; XSizeHints *size; Window window, frame, trans; Colormap cmap; int x, y; int width, height; int ignore_unmap; unsigned int hidden; unsigned int was_hidden; unsigned int focus_order; #ifdef SHAPE Bool has_been_shaped; #endif #ifdef MWM_HINTS Bool has_title, has_border; #endif #ifdef XFT XftDraw *xftdraw; #endif } Client; typedef struct Rect { int x, y; int width, height; } Rect; typedef struct MenuItem { char *command, *label; int x; int width; } MenuItem; // Below here are (mainly generated with cproto) declarations and prototypes for each file. // main.c extern Display *dsply; extern Window root; extern int screen; extern Client *head_client, *focused_client, *topmost_client, *fullscreen_client; extern unsigned int in_taskbar, showing_taskbar, focus_count; extern Rect fs_prevdims; extern XFontStruct *font; #ifdef XFT extern XftFont *xftfont; extern XftColor xft_detail; #endif extern GC border_gc, text_gc, active_gc, depressed_gc, inactive_gc, menu_gc, selected_gc, empty_gc; extern XColor border_col, text_col, active_col, depressed_col, inactive_col, menu_col, selected_col, empty_col; extern Cursor resize_curs; extern Atom wm_state, wm_change_state, wm_protos, wm_delete, wm_cmapwins; #ifdef MWM_HINTS extern Atom mwm_hints; #endif extern char *opt_font, *opt_border, *opt_text, *opt_active, *opt_inactive, *opt_menu, *opt_selected, *opt_empty; #ifdef SHAPE extern int shape, shape_event; #endif extern unsigned int numlockmask; // events.c extern void do_event_loop(void); // client.c extern Client *find_client(Window, int); extern void set_wm_state(Client *, int); extern long get_wm_state(Client *); extern void send_config(Client *); extern void remove_client(Client *, int); extern void redraw(Client *); extern void gravitate(Client *, int); #ifdef SHAPE extern void set_shape(Client *); #endif extern void check_focus(Client *); extern Client *get_prev_focused(void); extern void draw_hide_button(Client *, GC *, GC *); extern void draw_toggledepth_button(Client *, GC *, GC *); extern void draw_close_button(Client *, GC *, GC *); // new.c extern void make_new_client(Window); // manage.c extern void move(Client *); extern void raise_lower(Client *); extern void resize(Client *, int, int); extern void hide(Client *); extern void unhide(Client *); extern void toggle_fullscreen(Client *); extern void send_wm_delete(Client *); extern void write_titletext(Client *, Window); // misc.c extern void err(const char *, ...); extern void fork_exec(char *); extern void sig_handler(int); extern int handle_xerror(Display *, XErrorEvent *); extern int ignore_xerror(Display *, XErrorEvent *); extern int send_xmessage(Window, Atom, long); extern void get_mouse_position(int *, int *); extern void fix_position(Client *); extern void refix_position(Client *, XConfigureRequestEvent *); extern void copy_dims(Rect *, Rect *); #ifdef DEBUG extern void show_event(XEvent); extern void dump(Client *); extern void dump_clients(void); #endif // taskbar.c extern Window taskbar; #ifdef XFT extern XftDraw *tbxftdraw; #endif extern void make_taskbar(void); extern void cycle_previous(void); extern void cycle_next(void); extern void lclick_taskbar(int); extern void rclick_taskbar(int); extern void rclick_root(void); extern void redraw_taskbar(void); extern float get_button_width(void); // menufile.c extern int do_menuitems; extern MenuItem* menuitems; extern unsigned int num_menuitems; extern void get_menuitems(void); extern void free_menuitems(void); #endif /* WINDOWLAB_H */ windowlab-1.40/CHANGELOG0000666000175000017500000005120211356155523013302 0ustar nicknick1.40 (2010-04-04) * integrated a change from Simon Engelsman (thanks!): * XNextEvent() was replaced by interruptible_XNextEvent() function in do_event_loop() 1.39 (2009-12-27) * integrated more changes from Mats Erik Andersson: * menu file handling made more lenient 1.38 (2009-11-14) * integrated more changes from Mats Erik Andersson: * makefile made more flexible * signal handler for SIGHUP now just sets a semaphore, and reloading of menu resources happens in the event loop * fixed problems found by auditing the code with Flawfinder 1.37 (2009-10-04) * integrated a change from Campbell Barton (thanks!): * fixed a bug which was freeing clients' names twice 1.36 (2009-10-01) * rewrote the inherited licences part of the readme file to take into account 9wm's switch to the MIT licence * updated the menu options * integrated more changes from Mats Erik Andersson: * added a simple mechanism which updates the menu in the running instance of WindowLab 1.35 (2009-09-20) * integrated changes from Mats Erik Andersson (thanks!): * fixed a bug that could cause processes to become zombified * fixed a bug that made some windows unviewable 1.34 (2006-11-12) * if no window has focus, focus is given to new windows * if the focused window is closed and no previous window has ever had focus, focus is given to the first client * integrated changes from Jeffrey Drake (thanks!): * fonts now closed properly on exit * integrated more changes from Antti Nykänen: * fixed a compiler warning * integrated more changes from David Lawrence Ramsey: * fixed a compiler warning * changes to the Makefile * many other misc changes! 1.33 (2005-10-16) * integrated changes from Dushkin (thanks!): * scrolling the mouse wheel in the taskbar now task switches * integrated changes from Antti Nykänen (thanks!): * fixed a crash that occurred on the BSDs (and presumably on other systems without /proc/self/exe) * integrated changes from Gregor Imboden (thanks!): * fixed a crash that ocurrred when there are no focused windows and alt + F12 is pressed was fixed * events are always replayed rather than sometimes being eaten * new windows are no longer given focus * added TODO file 1.32 (2005-07-20) * the executable has been made relocatable * double clicking on a windows titlebar toggles its depth (based on code from Roland Haas) * integrated changes from Mike M. Volokhov (thanks!): * a segfault when using realloc() with menu items was fixed * integrated more changes from Roland Haas: * fixed bug with applications that start in iconic mode * -display option added * the initial position and size hints in WM_HINTS are now ignored since they are flagged as obsolete in the manpage of SetWMHints 1.31 (2005-06-21) * more resizing bugs were fixed * integrated changes from Roland Haas (thanks!): * window borders are now taken into account properly when resizing * bugs with XFT fonts when resizing were fixed 1.30 (2005-05-23) * a bug that prevented windows from being made smaller from a side that was at the edge of the screen was fixed * a bug that caused the first clients taskbar button to disappear when all clients were hidden was fixed 1.29 (2005-05-18) * integrated more changes from David Lawrence Ramsey: * a segfault that occurred when removing clients was fixed * some cosmetic code changes were made 1.28 (2005-05-15) * when the focused window is closed or hidden, focus is returned to the previous window * fixed serious problem with using a modifier key for resizing that occurred on some systems * changed resizing to use alt instead of the Windows key * fixed bug when using alt-tab/alt-q to switch focus to a hidden window * changed default fontname to work with Xorg 1.27 (2005-04-16) * hidden windows are now shown and re-hidden when their taskbar button is dragged over 1.26 (2005-02-23) * integrated more changes from David Lawrence Ramsey: * various improvements to the makefile were made * a bug with vertically resizing windows that use size increments was fixed * a few cosmetic cleanups to various sections of code were made 1.25 (2004-12-23) * integrated changes from Matt Borkowski (thanks!): * some Z ordering bugs were fixed * integrated more changes from David Lawrence Ramsey: * click-to-focus was made to work on fullscreen windows that have lost focus * size changes are applied to the original non-fullscreen coordinates of fullscreen windows * all of the function prototypes were made consistent * windows that reconfigure themselves without changing positions no longer move * the shortcut keys behavior changed * some gcc 3.3.x warnings were fixed (ported from aewm) * the switch statement in handle_property_change() is no longer missing a break (ported from aewm) * send_xmessage() now uses an XClientMessageEvent instead of a generic XEvent (ported from aewm) 1.24 (2004-05-29) * holding down the Windows key on it's own now brings the current window to the front, after which dragging against the window's edge with any mouse button depressed resizes it * integrated more changes from David Lawrence Ramsey: * a few prototypes/declarations were fixed 1.23 (2004-03-12) * resizing now optionally uses a modifier key * a very serious bug in the resizing system was fixed * the button graphics were altered * the task switching keys were changed to alt-tab/alt-q * it's no longer possible to resize a fullscreen window * integrated more changes from David Lawrence Ramsey: * a bug where resized windows lost focus was fixed * a debugging statement was added * a compiler warning was fixed * an unnecessary get_mouse_position() call was removed 1.22 (2004-02-22) * the middle mouse button is now used to resize the active window * the resize button has become a hide button * a bug when making windows smaller was fixed * alt-F9/F10 now raises the window as well as changing focus 1.21 (2004-01-17) * the 8½ style of window reshaping was dropped in favour of a completely new mechanism that allows users to change one or many different edges of the window independantly in one action * small bug fix in window titlebar drawing * integrated changes from Guido Schimmels (thanks!): * a bitmap font is no longer referenced if an XFT font is used * integrated more changes from David Lawrence Ramsey: * the code was changed to use NULL explicitely * draw_redraw_button() was renamed as draw_resize_button() * warnings fixed when compiling using gccs -pedantic option 1.20 (2003-12-31) * altered the button graphics and changed the default active window colour * removed the borderwidth command line option * integrated more changes from David Lawrence Ramsey: * made fullscreen mode respect window size increment hints as well as maximum size hints * clicking the right mouse button between between clicking the resize button and starting the window drag cancels resize mode 1.19 (2003-11-14) * users can now click and drag the mouse pointer over the taskbar to quickly find different windows * fixed bug where a menu item would not be lauched unless the cursor was moved * corrected amount that taskbar items text are indented to match that of windows titlebars 1.18 (2003-11-03) * small bug fix in window titlebar drawing 1.17 (2003-11-01) * images added to windows titlebar buttons * quit option added to the sample menu file 1.16 (2003-10-04) * integrated more changes from David Lawrence Ramsey: * ConfigureRequest handler modified so that refix_position() is called before gravity ids reapplied (this allows refix_position() to be much simpler) * resize increments of zero are now handled properly * some changes to the minimum size #defines 1.15 (2003-08-17) * integrated more changes from David Lawrence Ramsey: * it now compiles with Xft support (it previously referenced detail_col instead of text_col in main.c) * extra logic added to refix_position() to keep windows from overlapping the taskbar 1.14 (2003-08-17) * fullscreen mode now reserves space at the top of the screen for the taskbar/menubar which is only displayed when the mouse is over it (for users who want to watch fullscreen video without the wm showing) * created a new colour to cover the screen when a window in fullscreen mode is too small to fill the screen and reintroduced a separate colour for the text * rewrote refix_postion() to use fix_position() * reduced the height of the taskbar - it was previously BORDERWIDTH taller than the windows titlebars * WindowLab now reallocs memory unused by the menu options 1.13 (2003-08-09) * depressed button colour is now derived from the active titlebar colour * removed redundant command line arguments and made the rest less cryptic * clients that cannot be made as big as the screen are now centred when put into fullscreen mode * Makefile now prompts the user before overwriting an existing menurc file * integrated more changes from David Lawrence Ramsey: * fullscreen_client now set to NULL in send_wm_delete() * made a few minor cleanups 1.12 (2003-07-20) * cycle_previous() and cycle_next() greatly simplified * unhide() function added * hidden windows are now listed in the taskbar, and clicking their buttons will unhide them * RATIONALE file added to explain the reasoning behind some of WindowLabs features * integrated more changes from David Lawrence Ramsey: * code added to keep windows (eg Mozilla and Mozilla Firebird) from raising themselves * modified refix_position() to handle maximized (decorless) windows properly * fixed a bug in the manpage where the description of the keybindings is all fused into one paragraph * made a few minor cleanups 1.11 (2003-07-05) * fixed fullscreenmode so that no border is shown on screen * setsid() is now called in fork_exec() to prevent child processes from dying when WindowLab is killed or crashes * support added for toggling window depth and cycling between next and previous windows using the keyboard 1.10 (2003-05-25) * added code to toggle fullscreen mode on non transient windows when the user hits F11 * tidied up some more code 1.09 (2003-04-19) * made new windows appear fully on screen instead of just their titlebar * added code to destroy the constraint window if it can't be grabbed (found by Pierre-Paul Lavoie) * removed unnecessary unmapping of windows before they were destroyed (found by Pierre-Paul Lavoie) * integrated changes from Pierre-Paul Lavoie (thaks ppl!): * the menurc path is now specified by a -D option on the compile line in the makefile instead of being a #define in the code * integrated more changes from David Lawrence Ramsey: * significant changes made to the ConfigureRequest event handler with the addition of refix_position() * crash in dump_clients() in DEBUG mode fixed 1.08 (2003-03-30) * integrated more changes from David Lawrence Ramsey: * the makefile now uses pkg-config (which XFree86 4.3.0 should include an entry for) to get the library and include directory information needed to compile properly (ported from aewm) * menufile.c changed to use XftTextExtents8() to get the proper width of text when Xft is used 1.07 (2003-03-30) * added title bar to the reshape window * small improvements made to manage.c 1.06 (2003-03-15) * added visual hint when a button is depressed * integrated changes from David Lawrence Ramsey (thanks!): * some focussing problems fixed * GTK resizing bug handled * iconified windows now handled properly * misc small fixes 1.05 (2003-02-27) * gave menu its own colours * many changes and fixes, especially to sweep() and helper functions in manage.c 1.04 (2003-02-18) * added menu system - this should be the last fundamental change to functionality 1.03 (2003-02-10) * fixed crash caused if the taskbar is clicked and no clients are present (found by lanzz) * changed resizing to use a window rather than inverting the background * many misc bug fixes * fixed a problem with xft/freetype (found by Michael Haller) 1.02 (2003-01-23) * new client window positioning algorithm altered so that it's more obvious to the user * small bug in find_client fixed 1.01 (2003-01-12) * some refactoring in events.c * added some missing event handling for the taskbar window (found by Pierre-Paul Lavoie) * made taskbar window update when a client window changes its title 1.00 (2002-12-26) * first public release *************************** * ORIGINAL AEWM CHANGELOG * *************************** 1.1.2: * Rewrote init_position again. This fixes the problem with specifying a USPosition containing 0. * Added gtk-menu client contributed by Adam Sampson . I want to fold this stuff into the rest of the goodies eventually. For now, just keep in mind that the extensions to .paletterc may change. * Added a "-version" option for printing version information from the command line. * Added some proper headers to all the files in goodies/lib/. * Replaced strcpy/strcat in panel-misc.c with snprintf to prevent a possible buffer overflow. * Made some improvements to the .paletterc parser: squish a possible segfault, handle comments/blank lines, ignore menu directives. * Reformatted man pages. 1.1.1: * Fix typo in man page install location. * Use -lXt when compiling Xaw goodies (required to build on SunOS). * Added some more documentation (mostly about things that are likely to break.) 1.1.0: * Xft (freetype extension) support, thanks once again to help from Adam Sampson . * A few Makefile improvements: only link against required libraries, easier enabling/disabling of options, don't attempt to compile against headers in the binary destination tree. * Yet more init_position tweaks -- use x position hint even if y is out of range and vice versa, and take window gravity into account when positioning. * Some additions and improvements to the debug code (mainly printing names of constants instead of cryptic numbers). 1.0.3: * Backport new init_position, -version option, new man pages, and panel-misc.c crasher/overflow fixes. 1.0.2: * Backport -lXt fix and new documentation. 1.0.1: * Fix remove_client so that it compiles with -DDEBUG turned on. 1.0.0: * All right, I think we're stable now. New stuff will go into 1.1.x. * Changed init_position so that it doesn't cut off very large windows. This was merely annoying for regular windows, but it was downright buggy for incsized ones. * Fixed compilation bug when shape support was disabled. 0.9.19: * OK, I broke command line parsing again. Yes, I'm an idiot. * Fixed problem with exec()-ing a non-existent program. 0.9.18: * Fixed bug in init_position; we can safely use PPosition now. If windows start popping up in bad places, check their size hints before yelling at me. * Use fork/exec instead of system(3) to run programs. Fixed signal handlers to reflect this (we need POSIX sigaction(2)). * Cleaned up MWM hints/WM_SIZE hints code (they sort of match now), and only request the MWM atom at startup instead of for each call. * Started yet another goodies reorganization, and ended up reverting a lot of it. However what's changed should go a little ways towards cleaning things up. * Fix a build error where some goodies files that needed to be compiled against X were compiled without -I/use/X11R6/lib, failing on systems without a symlink from /usr/include/X11. * Tossed out historical 'iheight' junk in border calculation. 0.9.17: * Use ln -f to ignore overwriting previously installed manpage links. * If MWM hints are enabled, no-border windows will no longer get a border upon exiting. * The order of buttons in *-palette is no longer changed by title updates or unhiding windows. * xaw-palette was fixed to work with proper versions of Xaw (shame on me for testing with Xaw3d!), including the one in XF4. The new internals have ported over to gtk-palette. 0.9.16: * Fixed a shaping bug (which actually existed before changes made in 0.9.15) where a window that used to be shaped, but then became unshaped, wasn't updated properly. * MWM hints support can now be compiled in with -DMWM_HINTS, thanks to help from Adam Sampson . * Set the input focus upon entering a window frame, instead of on entering the child window. 0.9.15: * Display a titlebar for shaped windows. This also makes the bug where shaped windows were getting gravitated as if they had a titlebar irrelevant. * Tiny cleanups for the Debian package, including: * Man page for the goodies. * Typo in makefile fixed (tried to strip manpage, ah-reer-reer-reer). * Polished the main man page a bit. 0.9.14: * Free cursors and GCs in quit_nicely. * Switch order of objects and libraries in Makefile to placate Solaris cc. * Rename raise to raise_win -- raise is in signal.h of course (duh!) * Added copyright notice to all goodies and Makefiles due to someone ignoring my license (this has been worked out). * Bail out on lack of default font. You *should* be reading aewm.h first of course ;-) 0.9.13: * Fix really stupid thing I did while refactoring make_new_client, where a window that started as Withdrawn would stay that way instead of getting mapped. * Deal with withdrawing clients properly in *-palette, by watching for the WM_STATE property to be changed instead of looking at UnmapNotify events. 0.9.12: * Clean up clients on receipt of a DestroyNotify. This is needed when a client is already unmapped (i.e, the user iconified it) and it exits. * Preserve window stacking order on exit and restart. * Mucked about with the make_new_client logic; tell me if this breaks something. * Added gtk-*-menu clients contributed by Adam Sampson . 0.9.11: * Got rid of unneeded PropertyChangeMask on root window. Silly me. * Removed the ugly array/linked-list hack from xaw-palette, so that the internal workings of both palette clients are now basically identical. * static'd everything that should have been static. * Updated email, documentation, etc. * Got rid of handle_reparent_event, as a client call to XReparentWindow is taken care of by handle_unmap_event. * Backed out the 0.9.9 change to option-parsing macros, which were causing all options to fail miserably (argh). 0.9.10: * Handle withdrawing windows properly in xaw-palette. Both palette clients are a little saner now. * Updated goodies docs. * ungravitate when printing geometry for move/resize. * Moved more code from individual goodies to common-run.c. * Got rid of unhide() as we never use it. * Replaced GenericWidget typedef silliness with global variables. sometimes you just have to pick the lesser of two evils... 0.9.9: * Finally de-insanified handle_xerror. Instead of going through contortions in remove_client to avoid raising errors, we turn the error handler off during the server grab. * Both palette goodies now track iconification of clients and WM_NAME changes. * gtk-palette is now oriented horizontally, and includes a menu, providing lots more space for client buttons. * Made the parse_option macros reusable (thanks to the comp.lang.c folks for the reminder). * make sure get_wm_name in the goodies doesn't crash for windows that have no name. * Minor typo corrections and stuff. 0.9.8: * Brown paper bag: take debugging stupidity out of gtk-palette. * Overhaul the goodies' build system yet again. * Gtk-palette now gets the screen size correctly. * All switch/palette goodies now cut off long titles, use WM_NAME instead of WM_ICON_NAME, and place iconified titles in parenthesis. * No changes to aewm itself in this release. 0.9.7: * Added lots of comments. * General code cleanups, tweaks, reformats all over. * Fixed iconic state problem. * Plugged a memory leak in send_wm_delete. * Added -new3. * Fixed -new[123] allocation bug. * Made debug code considerably saner. * Print "80x25" and such when resizing xterms. * Replaced sprintf with snprintf. * Got rid of -display. set DISPLAY in your environment instead, so that it propagates to child processes. * Messed around with the goodies' build system. * Fixed gtk-palette; events are now filtered properly at the GDK level. * Replaced variable length arrays with malloc/free. * Added xsession, since I've been using it forever. 0.9.6: * Fix for handling inital window geometry. * A few memory leaks plugged. * Wrote a man page * More consistent borders for transient windows. 0.9.5: * Print window geometry while moving/resizing. * Added some WM_NORMAL_HINTS sanity checks * Set the keyboard focus on window enter (for rxvt, etc). 0.9.4: * Root menu replaced by another client. * Added -bw option. * Border-drawing fixes (only visible if you have very wide borders). * Got rid of mouse button exit. 0.9.3: * Put the root menu code back in. * Added more goodies and reorganized them. 0.9.2: * Minor ICCCM compliance fix regarding WM_STATE. 0.9.1: * A small fix to make the palette complain if no rc file exists. 0.9: * Initial public release. Before this, aewm was called 'swim' and was used by me as a school project. It was also rather unstable.