Scwm: an Extensible Constraint-Enabled Window Manager
Total Page:16
File Type:pdf, Size:1020Kb
Scwm: An Extensible Constraint-Enabled Window Manager Greg J. Badros Jeffrey Nichols InfoSpace.com School of Computer Science, HCI Institute 2801 Alaskan Way, Suite 200 Carnegie Mellon University, 5000 Forbes Avenue Seattle, WA 98121, USA Pittsburgh, PA 15213, USA [email protected] [email protected] Alan Borning Dept. of Computer Science and Engineering University of Washington, Box 352350 Seattle, WA 98195-2350, USA [email protected] ABSTRACT Using C to implement a highly-interactive application We desired a platform for researching advanced win- also complicates extensibility and customizability. To dow layout paradigms including the use of constraints. add a new feature, the user likely must write C code, Typical window management systems are written en- recompile, relink, and restart the application before tirely in C or C++, complicating extensibility and pro- changes are finally available for testing and use. This grammability. Because no existing window manager was development cycle is especially problematic for software well-suited to our goal, we developed the Scwm window such as a window manager that generally is expected to manager. In Scwm, only the core window-management run for weeks at a time. Additionally, maintaining all primitives are written in C while the rest of the package the features that any user desires would result in terrible is implemented in its Guile/Scheme extension language. code bloat. This architecture, first seen in Emacs, enables program- An increasingly popular solution to these problems is ming substantial new features in Scheme and provides a the use of a scripting language on top of a core system solid infrastructure for constraint-based window layout that defines new domain-specific primitives. A prime research and other advanced capabilities such as voice example of this architecture is Richard Stallman’s GNU recognition. We have used Scwm to implement an in- Emacs text editor [40]. In the twenty years since the terface to the Cassowary constraint solving toolkit to introduction of Emacs, numerous extensible scripting permit end users to declaratively specify relationships languages have evolved including Tcl [34], Python [22], among window positions and sizes. The window man- Perl [42], and Guile [12, 37]. Each of the first three ager dynamically maintains those constraints and lets languages was designed from scratch with scripting in users view and modify them. Scwm succeeds in pro- mind. In contrast, Guile—the GNU Ubiquitous Intelli- viding an excellent implementation framework for our gent Language for Extension—takes a pre-existing lan- research and is practical enough that we rely on it ev- guage, Scheme, and adapts it for use as an extension eryday. language. KEYWORDS: constraints, Cassowary toolkit, Scheme, We are exploring constraint-based window layout Scwm, X/11 Window Manager paradigms and their user interfaces. Because we are most interested in practical use of constraints, we INTRODUCTION decided to target the X windows system and build We desired a platform for researching advanced window a complete window manager for X/11. We chose to layout paradigms including the use of constraints. Typi- use Guile/Scheme as the extension language for our Scwm cal window management applications for the X windows project that we named —the Scheme Constraints Scwm system are written entirely in a low-level systems lan- Window Manager. The most notable feature of guage such as C or C++. Because the X windows li- is constraint-based layout. Whereas typical window braries have a native C interface, using C is justified. management systems use only direct manipulation [38] Scwm However, a low-level language is far from ideal when of windows, also supports a user-interface for prototyping implementations of sophisticated window specifying constraints among windows that it then manager functionality. For our purposes, a higher-level maintains using our Cassowary Constraint solving language is much more appropriate, powerful, and sat- toolkit [1]. Much of the advanced functionality of Scwm isfying. is implemented in Scheme, thus exploiting the embedded-extension-language architecture. Embedded Constraint Solver Cassowary is a constraint solving toolkit that includes BACKGROUND support for arbitrary linear equalities and inequali- Scwm leverages numerous existing technologies to pro- ties [1]. Constraints may have varying strengths, and vide its infrastructure and support its advanced capa- constraint hierarchy theory [6] defines what constitutes bilities. a correct solution. We implemented the Cassowary toolkit in C++, Java, and Smalltalk, and created a X Windows and fvwm2 wrapper of the C++ implementation for Guile/Scheme. A fundamental design decision for the X windows sys- Thus, it is straightforward to use the constraint solver tem [33] was to permit an arbitrary user-level program in a broad range of target applications. to manage the various application windows. This open In addition, the Cassowary toolkit permits numerous architecture permits great flexibility in the way windows hooks for extension. Each constraint variable has an look and behave. optional attached object, and the constraint solver can X window managers are complex applications. They be instructed to invoke a callback upon changing the are responsible for decorating top-level application win- value assigned to any variable and also upon completion dows (e.g., drawing labelled titlebars), permitting resiz- of the re-solve phase (i.e., after all variable assignments ing and moving of windows, iconifying, tiling, cascading are completed). Scwm exploits these facilities to isolate windows, and much more. Many Xlib library functions the impact of the constraint solver on existing code. wrapping the X protocol are specific to the special needs CONSTRAINTS FOR LAYOUT of window managers. Because our goal is to do interest- Ordinary window managers permit only direct-manip- ing research beyond that of modern window managers, ulation as a means of laying out their windows. Al- we used an existing popular window manager, fvwm2,as though this technique is useful, a constraint-based ap- our starting point [13]. In 1997 when the first author be- proach provides a more dynamic and expressive system. Scwm gan the project with Maciej Stachowiak, fvwm2 In Scwm, we use the Cassowary constraint solving tool- was arguably the most used window manager in the X kit. On top of the primitive equation-solving capabilities windows community. It supports flexible configuration of Cassowary, Scwm adds a graphical user interface that capabilities via a per-user .fvwm2rc file that is loaded employs an object-oriented design. We specify numer- once when fvwm2 starts. To tweak parameters, end- ous constraint classes representing kinds of constraint users edit their .fvwm2rc files using an ordinary text relationships, and instances of each class are added to editor, save the changes, then restart the window man- the system for maintaining relationships among actual ager to activate the changes. The fvwm2 configuration windows. The interface allows users to create constraint language supports a very restricted form of functional objects, to manage constraint instances, and to create abstraction, but lacks loops and conditionals. new constraint classes from existing classes by demon- Despite these shortcomings, fvwm2 provides a good stration. amount of control over the look of windows. It also has Applying Constraints evolved over the years to meet complex specifications Applying constraints to windows is done using a tool- (e.g., the Interclient Communication Conventions bar. Each constraint class in the system is represented Manual [36]) and to deal with innumerable quirks by a button on the toolbar (figure 1). The user ap- of applications. By our basing Scwm on ,we fvwm2 plies a constraint by clicking a button, then selecting leveraged those capabilities and ensured that Scwm the windows to be constrained. Alternatively, the user was at least as well-behaved as . Our fundamental fvwm2 can first highlight the windows to be constrained and change to was to replace its ad-hoc configuration fvwm2 then click the appropriate button. Icons and tooltips language with Guile/Scheme [12]. with descriptive text assist the user in understanding Scheme for Extensibility what each constraint does. We consulted with a graphic artist on the design of our icons in an effort to make Guile [12] is the GNU project’s R4RS-compliant Scheme them intuitive and attractive. Preliminary user studies [9] system designed specifically for use as an embedded have demonstrated that users can determine the repre- interpreter. Scheme is a very simple, elegant dialect of sented relationship reasonably well from the icons even the long-popular Lisp programming language. It is easy without the supporting tooltip text. to learn and provides exceptionally powerful abstraction capabilities including higher-order functions, lexically- We provide the following constraint classes in our sys- scoped closures and a hygienic macro system. Guile ex- tem. Many interesting relationships are either present tends the standard Scheme language with a module sys- or can be created by combining classes in the list. tem and numerous wrappers for system libraries (e.g., POSIX file operations). Constant Height/Width Sum Keep the total of the 2 Figure 1: Our constraint toolbar. The text describes the constraint classes in the same order as they are laid out in the toolbar (from left to right). height/width of two windows constant. NW NNE 013 Horizontal/Vertical Separation Keep one window always to the left of or above another. WCE 345 Strict Relative Position Maintain the relative posi- tions of two windows. SWSSE 678 Vertical/Horizontal Maximum Size Keep height/ width of a window below a threshold. Figure 2: The nine nonants of a window. Vertical/Horizontal Minimum Size Keep height/ width of a window above a threshold. window and how that window will interact with other windows. Our constraint investigation interface allows Vertical/Horizontal Relative Size Keep the for all of these kinds of interactions. change in heights/widths of two windows constant (i.e., resize them by the same amount, together).