\input texinfo  @c -*-Texinfo-*-
@setfilename sawfish.info
@settitle sawfish Programming Manual
@footnotestyle end

@set EDITION 0.14
@set VERSION 1.5.0
@set UPDATED 02 Apr 2009
@set UPDATE-MONTH Apr 2009

@ifinfo
@direntry
* sawfish: (sawfish).		sawfish programming manual
@end direntry

This is Edition @value{EDITION}, last updated @value{UPDATED}, of
@cite{The sawfish Programming Manual}, for sawfish, Version
@value{VERSION}.

Copyright 1999 John Harper.

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
@end ignore

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
@end ifinfo

@titlepage
@title sawfish
@subtitle An Extensible X11 Window Manager
@subtitle Programming Manual
@subtitle Edition @value{EDITION}
@subtitle @value{UPDATE-MONTH}
@author John Harper
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1999 John Harper.

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
@end titlepage

@node Top, Copying, (dir), (dir)

@ifnottex
This document describes the Lisp programming interface to
@code{sawfish}, an extensible X11 window manager.

This is Edition @value{EDITION} of its documentation,
last updated @value{UPDATED} for Sawfish version @value{VERSION}.
@end ifnottex

@menu
* Copying::                     Distribution conditions
* Introduction::                Brief introduction to sawfish
* News::                        Feature history

* Colors::			Color type
* Fonts::			Font type
* Images::			Image type
* Cursors::			Cursor type
* Windows::			Window type
* Customization::		Supporting user-configuration

* Window Frames::		Decorating windows
* Viewports::			Subdivided desktop areas
* Workspaces::			Multiple desktop areas
* Multi-Head Environments::     Multiple monitors
* Window Placement::            Controlling placement of new windows
* Popup Menus::			Displaying menus
* Events::			Input event types
* Commands::			Functions you can invoke interactively
* Keymaps::			Bindings events to actions
* Event Loop::			Handling input events
* Miscellaneous Functions::	Useful features
* Standard Hooks::		Hooking into wm actions
* Standard Properties::		Window properties
* Session Management::		Saving state across sessions
* Low-level X Interface::       Accessing the server directly

* FAQ::				Frequently asked questions

* Function Index::              Menu of all documented functions
* Variable Index::              All variables which have been mentioned
* Concept Index::               Main index, references to all sections
@end menu

@node Copying, Introduction, Top, Top
@chapter Copying
@cindex Copying

Sawfish is copyright (C) 1999 John Harper and is released under the
terms of the GNU General Public License. See the included file
@file{COPYING} for the full text of the license (or @pxref{Copying, ,
Copying, emacs, The GNU Emacs Manual}).

@quotation
This is free software -- you are welcome to 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, or
(at your option) any later version.

Sawfish 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.
@end quotation


@node Introduction, News, Copying, Top
@chapter Introduction
@cindex Introduction

Sawfish is a lisp-extensible window manager for X11. Its aim is to
allow all areas of window management (decoration, manipulation) to be
customized as far as is possible, yet still remain as fast or faster
than existing window managers.

Despite this extensibility its policy is very minimal compared to most
window managers. It does not implement desktop backgrounds,
applications docks, or other things that may be achieved through
separate applications.

All high-level window management functions are implemented in Lisp for
future extensibility or redefinition. Also, most received events are
exported to the Lisp environment through key-bindings and hooks,
similar to in Emacs. These events include pointer behavior and many
internal X11 events.

Sawfish uses the librep Lisp environment (@pxref{Top, , Overview,
librep, The Librep Manual}), this is a run-time library implementing a
language similar to Emacs Lisp (@pxref{Top, , Overview, elisp, The
Emacs-Lisp Manual}), but with many extensions, and using lexical
instead of dynamic scope. This manual assumes at least a basic
knowledge of the language.

Homepage and mailing list are listed in @xref{FAQ}.

@node News, Colors, Introduction, Top

@include news.texi


@node Colors, Fonts, News, Top
@chapter Colors
@cindex Colors

Sawfish provides a primitive type allowing colors to be represented.
Each color object allows a single color value to be named and passed
between Lisp functions.

@defun colorp arg
Returns @code{t} when @var{arg} is a member of the color type.
@end defun

@defun get-color name &optional alpha
Returns the color object representing the color specified by the string
@var{name}. This is according to the standard X11 color specifiers,
either a named color from the @file{rgb.txt} database, or a string
defining the red, green and blue components of the color, either eight
or sixteen bits in hexadecimal, i.e. @samp{#RRGGBB} or
@samp{#RRRRGGGGBBBB}.

Optional argument @var{alpha} becomes the alpha value of
the returned color.  It is passed through to @code{get-color-rgb}.

Signals an error if no known color has the name @var{name}.
@end defun

@defun get-color-rgb red green blue &optional alpha
Return the color object representing the color with RGB components as
specified (each component ranging from 0 to 65535).

Optional argument @var{alpha} becomes the alpha value of the returned
color.  Use an integer value in the range from 0 to 65535.  Integers
outside that range are not supported, while non-integers such as
@code{nil} are silently converted to 65535 (fully opaque).
@end defun

Given a color object, it's possible to find both the actual rgb values
defining the color and one of the names that X11 uses to refer to the
color.

@defun color-rgb color
Return a list of integers @code{(@var{red} @var{green} @var{blue}
@var{alpha})}, the actual color values of the color represented by
object COLOR.  The individual values range from 0 to 65535.
@end defun

@defun color-rgb-8 color
Return a list of integers @code{(@var{red} @var{green} @var{blue}
@var{alpha})}, just like @code{color-rgb}.  However, the color values
are scaled to fit a range from from 0 to 255.
@end defun

@defun color-name color
Return the name of the color represented by the color object
@var{color}.  Note that this picks one name from the set of valid
names for this color; it may well be different to the name used when
the color was originally allocated.

The X11 name does not include alpha information.
@end defun

Where a color object is used to define the foreground color of a piece
of text, the @code{default-foreground} color provides the default value
used if no actual color is specified.

@defvar default-foreground
The color used for text where no other color is defined.
@end defvar


@node Fonts, Images, Colors, Top
@chapter Fonts
@cindex Fonts

As with the color type, the font type allows X11 fonts to be
manipulated by Lisp code.

@defun fontp arg
Returns @code{t} if @var{arg} is a font object.
@end defun

Sawfish supports two types of fonts: X11 core fonts (fontsets and
fontstructs) and Xft fonts.  Calling code must look up fonts by
giving both a name and a type: an @code{xlfd} argument indicates the
core fonts, and @code{Xft} indicates Xft fonts.  These types are
always literal strings.

@defun font-type-exists-p type
Returns true if fonts with the type described by the string @var{type}
can be loaded, false otherwise.
@end defun

@defun get-font-typed type name
Return a font object representing the X11 font specified by the string
@var{name}.  Argument @var{type} indicates the type of font to look
for; it must be one of the strings @code{xlfd} for a X11 core fonts
(based on fontsets or a fontstructs), or @code{Xft} for an Xft font.

Signals an error if @var{type} is not one of the literal strings
listed above.  Also signals an error if no font named @var{name}
can be found within the requested type.
@end defun

@defun get-font name
Return a font object representing the X11 core font (fontset or
fontstruct) specified by the string @var{name}.

Signals an error if no font named @var{name} is available among the
X11 core fonts.
@end defun

Several functions allow the attributes associated with a font object to
be found.

@defun font-name font
Returns the name of the X11 font represented by object @var{font} (a
string).
@end defun

@defun font-type font
Returns a string indicating the font's class.  This is @code{xlfd}
for X11 core fonts, or @code{Xft} for Xft fonts.
@end defun

@defun font-height font
Returns the bounding height of glyphs in the font represented by object
@var{font}.
@end defun

@defun font-ascent &optional font
Returns the ascent of glyphs rendered using the font represented by
@var{font}.  If no font argument is given, use the default font.
@end defun

@defun font-descent &optional font
Returns the descent of glyphs rendered using the font represented by
@var{font}.  If no font argument is given, use the default font.
@end defun

@defun text-width string &optional font
Returns the number of horizontal pixels that would be required to
display the text @var{string} using font object @var{font} (or the
value of the @code{default-font} variable if @var{font} is undefined).
@end defun

As with colors, a default font may be specified, to be used where no
other font is specified.

@defvar default-font
Font object used when no other font has been specified.
@end defvar

Fonts can have Lisp properties associated with them (similar to the
property lists associated with symbols). Currently these aren't
actually used by the window manager.

@defun font-put font property value
Associate the lisp object @var{value} with the property named by the
symbol @var{property} of the font object @var{font}.
@end defun

@defun font-get font property
Return the value of the property named by the symbol @var{property} of
the font @var{font}, or @code{nil} if no such property exists.
@end defun

@defvar fonts-are-fontsets
True if the X fonts in use are fontsets.  This will be false if
@code{setlocale} fails, or returns an ASCII locale, or if X doesn't
support the locale.
@end defvar


@node Images, Cursors, Fonts, Top
@chapter Images
@cindex Images

The image type allows arbitrary 24-bit images to be manipulated by the
window manager. Images may be both loaded from files, and rendered
dynamically.

@defun imagep arg
Returns @code{t} when @var{arg} is a member of the image type.
@end defun

@defun make-image file-name &optional plist
Creates and returns an image object containing the image defined by the
contents of the file named @var{file-name} (a string). The
@code{image-load-path} directory provides the search path used while
trying to find a directory containing the file named @var{file-name}.

All common image formats will likely be able to be loaded. But PNG,
JPEG and XPM should always be supported.

Argument @var{plist} becomes the property list of the returned image.

Signals an error if file called @var{file-name} may be found, or if an
image may not be constructed from the file.
@end defun

@defvar image-directory
Directory containing built-in Sawfish images.  By default, this is
@code{@var{sawfish-directory}/images}.
@end defvar

@defvar image-load-path
A list of directory names. This defines the search path used when
loading images.  By default, this is @code{("."
@var{image-directory})}.  Modifying @var{image-directory} does not
modify @var{image-load-path}.
@end defvar

@defun make-sized-image width height &optional color
Create and return a new image, of size @var{width},  @var{height}. If
@var{color} is defined it specifies the color of all pixels in the
image. If undefined, all pixels will be black.
@end defun

@defun make-image-from-x-drawable id &optional mask-id
Create and return an new image.  The image is constructed by copying
an X Drawable (identified by @var{id}) into a Sawfish image object.
The function automatically handles depth conversion.

If @var{mask-id} is given, it identifies another X Drawable.  Black
pixels in this drawable indicate transparent pixels in the image
object (non-black pixels have no effect on the image object).
@end defun

@defun copy-image image
Returns a newly allocated image object, an exact copy of the image
object @var{image}.
@end defun

@defun image-dimensions image
Returns a cons-cell @code{(@var{width} . @var{height})} defining the
dimensions of the image represented by @var{image}.
@end defun

@defun flip-image-horizontally image
Flip the contents of @var{image} about the vertical axis.
This is a mutating operation that returns the modified argument.
@end defun

@defun flip-image-vertically image
Flip the contents of @var{image} about the horizontal axis.
This is a mutating operation that returns the modified argument.
@end defun

@defun flip-image-diagonally image
Flip the contents of @var{image} about an axis running from the
top-left corner to the bottom-right corner of the image.
This is a mutating operation that returns the modified argument.
@end defun

As with many of the other types, arbitrary state may be associated with
image objects.

@defun image-put image property value
Set the property named @var{property} (a symbol) of @var{image} to
@var{value}.
@end defun

@defun image-get image property
Return the property named @var{property} of @var{image}, or @code{nil}
if no such property exists.
@end defun

The only predefined property is the symbol @code{tiled}, used when an
image is displayed in a window decoration. When set to a non-nil value
the image is not scaled to the size of the decoration (the default),
but is tiled across the decoration.

When images are scaled across border decorations the pixels that are
actually scaled are defined by the @dfn{border} of the image. The
border defines the outer rectangle of pixels that are left as-is, and
the inner rectangle which is scaled.

@defun image-border image
Returns a list of integers @code{(@var{left} @var{right} @var{top}
@var{bottom})}, the border of the image object @var{image}.

The number associated with each edge of the image defines the number of
pixels adjacent to that edge that @emph{will not} be scaled.
@end defun

@defun set-image-border image left right top bottom
Sets the border of @var{image}.

The number associated with each edge of the image defines the number of
pixels adjacent to that edge that @emph{will not} be scaled.
@end defun

The shape of the image may also be specified, this defines which pixels
are treated as being transparent. Each image may define a single color
as marking transparent pixels.

Image shapes are not supported under GDK Pixbuf.  Sawfish will
print a diagnostic message to @code{STDERR} if the function is called
without being supported.

@defun image-shape-color image
Return the color marking transparent pixels in @var{image}, or
@code{nil} if no such color has been specified.
@end defun

@defun set-image-shape-color image color
Specify that @var{color} marks transparent pixels in @var{image}.
@end defun

It's also possible to define @dfn{color modifiers} for each image.
These define the transformation applied to the value of each pixel when
it is displayed. Four different modifiers exist for each image, one for
each color component, and one for the image as a whole.

@defun image-modifier image type
Return the modifier defined by the symbol @var{type} of @var{image}, a
list of integers @code{(@var{gamma} @var{brightness} @var{contrast})}.
Each integer has a value between zero and 255 representing the weight
applied to the associated attribute when rendering the image.

The four types are @code{red}, @code{green}, @code{blue} and @code{nil}
(all colors).  The argument must be @code{eq} to one of those symbols.
@end defun

@defun set-image-modifier image type gamma brightness contrast
Set the image modifier of @var{image} defined by @var{type}.
@var{Type} may be one of the values of (not the symbols) @code{red},
@code{green} or @code{blue}.
@end defun

There are also several other functions manipulating images:

@defun bevel-image image border upwards &optional bevel-percent
Transform the edgemost pixels of @var{image} to give it a ``bevelled''
effect. @var{BORDER} is an integer defining the width of the bevel. If
@var{upwards} is non-nil the bevel is raised, otherwise it is lowered.

If @var{bevel-percent} is defined it specifies the height or depth of
the drawn bevel. When undefined, the value of the parameter is taken
from the @code{default-bevel-percent} variable.
@end defun

@defvar default-bevel-percent
Default height of drawn bevels, as a percentage.  Normally 50%.
@end defvar

@defun clear-image image &optional color
Set all pixels in @var{image} to @var{color} (or black if @var{color}
is undefined).
@end defun

@defun tile-image dest-image source-image
Tiles @var{source-image} into @var{dest-image}, starting from the
upper-left corner, working outwards.
@end defun

@defun scale-image image width height
Return a copy of @var{image}, scaled to @var{width} by @var{height}
pixels.
@end defun

@defun composite-images image1 image2 &optional x y
Copy the contents of @var{image2} into @var{image1}.  @var{Image2} is
cropped to fit.  Arguments @var{x} and @var{y} indicate the position
in @var{image1} of the top-left corner of @var{image2}.  If not
supplied, they default to 0.
@end defun

@defun crop-image image x y width height
Return a new image that is a rectangular section of @var{image}.  The
result image starts at pixel (@var{x}, @var{y}) in @var{image}, and
extends over @var{width} and @var{height} pixels in @var{image}.

When the cropped image extends beyond the boundary of @var{image}, the
behavior is undefined.
@end defun

The following functions allow users to manipulate images on a
pixel-by-pixel level.  They all use a list representation for pixels:
(@var{r}, @var{g}, @var{b}, @var{a}) indicating the red, green, blue
and alpha components

@defun image-ref image x y
Return a list (@var{r}, @var{g}, @var{b}, @var{a}) of the red, green,
blue and alpha components of the pixel (@var{x}, @var{y}) in
@var{image}.

When the pixel position extends outside the bounds of the image, the
behavior is undefined.
@end defun

@defun image-set image x y pixel
Set the pixel at (@var{x}, @var{y}) in @var{image} to @var{pixel}.
@var{Pixel} is a list of four numbers (@var{r}, @var{g}, @var{b},
@var{a}), the red, green, blue and alpha components.

When the pixel position extends outside the bounds of the image, the
behavior is undefined.
@end defun

@defun image-map xform image
Transform each pixel in @var{image} in place by calling @var{xform} on
each pixel in the image.

@var{Xform} takes a single argument, a four element list (@var{r},
@var{g}, @var{b}, @var{a}) indicating the red, green, blue and alpha
components of a pixel.  @var{Xform} should return the new value for
the pixel it was given.  The return format is the same four-element
list.

@var{Xform} is allowed to return @code{nil}.  In this case,
@code{image-map} immediately returns an invalid object.
@end defun

@defun image-fill generator image
Set each pixel in @var{image} based on the results of calling
@var{generator}.

@var{Generator} takes two arguments: the X and Y coordinates of a
pixel.  It returns a four element list (@var{r}, @var{g}, @var{b},
@var{a}) indicating the red, green, blue and alpha components of a
pixel.  This new pixel replaces the current pixel contents at (X, Y).

@var{Generator} is allowed to return @code{nil}.  In this case,
@code{image-map} immediately returns an invalid object.
@end defun

@defun pixmap-cache-control max
Tell Sawfish to cache no more than @var{max} pixels.  Returns a
four-element list indicating the current cache status:
@code{(@var{max-cached-pixels}, @var{cached-pixels}, @var{hits},
@var{misses})}.
@end defun


@node Cursors, Windows, Images, Top
@chapter Cursors
@cindex Cursors

Cursors define the shape and hot-spot of the mouse pointer's image.  A
lisp type is provided for manipulating these objects.  In addition,
Sawfish provides functions for manipulating the position of the
cursor.

@menu
* Cursor Appearance::
* Cursor Positioning::
@end menu

@node Cursor Appearance, Cursor Positioning, Cursors, Cursors
@section Cursor Appearance

@defun cursorp arg
Returns @code{t} if @var{arg} is a member of the cursor type.
@end defun

@defun get-cursor data
Returns the cursor object representing the cursor defined by
@var{data}. If @var{data} is a symbol, it's replaced by its
@code{cursor-shape} property.

Possible @var{data} values are an integer representing a glyph in the
standard X11 cursor font, or a four-element vector.

The format for a vector is @code{[@var{image} @var{mask} @var{fg}
@var{bg}]} where @var{image} and @var{mask} are the filenames of
standard X11 bitmaps, and @var{fg} and @var{bg} are colors (or names of
colors). All bitmap files are searched for using the
@code{image-load-path} variable.
@end defun

@defun recolor-cursor cursor fg bg
Change the colors of the cursor object @var{cursor} to @var{fg} and
@var{bg} (either color objects or the names of colors).
@end defun

@defun default-cursor &optional cursor
Set the cursor object displayed in the root window, and in parts of
window frames that have no other cursor specified, to @var{cursor}.

If called with no argument, simply return the current such cursor
object.
@end defun

So that the integer indices of glyphs in the X11 cursor font do not
have to be remembered, the @code{cursor-shape} properties of the
following symbols are automatically set:

@noindent
@code{X_cursor}, @code{arrow}, @code{based_arrow_down},
@code{based_arrow_up}, @code{boat}, @code{bogosity},
@code{bottom_left_corner}, @code{bottom_right_corner},
@code{bottom_side}, @code{bottom_tee}, @code{box_spiral},
@code{center_ptr}, @code{circle}, @code{clock}, @code{coffee_mug},
@code{cross}, @code{cross_reverse}, @code{crosshair},
@code{diamond_cross}, @code{dot}, @code{dotbox}, @code{double_arrow},
@code{draft_large}, @code{draft_small}, @code{draped_box},
@code{exchange}, @code{fleur}, @code{gobbler}, @code{gumby},
@code{hand1}, @code{hand2}, @code{heart}, @code{icon},
@code{iron_cross}, @code{left_ptr}, @code{left_side}, @code{left_tee},
@code{leftbutton}, @code{ll_angle}, @code{lr_angle}, @code{man},
@code{middlebutton}, @code{mouse}, @code{pencil}, @code{pirate},
@code{plus}, @code{question_arrow}, @code{right_ptr},
@code{right_side}, @code{right_tee}, @code{rightbutton},
@code{rtl_logo}, @code{sailboat}, @code{sb_down_arrow},
@code{sb_h_double_arrow}, @code{sb_left_arrow}, @code{sb_right_arrow},
@code{sb_up_arrow}, @code{sb_v_double_arrow}, @code{shuttle},
@code{sizing}, @code{spider}, @code{spraycan}, @code{star},
@code{target}, @code{tcross}, @code{top_left_arrow},
@code{top_left_corner}, @code{top_right_corner}, @code{top_side},
@code{top_tee}, @code{trek}, @code{ul_angle}, @code{umbrella},
@code{ur_angle}, @code{watch}, @code{xterm}.

The glyphs associated with these names are shown in Appendix I, of
Volume Two, @cite{Xlib Reference Manual}.

@node Cursor Positioning,  , Cursor Appearance, Cursors
@section Cursor Positioning

Sawfish provides one basic command for adjusting the relative position
of the cursor.

@defun move-cursor right down
Move the cursor @var{right} pixels to the right across the screen, and
@var{down} pixels down the screen.  The cursor stops at the edge of
the screen (although in multi-head environments, this may not be at
the edge of the display).
@end defun

There are also more specialized cursor movement commands.

@defun move-cursor-left-fine
@defunx move-cursor-right-fine
@defunx move-cursor-up-fine
@defunx move-cursor-down-fine
Move the cursor 1 pixel in the indicated direction.
@end defun

@defun move-cursor-left
@defunx move-cursor-right
@defunx move-cursor-up
@defunx move-cursor-down
Move the cursor @code{move-cursor-increment} pixels in the indicated
direction.
@end defun

@defvar move-cursor-increment 16
The @code{move-cursor-@var{DIRECTION}} functions move this cursor this
many pixels at a time.
@end defvar

@node Windows, Customization, Cursors, Top
@chapter Windows
@cindex Windows

One of the most important data types in sawfish is the window type. All
managed client windows have a single window object associated with
them.

@defun windowp arg
Returns @code{t} if @var{arg} is a member of the window type, and has a
client window associated with it.
@end defun

@defun managed-windows
Returns a list containing all managed window objects, in the order that
they were adopted by the window manager (first to last).
@end defun

@defun get-window-by-id xid
Return a window object with id @var{xid}, or @code{nil}.
@end defun

@defun get-window-by-name name
Return a window object with name @var{name}, or @code{nil}.
@end defun

@defun get-window-by-name-re name
Return a window object with name matching regular expression
@var{name}, or @code{nil}.
@end defun

@defun activate-window window
Do everything necessary to make @var{window} active, including raising
it, giving it focus, etc.  Certain steps may be skipped (e.g., giving
focus) if the window doesn't allow that operation.
@end defun

@defun filter-windows pred
Return the list of windows (mapped or unmapped) that match the
predicate function @var{pred}.
@end defun

@defun map-windows function
Call @code{(@var{function} @var{window})} on all existing windows.
Returns the value of the last @var{function} invocation.  If any
@var{function} returns @code{nil}, @code{map-windows} returns
@code{nil} immediately.
@end defun

@defun window-class window
Return the class that @var{window} belongs to as a string, or nil if
@var{window} has no associated class.
@end defun

@defun get-window-wm-protocols window
Return a list of symbols defining the X11 window manager protocols
supported by client @var{window}.
@end defun
@defun window-supports-wm-protocol-p window atom
Return true if @var{window} includes @var{atom} in its
@code{WM_PROTOCOLS} property.
@end defun

@menu
* Window Property Lists::
* Window Types::
* Window Attributes::
* Input Focus::
* X Properties::
* Window Stacking::
* Moving and Resizing Windows::
* Showing and Hiding Windows::
* Destroying Windows::
* Shading Windows::
* Iconifying Windows::
* Window Stickiness::
* Ignored Windows::
* Avoided Windows::
* Maximizing Windows::
* Animating Windows::
* Cycling Between Windows::
* Window Groups::
@end menu


@node Window Property Lists, Window Types, , Windows
@section Window Property Lists
@cindex  Window property lists
@cindex Property lists, of windows

Many window manager extensions need to be able to associate Lisp data
with individual windows. For example, the module handling iconification
needs to associate a boolean value with each window---whether that
window is iconified or not.

To solve this problem, Sawfish gives each window a property list. These
are exactly analogous to the property lists stored with each symbol
(@pxref{Property Lists, , Property Lists, librep, The Librep Manual});
they allow values to be associated with Lisp symbols, for a particular
window.

Note that these properties are different to the properties that X
stores with each window, since these properties are internal to the
window manager (@pxref{X Properties}).

For a list of the standard window properties, see @ref{Standard Properties}.

@defun window-put window property value
Set the lisp property named @var{property} (a symbol) associated with
window object @var{window} to @var{value}.  Note that these are Lisp
properties not X properties.
@end defun

@defun window-get window property &optional checker
Return the window property named @var{property} (a symbol) associated
with the window object @var{window}, or @code{nil} if no such property
exists.  Note that these are Lisp properties not X properties.

If the optional third argument @var{checker} is non-nil, then @var{checker}
is returned if the requested property does not exist. This is used to
distinguish the assigned value of @code{nil} from property's absence.
A symbol is usually a good choice for @var{checker}.
@end defun

@defun map-window-properties function window
Call @code{(@var{function} @var{property} @var{value})} on each of the
Lisp properties bound to @var{window}.  Returns the value of the last
@var{function} invocation.  If any @var{function} returns @code{nil},
@code{map-window-properties} returns @code{nil} immediately.
@end defun

@defun window-plist window
Returns the property list of the window @var{window} which is of the form
@code{(prop value prop value ...)}. 

Do not attempt to change properties by modifying the property list in place.
Use window-put instead.
@end defun

@defun window-remprop window property
Remove @var{property} of @var{window}. Returns @code{t} for success,
@code{nil} if the property did not exist.
@end defun

@node Window Types, Window Attributes, Window Property Lists, Windows
@section Window Types
@cindex Window types
@cindex Types, of windows
@cindex Windows, types of

Transient windows are pop-up or dialog windows associated with a main
application.  They tend to have less window decorations, and are
intended to last a short time only.

@defun window-transient-p arg
Returns @code{t} if @var{arg} represents a transient window.
@end defun

@defun mark-window-as-transient w
Mark that the window associated with object @var{w} is a transient
window.
@end defun

@defun transient-of-p child parent
Return true if window @var{child} is directly a transient for window
@var{parent}, false otherwise.
@end defun

@defun indirect-transient-of-p descendant ancestor
Return true if window @var{descendant} is (directly or indirectly) a
transient for window @var{ancestor}, false otherwise.
@end defun

@defun transient-parents child &optional indirectly
Return the list of windows that window @var{child} is a transient
for.  If @var{indirectly} is true, then return the list of all
ancestors rather than parents.
@end defun 

@defun transient-children parent &optional indirectly
Return the list of windows that are transients for window
@var{parent}.  If @var{indirectly} is true, then return the list of
all descendants rather than children.
@end defun

@defun transient-group window &optional by-depth
Return the list of windows which is either a transient window for
window @var{window}, or a window which @var{window} is a transient
for.  This always includes W.  The `transient window for' relation holds
for windows which are direct or indirect transients of the parent
window in question.

If the @var{by-depth} argument is true, then the retrurned list is in
stacking order.
@end defun

@defun map-transient-group fun window
Map the single argument function @var{fun} over all windows in the same
transient group as window @var{window}.
@end defun

@defun raise-window-and-transients window
Raise window @var{window} to its highest allowed position in the
stacking order.  Also raise any transient windows that it has.
@end defun

@defun lower-window-and-transients window
Lower window @var{window} to its lowest allowed position in the
stacking order.  Also lower any transient windows that it has.
@end defun

@defun raise-lower-window-and-transients window
If window @var{window} is at its highest possible position, then lower
it to its lowest possible position.  Otherwise raise it as far as
allowed.  Also changes the level of any transient windows it has.
@end defun

@defvr Customizable focus-windows-when-mapped
Focus on application windows when they first appear.  Defaults to
true, must be true or false.
@end defvr

@defvar decorate-transients
Decorate dialog windows similarly to application windows.  Defaults to
false.
@end defvar

Desktop windows are root windows or viewport windows.

@defun desktop-window-p arg
Returns @code{t} if @var{arg} represents a desktop window.
@end defun

@defun mark-window-as-desktop w
Mark that the window associated with object @var{w} is a desktop
window.
@end defun

@defvar desktop-window-properties
List of properties set (to true) on windows marked as desktops.
Defaults to
@lisp
'(fixed-position sticky sticky-viewport)
@end lisp
@end defvar

@defvar desktop-window-depth
The stacking depth of desktop windows.  Defaults to -4.
@end defvar

Dock windows are simply those with the @code{dock-type} property.
GNOME panels are one example.  Sawfish does not currently assign them
any special behavior.

@defun dock-window-p arg
Returns @code{t} if @var{arg} represents a dock window.
@end defun

@defun mark-window-as-dock w
Mark that the window associated with object @var{w} is a dock
window.
@end defun

@defvar dock-window-properties
List of properties set (to true) on windows marked as docks.
Defaults to
@lisp
'(window-list-skip cycle-skip fixed-position focus-click-through
  avoid no-history never-iconify never-maximize sticky
  sticky-viewport placed)
@end lisp
@end defvar

@defvar dock-window-depth
The stacking depth of dock windows.  Defaults to 0.
@end defvar

@node Window Attributes, Input Focus, Window Types, Windows
@section Window Attributes
@cindex Window attributes
@cindex Attributes, of windows
@cindex Windows, attributes of

@defun window-name window
Return the name associated with @var{window}.
@end defun

@defun window-full-name window
Return the full-name associated with @var{window}. This may or may not
be the same as the normal name.
@end defun

Sawfish provides functions to ensure that window names are unique.

@defun uniquify-name proposal existing
Uniquify the string @var{proposal} against the list of strings
@var{existing}.  Uses the format string @code{uniquify-name-format} to
generate unique names.
@end defun

@defvar uniquify-name-format
Format to create unique window names.  Defaults to @code{"%s [%d]"}.
@end defvar

@deffn Function uniquify-window-name window
@deffnx Command uniquify-window-name window
Force @var{window} to have a unique title.
@end deffn

@defun window-icon-name window
Return the icon name associated with @var{window}.
@end defun

@defun window-mapped-p window
Return @code{t} if the client window associated with object
@var{window} is mapped. (Note that this doesn't necessarily mean that
it is visible.)
@end defun

@defun window-transient-p window
Returns @code{nil} if @var{window} isn't marked as a transient window.
Otherwise returns an integer, the xid of the parent window.
@end defun

@defun window-shaped-p window
Return @code{t} if @var{window} is shaped (possibly not rectangular).
@end defun

@defun window-id window
If window object @var{window} has a client window associated with,
return an integer defining its xid, otherwise return @code{nil}.
@end defun

@defun root-window-id
Returns the numeric ID of the root window of the managed screen.
@end defun

@defun window-group-id window
If @var{window} is part of a group, return the X window id of the
leader of that group.  Otherwise return @code{nil}.
@end defun

@defun window-wants-input-p window
Return @code{t} when the client window associated with object
@var{window} has asked for the input focus to be assigned to it when
applicable (through the @code{input} field of its @code{WM_HINTS}
property).
@end defun

@defun window-really-wants-input-p window
Return @code{nil} if the client window associated with object
@var{window} should never be focused, @code{t} otherwise.
@end defun

@defun window-dimensions window
Returns a cons cell @code{(@var{width} . @var{height})} defining the
dimensions of the client window associated with object @var{window}.
@end defun

@defun window-position window
Returns a cons-cell @code{(@var{x} . @var{y})} defining the position
relative to the root window of @var{window}.
@end defun

@defun window-size-hints window
Return an alist defining the size-hints structure specified by the
client window associated with @var{window}. Possible keys in the alist
are @code{min-height}, @code{max-height}, @code{min-width},
@code{max-width}, @code{height-inc}, @code{width-inc},
@code{min-aspect}, @code{max-aspect}, @code{base-height},
@code{base-width}, @code{user-position}, @code{program-position},
@code{user-size}, @code{program-size}, @code{window-gravity},
@code{border-size}.
@end defun

@defun stacking-visibility window
Returns @code{unobscured} if @code{window} is unobscured,
@code{fully-obscured} if one or more windows completely obscure
@code{window}, or @code{partially-obscured} if one or more window
partially obscure @code{window}.

Deciding between fully and partially obscured can be expensive.  If
@code{window-obscured} satisfies your needs, use that in preference to
@code{stacking-visibility}.
@end defun

@defun window-obscured window
Returns @code{nil} if @code{window} is unobscured, @code{t} if
@code{window} is completely obscured by exactly one other window, or a
list of windows that partially obscure @code{window}.

If a list of partially obscuring windows is returned, taken together
they may or may not fully obscure @code{window}.
@end defun

@deffn {Obsolete Function} window-visibility window
Returns a symbol defining the current visibility of @var{window}.
Possible returned symbols are @code{fully-obscured},
@code{partially-obscured} or @code{unobscured}.

@code{window-visibility} is deprecated.  It is unreliable when using
the Composite extention, as every window is reported unobscured.  Use
@code{window-obscured} and @code{stacking-visibility} instead.
@end deffn

@defun window-urgent-p window
Return @code{t} if the ``Urgency'' hint of the window associated with
@var{window} is set.
@end defun


@node Input Focus, X Properties, Window Attributes, Windows
@section Input Focus
@cindex Input focus
@cindex Keyboard focus
@cindex Focus, input
@cindex Windows, input focus

The input focus defines exactly which client window will receive events
generated by the keyboard.

@defun input-focus
Returns the window object of the currently focused window, or
@code{nil} if no window is focused.
@end defun

@defun set-input-focus window
Sets the focus to the client window associated with @var{window}.

If @var{window} is @code{nil}, then no window will have the focus.
@end defun

The window manager is responsible for switching the input focus from
client window to client window.  Sawfish implements several
@dfn{focus modes} that provide this behavior.  Each focus mode is
bound to a symbol; the implementation is bound to that symbol's
@code{focus-mode} property slot.

@defvar focus-mode
Defines the current method of using the mouse to assign the input
focus.  This is a symbol from the list @code{focus-modes}.
@end defvar

@defvar focus-modes
A list containing all names of focus modes.  The built-in values are
@code{enter-exit}, @code{enter-only}, @code{enter-click} and @code{click}.
@end defvar

Focus mode @code{enter-exit} changes focus when the pointer enters a
window or leaves the focused window.  Focus mode @code{enter-only}
changes focus when the pointer enters a window, but not when it leaves
the focused window.  Focus mode @code{click} changes focus when you
click on a window.  Focus mode @code{enter-click} is the union of
@code{enter-only} and @code{click}, and changes focus on any
of their conditions.

It is possible to add additional focus modes by defining your own
handler function.  The handler function must obey a
``focus-mode-handler'' protocol.

@deftp {Function Protocol} focus-mode-handler window event-name &optional args
A function that implements the @code{focus-mode-handler} protocol can
be used to define a focus mode.  A @code{focus-mode-handler} responds
to events associated with windows.

Argument @var{window} is the window that received this event.

Argument @var{event-name} is one of the following symbols:

@table @code
@item pointer-in
@itemx pointer-out
The pointer has entered or exited the window.  The handler is
responsible for checking whether an entered window wants input events.
The desktop never receives @code{pointer-in} or @code{pointer-out};
only normal windows do.

@item
@item enter-root
@itemx leave-root
The pointer has entered or exited the desktop (which is the
@var{window} argument).  Normal windows never receive
@code{enter-root} or @code{leave-root}.

@item focus-in
@itemx focus-out
The window argument has gotten or lost focus.  Note that the
@code{focus-in} handler is not responsible for updating the
window-order list.

@item before-mode-change
@itemx after-mode-change
Sawfish sends these synthetic events to each window before/after
changing that window's focus mode.  When the global focus mode
changes, all windows get these events.

@item add-window
Sawfish sends this event to every window immediately after mapping it.
Handlers can use this to initialize window-internal data structures.

@item warp-if-necessary
Warp the cursor to the window if doing so would make the cursor
position ``consistent'' with the focus mode.  For example, in
@code{enter-exit} mode we warp the cursor if it is not already in this
window.  In @code{enter-only} mode, we warp the cursor if it is in
another window, but not if it is over the desktop---a window would not
lose focus when the cursor moved from it to the desktop.

This event is implemented via @code{warp-cursor-to-window}, so Sawfish
will not warp unless @code{warp-to-window-enabled} is true.

@item focus-revert
The focused window has disappeared (the @var{window} argument is not
used here).  The focus mode may react by setting focus to some other
window.  If a focused transient window disappears, focus normally
reverts to the window that the disappearing window was transient for.
@code{focus-revert} is not invoked in that case.
@end table

The protocol allows for any number of additional arguments, but does
not define any.  Any handler function must be prepared to receive and
ignore them.

Unsupported events may be ignored.  The return value of this function
is ignored.
@end deftp

@defun define-focus-mode name fun
Defines a new focus mode called @var{name} (a symbol).  The focus-mode
handler @var{fun} implements this focus mode.

See the documentation for @code{focus-mode-handler} for more
information.
@end defun

@defun set-focus-mode window mode
Set the focus mode of window @var{window} to @var{mode}.
This triggers @code{before-mode-change} and @code{after-mode-change}
focus-mode events on @var{window}.
@end defun

@defun warp-pointer-if-necessary window
Generate a @code{warp-if-necessary} event and sends it to the window's
focus function.

Various functions call @code{warp-pointer-if-necessary} if they move
the focused window out from underneath the pointer.
@end defun

@defvar focus-click-through
When in @code{click} focus mode, the focus-assigning click is only
passed through to the client window if this variable is @code{t} (the
default).

This option may be set on a per-window basis by setting the
@code{focus-click-through} property of the window (using the
@code{window-put} function).
@end defvar

@defvar focus-ignore-pointer-events
When true, pointer in/out events don't cause focus changes.  This is
independent of the current focus mode.
@end defvar

@defvar focus-within-click-event
When true, the current command is being called from within a
click-to-focus button press event.

This is a fluid object, not an ordinary variable.
@end defvar

Sawfish also maintains the order in which windows were recently
focused.

@defun window-order &optional workspace allow-iconified all-viewports
Return a list of windows, in most-recently-focused order.

If @var{workspace} is an integer, then only windows on that workspace
are included, otherwise all workspaces are searched.

If @var{allow-iconified} is non-nil, iconified windows are included. If
@code{all-viewports} is non-nil, then all viewports of the workspace(s)
are scanned.
@end defun

@defun window-order-push window
Push window object @var{window} onto the top of the focus stack.
@end defun

@defun window-order-pop window
Remove window object @var{window} from the focus stack.
@end defun

@defun window-order-most-recent &optional windows
Return the most-recently focused window in the current workspace.  If
the optional argument @var{windows} is given, it must be a list of
windows.  In that case, the function will return the most-recently
focused window from that list.
@end defun

@defun window-order-focus-most-recent
Focus the most-recently-focused window of the current workspace.
@end defun

@defvar focus-dont-push
When true, focusing a window doesn't change it's position in the stack of
most-recently focused windows.
@end defvar

@defun window-in-cycle-p window &keyword ignore-cycle-skip
Returns @code{t} if the window @var{window} should be included when
cycling between windows.  Desktop windows and those with the
@code{cycle-skip} property should normally not be included.

When @code{t}, the @var{ignore-cycle-skip} keyword argument
forces the function to include windows with the @code{cycle-skip}
property.
@end defun

@defun focus-push-map window keymap
@defunx focus-pop-map window
Maintain a two-element keymap stack for @var{window}.

@code{focus-push-map} makes @var{keymap} current for @var{window}, but
saves the existing keymap.  We can restore this existing keymap with
@code{focus-pop-map}.

These functions are intended to support click-to-focus.  They enforce
certain sanity rules: pushing into a two-element stack will only
overwrite the top element, while popping a one-element stack has no
effect.
@end defun

@defun autoload-focus-mode name func
MISSING.  This does not seem to be used anywhere, and its behavior is
unclear.
@end defun

@defun select-window
Waits for the user to left-click on a window, and returns that window.
The mouse cursor changes shape, and all normal input events are
suppressed until a window is selected.
@end defun

@defvar select-window-cursor-shape
The cursor shape to use when selecting a window.  Defaults to
@code{crosshair}.
@end defvar

@node X Properties, Window Stacking, Input Focus, Windows
@section X Properties
@cindex X properties
@cindex Properties, X
@cindex Windows, X properties

The X window system associates properties with windows (these are
totally separate to the properties that sawfish associates with window
@emph{objects}, @pxref{Window Property Lists}). Most inter-client
communication is performed through manipulation of these properties.

All functions defined below, that operate on X properties, accept their
@var{window} parameter as either a window object (denoting the
associated client window), the numeric xid of a window, or the symbol
@code{root} denoting the root window.

Sawfish represents X atoms (both the names and data types of  X
properties) as symbols. There is an exact correspondence between the
names of atoms and the name of the symbol representing them. For
example, the X atom @samp{STRING} is represented by the lisp symbol
@code{STRING}.

@defun list-x-properties window
Return a list of symbols defining the X properties set on @var{window}.
@end defun

@defun delete-x-property window property
Deletes the X property named @var{property} (a symbol) associated with
@var{window}.
@end defun

@defun get-x-property window property
Returns a list @code{(@var{type} @var{format} @var{data})} representing
the X property @var{property} of @var{window}. If no such property
exists, return nil.

@var{type} is the atom defining the type of the property. @var{format}
is an integer, either 8, 16 or 32, defining the number of bits in each
of the data items. @var{data} is an array, either a string for an 8-bit
format property, or a vector of integers otherwise.

If @var{type} is @code{ATOM} and @var{format} is 32, then @var{data}
will be a vector of symbols, representing the atoms read.
@end defun

@defun set-x-property window property data type format
Set the X property @var{property} of @var{window} to the array
@var{data}, either a string or a vector of integers.

@var{type} is a symbol representing the atom defining the type of the
property; @var{format} is either 8, 16 or 32 defining the number of
bits in the data values.

If @var{type} is @code{ATOM} and @var{format} is 32, then any symbols
in @var{data} will be converted to their numeric X atoms.
@end defun

The standard X property formats don't allow for an array of strings to
be stored, so these are often encoded as the strings concatenated,
separated by zero characters. These are usually called @dfn{text
properties}. Sawfish has two functions for manipulating them:

@defun get-x-text-property window property
Similar to @code{get-x-property}, but returns either @code{nil} or a
vector of strings.
@end defun

@defun set-x-text-property window property data
Sets the X text property @var{property} of @var{window} to the array
of strings @var{data}.
@end defun

It's also possible to detect when the value of any property associated
with a managed window changes, using the @code{property-notify-hook}.
@xref{Standard Hooks}.  The following convenience function takes
advantage of this hook:

@defun call-after-property-changed prop fun
Arrange for function @var{fun} to be called with arguments
@samp{(window property state)} when the X11 property named @var{prop}
(a symbol) changes.  @var{Prop} may also be a list of property names
to monitor.
@end defun


@node Window Stacking, Moving and Resizing Windows, X Properties, Windows
@section Window Stacking
@cindex Window stacking
@cindex Stacking, of windows
@cindex Windows, stacking

The stacking order of the display defines the order in which windows
are shown, from topmost to bottommost.  Sawfish maintains this list.
Raising or lowering windows changes their positions in this list.

@menu
* Stacking Order::
* Raising and Lowering Windows::
@end menu

@node Stacking Order, Raising and Lowering Windows, Window Stacking, Window Stacking
@subsection Stacking Order

@defun stacking-order
Return a list of window objects defining the current stacking order of
all client windows, from top-most to bottom-most.
@end defun

@defun mapped-stacking-order
Similar to @code{stacking-order}, but only returns windows that are
mapped.
@end defun

@defun restack-windows list
Restack all client windows specified in the list of window objects
@var{list} in the order they occur in the list (from top to bottom).
The stacking order of any unspecified windows isn't affected.
@end defun

Sawfish allows the stacking order to be managed as a sequence of
layers, with windows being assigned a particular depth within the
order. For any given window with depth @var{d}, it will be above all
windows with depth less than @var{d}, and below all windows with depth
greater than @var{d}. It may be above or below any other windows with
depth @var{d}.

The @code{depth} property of each window is used to store this depth. A
depth of zero is ``normal'', with negative depths stacked below, and
positive depths stacked above this normal level.

@defun stacking-order-by-depth depth
Similar to @code{stacking-order}, but only returns windows with depth
@var{depth}.
@end defun

@defun window-depth window
Returns the depth of @var{window}.
@end defun

@defun set-window-depth window depth
Sets the stacking depth of @var{window} to @var{depth}, then restacks
the windows to reflect this change.
@end defun

@defun window-on-top-p window
Returns @code{t} if @var{window} is at the top of its stacking depth.
@end defun

@defun stack-window-below below above
Change stacking order of window @var{below} so that it is immediately
below window @var{above}.
@end defun

@defun stack-window-above above below
Change stacking order of window @var{above} so that it is immediately
above window @var{below}.
@end defun

@defmac save-stacking-order &rest forms
Evaluate @var{forms} in an implicit @code{progn}, then restore the
original window stacking order, returning the value of the
@code{progn}.
@end defmac

@defun restack-window w
Assuming that the current stacking order is in a consistent state
except, possibly, for the position of window @var{w}, restore the
consistent state including window @var{w}. This is achieved by raising
or lowering window W as appropriate.
@end defun

@node Raising and Lowering Windows,  , Stacking Order, Window Stacking
@subsection Raising and Lowering Windows
@cindex Windows, raising
@cindex Windows, lowering

Over time, Sawfish has accumulated several subtle variations of
functions for raising and lowering windows.  One set of functions
operates on single windows.

@deffn Function lower-window window
@deffnx Command lower-single-window window
Lower @var{window} to the bottom of its stacking depth.
@end deffn

@deffn Function raise-window window
@deffnx Command raise-single-window window
Raise @var{window} to the top of its stacking depth.
@end deffn

@deffn Function raise-lower-window window
@deffnx Command raise-lower-single-window window
If @var{window} is the highest in its stacking level, lower it to the
bottom of this level, otherwise raise it to the top of its level.
@end deffn

Notice how the function name and command name for each pair differs
slightly.  Another set of functions supports operating on multiple windows
simultaneously.  Again, the function name and command name for each
pair is different.

@deffn Function lower-window* window
@deffnx Command lower-window window
Lower @var{window} and possibly associated windows to the bottom of
their stacking depths. 
@end deffn

@deffn Function raise-window* window
@deffnx Command raise-window window
Raise @var{window} and possibly associated windows to the top of their
stacking depth.
@end deffn

@deffn Function raise-lower-window* window
@deffnx Command raise-lower-window window
If @var{window} is the highest in its stacking level, lower it and
possibly associated windows to the bottom of their level, otherwise
raise them to the top of their level.
@end deffn

@defvar user-raise-type
Indicates which windows the @code{lower-window*}, @code{raise-window*}
and @code{raise-lower-window*} functions affect.  This variable can be

@table @code
@item none
Only the specific argument window is affected.
@item transients
The specific argument window and all of its transients are affected.
This is the default.
@item group
The specific argument window and all windows in its group are
affected.
@end table
@end defvar

@defun maybe-raise-window w
If window @var{w} supports the @code{_SAWFISH_WM_RAISE_WINDOW}
protocol, ask it whether it wants to raise itself or not.  Otherwise,
raise the window unconditionally.
@end defun

@defun maybe-lower-window w
If window @var{w} supports the @code{_SAWFISH_WM_LOWER_WINDOW}
protocol, ask it whether it wants to lower itself or not.  Otherwise,
lower the window unconditionally.
@end defun

Sawfish has more general operations that raising a window to the top
or lowering it to the bottom.  It can place a window relative to one
or more other managed windows.

@defun raise-windows w order
@defunx lower-windows w order
@defunx raise-lower-windows w order
Raise (or lower) all windows in @var{order}, such that items earlier in
the list are higher (or lower) than later items.  The window @var{w}
is special, always being the highest or lowest window, even if appears
in the middle of @var{order}.

For @code{raise-lower-windows}, if @var{w} would be raised or lowered,
then all the other windows are also raised or lowered.
@end defun

There are also functions (and associated commands) to change a
window's depth.

@deffn Function lower-window-depth window
@deffnx Command lower-window-depth window
Decrement the stacking depth of @var{window}.
@end deffn

@deffn Function raise-window-depth window
@deffnx Command raise-window-depth window
Increment the stacking depth of @var{window}.
@end deffn

Sawfish provides special support for ``click-to-focus'' mode, where
you may or may not want to raise the window or pass the click to the
underlying application.

@defun raise-and-pass-through-click w
Raise the window that received the current event with
@code{maybe-raise-window}.  Then replay any pointer events that
invoked the command.
@end defun

@defun raise-and-pass-through-click-if-focused w
Raise the window that received the current event (if it's focused)
with @code{maybe-raise-window}.  Then replay any pointer events that
invoked the command.
@end defun

@defun raise-or-pass-through-click w
If the window that received the current event is not on top, raise it
with @code{maybe-raise-window}.  Otherwise replay any pointer events
that invoked the command, sending them to the window.
@end defun

When the above commands are called interactively, Sawfish will try to
invoke them on the window that received the current event.  Failing
that, Sawfish will invoke them on the currently focused window.

@node Moving and Resizing Windows, Showing and Hiding Windows, Window Stacking, Windows
@section Moving and Resizing Windows
@cindex Moving and resizing windows
@cindex Resizing and moving windows
@cindex Windows, moving and resizing

As noted above (@pxref{Window Attributes}), the
@code{window-dimensions} and @code{window-position} functions return
the current configuration of a window.

@defun move-window-to window x y
Move the top-left corner of the window frame of @var{window} to
(@var{x}, @var{y}).
@end defun

@defun resize-window-to window width height
Set the dimensions of the client window associated with object
@var{window} to (@var{width}, @var{height}).
@end defun

@defun move-resize-window-to window x y width height
Move the top-left corner of the window frame of @var{window} to
(@var{x}, @var{y}), and set the dimensions of the frame to
(@var{width}, @var{height}).
@end defun

@defun resize-window-with-hints window cols rows &optional hints
@defunx resize-window-with-hints* window width height &optional hints
Resize the window associated with object @var{window} so that it has
certain X and Y dimensions.  For the first function, the dimensions
are @var{cols} columns and @var{rows} rows.   For the second function,
the dimensions are @var{width} pixels and @var{height} pixels.

The @var{hints} parameters is either the size hints alist to use, or
@code{nil} in which case the @code{window-size-hints} function is used
to retrieve the window's hints.
@end defun

Usually, however, it is left to the user to configure windows. The
following functions may be called interactively: their sole argument is
then either the window that received the current event or the currently
focused window.

Sawfish honors the @code{min-aspect} and @code{max-aspect} window
hints when interactively resizing a window.

@deffn Command move-window-interactively window
Move @var{window} interactively using the mouse. Releasing any mouse
button places the window at its current position.
@end deffn

@deffn Command resize-window-interactively window
Resize @var{window} interactively using the mouse. Releasing any mouse
button places the window at its current position.

Note that this function selects the edge or edges of the window to move
from the current position of the mouse when the resizing begins. The
window is divided into a three-by-three grid; the rectangle containing
the mouse pointer gives the direction to resize in. If the pointer is
in the central rectangle the bottom and right edges are moved.
@end deffn

@deffn Command move-selected-window
Wait for the user to select a window using the mouse, then
interactively move that window.
@end deffn

@deffn Command resize-selected-window
Wait for the user to select a window with the mouse, then interactively
resize that window.
@end deffn

The interactive move and resize behavior can be customized through the
following variables:

@defvar move-outline-mode
A symbol defining the visual method of interactively moving windows.
Current options include @code{box} for a wire-frame grid, and
@code{opaque} for full redisplay.
@end defvar

@defvar resize-outline-mode
A symbol defining the visual method of interactively resizing windows.
Current options include @code{box} for a wire-frame grid, and
@code{opaque} for full redisplay.
@end defvar

@defvar move-show-position
When non-nil, the current window position is shown in the center of the
screen.
@end defvar

@defvar resize-show-position
When non-nil, the window size is shown in the center of the screen.
@end defvar

@defvar move-snap-edges
When non-nil, the window position is ``snapped'' to edges of other
windows within close proximity.
@end defvar

@defvar move-snap-epsilon
The distance in pixels before snapping together two edges.
@end defvar

Windows have a ``gravity'' property, which affect how they are placed
in particular positions.

@defun window-gravity window &optional hints
Returns the gravity of window.  The order of precedence is Sawfish
@code{gravity} window property, explicit @var{hints} argument, X
window size hints.  The default gravity when nothing else is specified
is @code{north-west} (specified by ICCCM).
@end defun

@node Showing and Hiding Windows, Destroying Windows, Moving and Resizing Windows, Windows
@section Showing and Hiding Windows
@cindex Showing and hiding windows
@cindex Hiding and showing windows
@cindex Windows, showing and hiding

Sawfish provides two low-level functions for withdrawing client windows
from the display. These are used to implement both virtual workspaces
(@pxref{Workspaces}) and iconification (@pxref{Iconifying Windows}).

@defun hide-window window
Prevent object @var{window} from being displayed.  See
@code{show-window}.
@end defun

@defun show-window window
Ensure that @var{window} (if it has been mapped, and is within the
screen boundary) is visible.  See @code{hide-window}.
@end defun

@defun window-visible-p window
Returns @code{t} if object @var{window} has not been hidden by the
@code{hide-window} function.
@end defun


@node Destroying Windows, Shading Windows, Showing and Hiding Windows, Windows
@section Destroying Windows
@cindex Destroying windows
@cindex Windows, destroying

There are several methods through which X11 client windows may be
removed from the display. These differ in the level ``politeness'' they
show the window and its owning application.

@deffn Command delete-window window
Delete @var{window}, i.e. send a @code{WM_DELETE_WINDOW} client-message
if possible, or just kill the associated X11 client if not.
@var{window} may be a window object or a numeric window id.
@end deffn

@deffn Command delete-window-safely window
If the application owning @var{window} supports it, send a
@code{WM_DELETE_WINDOW} message to @var{window}. Otherwise just emit a
beep.
@end deffn

@deffn Command destroy-window window
Destroy @var{window} without giving the owning application any warning.
@var{window} may be a window object or a numeric window id.
@end deffn

@defun x-kill-client window
Force a close down of the X11 client that created the window specified
by @var{window} (a window object, or numeric id).
@end defun

When a managed window is destroyed, the @code{destroy-notify-hook} will
subsequently be invoked (@pxref{Standard Hooks}).

@node Shading Windows, Iconifying Windows, Destroying Windows, Windows
@section Shading Windows
@cindex Shading windows
@cindex Windows, shading

Many window managers allow a window to be @dfn{shaded}; when in this
state only the title bar of the window is visible.

@defun window-shaded-p window
Returns true when @var{window} is shaded, false otherwise.
@end defun

@deffn Command shade-window window
Arrange for only the title bar of @var{window} to be visible.
@end deffn

@deffn Command unshade-window window
If the window is shaded, restore it to it's original state.
@end deffn

@deffn Command toggle-window-shaded
Toggle the shaded state of the window.
@end deffn

@defvar raise-windows-when-unshaded nil
When true, raise windows when they are unshaded.  Defaults to false.
@end defvar

The @code{shaded} property of a window is set to @code{t} when the
window is shaded. If a window is added with this property already set,
then the window will appear in its shaded state.


@node Iconifying Windows, Window Stickiness, Shading Windows, Windows
@section Iconifying Windows
@cindex Iconifying windows
@cindex Windows, iconifying

X defines an iconic state for windows, often windows in this state are
displayed as small icons. Sawfish does not display these icons, instead
iconified windows are shown slightly differently in the menu of all
windows.

@deffn Command iconify-window window
Iconify the window associated with object @var{window}.
@end deffn

@deffn Command uniconify-window window
Return the window associated with @var{window} from its iconified state.
@end deffn

@deffn Command toggle-window-iconified window
Minimize the window associated with @var{window}, or restore it if it
is already minimized.
@end deffn

@deffn Command iconify-workspace-windows
Minimize all windows in the current workspace.
@end deffn

A window's iconic state may be tested through examination of its
@code{iconified} property---when @code{t} the window is iconified.
But it is preferable to use explicit testing functions instead:

@defun window-iconified-p window
Returns true if the window associated with @var{window} is iconified,
false otherwise.
@end defun

@defun window-iconifiable-p window
Returns true if the window associated with @var{window} can be
iconified, false otherwise.  Some reasons a window might not be
iconifiable are: it has a @code{never-iconify} property; it is
already iconified; it is not a desktop window; or it is marked
@code{ignored} and @code{iconify-ignored} is not true.
@end defun

@defvar iconify-ignored nil
Unmanaged (@code{ignored}) windows may be iconified.  Defaults to nil.
@end defvar

Sawfish allows you to control certain behaviors when restoring
minimized windows.

@defvar focus-windows-on-uniconify
Windows are focused after being unminimized.  Defaults to false.
@end defvar

@defvar raise-windows-on-uniconify
Windows are raised after being unminimized.  Defaults to true.
@end defvar

@defvar uniconify-to-current-workspace
Move windows to the current workspace when they are unminimized.
Defaults to true.
@end defvar

When iconifying, it is possible to force other windows to iconify.

@defvr Customizable iconify-group-mode
@defvrx Customizable uniconify-group-mode
Policy for performing chains of minimizations or restorations.  When a
particular window is minimized or restored, it can cause other windows
to be minimized or restored at the same time.  Their allowed values
are set to the following list.  By default, both variables are bound
to the symbol @code{transients}. but they are not required to have the
same value.
@end defvr

@table @code
@item none
No additional windows are minimized or restored.
@item transients
All transient windows associated with the target window are minimized
or restored.
@item group
All windows in the target window's group are minimized or restored.
@end table

Finally, it's possible to get the icon that would normally be
displayed for an iconified window.

@defun window-icon-image window
Return an image object representing the icon currently associated with
@var{window}, or @code{nil} if there is no such image.
@end defun

@node Window Stickiness, Ignored Windows, Iconifying Windows, Windows
@section Window Stickiness
@cindex Window stickiness
@cindex Sticky, windows

Windows normally exist in a single workspace and a single viewport
into that workspace.  When changing workspace or viewport, the current
windows disappear.  This is sometimes not the correct policy; there
are certain windows that should ``follow'' the user from window to
window.  These are typically windows that are not bound to a
particular activity.  The most common example is a dashboard window
for calling other applications.  Another example might be a diagnostic
program such as a load monitory.

Each window has ``stickiness'' flags that govern this behavior.  One
flag controls stickiness across workspaces: sticky windows will appear
in every workspace automatically.  The other flag similarly governs
stickiness across viewports.  A window is ``sticky'' if either of
these flags are set.

Sticky windows are often @code{ignored}, so they lack window
decorations, and @code{avoid}ed so other windows do not cover them up.

@defun window-sticky-p/workspace window
@defunx window-sticky-p/viewport window
@defunx window-sticky-p window
Returns true if @var{window} is sticky across a particular environment
(workspaces, viewports, or either), false otherwise.
@end defun

@defun make-window-sticky/workspace window
@defunx make-window-sticky/viewport window
@defunx make-window-sticky window
Make the @var{window} sticky across some environment (workspaces,
viewports, or both).
@end defun

@defun make-window-unsticky/workspace window
@defunx make-window-unsticky/viewport window
@defunx make-window-unsticky window
Make the @var{window} unsticky across some environment (workspaces,
viewports or both).
@end defun

@defun toggle-window-sticky window
If @code{window-sticky-p} would report true for @var{window}, make
@var{window} unsticky for all environments.  Otherwise make it sticky
for all environments.
@end defun

@node Ignored Windows, Avoided Windows, Window Stickiness, Windows
@section Ignored Windows
@cindex Windows, ignored
@cindex ignored

Sawfish has a general concept of ``ignored'' windows; the user does
not interact normally with those windows.  The concept is actually
defined by five different window properties:

@table @code
@item ignored
The window does not receive frames.

@item never-focus
The window never receives the input focus.

@item cycle-skip
The window is ignored while window cycling.

@item window-list-skip
The window will not be included in the window list.

@item task-list-skip
The window will not be included in the task list.

@end table

A monitor application such as ``xload'' might have all five of these
flags set.

Rather than directly manipulating the window properties, it is better
to use the following access functions:

@defun window-ignored-p window
Returns true if the window has the @code{ignored} property, false
otherwise.
@end defun

@deffn Command make-window-ignored window
Ignore the window @var{window}.
@end deffn

@deffn Command make-window-not-ignored window
Unignore the window @var{window}.
@end deffn

@deffn Command toggle-window-ignored window
If @code{window-ignored-p} would return true for @var{window}, make it
unignored.  Otherwise make it ignored.
@end deffn

The remaining flags only have toggle functions implemented right now:

@deffn Command toggle-window-never-focus window
@deffnx Command toggle-window-cycle-skip window
@deffnx Command toggle-window-list-skip window
@deffnx Command toggle-task-list-skip window
Toggle the appropriate flag on @var{window}.
@end deffn

All five of the flags are available through the window menu's
``Toggle'' entry.

@node Avoided Windows, Maximizing Windows, Ignored Windows, Windows
@section Avoided Windows
@cindex Windows, avoided
@cindex avoid

``Avoided'' windows are kept unobscured by other windows
wherever possible. It is involved in window placement (@pxref{Window
Placement}) and maximization (@pxref{Maximizing Windows}).
Most placement modes will attempt to place a new window avoiding
overlap with them. Windows can be maximized avoiding overlap to
avoided windows.

In this context, windows are categorized into three: windows with
@code{avoid} property, those with
@code{ignored} property (@pxref{Ignored Windows}), and the others.

It is possible to avoid overlap only with avoided windows, and
also is possible @emph{not} to avoid overlap only with ignored windows.

Remember that the window with @code{avoid} property is @emph{avoided}
by @emph{other} windows. Thus property name @code{avoid} should have
been named ``avoided''. On the other hand, related functions and
variables are named correctly, and no special care is necessary.

@defvar dont-avoid-ignored
When non-nil (the default), ignored windows aren't avoided.
@end defvar

@defvar avoid-by-default
When non-nil, any windows are avoided. Defaults to nil.
@end defvar

@defun window-avoided-p window
Returns t if @var{window} is avoided by other windows.
It is determined in the following order:

@enumerate
@item A window with @code{avoid} property is always avoided.
@item A window with @code{ignored} property is always @emph{not} avoided
unless @code{dont-avoid-ignored} is non-nil.
@item Otherwise, @code{avoid-by-default} determines if it should be avoided.
@end enumerate
@end defun

@defun avoided-windows &optional window
Returns a list of all windows that are avoided. If
@var{window} is defined, then it is excluded from the returned list.
@end defun

@node Maximizing Windows, Animating Windows, Avoided Windows, Windows
@section Maximizing Windows
@cindex Maximizing windows
@cindex Windows, maximizing

The dimensions of a window may be temporarily @dfn{maximized},
stretching as far as possible within the screen in one or two dimensions.

@defun window-maximizable-p window &optional direcion hints
Return @code{t} when @var{window} is maximizable. The window property
@var{never-maximize} prevents maximization.

If defined, @var{direction} is a symbol, either @code{vertical} or
@code{horizontal}, and maximization will only occur for that
direction.

The optional argument @var{hints} overrides the window's hints.
@end defun

@defun window-maximized-p window
Return @code{t} when @var{window} is maximized in any direction.
@end defun

@defun window-maximized-vertically-p window
Return @code{t} when @var{window} is vertically maximized.
@end defun

@defun window-maximized-horizontally-p window
Return @code{t} when @var{window} is horizontally maximized.
@end defun

@menu
* Basic Maximizations::         
* Maximizing Without Overlap::
* Maximizing Without Borders::  
* Unmaximizing::                
@end menu

@node Basic Maximizations, Maximizing Without Overlap, Maximizing Windows, Maximizing Windows
@subsection Basic Maximizations

Ordinary maximization occurs on the current screen, and possibly
rounding down to fit character sizes.

@deffn Function maximize-window window &optional direction only-1d
@deffnx Command maximize-window window
Maximize both dimensions of @var{window} on the screen.

If defined, @var{direction} is a symbol, either @code{vertical} or
@code{horizontal}, and maximization will only occur for that
direction.

The optional argument @var{only-1d} is for internal use. Don't use it.
@end deffn

@deffn Function maximize-window-vertically window
@deffnx Command maximize-window-vertically window
Maximize the vertical dimension of @var{window} in the screen.
@end deffn

@deffn Function maximize-window-horizontally window
@deffnx Command maximize-window-horizontally window
Maximize the horizontal dimension of @var{window} in the screen.
@end deffn

@deffn Function maximize-window-toggle window &optional direction
@deffnx Command maximize-window-toggle window
Toggle the state of @var{window} between maximized and unmaximized
in the screen.

If defined, @var{direction} is a symbol, either @code{vertical} or
@code{horizontal}, and maximization will only occur for that
direction.
@end deffn

@deffn Function maximize-window-vertically-toggle window
@deffnx Command maximize-window-vertically-toggle window
Toggle the state of @var{window} between vertically maximized and
unmaximized in the screen.
@end deffn

@deffn Function maximize-window-horizontally-toggle window
@deffnx Command maximize-window-horizontally-toggle window
Toggle the state of @var{window} between horizontally maximized and
unmaximized in the screen.
@end deffn

@defvr Customizable move-lock-when-maximized
When true (the default), Sawfish will not allow the user to manually
resize maximized windows.  It will also prevent the user from moving
the windows along their maximized axes.

For example, a vertically maximized window is vertically locked, so a
user can slide it left and right, but cannot move it up or down.
@end defvr

@defun window-locked-vertically-p window
Return @code{t} when @var{window} is vertically locked.
@end defun

@defun frame-part-movable-p window part
Return @code{t} if the @var{part} of @var{window} can be moved.

@var{part} is one of the symbols: @code{top-border},
@code{bottom-border}, @code{left-border}, @code{right-border},
@code{top-left-corner}, @code{top-right-corner},
@code{bottom-left-corner}, @code{bottom-right-corner}, or
@code{title} 
@end defun

@defvar maximize-raises
When true (the default), maximizing a window raises it as well.
@end defvar

@defvar maximize-always-expands
In general, if a window's dimension is larger than the screen size,
maximizing that dimension can actually shrink it to fit into the
screen.  When this variable is true (default false), maximizing a
window's dimension will never shrink it.
@end defvar

@node Maximizing Without Overlap, Maximizing Without Borders, Basic Maximizations, Maximizing Windows
@subsection Maximizing Without Overlap

It is possible to maximize a window where it gets only large enough
not to overlap with other windows. 

@defvar maximize-avoid-avoided
When true (the default), maximized window does not cover avoided
windows. (@pxref{Avoided Windows})
@end defvar

The ``fill'' category of maximizing commands provides a convenient way to
maximize without overlap to any other windows, except ``ignored'' ones.
(@pxref{Ignored Windows})

In addition, they don't shrink the window even if it is already bigger
than the screen size.

@deffn Function maximize-fill-window window &optional direction
@deffnx Command maximize-fill-window window
Maximize both dimensions of @var{window} without overlapping other
windows.

If defined, @var{direction} is a symbol, either @code{vertical} or
@code{horizontal}, and maximization will only occur for that
direction.
@end deffn

@deffn Function maximize-fill-window-vertically window
@deffnx Command maximize-fill-window-vertically window
Maximize the vertical dimension of @var{window} in the screen without
overlapping other windows.
@end deffn

@deffn Function maximize-fill-window-horizontally window
@deffnx Command maximize-fill-window-horizontally window
Maximize the horizontal dimension of @var{window} in the screen
without overlapping other windows.
@end deffn

@deffn Function maximize-fill-window-toggle window
@deffnx Command maximize-fill-window-toggle window
Toggle the state of @var{window} between maximized and unmaximized in
the screen without overlapping other windows.

If defined, @var{direction} is a symbol, either @code{vertical} or
@code{horizontal}, and maximization will only occur for that
direction.
@end deffn

@deffn Function maximize-fill-window-vertically-toggle window
@deffnx Command maximize-fill-window-vertically-toggle window
Toggle the state of @var{window} between vertically maximized and
unmaximized in the screen without overlapping other windows.
@end deffn

@deffn Function maximize-fill-window-horizontally-toggle window
@deffnx Command maximize-fill-window-horizontally-toggle window
Toggle the state of @var{window} between horizontally maximized and
unmaximized in the screen without overlapping other windows.
@end deffn

@defvar maximize-ignore-when-filling
For ``filling'' maximization, ``ignored'' windows are ignored when true
(the default). (@pxref{Ignored Windows})
@end defvar

@node Maximizing Without Borders, Unmaximizing, Maximizing Without Overlap, Maximizing Windows
@subsection Maximizing Without Borders

The ``fullscreen'' and ``fullxinerama'' categories of maximizing
commands maximize the window to some extent and remove all the
window's decorations.  If necessary, Sawfish will pad the bottom and
right window edges to make the window fill the complete extent.  (This
is usually required for terminal windows, for example.)

The ``fullscreen'' category maximizes the window to the current
screen.

@deffn Function maximize-window-fullscreen window
@deffnx Command maximize-window-fullscreen window
Maximize both dimensions of @var{window} on the screen, removing
window decorations and making the window edges flush with the screen
sides.

If defined, @var{direction} is a symbol, either @code{vertical} or
@code{horizontal}, and maximization will only occur for that
direction.
@end deffn

@deffn Function maximize-window-fullscreen-toggle window
@deffnx Command maximize-window-fullscreen-toggle window
Toggle the state of @var{window} between maximized and unmaximized in
the screen, removing window decorations and making the window edges
flush with the screen sides.

If defined, @var{direction} is a symbol, either @code{vertical} or
@code{horizontal}, and maximization will only occur for that
direction.
@end deffn

The ``fullxinerama'' category maximizes the window to the entire
Xinerama display.

@deffn Function maximize-window-fullxinerama window
@deffnx Command maximize-window-fullxinerama window
Maximize both dimensions of @var{window} across all Xinerama screens,
removing window decorations and making the window edges flush with the
screen sides.

If defined, @var{direction} is a symbol, either @code{vertical} or
@code{horizontal}, and maximization will only occur for that
direction.
@end deffn

@deffn Function maximize-window-fullxinerama-toggle window
@deffnx Command maximize-window-fullxinerama-toggle window
Toggle the state of @var{window} between maximized and unmaximized
across all Xinerama screeens, removing window decorations and making
the window edges flush with the screen sides.

If defined, @var{direction} is a symbol, either @code{vertical} or
@code{horizontal}, and maximization will only occur for that
direction.
@end deffn

@node Unmaximizing,  , Maximizing Without Borders, Maximizing Windows
@subsection Unmaximizing

One command restores windows from all the different types of
maximization.

@deffn Command unmaximize-window window &optional direction
Restore the position and dimensions of @var{window} to their original,
unmaximized, states.

Positions and dimensions that were not maximized are not affected by
unmaximizing.

If defined, @var{direction} is a symbol, either @code{vertical} or
@code{horizontal}, and maximization will only occur for that
direction.
@end deffn

@defun window-unmaximized-position window
Returns a cons-cell @code{(@var{x} . @var{y})} indicating the position
that the @code{window} would unmaximize to.

Sawfish preserves the positions of maximized axes only, so a
vertically maximized window will be restored to its original @var{y}
coordinate, but its @var{x} coordinate may have changed.
@end defun

@defun window-unmaximized-dimensions window
Returns a cons-cell @code{(@var{w} . @var{h})} indicating the
dimensions that @code{window} would unmaximize to.

Sawfish preserves the dimensions of maximized axes only, so a
vertically maximized window will be restored to its original @var{h}
dimension, but its @var{w} coordinate may have changed.
@end defun

@node Animating Windows, Cycling Between Windows, Maximizing Windows, Windows
@section Animating Windows
@cindex Windows, Animating

Sawfish provides certain window animation capabilities.  They have
been described as ``lame'', so they are off by default.

@defvar default-window-animator
The default window animation mode, used if a window has no explicit
animation set.  Normally @code{none}.
@end defvar

@defun define-window-animator name fun
Define a window animator called @var{name} (a symbol) that is managed
by function @var{fun}. @var{fun} is called as @samp{(fun window op
[action])} when it should change the state of an animation sequence.
@var{Op} may be one of the symbols @code{start}, @code{stop}.
@end defun

@defun autoload-window-animator name struct
Construct an autoloader for window animator @var{name} from structure
@var{struct}.
@end defun

@defun run-window-animator window action
Invoke an animation for action @var{action} on @var{window}.
@var{Action} may be one of the symbols @code{start}, @code{stop}.
@end defun

@defun record-window-animator window animator
Note that @var{window} currently has an animation running, being
controlled by animator function @var{animator}.
@end defun

@node Cycling Between Windows, Window Groups, Animating Windows, Windows
@section Cycling Between Windows
@cindex Windows, cycling between

Sawfish provides two categories of commands for cycling between
windows.  The first category cycles between windows in an order that
is essentially fixed.  The second category cycles between windows in a
dynamic order.

@menu
* Fixed Window Cycles::
* Dynamic Window Cycles::
@end menu

@node Fixed Window Cycles, Dynamic Window Cycles, Cycling Between Windows, Cycling Between Windows
@subsection Fixed Window Cycles
@cindex Window cycles, fixed

These commands organize the set of mangaged windows into loops.  A
loop may consist of all windows in a workspace, or it may consist of
all windows anywhere.  The positions of windows in this loop do not
change, except when a new window is managed or unmanaged.

@defun next-workspace-window
@defunx previous-workspace-window
Switch focus to the ``next'' or ``previous'' window in the current
workspace.
@end defun

@defun next-window
@defunx previous-window
Switch focus to the ``next'' or ``previous'' window in this
workspace.  If this function reaches the ``end'' of the windows in
this workspace, it switches to the next workspace and displays the
first window there.
@end defun

@node Dynamic Window Cycles,  , Fixed Window Cycles, Cycling Between Windows
@subsection Dynamic Window Cycles
@cindex Window cycles, dynamic

These commands implement something much close to Microsoft Windows'
@key{Alt-TAB} mechanism, working with a stack of recently used
windows.

@defun cycle-windows
@defunx cycle-windows-backwards
Cycle through all cycleable windows.
@end defun

@defun cycle-group
@defunx cycle-group-backwards
Cycle through all windows in this group.

This is somewhat comparable to the @key{Control-TAB} behavior of
windows.
@end defun

@defun cycle-prefix
@defunx cycle-prefix-backwards
Cycle through all windows whose titles match that of the initial
window (up to, but not including, the first colon).
@end defun

@defun cycle-class
@defunx cycle-class-backwards
Cycle through all windows whose classes match that of the initial
window.
@end defun

@defun cycle-dock
@defunx cycle-dock-backwards
Cycle through all windows in the dock, even those with the
@code{cycle-skip} property.
@end defun

Each of these cycling commands may include windows that are not
visible on-screen.

@defvar cycle-include-iconified
If true, Sawfish includes iconified windows when cycling.  Defaults to
true.
@end defvar

@defvar cycle-all-workspaces
If true, Sawfish includes windows on all workspaces when cycling.
Defaults to false.
@end defvar

@defvar cycle-all-viewports
If true, Sawfish includes windows on all viewports when cycling.
Defaults to false.
@end defvar

It is possible to configure the cycling to get more feedback during
the process.

@defvar cycle-show-window-names
If true, Sawfish displays window names and icons while cycling through
windows.  Defaults to true.
@end defvar

@defvar cycle-raise-windows t
If true, Sawfish raises windows while they're temporarily selected
during cycling, and invokes @code{warp-pointer-if-necessary}.
Defaults to true.
@end defvar

It is also possible for you to define your own stacking cycle
commands, or even to alter the window stack to suit your tastes.

@defun define-cycle-command name body &rest rest
Create a command that will not cause the current cycle operation
to abort before execution.

All arguments are passed to define-command.
@end defun

@defun define-cycle-command-pair forward-name reverse-name selector &rest rest
Create a pair of commands for cycling through windows. The command named
@var{forward-name} cycles forwards, while the command named
@var{reverse-name} cycles backwards.

@var{Selector} is called when initializing the cycle environment, it
should return the list of windows to cycle through, or the symbol `t'
to denote all cyclable windows.

Any extra arguments are passed to each call to define-command.
@end defun

@defun window-order &optional workspace allow-iconified all-viewports
Return managed windows in most-recently used order.

If @var{workspace} is non-nil, then only managed windows in that
workspace will be returned.

If @var{allow-iconified} is non-nil, then iconified windows will be
returned instead of ignored.

If @var{all-viewports} is non-nil, then windows in all viewports will
be returned, instead of just the current viewport.
@end defun

@defun window-order-push w
Push window @var{w} onto the top of the cycle stack.
@end defun

@defun window-order-pop w
Remove window @var{w} from the cycle stack.
@end defun

@defun window-order-most-recent &key windows
Return the most-recently focused window in the current workspace.  If
the @var{windows} argument is given it should be a list of windows, in
this case the function will restrict its search to the elements of
this list.
@end defun

@defun window-order-focus-most-recent
Switch input focus to the most-recently focused window in the current
workspace.
@end defun

@node Window Groups,  , Cycling Between Windows, Windows
@section Window Groups
@cindex Groups, windows

Sawfish provides extra tools and commands for dealing with ICCCM
groups.  Most ``normal'' groups work the same way as they do in the
ICCCM standard: windows have a group property that is set to the X
window ID of the group leader.  These are ``group IDs'', and they are
always positive integers.  In addition, Sawfish allows group IDs to
be:

@table @asis
@item negative integers
These are anonymous user-defined groups.
@item symbols
These are named user-defined groups.  Named user-defined groups are
saved as part of window properties when saving sessions.
@end table

@defun window-group-ids
Return the list of all group ids.
@end defun

There may be certain named groups that always exist, whether or not
any window belongs to them.

@defvar peristent-group-ids
A list of symbols naming groups that always exist.
@end defvar

In any case, a window is limited to belonging to one group, and always
belongs to one group.

@menu
* Assigning Windows to Groups::
* Operations on Groups::
@end menu

@node Assigning Windows to Groups, Operations on Groups, Window Groups, Window Groups
@subsection Assigning Windows to Groups
@cindex Groups, assigning windows to

It is possible to change the group of a window in Sawfish.  Use
@code{add-window-to-group}, or if necessary you can set the window's
@code{group} property explicitly.

@defun add-window-to-group window group-id
Place @var{window} in group @var{group-id}, replacing any previous
group membership.  If @var{group-id} is @code{nil}, then Sawfish
returns the window to whatever group membership was supplied by ICCCM.
@end defun

@defun add-window-to-new-group window
Place @var{window} into a new group, which will have @var{window} as
its sole member.  This is an anonymous user-defined group.  The new
group ID is returned.
@end defun

The Sawfish group assignment never overrides the ICCCM group
assignment, just suppresses it.  The @code{window-actual-group-id}
function implements this overriding.

@defun window-actual-group-id window
Return the (Sawfish) group ID for @var{window}.  This is, in order of
preference:
@itemize @bullet
@item The group ID assigned by Sawfish
@item The group ID passed in by ICCCM.
@item The corresponding values for an owning window, if the given window is transient.
@item The window's own window ID.
@end itemize

This means that a window is, at the very least, part of its own group.
@end defun

Each of the following functions operates on the ``actual group ID'' as
returned by the above function.

@defun windows-by-group group-id &optional by-depth
Return the list of windows in the group with id @var{group-id}.
If @var{by-depth} is non-nil, then return the windows in order of
stacking, from topmost to bottommost.
@end defun

@defun windows-in-group w &optional by-depth
Return the list of windows in the same group as window @var{w}.
If @var{by-depth} is non-nil, then return the windows in order of
stacking, from topmost to bottommost.
@end defun

@defun map-window-group fun w
Map the single argument function @var{fun} over all windows in the
same group as window @var{w}.  Note that @var{fun} needs to operate
using side-effects, rather than returning values.
@end defun

@defun map-other-window-groups fun w
Map the single argument function @var{fun} over all windows not in the
same group as window @var{w}.  Note that @var{fun} needs to operate
using side-effects, rather than returning values.
@end defun

@defun window-group-menu &optional w
Return a menu definition suitable for @code{popup-menu}.  This menu
will allow the user to assign the window @var{w} into any group of a
managed window, or into a brand new group.  The window's current group 
is checked or otherwise marked.
@end defun

@node Operations on Groups,  , Assigning Windows to Groups, Window Groups
@subsection Operations on Groups
@cindex Groups, operations on

Most of the window manipulation functions that operate on windows are
also available for window groups.  Each of these functions takes a
window as argument; the affected group is that window's group.

@defun iconify-group w
@defunx uniconify-group w
@defunx iconify-transient-group w
@defunx uniconify-transient-group w
These operate like their single-window counterparts.  They work by
temporarily rebinding @code{iconify-group-mode} and
@code{uniconify-group-mode}.
@end defun

@defun make-group-sticky w
@defunx make-group-unsticky w
These operate like their single-window counterparts.
@end defun

@defun toggle-group-sticky w
If window @var{w} is sticky, all windows in its group have their
stickyness removed.  Otherwise all windows in its group become sticky.
@end defun

@defun send-group-to-workspace w workspace
@defunx send-group-to-next-workspace w count
@defunx send-group-to-previous-workspace w count
These operate like their single-window counterparts.
@end defun

@defun send-group-to-current-workspace w
All windows in the group of @var{w} are moved from their existing
workspaces to the nearest workspace that @var{w} is in.  Sticky
windows are not affected.  If the window had the input focus and it is
visible after the move, it retains the input focus.
@end defun

@defun move-group-to-current-viewport w
@defunx move-group-viewport w
@end defun

@defun move-group-left w
@defunx move-group-right w
@defunx move-group-up w
@defunx move-group-down w
These operate like their single-window counterparts.
@end defun

@defun raise-group w
@defunx lower-group w
@defunx raise-lower-group w
@defunx raise-group-depth w
@defunx lower-group-depth w
These operate like their single-window counterparts.
@end defun

@defun set-group-frame-style w style
This operates like its single-window counterpart.
@end defun

@node Customization, Window Frames, Windows, Top
@chapter Customization
@cindex Customization

Sawfish provides two levels of configuration:

@enumerate
@item @dfn{customization}: setting variables to change the behavior of
existing features of the window manager, and,

@item @dfn{extensibility}: the ability to add entirely new features to
the window manager through the creation of new Lisp modules.
@end enumerate

Obviously the first of these requires a lot less specialized knowledge
than the second. But even then, the user has to edit startup files
containing the Lisp forms setting the variables. To remove this need
for hand-editing, Sawfish has a specialized system allowing all
customizations to be made through a GUI, and then automatically
reloaded each time that the window manager is started.

@deffn Command customize &optional group
Invoke the user-customization GUI. @var{group} defines the class of
customization variables to configure, or all classes if @var{group} is
undefined.
@end deffn

The @file{sawfish-ui} program can be used to invoke the GUI manually;
if GNOME is being used, then the GNOME Control Center can also be used
to customize certain classes.

In order to provide these customization options however, an extra
requirement is placed on the Lisp programmer. Instead of just using the
@code{defvar} special form to declare variables, the @code{defcustom}
macro must be used. This augments the variable with extra information
for the GUI, including such things as its required data type.

@menu
* Defgroup and Defcustom::      
* Customization Files::         
* Customized Variable Status::  
@end menu

@node Defgroup and Defcustom, Customization Files, Customization, Customization
@section Defgroup and Defcustom
@cindex defgroup
@cindex defcustom

Customization options are organized into groups.  Each group has a name
and contains a set of related options.  Groups can be assigned to
parent groups using the @code{:group} parameter during construction.

@defmac defgroup group real-name &rest keys
Declares a new customization group whose name is defined by the symbol
@var{group}. The string @var{real-name} is the title of the group as
seen by the user.

@var{keys} is a list, defining the properties of the group. The members
of the list are grouped into pairs of elements, the first element names
the property, the second defines its value.

@table @code
@item :group @var{group}
Specifies the parent customization group of this group.  The value of
this key is not evaluated.

@item :require @var{struct}
Before displaying the customization UI for this group, @code{require}
the structure @var{struct}.  This guarantees that all customizable
variables will be known at display time.  The value of
this key is not evaluated.

@item :layout @var{symbol}
Use a particular UI widget to display this group.  The value is a
symbol, one of:

@table @code
@item single
Holds a single customizable item.
@item vbox
Holds any number of customizable items, arranging them vertically.
This is the default.
@item hbox
Holds any number of customizable items, arranging them horizontally.
@item frame
Embed the items in a vbox in a frame.
@item keymaps
Use a special UI widget for customizing keymaps.
@end table

The value of this key is not evaluated.
@end table

This macro also creates an interactive function named
@code{customize:@var{group}} allowing the GUI to be invoked to
configure the new group.

While @code{defgroup} is a macro, there is a corresponding
@code{custom-declare-group} function.
@end defmac

@defmac defcustom variable value documentation &rest keys
The first three arguments are analogous to the @code{defvar} special
form, they declare a special variable stored in the symbol
@var{variable}, whose value is set to @var{value} if the variable is
currently unbound, with a documentation string @var{documentation}.

All other parameters are key-value pairs as with @code{defgroup}. The
possible pairs are as follows:

@table @code
@item :group @var{group}
Specifies the customization group that this variable is a member of.
This is a list of symbols, indicating a series of nested groups, e.g.,
@code{(workspace edge-flip)}.  A variable in a top-level customization
group can also be specified as a plain symbol, e.g., @code{workspace}.
The value of this key is not evaluated.

@item :type @var{type}
Specifies the required type of the variable. The current possibilities
are:

@item @code{(symbol [@var{option} @dots{}])}
A symbol.  The UI looks for a symbol property @code{:options} and
interprets it as the list of valid symbols to select from.  The
@var{option} arguments allow you to define a list at eval time.  It is
also possible to change this list at run time by changing the custom
symbol's @code{:options} property; see the access functions
@code{custom-add-options} and @code{custom-set-options} for more
information.

@item @code{(choice @var{option} @dots{})}
One of the @var{option} elements.  Each @var{option} is a symbol.
Unlike the @code{symbol} type, there is no expectation that this list
will change at run-time.

@item @code{string}
An arbitrary string.

@item @code{(number [[@var{min}] @var{max}]}
Integer number.  Two additional arguments specify the minimum and
maximum allowed values for the integer.  One additional argument
specified the maximum allowed value; the minimum defaults to zero.
Zero additional arguments implies no minimum nor maximum.

@item @code{boolean}
True (@code{t}) or false (@code{nil}) value.

@item @code{color}
A color.

@item @code{font}
A font name.

@item @code{file}
A file name.

@item @code{program}
A file name that must be an executable program.

@item @code{command}
A Sawfish command.

@item @code{event}
A Sawfish event.

@item @code{keymap}
A Sawfish keymap.

@item @code{frame-style}
The name of a defined Sawfish frame style.

@item @code{icon}
An X icon.

@item @code{modifier-list}
A list of X modifier keys.

@c @item @code{workspace-geometry}
@c A @code{(@var{columns} . @var{rows})} pair.

@end table

Except where specified, the values of these keys are not evaluated.

@table @code
@item :require @var{feature}
Denotes that the feature @var{feature} must be loaded if the variable
is set to a non-@code{nil} value by user customizations.  This is
necessary because customization options are loaded on startup, possibly
before the modules that define them.
The value of this key is not evaluated.

@item :allow-nil @var{bool}
Specifies whether the variable may be @code{nil}, instead of a member
of its actual type. This is only supported by the @code{string},
@code{symbol}, @code{font} and @code{color} types.

@item :set @var{function}
Specifies that the variable must be set by calling @var{function}
instead of the default @code{custom-set-variable}. The function should
accept three arguments: @code{(@var{variable} @var{value} &optional
@var{require})}.

The usual action of this function is to translate the value into the
correct type, then call @code{custom-set-variable}. This translation is
necessary since many of the UI widgets accept strings representing more
complex types (i.e. a color's name, instead of the actual object)

@item :get @var{function}
Provides a function for reading the current value of the variable.
Should return a value that's acceptable to the UI widget associated
with the variable. Called with a single argument, the symbol containing
the variable.

@item :before-set @var{function}
@itemx :after-set @var{function}
Functions called both immediately before and after setting the value of
the variable. Called with a single parameter: the variable itself.

@item :range (@var{min} . @var{max})
The allowed range for numeric variables.  If @var{min} is @code{nil} the
the default minimum allowed value is zero; if @var{max} is @code{nil}
then the default maximum is unbounded.  This is obsolete, since the
@code{:number} type now supports range declarations.
The value of this key is not evaluated.

@item :tooltop @var{string}
A tooltip that appears when the user's mouse hovers over the widget
item.

@item :depends @var{symbol}
This widget item is only settable when the symbol-value for
@var{symbol} is non-nil.

@end table

While @code{defcustom} is a macro, there is a corresponding
@code{custom-declare-variable} function.
@end defmac

Note that where necessary the types themselves define default
@code{:set}, @code{:get} and @code{:widget} values that may be
overridden by values in the @code{defcustom} call. Usually, however,
this will not be necessary.

Consider the following example:

@lisp
(defgroup move "Move/Resize")

(defcustom move-outline-mode 'opaque
  "The method of drawing windows being moved interactively."
  :type (set opaque box)
  :group move)

(defcustom move-snap-epsilon 8
  "Proximity in pixels before snapping to a window edge."
  :group move
  :type (number 0 64))
@end lisp

@noindent
This defines a group and two customization options.

There are two special accessor functions to make it easier to deal
with lists of allowed symbols.

@defun custom-add-option variable option
Add symbol value @var{option} to the list of symbols that can be
stored in @var{variable}.  The new option goes on the end of the
list.
@end defun

@defun custom-get-options variable
Return the list of symbols that can be stored in @var{variable}.
@end defun

@node Customization Files, Customized Variable Status, Defgroup and Defcustom, Customization
@section Customization Files
@cindex Customization files
@cindex Files, customization

@defvar custom-user-file
User configuration settings are stored in the file referenced by this
variable.  While this file contains valid Rep forms, users should not
edit it directly: Sawfish will overwrite the file's contents each time
a customization is made through the GUI.

By default, this variable is set to @code{"~/.sawfish/custom"}.  The
@code{--custom-file} command-line option sets it to a different file
on program startup.
@end defvar

@defvar custom-default-file
Default customization settings are stored in the file referenced by
this variable.  These settings are only applied if the user has no
personal settings.  By default, this variable is set to
@code{"sawfish/wm/custom-defaults.jl"} relative to the
@code{sawfish-lisp-lib-directory} directory.
@end defvar

@defun custom-load-user-file
If the file referenced by @code{custom-user-file} exists, load it.
Otherwise if @code{custom-default-file} is non-nil, interpret it as a
filename and load it.
@end defun

@node Customized Variable Status,  , Customization Files, Customization
@section Customized Variable Status

To get information about a customizable variable, you can use the
following functions.

@defun variable-customized-p symbol
Returns true if @var{symbol} has been customized by the user, false
otherwise.
@end defun

@defun variable-declared-p symbol
@defunx variable-default-value symbol
The @code{variable-declared-p} function returns true if the variable
named @var{symbol} has a default value declared for it, false
otherwise.  The @code{variable-default-value} function returns the
default value of that variable, or nil if no such default value
exists.
@end defun

@defun variable-type symbol
Returns the customizable type of the variable named @var{symbol}.
@end defun

@node Window Frames, Viewports, Customization, Top
@chapter Window Frames
@cindex Window frames
@cindex Frames, of windows

Perhaps one of the most important features of a window manager is its
ability to decorate client windows, typically seen as an added border,
and then to allow the window to be manipulated through user input on
the border.

Sawfish provides an extremely flexible method of decorating windows,
the look and feel of the border may be specified completely. Also, no
limits are placed on which windows are given which borders, if
necessary a completely different border could be dynamically created
for each window!

@menu
* Frame Basics::
* Frame Part Classes::
* Frame Part Definition::
* Frame Functions::
* Frame Types::
* Frame Styles::
* Themes::
* Removing Frame Parts::
@end menu

@node Frame Basics, Frame Part Classes, , Window Frames
@section Frame Basics
@cindex Frame basics
@cindex Window frames, basics

The @dfn{frame} of a client window is defined as all decorations added
by the window manager. Usually these decorations will be immediately
adjacent to the outer edges of the window, but there is no requirement
to use this model.

In Sawfish, each window frame is constructed from a list of @dfn{frame
parts}, conceptually rectangular objects with a specified position
relative to the edges of the client window. When shaped images are used
to define frame parts, they are still thought of as being rectangular,
just with some pixels missing from the display.

Each frame part has a list of attributes associated with it, these
include items defining the background of the part (i.e. a color or an
image), and items defining the foreground of the part (i.e. probably
some kind of text, with a color, font, etc@dots{}). Non-visual
attributes may also be defined, such as, for example, the keymap
mapping events occurring in the part to Lisp commands to execute
(@pxref{Keymaps}).

So a window frame is defined in Lisp as a list of frame part
definitions (@pxref{Frame Part Definition}). These frame parts are
added to the client window (in the order they are defined, so later
frame parts are above earlier parts at the same position), to produce
the entire window frame.


@node Frame Part Classes, Frame Part Definition, Frame Basics, Window Frames
@section Frame Part Classes
@cindex Frame part classes
@cindex Window frames, frame part classes
@cindex Classes, of frame parts

Although one of the aims of Sawfish is to provide as much flexibility
as possible, this can sometimes be detrimental to the overall
experience. For example, it would be easier for the user if all themes
use consistent keymaps and cursor images in conceptually similar parts
of window frames. That is, it would be better if all close buttons had
the same mouse button bindings and the same mouse cursor displayed when
the pointer is over them.

To achieve this, Sawfish defines a number of @dfn{classes} of frame
parts, each with several default attributes. When defining a window
frame, the definitions of each part then specifies which class it is a
member of, and inherits the associated default attributes (provided
that it hasn't explicitly specified values for these attributes).

@defvar frame-part-classes
This variable is an association list, associating symbols naming frame
part classes with an association list of default attributes for that
class.
@end defvar

The names of the pre-defined classes are as follows, their meanings
should be self-explanatory:

@code{title}, @code{menu-button}, @code{close-button},
@code{iconify-button}, @code{maximize-button}, @code{top-border},
@code{left-border}, @code{right-border}, @code{bottom-border},
@code{top-left-corner}, @code{top-right-corner},
@code{bottom-left-corner}, @code{bottom-right-corner}.

@noindent
Extra classes can be created by adding to @code{frame-part-classes}.
However, it's likely that more than one theme may need to use the same
class, and that the user may then wish to customize any extra keymaps
used. The @code{def-frame-class} macro should be used to add new
classes, since it handles these situations.

@defmac def-frame-class class alist-form &rest binding-forms @dots{}
Creates a new frame part class named by the symbol @var{CLASS}.

The @var{ALIST-FORM} is evaluated to give an association list defining
attributes for the class. Each key-value pairs is only set if no
existing value exists for that key.

If @var{binding-forms} are given, they will be evaluated when no keymap
already exists for the class. A keymap will be created, and stored in
the variable named @samp{@var{class}-name}. This variable may then be
used within the @var{binding-forms}.
@end defmac

So to define a hypothetical @code{shade-button} class, the following
might be used:

@lisp
(def-frame-class shade-button '((cursor . left_ptr))
  (bind-keys shade-button-keymap
    "Button1-Off" 'toggle-window-shaded))
@end lisp

In some cases it might be valuable to be able to override pre-defined
frame part properties. For example, it might be your preference that
text in window title bars is always blue.

@defun define-frame-class class alist-form &optional with-keymap
Creates a new frame part class named by the symbol @var{class}.

Unlike @code{def-frame-class}, the trailing argument is just a boolean
flag.  This flag only indicates whether to create a keymap for the
class.  Any bindings have to be established through a separate call to
@code{bind-keys}.

The function returns @code{t} if it was able to create and bind the
empty keymap, @code{nil} otherwise.  This allows us to check for
errors.
@end defun

@defvar override-frame-part-classes
Similar to @code{frame-part-classes} except that the properties take
precedence over values defined both in that variable and in the frame
style itself.
@end defvar

The following function may be used to simplify the customization of
these two variables:

@defun set-frame-part-value class key value &optional override
Associate @var{value} with property @var{key} for all frame parts of
class @var{class}.

If @var{override} is non-nil, then the setting is installed in the
@code{override-frame-part-classes} variable, otherwise it's stored in
the @code{frame-part-classes} variable.
@end defun

@noindent
The following example would override the colors of all title bars:

@lisp
(set-frame-part-value 'title 'background
                      '("black" "white" "green" "blue") t)
@end lisp

@noindent
(See the next section for details about what is actually being set
here.)


@node Frame Part Definition, Frame Functions, Frame Part Classes, Window Frames
@section Frame Part Definitions
@cindex Frame part definitions
@cindex Window frames, frame part definitions

Each frame part is defined as an association list (or alist), a list of
cons cells, the car of each cell defines the attribute, the cdr defines
the value given to that attribute. So, for example, the alist
@code{((foo . 1) (bar . 2))} specifies two attributes: @code{foo} with
value @code{1}, and @code{bar} with value @code{2}. @xref{Association
Lists, , Association Lists, librep, The Librep Manual}.

The attributes that may be defined are as follows:

@table @code
@item (class . @var{class})
Specifies the frame part class of the part.

@item (background . @var{data})
@itemx (background . (@var{normal} @var{focused} @var{highlighted} @var{clicked}))
Specifies the background of the part. May be a color, an image, or a
string naming a color. If a single element, then it is used for all
states of the part, otherwise if a list, then each of the four elements
defines the background for that particular state.

If an image is used it will be scaled to the size of the frame part,
unless it's @code{tiled} property is set, in which case it will be
tiled across the frame part.

@item (foreground . @var{data})
@itemx (foreground . (@var{normal} @var{focused} @var{highlighted} @var{clicked}))
Specifies a foreground color or image for the frame part, either for
all states, or for each individual state.

Unlike the @code{background} attribute, by default images are not
scaled when used to define the foreground of a frame part.

@item (scale-foreground . @var{value})
When @var{value} is non-@code{nil}, the foreground image of the frame
part will be scaled to the size of the part.

@item (font . @var{font})
@itemx (font . (@var{normal} @var{focused} @var{highlighted} @var{clicked}))
Specifies the font(s) of the part.

@item (text . @var{value})
Specifies the string to draw in the foreground of the frame part
(unless the @code{foreground} property is an image). Either a string,
or a function, that will be called each time that the part is
refreshed, that will return the string to draw.

@item (x-justify . @var{value})
Defines the horizontal position of the foreground contents of the part
(i.e. the text or foreground image). May be one of the symbols
@code{left}, @code{right} or @code{center}, or a number. If a number it
defines the number of pixels from the left edge if positive, or the
right edge if negative.

@item (y-justify . @var{value})
Similar to @code{x-justify}, but the accepted symbols are @code{top},
@code{bottom} or @code{center} instead.

@item (renderer . @var{function})
This attribute may be used instead of the @code{background} attribute.
When the part needs to be drawn @var{function} will be called with an
image in which to render the background, and the current state of the
part, a symbol @code{focused}, @code{highlighted}, @code{clicked}, or
@code{nil} (for the normal state).

@item (render-scale . @var{value})
This attribute causes the size of the image used with the
@code{renderer} property to be reduced by a factor of @var{value}, an
integer.

@item (left-edge . @var{value})
Defines the position of the left edge of the part, in relation to the
left edge of the client window.

@item (right-edge . @var{value})
Defines the position of the right edge of the part, in relation to the
right edge of the client window.

@item (top-edge . @var{value})
Defines the position of the top edge of the part, in relation to the
top edge of the client window.

@item (bottom-edge . @var{value})
Defines the position of the bottom edge of the part, in relation to the
bottom edge of the client window.

@item (width . @var{value})
Defines the width of the frame part.

@item (height . @var{value})
Defines the height of the frame part.

@item (keymap . @var{value})
Defines the keymap to use when evaluating events originating in this
frame part.

@item (cursor . @var{cursor})
Defines the cursor to display when the mouse is in this part. May be
either a cursor object, or the argument to @code{get-cursor} to create
the required cursor object.

@item (removable . @var{value})
When specified and @var{value} is non-@code{nil}, this frame part may
be removed from the frame without being detrimental to the overall
appearance of the frame. This is only important for button classes,
which may sometimes be removed at the request of the client window.

@item (below-client . @var{value})
When specified and @var{value} is non-@code{nil}, then this frame part
will be displayed beneath the client window. The default action is for
frame parts to be stacked above the client window.

@item (hidden . @var{value})
When specified and @var{value} is non-@code{nil}, don't display this
frame part.

@end table

The values specified for the @code{background}, @code{foreground},
@code{render-scale}, @code{font}, @code{left-edge}, @code{right-edge},
@code{top-edge}, @code{bottom-edge}, @code{width}, @code{height},
@code{cursor}, @code{below-client} and @code{hidden} attributes may
actually be functions. In which case the function will be called (with
a single argument, the window object) when the frame is constructed,
the value returned will be used as the actual value of the attribute.

The coordinate system used for specifying the part's position is
relative to the window edge that the position is defined against.
Positive values count in from the window edge towards the center of the
window, while negative values count out from the edge, away from the
center of the window.

Consider the following example, a solid black title bar that is twenty
pixels high, directly above the client window:

@lisp
`((background . "black")
  (foreground . "white")
  (text . ,window-name)
  (x-justify . 30)
  (y-justify . center)
  (left-edge . 0)
  (right-edge . 0)
  (top-edge . -20)
  (height . 20)
  (class . title))
@end lisp

@noindent
The backquote operator is used since the definition is only mostly
constant, the comma operator inserts the value of the
@code{window-name} variable (a function giving the name of a window)
into the definition; @pxref{Backquoting, , Backquoting, librep, The
Librep Manual}).

This function is then used to dynamically specify the string drawn in
the foreground. The window manager will automatically refresh the
foreground of all frame parts of a window whenever any X property of
that window changes.

Given a framed window, and a particular frame part class, it is
possible to retrieve the values of individual attributes from the
complete list of definitions (including inherited or overrided
definitions).

@defun frame-part-get part property
Returns the value of the property @var{property} for the frame part
object @var{part}.  Returns @code{nil} if no such attribute exists.
@end defun

@defun frame-part-put part prop value
Set the property @var{prop} of frame part @var{part} to @var{value}.
@end defun

@defun frame-part-state part
Return the current state for frame part @var{part}, one of the symbols
@code{focused}, @code{highlighted}, @code{clicked},
@code{inactive-highlighted}, @code{inactive-clicked}, or @code{nil} if
the part is inactive.
@end defun

@node Frame Functions, Frame Types, Frame Part Definition, Window Frames
@section Frame Functions
@cindex Frame functions
@cindex Window frames, functions

@defun set-window-frame window frame-def
Sets the frame of the client window associated with the object
@var{window} to that defined by the list of frame part definitions
@var{frame-def}. If the window is mapped the old frame will be
destroyed and a new frame constructed.
@end defun

@defun window-frame window
Return the list of frame part definitions defining the frame associated
with @var{window}.
@end defun

@defun window-framed-p window
Return @code{t} when @var{window} has been reparented to a frame
created by the window manager.
@end defun

@defun refresh-window window
Refresh all the frame parts belonging to @var{window}.
@end defun

@defun rebuild-frame window
Recreates the window frame associated with @var{window}, from the
previously defined frame definition. All frame parts are reinitialized
and recalibrated.
@end defun

@defun window-frame-dimensions window
Return a cons cell @code{(@var{width} . @var{height})} defining the
dimensions of the frame associated with @var{window}. These will always
be greater than or equal to the dimensions of the client window.

If @var{window} is not framed, then this function returns the same
values as @code{window-dimensions} would.
@end defun

@defun window-frame-offset window
Return a cons cell @code{(@var{x} . @var{y})} defining the offset from
the origin of the client window associated with @var{window} to the
origin of its frame.
@end defun

@defun window-border-width window
Return the width of the border of the window that @var{window}
manages.
@end defun

@defun clicked-frame-part
Return a pointer to the frame part object that was clicked on as part
of the current event.  Returns @code{nil} if no frame part was clicked
on.
@end defun

@defun frame-part-dimensions part
Return a cons cell @code{(@var{width} . @var{height})} of dimensions
for frame part @var{part}.
@end defun

@defun frame-part-position part
Return a cons cell @code{(@var{x} . @var{x})} of the @emph{relative}
position of frame part @var{part} against its window's frame
origin.
@end defun

@defun frame-part-window part
Return the window object associated with this frame part.
@end defun

@defun frame-part-x-window part
Return the X11 window ID associated with this frame part.
@end defun

@defun frame-draw-mutex lock
Called with @var{lock} equal to @code{t}, frame part redraws will be
delayed.  The redraws will take place once the function is called with
@var{lock} set to @code{nil}.
@end defun

@defun map-frame-parts function window
Call @code{(@var{function} @var{part})} on each the frame parts of
@var{window} and return @code{nil}.  If any @var{function} returns
@code{nil}, @code{map-frame-parts} returns @code{nil} immediately.
@end defun

@defun rebuild-frame-part part
Build a new copy of the frame part @var{part} and install the copy in
the owning window, replacing the old part.
@end defun

@defun refresh-frame-part part
The frame part @var{part} will be redrawn at the next opportunity.
@end defun


@node Frame Types, Frame Styles, Frame Functions, Window Frames
@section Frame Types
@cindex Frame types
@cindex Window frames, types

In order to visually differentiate between different types of windows,
several predefined types of window frame exist.

@defun window-type window
Returns a symbol naming the frame type currently associated with
@var{window}.
@end defun

These frame types currently include the following:

@table @code
@item default
The normal frame type. Includes all decorations, both borders and the
title bar.

@item transient
The frame for a transient window. This usually does not include a title
bar, but does have all four borders.

@item shaped
Shaped windows are normally decorated with only a title-bar, since
their boundary is not rectangular it makes no sense to surround them
with a rectangular border.

@item shaped-transient
A combination of the @code{shaped} and @code{transient} types, normally
just a very small title border with no text.

@item shaded
A shaded window (normally just the title bar).

@item shaded-transient
A shaded transient window.

@item unframed
No frame at all, just the client window itself. The predefined
@code{nil-frame} variable contains a null frame that may be used for
this frame type.
@end table

@defun define-frame-type-mapper fun
Function @var{fun} maps from @{@var{window}, @var{frame-type}@} to
@var{frame-type}.

Each time we want to determine a window's frame-type (@code{shaded},
@code{transient}, etc.), we calculate an initial frame type with
@code{window-type} and run the results through each frame type mapper
in sequence (most recent to oldest).  The frame type returned from the
final mapper function is ``the'' frame type.

This sequence of mappers allows us to override window frame types
based on window properties.  For example, any shaded window has to
have @code{shaded} or @code{shaded-transient} type, regardless of what
its normal type is.
@end defun

@defun window-type-add-border type
@defunx window-type-add-title type
@defunx window-type-remove-border type
@defunx window-type-remove-title type
Given a window type of @var{type}, return the closest matching window
type with the given property change.  For example:

@lisp
(window-type-add-title 'unframed)
@result{} 'shaped
@end lisp

@noindent
This is because shaped windows normally have title bars but not
borders, while unframed windows normally have neither.
@end defun

@defun frame-type-menu window
Returns a list of frame types, suitable for use by the graphical
customizer.  The frame type of @var{window} is automatically checked.
@end defun

We provide a function to simplify monitoring of window changes to certain
window states.  This monitoring runs on top of the
@code{window-state-change-hook}.

@defun call-after-state-changed states fun
Arrange for function @var{fun} to be called with arguments
@samp{(window changed-states)} when one of the states defined by the
list of symbols @var{states} has been changed.  @var{States} may also
be a single symbol.
@end defun

@node Frame Styles, Themes, Frame Types, Window Frames
@section Frame Styles
@cindex Frame styles
@cindex Styles, frame
@cindex Window frames, styles

Frame styles are used to encapsulate frames of the different types that
have a single visual appearance. Each frame style associates a name
with a function that creates a frame definition for a particular window
and frame type combination.

Several window properties are used while choosing frame styles:

@defvr {Window Property} frame-style
The user-chosen frame style of the window.  If @code{nil}, Sawfish
will use the default frame style.
@end defvr

@defvr {Window Property} current-frame-style
The current frame style of the window.  This is not set explicitly;
window update functions will change it behind the scenes.
@end defvr

@defvr {Window Property} ignored
When set, the window is not given a frame.
@end defvr

It is possible to edit certain frame styles in place with
@code{sawfish-themer}.

@defun frame-style-editable-p style
Returns @code{t} if @var{style} can be edited interactively,
@code{nil} otherwise.
@end defun

@deffn {Command} edit-frame-style style
Prompts for a frame style (defaulting to the value of @code{default-frame-style}),
and runs @code{sawfish-themer-program} on it.
@end deffn

@defun reload-frame-style name
Reloads the frame style @var{name} from disk if it is already known to
the system.  All windows with that style are reframed.
@end defun

@node Themes, Removing Frame Parts, Frame Styles, Window Frames
@section Themes
@cindex Themes
@cindex Window frames, themes

Themes and frame styles are currently almost synonymous, the slight
difference being that themes provide a mechanism for loading frame
styles from the filing system as they are required. Although it is
possible that themes may include other user-interface settings in a
later version, at the moment it seems unlikely.

When a frame style is requested, if it is not already available (i.e.
if the @code{add-frame-style} function hasn't been called for that
style) then the window manager will attempt to load a theme of the same
name from the filing system.

Each theme is stored in a directory; this directory must have the same
name as the name of the theme itself. Within this directory there must
be a Lisp script named @file{theme.jl} or @file{theme.jlc}. This script
will be evaluated, it should provide a frame style of the same name as
the theme (by calling @code{add-frame-style}).

While the theme script is evaluating the @code{image-load-path}
variable is set to include the theme directory as its first element.
This ensures that any image files stored in the directory can be loaded
using the @code{make-image} function.

Since rep has no module system, any global variables defined within the
theme must be prefixed by the name of the theme to ensure their
uniqueness. For example, in the theme @code{foo}, a variable @code{bar}
would actually be called @code{foo:bar}.

In most cases however, rep's lexical scoping can be used to avoid
declaring any global variables or functions, the only usual exception
is when declaring customization options with @code{defcustom}; these
must be globally visible.

Since themes are generally passed around very casually, sawfish
evaluates all theme code in a very restricted environment; the idea
being that themes should only be able to affect the look of the window
manager. Despite this, it is still possible for malicious themes to
lock, and possibly crash, the window manager; in the first case sending
a @code{SIGINT} signal may unblock it. Hopefully themes are unable to
affect the rest of the user's environment, but there are no
guarantees@dots{}

@defvar theme-load-path
A list of directory names, provides the search path for locating theme
directories. By default this includes the user's theme directory and
the system theme directory.
@end defvar

@defvar user-theme-directory
The name of the user's theme directory, by default
@file{~/.sawfish/themes}.
@end defvar

@defvar system-theme-directory
The name of the directory holding themes from the current Sawfish
version, by default
@lisp
(expand-file-name "../themes" sawfish-lisp-lib-directory)
@end lisp
@end defvar

@defvar site-theme-directory
The name of the directory holding system-wide themes, by default
@lisp
(expand-file-name "../../themes" sawfish-lisp-lib-directory)
@end lisp
@end defvar

@defvar theme-update-interval
Number of seconds between checking if theme files have been modified.
Default 60.
@end defvar

@defvar themes-are-gaoled
If @code{t}, non-nil themes are assumed to be malicious.  They will be
evaluated in a restricted environment.
@end defvar

@node Removing Frame Parts,  , Themes, Window Frames
@section Removing Frame Parts
@cindex Removing frame parts
@cindex Frame parts, removing
@cindex Window frames, removing frame parts

It is often useful to be able to disable certain parts of a window's
frame. For example, a window may hint to the window manager that it
doesn't want a maximize button. Sawfish allows all parts of a
particular class to be disabled or enabled on a window by window basis.
However, not all frame styles will support this (it depends on the
frame part's @code{removable} property, @ref{Frame Part Definition}).

@defun add-frame-class window class
Enable all frame parts that are a member of @var{class} in
@var{window}.
@end defun

@defun frame-class-removed-p window class
Returns @code{t} if the frame part @var{class} has been removed from
@var{window}, @code{nil} otherwise.
@end defun

@defun remove-frame-class window class
Disable all frame parts that are a member of @var{class} in
@var{window} where possible.
@end defun

@node Viewports, Workspaces, Window Frames, Top
@chapter Viewports
@cindex Viewports

It is sometimes useful to have a logical display that is larger than
the computer screen.  This is most often implemented by displaying
only a portion of the logical display at any time.  Sawfish does this
using ``viewports''.

When viewports are enabled, the Sawfish logical display becomes
potentially infinitely large in the two directions ``across'' and
``down'' (to the maximum representable size of integers).  Sawfish
divides this logical display into a potentially infinite grid of
cells.  Each cell of the grid is the same size of the virtual display.

@defvar viewport-dimensions
The current number of viewports across and down the virtual display.
This is a cons cell @code{(@var{across} . @var{down})}.  Defaults to
@code{(1 . 1)}.
@end defvar

@defun set-number-of-viewports width height
Change @code{viewport-dimensions} to have the value
@code{(@var{width} . @var{height})}.
@end defun

Note that cell indices start at zero in each dimension.  Indices are
never negative.

@menu
* Switching Viewports::
* Windows and Viewports::
@end menu

@node Switching Viewports, Windows and Viewports, Viewports, Viewports
@section Switching Viewports

A user switches viewports by telling Sawfish to move the physical
display from cell to cell.  On a cell change, windows in previous
cells are removed, and windows in the current cell appear.  Windows
that span two or more cells will appear in each cell, appropriately
displaced.

@defun screen-viewport
Returns the currently displayed viewport as a pair @code{(@var{x},
@var{y})}.
@end defun

@defun set-screen-viewport col row
Change the physical display to view cell @code{(@var{col},
@var{row})}.
@end defun

@defun move-viewport right down
Move the viewport to see the cell @var{right} slots to the right and
@var{down} slots down.  Either argument may be zero or negative.
@end defun

@defvar viewport-boundary-mode
How to act when switching via @code{set-screen-viewport} to a viewport
that is outside of @code{viewport-dimensions}.  When set to
@code{wrap-around}, it loops in the vertical and horizontal axes
enough times to keep the viewport within the defined dimensions.  When
set to @code{stop}, it refuses to switch to a viewport outside of
@code{viewport-dimensions}.  Defaults to @code{wrap-around}.
@end defvar

@defun warp-viewport x y
Change the position of the physical display, such that location
@code{(@var{x}, @var{y})} is at the top-left of the display.  The
physical display may be showing more than one cell at this point.
All windows are redisplayed as appropriate.
@end defun

@defun set-viewport x y
Change the position of the physical display, such that location
@code{(@var{x}, @var{y})} is at the top-left of the display.  The
physical display may be showing more than one cell at this point.

Unlike @code{warp-viewport}, the change takes place by dividing the
motion into @code{scroll-viewport-steps} steps, and redisplaying after
each step in the motion.
@end defun

@defvr Customizable scroll-viewport-steps
Number of steps in which to divide a viewport change for
@code{set-viewport}.  Each step requires a redisplay.  Defaults to 1,
which causes an instantaneous change to the new viewport.  The
customization limit is 50.
@end defvr

@node Windows and Viewports,  , Switching Viewports, Viewports
@section Windows and Viewports

@defun window-viewport window
Returns a cons cell @code{(@var{col} . @var{row})} of the viewport
holding the top-left corner of @var{window}.
@end defun

@defun window-outside-viewport-p window
Returns true if @var{window} is completely outside the current
viewport in any direction.
@end defun

@defun window-absolute-position window
Returns a cons cell @code{(@var{x} . @var{y})} of the position of
@var{window} in its containing viewport.  The containing viewport may
or may not be the current viewport.
@end defun

@defun set-window-viewport window col row
Move @var{window} to the cell at @code{(@var{col}, @var{row})}.  The
relative position of the window within the cells is preserved.
@end defun

@defun move-window-viewport window col-delta row-delta
Move @var{window} to the cell @var{col-delta} positions across and
@var{row-delta} positions down from its current cell.  The relative
position of the window with its cells its preserved.
@end defun

@defun move-window-to-current-viewport window
Move @var{window} from its existing viewport to the current viewport.
The window's relative position in the existing viewport is preserved
after the move.
@end defun

@defun move-viewport-to-window window
Move the viewport to a cell that shows window @var{window}.  For a
window that spans multiple cells, this function will pick the cell
showing the window's top-left corner.
@end defun

@defvar uniconify-to-current-viewport
When true, windows uniconify to the current viewport, rather than to
the viewport they were iconified on.  Defaults to true.
@end defvar

@node Workspaces, Multi-Head Environments, Viewports, Top
@chapter Workspaces
@cindex Workspaces
@cindex Desktop workspaces

Workspaces provide another way for users to organize their windows in
Sawfish.  Instead of stretching the screen real estate to the right
and down, workplaces stack screens on top of each other.  The user
drills down into the stack, or pops up through the stack, seeing the
appropriate windows in each workspace.

@menu
* Workspace Intervals::			``Interesting'' workspaces
* Workspace Manipulation::		Creating, rearranging, deleting
* Workspaces and Windows::		Adding, removing
* Edge Flipping::			Moving workspaces using the mouse
@end menu

@node Workspace Intervals, Workspace Manipulation, Workspaces, Workspaces
@section Workspace Intervals

While the stack of workspaces conceptually goes from negative infinity
to positive infinity, we normally present only the first non-empty
workspace through the last non-empty workspace to the user.  The
non-empty interval is occasionally re-normalized to start with zero.

We typically refer to workplaces with lower IDs being to the ``left''
of workplaces with higher IDs, as if on a number line.

@defvar current-workspace
The ID of the currently active workspace.  This is an integer.  The
``default'' workspace has ID 0.
@end defvar

@defun workspace-limits
Returns a pair @code{(@var{first-index} . @var{last-index})} defining
the subset of the workspace continuum that is ``interesting'' to the
user (typically, all those that have ever been explicitly created).
@end defun

@defun workspace-id-to-logical space-id &optional limits
Takes an absolute workspace ID and returns its position in the
interval of ``interesting'' workspaces.  If @var{limits} is provided,
it must be a pair @code{(@var{first-index} . @var{last-index})} like
that returned by @code{workspace-limits}.  If it is not provided, the
function uses the result of @code{workspace-limits} directly.
@end defun

@defun workspace-id-from-logical offset &optional limits
Takes an offset position into an interval of ``interesting''
workspaces, and returns the workplace ID at that position.  If
@var{limits} is provided, it must be a pair @code{(@var{first-index}
. @var{last-index})} like that returned by @code{workspace-limits}.
If it is not provided, the function uses the result of
@code{workspace-limits} directly.
@end defun

@defun popup-workspace-list
Display the menu containing the list of all workspaces.
@end defun

@defun workspace-menu
Returns a list of workspaces, suitable for display in a menu.
@end defun

@defvr Customizable workspace-names
A list of workspace names.  When displaying the workspace menu, the
first @var{N} workspaces use the corresponding list elements as their
display names (where @var{N} is the length of the list).  Normally
they get the display name @samp{space N} for some value of N.
@end defvr

@node Workspace Manipulation, Workspaces and Windows, Workspace Intervals, Workspaces
@section Workspace Manipulation

Sawfish has various functions to create, rearrage and delete
workspaces.  Windows in a deleted workspace are not lost; they are
moved to another workspace.

@defun select-workspace space &key dont-focus force
Activate workspace @var{space}, making it current.

By default in @code{enter} and @code{click} focus modes, the most
recently used window will receive focus.  The caller can disable this
behavior by passing a true @var{dont-focus} keyword argument.

If the @var{force} keyword argument is true, we will go through the
activation process even if @var{space} already is current.
@end defun

@defun select-workspace-from-first count
Select the workspace in position @var{count} from the list of
``interesting'' workspaces.
@end defun

@defun select-workspace-and-viewport space col row
Select workspace @var{space} and then switch to viewport
@code{(@var{col}, @var{row})} in that workspace.
@end defun

@defun insert-workspace &optional before
Insert a new workspace, returning its index.  The new index appears
before the workspace indicated by @var{before}, or the current
workspace if @var{before} is @code{nil}.
@end defun

@defun insert-workspace-after
Create a new workspace following the current workspace.
@end defun

@defun insert-workspace-before
Create a new workspace preceeding the current workspace.
@end defun

@defun move-workspace space count
Move the workspace @var{space} @var{count} positions forward, or
@var{count} positions backwards if @var{count} is negative.
@end defun

@defun move-workspace-forwards &optional count
Move the current workspace one place to the right (or @var{count}
places to the right if @var{count} is defined).
@end defun

@defun move-workspace-backwards &optional count
Move the current workspace one place to the left (or @var{count}
places to the left if @var{count} is defined).
@end defun

@defun next-workspace count
@defunx previous-workspace count
Switch from the current workspace (index @var{i}) to the workspace
@var{i}+@var{count}.  The @code{previous-workspace} function is
identical to @code{(next-workspace (- @var{count}))}.

These functions do not have default values for their @var{count}
arguments.
@end defun

@defun remove-workspace &optional index
Remove workspace @var{index} (or the current workspace if @var{index}
is @code{nil}).  All windows in that workspace are moved to the next
workspace @var{index}+1.  This will change the set of ``interesting''
workspaces.
@end defun

@defun merge-next-workspace
Delete the current workspace.  Its member windows are relocated to the
next workspace.
@end defun

@defun merge-previous-workspace
Delete the current workspace.  Its member windows are relocated to the
previous workspace.
@end defun

@defun set-number-of-workspaces wanted
Add or remove workspaces until the number of ``interesting''
workspaces is equal to @var{wanted}.

When adding workplaces, the new workplaces get indices higher than any
existing indices.  When removing workplaces, the lowest workplaces are
always chosen for removal (their windows are merged into the new
lowest-index workspace).
@end defun

@defvar lock-first-workspace
When true, preserve the outermost empty workspaces in the pager.
Don't quietly remove them when they become empty.  Defaults to true.
@end defvar

@node Workspaces and Windows, Edge Flipping, Workspace Manipulation, Workspaces
@section Workspaces and Windows

Workspaces do not need to have windows assigned to them, but most
operations with workspaces involve adding and removing windows.

@defun all-workspaces
Returns a list of indices for all workspaces that contain windows.
Sticky windows appear in the current workspace.
@end defun

@defun workspace-empty-p space
Returns true if workspace @var{space} contains zero (non-sticky)
windows.
@end defun

@defun delete-empty-workspaces
Delete any workspaces that don't contain any windows.
@end defun

@defvar workspace-boundary-mode
How to act when passing the first or last workspace, one of @code{stop},
@code{wrap-around} or @code{keep-going}.  Defaults to @code{stop}.
@end defvar

Each window can be a member of any (positive) number of workspaces;
their @code{workspaces} property contains a list of workspace ids.
Sticky windows appear on all workspaces, and have their @code{sticky}
property set (with a null @code{workspaces} property).  If Sawfish
begins managing a window with its @code{workspaces} property set, then
the window is added to those workspaces automatically.

@defun window-in-workspace-p window space
Returns true if @var{window} is a member of workspace @var{space},
false otherwise.
@end defun

@defun window-appears-in-workspace-p window space
Returns true if @var{window} appears in workspace @var{space}, false
otherwise.  To appear, @var{window} has to be visible, but it can
either be assigned to the workspace or be sticky.
@end defun

@defun windows-share-workspace-p window1 window2
Returns true if @var{window1} and @var{window2} are members of at
least one common workspace.
@end defun

@defun nearest-workspace-with-window window space
Returns the nearest workspace to @var{space} that contains
@var{window}.
@end defun

@defun workspace-windows &optional space include-iconified
Returns a list of all windows that are members of the current
workspace (or @var{space} if it is not @code{nil}).  The list normally
does not contain iconified windows, but they can by included by
specifying a true @var{include-iconified} argument.
@end defun

@defun popup-window-menu
Display the menu of all managed windows.
@end defun

@defun move-window-to-workspace window old new &optional was-focused
Move @var{window} from workspace @var{old} to workspace @var{new}.

We need the old workspace as an explicit argument because a window can
be in more than one workspace.  The function does the right thing if
the window already appears in workspace @var{new}.

If @var{was-focused} is true and the window is visible, it gets the
input focus in the new workspace.
@end defun

@defun copy-window-to-workspace window old new &optional was-focused
Arrange it so @var{window} appears in both @var{old} and @var{new}
workspaces.

If @var{was-focused} is true and the window is visible, it gets the
input focus in the new workspace.
@end defun

@defun send-to-next-workspace window count &optional copy select
Move the window @var{count} workspaces to the right.  @var{Count} does
not default to one.

The window is normally removed from the current workspace (if it is in
that workspace), or from the first workspace it belongs to.  Supplying
a true @var{copy} argument causes Sawfish to copy the window instead.

If @var{select} is true, then we switch to the destination workspace.
If the moved window had input focus before the move, it will have
input focus after the move as well.
@end defun

@defun send-to-previous-workspace window count &optional copy select
Move the window @var{count} workspaces to the left.  @var{Count} does
not default to one.

The window is normally removed from the current workspace (if it is in
that workspace), or from the first workspace it belongs to.  Supplying
a true @var{copy} argument causes Sawfish to copy the window instead.

If @var{select} is true, then we switch to the destination workspace.
If the moved window had input focus before the move, it will have
input focus after the move as well.

This is identical to @code{(send-to-next-workspace window count copy select)}.
@end defun

@defun copy-to-next-workspace window count select
Copy the window @var{count} workspaces to the left.  @var{Count} does
not default to one.

If @var{select} is true, then we switch to the destination workspace.
If the moved window had input focus before the move, it will have
input focus after the move as well.

This is identical to @code{(send-to-next-workspace window count t select)}.
@end defun

@defun copy-to-previous-workspace window count &optional select
Copy the window @var{count} workspaces to the right.  @var{Count} does
not default to one.

If @var{select} is true, then we switch to the destination workspace.
If the moved window had input focus before the move, it will have
input focus after the move as well.

This is identical to @code{(send-to-previous-workspace window count t select)}.
@end defun

@defun send-window-to-workspace-from-first window count &optional copy select
Move @var{window} to the workspace at position @var{count} in the
``interesting'' list.

The window is normally removed from the current workspace (if it is in
that workspace), or from the first workspace it belongs to.  Supplying
a true @var{copy} argument causes Sawfish to copy the window instead.

If @var{select} is true, then we switch to the destination workspace.
If the moved window had input focus before the move, it will have
input focus after the move as well.
@end defun

@defvar workspace-send-boundary-mode
How to act when passing the first or last workspace, while moving a
window.  One of @code{stop}, @code{keep-going}, @code{wrap-around}.
Defaults to @code{stop}.
@end defvar

@defun delete-window-instance window
Remove the copy of @var{window} on the current workspace.  If this is
the last instance remaining, then delete the actual window.  Note that
this behavior differs from the merging that happens when you delete a
workspace.
@end defun

@defun map-window-workspaces fun window
Map function @var{fun} over all workspaces containing @var{window}.
@end defun

When a window appears on more than one workspace, some of its
properties may be swapped in and out on demand when the current
workspace is changed.

@defvar workspace-local-properties
Window properties whose values may differ on differnet workspaces.
Defaults to the empty list.
@end defvar

@defvar add-swapped-properties props
Add all properties in the list @var{props} to
@var{workspace-local-properties}.
@end defvar

It is possible to hide all ``normal'' windows across workspaces.
``Normal'' in this case excludes desktop windows and dock windows, but
includes sticky and ignored windows.  The hidden windows are no longer
considered ``viewable'' according to @code{window-viewable-p}.

@defun show-desktop
Hide all windows except the desktop and dock windows.
@end defun

@defun hide-desktop
Undo the effects of the @code{show-desktop} command.
@end defun

@defun showing-desktop-p
Return true if non-desktop and non-dock windows are hidden, false
otherwise.
@end defun

@node Edge Flipping,  , Workspaces and Windows, Workspaces
@section Edge Flipping

Sawfish provides a way to flip between workspaces (or viewports)
automatically by moving the mouse to the edge of the screen.  The
technique is called ``edge flipping''.

These definitions are stored in the @code{sawfish.wm.ext.edge-flip}
structure.  They can only be enabled through the customization
interface.

@defvr Customizable edge-flip-enabled nil
When true, select the next desktop when the pointer hits screen edge.
Defaults to false.
@end defvr

@defvr Customizable edge-flip-type
Indicates what is selected when hitting the screen edge.  Must be one
of @code{viewport} or @code{workspace}.  Defaults to @code{workspace}.
@end defvr

@defvr Customizable edge-flip-only-when-moving
When true, Sawfish only flips when the user is interactively moving a
window.  Defaults to false.
@end defvr

This variable is not customizable, but it can be edited.

@defvar edge-flip-delay
Milliseconds to delay before edge flipping.  Defaults to 250.
@end defvar

Flippers are implemented as invisible windows on the edges of the
display (the windows overlap at the corners).  When the pointer moves
over any of these windows, Sawfish generates @code{enter-flipper-hook}
and @code{leave-flipper-hook} events.

Programmers can add their own callbacks to perform other actions with
the flippers.  This depends on manually enabling the flippers, using
the following functions in the @code{sawfish.wm.util.flippers}
structure.  Note that you may have to manually remove the
@code{edge-flip-enter} and @code{edge-flip-leave} callbacks from the
hooks before adding your own callbacks.

@defun enable-flippers
Add edge windows used to implement flipping.
@end defun

@defun disable-flippers
Remove the edge windows used to implement flipping.
@end defun

@node Multi-Head Environments, Window Placement, Workspaces, Top
@chapter Multi-Head Environments
@cindex Multi-head environments
@cindex Environments, multi-head
@cindex Monitors, multiple

Sawfish has special functions to support environments with multiple
monitors displaying a single logical screen (as provided by Xinerama).

@defun find-head x y
Return a ID for the display head that point (@var{x}, @var{y}) is in.
The return value is an integer; the default head has ID zero.  Returns
@code{nil} if it cannot determine the head from @var{x} and @var{y}.
@end defun

@defun head-count
Return the number of display heads on the machine.
@end defun

@defun head-dimensions id
Return the cons cell @code{(@var{width} . @var{height})} of the
dimensions of the display head indicated by @var{id}.  @var{Id} must
be a non-negative integer.  Without Xinerama support, @var{id} must be
zero and the function returns the screen size.
@end defun

@defun head-offset id
Return the cons cell @code{(@var{x} . @var{y})} of the
dimensions of the display head indicated by @var{id}.  @var{Id} must
be a non-negative integer.  Without Xinerama support, @var{id} must be
zero and the function returns @code{(0 . 0)}.
@end defun

@defun pointer-head
Return the ID of the head containing the mouse pointer.
@end defun

@defun current-head &optional window
Return the ID of the head containing the window with input focus.  If
@var{window} is supplied and a window, return the head containing that
window.  If @var{window} is supplied and @var{nil}, return
@code{(pointer-head)}.
@end defun

@defun current-head-dimensions &optional window
Return a cons-cell defining the size in pixels of the current head
(that containing the window @var{window}, or the pointer if
@var{window} is false).  Returns the screen dimensions if no such head
can be identified.
@end defun

@defun current-head-offset &optional window
Return a cons-cell defining the origin of the current head (that
containing the window @var{window}, or the pointer if @var{window} is
false).  Returns @code{'(0 . 0)} if no such head can be identified.
@end defun


@node Window Placement, Popup Menus, Multi-Head Environments, Top
@chapter Window Placement
@cindex Placement of windows

Sawfish supports multiple ways of placing new windows on the display.
There is a ``current'' placement mode for normal windows, and another
mode for transient windows.

@defvar place-window-mode
A symbol indicating the method of placing normal windows.  This
defaults to @code{top-left}.
@end defvar

@defvar place-transient-mode
A symbol indicating the method of placing transient windows.  This
defaults to @code{centered-on-parent}.
@end defvar

@defun placement-mode name
Return the placement mode object corresponding to @var{name}.
@end defun

@defvar placement-modes
List of names of all placement modes.  Sawfish 1.3 ships with the
following placement modes:

@itemize @bullet
@item @code{randomly}
The new window is placed at a random location on the screen.

@item @code{interactively}
Prompt the user to select a position with the mouse.  The new window
is created such that its top-left corner is at that position.

@item @code{centered}
The new window is created at the center of the screen.

@item @code{centered-on-parent}
The new window has a parent, it is centered on that parent.  If the
new window instead has a focused window in the same group, it is
centered on that focused window.  Otherwise the new window is simply
@code{centered}.

@item @code{under-pointer}
Create the new window so that it's under the pointer, without going
off the edge of the screen.

@item @code{first-fit}
@item @code{best-fit}
Look for positions where the new window would have a small overlap
area with already visible windows.  The @code{first-fit} algorithm
uses the first ``good'' position found.  The @code{best-fit} algorithm
looks at all possible positions and picks the best of them.

@item @code{best-fit-group}
As @code{best-fit}, but the new window is only checked for overlap
with other windows in its group.

@item @code{first-fit-or-interactive}
As @code{first-fit}, but if Sawfish cannot find a ``good'' position,
it falls back to @code{interactively} mode.

@item @code{stagger}
Attempts to place each new window below and to the right of the
previous window.  See @code{stagger-placement-step}.

@item @code{top-left}
Interpret the top-left to bottom-right screen diagonal as a series of
slots, each of which may have a window.  Find the first empty slot and
place the window there.  @emph{Sawfish will shrink the window to
prevent it from going past the right or bottom edge, or even beneath a
special window like a panel.}  If Sawfish is not allowed to shrink the
window enough to prevent this, it instead places the window randomly.

@item @code{off-center}
Tries to put windows in the center of the screen, but in such a way
that the newly placed window doesn't fully obscure an existing
window.

This is to handle the case where two windows of the same size are
created one after the other, so that the user is sure to see (at least
part of) both windows.

@item @code{none}
Make no changes to the window's position.  The window remains wherever
the X server placed it initially.
@end itemize

@end defvar

In all of these placement modes, the mode is responsible for taking
the window object as an argument, and manipulating its position with,
e.g., @code{move-window-to}.

The window to be placed avoids overlapping with already existing
``avoided'' windows (@pxref{Avoided Windows}), unless
the position is explicitly specified by coordinates, or placement mode
@code{interactively} is used.

@defvar stagger-placement-step
In @code{stagger} placement mode, the distance down and to the right
from the previously placed window to the new one.  This is measured
in pixels.
@end defvar

There are two circumstances in which Sawfish will place a window:
either the window has just been created, or Sawfish has begun managing
the window's display.  In the latter case, the window will have the
@code{placed} property.

@defvar ignore-program-positions
When @code{t}, program position size hints are not considered when
placing windows.
@end defvar

You can define your own placement modes.

@defun define-placement-mode name fun &keywords for-normal for-dialogs
Define a new window placement mode called @var{name} (a symbol).  The
function @var{fun} will be called with a single argument when a window
should be placed using this mode.  The single argument is the window
to be placed.

If the @var{for-normal} keyword is @code{t}, then this placement mode
is marked as valid for @code{place-window-mode}.  The same applies to
@var{for-dialogs} and @code{place-transient-mode}.
@end defun

@defun autoload-placement-mode name module-name &keywords for-normal for-dialogs
Define placement mode @var{name} (a symbol) to be loaded from
structure @var{structure-name} (a symbol) when first referenced.  The
@var{keyword-args} are passed along to the call to
@code{define-placement-mode} that creates the placement mode.
@end defun

@node Popup Menus, Events, Window Placement, Top
@chapter Popup Menus
@cindex Popup menus
@cindex Menus, popup

Popup menus are one of the two main methods through which the user may
invoke Lisp code (the other is via keymaps, @pxref{Keymaps}). The
@code{popup-menu} function is invoked with a list of menu item
definitions and the associated Lisp function to call for each item.
This starts a subprocess to display the menu, then at a later date the
chosen menu item is received and evaluated.

Each menu item is specified by a list, the first element of which is a
string providing the label for the menu item, the second element is a
function to be called if that item is selected by the user. If this
function has an interactive specification it will be invoked using the
@code{call-command} function, otherwise @code{funcall} will be used.
Alternatively the second element may be a lisp form to evaluate. So,
for example, a single-level menu could be defined by:

@lisp
(("Item 1" function-1)
 ("Item 2" function-2)
 ()
 ("Item 3" function-3))
@end lisp

@noindent
The null item will create a separator line in the displayed menu.

If the cdr of first element of any item is a symbol, then the rest of
the item is defined by the value of the named variable. If this value
is functional then the definition is found by calling the function.

Consider the following definition:

@lisp
(("Workspaces" . workspace-menu)
 ("Windows" . window-menu)
 ("Programs" . apps-menu)
 ("Customize" . custom-menu)
 ("About..." (customize 'about))
 ()
 ("Restart" restart)
 ("Quit" quit))
@end lisp

@noindent
This is the definition of Sawfish's root menu. We can see that four
submenus are created dynamically by dereferencing variables (in fact,
three of this variables contain functions) (@code{workspace-menu},
@code{window-menu}, @code{apps-menu} and @code{custom-menu}). Note that
these must be special variables, i.e. initially declared using the
@code{defvar} special form.

The @code{apps-menu} variable can thus be used to redefine the
applications menu. The default definition is as follows:

@lisp
(("xterm" (system "xterm &"))
 ("Emacs" (system "emacs &"))
 ("Netscape" (system "netscape &"))
 ("The GIMP" (system "gimp &"))
 ("XFIG" (system "xfig &"))
 ("GV" (system "gv &"))
 ("xcalc" (system "xcalc &")))
@end lisp

@noindent
The @code{system} function simply executes its single argument using
@file{/bin/sh}.

When displaying a menu item, it is possible to also display the
corresponding keyboard shortcut in the menu.

@defvar menus-include-shortcuts
When true, menu items also display key-binding information.  Defaults
to false.
@end defvar

The actual creation of a menu is performed by an auxiliary process,
distributed with Sawfish.  Since the overhead of starting the menu
subprocess may be noticeable on some systems, it is possible to leave
it running between menu requests.

@defvar menu-program
Location of the program implementing Sawfish's menu interface.
@end defvar

@defvar menu-program-stays-running
This variable defines if, and for how long, the menu subprocess is
allowed to remain executing for after the last menu has completed. If
@code{nil}, the program is terminated immediately, if @code{t} it is
left running indefinitely, if an integer then the program will run for
that many seconds (unless another menu is displayed).
@end defvar

The actual interface to invoke the external menu program is hidden in
the @code{popup-menu} function.

@defun popup-menu spec
Displays a menu defined by the list of item definitions @var{spec}.
@end defun

In addition, Sawfish provides various canned menus, and functions to
display those menus.

@defvar root-menu
Contains the root menu definition.
@end defvar

@defun popup-root-menu
Display the main menu.  By default, this is bound to Button2-click on
the root window.
@end defun

@defvar apps-menu
The variable containing the definition of the applications submenu of
the root menu.  The default root menu includes this as a child menu.
@end defvar

@defun popup-apps-menu
Display the applications menu.
@end defun

@defun window-ops-menu
The variable containing the definition of all window operations.
@end defun

@defun popup-window-menu
Display the menu listing all window operations.  This has several
bindings by default.  In particular, clicking on a window's menu
button displays this menu.
@end defun

@defvar window-ops-toggle-menu
A list of flags describing windows, e.g., ``sticky'' or ``shaded''.
This list is displayed in a menu, and by selecting items in this menu
a user can turn the flags on and off for a given window.
@end defvar

@defun add-window-menu-toggle label command &optional predicate
Add additional flags to @code{window-ops-toggle-menu}.  The
@var{command} is a function (or a symbol pointing to a function) that
gets run when the menu item is selected.  If @var{predicate} is
non-nil, it must be a function taking a window as argument.  If
@var{predicate} return true, the menu item will have a check mark next
to it.
@end defun

@node Events, Commands, Popup Menus, Top
@chapter Events
@cindex Events

Events refer to input events from X that the window manager receives,
either for the root window, the window frames it creates, or grabbed
from the client windows themselves. Each event induced by the mouse or
keyboard has a Lisp representation.

@defun eventp object
This function returns @code{t} if its argument is an input event.
@end defun

@menu
* Event Representation::        Objects versus string names
* Event Modifiers::             Meta, Alt, Buttons
* Event Actions::               Keys and Clicks
* Event Matching::
* Synthetic Events::            Creating events that seem real
@end menu

@node Event Representation, Event Modifiers, Events, Events
@section Event Representation

Each input event is represented by a cons cell containing two
integers, and these integers encode the event. The encoding is opaque;
the only way to access an event meaningfully is via the functions
provided.

Each event has a string representation, called its ``name''.  Names
consist of zero or more modifiers, followed by a key or mouse action
indicator.  Modifiers are separated from succeeding elements by
hyphens @samp{-}.  For example, hitting @key{x} while holding down the
@key{Control} and @key{Meta} keys would generate an event named
@key{Control-Meta-x}.  This notation is designed to closely match
Emacs Lisp's notation.

Functions are available to convert between the name of an event and the
actual event itself, and vice versa.

@defun lookup-event event-name
Create and return a new input event whose name is @var{event-name}.

@lisp
(lookup-event "C-x")
    @result{} (120 . 65540)

(lookup-event "C-M-Button1-Click1")
    @result{} (1 . 131340)
@end lisp
@end defun

@defun event-name event
This function returns a string naming the input event @var{event}.

@lisp
(event-name (lookup-event "C-x"))
    @result{} "C-x"
@end lisp
@end defun

@node Event Modifiers, Event Actions, Event Representation, Events
@section Event Modifiers
@cindex Event Modifiers
@cindex Modifiers, for events

Sawfish event modifiers are copied directly from the standard X
modifiers:

The standard X modifier names are provided, as well as four special
modifiers @key{Meta}, @key{Alt} @key{Hyper} and @key{Super} that are
mapped to the keysyms of the same name.

The following table lists the possible modifier prefixes:

@table @key
@item Control
@itemx C
The control modifier

@item Meta
@itemx M
The meta modifier

@item Alt
@itemx A
The alt modifier

@item Shift
@itemx S
The shift modifier

@item Hyper
@itemx H
The hyper modifier

@item Super
@itemx s
The super modifier; note that this is a lowercase @kbd{s}

@item Mod@var{k}
The standard X modifiers, for @var{k} between 1 and 5

@item Any
A special modifier that matches any set of modifiers in events.
@xref{Event Matching}.

@item Release
A special modifier that matches key release events, not the default
key press events.  Mouse events never have @key{Release} modifiers;
they have separate actions instead.  @xref{Event Actions}.

@item Button@var{k}
The @var{k}'th mouse button is currently pressed.

@item W
A placeholder ``window manager'' modifier that can be bound to a real
modifier on the fly.  See @code{wm-modifier} below.
@end table

The default Sawfish bindings use the @key{Meta} modifier.  For
convenience, if no X keysym generates @key{Meta}, Sawfish will treat
the first defined modifier of @key{Alt}, @key{Hyper} and @key{Super}
(in that order) as @key{Meta}.  The mapping from keysyms to
modifiers is exposed in the following variables:

@defvar meta-keysyms
A list defining the names of the X keysyms generating the virtual
@samp{Meta} or @samp{M} modifier.
@end defvar

@defvar alt-keysyms
A list defining the names of the X keysyms generating the virtual
@samp{Alt} or @samp{A} modifier.
@end defvar

@defvar hyper-keysyms
A list defining the names of the X keysyms generating the virtual
@samp{Hyper} or @samp{H} modifier.
@end defvar

@defvar super-keysyms
A list defining the names of the X keysyms generating the virtual
@samp{Super} modifier.
@end defvar

There are two functions to manipulate the placeholder ``window
manager'' (@key{W}) modifier.  Unfortunately, these are low-level
functions that operate on integer encodings.

@defun wm-modifier
Return the current value (an integer) of the placeholder ``window
manager'' (@key{W}) modifier.
@end defun

@defvr {Customizable} wm-modifier-value
An integer encoding zero or more modifier keys that form the
placeholder ``window manager'' (@key{W}) modifier.  Setting this value
through the customization UI automatically calls
@code{set-wm-modifier}.
@end defvr

@defun set-wm-modifier modifiers
Set the value of the placeholder ``window manager'' (@key{W}) modifier
to @var{modifiers} (an integer).
@end defun

@node Event Actions, Event Matching, Event Modifiers, Events
@section Event Actions

Sawfish recognizes keyboard actions and mouse actions.

@table @asis
@item Key Press
@itemx Key Release
Keys pressed on the keyboard generate one or more key press events,
followed by a key release event.  Bindings normally recognize key
press events only.  To recognize key releases, add a @key{Release}
modifier to the bound event.
@end table

Generally keys have the same names as their X keysyms.  The following
unusual names are worth listing: @samp{SPC}, @samp{TAB}, @samp{RET},
@samp{ESC}, @samp{BS}, @samp{DEL}, @samp{Up}, @samp{Down},
@samp{Left}, @samp{Right}.

For example, pressing the @key{Delete} key while @key{Control} is held
down generates a @kbd{Control-DEL} event, while releasing the @key{a}
key while @key{Hyper} is held down generates a @kbd{H-Release-a}
event.

@table @asis
@item Button Clicks
Button presses generate @key{Click} actions.  If Sawfish receives
several clicks in close succession (less than @code{multi-click-delay}
milliseconds between clicks), the second and third events are
@key{Click2} and @key{Click3}, respectively.  Any further clicks are
simple @key{Click} events.  For consistency, @key{Click1} is a synonym
for @key{Click}.

@item Button Releases
Once the button has been released from a @key{ClickN} action, Sawfish
receives a corresponding @key{OffN} action.  The actions @key{Off} and
@key{Off1} are synonyms.

@item Pointer Motion
Pointer motion generates @key{Move} actions.  The action does not
indicate anything about the pointer position; use e.g.,
@code{query-last-pointer} to find that information.
@end table

@noindent
For example, a single click of the left mouse button with the
@key{Meta} key held would be described as @kbd{M-Button1-Click1}.
After triple-clicking with the @key{Alt} key held down, Sawfish will
receive a @kbd{Alt-Off3} event.

@defvar multi-click-delay
An integer indicating the maximum number of milliseconds between
successive clicks.  Defaults to 250 milliseconds at startup; if
@code{nil}, Sawfish uses 250 milliseconds.
@end defvar

@node Event Matching, Synthetic Events, Event Actions, Events
@section Event Matching
@cindex Event Matching
@cindex Matching, Events

There is a special function that matches event objects.  If the
actions of two event objects are not identical, the events do not
match.  If they are identical, then the events match if the modifiers
are identical, or if one of the modifiers is @key{Any}.
@xref{Event Modifiers}.

@defun event-match ev1 ev2
Returns @code{t} if events @var{ev1} and @var{ev2} match, @code{nil}
otherwise.
@end defun

@node Synthetic Events,  , Event Matching, Events
@section Synthetic Events
@cindex Synthetic Events
@cindex Events, Synthetic
@cindex Events, Synthesizing

It is possible to create an event inside Sawfish that mimics a real
keyboard or mouse event.

@defun synthesize-event event window &optional propagate
Generate a synthetic key press or button press and send it to the X
window bound to the @var{window} object.  This press is automatically
followed by the appropriate release event.

The current pointer position becomes the position of the event.

@var{Event} is either an event object, or the string representation of
an event (such as @code{"A-f"} or @code{"C-M-Button3-Click2"}).
Strings are parsed into event objects before any work is done.
@xref{Event Representation}.

If @var{propagate} is true, the event will propagate up the window
ancestor chain until it is handled.
@end defun


@node Commands, Keymaps, Events, Top
@chapter Commands
@cindex Commands

A @dfn{command} is a Lisp function which may be called interactively,
that is, as a result of being bound to an input event.  To support
this, we mark them with metadata that the runtime system can query.

@menu
* Old-style Command Definition::  Emacs-Lisp style
* New-style Command Definition::  Common-Lisp style
* Interactive Calling Specification::  
* Operations on Commands::	Accessors and the like
* Invoking Commands::           call-commmand, command hooks
* Default Commands::            Sawfish ships with a few commands
@end menu

@node Old-style Command Definition, New-style Command Definition, Commands, Commands
@section Old-style Command Definition

The old-style command declaration syntax looks very much like that of
GNU Emacs Lisp.  Commands are defined like any other function (using
@code{defun}), but the first form in the body must be an
@dfn{interactive declaration}.  This marks that the function may be
called interactively and tells the @code{call-command} function how to
compute the argument values to apply to the command.

The interactive declaration looks like a call to the special form
@code{interactive}, in actual fact this special form always returns
@code{nil} and has no side-effects. The only effect of this form is to
show the @code{call-command} function that the function definition may
be called interactively. The second element of the declaration form
(after the @code{interactive} symbol) defines how the argument values
applied to the command are computed.

The structure of an interactive declaration, then, is:

@lisp
@findex interactive
(interactive [@var{calling-spec}])
@end lisp

When a command is defined this is how it includes the interactive
declaration:

@lisp
(defun some-command (arg1)
  "Optional documentation string."
  (interactive @dots{})
  @dots{}
@end lisp

The @var{calling-spec} is defined in @xref{Interactive Calling
Specification}.

@node New-style Command Definition, Interactive Calling Specification, Old-style Command Definition, Commands
@section New-style Command Definition

The new syntax does not depend on special magic in @code{defun}.
Instead, it uses keyword arguments to indicate the calling
specification and other properties.

@defun define-command name fun #!key spec type doc doc-key class
Define a window managed command called @var{name} (a symbol).  The
function @var{fun} will be called to execute the command.

@var{spec} and @var{type} may be used to define the arguments expected
by the command; @var{spec} is an interactive specification and
@var{type} is a custom-type specification.  @xref{Interactive Calling
Specification}.

@var{doc} is the documentation string associated with the command.
The command-documentation may be stored in the doc file, rather than
in the code itself; if it exists, the @var{doc-key} will be used to
look up the doc file entry.  If both arguments are provided, both will
be stored.  But the @code{command-documentation} function favors the
built-in doc string over the doc file entry.

@var{class} is an annotation for the command.  It allows the
definition to mark the class as @code{'advanced}, for example.  Other
parts of Sawfish can then take advantage of this note.
@end defun

@defun define-command-to-screen name fun #!key spec type doc doc-key class
As @code{define-command}, but any printed output of @var{fun} is sent
to the screen.
@end defun

@defun autoload-command name module #!key spec type doc doc-key class
Record that loading the module called @var{module} (a symbol) will provde a
command called @var{name}.

The keyword values have the same meanings as for
@code{define-command}.  Defining those properties as part of the
autoload provides useful feedback to the user without having to do
loading.
@end defun

@node Interactive Calling Specification, Operations on Commands, New-style Command Definition, Commands
@section Interactive Calling Specification

The @var{calling-spec} argument to @code{interactive} or
@code{define-command} defines the argument values applied to the
command when it is called interactively.  It may be one of:

@itemize @bullet
@item @code{nil} or undefined (i.e. @code{(interactive)})
No arguments are given to the command, this type of interactive
declaration just shows that the function may be called interactively.

@item A string
This is interpreted as zero or more lines (each separated by a newline
character).  Each line defines how to compute one argument value.  The
first one or two characters of each line is a prefix defining exactly
how to compute the argument, the rest of the line is an optional
argument which some prefixes may use.  See below for a list of
prefixes.  A null line produces an argument value of @code{nil}.

@item Anything else
The form is evaluated and expected to return a @emph{list} of
arguments to apply to the command.
@end itemize

The currently available prefixes are,

@table @samp
@item e
The event which caused this command to be invoked.

@item E
The event which caused this command, cooked into a string.

@item p
The prefix argument as a number, this will be 1 if no prefix argument
has been entered.

@item P
The raw prefix argument.

@item t
The symbol @code{t}.

@item %f
The window which currently has the input focus, or @code{nil} if no
window is focused.

@item %w
The result of calling the @code{current-event-window} function.

@item %W
The result of calling the @code{current-event-window} function, or if
this returns @code{nil} or @code{root}, the currently focused window.
@end table

@node Operations on Commands, Invoking Commands, Interactive Calling Specification, Commands
@section Operations on Commands

Once a command has been defined, we can extract certain information
about it.

@defun commandp @var{object}
This function returns @code{t} if its argument may be called interactively.
If @var{object} is a function (i.e. a symbol or a lambda-expression) it
is a command if it contains an interactive declaration

The only other object which is a command is a function call form; the
use of these types of commands is discouraged but they can be useful
sometimes.
@end defun

@defun command-documentation name
Return the documentation for the command @var{name}.  It returns the
first documentation found by looking at (in order): the documentation
property of the command; the doc file entry associated with the doc
key property; or the documentation for the function with the same
name.
@end defun

@defun command-spec name
@defunx command-type name
@defunx command-class name
Return the specification, type or class (respectively) of the named
command.
@end defun

@node Invoking Commands, Default Commands, Operations on Commands, Commands
@section Invoking Commands

When a command is to be invoked, the @code{call-command} function is
used. This builds a list of argument values to apply to the command
(using its interactive declaration) then calls the command.

@defun call-command command &optional prefix-arg
This function calls the command @var{command} interactively. See the
documentation of @code{commandp} above for what constitutes a command.

If the @var{prefix-argument} is non-nil it defines the value of the
@code{current-prefix-arg} variable for this command, normally the value
of this variable would be taken from the global @code{prefix-arg}
variable.

There is a corresponding @code{call-command} command that prompts for
a command to execute.
@end defun

@defun apply-command name &rest args
Call the function underlying the command @var{name}, passing in
@var{args} as the arguments.  This is useful for calling a command in
a non-interactive context.
@end defun

@defvar current-prefix-arg
When invoking an interactive command, this is set to the current
prefix argument.
@end defvar

@defvar this-command
The command currently being called, or @samp{nil} if no command is
being called.
@end defvar

@defvar last-command
The command previously called, or @samp{nil} if there is no such
command.
@end defvar

@xref{Command Hooks}, for hooks run before and after commands.

@node Default Commands,  , Invoking Commands, Commands
@section Default Commands

Sawfish defines several commands by default.

@defun run-shell-command
The command prompts the user for a string, and executes that string as
under @code{system}.
@end defun

@defun quit
@defunx restart
@defunx destroy-window
@defunx kill-client
@defunx no-operation
Calls the function of the same name.  @code{destroy-window} and
@code{kill-client} both take @code{%W} as argument.
@end defun

@node Keymaps, Event Loop, Commands, Top
@chapter Keymaps
@cindex Keymaps

Keymaps are used to associate events with commands. When an event
occurs, the associated command is found and evaluated. A keymap is
simply a list whose first element is the symbol @code{keymap}.

@defun keymapp arg
Returns @code{t} if @var{arg} may be used as a keymap.
@end defun

@defun make-keymap
Returns a newly-created empty keymap.
@end defun

@defun bind-keys keymap &rest bindings
Installs zero or more key bindings into the keymap @var{keymap}, then
returns @var{keymap}.

Each binding is defined by two elements in the list of @var{bindings},
the first defines the name of the input event (or the event itself) and
the second defines the command to be associated with the event.

For example to bind two keys in the keymap @var{keymap}; the event
@kbd{C-f} to the command @code{foo} and the event @kbd{C-b} to the
command @code{bar} the following form would be used,

@lisp
(bind-keys @var{keymap}
 "C-f" 'foo
 "C-b" 'bar)
@end lisp
@end defun

@defun unbind-keys @var{keymap} &rest @var{keys}
Removes the bindings of the events @var{keys} (these may be the names
of the events or the event objects themselves) from the keymap
@var{keymap}.
@end defun

@defun search-keymap event keymap
Search for a binding of the event @var{event} in @var{keymap}. If a
binding is found a cons cell @code{(@var{command} . @var{event})} is
returned.
@end defun

There are several pre-defined keymaps that are always available:

@table @code
@item global-keymap
Keymap containing bindings active anywhere.

@item window-keymap
Keymap containing bindings active when a client window is focused.

@item root-window-keymap
Keymap containing bindings active when the pointer is in the root
window.

@item title-keymap
@itemx border-keymap
Keymaps active in the title and borders of window frames.

@item close-button-keymap
@itemx iconify-button-keymap
@itemx maximize-button-keymap
@itemx menu-button-keymap
@itemx shade-button-keymap
Keymaps active in the standard window frame buttons.

@item override-keymap
Must be a keymap, a symbol, or @code{nil}.  If it is a keymap,
this becomes the keymap in which all lookups occur (overriding the window,
root and global keymaps).  If it is a symbol, Sawfish finds the
symbol's value and tries again.  If it is @code{nil}, Sawfish behaves
normally.

@end table


@node Event Loop, Miscellaneous Functions, Keymaps, Top
@chapter Event Loop
@cindex Event loop

The event loop reads all X events received on any of the windows that
Sawfish is aware off. Many of these events invoke hooks, as described
in @ref{Standard Hooks}. Keyboard and pointer events are translated to
their Lisp equivalents (@pxref{Events}) and then used to scan all
active keymaps for a binding. If a binding is found, the associated
command is invoked through the @code{call-command} function.

The active keymaps are determined as follows:

@itemize @bullet
@item If the variable @code{override-keymap} is non-nil, then this is
the only keymap searched

@item Otherwise three keymaps are searched:

@enumerate
@item the @code{keymap} property of the currently ``clicked'' frame
part if there is one,

@item the @code{keymap} property of the currently focused window

@item the contents of the variable @code{global-keymap}.
@end enumerate
@end itemize

Note that for @code{ButtonRelease} events, the frame part's keymap is
only searched if the pointer is actually within the frame part when the
release event occurs.

If no binding may be found in any of the active keymaps, then the
@code{unbound-key-hook} hook is called. This is an @code{or} type
hook---the first function that returns non-nil will terminate the hook
call.

@defun lookup-event-binding event
Perform the usual binding lookup for the event object @var{object}.
Returns the command found, or @code{nil} if no binding exists.
@end defun

By default, both key-release events, and events that are bound to
modifier keys (e.g. @key{Control_L}), are ignored. However, this
behavior may be changed:

@defvar eval-modifier-events
When non-nil, key events bound to modifier keys are evaluated.
@end defvar

@defvar eval-key-release-events
When non-nil, key-release events are evaluated.
@end defvar

While a command is being evaluated, information about the event that
caused it may be found:

@defun current-event
Return the event which caused the current command to be invoked
@end defun

@defun current-event-string
Returns the string which the current event would usually insert.
@end defun

@defun current-event-window &optional win
Extract the owning window of the current X event (this is a window
object, or the symbol @code{root} for the root window, or @code{nil}
if there is no window or no event).  This is stored internally as the
current event window, and returned.
@c FIXME-DLU: why does this function take a WIN parameter?
@end defun

@defun last-event
Return the previous event which occurred.
@end defun

@defun proxy-current-event window &optional mask propagate
Send the current X event to @var{window}, either a window object, a
numeric window id, or the symbol @code{root}. If a @code{ButtonPress}
event the pointer grab will be released first.

@var{Mask} may be an integer defining the X event mask to pass to the
@code{XSendEvent} function. If not defined, a mask is chosen that would
usually be used to select the type of event being proxied.

@var{Propagate} is a flag (@code{nil}/non-@code{nil}) passed directly
to an underlying @code{XSendEvent} call.  (And if someone would like
to explain what @emph{that} means, please do so @enddots{}
@end defun

@defun allow-events mode
This is a wrapper for the @code{XAllowEvents} function. The @var{mode}
parameter may be one of the following symbols: @code{async-pointer},
@code{async-keyboard}, @code{sync-pointer}, @code{sync-keyboard},
@code{replay-pointer}, @code{replay-keyboard}, @code{async-both},
@code{sync-both}.

Events that have to be grabbed to be received (i.e. all bindings in the
@code{global-keymap} and the @code{window-keymap}) are grabbed
synchronously. This means that no more events will be received until
either the command returns, or @code{allow-events} is called.

This is normally not important, but if the command expects to receive
further events it must call @code{allow-events}. See the interactive
move and resize functions for an example.
@end defun

@defun forget-button-press
Cause the next button press to be treated as a single click event, no
matter how soon it occurs after the prevous button-press event.
@end defun

@defun accept-x-input &optional mask
Handle any X events received. If @var{mask} is non-nil then only events
matching this numeric value are handled (see the X header files for
details).
@end defun

@defun x-events-queued
Returns the number of X events waiting to be handled.
@end defun


@node Miscellaneous Functions, Standard Hooks, Event Loop, Top
@chapter Miscellaneous Functions
@cindex Miscellaneous functions

@menu
* Pointer Functions::
* Grab Functions::
* Display Functions::
* Gradient Functions::
* Other Functions::
@end menu

@node Pointer Functions, Grab Functions, , Miscellaneous Functions
@section Pointer Functions
@cindex Pointer functions
@cindex Functions, pointer

@defun query-pointer &optional from-server
Returns a cons cell @code{(@var{x} . @var{y})} representing the current
mouse pointer position, relative to the origin of the root window.

If there is a mouse update current event, the position is read
directly from that event.  Otherwise it is read from the server.  If
@var{from-server} is non-nil then the position is read directly from 
the server in any case.
@end defun

@defun query-pointer-window
Returns the top-level window under the mouse pointer, or @code{nil} if
the cursor is in the root window.
@end defun

@defun query-last-pointer
Returns a cons cell @code{(@var{x} . @var{y})} representing the second
most recent mouse pointer position, relative to the root window.
@end defun

@defun query-button-press-pointer
Returns @code{(@var{mouse-x} . @var{mouse-y})} representing the mouse
position relative to the root window at the last button-press event.

Use this function to track the displacement of the pointer during a
drag.
@end defun

@defun query-button-press-window
Returns the window that the mouse was in when the button was pressed.
@end defun

@defun warp-cursor x y
Move the mouse pointer to position (@var{x}, @var{y}) relative to the
origin of the root window.
@end defun

@defun warp-cursor-to-window window &optional x y
Move the mouse pointer to position (@var{x}, @var{y}) relative to the
client window associated with object @var{window}.

If @var{x} and @var{y} are @code{nil}, then they are taken as the
top-left corner of the window's frame.

If @code{warp-to-window-enabled} is @code{nil}, this function does
nothing.
@end defun

@defvar warp-to-window-offset
Offset (%) from window edges when warping pointer. A negative number
means outside the left window edge.
@end defvar

@defvar warp-to-window-enabled
When false, disable warping the cursor to windows.
@end defvar

@defvar pointer-motion-threshold
If set to an integer value, a pointer must move by this many pixels on
either axis before Sawfish considers it to have moved.  If the pointer
has not moved by this amount, Sawfish will ignore @code{MotionNotify}
events from X.  The variable defaults to 2 pixels.  If not an integer,
Sawfish assumes a threshold of 0 pixels.
@end defvar


@node Grab Functions, Display Functions, Pointer Functions, Miscellaneous Functions
@section Grab Functions
@cindex Grab functions
@cindex Functions, grab

@defun grab-server
Prevent any other clients from accessing the X server.
@end defun

@defun ungrab-server
After a call to @code{grab-server} this will allow other clients to
access the X server again.

Note that calls to @code{grab-server} and @code{ungrab-server}
@emph{nest}.
@end defun

@defmac with-server-grabbed &rest forms
Evaluate forms with the server grabbed. Releases the grab afterwards.
@end defmac

@defun call-with-server-ungrabbed thunk
Return the result of calling the zero-parameter function
@var{thunk}.  If the server is currently grabbed, ungrab it first,
restoring the original grab status after the call to @var{thunk}
returns.
@end defun

@defun server-grabbed-p
Returns @code{t} if the X server is currently grabbed.
@end defun

@defun grab-pointer &optional window cursor ptr-sync kbd-sync confine-to
Grab the mouse pointer and direct all pointer events to window object
@var{window}.  If @var{cursor} is defined and a cursor object, display
this while the pointer is grabbed.

If @var{window} is a window object corresponding to a
visible window, the grab will be made on its frame.

If @var{window} is an integer, it specifies the window ID of the grab
window.

Otherwise the grab will be made on the root window.  This includes
@var{window} corresponding to a non-viewable window.

@var{Confine-to}, if non-@code{nil}, is a visible window to confine
the pointer to.  It is interpreted similarly to the rules for
@var{window}, except that the ``otherwise'' case is to not confine the
pointer.

If the window id of a non-viewable window was specified for either
@var{window} of @var{confine-to}, the grab will be made on the root
window without confining the pointer.

If @var{ptr-sync} or @var{kbd-sync} is non-@var{nil}, the pointer or
keyboard will be frozen, i.e., the device will not produce events
until either the grab is released or events are re-enabled using
@code{allow-events}.

Returns non-nil if the grab succeeded.
@end defun

@defun ungrab-pointer
Release the grab on the mouse pointer.
@end defun

@defun grab-keyboard &optional window ptr-sync kbd-sync
Grab the keyboard and direct all keyboard events to window object
@var{window}.

If @var{window} is a window object corresponding to a
visible window, the grab will be made on its frame.

If @var{window} is an integer, it specifies the window ID of the grab
window.

Otherwise the grab will be made on the root window.  This includes
@var{window} corresponding to a non-viewable window.

If @var{ptr-sync} or @var{kbd-sync} is non-@var{nil}, the pointer or
keyboard will be frozen, i.e., the device will not produce events
until either the grab is released or events are re-enabled using
@code{allow-events}.

Returns non-nil if the grab succeeded.
@end defun

@defun ungrab-keyboard
Release the grab on the keyboard.
@end defun

@defun call-with-keyboard-grabbed thunk
Call the zero-parameter function @var{thunk} with the keyboard
grabbed.  If unable to grab the keyboard then @var{thunk} won't be
called.
@end defun


@node Display Functions, Gradient Functions, Grab Functions, Miscellaneous Functions
@section Display Functions
@cindex Display functions
@cindex Functions, display

@defun screen-width
Return the width of the root window.
@end defun

@defun screen-height
Return the height of the root window.
@end defun

@defun screen-dimensions
Return the screen dimensions in pixels as a cons cell
@code{(@var{width} . @var{height})}.
@end defun

@defun draw-window-outline mode x y width height
Draw an outline of a window of dimensions (@var{width}, @var{height})
at position (@var{x}, @var{y}) relative to the root window.

@var{mode} is a symbol defining the type of outline drawn, currently it
may only be @code{box} for a 3x3 grid.

Use the @code{erase-window-outline} to erase the grid. Also note that
since these functions draw directly on the root window the server
should be grabbed until the outline is erased.
@end defun

@defun erase-window-outline mode x y width height
Erase a previously drawn outline of a window of dimensions
(@var{width}, @var{height}) at position (@var{x}, @var{y}) relative to
the root window.

@var{mode} is a symbol defining the type of outline drawn, currently it
may only be @code{box} for a 3x3 grid.
@end defun

@defun display-message &optional text attributes
Display the string @var{text} in a window on the screen. If @var{text}
is @code{nil} then any string previously displayed is removed. Returns
the numeric id of the window displaying the message, or @code{nil} if
no message is displayed.

@var{attributes} is an alist specifying how the string should be
displayed; each element of the list is a cons cell @code{(@var{attr} .
@var{value})} associating an attribute @var{attr} (a symbol) with it's
value.

Possible attributes currently include:

@table @code
@item font
The font to use

@item foreground
The color (or color name) to draw the text with

@item background
The color (or color name) to draw the background with

@item x-justify
The justification method for multi-line strings. One of the symbols
@code{left}, @code{right}, or @code{center}

@item spacing
The number of extra pixels of vertical spacing to leave between text
lines.

@item position
A cons cell defining the coordinates at which to display the message
window. The cell is @code{(@var{x} . @var{y})}. @var{x} and @var{y} are
integers or @code{nil} (for centered display). If negative they count
in from the left and bottom edges respectively.

@item head
The head on which to center the message when a position is not specified or
given as nil.  If not provided defaults to the head containing the window that
has the input focus.
@end table
@end defun


@node Gradient Functions, Other Functions, Display Functions, Miscellaneous Functions
@section Gradient Functions
@cindex Gradient functions
@cindex Functions, gradients

The @code{gradient} feature allows color gradients to be drawn in
images. (Evaluate @code{(require 'gradient)} to load this feature.)

@defun draw-vertical-gradient image from to
Draw a vertical color gradient in @var{image}. The color at the top of
the image will be @var{from}, the color at the bottom @var{to}, with a
smooth transition between.
@end defun

@defun draw-horizontal-gradient image from to
Draw a horizontal color gradient in @var{image}, from left to right.
The color at the left of the image will be @var{from}, the color at
the right @var{to}, with a smooth transition between.
@end defun

@defun draw-diagonal-gradient image from to
Draw a horizontal color gradient in @var{image}, from the top-left
corner to the bottom-right. The color at the top-left of the image
will be @var{from}, the color at the bottom-right @var{to}, with a
smooth transition between.
@end defun


@node Other Functions, , Gradient Functions, Miscellaneous Functions
@section Other Functions
@cindex Other functions
@cindex Functions, other

@defun sync-server
Flush all pending X requests, don't wait for them to finish.
@end defun

@defun send-client-message window type data format
Send an X @code{ClientMessage} event to @var{window} (a window object,
the symbol @code{root} or a numeric xid).

The event will be of the type @var{type} (a symbol), contain the array
of integers @var{data} (i.e. a vector or a string), and will be
transferred as @var{format} sized quantities (8, 16 or 32).
@end defun

@defun create-window parent x y width height
Create an unmapped window that is a child of @var{parent} (a window
object, an integer window id, or the symbol @code{root}), with the
specified dimensions.

Returns the window id of the new window.
@end defun

@defun exit-type
If Sawfish is shutting down, this function returns one of the strings
@code{"user-quit"}, @code{"user-restart"} or @code{"session-quit"}.
If Sawfish is not shutting down, it returns @code{nil}.
@end defun

@defun x-atom symbol
Return the integer identifying the X atom with the same name as
@var{symbol}.
@end defun

@defun x-atom-name integer
Return the symbol with the same name as the X atom identified by the
integer @var{integer}.
@end defun

@defvar canonical-display-name
A string containing the canonical name of the X display.  This
includes the full host name and the screen number.  For example:
@code{"foo.bar.com:0.0"}.
@end defvar

@defvar display-name
A string containing the name of the X display, exactly as passed to
Sawfish.  For example: @code{":0"}, or @code{"foo:0.0"}.
@end defvar

@defvar saved-command-line-args
Holds a list of all of the command line arguments (including the
executable name).
@end defvar

@defvar sawfish-directory
The home directory for Sawfish files.  For example:
@code{"/usr/share/sawfish"}.
@end defvar

@defvar sawfish-exec-directory
The directory for architechture-specific Sawfish executables.  For
example: @code{"/usr/lib/sawfish/1.3/i386-pc-linux-gnu"}.
@end defvar

@defvar sawfish-lisp-lib-directory
The top-level directory for Sawfish lisp files.  For example:
@code{"/usr/share/sawfish/1.3/lisp"}.
@end defvar

@defvar sawfish-locale-directory
The system directory where Sawfish can find locale files.  This is not
part of the Sawfish distribution.  For example:
@code{"/usr/share/locale"}.
@end defvar

@defvar sawfish-site-lisp-directory
The top-level directory for site-specific Sawfish lisp files.  For
example: @code{"/usr/share/sawfish/site-lisp"}.
@end defvar

@defvar sawfish-version
The version number of the running Sawfish.
@end defvar

@defun primitive-play-sample filename
Plays the sound file @var{filename} (which must be a string).
@end defun

@defun call-with-error-handler thunk
Call the zero-parameter function @var{thunk}.  If an error occurs,
trap it and pass its @code{car} and @code{cdr} to
@code{error-handler-function}.
@end defun

@defun load-module name
Ensure that module @var{name} has been loaded.  This does @emph{not}
import its bindings or make them accessible.
@end defun

@defun eval-in form struct-name
Evaluates @var{form} in the structure named by @var{struct-name}.
Compare this with @code{eval}, which takes a structure object as its
second parameter, not a structure name.
@end defun

@defvar *user-module*
@code{*user-module*} is the default module for human interaction with
Sawfish.
@end defvar

@defun user-eval form
@defunx user-require feature
@code{user-eval} evaluates @code{form} in @code{*user-module*}.
@code{user-require} evaluates @code{(require @var{feature})} in
@code{*user-module*}.
@end defun

@defun quote-menu-item string
Escape any @samp{_} characters in @var{string} such that the result
can be used as the label of a menu item.
@end defun

@defun make-directory-recursively dir
Create directory @var{dir}.  Any missing parent directories will also
be created.
@end defun

@defun locate-file filename dirs
Search for a file @var{filename} in any of the directories named by
the list of strings @var{dirs}.
@end defun

@defun clamp x lower upper
Return @var{x} clamped between @var{lower} and @var{upper}.  If
@var{x} is less than @var{lower}, return @var{lower}; if it is larger
than @var{upper} return @var{upper}.  Otherwise return @var{x}.
@end defun

@defun clamp* x y lower upper
Return the interval (@var{x}, @var{x}+@var{w}) clamped between
@var{lower} and @var{upper}.  If @var{x} is less than @var{lower},
return @var{lower}.  If @var{x}+@var{w} is larger than @var{upper},
return @var{upper}-@var{w}; this is a value of @var{x} that satisfies
the upper bound, although it may violate the lower bound.  Otherwise
return @var{x}.
@end defun

@defun uniquify-list lst
Remove all duplicates values from @var{lst}, using @code{eq}.  The
order of elements is not preserved.
@end defun

@node Standard Hooks, Standard Properties, Miscellaneous Functions, Top
@chapter Standard Hooks
@cindex Standard hooks
@cindex Hooks, standard

Sawfish provides many hooks to allow extension of previously defined
functions. Also, many X events are exported to the Lisp environment via
the hooks mechanism. For more details on the hooks mechanism see
@ref{Normal Hooks, , Normal Hooks, librep, The Librep Manual}.

As well as using the standard @code{call-hook} function, sawfish also
provides the @code{call-window-hook} function. This is used to invoke
hooks which refer to a single window. If the hook has a local value
defined in the window's property list then this value is used, before
the default value defined by the actual variable.

@defun call-window-hook hook window &optional args hook-type
Call @var{hook} for @var{window} with further arguments @var{args}. See
@code{call-hook} for a description of @var{hook-type}. Each function in
the hook is called with arguments @code{(@var{window} . @var{args})}.
@end defun

The available hooks are listed below.

@menu
* Command Hooks::
* Key Hooks::
* Window Construction Hooks::
* Window Destruction Hooks::
* Window Mapping Hooks::
* Window Motion Hooks::
* Window Cycling Hooks::
* X Hooks::
* Pointer Motion Hooks::
* Workspace Hooks::
* Startup and Shutdown Hooks::
* Other Hooks::
@end menu


@node Command Hooks, Key Hooks, Standard Hooks, Standard Hooks
@section Command Hooks
@cindex Command Hooks
@cindex Hooks, Command

@defvr {Hook} pre-command-hook
Called before each command is evaluated.
@end defvr

@defvr {Hook} post-command-hook
Called after each command is evaluated.
@end defvr


@node Key Hooks, Window Construction Hooks, Command Hooks, Standard Hooks
@section Key Hooks
@cindex Key Hooks
@cindex Hooks, Key

@defvr {Hook} unbound-key-hook
Called when an key or pointer event has been received which there is
no binding for.  The hook functions return no arguments.  This is an
@code{or}-type hookk---the first function that returns non-@code{nil}
will terminate the hook call.

Under normal circumstances, an unbound key release causes a
@code{throw} to top-level.  Adding @emph{any} function to this hook
suppresses that behavior.
@end defvr


@node Window Construction Hooks, Window Destruction Hooks, Key Hooks, Standard Hooks
@section Window Construction Hooks
@cindex Window Construction Hooks
@cindex Hooks, Window Construction

@defvr {Window Hook} before-add-window-hook
@defvrx {Window Hook} add-window-hook
Called when the window is first adopted by the window manager.  This
occurs before the window is created, installed or placed.  At this
early stage, the only safe action is to set properties of the window
(with @code{window-set}).

@code{add-window-hook} is a deprecated hook, replaced by
@code{before-add-window-hook}.  It is called immediately after
@code{before-add-window-hook}.
@end defvr

@defvr {Window Hook} after-add-window-hook
Called when the window is first adopted by the window manager.  This
occurs after the window has been created, installed and placed.
@end defvr

@defvr {Window Hook} after-framing-hook
Called after a window gets a frame assigned, or after a window's
frame is rebuilt.
@end defvr


@node Window Destruction Hooks, Window Mapping Hooks, Window Construction Hooks, Standard Hooks
@section Window Destruction Hooks
@cindex Window Destruction Hooks
@cindex Hooks, Window Destruction

@defvr {Window Hook} destroy-notify-hook
Called when the window is destroyed.  Note that this may be called
asynchronously to the normal event loop.  In general, once the window
manager knows the window has been destroyed, it will attempt to call
this hook as soon as possible.
@end defvr


@node Window Mapping Hooks, Window Motion Hooks, Window Destruction Hooks, Standard Hooks
@section Window Mapping Hooks
@cindex Window Mapping Hooks
@cindex Hooks, Window Mapping

@defvr {Window Hook} map-notify-hook
@defvrx {Window Hook} unmap-notify-hook
@defvrx {Window Hook} reparent-notify-hook
@defvrx {Window Hook} shape-notify-hook
Called with a window is mapped, unmapped, reparented, or has its shape
changed, respectively.

Note that iconifying and uniconifying windows triggers unmapping and
mapping, respectively.
@end defvr

@defvr {Window Hook} iconify-window-hook
@defvrx {Window Hook} uniconify-window-hook
@defvrx {Window Hook} shade-window-hook
@defvrx {Window Hook} unshade-window-hook
@defvrx {Window Hook} window-maximized-hook
@defvrx {Window Hook} window-unmaximized-hook
@defvrx {Window Hook} window-depth-change-hook
Called when a window is iconified, uniconified, shaded, unshaded,
maximized, unmaximized, or has its depth changed, respectively.
@end defvr

@defvr {Window Hook} visibility-notify-hook
Called when a window's visibility changes.  In addition to the window,
the hook is called one one of the symbols @code{fully-obscured},
@code{partially-obscured}, or @code{unobscured}.
@end defvr

@defvr {Window Hook} place-window-hook
Called the first time a window is mapped, or if the window does not
have a true @code{placed} property.  This is an @code{or}-type
hook---the first function that returns non-@code{nil} will terminate
the hook call.
@end defvr


@node Window Motion Hooks, Window Cycling Hooks, Window Mapping Hooks, Standard Hooks
@section Window Motion Hooks
@cindex Window Motion Hooks
@cindex Hooks, Window Motion

@defvr {Window Hook} window-moved-hook
@defvrx {Window Hook} window-resized-hook
Called whenever the window is moved or resized.

This hook is called inside the @code{move-window-to} and
@code{move-resize-window-to} functions, so any operation that moves
the window will trigger this hook.  The window motion does not have to
be interactive.

Note that outline window sizing and movement does not use
@code{move-window-to} or @code{move-resize-window-to}, except at the
very end of the operation.

Compare with @code{while-moving-hook} and @code{while-resizing-hook}.
@end defvr

@defvr {Window Hook} before-move-hook
@defvrx {Window Hook} before-resize-hook
Called before starting an interactive move or resize.
@end defvr

@defvr {Window Hook} while-moving-hook
@defvrx {Window Hook} while-resizing-hook
Called during every pointer motion event during a move or resize.
This includes outline window motion.  The calls take place before the
window or its outline are actually moved.

Compare with @code{window-moved-hook} and @code{window-resized-hook}.
@end defvr

@defvr {Window Hook} after-move-hook
@defvrx {Window Hook} after-resize-hook
Called after completion of an interactive move or resize.  In addition
to the window, the hook is called with a list of symbols indicating how
the window was moved or resized: 
@code{horizontal} and @code{vertical} for movement,
@code{right}, @code{left}, @code{bottom} and @code{top} for resizing.
@end defvr

@defvr {Window Hook} before-slide-hook
Called before a window move when using key binding.
@end defvr


@defvr {Hook} after-restacking-hook
Called after any window restacking operation, including (but possibly
not limited to @code{restack-windows}, @code{x-raise-window} and
@code{x-lower-window}.  The hook functions take no arguments.
@end defvr

@node Window Cycling Hooks, X Hooks, Window Motion Hooks, Standard Hooks
@section Window Cycling Hooks
@cindex Window Cycling Hooks
@cindex Hooks, Window Cycling

@defvr {Window Hook} after-cycle-step-hook
Called after each step of window cycling. (See @ref{Cycling Between Windows}.)
@end defvr

@node X Hooks, Pointer Motion Hooks, Window Cycling Hooks, Standard Hooks
@section X Hooks
@cindex X Hooks
@cindex Hooks, X

@defvr {Window Hook} configure-request-hook
Called when an X
@code{ConfigureRequest} event is received.
In addition to the window, the hook is called with an association list
of configure request properties.  This alist may contain items
@code{(stack . above)}, @code{(stack . below)},
@code{(position . @var{coordinates})},
and @code{(dimensions . @var{dimensions})}.
@end defvr

@defvr {Window Hook} property-notify-hook
Called whenever an X window property (not a Sawfish window property)
changes.  In addition to the window, the hook is called with the
atom name and one of the symbols @code{new-value} or @code{deleted}.
@end defvr

@defvr {Window Hook} window-state-change-hook
Called whenver certain window manager hints change for a window.
Currently only @code{urgency} is monitored.  The hint is an additional
argument to the hook.
@end defvr


@node Pointer Motion Hooks, Workspace Hooks, X Hooks, Standard Hooks
@section Pointer Motion Hooks
@cindex Pointer Motion Hooks
@cindex Hooks, Pointer Motion

In the hooks below, @var{focus-mode} is one of the symbols
@code{normal}, @code{grab} or @code{ungrab}.

@defvr {Window Hook} enter-notify-hook
@defvrx {Window Hook} enter-frame-part-hook
Called when the pointer enters a window (including the root window).

If the window was part of a frame, then @code{enter-frame-part-hook}
is called with three arguments: the window, the frame part class
(@pxref{Frame Part Classes}), and @var{focus-mode}.

Otherwise @code{enter-notify-hook} is called with two arguments: the
window and @var{focus-mode}.

The root window is considered to be a valid window for this hook.
Sawfish will report entering the root window.
@end defvr

@defvr {Window Hook} leave-notify-hook
@defvrx {Window Hook} leave-frame-part-hook
Called when the pointer leaves a window (including the root window).

If the window was part of a frame, then @code{leave-frame-part-hook}
is called with three arguments: the window, the frame part class
(@pxref{Frame Part Classes}), and @var{focus-mode}.

Otherwise @code{leave-notify-hook} is called with two arguments: the
window and @var{focus-mode}.

The root window is considered to be a valid window for this hook.
Sawfish will report leaving the root window.
@end defvr

@defvr {Window Hook} focus-in-hook
Called when focus gains focus.  The hook functions take two arguments:
the window that received focus, and @var{focus-mode}.

If your @var{focus-mode} is set to @code{enter-exit}, your window
focus is tightly bound to your pointer position; focus-related hooks
and enter/leave hooks will be called in lockstep.  For other values of
@code{focus-mode}, Sawfish will trigger fewer focus-related hook calls
than enter/leave hook calls.

This hook is never called for the root window, because the root window
never gets focus.
@end defvr

@defvr {Window Hook} focus-out-hook
Called when a window loses focus.  The hook functions take two
arguments: the window that lost focus, and @var{focus-mode}.

If your @var{focus-mode} is set to @code{enter-exit}, your window
focus is tightly bound to your pointer position; focus-related hooks
and enter/leave hooks will be called in lockstep.  For other values of
@code{focus-mode}, Sawfish will trigger fewer focus-related hook calls
than enter/leave hook calls.

This hook is never called for the root window, because the root window
never gets focus.
@end defvr


@node Workspace Hooks, Startup and Shutdown Hooks, Pointer Motion Hooks, Standard Hooks
@section Workspace Hooks
@cindex Workspace Hooks
@cindex Hooks, Workspace

@defvr {Hook} enter-workspace-hook
@defvrx {Hook} leave-workspace-hook
Called when switching from one workspace to another.  This includes
switching caused by adding or removing a workspace.  The hook is
called with a @emph{list} containing the workspace in question.
@end defvr

@defvr {Window Hook} add-to-workspace-hook
@defvrx {Window Hook} remove-from-workspace-hook
Called when a window is added or removed from a workspace.  In
addition to the window, the hook is called with a @emph{list}
containing the workspace being changed.  If the window is in multiple
workspaces, then removing triggers @code{remove-from-workspace-hook}
for each workspace.
@end defvr

@defvr {Hook} workspace-state-change-hook
Called when any aspect of the workspaces change, including adding a
workspace, removing a workspace, moving a workspace, inserting or
removing a window from a workspace, etc.  This hook is called with no
arguments, so you should use one of the more specific hooks if
possible.
@end defvr

@defvr {Hook} viewport-resized-hook
Called when the number of rows and columns in each virtual workspace is
changed.
@end defvr

@defvr {Hook} viewport-moved-hook
Called when the origin of the viewport into the virtual workspace is
moved.
@end defvr

@defvr {Hook} enter-flipper-hook
@defvrx {Hook} leave-flipper-hook
When viewport edge-flipping is enabled, these hooks are called as the
pointer enters and leaves the pixel-wide border on the edge of the
screen. They're called with a single argument, one of the symbols
@code{left}, @code{right}, @code{top}, @code{bottom} indicating the
edge in question.
@end defvr


@node Startup and Shutdown Hooks, Other Hooks, Workspace Hooks, Standard Hooks
@section Startup and Shutdown Hooks
@cindex Startup and Shutdown Hooks
@cindex Hooks, Startup and Shutdown

@defvr {Hook} after-initialization-hook
Called after adopting the initial set of windows.
@end defvr

@defvr {Window Hook} remove-window-hook
Called on each window as Sawfish shuts down (possibly for a restart).
The hook functions take no arguments.
@end defvr

@defvr {Hook} before-exit-hook
Called immediately before exiting.
@end defvr

@defvr {Hook} sm-window-save-functions
@defvrx {Hook} sm-restore-window-hook
@defvrx {Hook} sm-after-restore-hook
Session management hooks, @ref{Session Management}.
@end defvr


@node Other Hooks,  , Startup and Shutdown Hooks, Standard Hooks
@section Other Hooks
@cindex Other Hooks
@cindex Hooks, Other

@defvr {Hook} gtkrc-changed-hook
When using the @code{gtkrc} module to load the current gtk style
parameters, this hook is called when the style changes.
@end defvr

@defvr {Window Hook} client-message-hook
Called with arguments @code{(@var{window} @var{type}
@var{data-array})}.  This is an @code{or}-type hook---the first
function that returns non-@code{nil} will terminate the hook call.
@end defvr


@node Standard Properties, Session Management, Standard Hooks, Top
@chapter Standard Window Properties
@cindex Standard window properties
@cindex Window properties, standard

As described in an earlier section of this manual, each window has a
property list, which may be used to associate arbitrary lisp data with
symbolic keys (@pxref{Window Property Lists}). The following table
documents a subset of the keys currently used.

@vtable @code

@item ignored
When set, the window is ignored in many operations. @xref{Ignored
Windows}.

@item avoid
When set, the window will not be covered by other windows when they
are maximized or newly placed. @xref{Avoided Windows}.

@item workspaces
A list of integers defining the workspaces that the window is a member of, or
nil if the window is sticky.
@xref{Workspaces}.

@item sticky
Whether the window should appear on all workspaces.

@item sticky-viewport
When set, the window will appear in all viewports of its workspace.

@item keymap
An optional, window-local, keymap. @xref{Keymaps}.

@item focus-click-through
When set, and click-to-focus mode is enabled, the click that focuses a
window is passed through to the client window.

@item ignore-window-input-hint
When set the value of the window's input hint is ignored, i.e. the
focus @emph{will} be given to the window when appropriate

@item never-focus
When set the window will @emph{never} be given the input focus

@item focus-when-mapped
Focus the window when it is mapped on to the display.

@item ignore-program-position
When set the window's program-position property is ignored, use this
with windows that set this hint incorrectly.

@item place-mode
When set, the placement mode to be used with this window.

@item placement-weight
When set, the weight assigned to the pixels in this window when doing
fitted window placement.

@item type
The frame-type of the window, or @code{nil}. @xref{Frame Types}.

@item frame-style
The frame style explicitly chosen by the user, or unset. @xref{Frame
Styles}.

@item current-frame-style
The frame style currently used for the window. @xref{Frame Styles}.

@item removed-classes
A list of frame part classes removed from the decorations of this
window. @xref{Removing Frame Parts}.

@item shaded
Is the window shaded? @xref{Shading Windows}.

@item hide-client
Is the client window visible within its frame. Used to implement window
shading.

@item depth
An integer, the layer that the window is a member of. Layer zero is the
depth of ``normal'' windows, negative depths are below this level,
while positive depths are above. @xref{Window Stacking}.

@item placed
Has the window been placed in a position yet? The
@code{place-window-hook} is only called when this is unset.

@item iconified
Is the window iconified? @xref{Iconifying Windows}.

@item gravity
When set, overrides the window gravity field of the window's size
hints. May be one of the symbols: @code{north-west}, @code{north},
@code{north-east}, @code{west}, @code{center}, @code{east},
@code{south-west}, @code{south}, @code{south-east}.

@item fixed-position
When set, the user is not allowed to change the position of this window.

@item client-set-position
When set, the program owning the window has manually moved the window
after it was mapped.

@end vtable


@node Session Management, Low-level X Interface, Standard Properties, Top
@chapter Session Management
@cindex Session management

Sawfish has fully integrated support for the X session management
protocols. Also, this support is extensible to allow all Lisp modules
to save and reload their own window state.

There are two methods of doing this. If the module only wants to save
and restore the values of properties in each window's property list
(i.e. those values set via @code{window-put}), then the following
functions may be used:

@defun sm-add-saved-properties &rest properties
@defunx sm-add-restored-properties &rest properties
Arrange for all symbols @var{properties} to be saved or restored with
the session.
@end defun

@defvar sm-saved-window-properties
@defvarx sm-restored-window-properties
Lists of properties (symbols) to be saved or restored with each
session.
@end defvar

If a Lisp module chooses to use this method it may add a function to
the @code{add-window-hook} to act on the reloaded properties when the
session is reloaded.

For more complex window properties that can't be saved straight from
the window's plist two hooks are available:

@defvar sm-window-save-functions
A list of functions, each of which is called when the state of each
window is saved. Each function is called with a single argument (the
window) and should return a list of alist elements that will be saved
in the state file. (As such, only values with valid read syntaxes may
be included.)
@end defvar

@defvar sm-restore-window-hook
List of functions called when the state of a window is restored. Each
is called with arguments @code{(@var{window} @var{alist})}, where
@var{alist} defines the state saved for the window.

Each function should look for the properties it saved, and then take
any action dependent on the values.
@end defvar

The following hook is also called.

@defvar sm-after-restore-hook
Hook called after loading a saved session.
@end defvar

@defvar sm-save-directory
The directory that will contain all Sawfish sessions.  It must be a
string.  By default it is @code{"~/.sawfish/sessions"}.
@end defvar

@defvar sm-sloppy-id-matching
When loading sessions, the algorithm that matches saved session data
to running clients requires that if one has a session id, then so must
the other, and they must match. Setting this variable to true turns
that feature off, allowing some broken clients to be session managed.
Defaults to false.
@end defvar

@node Low-level X Interface, FAQ, Session Management, Top
@chapter Low-level X Interface

@menu
* X Server::
* X Windows::
* X Selections::
* X Keysyms::
* X Bitmaps and Pixmaps::
* X Drawing::
* Available X Symbols::
@end menu


@node X Server, X Windows, Low-level X Interface, Low-level X Interface
@section X Server

@defun x-server-timestamp &optional from-server store
Return a recent X server timestamp as an integer.

If @var{from-server} is non-@var{nil}, the timestamp is read directly
from the server; otherwise the most recent timestamp seen by the
window manager (i.e., from an event) is returned.

If @var{store} is true, this becomes the most recent timestamp seen by
the window manager.
@end defun


@node X Windows, X Selections, X Server, Low-level X Interface
@section X Windows

@defun x-create-window (x . y) (width . height) bw attrs &optional event-handler
Create a new X window at @code{(@var{x}, @var{y})} with dimensions
@code{(@var{width}, @var{height})} and border width @var{bw}.
@var{Attrs} is an alist mapping attribute names to values.  Allowed
attribute names are @code{background} and @code{border-color}.
@end defun

@defun x-configure-window window attrs
Reconfigure the window associated with @var{window}.  @var{Attrs} is 
an alist mapping attribute names to values.  Allowed attribute names
are @code{x}, @code{y}, @code{width}, @code{height} and
@code{border-width}.
@end defun

@defun x-destroy-window window
Destroy the X window @var{window}.
@end defun

@defun x-map-window window &optional unraised
Map the window associated with @var{window} to the display.  If
@var{unraised} is not specified, the window will be mapped at the top
of the window stack.
@end defun

@defun x-unmap-window window
Unmap the window associated with @var{window}.
@end defun

@defun x-window-id window
Return the X window ID (an integer) associated with @var{window}.
@end defun

@defun x-window-p obj
Return @code{t} if @var{obj} is associated with an X window object.
@end defun

@defun x-change-window-attributes window attrs
Set attributes of the window associated with @var{window}.
@var{Attrs} is an alist mapping attribute names (symbols) to values.
Allowed attribute names are @code{background} and @code{border-color}.
@end defun


@node X Selections, X Keysyms, X Windows, Low-level X Interface
@section X Selections

@defun x-get-selection sel
Return the string corresponding to the current value of the X11
selection defined by @var{sel}, or @code{nil} if the selection
currently has no value.  @var{Sel} should be one of
@code{PRIMARY}, @code{SECONDARY} or @code{CLIPBOARD}.
@end defun

@defun x-selection-active-p sel
Returns t if the X11 selection defined by the symbol @var{sel} is
available for reading.  @var{Sel} should be one of @code{PRIMARY},
@code{SECONDARY} or @code{CLIPBOARD}.
@end defun


@node X Keysyms, X Bitmaps and Pixmaps, X Selections, Low-level X Interface
@section X Keysyms

@defun x-keysym-name ks
Return the Lisp symbol naming the X11 keysym represented by the
integer @var{ks}.
@end defun

@defun x-lookup-keysym name
Return the X11 keysym (an integer) named by the Lisp symbol
@var{name}.
@end defun


@node X Bitmaps and Pixmaps, X Drawing, X Keysyms, Low-level X Interface
@section X Windows

@defun x-bitmap-p
Return @code{t} if @var{arg} is an X-bitmap object.
@end defun

@defun x-create-bitmap (width . height)
Create a bitmap of size @var{width}x@var{height}.
@end defun

@defun x-create-pixmap (width . height)
Create a pixmap of size @var{width}x@var{height}.
@end defun

@defun x-destroy-drawable drawable
Destroy the X drawable @var{drawable}.
@end defun

@defun x-drawable-height drawable
Return the height in pixels of @var{drawable}.
@end defun

@defun x-drawable-id drawable
Return the X11 drawable-ID (an integer) associated with
@var{drawable}.
@end defun

@defun x-drawable-p obj
Return @code{t} if @var{obj} is an X drawable object.
@end defun

@defun x-drawable-width drawable
Return the width in pixels of @var{drawable}.
@end defun

@defun x-grab-image-from-drawable drawable mask
Return a new image object copied from @var{drawable}.  @var{Mask} is a
stencil mask for the image; black pixels in @var{mask} become
transparent in the returned image.
@end defun

@defun x-pixmap-p obj
Return @code{t} if @var{obj} is an X pixmap object.
@end defun


@node X Drawing, Available X Symbols, X Bitmaps and Pixmaps, Low-level X Interface
@section X Windows

@defun x-clear-window window
Clear the window associated with @var{window} to its background color.
@end defun

@defun x-copy-area window gc (x . y) (width . height) (dest-x . dest-y)
Copy a region of @var{window} with top-left corner @code{(@var{x},
@var{y})} and dimensions @code{(@var{width}, @var{height})} to the
position @code{(@var{dest-x}, @var{dest-y})} using @var{gc}.
@end defun

@defun x-create-gc window attrs
Create a new GC for the specified window @var{window}.  @var{Attrs} is
an alist mapping attributes to values.  Allowed attribute names are
@code{foreground}, @code{background}, @code{line-width},
@code{line-style}, @code{cap-style}, @code{join-style},
@code{fill-style}, @code{fill-rule}, @code{arc-mode}, @code{tile},
@code{stipple}, @code{ts-x-origin}, @code{ts-y-origin},
@code{clip-mask}, @code{clip-x-origin}, @code{clip-y-origin} and
@code{function}.
@end defun

@defun x-change-gc gc attrs
Sets attributes of the X Graphical Context.  @var{Attrs} is an
association list of attribute names and values.  Allowed attribute
names are @code{foreground}, @code{background}, @code{line-width},
@code{line-style}, @code{cap-style}, @code{join-style},
@code{fill-style}, @code{fill-rule}, @code{arc-mode}, @code{tile},
@code{stipple}, @code{ts-x-origin}, @code{ts-y-origin},
@code{clip-mask}, @code{clip-x-origin}, @code{clip-y-origin} and
@code{function}.
@end defun

@defun x-create-root-xor-gc
Create a graphics context specialized for XOR-ing onto the root
window.  This is used for drawing outlines for window movement.
@end defun

@defun x-destroy-gc gc
Destroy the X graphics context @var{gc}.
@end defun

@defun x-draw-arc window gc (x . y) (width . height) (angle1 . angle2)
Draw a single circular or elliptical arc in @var{window} using the
graphics context @var{gc}.  The center of the circle or ellipse is the
center of an imaginary rectangle at @code{(@var{x}, @var{y})}.  The
major and minor axes are the @code{(@var{width}, @var{height})} of
that rectangle.  The arc sweeps from @var{angle1} to @var{angle2};
positive angles are rotated counter-clockwise from zero, and negative
angles are rotated clockwise from zero.
@end defun

@defun x-draw-image image window (x . y) &optional (width . height)
Render the image object @var{image} in @var{window} at position
@code{(@var{x}, @var{y})}.  If @var{width} and @var{height} are
defined the image is first scaled to these dimensions; otherwise it is
drawn using its natural dimensions.
@end defun

@defun x-draw-line window gc (x1 . y1) (x2 . y2)
Draw a line from @code{(@var{x1}, @var{y1})} to @code{(@var{x2},
@var{y2})} in @var{window} using the graphics context @var{gc}.
@end defun

@defun x-draw-rectangle window gc (x . y) (width . height)
Draw a rectangle with its top-left corner at @code{(@var{x}, @var{y})}
and dimensions @code{(@var{width}, @var{height})} in @var{window}
using the graphics context @var{gc}.
@end defun

@defun x-draw-string window gc (x . y) string &optional font
Draw the specified string at @code{(@var{x}, @var{y})} in @var{window}
using the graphics context @var{gc}.  If @var{font} is specified use
that font.
@end defun

@defun x-fill-arc window gc (x . y) (width . height) (angle1 . angle2)
Draw a single filled circular or elliptical arc in @var{window} using
the graphics context @var{gc}.  The center of the circle or ellipse is
the center of an imaginary rectangle at @code{(@var{x}, @var{y})}.
The major and minor axes are the @code{(@var{width}, @var{height})} of
that rectangle.  The arc sweeps from @var{angle1} to @var{angle2};
positive angles are rotated counter-clockwise from zero, and negative
angles are rotated clockwise from zero.
@end defun

@defun x-fill-polygon window gc points &optional draw-mode
Draw a single filled polygon in @var{window} using
the graphics context @var{gc}.  @var{Points} is a list of
@code{(@var{x}, @var{y})} pairs that defines the polygon vertices.

@var{Draw-mode} is a hint to the X server on how to draw the polygon;
if supplied, it should be one of the symbols @code{convex} or
@code{non-convex}.  The default mode is ``Convex''.
@end defun

@defun x-fill-rectangle window gc (x . y) (width . height)
Draw a filled rectangle with its top-left corner at @code{(@var{x},
@var{y})} and dimensions @code{(@var{width}, @var{height})} in
@var{window} using the graphics context @var{gc}.
@end defun

@defun x-gc-p obj
Returns @code{t} if @var{obj} is an X GraphicsContext object.
@end defun

@defun x-gc-set-dashes gc pixels-list &optional offset
Set the dash style of graphics context @var{gc} to the value of
@var{pixels-list}.  @var{Pixels-list} is a list of cons cells
@code{((pixels-on . pixels-off) ...)} indicating runs of on and off
pixels in a dash segment.  If @var{offset} is given, this should be an
integer indicating the number of pixels to offset the dashes.
@end defun

@defun x-window-back-buffer window
Return the X object ID (an integer) for the back buffer associated
with @var{window}.  If no such back buffer exists, the function will
attempt to create one.

If the function is unable to find or create a back buffer (possibly
because the X server does not support them), it returns the window's
own ID.
@end defun

@defun x-window-swap-buffers window
Swap the fore and back buffers of the window associated with
@var{window}.  If the X server does not support double buffers, the
function quietly does nothing.
@end defun


@node Available X Symbols,  , X Drawing, Low-level X Interface
@section Available X Symbols

The following symbols can be used where X window attributes are
expected:

@table @code
@item border-width
@itemx border-color
@itemx expose
@itemx convex
@itemx non-convex
@itemx line-width
@itemx line-style
@itemx cap-style
@itemx join-style
@itemx fill-style
@itemx fill-rule
@itemx arc-mode
@itemx tile
@itemx stipple
@itemx ts-x-origin
@itemx ts-y-origin
@itemx clip-mask
@itemx clip-x-origin
@itemx clip-y-origin
@end table

The following symbols can be used where X window attribute values are
expected:

@table @code
@item line-solid
@itemx line-on-off-dash
@itemx line-double-dash
@itemx cap-not-last
@itemx cap-butt
@itemx cap-round
@itemx cap-projecting
@itemx join-miter
@itemx join-round
@itemx join-bevel
@itemx fill-solid
@itemx fill-tiled
@itemx fill-stippled
@itemx fill-opaque-stippled
@itemx even-odd-rule
@itemx winding-rule
@itemx arc-chord
@itemx arc-pie-slice
@itemx function
@itemx clear
@itemx and
@itemx and-reverse
@itemx copy
@itemx and-inverted
@itemx no-op
@itemx xor
@itemx or
@itemx nor
@itemx equiv
@itemx invert
@itemx or-reverse
@itemx copy-inverted
@itemx or-inverted
@itemx nand
@itemx set
@end table


@node FAQ, Function Index, Low-level X Interface, Top

@include faq.texi


@node Function Index, Variable Index, FAQ, Top
@unnumbered Function Index

@printindex fn


@node Variable Index, Concept Index, Function Index, Top
@unnumbered Variable Index

@printindex vr


@node Concept Index, , Variable Index, Top
@unnumbered Concept Index

@printindex cp


@contents
@bye
