\input texinfo  @c -*-Texinfo-*-

@c To compile: makeinfo  -I . sawfish.texi -o sawfish.info

@setfilename sawfish.info
@settitle sawfish Programming Manual
@footnotestyle end

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

This is @cite{The sawfish Programming Manual}, for sawfish.

Copyright 1999 - 2003 John Harper, 2007 - 2011 Sawfish team.

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
@author John Harper, Sawfish team.
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1999 - 2003 John Harper, 2007 - 2011 Sawfish team.

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.

For edit history, see @file{ChangeLog} file.
@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
* RandR and Xinerama::          Many monitors and updates
* 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
* External Applications::       Invocation of external applications
* 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 @t{#!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 @t{#!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

Lisp font object allows manipulation of correspondig X11 fonts.

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

Sawfish supports three ``types'' of fonts: X11 old core fonts (fontsets
and fontstructs), Xft fonts, and if supported, Pango fonts. In lisp,
type is represented by a string, @code{"xlfd"}, @code{"Xft"}, or
@code{"Pango"}.

@defun font-type-exists-p type
Returns true if fonts of @var{type} are available, false otherwise.
@end defun

@defun get-font-typed type name
Returns a font object which represents an X11 font. It's specified by
the string @var{name}, and string @var{type}. Signals an error if the
specified font is not available.

``Safe'' examples are:
@lisp
(get-font-typed "xlfd" "fixed")
(get-font-typed "Xft" "Sans")
(get-font-typed "Pango" "Sans")
@end lisp
@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, in string, of the X11 font represented by object
@var{font}.
@end defun

@defun font-type font
Returns the font's type. It is one of @code{"xlfd"}, @code{"Xft"}, and
@code{"Pango"}.
@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 @t{#!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 @t{#!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 @t{#!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 @t{#!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 @t{#!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 @t{#!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 @t{#!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 @t{#!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 @t{#!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. For pointer
related functions, @xref{Pointer Functions}.

@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 @t{#!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 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

Since the root window is not a managed client window, it is not
represented by a window object. Sometimes functions' arguments and
return value treat the symbol @code{root} as the root window. Window
hooks are so. But sometimes not.

@menu
Basics:
* Window Attributes::
* Getting Windows:: Get window by name, class, all, etc.
* Window Property Lists:: Plist attached by Sawfish.
* Window Types::  Some windows have type, like transient.
* Input Focus::
* X Properties::
* Window Groups::

@noindent
Operations on windows:
* Activating Window:: Make a window ready for use.
* Window Stacking::
* Moving and Resizing Windows::
* Showing and Hiding Windows::
* Destroying Windows::
* Shading Windows::
* Maximizing Windows::
* Cycling Between Windows::
* Window Rules by Matching::
* Animating Windows::
* Iconifying Windows::

@noindent
Windows with special properties:
* Window Stickiness::
* Ignored Windows::
* Avoided Windows::
@end menu

@node Window Attributes, Getting Windows, , Windows
@section Window Attributes
@cindex Window attributes
@cindex Attributes, of windows
@cindex Windows, attributes of

Many attributes are described in the related sections.

First, basic attributes, like name, class, ID, etc.
@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 rename-window win name
Change the window's name to @var{name}. This works in practice, but
technically ICCCM doesn't suppose window name changes.
@end defun

@defun window-class window @t{#!optional} spec
If the optional argument @var{spec} is @code{nil}, returns the class
that @var{window} belongs to as a string, or nil if @var{window} has
no associated class.

ICCCM class consists of ``Instance'' and ``Class''. If @var{spec} is
the symbol @code{cons}, then the cons of the form
@code{(@var{instance} . @var{class})} is returned. If @var{spec} is
the symbol @code{configurator}, then the string of the form
``@var{instance}/@var{class}'' is returned.
@end defun

@defun window-role window
Return the window role set by @code{NET_WM_ROLE}.
@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-dimensions window
Returns the size of the window @var{window} in a cons cell
@code{(@var{width} . @var{height})}. This does @emph{not} include the
frame. The size including the frame is returned by
@code{window-frame-dimensions}. (@pxref{Frame Functions})
@end defun

@defun window-position window
Returns the position of the window decorated with the frame in a
cons-cell @code{(@var{x} . @var{y})}.
@end defun

@defun display-window-position @t{#!optional} window
Display @var{window}'s position and size in a popup. If the argument
is @code{nil} or called as a command, user chooses the window by cursor
and click.

This function is defined in @code{sawfish.wm.util.display-wininfo}.
@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

@defun window-pid window
Returns the window process ID, or nil if not available.
@end defun

@noindent
Listed here are window visibility predicates:
@code{stacking-visibility}, @code{window-obscured} (@pxref{Stacking
Visibility}), @code{window-visible-p} (@pxref{Showing and Hiding
Windows}), @code{window-shaped-p} (@pxref{Shading Windows}),
@code{window-iconified-p} (@pxref{Iconifying Windows}),
@code{window-in-workspace-p} (@pxref{Workspaces and Windows}),
@code{window-outside-viewport-p} (@pxref{Windows and Viewports}).

@noindent
Various predicates:
@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-shaped-p window
Return @code{t} if @var{window} is shaped (possibly not rectangular).
@end defun

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

@defun window-wants-input-p window
@defunx window-really-wants-input-p window
See @xref{Input Focus}.
@end defun

@node Getting Windows, Window Property Lists, Window Attributes, Windows
@section Getting Windows
@cindex Getting Windows

First, functions which treat all windows.

@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 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

@noindent
Functions to get specific windows.

@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 #!key regex icon
Return a window object with name @var{name}, or @code{nil}.  Even if
multiple windows are matched, one of them is returned.

If @code{regex} is non-nil, @var{name} is treated as a regex, and
matched against window names.

If @code{icon} is non-nil, window's icon name (set by
@code{NEW_WM_ICON_NAME}, @emph{not} EWMH @code{_NET_WM_ICON_NAME}) is
searched, instead of the window's name.
@end defun

@defun get-window-by-class class #!regex
Same as the above, but the match is done against the window class.
Here, the class does not include the ``instance''. (See @code{window-class} in
@xref{Window Attributes}.)

The option @code{regex} is boolean, not a regex, like @code{get-window-by-name}.
@end defun

@defun get-window-by-role role
Same as the above, but the match is done against the window role.

The option @code{regex} is boolean, not a regex, like @code{get-window-by-name}.

@end defun

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

@node Window Property Lists, Window Types, Getting Windows, 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 @t{#!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, Input Focus, Window Property Lists, Windows
@section Window Types
@cindex Window types
@cindex Types, of windows
@cindex Windows, types of

Some window ``types'' are defined. They represent the window's special
nature based on the role. Defined types are ``transient'',
``desktop'', and ``dock''.

A type is usually set by applications through hints when the
window appears. Many windows do not have any types.

``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 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 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 @t{#!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 @t{#!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 @t{#!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. They
accept keys as if it is a root window. (I.e.,
@code{root-window-keymap} is used.) They don't have a frame.

@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 when they are 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 docks or panels. They don't have frame by
default.

@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 when they are 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 Input Focus, X Properties, Window Types, 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

@defun window-wants-input-p window
If you're unsure, use @code{window-really-wants-input-p} function
described below.

Return @code{t} when the window @var{window} wants input focus in X
sense, i.e. if it has asked for the input focus to be assigned to,
through the @code{input} field of its @code{WM_HINTS} property.
@end defun

@defun window-really-wants-input-p window
Like @code{window-wants-input-p}, but in addition, this function also
takes into account user option provided by Sawfish, i.e. if the window
has @code{never-focus} property or not.
@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 @t{#!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 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-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 @t{#!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 @t{#!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

@noindent
Other focus related functions:

@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. For root window, @code{nil} is
returned.
@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 Groups, 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 Groups, Activating Window, X Properties, 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-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-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 @t{#!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 @t{#!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 @t{#!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 Activating Window, Window Stacking, Window Groups, Windows
@section Activating Window
@cindex Activating Window
@cindex Activation, of a window

When user wants to use a window, displaying, focusing, raising, etc,
are necessary. Functions in this section do such jobs.

@defun display-window window
Roughly speaking, do everything necessary to make @var{window} ready
for user.

The operations are done in the following order. If the window is
iconified, it gets un-iconified. The workspace and the viewport in
which the window lies is selected. Unshade if necessary. (See
@code{unshade-selected-windows} variable below.) Then call the
@code{activate-window} function described below.

It is defined in @code{sawfish.wm.util.display-window} module.
@end defun

@defun activate-window window
Raise, focus, warp pointer if necessary, and mark the window as the
top of window order. Don't focus if the window doesn't allow that
operation.
@end defun

@defvr Customizable unshade-selected-windows
When non-nil, unshade windows when selected.
@end defvr

@node Window Stacking, Moving and Resizing Windows, Activating Window, 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. It's Sawfish that maintains
this list.  Raising or lowering windows changes their positions in
this list.

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

@node Stacking Order, Stacking Visibility, 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

Functions to change stacking order.

@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}. This function alone does not raise / lower
windows.
@end defun

@defun stack-window-above above below
Change stacking order of window @var{above} so that it is immediately
above window @var{below}. This function alone does not raise / lower
windows.
@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 Stacking Visibility,  Raising and Lowering Windows, Stacking Order, Window Stacking
@subsection Stacking Visibility
@cindex Visibility, stacking
@cindex Stacking, visibility
@cindex Covering, of windows

There're functions which tell how the window is covered by others.

@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 extension, as every window is reported unobscured.  Use
@code{window-obscured} and @code{stacking-visibility} instead.
@end deffn

@node Raising and Lowering Windows,  , Stacking Visibility, 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. Notice how the function name and command
name for each pair differs slightly.

@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

@defun x-raise-window win ref
@defunx x-lower-window win ref
Raise / lower window @var{win} so that it is above / below window
@var{ref}. If @var{ref} is undefined, @var{win} is put at the top
/ bottom of the stacking order.
@end defun

Another set of functions supports operating on multiple windows
simultaneously. You have to import @code{sawfish.wm.util.stacking} to
use them.  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

@defvr Customizable user-raise-type
This user option 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 defvr

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 @t{#!optional} hints
@defunx resize-window-with-hints* window width height @t{#!optional} hints
Resize the window @var{window} respecting the hints (see below).
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.

Hints can specify minimum or maximum value of each dimension, and
also increase step, as far as these two functions are concerned.
@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

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 Function move-window-interactively window
@deffnx 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 Function resize-window-interactively window
@deffnx 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 resize-window-to-preset-size
@deffnx Command resize-window-to-preset-height
@deffnx Command resize-window-to-preset-width
For these commands, first you specify a window dimension(s) in the
configurator. The focused window will be resized to that preset size
on invocation.
@end deffn

@deffn Command resize-window-prompt window
You're prompted to enter the new window size, and the window
will be resized.
@end deffn

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

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

@deffn Command double-window-size window
@deffnx Command halve-window-size window
Double / halve the size of @var{window} in both direction, i.e.
the area will be 4 or 1/4 times.
@end deffn

Sawfish supports increasing the windows size until it touches another
window. This is called ``grow''. ``Shrink'' achieves the opposite,
i.e. it decreases the windows size, until it does no longer overlap any
other window. More precisely, the grow can be done repeatedly, each
time until the edge meets another edge, and shrink is done so that
it overlaps with one less window.

@deffn Function grow-window-up window @t{#!optional} arg
@deffnx Function grow-window-down window @t{#!optional} arg
@deffnx Function grow-window-left window @t{#!optional} arg
@deffnx Function grow-window-right window @t{#!optional} arg
Grows @var{window} upwards / downwards / left / right until it touches
another window.  If that edge is beyond the screen edge, it is
brought back in. With a universal prefix @var{arg}, maximize in that
direction instead. With a numeric prefix @var{arg}, grow by that many
increments specified by window or pixels instead.

There are commands, too, with the same name.
@end deffn

@deffn Function shrink-window-up window
@deffnx Function shrink-window-down window
@deffnx Function shrink-window-left window
@deffnx Function shrink-window-right window
Shrinks @var{window} by moving one edge upwards / downwards / left /
right until it intersects with one window less than before. (So,
in @code{shrink-window-up} for example, the lower edge is moved.)

Window won't be made smaller than the minimum size, or
@code{shrink-window-minimum-size}. More precisely, size truncation
may make the window smaller than these values.

There are commands, too, with the same name.
@end deffn

Moving counterparts, instead of resizing of ``grow'' and ``shrink'',
are ``pack'' and ``yank''. So, ``pack'' moves until the window touches
another, and ``yank'' moves until the overlap reduces.

@deffn Function pack-window-up window @t{#!optional} arg
@deffnx Function pack-window-down @t{#!optional} arg
@deffnx Function pack-window-left window @t{#!optional} arg
@deffnx Function pack-window-right window @t{#!optional} arg
Moves @var{window} upwards / downwards / left /right until it touches
another window.  If that edge is beyond the screen edge, it is moved
back in.  With a universal prefix @var{arg}, move in that direction
maximally instead.  With a numeric prefix @var{arg}, move by that many
pixels instead.

There are commands, too, with the same name.
@end deffn

@deffn Function yank-window-up window
@deffnx Function yank-window-down window
@deffnx Function yank-window-left window
@deffnx Function yank-window-right window
Yanks @var{window} upwards / downwards / left / right until it
overlaps with one less window than before.

There are commands, too, with the same name.
@end deffn

Grow, pack, shrink and yank behavior can be customized through the
following variables:

@defvar grow-is-maximize
Whether growing is considered to be maximization.
The default value is @code{t}.
@end defvar

@defvar pack-warp-pointer
Whether and how to move the pointer, either @code{always} @code{maybe}
or @code{never}. The default value is @code{maybe}

@code{maybe} means that the pointer is moved along with the window, if
the pointer was within the window area before packing. @code{always}
warps the pointer to the center of the window if it isn't already in
the window, then does like @code{maybe}. @code{never} means not to
warp the pointer.
@end defvar

@defvar grow-pack-bump-obscured
Whether to bump into fully obscured windows.
The default value is @code{nil}.
@end defvar

@defvar grow-pack-bump-other-depth
Whether to bump into windows on a different depth, either @code{always}
@code{maybe} or @code{never}. The default value is @code{always}.

@code{maybe} means only @code{avoided} windows (@pxref{Avoided Windows}).
@end defvar

@defvar grow-pack-bump-ignored
Whether to bump into ignored windows.
The default value is @code{t}.
@end defvar

@defvar shrink-window-minimum-size
The minimum height or width to which a window may be shrunk.
The default value is @code{10}.
@end defvar

@defvar yank-window-minimum-visible
The minimum amount of window left visible, if yanked over the screen
edge. The default value is @code{10}.
@end defvar

@deffn Function move-window-center window
@deffnx Command move-window-center window
Place @var{window} in the middle of the screen (frame-size is
respected while calculating position)
@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

When you move a window and it comes close to another, sawfish adjusts
its position so that its edge fits to the other, or ``snaps''. (It may
be dubbed as ``interactive tiling''.) Snapping also takes place against
screen boundary.

@defvar move-snap-epsilon
The distance in pixels before snapping together two edges. The bigger
the value, the more adhesive windows get.
@end defvar

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

@defun window-gravity window @t{#!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 (un)withdrawing client windows
from the display. These are used to implement both workspaces
(@pxref{Workspaces}) and iconification (@pxref{Iconifying Windows}).

@defun hide-window window
Prevent object @var{window} from being displayed.

This function is low-level and mainly for internal use. You should
probably use @code{iconify-window}. (@pxref{Iconifying Windows})
@end defun

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

This function is low-level and mainly for internal use. For
interactive use, you should probably use
@code{display-window}. (@pxref{Activating 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 Function delete-window window
@deffnx 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 Function delete-window-safely window
@deffnx 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 Function destroy-window window
@deffnx 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

@deffn Function x-kill-client window
@deffnx Command 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 deffn

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

@node Shading Windows, Maximizing 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 Function shade-window window
@deffnx Command shade-window window
Arrange for only the title bar of @var{window} to be visible.
@end deffn

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

@deffn Function toggle-window-shade window
@deffnx Command toggle-window-shaded window
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 Maximizing Windows, Cycling Between Windows, Shading 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.

If you have multiple monitors, maximization is done within a head,
unless stated explicitly that it's xinerama.

@defun window-maximizable-p window @t{#!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, regardless
if it's horizontally maximized or not.
@end defun

@defun window-maximized-horizontally-p window
Return @code{t} when @var{window} is horizontally maximized, regardless
if it's vertically maximized or not.
@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 @t{#!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
@deffnx Function maximize-window-horizontally window
@deffnx Command maximize-window-horizontally Windows
Maximize the vertical or horizontal dimension of @var{window} in the screen.
@end deffn

@deffn Function maximize-window-toggle window @t{#!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.

If you set this to @code{nil} and resize a maximized window, then
you can't unmaximize it any more.
@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 @t{#!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 state
@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 @var{state} nil, it unmaximizes. Else, it maximizes. If called as
a command, it always maximizes.
@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.
@end deffn

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

@deffn Function maximize-window-fullxinerama window state
@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 @var{state} nil, it unmaximizes. Else, it maximizes. If called as
a command, it always maximizes.
@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.
@end deffn

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

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

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

If the window is maximized for example vertically but not
horizontally, then only vertical position and dimension are restored.

If defined, @var{direction} is a symbol, either @code{vertical} or
@code{horizontal}, and unmaximization 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.

If the window is maximized for example vertically but not
horizontally, then @var{y} is the y coordinate before maximization,
but @var{x} is the window's current x coordinate.
@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.

If the window is maximized for example vertically but not
horizontally, then @var{y} is the height before maximization, but
@var{x} is the window's current width.
@end defun

@defun maximize-discard window @t{#!optional} direction
Don't treat window as maximized any more, keeping the size and the
position. You'll be able to move and resize, but won't be able to
unmaximize.

If the optional argument `direction' is `vertical' or `horizontal',
then only that direction is unmaximized.

When @var{window} is not maximized, nothing happens.
@end defun

@node Cycling Between Windows, Window Rules by Matching, Maximizing 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 inside the same group. This is somewhat
comparable to the @key{Control-TAB} behavior of Windows OS.
@end defun

@defun cycle-among-groups
@defunx cycle-among-groups-backwards
Cycle through windows at the top of each group.
@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 @t{#!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 Rules by Matching, Animating Windows, Cycling Between Windows, Windows
@section Window Rules by Matching
@cindex Matching, windows

Sawfish can trigger actions particular to each window. More
precisely, if the window's properties match to the user set rule, then
it is executed when the window appears. Check is done in
@code{before-add-window-hook}. (@pxref{Standard Hooks})

These rules can easily be set by configurater GUI, but there're
functions to manipulate them. They're defined in
@code{sawfish.wm.ext.match-window}.

@defun add-window-matcher rules actions
Let us see an example first:

@lisp
(add-window-matcher '((WM_NAME . "^root$")
                      (WM_CLASS . "^XTerm/xterm$"))
                    '((ignore-program-position . t)
                      (maximize . vertical)))
@end lisp

@var{rules} is an alist, and each value is matched using regex.
Allowed keys are any of @code{WM_NAME}, @code{WM_CLASS},
@code{WM_ICON_NAME}, @code{WM_WINDOW_ROLE}, @code{WM_CLIENT_MACHINE},
@code{WM_COMMAND}, and @code{WM_LOCALE_NAME}. Values to the keys are
strings. Windows are selected if all of these rules match.

@var{actions} is an alist. For possible keys and values, see
@file{lisp/sawfish/wm/ext/match-window.jl}.

Check for invalid arguments are not done.
@end defun

@defun remove-window-matcher rules props
Opposite of @code{add-window-matcher}, but unlike it, @var{props} are
list of properties. Example:

@lisp
(remove-window-matcher '((WM_NAME . "^root$"))
                       '(place-mode ignore-program-position))
@end lisp
@end defun

The best place to use @code{add-window-matcher} is in
@file{~/.sawfish/rc}. It's because rules modified by these commands are
not necessarily saved, depending on how you run the configurator.

The rules are stored in variable @code{match-window-profile}. Use
the above functions to modify its value. It is not recommended
to directly manipulate it.

@node Animating Windows, Iconifying Windows, Window Rules by Matching, 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 animation mode when an window is iconified. The default is @code{none}.

You can set the animation mode for each window from the configurator
``Window Rules'', or via window property. (@pxref{Standard Properties})
@end defvar

Here are listed functions to define and invoke animator.

@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 Iconifying Windows, Window Stickiness, Animating 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. Use
softwares called ``trayers'' and / or ``pagers'' for such things.

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

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

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

@deffn Function iconify-workspace-windows
@deffnx 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

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

When a window has a property @code{iconify-on-leave} set to non-nil,
it gets iconified when the mouse pointer leaves it. It can be set
from the configurator.

@lisp
;; Example:
;; ( add-window-matcher '( ( WM_CLASS . "^Konsole/konsole$" ) )
;;   '( ( iconify-on-leave . t ) ) )
@end lisp

@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 Function make-window-ignored window
@deffnx Command make-window-ignored window
Ignore the window @var{window}.
@end deffn

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

@deffn Function toggle-window-ignored window
@deffnx 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 Function toggle-window-never-focus window
@deffnx Function toggle-window-cycle-skip window
@deffnx Function toggle-window-list-skip window
@deffnx Function toggle-task-list-skip window
Toggle the appropriate flag on @var{window}. They have the same
name commands.
@end deffn

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

@node Avoided 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 @t{#!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 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 Function customize @t{#!optional} group
@deffnx Command customize
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

There also exists commands like @code{customize:appearance}, i.e. for
each top-level customization group, the command to customize only it
and its subgroups.

The @file{sawfish-config} program can be used to invoke the GUI manually.

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}.

In the configurator, gtk widget appears left to the docstring. But if
the docstring ends with ``\\w'' (literally in the source; the first
backslash for escaping the second), then the widget is put right to
the text. This feature is supported by only some widgets.

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} @t{#!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{sticky-button},
@code{lock-button}, @code{rename-button}, @code{move-resize-button},
@code{raise-lower-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 @t{#!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 @t{#!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 (border-width . @var{value})
@itemx (border-color . @var{value})
Defines the border width and color. A ``border'' if present surrounds
the window and all other frame parts. Both width and color are applied
to the whole window instead of current frame part. (Thus they should
be properties of window, not frame parts. Sorry.)

@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{border-color}, @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 the size of the window @var{window} including the frame, in a
cons cell @code{(@var{width} . @var{height})}.

The size excluding the frame is returned by
@code{window-dimensions}. (@pxref{Window Attributes})
@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. That is, their values are negative integers.
@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 window-frame-id win
Returns the numeric id of the framing window associated with object
@var{window}. Returns nil if the client window has no frame.
@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
If @var{lock} equals 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}.

Returns the previous value.
@end defun

@defun frame-state-mutex lock
If @var{lock} is non-nil, the state of frame parts will not be altered
at pointer enter and leave events.

Returns the previous value.
@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

@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

@defun update-frame-font-color
Reloads the frame font colors, if @var{use-custom-font-color} is true.
Use @var{frame-font-active-color} and @var{frame-font-inactive-color}
to modify the frame font colors.
@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

@defvar frame-type-fallback-alist
Frame type fallbacks. This is an alist whose elements are
(required-type . fallback-type). When REQUIRED-TYPE is not supported
by the current theme, then FALLBACK-TYPE is used instead."
@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
@cindex Large Desktop

Sawfish can have a virtual desktop which is larger than the computer's
screen size. This is done through the use of ``viewport''.

Viewport can be thought of as a screen-sized hole through which you
can view a portion of the virtual desktop.  The entire virtual desktop
consists of the grid of ``cells'' whose size is that of the physical
screen. Viewport moves around, and sits on a cell.

In Sawfish, the word ``viewport'' is sometimes used to mean the entire
larger-than-normal desktop.  This is natural, but a confusion and not
technically correct. When focused to enlargement, ``large desktop'' is
the correct nomenclature, but simply calling it the ``workspace'' or
the ``virtual desktop'' are correct too.

The word ``viewport'' is also used to mean the cell on which the
viewport is set, like ``Go to the next viewport.''

@defvar viewport-dimensions
The dimension of the virtual destkop.  This is a cons cell
@code{(@var{columns} . @var{rows})}.  Defaults to @code{(1 . 1)}.  The number of
viewport cells in the virtual desktop is @code{columns} times
@code{rows}.

If @code{viewport-boundary-mode} is @code{dynamic} (@pxref{Dynamic
Viewport}) then this variable is set by Sawfish to the current size of
the current workspace and should not be set by the user.
@end defvar

@defun set-number-of-viewports width height
Change @code{viewport-dimensions} to have the value
@code{(@var{width} . @var{height})}.  If @code{viewport-boundary-mode}
is @code{dynamic} then this sets the minimum dimensions of the virtual
workspace (@pxref{Dynamic Viewport}) rather than setting the
dimensions directly.
@end defun

@menu
* Viewport Functions::
* Dynamic Viewport::       Automatic resizing of workspace.
* Smooth Viewport::        Nice feature but not always compatible
* Windows and Viewports::
@end menu

@node Viewport Functions, Dynamic Viewport, Viewports, Viewports
@section Viewport Functions

Each cell is labeled with the index @code{(@var{col}, @var{row})}, and the
top-left cell is @code{(0, 0)}.  Indices are never negative.

Sawfish implements viewport as follows. 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 viewport to visit cell (@var{col}, @var{row}).
@end defun

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

@defvr Customizable viewport-boundary-mode
Decides how to act when you call @code{set-screen-viewport} and you
try to go outside of the virtual desktop. (Its size is specified by
@code{viewport-dimensions}.) Defaults to @code{stop}.

When set to @code{stop}, it stops at the boundary of the virtual desktop.

When set to @code{wrap-around}, it behaves as if the leftmost viewport
and the rightmost are connected. Same for the top and bottom.

If it is set to @code{dynamic}, then the workspace size changes
automatically. For details, see @xref{Dynamic Viewport}.
@end defvr

@defun viewport-honor-workspace-edges
Returns whether or not the display is permitted to move past the
current workspace boundaries.  It returns true if
@code{viewport-boundary-mode} is not set to @code{dynamic}.
@end defun

@defun viewport-at x y
Returns a cons cell consisting of @code{(@var{column} . @var{row})} of
the viewport containing the specified @var{x} and @var{y} coordinates.
The coordinates are specified relative to the current viewport, so
@code{(viewport-at 0 0)} is equivalent to @code{(screen-viewport)}.
@end defun

@defun viewport-offset-coord viewport
Returns the offset from the current viewport to @var{viewport} which
is specified as @code{(@var{column} . @var{row})}. The return value is
the cons cell @code{(@var{x} . @var{y})}. The values are in pixel, and are
negative if it lies at left or above the current viewport.

@var{viewport} can be outside of the workspace. (The check is not
done.) If @var{viewport} is @code{nil} it is understood as the
current viewport, i.e., @code{(0 . 0)} will be returned.
@end defun

There are lower-level functions which move viewport by pixel, not
by multiples of the physical screen dimensions.

Note that use of these breaks the traditional behavior and user
interface of Sawfish. Though they are useful, simultaneous use of
these functions and other functions may cause weird results.

@defun set-viewport x y
Change the position of the viewport, such that location
@code{(@var{x}, @var{y})} is at the top-left of the display.  So
@code{(set-viewport 0 -5)} will shift the viewport up five pixels.
@end defun

@defvr Customizable scroll-viewport-steps
When you move the viewport, the bigger this value, the more
smoothly the screen is scrolled. It is the number of steps for
scrolling.

The default value 1 means the change is instantaneous, and no scroll
is done. The upper limit for customization is 50.

This variable is used for @code{set-viewport}. All interactive commands
defined by Sawfish call this function, so this variable is important
for the user.
@end defvr

@node Dynamic Viewport, Smooth Viewport, Viewport Functions, Viewports
@section Dynamic Viewport

``Dynamic viewport'' is enabled by setting
@code{viewport-boundary-mode} to the symbol @code{dynamic}. It has
two features.

Normally, the viewport cannot move beyond the limits set by
@code{viewport-dimensions}, but this limitation is removed in dynamic
viewport. The viewport is allowed to go as far as you wish.

In addition, workspace is automatically resized, both enlarged and
shrunk, so that it contains the current viewport and all
windows. (Precisely speaking, it takes the minimum such size.)  The
size is set when you move the viewport, and also at Sawfish
startup. Each workspace has its own size independent of the others.

Even in dynamic viewport, the top-left cell is always @code{(0, 0)},
and the cell indices are never negative.

The dynamic viewport is still an experimental feature, and its
specification may change.

@defvr Customizable viewport-minimum-dimensions
This is only useful if dynamic viewport is enabled.
@code{viewport-dimensions} will never be set to less than
@code{viewport-minimum-dimensions}, unless it is a change requested by
the user, either by using the configuration interface or by calling
@code{set-number-of-viewports}.

If setting @code{viewport-minimum-dimensions} by hand (not by the
customization interface) be sure to call
@code{viewport-minimum-size-changed} after doing so to ensure that the
new minimum dimensions immediately go into effect.

If @code{set-number-of-viewports} is called to set the viewport
dimensions @code{viewport-minimum-dimensions} will be set to the same
value.  Also, if (using the configuration interface) you set the
viewport dimensions to less than @code{viewport-minimum-dimensions} then
@code{viewport-minimum-dimensions} will be adjusted to match.  This way
those who are not using dynamic viewports do not need to worry about
@code{viewport-minimum-dimensions}.
@end defvr

Under dynamic viewport, @code{viewport-dimensions} is the current size
of the current workspace, and does not have the meaning as a user option.

@node Smooth Viewport, Windows and Viewports, Dynamic Viewport, Viewports
@section Smooth Viewport
@cindex Smooth Viewport
@cindex Infinite Desktop

``Infinite desktop'' is an intuitive, nice feature. Just move the
mouse, for example to right, very far. As the pointer hits the screen
edge, the viewport moves as if it is dragged by mouse motion. Viewport
moves around by any amount, not limited to by a step of the physical
screen size.

To enable infinite desktop, put the following in your
@file{~/.sawfish/rc}:

@lisp
(require 'sawfish.wm.ext.infinite-desktop)
@end lisp

Options can be set from the configurator, under @code{Workspace}
section.

Infinite desktop behavior differs noticeably from the usual viewport
which lies on grid cells. For example, it does not make sense to ask
in which viewport a window lies. The design is not complete yet, and
may change in future. There may be some bugs.

It is called ``infinite desktop'' by historical reason, but in fact
you can limit the entire desktop size as you like.

@node Windows and Viewports,  , Smooth Viewport, 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 @t{#!optional} viewport
Returns true if @var{window} is completely outside the current
viewport in any direction.  If @var{viewport} is specified check against
that viewport rather than the current one.
@end defun

@defun window-absolute-position window
Returns the coordinates of the window as if the window's viewport
is selected. The return value is the cons cell (x . y).
@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

@defvr Customizable 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 defvr

@node Workspaces, RandR and Xinerama, Viewports, Top
@chapter Workspaces
@cindex Workspaces
@cindex Desktop workspaces
@cindex Virtual desktop

Workspaces provide another way for users to organize their windows in
Sawfish. Unlike viewports, workspaces don't have geometric relationship
with each other.

The word ``virtual desktop'' is sometimes used instead of
``workspace''.

@menu
* Workspace Intervals::			``Interesting'' workspaces
* Workspace Manipulation::		Creating, rearranging, deleting
* Workspaces and Windows::
* EdgeActions::			Switching workspaces with 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 workspaces with lower IDs being to the ``left''
of workspaces 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 @t{#!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 @t{#!optional} limits
Takes an offset position into an interval of ``interesting''
workspaces, and returns the workspace 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 @t{#!optional} after
Insert a new workspace, returning its index.  The new index appears
after the workspace indicated by @var{after}, or the current
workspace if @var{after} 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 preceding 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 @t{#!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 @t{#!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 @t{#!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 workspaces, the new workspaces get indices higher than any
existing indices.  When removing workspaces, the lowest workspaces 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, EdgeActions, 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 @t{#!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 @t{#!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 @t{#!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 @t{#!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 @t{#!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 @t{#!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 @t{#!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 EdgeActions,  , Workspaces and Windows, Workspaces
@section EdgeActions

EdgeActions is a centralized way to control the behaviour of the
screen-borders and -corners, which offers high customizability.

It consists of the following modules: @code{sawfish.wm.edge.subrs} -, which
contains the C-subroutines, @code{sawfish.wm.edge.utils} - a set of utility
functions, @code{sawfish.wm.edge.conf} - configuration infrastructure,
@code{sawfish.wm.edge.actions} - functionality infrastucture module,
@code{sawfish.wm.edge.flip} - viewport/workspace fliping functions,
@code{sawfish.wm.edge.hot-spots} - hot-spot/hot-move functions,
@code{sawfish.wm.edge.tile} - simple, but functional tiling function and
@code{sawfish.wm.edge.viewport-drag} - functions for dragging the viewport.

@section EdgeAction Internals

C-Subroutines (@code{sawfish.wm.edge.subrs}):

@defun create-flippers
Create the flipper-window, which is -to put it plainly- your screen-border.
Actions are performed when the flipper-window is activated. Technically it's
one window, but from users point of view it consists of 8 parts (4 borders
plus 4 corners).
@end defun

@defun destroy-flippers
Destroy the flipper-window.
@end defun

@defun recreate-flippers
Recreate the flipper-window, this is done automatically, when the resolution
changes, to ensure EdgeActions stays working properly.
@end defun

@defvr {HOOK} enter-flipper-hook
This hook is called when the flipper-window is entered.
@end defvr

@defvr {HOOK} leave-flipper-hook
This hook is called when the flipper-window is left.
@end defvr

Utils (@code{sawfish.wm.edge.utils}):

@defun activate-flippers t
A wrapper-functions around @code{recreate-flippers} and @code{destroy-flippers},
which additionally adds (respectively removes) the required hook-functions.
@end defun

@defun get-active-corner
This function returns the corner of the flipper-window which was entered, or nil.
@end defun

@defun get-active-border
This function returns the border of the flipper-window which was entered, or nil.
@end defun

Configuration infrastructure (@code{sawfish.wm.edge.conf}):

@defvr {HOOK} before-edge-action-hook
This hook is called before an edge-action is performed.
Passes @code{func}, @code{edge} and @code{while-moving} to the functions invoked.
@end defvr

@defvr {HOOK} after-edge-action-hook
This hook is called after an edge-action is performed.
Passes @code{func}, @code{edge} and @code{while-moving} to the functions invoked.
@end defvr

@defvr Customizable edge-actions-enabled nil
Global configuration, whether to enable or disable EdgeActions.
@end defvr

@defvr Customizable left-right-edge-action 'none/hot-spot
Action to perform for the left and right screen-edges when they are hit by the
pointer, either flip-workspace, flip-viewport, viewport-drag or none/hot-spot.
@end defvr

@defvr Customizable left-right-edge-move-action 'none/hot-move
Action to perform for the left and right screen-edges when a window is dragged over
them, either flip-workspace, flip-viewport, viewport-drag or none/hot-move.
@end defvr

@defvr Customizable top-bottom-edge-action 'none/hot-spot
Action to perform for the top and buttom screen-edges when they are hit by the
pointer, either flip-workspace, flip-viewport, viewport-drag or none/hot-spot.
@end defvr

@defvr Customizable top-bottom-edge-move-action 'none/hot-move
Action to perform for the top and bottom screen-edges when a window is dragged
over them, either flip-workspace, flip-viewport, viewport-drag or none/hot-move.
@end defvr

@defvr Customizable edge-flip-delay 250
"Delay (in milliseconds) of flipping of viewport / workspace."
@end defvr

@defvr Customizable hot-spot-delay 150
Delay (in milliseconds) before activating a hot-spot.
@end defvr

@defvr Customizable hot-spots-corner-length 50
Length in px (in both x and y direction) which is used for the hot-spot corners.
All remaining pixels represent the borders.
@end defvr

@defvr Customizable viewport-drag-distance 64
Amount to drag the viewport (in pixel) each time the pointer hits the screen edge.
@end defvr

@defvr Customizable viewport-drag-cursor-distance 32
"Amount to pull back the cursor (in pixel) after dragging the viewport."
Recommended is half of @code{viewport-drag-distance}.
@end defvr

Functionality infrastructure (@code{sawfish.wm.edge.actions}):

@defun activate-edges t
This function calls @code{activate-flippers} and adds the required
hook-functions to be able to perform user-actions on the edges.
@end defun

@defun activate-edges-after-set
This function is used by the @code{edge-actions-enabled} customizable to make
(de-)activating EdgeActions from SawfishConfig and resource-file work.
@end defun

@defun edge-action-call func edge while-moving
This function calls the desired user-action @code{func} for the screen-edge
@code{edge}. @code{while-moving} to distinguish whether a window is dragged or not.
@end defun

@defun edge-action-hook-func
This hook-function is responsible to either call @code{hot-spot-invoke} (if a
corner was activated) or to call @code{edge-action-call} to perform an action,
when the edge was activated using the pointer.
@end defun

@defun edge-action-move-hook-func
This hook-function is responsible to either call @code{hot-move-invoke} or to 
call @code{edge-action-call} to perfom an action, if the edge was activated
while dragging a window over it.
@end defun

EdgeFlip (@code{sawfish.wm.edge.flip}):

This is the traditional EdgeFlip. When a window or the pointer hits the
screen-edge, the screen is shifted by either one Viewport or one Workspace in
that direction. The pointer is warped accordingly (to keep in logical position).

@defun edge-flip-invoke edge type while-moving
This function invokes edge-fliping. edge (a symbol) is the screen-edge that is active
(left, right, top, bottom), type is either @code{flip-workspace} or @code{flip-viewport}.
@code{while-moving} is used to distinguish whether a window is dragged or not.
@end defun

ViewportDrag (@code{sawfish.wm.edge.viewport-drag}):

iViewportDrag (formerly Infinite-Desktop) is a mechanic, that shifts the
Viewport accordingly to which screen edge was activated. This way the Viewport
becomes virtually "infinite", regardless of the physical size (thus the old name).

@defun viewport-drag edge while-moving
This function invokes viewport-dragging. edge is the screen-edge that is active
(left, right, top, bottom) (a symbol).  @code{while-moving} is used to distinguish
whether a window is dragged or not.
@end defun

Tile (@code{sawfish.wm.edge.tile}):

Tiling is a mechanic to re-arrange windows in a non-overlapping way. Tiling as such
means to "organization of the screen into mutually non-overlapping frames, as opposed
to the more popular approach of coordinate-based stacking of overlapping objects".

@c maybe merge DMG quadrants stuff?
@c need untile-windows, respectively toggle-tiling for full expose experience
This simple approach Sawfish provides may also be known as "Expose" or "Mosaic".

Sawfish does not tile all windows visible. It filters by given rules:

- only current head (xinerama)
- only current workspace
- only current visible viewport
- exclude iconified windows
- exclude ignored windows
- exclude windows with @code{never-expose} matcher

@defun tile-windows
Interactive command to manually tile windows.
@end defun

@defun tile-windows-core edge while-moving
Internal function to tile windows when activating an edge.
@end defun

@defun window-never-expose-p w
Returns whether window should be tiled or not.
@end defun

HotSpots (@code{sawfish.wm.edge.hot-spots}):

HotSpots is a mechanic, which allows for practically everything to be done when
a screen edge or a corner is activated. the corners are defined via
@code{hot-spots-corner-length}. Only HotSpots responds to the corners.

HotMove is HotSpots' companion, which allows for practically everything to be done
when a screen edge is activated by dragging a window over it. HotMove doesn't know about
corners, it only sees for edges.

That way your screen-edge is actually split into 12: 4 corners, two times 4
edges (as explained above actions are split for when while moving a window and
for when activating the edges using the pointer). Corners are not recognized for
for while moving a window.

@c this is going to be changed by Teika, he said
@c I'll check into this before merging into master 11-07-08
HotSpots only allows functions to be used as actions, though practically
everything can be done this way. If the argument is not a function, an
error is thrown, to in form the user.

@defvr Customizable left-edge-function nil
The function launched when hitting the left-edge.
@end defvr

@defvr Customizable top-left-corner-function nil
The function launched when hitting the top-left-corner.
@end defvr

@defvr Customizable top-edge-function nil
The function launched when hitting the top-edge.
@end defvr

@defvr Customizable top-right-corner-function nil
The function launched when hitting the top-right-corner.
@end defvr

@defvr Customizable right-edge-function nil
The function launched when hitting the bottom-edge.
@end defvr

@defvr Customizable bottom-right-corner-function nil
The function launched when hitting the bottom-right-corner.
@end defvr

@defvr Customizable bottom-edge-function nil
The function launched when hitting the bottom-edge.
@end defvr

@defvr Customizable top-left-corner-function nil
The function launched when hitting the bottom-left-corner.
@end defvr

@defvar Customizable left-edge-move-function nil
The function launched when dragging a window over the left-edge.
@end defvar

@defvar Customizable top-edge-move-function nil
The function launched when dragging a window over the top-edge.
@end defvar

@defvar Customizable right-edge-move-function nil
The function launched when dragging a window over the right-edge.
@end defvar

@defvar Customizable bottom-edge-move-function nil
The function launched when dragging a window over the bottom-edge.
@end defvar

@defun hot-spot-invoke spot
This function invokes the hot-spot. spot (a symbol) is either left,
top-left, top, top-right, right, bottom-right, bottom or bottom-left.
@end defun

@defun hot-move-invoke spot
This function invokes the hot-spot while moving. spot (a symbol) is
either left, top, right, or bottom.
@end defun

Example configuration (@file{~/.sawfishrc}):

Note: this is just an example, not all functions in
      it may be available on your system.

@lisp
;; Timers
( defvar-setq edge-flip-delay 250 )
( defvar-setq hot-spot-delay 125 )

;; Activate screen edges
( activate-edges t )

;; HotSpots
( defvar-setq top-left-corner-function
  ( lambda () ( tile-windows ) ) )

( defvar-setq top-right-corner-function
  ( lambda () ( pager-unhide ) ) )

( defvar-setq  bottom-right-corner-function
  ( lambda () ( show-desktop ) ) )

( defvar-setq bottom-left-corner-function
  ( lambda () ( raise-window ( get-window-by-role "panel_" #:regex t ) ) ) )

( defvar-setq top-edge-function
  ( lambda () ( jump-or-exec "Konsole" "konsole" #:match-class t ) ) )

( defvar-setq bottom-edge-function
  ( lambda () ( jump-or-exec "Dolphin" "dolphin" #:match-class t ) ) )

;; HotMove
( defvar-setq top-edge-move-function
  ( lambda ( win ) ( maximize-window win ) ) )

( defvar-setq bottom-edge-move-function
  ( lambda ( win ) ( delete-window win ) ) )

;; actions when pointer hits edge
( defvar-setq left-right-edge-action 'flip-viewport )
( defvar-setq top-bottom-edge-action 'none/hot-spot )

;; actions while moving window hits edge
( defvar-setq left-right-edge-move-action 'flip-workspace )
( defvar-setq top-bottom-edge-move-action 'none )
@end lisp

@node RandR and Xinerama, Window Placement, Workspaces, Top
@chapter RandR and Xinerama
@cindex RandR
@cindex Xrandr
@cindex Xinerama

Sawfish supports multiple monitors displaying a single logical screen.
Partial support of RandR is done.

@defun has-randr-p
Returns @code{t} if RandR is supported.
@end defun

@menu
* Multi-head Environment::
* Screen Change Notification::
@end menu

@node Multi-head Environment, Screen Change Notification,, RandR and Xinerama
@section Multi-head Environment
@cindex Multi-head environments
@cindex Environments, multi-head
@cindex Monitors, multiple

Functions which provide information on monitor geometries are
available. On the other hand, few user interface functions take them
into account, so for example, windows often appear across multiple
monitors.

Currently, monitor geometries are taken from Xinerama only. RandR
support in this regard is yet to be done.

A ``head'' means each physical monitor. When there're multiple heads,
the word ``screen'' means the entire screen which is the combination
of all heads. For example the function @code{screen-width} returns the
width of the ``screen'' in this sense. A viewport contains the entire
screen. The only exception is maximizations which are done within a
head, unless stated explicitly that it's 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 @t{#!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 window-head-any-viewport window
Like @code{current-head}, this will return the ID of the head
containing the specified window.  But unlike @code{current-head},
@code{window-head-any-viewport} returns the head that the window would
be in if its viewport were the visible viewport.
@end defun

@defun current-head-dimensions @t{#!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 @t{#!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 Screen Change Notification, , Multi-head Environment, RandR and Xinerama
@section Screen Change Notification
@cindex Screen change notification
@cindex Change, of screen

If some changes happen to the screen, hot-plugging, removal, or
resolution change, then you can receive the notification.

One way is to use @code{configure-notify-hook}.(@pxref{X Hooks})
Then the window argument is set to the symbol @code{root}. The other way
is to use @code{randr-change-notify-hook} below. Both are called,
but there's no guarantee of the order.

Notice that both may be called several times for one change. For
example, ``xrandr'' command invocation from shell triggers three
calls of both hooks in an author's environment.

@defvr {Hook} randr-change-notify-hook
Called when screen configuration changes, via RandR extension support.
When RandR is not supported, then this hook will never be called.
@end defvr

@node Window Placement, Popup Menus, RandR and Xinerama, 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

Sawfish provides @dfn{popup menus}. Each line of a popup menu is
either an action or the parent of a submenu. Together with key and
mouse bindings, popup menus offer a command invocation method to
users.

@menu
* Ready-made Popups:: User options on ready-made popups.
* Applications Menu:: Description and usage of application menu.
* Popup Definitions:: How to manually define popup menus.
@end menu

@node Ready-made Popups, Applications Menu, Popup Menus, Popup Menus
@section Ready-made Popups

First let's see popup menus available out-of-box. There are root menu,
window operation menu, window list menu, applications menu, and
others.

The @dfn{root menu} is obviously the most important one. Many things can be
done from the root menu, including other menus invocation.  By
default, you can call the root menu by middle-clicking the background
screen, i.e., anywhere outside of all windows.

The @dfn{window operation menu} is what the name describes. You can call it
from window's frames like buttons or the title bar, depending on
themes.

The @dfn{window list menu} lets you choose a window. When selected,
that window is shown, raised, and focused.

The @dfn{applications menu} lets you invoke softwares. Many options are
available, and it's explained in the next section. (@pxref{Applications
Menu})

Popup menu invocation functions can be called from keyboard or mouse.

@defun popup-root-menu
Display the main menu.
@end defun

@defun popup-window-ops-menu
Display the window operation menu. This has several
bindings by default. In particular, clicking on a window's menu
button displays this menu.
@end defun

@defun popup-window-list-menu
Display the menu containing the list of all open windows.
@end defun

@defun popup-apps-menu
Popup the applications menu.
@end defun

Here are popup menu options.

@defvar menus-include-shortcuts
When true, menu items also display the key-binding. Defaults
to false.
@end defvar

The actual creation of a popup menu is performed by an auxiliary
process. By default, it stays after menu use is done, and reused
at the next menu invocation.

@defvar menu-program-stays-running
Defines if and how long the menu program stays alive after the
last menu has completed. If @code{nil}, the program is terminated
immediately. This means each time the popup menu is invoked, menu
program is executed.

If it's @code{t} it is left running indefinitely, if an integer then
the program may last for that many seconds.
@end defvar

You can modify menus. @xref{Popup Definitions}.

@node Applications Menu, Popup Definitions, Ready-made Popups, Popup Menus
@section Applications Menu
@cindex Applications menu
@cindex Menus, applications

The applications menu lets you invoke installed applications. Sawfish
generates applications menu from @file{*.desktop} files (usually found
in @file{/usr/share/applications/}) at Sawfish startup.

Functions in this section are defined in the module
@code{sawfish.wm.ext.apps-menu}.

@menu
* Applications Menu Variables::
* Applications Menu Functions::
* Desktop File Processing::
@end menu

@node Applications Menu Variables, Applications Menu Functions, Applications Menu, Applications Menu
@subsection Applications Menu Variables
@cindex Applications menu variables
@cindex Variables, applications menu

@defvar apps-menu-autogen
If non-nil, the applications menu is automatically generated from
the variable @code{user-apps-menu} and @file{*.desktop} files, and
stored in the variable @code{apps-menu}.  Default is @code{t}.

If you set the applications menu manually to the variable
@code{apps-menu}, then it won't happen anyway.
@end defvar

@defvar desktop-cat-alist
Defines categorization of applications. For example, if a
@file{*.desktop} file's category has an entry ``X-Desktop'', it'll be
classified as ``Desktop'' by Sawfish default.

If another option @code{apps-menu-associate-categories} is set to nil,
then the original value defined in @file{*.desktop} is respected.

If you want to customize this variable, see the file
@file{lisp/sawfish/wm/ext/apps-menu.jl} for the default value.
@end defvar

@defvar apps-menu-associate-categories
See the above. Default is @code{t}.
@end defvar

@defvar apps-menu-filter
The filter to use while generating the @code{apps-menu}. For the details,
see @xref{Desktop File Processing}.

It can be a symbol @code{default}, @code{some}, or a function.

The @code{default} filters include @code{fdo-toplevel-filter}
@code{fdo-nodisplay-filter} @code{fdo-hidden-filter}
@code{fdo-onlyshowin-filter} and @code{fdo-notshowin-filter}. This is
the default value.

The @code{some} filter only uses @code{fdo-notshowin-filter} and
@code{fdo-onlyshowin-filter}.

Or if it is set to nil, no filtering is done.
@end defvar

@defvar desktop-directory
List of directories to look for *.desktop files. Default is
@code{("/usr/share/applications")}.
@end defvar

@defvar kde-desktop-directories
KDE specific directories where *.desktop files are stored.
@end defvar

@defvar apps-menu-alphabetize
Sort the generated applications menu alphabetically.
Defaults is @code{t}.
@end defvar

@defvar apps-menu-lang
Human language for applications menu generation, in
string, like ``en'' for English. Default is set from the locale.
@end defvar

You can prepend anything to the applications menu, by setting the
variable @code{user-apps-menu}. An example definition:

@lisp
(("_xterm" (system "xterm &"))
 ("Emacs" (system "emacs &"))
 ("Firefox" (system "firefox &"))
 ("The _GIMP" (system "gimp &"))
 () ; Separation horizontal bar
 ) ;; Auto generated menu will follow.
@end lisp

@noindent
The @code{system} function simply executes its single argument using
@file{/bin/sh}. The underscore defines the keyboard shortcut.

If you set value to @code{apps-menu}, Sawfish doesn't generate
applications menu from @file{*.desktop} files.

@defvar apps-menu
The variable containing the definition of the applications menu. By default,
Sawfish automatically sets this.

If you set this variable manually, it is exclusively used, and Sawfish
doesn't generate its applications menu.
@end defvar

@defvar user-apps-menu
Your own applications menu entries. In the applications menu, this is
followed by auto generated applications menu.
@end defvar

@node Applications Menu Functions, Desktop File Processing, Applications Menu Variables, Applications Menu
@subsection Applications Menu Functions
@cindex Applications menu functions
@cindex Functions, applications menu

@defun popup-apps-menu
Display the applications menu.
@end defun

@defun update-apps-menu
Set @code{apps-menu} to @code{user-apps-menu}, and if
@code{apps-menu-autogen} is non-nil, append the auto generated one.
@end defun

@defun generate-apps-menu
Return the applications menu (a list), generated from @file{*.desktop}
files which can be set to @code{apps-menu}.
@end defun

Here're functions to process each desktop file. See also the next
section. (@pxref{Desktop File Processing})

@defun parse-fdo-file file
Parse an *.desktop file @var{file} list.
Returns @code{(group1 (key1 . value1) ... group2 (keyA . valueA) ...)}
@end defun

@defun fdo-filter-record fdo-list filter
Let @var{filter} process a desktop file entry @var{fdo-list}, and
return the result.

If @var{filter} is a function, it's executed with the argument
@var{fdo-list}. If it's a symbol @code{default} or @code{some}, then
@code{fdo-default-filter} or @code{fdo-some-filter} is exectuted,
respectively. If @var{filter} is not defined, will return the input
@code{fdo-list}.

This can be useful for testing filters, and is also used internally.
@end defun

@node Desktop File Processing, , Applications Menu Functions, Applications Menu
@subsection Desktop File Processing
@cindex Applications menu filtering
@cindex Filtering, applications menu

In this section it is shown how Sawfish processes desktop file entries
while building the applications menu. Each entry passes through many
@dfn{filters}, and they're what you may want to customize.

Desktop file entries are expressed as a list. Here is an example of
@file{emacs.desktop} file before any filters are performed:

@lisp
("Desktop Entry"
	   ("Name" . "Emacs Text Editor")
	   ("Name[de]" . "Emacs Texteditor")
	   ("GenericName" . "Text Editor")
	   ("Comment" . "Edit text")
	   ("Exec" . "emacs %f")
	   ("Icon" . "emacs-icon")
	   ("Type" . "Application")
	   ("Terminal" . "false")
	   ("Categories" . "Development;TextEditor;")
	   ("StartupWMClass" . "Emacs"))
@end lisp

It then gets split into two lists. The original ``Categories'' key
contains several values, and each of new entries has ``Category'' key
which contains only one of the original categories.

@lisp
("Desktop Entry"
	   ("Name" . "Emacs Text Editor")
	   ("Name[de]" . "Emacs Texteditor")
	   ("GenericName" . "Text Editor")
	   ("Comment" . "Edit text")
	   ("Exec" . "emacs %f")
	   ("Icon" . "emacs-icon")
	   ("Type" . "Application")
	   ("Terminal" . "false")
	   ("Categories" . "Development;TextEditor;")
	   ("Cateogry" . "Development") ; Look here
	   ("StartupWMClass" . "Emacs"))

("Desktop Entry"
	   ("Name" . "Emacs Text Editor")
	   ("Name[de]" . "Emacs Texteditor")
	   ("GenericName" . "Text Editor")
	   ("Comment" . "Edit text")
	   ("Exec" . "emacs %f")
	   ("Icon" . "emacs-icon")
	   ("Type" . "Application")
	   ("Terminal" . "false")
	   ("Categories" . "Development;TextEditor;")
	   ("Cateogry" . "TextEditor") ; Look here
	   ("StartupWMClass" . "Emacs"))
@end lisp

@noindent
This is the entry list format that is used in all of the later filters.
All filtering functions should accept such an entry list as its argument,
and all filtering functions should either return nil or an entry list.
If @code{fdo-associate-categories} is @code{t} then the ``Category'' key will be
changed to the main category that will eventually show up in the @code{apps-menu}.
The keys that are used by the applications menu are currently,

@itemize @bullet
@item Name([])

The name to be displayed in the applications menu. If
@code{apps-menu-lang} or the locale coincides with one of the
Name[lang] keys in the entry list, then that will be the name used.

@item Exec

The command to be run when the entry is called.

@item Terminal

Whether or not to run the @code{Exec} value inside of a terminal or
not. If it's true, the terminal specified by @code{xterm-program} is
used.

@item Category

Which top-level category to place the entry in.

@item Hidden

Whether or not the entry should be hidden by default.

@item NoDisplay

Whether or not the entry should be displayed by default.

@item NotShowIn

If an item should not be shown by checking the current desktop
environment against the value of this key.

@item OnlyShowIn

If an item should be shown by checking the current desktop environment
against the value of this key.
@end itemize

@subsubheading Filters
Filters are functions, either pre-defined or user-defined, which take
one argument, a desktop file entry. You can set your filter to the
@code{apps-menu-filter} variable.

Here we show an example user-defined filter, and all pre-defined
filters, which are also available to user codes.

@lisp
;; This will move emacs to the ``util'' category, in addition to the
;; operations done by default filter.
(setq apps-menu-filter
      (lambda (ent)
	(let ((ent (fdo-default-filter ent)))
	  (when ent
	    (cond ((string-match "[Ee]macs" (cdr (assoc "Name" ent)) nil t)
		   (rplacd (assoc "Category" ent) "util")))
	    ent))))
@end lisp

@noindent
The pre-defined filters:

@lisp
(define (fdo-nodisplay-filter fdol)
  "Return the desktop-file-list if NoDisplay is False, or if NoDisplay is
not present in the desktop-file-list"
  (if (assoc "NoDisplay" fdol)
      ;; [Ff] means match to "false"
      (if (string-match "[Ff]" (cdr (assoc "NoDisplay" fdol)))
      	  fdol)
    fdol))

(define (fdo-hidden-filter fdol)
  "Return the desktop-file-list if Hidden is False, or if Hidden is
not present in the desktop-file-list"
  (if (assoc "Hidden" fdol)
      (if (string-match "[Ff]" (string-downcase (cdr (assoc "OnlyShowIn" fdol))))
	  fdol)
    fdol))

(define (fdo-onlyshowin-filter fdol)
  "Return the desktop-file-list if OnlyShowIn matches `desktop-environment',
or if OnlyShowIn is not present in the desktop-file-list"
  (if (assoc "OnlyShowIn" fdol)
      (if (string-match desktop-environment (string-downcase (cdr (assoc "OnlyShowIn" fdol))))
	  fdol)
    fdol))

(define (fdo-notshowin-filter fdol)
  "Return the desktop-file-list if NotShowIn does not match `desktop-environment',
or if NotShowIn is not present in the desktop-file-list"
  (if (assoc "NotShowIn" fdol)
      (if (not (string-match desktop-environment (string-downcase (cdr (assoc "NotShowIn" fdol)))))
	  fdol)
    fdol))

(define (fdo-associate-categories-filter fdol)
  "If `apps-menu-associate-categories' is true, filter the
desktop-entry through `fdo-associate-categories'."
  (when fdol
    (if apps-menu-associate-categories
	(associate-categories fdol)
      fdol)))

(define (fdo-toplevel-filter fdol)
  "Return the desktop-file-list if the `Category' is of the
Top-Level variety."
  (when fdol
    (if (not (equal "Top-Level" (cdr (assoc "Category" fdol))))
	fdol)))

(define (fdo-default-filter fdol)
  "The default fdo-filter, combines the above."
  (fdo-toplevel-filter
   (fdo-hidden-filter
    (fdo-notshowin-filter
     (fdo-onlyshowin-filter
      (fdo-nodisplay-filter fdol))))))

(setq apps-menu-filter fdo-default-filter)
@end lisp

@node Popup Definitions, , Applications Menu, Popup Menus
@section Popup Definitions
@cindex Popup definitions
@cindex Definitions, popup

Sawfish comes with ready-made popup menus. This section describes
how you can modify them.

An entire popup menu is specified by a list. Each element corresponds
to a menu item, in the displayed order from top to bottom. Example:

@lisp
(("Item _1" command-1)   ;; list for a command.
 ("Item _2" . submenu-2) ;; cons for a submenu.
 ()                      ;; nil makes a seperator line
 ("_xterm" (system "xterm &")) ;; lisp expression is possible too.
@end lisp

Each menu item is typically specified by a list with two elements.
The first is the name; it's a string, and displayed in the menu.
An underscore (_) before a character defines an accelerator, or
a shortcut key.

The second element specifies the action to take. Possible choices are:

@table @asis
@item Command
If it's a command name (a symbol), then that command is invoked.
In the window operation menu, if that command takes a window as the
argument, it's passed.

@item Lisp expression
If it's a lisp expression, then it's evaluated inside of the
@code{user} module.

@item Function
If it's a function (a closure or a subr), then it's invoked with
no argument.
@end table

@noindent
If an item is nil (instead of a list with two elements), then it's
printed as a seperator line.


An item can invoke a submenu. In this case, the item is a cons. The
car is the printed name. The cdr is a symbol which is the name of a
variable. That variable specifies another menu's contents.  Or the
variable refers to a function, it's invoked, and the return value is
used. Notice that this variable has to be special, or dynamically
scoped, so that its value can be seen inside of the involved module.

It's possible to pass a list with more than two elements as an item,
but it is not explained. (Read the code and please tell us the usage.)

Let's see one more example:

@lisp
(("Workspaces" . workspace-menu)
 ("Windows" . window-menu)
 ("Programs" . apps-menu)
 ("Customize" . custom-menu)
 ("About..." (customize 'about))
 () ; Separation horizontal bar.
 ("Restart" restart)
 ("Quit" quit))
@end lisp

@noindent
This is the old definition of Sawfish's root menu. We can see that
four submenus are created by seeing the value of variables.
They contain functions, and they're invoked.

@defun popup-menu spec
Displays a menu defined by the list of item definitions @var{spec}.
@end defun

@defvar root-menu
Contains the root menu definition.
@end defvar

@defvar window-ops-menu
The variable containing the definition of all window operations.
@end defvar

Popup menu is made by making a separate process.

@defvar menu-program
Location of the program implementing Sawfish's menu interface.
@end defvar

Mainly for developers, one more esoteric thing, ``toggle menu'', is
explained.

@defvar window-ops-toggle-menu
The toggle type submenu of window operations, like ``sticky'' or
``shaded''. 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 @t{#!optional} predicate
Add an item 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

Lisp ``event'' object is a representation of input, regardless of actual
or expected. If it's a keypress for example, it tells which key with
which modifiers are pressed, and that's all. Please do not confuse it
with X or other's event which is generated only after keypress or
other ``event''.

Each X input event induced by the mouse or the keyboard has a Lisp
representation. X input events that Sawfish receives are either for
the root window, the window frames it creates, or grabbed from the
client windows themselves.

Sawfish can respond to X events other than input, most often via
hooks. (@pxref{Standard Hooks})

@defun eventp object
This function returns @code{t} if its argument is an event.
@end defun

@menu
* Event Name Representation::   Raw object versus string name
* Event Modifiers::             Meta, Alt, Buttons
* Event Actions::               Keys and Clicks
* Event Matching::
* Synthesis of Events::            Creating events that seem real
@end menu

@node Event Name Representation, Event Modifiers, Events, Events
@section Event Name Representation
@cindex Name, of Event

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
event object 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) ;; Internally, event is a pair of integers.

(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 Name 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}, in order to
distiguish from shift

@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,
including no modifier.
@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}.

You have to set the variable @code{eval-key-release-events} to
@code{non-nil} to use this modifier.

@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, Synthesis of 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 Synthesis of Events,  , Event Matching, Events
@section Synthetic Events
@cindex Synthesis of Events
@cindex Events, Synthesis
@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 @t{#!optional} propagate
Generate a synthetic key press or button press and send it to the X
window bound to the @var{window} object. Pass the symbol @code{root}
for the root window. 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 Name 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 roughly speaking a lisp function which can be
called from key or mouse input. But it may be preferable for example
to pass the currently focused window as the argument, and such
mechanism is prepared.  So Sawfish distinguishes the notion of
commands from functions.

Formally stated, a command is an association of the name to a
function, and a way to pass the arguments, and so on.

The name space of commands are independent of that of bindings (which
includes functions.)

@defvar customize-command-classes
In configurator "binding" section, show commands of these
classes. It is a list. Possible keys are @code{default}, @code{advanced},
@code{viewport}, and @code{deprecated}.

The default value is @code{(default)}.
@end defvar

@menu
* Command Definition::          Common-Lisp style
* Old-style Command Definition:: Emacs-Lisp style (deprecated)
* Interactive Calling Specification::
* Operations on Commands::	Accessors and the like
* Invoking Commands::           Invocation in lisp side
@end menu

@node Command Definition, Old-style Command Definition, , Commands
@section Command Definition

@defun define-command name fun #!key spec type doc class
Define a command called @var{name} (a symbol).  The function @var{fun}
will be called to execute the command.

@var{spec} defines how the arguments are passed by the interactive
call of the command. @xref{Interactive Calling Specification}.

@var{doc} is the documentation string associated with the command.
If it's lacking, that of the function @var{fun} will be looked up.

Other arguments are mostly for internal use.

@var{type} specifies arguments, too. These arguments are statically
set in ``Bindings'' section of the configurator. If @var{type} is set,
then a lisp expression like @code{(command-name arg1 arg2...)} is bound
to the key, in contrast to the usual case where command name is bound.
(The precise doc is lacking.)

@var{class} is a symbol which annotates the command, for example
@code{advanced}. Users can choose which commands are shown in the
configurator according to @var{class}. See the documetation
of @code{customize-command-classes} (@pxref{Commands}.)
@end defun

@defun define-command-to-screen name fun #!key spec type doc class
As @code{define-command}, but any printed output of @var{fun} is sent
to the screen, i.e. @code{standard-output} is redirected.
@end defun

@defun autoload-command name module #!key spec type doc 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 Old-style Command Definition, Interactive Calling Specification, Command Definition, Commands
@section Old-style Command Definition

GNU Emacs-like command definition is a deprecated, old-syntax, but
still supported. There command definition is included in function
definition. The first form in the function body must be an
@dfn{interactive declaration} which 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 Interactive Calling Specification, Operations on Commands, Old-style Command Definition, Commands
@section Interactive Calling Specification

The @var{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:

@table @asis
@item @code{nil} or undefined
No arguments are given to the command.

@item A string
It consists of 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 table

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

We can extract certain information about commands.

@defun commandp @var{symbol}
Returns @code{t} if @var{symbol} is a command name.
@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

@defun report-commands #!optional type all
Returns the list of commands. Each element is the symbol of a command
name, and they're sorted alphabetically.

The optional argument @var{type} is for internal use. when it's non-nil,
@code{(command-name #:type type-param)} is returned for commands with
``type'', instead of a symbol.

If the optional argument @var{all} is nil, returns commands only user
wants, i.e. those specified by @code{customize-command-class} are
included. Else, all commands are returned.
@end defun

@node Invoking 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 @t{#!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. The value is only set during
command call, and @code{nil} anytime else.
@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 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 an 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

Currently, multiple keystrokes can't be bound with a single
@code{bind-keys} call. Instead, bind an event to another keymap.
@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

Functions @code{bind-keys} and @code{unbind-keys} do not affect the
bindings of existing windows, because keymaps are set on a window when
the window is created and begins to be managed by Sawfish. Update
can be done by following functions.

@defun grab-keymap keymap
@defunx ungrab-keymap keymap
All bindings stored in @var{keymap} get into / out of effect of all
windows, including root, but not of frame parts.

Notice that @code{ungrab-keymap} has to be called BEFORE you change
the keymap.

If the window foo has its own keymap rather than @code{window-keymap},
then it is not affected by @code{(grab-keymap window-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
@itemx sticky-button-keymap
@itemx lock-button-keymap
@itemx rename-button-keymap
@itemx move-resize-button-keymap
@itemx raise-lower-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 @t{#!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.

If the optional argument @var{win} is a window, then it will be
returned as the current event window.
@end defun

@defun last-event
Return the previous event which occurred.
@end defun

@defun proxy-current-event window @t{#!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 @t{#!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, External Applications, Event Loop, Top
@chapter Miscellaneous Functions
@cindex Miscellaneous functions

@menu
* Pointer Functions::
* Grab Functions::
* Display Functions::
* Rectangle Functions::
* Gradient Functions::
* Sawfish Invocation Functions::
* Other Functions::
@end menu

@node Pointer Functions, Grab Functions, , Miscellaneous Functions
@section Pointer Functions
@cindex Pointer functions
@cindex Functions, pointer

@defun query-pointer @t{#!optional} from-server
Returns a cons cell @code{(x . 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 @t{#!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

Sawfish provides functions to move the pointer relative to the current
positions. They're named ``move-cursor'', and defined in
@code{sawfish.wm.commands.move-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 functions.  All of
them are commands, too.

@defun move-cursor-left-fine
@defunx move-cursor-right-fine
@defunx move-cursor-up-fine
@defunx move-cursor-down-fine
@defunx move-cursor-northwest-fine
@defunx move-cursor-northeast-fine
@defunx move-cursor-southwest-fine
@defunx move-cursor-southeast-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
@defunx move-cursor-northwest
@defunx move-cursor-northeast
@defunx move-cursor-southwest
@defunx move-cursor-southeast
Move the cursor @code{move-cursor-increment} pixels in the indicated
direction. @code{move-cursor-northeast} is equal to the northward
move cobmined with the eastward.
@end defun

@defun move-cursor-center
Move the cursor to the center of the screen.
@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 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 @t{#!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 @t{#!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, Rectangle 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 @t{#!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.

The window is placed on top of X client windows, and basically at the
center of the screen. The window remains until another call of this
function, or the user clicks on it.

@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

Tip: Don't call this function during initialization. Instead, use
@code{after-initialization-hook} to defer. Otherwise the message
window is covered by X client windows.
@end defun

@node Rectangle Functions, Gradient Functions, Display Functions, Miscellaneous Functions
@section Rectangle Functions
@cindex Rectangle functions
@cindex Functions, rectangle

Rectangles define a region of the display.  A rectangle is a list of
values: @code{(left top right bottom [weight])}.  @code{left} and
@code{top} are the @code{x} and @code{y} coordinates of the upper left
corner, @code{right} and @code{bottom} are the coordinates for the lower
right corner.  @code{weight} is an integer.  The bulk of the rectangle
management functions are in sawfish.wm.util.rects.

@defun rect-left rect
The x-axis value of the left side of the rectangle.  Equivalent to
@code{car}
@end defun

@defun rect-top rect
The y-axis value of the top of the rectangle.  Equivalent to
@code{cadr}
@end defun

@defun rect-right rect
The x-axis value of the right side of the rectangle.  Equivalent to
@code{caddr}
@end defun

@defun rect-bottom rect
The y-axis value of the bottom of the rectangle.  Equivalent to
@code{cadddr}
@end defun

@defun rect-obscured r by
Check whether the rectangle @code{r} is wholly or partially contained in
rectangle @code{by}.  Returns one of the symbols @code{unobscured},
@code{partially-obscured}, or @code{fully-obscured}.
@end defun

@defun rect-minus r s @t{#!optional} tail
Return a list of rectangles whose union is the part of rectangle
@code{r} not contained in rectangle @code{s}.  If @code{tail} is given,
the result is prepended to it.
@end defun

@defun rectangles-from-grid x-points y-poinst @t{#!optional} pred
The two lists of integers @code{x-points} and @code{y-points} define a
rectangular grid. Return the complete list of rectangles formed by the
intersections of the grid.

If @code{pred} is defined it is called for each rectangle and only those
for which it returns @code{t} are added to the returned list.

Assumes that @code{x-points} and @code{y-points} are both sorted
smallest->largest.
@end defun

@defun rectangles-from-windows windows @t{#!optional} weight-fun
Returns a list of rectangle objects representing the list of window
objects @code{windows}.

If @code{weight-fun} is defined, it is a function to call on each window
to return the weight for that window. If not defined, the window's
@code{weight} property is used instead.
@end defun

@defun grid-from-rectangles rects @t{#!optional} with-root
Given a list of rectangles @code{rects} return a cons cell
@code{(x-points . y-points)} defining the grid they represent.

If @code{with-root} is non-nil, then add the root window boundaries to
the grid.
@end defun

@defun rectangle-area rect
Returns the area of the specified rectangle.
@end defun

@defun rectangle-from-coords point dims
Return the rectangle object with origin @code{point} and dimensions
@code{dims}.
@end defun

@defun rectangle-corners
Return a list of four cons cells representing the coordinates of the
corners of the rectangle @code{rect}.
@end defun

@defun rectangle-center rect
Returns a cons cell of the (approximate, to the nearest integer)
coordinates of the center of the rectangle @code{rect}.
@end defun

@defun rectangle-center* point dims
The same as @code{rectangle-center} except that the rectangle is
specified via the x,y coordinates @code{point} and the dimensions
@code{dims}.
@end defun

@defun rectangle-union rect1 rect2
Gives the smallest rectangle containing both @code{rect1} and
@code{rect2}.  The weight of the resulting rectangle is the weight of
@code{rect1}.
@end defun

@defun rectangle-intersection rect1 rect2
Gives the intersection of the two rectangles @code{rect1} and
@code{rect2}.  The weigth of the resultant rectangle is the weight of
@code{rect1}.  Returns @code{nil} if there the two rectangles do not
intersect.
@end defun

@defun rect-1d-overlap a-1 a-2 b-1 b-2
@code{a-1} to @code{a-2} indicates one line segment and @code{b-1} to
@code{b-2} indicates another.  Returns the overlap between the two line
segments.
@end defun

@defun rect-2d-overlap dims point rect
Returns the overlap between two rectangles, one with dimensions
@code{dims} and upper-left corner at @code{point}; the other is defined
by @code{rect}.
@end defun

@defun rect-2d-overlap* rect1 rect2
Like @code{rect-2d-overlap}, except that the rectangles are
@code{rect1} and @code{rect2}.
@end defun

@defun rect-total-overlap dims point rects
Returns the total area of the overlap between a rectangle defined by
@code{dims} and @code{point}, and the list of rectangles @code{rects}
when placed at @code{point}.
@end defun

@defun rect-wholly-within-rect outer inner
Returns @code{t} if @code{inner} is completely within the boundaries of
@code{outer}.
@end defun

@defun rect-wholly-visible-p
Returns @code{t} if @code{rect} is completely inside the screen
boundaries.
@end defun

@defun rectangle-heads
Returns the number of screen heads that the rectangle @code{rect}
appears on.
@end defun

These functions are found in sawfish.wm.viewport:

@defun rect-within-viewport-p rect @t{#!optional} viewport
Return @code{t} if @code{rect} is entirely inside the screen boundaries
for some viewport, regardless of whether it is the current viewport, or
even if the viewport currently exists.  If @code{viewport} is specified
check only against that viewport.
@end defun

@defun rect-within-head-p rect @t{#!optional} head
Return @code{t} if @code{rect} is entirely within some head on some
viewport. If @code{head} is provided @code{rect} must be within that
head on some viewport.
@end defun


@node Gradient Functions, Sawfish Invocation Functions, Rectangle Functions, Miscellaneous Functions
@section Gradient Functions
@cindex Gradient functions
@cindex Functions, gradients

The @code{gradient} feature allows color gradients to be drawn in
images. Import @code{gradient} or @code{sawfish.wm.util.gradient}
to use 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 Sawfish Invocation Functions, Other Functions, Gradient Functions, Miscellaneous Functions
@section Sawfish Invocation Functions
@cindex Sawfish Invocation Functions
@cindex Functions, Sawfish invocation

@defvar sawfish-version
The version number of the running Sawfish.
@end defvar

@defvar sawfish-directory
The home directory for Sawfish files.  For example:
@code{"/usr/share/sawfish"}. You can override it with the environment
variable @code{SAWFISHDIR}.
@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"}. You can
override it with the environment variable @code{SAWFISHEXECDIR}.
@end defvar

@defvar sawfish-lisp-lib-directory
The top-level directory for Sawfish lisp files.  For example:
@code{"/usr/share/sawfish/1.3/lisp"}. You can override it with the
environment variable @code{SAWFISHLISPDIR}.
@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"}. You can override it
with the environment variable @code{SAWFISHSITELISPDIR}.
@end defvar

@defvar sawfish-user-lisp-directory
The list of user's sawfish lisp directories. The default value is
@code{($HOME/.sawfish/lisp)}. It is prepended to @code{load-path}, so
that files under these directories are searched prior to
@code{sawfish-lisp-lib-directory}.

You can override the value with environment variable
@code{SAWFISH_USER_LISP_DIR}. Paths are separated by colon, like
the @code{PATH} environmental variable. Example:
@code{~/.sawfish/lisp-test:~/.sawfish/lisp}.
@end defvar

@defun quit
@defunx restart
Quits and restart Sawfish.

Restart does exec (3), replacing the current process. All command line
arguments are used again, except that session management related ones
are updated.

There also exist same name commands.
@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 poweroff action
A function for rebooting, halting, suspending and hibernating
your machine. Normally this is only used when running outside
of GNOME or KDE; they provied their own versions of functions.

@var{action} is a symbol, and each invokes the shell command
defined by the variable as follows:

@multitable @columnfractions .2 .5
@headitem @var{action} @tab variable
@item @code{reboot} @tab @code{reboot-command}
@item @code{halt} @tab @code{halt-command}
@item @code{suspend} @tab @code{suspend-command}
@item @code{hibernate} @tab @code{hibernate-command}
@end multitable

When @var{action} is @code{reboot} or @code{halt},
@code{before-exit-hook} is called, and @code{delete-windows} is
applied to each window to ensure we safely quit the current session.
@end defun

@defvar want-poweroff-menu
If you don't use GNOME, KDE, nor XFCE, power off related actions
are added under the root menu -> ``Sessions''.
@end defvar

@node Other Functions, , Sawfish Invocation 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 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), except options related to session mangement.
@end defvar

@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 w 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

@deffn Command run-shell-command
Executes a shell command. This is a wrapper for @code{system}
function, so in lisp code, use it instead. (@pxref{Shell Commands, ,
,librep}.)
@end deffn

@deffn Command no-operation
Does nothing.
@end deffn

@node External Applications, Standard Hooks, Miscellaneous Functions, Top
@chapter External Applications
@cindex External applications

In this chapter relation to external applications is described.
See also @xref{Applications Menu}, which is a popup to execute applications.

@menu
* Application Invocation::
* Common Applications::         terminal, browser, and so on.
@end menu

@node Application Invocation, Common Applications,, External Applications
@section Application Invocation

See also the lisp function @code{system} which invokes a command from
a shell.  (@pxref{Shell Commands,,, librep, The Librep Manual})

@defun jump-or-exec regex prog #!key match-class onfocused
Jump to a window, or if it doesn't exist, start a program. Main use of
this function is as a binding to keys. Defined in the
module @code{sawfish.wm.commands.jump-or-exec}.

Window is searched by matching the name with a regex @var{regex}.  If
@emph{boolean}@var{match-class} is non-nil, the value of @var{regex}
is matched with window's WM_CLASS. When no window matches, action
specified by @var{prog} is taken.

If @var{prog} is a string, then it should be a program name, and
executed from a shell in the background. (I.e. Sawfish adds ''&''.)
Otherwise, it should be one of a function, command name, or lisp
expression. The function is called without any argument. The lisp
expression will be evaluated in the @code{user} module.

If the optional argument @var{onfocused} is non-nil, it defines the
action when the window is already focused, in the same manner as
@var{prog}, but the function will receive the focused windows as the
argument. This can't be a string.

@lisp
;; Examples:

;; Jump to a window named "Geany". When not found, invoke "geany" 
;; from a shell.
(bind-keys global-keymap "W-F10"
  '(jump-or-exec "Geany" "geany"))

;; Jump to a window with the class "Gnome-run-dialog".
(bind-keys global-keymap "W-F2"
  '(jump-or-exec "Gnome-run-dialog" "/usr/local/bin/gnome-run-dialog" #:match-class t ))
@end lisp

@end defun

@defun toggle-or-exec regex prog #!key match-class
This function adds to @code{jump-or-exec} by turning a window to
``quake''-like "toggle-windows". That means, if this function is invoked
on a matching window, that window will be iconified. Else it works in
the same way as @code{jump-or-exec}.

You may also want to use a window property
@code{iconify-on-leave}. (@pxref{Iconifying Windows}.)

@lisp
;; Examples:

;; Application "dolphin", matched by its name (i.e. WM_NAME.)
;; Press "Home" key, and
;; * if no instance of dolphin is running, it's invoked.
;; * if one is there, the focus jumps to it.
;; * if it's already focused, it will be iconified.
;;
;;  ( bind-keys global-keymap "Home" 
;;    `( toggle-or-exec "Dolphin" "dolphin ~" )

;; "konsole", matched by its window-class (= WM_CLASS).
;;  ( bind-keys global-keymap "F12"
;;    `( toggle-or-exec "Konsole" "konsole" #:match-class t ) 
@end lisp

@end defun

@node Common Applications,, Application Invocation, External Applications
@section Common Applications
There're some functions and variables for invocation of external
applications. They're defined in @code{sawfish.wm.commands.launcher}
module.

@defvr {Customizable} xterm-program
The program launched by the @code{xterm} function. Interpreted by shell.
@end defvr

@deffn Function xterm @t{#!optional} command
@deffnx Command xterm
Start a new terminal specified the option @code{xterm-program}.

Optional argument @var{COMMAND} is passed to the terminal with
@code{-e} option, so for most terminals, including xterm, it can
contain arguments to be passed.
@end deffn

@defvr {Customizable} browser-program
The program launched by the @code{browser} function. Interpreted by shell.
@end defvr

@deffn Function browser @t{#!optional} url
@deffnx Command browser
Start a new browser instance. Visit @var{URL} if supplied.
@end deffn

Sawfish detects some desktop environments.
@defvar desktop-environment
Running desktop environment, detected by Sawfish.
Possible values are "kde", "gnome", "xfce", or "none".
@end defvar

@node Standard Hooks, Standard Properties, External Applications, 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. Such hook is called ``window
hook''. If a window 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 @t{#!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})}.

Root window is represented by the symbol @code{root}.
@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 and Viewport 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

The hook functions are passed one argument which is the command name.

@defvr {Hook} pre-command-hook
Called before invocation of each command. You can modify
@code{this-command} here. In particular, if it's set to @code{nil} in
this hook, then the command won't be executed.
@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-put}).

@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} configure-notify-hook
Called when an X @code{ConfigureNotify} event is received, i.e.
when window configuration request is complete.
@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 whenever 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 and Viewport Hooks, X Hooks, Standard Hooks
@section Pointer Motion Hooks
@cindex Pointer Motion Hooks
@cindex Hooks, Pointer Motion

@defvr {Window Hook} enter-notify-hook
@defvrx {Window Hook} enter-frame-part-hook
@defvrx {Window Hook} leave-notify-hook
@defvrx {Window Hook} leave-frame-part-hook
Called when the pointer enters or leaves a window, respectively.

If the window was part of a frame, then @code{enter-frame-part-hook}
or @code{leave-frame-part-hook} is called with three arguments: the
window, the frame part class (@pxref{Frame Part Classes}), and
@var{mode}. @var{mode} is one of the symbols @code{normal},
@code{grab} or @code{ungrab}.

Otherwise @code{enter-notify-hook} or @code{leave-notify-hook} is
called with two arguments: the window and @var{mode}.

Entering the root window is reported, too. In that case, the
symbol @code{root} is returned in place of a window object.
@end defvr

@defvr {Window Hook} focus-in-hook
@defvrx {Window Hook} focus-out-hook
Called when a window gains or loses focus, respectively.  The hook
function receives two arguments: the window that received / lost
focus, and @var{mode}. @var{mode} is one of the symbols @code{normal},
@code{grab}, @code{ungrab} or @code{while-grabbed}.

If your @code{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 nor loses focus.
@end defvr

@node Workspace and Viewport Hooks, Startup and Shutdown Hooks, Pointer Motion Hooks, Standard Hooks
@section Workspace and Viewport Hooks
@cindex Workspace Hooks
@cindex Viewport Hooks
@cindex Hooks, Workspace and Viewport

@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
Hook called when the number of rows and columns in each
workspace is changed.
@end defvr

@defvr {Hook} viewport-moved-hook
Called when the origin of the viewport into the workspace is
moved.
@end defvr

@defvr {Hook} enter-flipper-hook
@defvrx {Hook} leave-flipper-hook
See @xref{EdgeActions}.
@end defvr

@node Startup and Shutdown Hooks, Other Hooks, Workspace and Viewport 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 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 iconify-on-leave
Iconify this window then the mouse pointer leaves. @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.

@item animator
Animator when iconified. (@pxref{Animating Windows})

@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 @t{#!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 @t{#!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 @t{#!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

These functions are defined in @code{sawfish.wm.util.selection}.

@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 Bitmaps and Pixmaps

@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
@defunx x-drawable-width drawable
Return the height / width 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-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 Drawing

@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) @t{#!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-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 @t{#!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 @t{#!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

Two functions to draw strings are there. If you need to write a
message like @code{display-message} use @code{x-draw-string}. If you
need to write on the root-window directly, use @code{x-draw-text}.

@defun x-draw-string window gc (x . y) string @t{#!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. See also @code{x-draw-text}.
@end defun

@defun x-draw-text window gc (x . y) string
Draw the specified string at @code{(@var{x}, @var{y})} in @var{window}
using the graphics context @var{gc}. See also @code{x-draw-string}.
@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
