summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@herrb.eu>2020-10-16 19:11:09 +0200
committerMatthieu Herrb <matthieu@herrb.eu>2020-10-16 19:11:09 +0200
commitcc565f59c0ba5de8033489bb5235394f7717e743 (patch)
tree2e36697cf1a525bd2a0365e81804b5fa8cd85e60
parent61ee3956355d1b5d9993191b0000024b60a8d34b (diff)
parent12ae76feef16024a0911b0e61e64266b449599e7 (diff)
Merge remote-tracking branch 'origin/master' into obsd
-rw-r--r--configure.ac4
-rw-r--r--man/twm.man125
-rw-r--r--src/Makefile.am3
-rw-r--r--src/add_window.c52
-rw-r--r--src/cursor.c13
-rw-r--r--src/events.c40
-rw-r--r--src/gram.y1324
-rw-r--r--src/iconmgr.c23
-rw-r--r--src/iconmgr.h2
-rw-r--r--src/icons.c7
-rw-r--r--src/icons.h2
-rw-r--r--src/lex.l119
-rw-r--r--src/list.c5
-rw-r--r--src/menus.c193
-rw-r--r--src/menus.h2
-rw-r--r--src/parse.c88
-rw-r--r--src/resize.c7
-rw-r--r--src/resize.h2
-rw-r--r--src/session.c8
-rw-r--r--src/session.h3
-rw-r--r--src/twm.c205
-rw-r--r--src/twm.h28
-rw-r--r--src/util.c126
-rw-r--r--src/util.h2
24 files changed, 1302 insertions, 1081 deletions
diff --git a/configure.ac b/configure.ac
index ef7e482..db01b62 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,14 +22,14 @@ dnl Process this file with autoconf to create configure.
# Initialize Autoconf
AC_PREREQ([2.60])
-AC_INIT([twm], [1.0.10.2],
+AC_INIT([twm], [1.0.11.1],
[https://gitlab.freedesktop.org/xorg/app/twm/issues], [twm])
AC_CONFIG_SRCDIR([Makefile.am])
AC_CONFIG_HEADERS([config.h])
AC_USE_SYSTEM_EXTENSIONS
# Initialize Automake
-AM_INIT_AUTOMAKE([foreign dist-bzip2])
+AM_INIT_AUTOMAKE([foreign dist-xz])
# Require X.Org macros 1.8 or later for MAN_SUBSTS set by XORG_MANPAGE_SECTIONS
m4_ifndef([XORG_MACROS_VERSION],
diff --git a/man/twm.man b/man/twm.man
index 6926abf..e6ea7df 100644
--- a/man/twm.man
+++ b/man/twm.man
@@ -43,8 +43,7 @@
.SH NAME
twm \- Tab Window Manager for the X Window System
.SH SYNTAX
-\fBtwm \fP[ \fB\-display\fP \fIdpy\fP ] [ \fB\-s\fP ]
-[ \fB\-f\fP \fIinitfile\fP ] [ \fB\-v\fP ]
+\fBtwm \fP[ \fIoptions\fP ]
.SH DESCRIPTION
\fITwm\fP is a window manager for the X Window System.
It provides
@@ -56,8 +55,8 @@ key and pointer button bindings.
This program is usually started by the user's session manager or
startup script.
When used
-from \fIxdm(__appmansuffix__)\fP
-or \fIxinit(__appmansuffix__)\fP without a session manager,
+from \fBxdm\fP(__appmansuffix__)
+or \fBxinit\fP(__appmansuffix__) without a session manager,
\fItwm\fP is frequently executed in the foreground
as the last client.
When run this way, exiting \fItwm\fP causes the
@@ -92,7 +91,7 @@ Just
clicking in the title or highlight region raises the window without moving it.
.PP
When new windows are created, \fItwm\fP will honor any size and location
-information requested by the user (usually through \fI-geometry\fP
+information requested by the user (usually through \fI\-geometry\fP
command line argument or resources for the individual applications).
Otherwise, an outline of the window's default size, its titlebar, and lines
dividing the
@@ -108,46 +107,74 @@ Clicking pointer Button3 (usually the right pointer button)
will give the window its current position but attempt to make it long enough
to touch the bottom the screen.
.SH OPTIONS
-\fITwm\fP accepts the following command line options:
-.PP
+\fITwm\fP accepts several command line options,
+which may be abbreviated, e.g.,
+\*(``\fB\-d\fP\*('' for
+\*(``\fB\-display\fP\*(''
+(but upper/lower-case are different):
+.TP 8
+.B \-clientId \fIID\fP
+Each time \fItwm\fP starts, it calls
+\fBSmcOpenConnection\fP
+to establish a new session.
+It can be told to restart from a previous session by giving the previous
+session's client-identifier.
.TP 8
.B \-display \fIdpy\fP
-This option specifies the X server to use.
+Specify the X server to use.
+.TP 8
+.B \-file \fIfilename\fP
+Specify the name of the startup file to use.
+By default,
+\fItwm\fP will look in the user's home directory for files
+named \fI.twmrc.num\fP (where \fInum\fP is a screen number) or \fI.twmrc\fP.
.TP 8
-.B \-s
-This option indicates that only the default screen (as specified by
+.B \-quiet
+Tells \fItwm\fP that it should not print error messages when
+it receives unexpected X Error events.
+.IP
+Besides X Error events, \fItwm\fP also reports its own warnings.
+The \fB\-quiet\fP option suppresses those.
+.TP 8
+.B \-restore \fIfilename\fP
+When \fItwm\fP's session is stopped, it attempts to save the current
+window configuration.
+Use this option to tell \fItwm\fP to read this file for that information
+when starting (or restarting) a session.
+.TP 8
+.B \-single
+Tells \fItwm\fP that only the default screen (as specified by
\fB\-display\fP or by the \fBDISPLAY\fP environment variable) should be
managed.
By default, \fItwm\fP will attempt to manage
all screens on the display.
.TP 8
-.B \-f \fIfilename\fP
-This option specifies the name of the startup file to use.
-By default,
-\fItwm\fP will look in the user's home directory for files
-named \fI.twmrc.num\fP (where \fInum\fP is a screen number) or \fI.twmrc\fP.
-.TP 8
-.B \-v
-This option indicates that \fItwm\fP should print error messages whenever
-an unexpected X Error event is received.
+.B \-verbose
+Tells \fItwm\fP that it should print error messages whenever
+it receives an unexpected X Error event.
This can be useful when debugging
applications but can be distracting in regular use.
+.IP
+The \fB\-verbose\fP and \fB\-quiet\fP options increment and decrement
+the message level, cancelling each other.
+.TP 8
+.B \-V
+Tell \fItwm\fP to print its version to the standard output, and exit.
.SH CUSTOMIZATION
-.PP
Much of \fItwm\fP's appearance and behavior can be controlled by providing
a startup file in one of the following locations (searched in order for
each screen being managed when \fItwm\fP begins):
.TP 8
-.B "$HOME/.twmrc.\fIscreennumber\fP"
-The \fIscreennumber\fP is a small positive number (e.g.
-0, 1, etc.)
-representing the screen number (e.g., the last number in the DISPLAY environment
+.B $HOME/.twmrc.\fIscreennumber\fP
+The \fIscreennumber\fP is a small positive number (e.g., 0, 1, etc.)
+representing the screen number
+(e.g., the last number in the DISPLAY environment
variable \fIhost:displaynum.screennum\fP) that would be used to contact that
screen of the display.
This is intended for displays with multiple screens of
differing visual types.
.TP 8
-.B "$HOME/.twmrc"
+.B $HOME/.twmrc
This is the usual name for an individual user's startup file.
.TP 8
.B __datadir__/X11/twm/system.twmrc
@@ -161,11 +188,11 @@ If no startup files are found, \fItwm\fP will use the built-in defaults
described above.
The only resource used by \fItwm\fP is
\fIbitmapFilePath\fP for a colon-separated list of directories to search
-when looking for bitmap files (for more information, see the \fIAthena
-Widgets\fP manual and \fIxrdb(__appmansuffix__)\fP).
+when looking for bitmap files (for more information,
+see the \fIAthena Widgets\fP manual and \fBxrdb\fP(__appmansuffix__)).
.PP
\fITwm\fP startup files are logically broken up into three types of
-specifications: \fIVariables\fP, \fIBindings\fP, \fIMenus\fP.
+specifications: \fIVariables\fP, \fIBindings\fP, \fIMenus\fP.
The
\fIVariables\fP section must come first and is used to describe the
fonts, colors, cursors, border widths, icon and window placement, highlighting,
@@ -185,7 +212,6 @@ A pound sign (#) outside
of a string causes the remainder of the line in which the character appears to
be treated as a comment.
.SH VARIABLES
-.PP
Many of the aspects of \fItwm\fP's user interface are controlled by variables
that may be set in the user's startup file.
Some of the options are
@@ -227,7 +253,7 @@ prepend the user's directory
tilde (~).
If, instead, the first character is a colon (:), the name is
assumed to refer to one of the internal bitmaps that are used to
-create the default titlebars symbols: \fB:xlogo\fP
+create the default titlebars symbols: \fB:xlogo\fP
or \fB:delete\fP (both refer to the X logo),
\fB:dot\fP or \fB:iconify\fP (both refer to the dot),
\fB:resize\fP (the nested squares used by the resize button),
@@ -290,7 +316,7 @@ and may only be given within a
\fBGrayscale\fP or
\fBMonochrome\fP list.
The optional \fIwincolorlist\fP allows per-window colors to be specified.
-The default is "white".
+The default is "white".
.IP "\fBBorderTileForeground\fP \fIstring\fP [{ \fIwincolorlist\fP }]" 8
This variable specifies the default foreground color in the gray pattern
used in unhighlighted borders (only
@@ -395,7 +421,7 @@ from bitmap files, the following syntax is used instead:
.Ee
.IP
The \fIimage\fP and \fImask\fP strings specify the names of files containing
-the glyph image and mask in \fIbitmap(__appmansuffix__)\fP form.
+the glyph image and mask in \fBbitmap\fP(__appmansuffix__) form.
The bitmap files are located in the same manner as icon bitmap files.
The following example shows the default cursor definitions:
.RS 5
@@ -439,7 +465,7 @@ as icons while other windows are handled by the icon manager.
This variable indicates that windows should not be allowed to be moved off the
screen.
It can be overridden by the \fBf.forcemove\fP function.
-.IP "\fBDontSqueezeTitle\fP [{ \fIwin-list\fP }] " 8
+.IP "\fBDontSqueezeTitle\fP [{ \fIwin-list\fP }]" 8
This variable indicates that titlebars should not be squeezed to their
minimum size as described under \fBSqueezeTitle\fP below.
If the optional window list is supplied, only those windows will be
@@ -483,7 +509,7 @@ icon windows.
The default is 2.
.IP "\fBIconDirectory\fP \fIstring\fP" 8
This variable specifies the directory that should be searched if
-if a bitmap file cannot be found in any of the directories
+a bitmap file cannot be found in any of the directories
in the \fBbitmapFilePath\fP resource.
.IP "\fBIconFont\fP \fIstring\fP" 8
This variable specifies the font to be used to display icon names within
@@ -782,7 +808,7 @@ If the optional \fIwin-list\fP is given, only requests on
those windows will be ignored.
This is typically used to prevent applications
from relentlessly popping themselves to the front of the window stack.
-.IP "\fBNoTitle\fP [{ \fIwin-list\fP }] " 8
+.IP "\fBNoTitle\fP [{ \fIwin-list\fP }]" 8
This variable indicates that windows should not have titlebars.
If the
optional \fIwin-list\fP is given, only those windows will not have titlebars.
@@ -888,7 +914,7 @@ It can always be brought up using the
This variable indicates that entries in the icon manager should be
sorted alphabetically rather than by simply appending new windows to
the end.
-.IP "\fBSqueezeTitle\fP [{ \fIsqueeze-list\fP }] " 8
+.IP "\fBSqueezeTitle\fP [{ \fIsqueeze-list\fP }]" 8
This variable indicates that \fItwm\fP should attempt to use the SHAPE
extension to make titlebars occupy only as much screen space as they need,
rather than extending all the way across the top of the window.
@@ -909,7 +935,7 @@ the numerator is positive, and right to left if negative.
A denominator
of 0 indicates that the numerator should be measured in pixels.
For
-convenience, the ratio 0/0 is the same as 1/2 for \fBcenter\fP and -1/1
+convenience, the ratio 0/0 is the same as 1/2 for \fBcenter\fP and \-1/1
for \fBright\fP.
For example:
.RS 5
@@ -927,13 +953,13 @@ For example:
.IP
The \fBDontSqueezeTitle\fP list can be used to turn off squeezing on
certain titles.
-.IP "\fBStartIconified\fP [{ \fIwin-list\fP }] " 8
+.IP "\fBStartIconified\fP [{ \fIwin-list\fP }]" 8
This variable indicates that client windows should initially be left as
icons until explicitly deiconified by the user.
If the optional \fIwin-list\fP
is given, only those windows will be started iconic.
This is useful for
-programs that do not support an \fI-iconic\fP command line option or
+programs that do not support an \fI\-iconic\fP command line option or
resource.
.IP "\fBTitleBackground\fP \fIstring\fP [{ \fIwin-list\fP }]" 8
This variable specifies the background color used in titlebars,
@@ -973,7 +999,7 @@ in the \fBIcons\fP list.
This variable specifies whether or not \fItwm\fP should honor
program-requested locations (given by the \fBPPosition\fP flag in the
WM_NORMAL_HINTS property) in the absence of a user-specified position.
-The argument \fIstring\fP may have one of three values: \fB"off"\fP
+The argument \fIstring\fP may have one of three values: \fB"off"\fP
(the default)
indicating that \fItwm\fP
should ignore the program-supplied position,
@@ -1003,7 +1029,7 @@ This variable specifies the value to use when drawing window outlines for
moving and resizing.
This should be set to a value that will result in a
variety of
-of distinguishable colors when exclusive-or'ed with the contents of the
+distinguishable colors when exclusive-or'ed with the contents of the
user's typical screen.
Setting this variable to 1 often gives nice results
if adjacent colors in the default colormap are distinct.
@@ -1032,7 +1058,6 @@ from the \fBTwmWindows\fP menu.
If this variable is not set, the window
will be deiconified and raised.
.SH BINDINGS
-.PP
After the desired variables have been set, functions may be attached
titlebuttons and key and pointer buttons.
Titlebuttons may be added
@@ -1054,7 +1079,7 @@ or
\fBRightTitleButton\fP "\fIbitmapname\fP" = \fIfunction\fP
.Ee
.LP
-The \fIbitmapname\fP may refer to one of the built-in bitmaps
+The \fIbitmapname\fP may refer to one of the built-in bitmaps
(which are scaled to match \fBTitleFont\fP) by using the appropriate
colon-prefixed name described above.
.PP
@@ -1202,7 +1227,7 @@ WM_DELETE_WINDOW messages, the keyboard bell will be rung indicating that
the user should choose an alternative method.
Note this is very different
from \fBf.destroy\fP.
-The intent here is to delete a single window, not
+The intent here is to delete a single window, not
necessarily the entire application.
.IP "\fBf.deltastop\fP" 8
This function allows a user-defined function to be aborted if the pointer has
@@ -1408,7 +1433,6 @@ selected window is refreshed.
This function is similar to the \fBf.fullzoom\fP function, except that
the only the height of the selected window is changed.
.SH MENUS
-.PP
Functions may be grouped and interactively selected using pop-up
(when bound to a pointer button) or pull-down (when associated
with a titlebutton) menus.
@@ -1469,7 +1493,7 @@ left of the name when the window is iconified.
By default, clicking on an
entry in the icon manager performs \fBf.iconify\fP.
To change the actions taken in the icon manager, use the
-the \fBiconmgr\fP context when specifying button and keyboard bindings.
+\fBiconmgr\fP context when specifying button and keyboard bindings.
.PP
Moving the pointer into the icon manager also directs keyboard focus to
the indicated window (setting the focus explicitly or else sending synthetic
@@ -1492,7 +1516,6 @@ If \fBIconifyByUnmapping\fP is on and windows are listed in
they may be lost if they are iconified and no bindings to
\fBf.menu "TwmWindows"\fP or \fBf.warpto\fP are setup.
.SH FILES
-.PP
.nf
.I $HOME/.twmrc.<screen number>
.I $HOME/.twmrc
@@ -1508,10 +1531,10 @@ This variable is used as the prefix for files that begin with a tilde and
for locating the \fItwm\fP startup file.
.SH "SEE ALSO"
.PP
-X(__miscmansuffix__),
-Xserver(__appmansuffix__),
-xdm(__appmansuffix__),
-xrdb(__appmansuffix__)
+\fBX\fP(__miscmansuffix__),
+\fBXserver\fP(__appmansuffix__),
+\fBxdm\fP(__appmansuffix__),
+\fBxrdb\fP(__appmansuffix__)
.SH AUTHORS
Tom LaStrange, Solbourne Computer; Jim Fulton, MIT X Consortium;
Steve Pitschke, Stardent Computer; Keith Packard, MIT X Consortium;
diff --git a/src/Makefile.am b/src/Makefile.am
index 75e3d4a..805eaf9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,6 +28,9 @@ rcdir = ${datadir}/X11/twm
dist_rc_DATA = system.twmrc
AM_CPPFLAGS = \
+ -DAPP_NAME=\"twm\" \
+ -DAPP_CLASS=\"twm\" \
+ -DAPP_VERSION=\"$(VERSION)\" \
-DXVENDORNAME=\"The\ X.Org\ Foundation\" \
-DXORG_RELEASE=\"Release\ $(VERSION)\" \
-DSYSTEM_INIT_FILE=\"${rcdir}/system.twmrc\"
diff --git a/src/add_window.c b/src/add_window.c
index 154a369..3895729 100644
--- a/src/add_window.c
+++ b/src/add_window.c
@@ -51,7 +51,7 @@ in this Software without prior written authorization from The Open Group.
/**********************************************************************
*
- * Add a new window, put the titlbar and other stuff around
+ * Add a new window, put the titlebar and other stuff around
* the window
*
* 31-Mar-88 Tom LaStrange Initial Version.
@@ -147,11 +147,9 @@ TwmWindow *
AddWindow(Window w, int iconm, IconMgr *iconp)
{
TwmWindow *tmp_win; /* new twm window structure */
- int stat;
XEvent event;
unsigned long valuemask; /* mask for create windows */
XSetWindowAttributes attributes; /* attributes for create windows */
- int width, height; /* tmp variable */
int ask_user; /* don't know where to put the window */
int gravx, gravy; /* gravity signs for positioning */
int namelen;
@@ -172,9 +170,7 @@ AddWindow(Window w, int iconm, IconMgr *iconp)
/* allocate space for the twm window */
tmp_win = calloc(1, sizeof(TwmWindow));
if (tmp_win == NULL) {
- fprintf(stderr,
- "%s: Unable to allocate memory to manage window ID %lx.\n",
- ProgramName, w);
+ twmWarning("Unable to allocate memory to manage window ID %lx.", w);
return NULL;
}
tmp_win->w = w;
@@ -289,12 +285,14 @@ AddWindow(Window w, int iconm, IconMgr *iconp)
&tmp_win->class);
if (tmp_win->auto_raise)
Scr->NumAutoRaises++;
- tmp_win->iconify_by_unmapping = Scr->IconifyByUnmapping;
if (Scr->IconifyByUnmapping) {
tmp_win->iconify_by_unmapping = iconm ? FALSE :
!short_lookup LookInList(Scr->DontIconify, tmp_win->full_name,
&tmp_win->class);
}
+ else {
+ tmp_win->iconify_by_unmapping = Scr->IconifyByUnmapping;
+ }
tmp_win->iconify_by_unmapping |=
short_lookup LookInList(Scr->IconifyByUn, tmp_win->full_name,
&tmp_win->class);
@@ -402,10 +400,21 @@ AddWindow(Window w, int iconm, IconMgr *iconp)
*/
if (HandlingEvents && ask_user && !restoredFromPrevSession) {
if (Scr->RandomPlacement) { /* just stick it somewhere */
- if ((PlaceX + tmp_win->attr.width) > Scr->MyDisplayWidth)
- PlaceX = 50;
- if ((PlaceY + tmp_win->attr.height) > Scr->MyDisplayHeight)
- PlaceY = 50;
+ /* Avoid putting the new window off-screen */
+ if ((PlaceX + tmp_win->attr.width) > Scr->MyDisplayWidth) {
+ PlaceX = Scr->MyDisplayWidth - tmp_win->attr.width;
+ if (PlaceX < 0)
+ PlaceX = 0;
+ if (PlaceX > 50)
+ PlaceX = 50;
+ }
+ if ((PlaceY + tmp_win->attr.height) > Scr->MyDisplayHeight) {
+ PlaceY = Scr->MyDisplayHeight - tmp_win->attr.height;
+ if (PlaceY < 0)
+ PlaceY = 0;
+ if (PlaceY > 50)
+ PlaceY = 50;
+ }
tmp_win->attr.x = PlaceX;
tmp_win->attr.y = PlaceY;
@@ -416,11 +425,14 @@ AddWindow(Window w, int iconm, IconMgr *iconp)
if (!(tmp_win->wmhints && tmp_win->wmhints->flags & StateHint &&
tmp_win->wmhints->initial_state == IconicState)) {
Bool firsttime = True;
+ int height, width;
/* better wait until all the mouse buttons have been
* released.
*/
while (TRUE) {
+ int stat;
+
XUngrabServer(dpy);
XSync(dpy, 0);
XGrabServer(dpy);
@@ -1290,8 +1302,7 @@ CreateWindowTitlebarButtons(TwmWindow *tmp_win)
if (nb > 0) {
tmp_win->titlebuttons = malloc((size_t) nb * sizeof(TBWindow));
if (!tmp_win->titlebuttons) {
- fprintf(stderr, "%s: unable to allocate %d titlebuttons\n",
- ProgramName, nb);
+ twmWarning("unable to allocate %d titlebuttons", nb);
}
else {
TBWindow *tbw;
@@ -1483,9 +1494,9 @@ FetchWmColormapWindows(TwmWindow *tmp)
malloc(sizeof(Window) * (size_t) (number_cmap_windows + 1));
if (!new_cmap_windows) {
- fprintf(stderr,
- "%s: unable to allocate %d element colormap window array\n",
- ProgramName, number_cmap_windows + 1);
+ twmWarning
+ ("unable to allocate %d element colormap window array",
+ number_cmap_windows + 1);
goto done;
}
new_cmap_windows[0] = tmp->w; /* add to front */
@@ -1521,10 +1532,11 @@ FetchWmColormapWindows(TwmWindow *tmp)
if (j == tmp->cmaps.number_cwins) {
if (XFindContext(dpy, cmap_windows[i], ColormapContext,
(XPointer *) &cwins[i]) == XCNOENT) {
- if ((cwins[i] = CreateColormapWindow(cmap_windows[i],
- (Bool) tmp->cmaps.
- number_cwins == 0,
- True)) == NULL) {
+ if ((cwins[i] =
+ CreateColormapWindow(cmap_windows[i],
+ (tmp->cmaps.number_cwins == 0
+ ? True
+ : False), True)) == NULL) {
int k;
for (k = i + 1; k < number_cmap_windows; k++)
diff --git a/src/cursor.c b/src/cursor.c
index 98a1256..84d3f0c 100644
--- a/src/cursor.c
+++ b/src/cursor.c
@@ -133,15 +133,13 @@ NewFontCursor(Cursor *cp, const char *str)
i++) {
if (strcmp(str, cursor_names[i].name) == 0) {
if (cursor_names[i].cursor == None)
- cursor_names[i].cursor = XCreateFontCursor(dpy,
- cursor_names[i].
- shape);
+ cursor_names[i].cursor =
+ XCreateFontCursor(dpy, cursor_names[i].shape);
*cp = cursor_names[i].cursor;
return;
}
}
- fprintf(stderr, "%s: unable to find font cursor \"%s\"\n",
- ProgramName, str);
+ twmWarning("unable to find font cursor \"%s\"", str);
}
void
@@ -164,9 +162,8 @@ NewBitmapCursor(Cursor *cp, char *source, char *mask)
XGetGeometry(dpy, spm, &JunkRoot, &sx, &sy, &sw, &sh, &JunkBW, &JunkDepth);
XGetGeometry(dpy, mpm, &JunkRoot, &mx, &my, &mw, &mh, &JunkBW, &JunkDepth);
if (sw != mw || sh != mh) {
- fprintf(stderr,
- "%s: cursor bitmaps \"%s\" and \"%s\" not the same size\n",
- ProgramName, source, mask);
+ twmWarning("cursor bitmaps \"%s\" and \"%s\" not the same size\n",
+ source, mask);
return;
}
*cp = XCreatePixmapCursor(dpy, spm, mpm, &Scr->PointerForeground,
diff --git a/src/events.c b/src/events.c
index 6c34261..9d92322 100644
--- a/src/events.c
+++ b/src/events.c
@@ -380,9 +380,8 @@ void
HandleColormapNotify(void)
{
XColormapEvent *cevent = (XColormapEvent *) &Event;
- ColormapWindow *cwin, **cwins;
+ ColormapWindow *cwin;
TwmColormap *cmap;
- int lost, won, n, number_cwins;
XPointer context_data;
if (XFindContext(dpy, cevent->window, ColormapContext, &context_data) == 0)
@@ -430,6 +429,9 @@ HandleColormapNotify(void)
}
if (cevent->serial >= Scr->cmapInfo.first_req) {
+ ColormapWindow **cwins;
+ int lost, won, n, number_cwins;
+
number_cwins = Scr->cmapInfo.cmaps->number_cwins;
/*
@@ -698,13 +700,14 @@ free_window_names(TwmWindow *tmp, Bool nukefull, Bool nukename, Bool nukeicon)
void
free_cwins(TwmWindow *tmp)
{
- int i;
- TwmColormap *cmap;
-
if (tmp->cmaps.number_cwins) {
+ int i;
+
for (i = 0; i < tmp->cmaps.number_cwins; i++) {
+
if (--tmp->cmaps.cwins[i]->refcnt == 0) {
- cmap = tmp->cmaps.cwins[i]->colormap;
+ TwmColormap *cmap = tmp->cmaps.cwins[i]->colormap;
+
if (--cmap->refcnt == 0) {
XDeleteContext(dpy, cmap->c, ColormapContext);
free(cmap);
@@ -714,6 +717,7 @@ free_cwins(TwmWindow *tmp)
}
}
free(tmp->cmaps.cwins);
+
if (tmp->cmaps.number_cwins > 1) {
free(tmp->cmaps.scoreboard);
tmp->cmaps.scoreboard = NULL;
@@ -729,7 +733,6 @@ void
HandlePropertyNotify(void)
{
char *name = NULL;
- unsigned long valuemask; /* mask for create windows */
XSetWindowAttributes attributes; /* attributes for create windows */
Pixmap pm;
@@ -894,6 +897,8 @@ HandlePropertyNotify(void)
if (Tmp_win->icon_w && !Tmp_win->forced && Tmp_win->wmhints &&
(Tmp_win->wmhints->flags & IconPixmapHint)) {
+ unsigned long valuemask; /* mask for create windows */
+
if (!XGetGeometry(dpy, Tmp_win->wmhints->icon_pixmap, &JunkRoot,
&JunkX, &JunkY,
(unsigned int *) &Tmp_win->icon_width,
@@ -1167,7 +1172,6 @@ remove_window_from_ring(TwmWindow *tmp)
void
HandleDestroyNotify(void)
{
- int i;
/*
* Warning, this is also called by HandleUnmapNotify; if it ever needs to
@@ -1198,7 +1202,10 @@ HandleDestroyNotify(void)
XDeleteContext(dpy, Tmp_win->hilite_w, TwmContext);
XDeleteContext(dpy, Tmp_win->hilite_w, ScreenContext);
}
+
if (Tmp_win->titlebuttons) {
+ int i;
+
for (i = 0; i < nb; i++) {
XDeleteContext(dpy, Tmp_win->titlebuttons[i].window,
TwmContext);
@@ -1279,7 +1286,6 @@ void
HandleMapRequest(void)
{
XPointer context_data;
- int zoom_save;
Event.xany.window = Event.xmaprequest.window;
if (XFindContext(dpy, Event.xany.window, TwmContext, &context_data) == 0)
@@ -1309,6 +1315,7 @@ HandleMapRequest(void)
if ((!Tmp_win->icon) &&
Tmp_win->wmhints && (Tmp_win->wmhints->flags & StateHint)) {
int state;
+ int zoom_save;
Window icon;
/* use WM_STATE if enabled */
@@ -1484,7 +1491,6 @@ HandleMotionNotify(void)
void
HandleButtonRelease(void)
{
- int xl, xr, yt, yb, w, h;
unsigned mask;
XPointer context_data;
@@ -1496,6 +1502,9 @@ HandleButtonRelease(void)
}
if (DragWindow != None) {
+ int xl, yt;
+ int w, h;
+
MoveOutline(Scr->Root, 0, 0, 0, 0, 0, 0);
if (XFindContext(dpy, DragWindow, TwmContext, &context_data) == 0)
@@ -1529,8 +1538,8 @@ HandleButtonRelease(void)
}
if (Scr->DontMoveOff && MoveFunction != F_FORCEMOVE) {
- xr = xl + w;
- yb = yt + h;
+ int xr = xl + w;
+ int yb = yt + h;
if (xl < 0)
xl = 0;
@@ -2218,7 +2227,6 @@ void
HandleConfigureRequest(void)
{
XWindowChanges xwc;
- unsigned long xwcm;
int x, y, width, height, bw;
int gravx, gravy;
XConfigureRequestEvent *cre = &Event.xconfigurerequest;
@@ -2258,6 +2266,8 @@ HandleConfigureRequest(void)
* to configuration requests for windows which have never been mapped.
*/
if (!Tmp_win || Tmp_win->icon_w == cre->window) {
+ unsigned long xwcm;
+
xwcm = cre->value_mask &
(CWX | CWY | CWWidth | CWHeight | CWBorderWidth);
xwc.x = cre->x;
@@ -2420,10 +2430,12 @@ ScreenInfo *
FindScreenInfo(Window w)
{
XWindowAttributes attr;
- int scrnum;
attr.screen = NULL;
+
if (XGetWindowAttributes(dpy, w, &attr)) {
+ int scrnum;
+
for (scrnum = 0; scrnum < NumScreens; scrnum++) {
if (ScreenList[scrnum] != NULL &&
(ScreenOfDisplay(dpy, ScreenList[scrnum]->screen) ==
diff --git a/src/gram.y b/src/gram.y
index 6c4f4ea..8b18038 100644
--- a/src/gram.y
+++ b/src/gram.y
@@ -56,7 +56,7 @@ in this Software without prior written authorization from The Open Group.
*
* .twmrc command grammer
*
- * 07-Jan-86 Thomas E. LaStrange File created
+ * 07-Jan-86 Thomas E. LaStrange File created
* 11-Nov-90 Dave Sternlicht Adding SaveColors
* 10-Oct-90 David M. Sternlicht Storing saved colors on root
*
@@ -65,6 +65,7 @@ in this Software without prior written authorization from The Open Group.
***********************************************************************/
%{
+
#include <stdio.h>
#include <ctype.h>
#include "twm.h"
@@ -81,16 +82,16 @@ in this Software without prior written authorization from The Open Group.
static char empty[1];
static char *Action = empty;
static char *Name = empty;
-static MenuRoot *root, *pull = NULL;
+static MenuRoot *root, *pull = NULL;
-static MenuRoot *GetRoot ( const char *name, const char *fore, const char *back );
-static void GotButton ( int butt, int func );
-static void GotKey ( char *key, int func );
-static void GotTitleButton ( char *bitmapname, int func, Bool rightside );
-static Bool CheckWarpScreenArg ( char *s );
-static Bool CheckWarpRingArg ( char *s );
-static Bool CheckColormapArg ( char *s );
-static void RemoveDQuote ( char *str );
+static MenuRoot *GetRoot(const char *name, const char *fore, const char *back);
+static void GotButton(int butt, int func);
+static void GotKey(char *key, int func);
+static void GotTitleButton(char *bitmapname, int func, Bool rightside);
+static Bool CheckWarpScreenArg(char *s);
+static Bool CheckWarpRingArg(char *s);
+static Bool CheckColormapArg(char *s);
+static void RemoveDQuote(char *str);
static char *ptr;
static name_list **list;
@@ -100,7 +101,7 @@ int mods = 0;
unsigned int mods_used = (ShiftMask | ControlMask | Mod1Mask);
extern int yylineno;
-static void yyerror ( const char *s );
+static void yyerror(const char *s);
%}
@@ -124,355 +125,349 @@ static void yyerror ( const char *s );
%token <num> SKEYWORD DKEYWORD JKEYWORD WINDOW_RING WARP_CURSOR ERRORTOKEN
%token <num> NO_STACKMODE
%token <ptr> STRING
+%token <num> error
%type <ptr> string
%type <num> pixmap_list cursor_list color_list save_color_list stmt
%type <num> win_color_list iconm_list win_list icon_list function menu
-%type <num> noarg sarg error narg squeeze color_entry
+%type <num> noarg sarg narg squeeze color_entry
%type <num> action button number signed_number full fullkey
%start twmrc
%%
-twmrc : stmts
- ;
-
-stmts : /* Empty */
- | stmts stmt
- ;
-
-stmt : error
- | noarg
- | sarg
- | narg
- | squeeze
- | ICON_REGION string DKEYWORD DKEYWORD number number
- { AddIconRegion($2, $3, $4, $5, $6); }
- | ICONMGR_GEOMETRY string number { if (Scr->FirstTime)
- {
- Scr->iconmgr.geometry=$2;
- Scr->iconmgr.columns=$3;
- }
- }
- | ICONMGR_GEOMETRY string { if (Scr->FirstTime)
- Scr->iconmgr.geometry = $2;
- }
- | ZOOM number { if (Scr->FirstTime)
- {
- Scr->DoZoom = TRUE;
- Scr->ZoomCount = (short)$2;
- }
- }
- | ZOOM { if (Scr->FirstTime)
- Scr->DoZoom = TRUE; }
- | PIXMAPS pixmap_list {}
- | CURSORS cursor_list {}
- | ICONIFY_BY_UNMAPPING { list = &Scr->IconifyByUn; }
- win_list
- | ICONIFY_BY_UNMAPPING { if (Scr->FirstTime)
- Scr->IconifyByUnmapping = TRUE; }
- | LEFT_TITLEBUTTON string EQUALS action {
- GotTitleButton ($2, $4, False);
- }
- | RIGHT_TITLEBUTTON string EQUALS action {
- GotTitleButton ($2, $4, True);
- }
- | button string { root = GetRoot($2, NULLSTR, NULLSTR);
- Scr->Mouse[$1][C_ROOT][0].func = F_MENU;
- Scr->Mouse[$1][C_ROOT][0].menu = root;
- }
- | button action { Scr->Mouse[$1][C_ROOT][0].func = $2;
- if ($2 == F_MENU)
- {
- pull->prev = NULL;
- Scr->Mouse[$1][C_ROOT][0].menu = pull;
- }
- else
- {
- root = GetRoot(TWM_ROOT,NULLSTR,NULLSTR);
- Scr->Mouse[$1][C_ROOT][0].item =
- AddToMenu(root,"x",Action,
- NULL,$2,NULLSTR,NULLSTR);
- }
- Action = empty;
- pull = NULL;
- }
- | string fullkey { GotKey($1, $2); }
- | button full { GotButton($1, $2); }
- | DONT_ICONIFY_BY_UNMAPPING { list = &Scr->DontIconify; }
- win_list
- | ICONMGR_NOSHOW { list = &Scr->IconMgrNoShow; }
- win_list
- | ICONMGR_NOSHOW { Scr->IconManagerDontShow = TRUE; }
- | ICONMGRS { list = &Scr->IconMgrs; }
- iconm_list
- | ICONMGR_SHOW { list = &Scr->IconMgrShow; }
- win_list
- | NO_TITLE_HILITE { list = &Scr->NoTitleHighlight; }
- win_list
- | NO_TITLE_HILITE { if (Scr->FirstTime)
- Scr->TitleHighlight = FALSE; }
- | NO_HILITE { list = &Scr->NoHighlight; }
- win_list
- | NO_HILITE { if (Scr->FirstTime)
- Scr->Highlight = FALSE; }
- | NO_STACKMODE { list = &Scr->NoStackModeL; }
- win_list
- | NO_STACKMODE { if (Scr->FirstTime)
- Scr->StackMode = FALSE; }
- | NO_TITLE { list = &Scr->NoTitle; }
- win_list
- | NO_TITLE { if (Scr->FirstTime)
- Scr->NoTitlebar = TRUE; }
- | MAKE_TITLE { list = &Scr->MakeTitle; }
- win_list
- | START_ICONIFIED { list = &Scr->StartIconified; }
- win_list
- | AUTO_RAISE { list = &Scr->AutoRaise; }
- win_list
- | MENU string LP string COLON string RP {
- root = GetRoot($2, $4, $6); }
- menu { root->real_menu = TRUE;}
- | MENU string { root = GetRoot($2, NULLSTR, NULLSTR); }
- menu { root->real_menu = TRUE; }
- | FUNCTION string { root = GetRoot($2, NULLSTR, NULLSTR); }
- function
- | ICONS { list = &Scr->IconNames; }
- icon_list
- | COLOR { color = COLOR; }
- color_list
- | GRAYSCALE { color = GRAYSCALE; }
- color_list
- | SAVECOLOR
+twmrc : stmts
+ ;
+
+stmts : /* Empty */
+ | stmts stmt
+ ;
+
+stmt : error
+ | noarg
+ | sarg
+ | narg
+ | squeeze
+ | ICON_REGION string DKEYWORD DKEYWORD number number
+ { AddIconRegion($2, $3, $4, $5, $6); }
+ | ICONMGR_GEOMETRY string number { if (Scr->FirstTime)
+ {
+ Scr->iconmgr.geometry=$2;
+ Scr->iconmgr.columns=$3;
+ }
+ }
+ | ICONMGR_GEOMETRY string { if (Scr->FirstTime)
+ Scr->iconmgr.geometry = $2;
+ }
+ | ZOOM number { if (Scr->FirstTime)
+ {
+ Scr->DoZoom = TRUE;
+ Scr->ZoomCount = (short)$2;
+ }
+ }
+ | ZOOM { if (Scr->FirstTime)
+ Scr->DoZoom = TRUE; }
+ | PIXMAPS pixmap_list {}
+ | CURSORS cursor_list {}
+ | ICONIFY_BY_UNMAPPING { list = &Scr->IconifyByUn; }
+ win_list
+ | ICONIFY_BY_UNMAPPING { if (Scr->FirstTime)
+ Scr->IconifyByUnmapping = TRUE; }
+ | LEFT_TITLEBUTTON string EQUALS action {
+ GotTitleButton ($2, $4, False);
+ }
+ | RIGHT_TITLEBUTTON string EQUALS action {
+ GotTitleButton ($2, $4, True);
+ }
+ | button string { root = GetRoot($2, NULLSTR, NULLSTR);
+ Scr->Mouse[$1][C_ROOT][0].func = F_MENU;
+ Scr->Mouse[$1][C_ROOT][0].menu = root;
+ }
+ | button action { Scr->Mouse[$1][C_ROOT][0].func = $2;
+ if ($2 == F_MENU)
+ {
+ pull->prev = NULL;
+ Scr->Mouse[$1][C_ROOT][0].menu = pull;
+ }
+ else
+ {
+ root = GetRoot(TWM_ROOT,NULLSTR,NULLSTR);
+ Scr->Mouse[$1][C_ROOT][0].item =
+ AddToMenu(root,"x",Action,
+ NULL,$2,NULLSTR,NULLSTR);
+ }
+ Action = empty;
+ pull = NULL;
+ }
+ | string fullkey { GotKey($1, $2); }
+ | button full { GotButton($1, $2); }
+ | DONT_ICONIFY_BY_UNMAPPING { list = &Scr->DontIconify; }
+ win_list
+ | ICONMGR_NOSHOW { list = &Scr->IconMgrNoShow; }
+ win_list
+ | ICONMGR_NOSHOW { Scr->IconManagerDontShow = TRUE; }
+ | ICONMGRS { list = &Scr->IconMgrs; }
+ iconm_list
+ | ICONMGR_SHOW { list = &Scr->IconMgrShow; }
+ win_list
+ | NO_TITLE_HILITE { list = &Scr->NoTitleHighlight; }
+ win_list
+ | NO_TITLE_HILITE { if (Scr->FirstTime)
+ Scr->TitleHighlight = FALSE; }
+ | NO_HILITE { list = &Scr->NoHighlight; }
+ win_list
+ | NO_HILITE { if (Scr->FirstTime)
+ Scr->Highlight = FALSE; }
+ | NO_STACKMODE { list = &Scr->NoStackModeL; }
+ win_list
+ | NO_STACKMODE { if (Scr->FirstTime)
+ Scr->StackMode = FALSE; }
+ | NO_TITLE { list = &Scr->NoTitle; }
+ win_list
+ | NO_TITLE { if (Scr->FirstTime)
+ Scr->NoTitlebar = TRUE; }
+ | MAKE_TITLE { list = &Scr->MakeTitle; }
+ win_list
+ | START_ICONIFIED { list = &Scr->StartIconified; }
+ win_list
+ | AUTO_RAISE { list = &Scr->AutoRaise; }
+ win_list
+ | MENU string LP string COLON string RP {
+ root = GetRoot($2, $4, $6); }
+ menu { root->real_menu = TRUE;}
+ | MENU string { root = GetRoot($2, NULLSTR, NULLSTR); }
+ menu { root->real_menu = TRUE; }
+ | FUNCTION string { root = GetRoot($2, NULLSTR, NULLSTR); }
+ function
+ | ICONS { list = &Scr->IconNames; }
+ icon_list
+ | COLOR { color = COLOR; }
+ color_list
+ | GRAYSCALE { color = GRAYSCALE; }
+ color_list
+ | SAVECOLOR
save_color_list
- | MONOCHROME { color = MONOCHROME; }
- color_list
- | DEFAULT_FUNCTION action { Scr->DefaultFunction.func = $2;
- if ($2 == F_MENU)
- {
- pull->prev = NULL;
- Scr->DefaultFunction.menu = pull;
- }
- else
- {
- root = GetRoot(TWM_ROOT,NULLSTR,NULLSTR);
- Scr->DefaultFunction.item =
- AddToMenu(root,"x",Action,
- NULL,$2, NULLSTR, NULLSTR);
- }
- Action = empty;
- pull = NULL;
- }
- | WINDOW_FUNCTION action { Scr->WindowFunction.func = $2;
- root = GetRoot(TWM_ROOT,NULLSTR,NULLSTR);
- Scr->WindowFunction.item =
- AddToMenu(root,"x",Action,
- NULL,$2, NULLSTR, NULLSTR);
- Action = empty;
- pull = NULL;
- }
- | WARP_CURSOR { list = &Scr->WarpCursorL; }
- win_list
- | WARP_CURSOR { if (Scr->FirstTime)
- Scr->WarpCursor = TRUE; }
- | WINDOW_RING { list = &Scr->WindowRingL; }
- win_list
- ;
-
-
-noarg : KEYWORD { if (!do_single_keyword ($1)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unknown singleton keyword %d\n",
- $1);
- ParseError = 1;
- }
- }
- ;
-
-sarg : SKEYWORD string { if (!do_string_keyword ($1, $2)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unknown string keyword %d (value \"%s\")\n",
- $1, $2);
- ParseError = 1;
- }
- }
- ;
-
-narg : NKEYWORD number { if (!do_number_keyword ($1, $2)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unknown numeric keyword %d (value %d)\n",
- $1, $2);
- ParseError = 1;
- }
- }
- ;
-
-
-
-full : EQUALS keys COLON contexts COLON action { $$ = $6; }
- ;
-
-fullkey : EQUALS keys COLON contextkeys COLON action { $$ = $6; }
- ;
-
-keys : /* Empty */
- | keys key
- ;
-
-key : META { mods |= Mod1Mask; }
- | SHIFT { mods |= ShiftMask; }
- | LOCK { mods |= LockMask; }
- | CONTROL { mods |= ControlMask; }
- | META number { if ($2 < 1 || $2 > 5) {
- twmrc_error_prefix();
- fprintf (stderr,
- "bad modifier number (%d), must be 1-5\n",
- $2);
- ParseError = 1;
- } else {
- mods |= (Mod1Mask << ($2 - 1));
- }
- }
- | OR { }
- ;
-
-contexts : /* Empty */
- | contexts context
- ;
-
-context : WINDOW { cont |= C_WINDOW_BIT; }
- | TITLE { cont |= C_TITLE_BIT; }
- | ICON { cont |= C_ICON_BIT; }
- | ROOT { cont |= C_ROOT_BIT; }
- | FRAME { cont |= C_FRAME_BIT; }
- | ICONMGR { cont |= C_ICONMGR_BIT; }
- | META { cont |= C_ICONMGR_BIT; }
- | ALL { cont |= C_ALL_BITS; }
- | OR { }
- ;
-
-contextkeys : /* Empty */
- | contextkeys contextkey
- ;
-
-contextkey : WINDOW { cont |= C_WINDOW_BIT; }
- | TITLE { cont |= C_TITLE_BIT; }
- | ICON { cont |= C_ICON_BIT; }
- | ROOT { cont |= C_ROOT_BIT; }
- | FRAME { cont |= C_FRAME_BIT; }
- | ICONMGR { cont |= C_ICONMGR_BIT; }
- | META { cont |= C_ICONMGR_BIT; }
- | ALL { cont |= C_ALL_BITS; }
- | OR { }
- | string { Name = $1; cont |= C_NAME_BIT; }
- ;
-
-
-pixmap_list : LB pixmap_entries RB
- ;
-
-pixmap_entries : /* Empty */
- | pixmap_entries pixmap_entry
- ;
-
-pixmap_entry : TITLE_HILITE string { SetHighlightPixmap ($2); }
- ;
-
-
-cursor_list : LB cursor_entries RB
- ;
-
-cursor_entries : /* Empty */
- | cursor_entries cursor_entry
- ;
-
-cursor_entry : FRAME string string {
- NewBitmapCursor(&Scr->FrameCursor, $2, $3); }
- | FRAME string {
- NewFontCursor(&Scr->FrameCursor, $2); }
- | TITLE string string {
- NewBitmapCursor(&Scr->TitleCursor, $2, $3); }
- | TITLE string {
- NewFontCursor(&Scr->TitleCursor, $2); }
- | ICON string string {
- NewBitmapCursor(&Scr->IconCursor, $2, $3); }
- | ICON string {
- NewFontCursor(&Scr->IconCursor, $2); }
- | ICONMGR string string {
- NewBitmapCursor(&Scr->IconMgrCursor, $2, $3); }
- | ICONMGR string {
- NewFontCursor(&Scr->IconMgrCursor, $2); }
- | BUTTON string string {
- NewBitmapCursor(&Scr->ButtonCursor, $2, $3); }
- | BUTTON string {
- NewFontCursor(&Scr->ButtonCursor, $2); }
- | MOVE string string {
- NewBitmapCursor(&Scr->MoveCursor, $2, $3); }
- | MOVE string {
- NewFontCursor(&Scr->MoveCursor, $2); }
- | RESIZE string string {
- NewBitmapCursor(&Scr->ResizeCursor, $2, $3); }
- | RESIZE string {
- NewFontCursor(&Scr->ResizeCursor, $2); }
- | WAIT string string {
- NewBitmapCursor(&Scr->WaitCursor, $2, $3); }
- | WAIT string {
- NewFontCursor(&Scr->WaitCursor, $2); }
- | MENU string string {
- NewBitmapCursor(&Scr->MenuCursor, $2, $3); }
- | MENU string {
- NewFontCursor(&Scr->MenuCursor, $2); }
- | SELECT string string {
- NewBitmapCursor(&Scr->SelectCursor, $2, $3); }
- | SELECT string {
- NewFontCursor(&Scr->SelectCursor, $2); }
- | KILL string string {
- NewBitmapCursor(&Scr->DestroyCursor, $2, $3); }
- | KILL string {
- NewFontCursor(&Scr->DestroyCursor, $2); }
- ;
-
-color_list : LB color_entries RB
- ;
-
-
-color_entries : /* Empty */
- | color_entries color_entry
- ;
-
-color_entry : CLKEYWORD string { if (!do_colorlist_keyword ($1, color,
- $2)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unhandled list color keyword %d (string \"%s\")\n",
- $1, $2);
- ParseError = 1;
- }
- }
- | CLKEYWORD string { list = do_colorlist_keyword($1,color,
- $2);
- if (!list) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unhandled color list keyword %d (string \"%s\")\n",
- $1, $2);
- ParseError = 1;
- }
- }
- win_color_list { /* No action */; }
- | CKEYWORD string { if (!do_color_keyword ($1, color,
- $2)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unhandled color keyword %d (string \"%s\")\n",
- $1, $2);
- ParseError = 1;
- }
- }
- ;
+ | MONOCHROME { color = MONOCHROME; }
+ color_list
+ | DEFAULT_FUNCTION action { Scr->DefaultFunction.func = $2;
+ if ($2 == F_MENU)
+ {
+ pull->prev = NULL;
+ Scr->DefaultFunction.menu = pull;
+ }
+ else
+ {
+ root = GetRoot(TWM_ROOT,NULLSTR,NULLSTR);
+ Scr->DefaultFunction.item =
+ AddToMenu(root,"x",Action,
+ NULL,$2, NULLSTR, NULLSTR);
+ }
+ Action = empty;
+ pull = NULL;
+ }
+ | WINDOW_FUNCTION action { Scr->WindowFunction.func = $2;
+ root = GetRoot(TWM_ROOT,NULLSTR,NULLSTR);
+ Scr->WindowFunction.item =
+ AddToMenu(root,"x",Action,
+ NULL,$2, NULLSTR, NULLSTR);
+ Action = empty;
+ pull = NULL;
+ }
+ | WARP_CURSOR { list = &Scr->WarpCursorL; }
+ win_list
+ | WARP_CURSOR { if (Scr->FirstTime)
+ Scr->WarpCursor = TRUE; }
+ | WINDOW_RING { list = &Scr->WindowRingL; }
+ win_list
+ ;
+
+
+noarg : KEYWORD { if (!do_single_keyword ($1)) {
+ parseWarning (
+ "unknown singleton keyword %d",
+ $1);
+ ParseError = 1;
+ }
+ }
+ ;
+
+sarg : SKEYWORD string { if (!do_string_keyword ($1, $2)) {
+ parseWarning (
+ "unknown string keyword %d (value \"%s\")",
+ $1, $2);
+ ParseError = 1;
+ }
+ }
+ ;
+
+narg : NKEYWORD number { if (!do_number_keyword ($1, $2)) {
+ parseWarning (
+ "unknown numeric keyword %d (value %d)",
+ $1, $2);
+ ParseError = 1;
+ }
+ }
+ ;
+
+
+
+full : EQUALS keys COLON contexts COLON action { $$ = $6; }
+ ;
+
+fullkey : EQUALS keys COLON contextkeys COLON action { $$ = $6; }
+ ;
+
+keys : /* Empty */
+ | keys key
+ ;
+
+key : META { mods |= Mod1Mask; }
+ | SHIFT { mods |= ShiftMask; }
+ | LOCK { mods |= LockMask; }
+ | CONTROL { mods |= ControlMask; }
+ | META number { if ($2 < 1 || $2 > 5) {
+ parseWarning (
+ "bad modifier number (%d), must be 1-5",
+ $2);
+ ParseError = 1;
+ } else {
+ mods |= (Mod1Mask << ($2 - 1));
+ }
+ }
+ | OR { }
+ ;
+
+contexts : /* Empty */
+ | contexts context
+ ;
+
+context : WINDOW { cont |= C_WINDOW_BIT; }
+ | TITLE { cont |= C_TITLE_BIT; }
+ | ICON { cont |= C_ICON_BIT; }
+ | ROOT { cont |= C_ROOT_BIT; }
+ | FRAME { cont |= C_FRAME_BIT; }
+ | ICONMGR { cont |= C_ICONMGR_BIT; }
+ | META { cont |= C_ICONMGR_BIT; }
+ | ALL { cont |= C_ALL_BITS; }
+ | OR { }
+ ;
+
+contextkeys : /* Empty */
+ | contextkeys contextkey
+ ;
+
+contextkey : WINDOW { cont |= C_WINDOW_BIT; }
+ | TITLE { cont |= C_TITLE_BIT; }
+ | ICON { cont |= C_ICON_BIT; }
+ | ROOT { cont |= C_ROOT_BIT; }
+ | FRAME { cont |= C_FRAME_BIT; }
+ | ICONMGR { cont |= C_ICONMGR_BIT; }
+ | META { cont |= C_ICONMGR_BIT; }
+ | ALL { cont |= C_ALL_BITS; }
+ | OR { }
+ | string { Name = $1; cont |= C_NAME_BIT; }
+ ;
+
+
+pixmap_list : LB pixmap_entries RB
+ ;
+
+pixmap_entries : /* Empty */
+ | pixmap_entries pixmap_entry
+ ;
+
+pixmap_entry : TITLE_HILITE string { SetHighlightPixmap ($2); }
+ ;
+
+
+cursor_list : LB cursor_entries RB
+ ;
+
+cursor_entries : /* Empty */
+ | cursor_entries cursor_entry
+ ;
+
+cursor_entry : FRAME string string {
+ NewBitmapCursor(&Scr->FrameCursor, $2, $3); }
+ | FRAME string {
+ NewFontCursor(&Scr->FrameCursor, $2); }
+ | TITLE string string {
+ NewBitmapCursor(&Scr->TitleCursor, $2, $3); }
+ | TITLE string {
+ NewFontCursor(&Scr->TitleCursor, $2); }
+ | ICON string string {
+ NewBitmapCursor(&Scr->IconCursor, $2, $3); }
+ | ICON string {
+ NewFontCursor(&Scr->IconCursor, $2); }
+ | ICONMGR string string {
+ NewBitmapCursor(&Scr->IconMgrCursor, $2, $3); }
+ | ICONMGR string {
+ NewFontCursor(&Scr->IconMgrCursor, $2); }
+ | BUTTON string string {
+ NewBitmapCursor(&Scr->ButtonCursor, $2, $3); }
+ | BUTTON string {
+ NewFontCursor(&Scr->ButtonCursor, $2); }
+ | MOVE string string {
+ NewBitmapCursor(&Scr->MoveCursor, $2, $3); }
+ | MOVE string {
+ NewFontCursor(&Scr->MoveCursor, $2); }
+ | RESIZE string string {
+ NewBitmapCursor(&Scr->ResizeCursor, $2, $3); }
+ | RESIZE string {
+ NewFontCursor(&Scr->ResizeCursor, $2); }
+ | WAIT string string {
+ NewBitmapCursor(&Scr->WaitCursor, $2, $3); }
+ | WAIT string {
+ NewFontCursor(&Scr->WaitCursor, $2); }
+ | MENU string string {
+ NewBitmapCursor(&Scr->MenuCursor, $2, $3); }
+ | MENU string {
+ NewFontCursor(&Scr->MenuCursor, $2); }
+ | SELECT string string {
+ NewBitmapCursor(&Scr->SelectCursor, $2, $3); }
+ | SELECT string {
+ NewFontCursor(&Scr->SelectCursor, $2); }
+ | KILL string string {
+ NewBitmapCursor(&Scr->DestroyCursor, $2, $3); }
+ | KILL string {
+ NewFontCursor(&Scr->DestroyCursor, $2); }
+ ;
+
+color_list : LB color_entries RB
+ ;
+
+
+color_entries : /* Empty */
+ | color_entries color_entry
+ ;
+
+color_entry : CLKEYWORD string { if (!do_colorlist_keyword ($1, color,
+ $2)) {
+ parseWarning (
+ "unhandled list color keyword %d (string \"%s\")",
+ $1, $2);
+ ParseError = 1;
+ }
+ }
+ | CLKEYWORD string { list = do_colorlist_keyword($1,color,
+ $2);
+ if (!list) {
+ parseWarning (
+ "unhandled color list keyword %d (string \"%s\")",
+ $1, $2);
+ ParseError = 1;
+ }
+ }
+ win_color_list { /* No action */; }
+ | CKEYWORD string { if (!do_color_keyword ($1, color,
+ $2)) {
+ parseWarning (
+ "unhandled color keyword %d (string \"%s\")",
+ $1, $2);
+ ParseError = 1;
+ }
+ }
+ ;
save_color_list : LB s_color_entries RB
;
@@ -485,189 +480,186 @@ s_color_entry : string { do_string_savecolor(color, $1); }
| CLKEYWORD { do_var_savecolor($1); }
;
-win_color_list : LB win_color_entries RB
- ;
-
-win_color_entries : /* Empty */
- | win_color_entries win_color_entry
- ;
-
-win_color_entry : string string { if (Scr->FirstTime &&
- color == Scr->Monochrome)
- AddToList(list, $1, $2); }
- ;
-
-squeeze : SQUEEZE_TITLE {
- if (HasShape) Scr->SqueezeTitle = TRUE;
- }
- | SQUEEZE_TITLE { list = &Scr->SqueezeTitleL;
- if (HasShape && Scr->SqueezeTitle == -1)
- Scr->SqueezeTitle = TRUE;
- }
- LB win_sqz_entries RB
- | DONT_SQUEEZE_TITLE { Scr->SqueezeTitle = FALSE; }
- | DONT_SQUEEZE_TITLE { list = &Scr->DontSqueezeTitleL; }
- win_list
- ;
-
-win_sqz_entries : /* Empty */
- | win_sqz_entries string JKEYWORD signed_number number {
- if (Scr->FirstTime) {
- do_squeeze_entry (list, $2, $3, $4, $5);
- }
- }
- ;
-
-
-iconm_list : LB iconm_entries RB
- ;
-
-iconm_entries : /* Empty */
- | iconm_entries iconm_entry
- ;
-
-iconm_entry : string string number { if (Scr->FirstTime)
- AddToList(list, $1, (char *)
- AllocateIconManager($1, NULLSTR,
- $2,$3));
- }
- | string string string number
- { if (Scr->FirstTime)
- AddToList(list, $1, (char *)
- AllocateIconManager($1,$2,
- $3, $4));
- }
- ;
-
-win_list : LB win_entries RB
- ;
-
-win_entries : /* Empty */
- | win_entries win_entry
- ;
-
-win_entry : string { if (Scr->FirstTime)
- AddToList(list, $1, 0);
- }
- ;
-
-icon_list : LB icon_entries RB
- ;
-
-icon_entries : /* Empty */
- | icon_entries icon_entry
- ;
-
-icon_entry : string string { if (Scr->FirstTime) AddToList(list, $1, $2); }
- ;
-
-function : LB function_entries RB
- ;
+win_color_list : LB win_color_entries RB
+ ;
+
+win_color_entries : /* Empty */
+ | win_color_entries win_color_entry
+ ;
+
+win_color_entry : string string { if (Scr->FirstTime &&
+ color == Scr->Monochrome)
+ AddToList(list, $1, $2); }
+ ;
+
+squeeze : SQUEEZE_TITLE {
+ if (HasShape) Scr->SqueezeTitle = TRUE;
+ }
+ | SQUEEZE_TITLE { list = &Scr->SqueezeTitleL;
+ if (HasShape && Scr->SqueezeTitle == -1)
+ Scr->SqueezeTitle = TRUE;
+ }
+ LB win_sqz_entries RB
+ | DONT_SQUEEZE_TITLE { Scr->SqueezeTitle = FALSE; }
+ | DONT_SQUEEZE_TITLE { list = &Scr->DontSqueezeTitleL; }
+ win_list
+ ;
+
+win_sqz_entries : /* Empty */
+ | win_sqz_entries string JKEYWORD signed_number number {
+ if (Scr->FirstTime) {
+ do_squeeze_entry (list, $2, $3, $4, $5);
+ }
+ }
+ ;
+
+
+iconm_list : LB iconm_entries RB
+ ;
+
+iconm_entries : /* Empty */
+ | iconm_entries iconm_entry
+ ;
+
+iconm_entry : string string number { if (Scr->FirstTime)
+ AddToList(list, $1, (char *)
+ AllocateIconManager($1, NULLSTR,
+ $2,$3));
+ }
+ | string string string number
+ { if (Scr->FirstTime)
+ AddToList(list, $1, (char *)
+ AllocateIconManager($1,$2,
+ $3, $4));
+ }
+ ;
+
+win_list : LB win_entries RB
+ ;
+
+win_entries : /* Empty */
+ | win_entries win_entry
+ ;
+
+win_entry : string { if (Scr->FirstTime)
+ AddToList(list, $1, 0);
+ }
+ ;
+
+icon_list : LB icon_entries RB
+ ;
+
+icon_entries : /* Empty */
+ | icon_entries icon_entry
+ ;
+
+icon_entry : string string { if (Scr->FirstTime) AddToList(list, $1, $2); }
+ ;
+
+function : LB function_entries RB
+ ;
function_entries: /* Empty */
- | function_entries function_entry
- ;
-
-function_entry : action { AddToMenu(root, empty, Action, NULL, $1,
- NULLSTR, NULLSTR);
- Action = empty;
- }
- ;
-
-menu : LB menu_entries RB
- ;
-
-menu_entries : /* Empty */
- | menu_entries menu_entry
- ;
-
-menu_entry : string action { AddToMenu(root, $1, Action, pull, $2,
- NULLSTR, NULLSTR);
- Action = empty;
- pull = NULL;
- }
- | string LP string COLON string RP action {
- AddToMenu(root, $1, Action, pull, $7,
- $3, $5);
- Action = empty;
- pull = NULL;
- }
- ;
-
-action : FKEYWORD { $$ = $1; }
- | FSKEYWORD string {
- $$ = $1;
- Action = $2;
- switch ($1) {
- case F_MENU:
- pull = GetRoot ($2, NULLSTR,NULLSTR);
- pull->prev = root;
- break;
- case F_WARPRING:
- if (!CheckWarpRingArg (Action)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "ignoring invalid f.warptoring argument \"%s\"\n",
- Action);
- $$ = F_NOP;
- }
- break;
- case F_WARPTOSCREEN:
- if (!CheckWarpScreenArg (Action)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "ignoring invalid f.warptoscreen argument \"%s\"\n",
- Action);
- $$ = F_NOP;
- }
- break;
- case F_COLORMAP:
- if (CheckColormapArg (Action)) {
- $$ = F_COLORMAP;
- } else {
- twmrc_error_prefix();
- fprintf (stderr,
- "ignoring invalid f.colormap argument \"%s\"\n",
- Action);
- $$ = F_NOP;
- }
- break;
- } /* end switch */
- }
- ;
-
-
-signed_number : number { $$ = $1; }
- | PLUS number { $$ = $2; }
- | MINUS number { $$ = -($2); }
- ;
-
-button : BUTTON number { $$ = $2;
- if ($2 == 0)
- yyerror("bad button 0");
-
- if ($2 > MAX_BUTTONS)
- {
- $$ = 0;
- yyerror("button number too large");
- }
- }
- ;
-
-string : STRING { ptr = strdup($1);
- RemoveDQuote(ptr);
- $$ = ptr;
- }
- ;
-number : NUMBER { $$ = $1; }
- ;
+ | function_entries function_entry
+ ;
+
+function_entry : action { AddToMenu(root, empty, Action, NULL, $1,
+ NULLSTR, NULLSTR);
+ Action = empty;
+ }
+ ;
+
+menu : LB menu_entries RB
+ ;
+
+menu_entries : /* Empty */
+ | menu_entries menu_entry
+ ;
+
+menu_entry : string action { AddToMenu(root, $1, Action, pull, $2,
+ NULLSTR, NULLSTR);
+ Action = empty;
+ pull = NULL;
+ }
+ | string LP string COLON string RP action {
+ AddToMenu(root, $1, Action, pull, $7,
+ $3, $5);
+ Action = empty;
+ pull = NULL;
+ }
+ ;
+
+action : FKEYWORD { $$ = $1; }
+ | FSKEYWORD string {
+ $$ = $1;
+ Action = $2;
+ switch ($1) {
+ case F_MENU:
+ pull = GetRoot ($2, NULLSTR,NULLSTR);
+ pull->prev = root;
+ break;
+ case F_WARPRING:
+ if (!CheckWarpRingArg (Action)) {
+ parseWarning (
+ "ignoring invalid f.warptoring argument \"%s\"",
+ Action);
+ $$ = F_NOP;
+ }
+ break;
+ case F_WARPTOSCREEN:
+ if (!CheckWarpScreenArg (Action)) {
+ parseWarning (
+ "ignoring invalid f.warptoscreen argument \"%s\"",
+ Action);
+ $$ = F_NOP;
+ }
+ break;
+ case F_COLORMAP:
+ if (CheckColormapArg (Action)) {
+ $$ = F_COLORMAP;
+ } else {
+ parseWarning (
+ "ignoring invalid f.colormap argument \"%s\"",
+ Action);
+ $$ = F_NOP;
+ }
+ break;
+ } /* end switch */
+ }
+ ;
+
+
+signed_number : number { $$ = $1; }
+ | PLUS number { $$ = $2; }
+ | MINUS number { $$ = -($2); }
+ ;
+
+button : BUTTON number { $$ = $2;
+ if ($2 == 0)
+ yyerror("bad button 0");
+
+ if ($2 > MAX_BUTTONS)
+ {
+ $$ = 0;
+ yyerror("button number too large");
+ }
+ }
+ ;
+
+string : STRING { ptr = strdup($1);
+ RemoveDQuote(ptr);
+ $$ = ptr;
+ }
+ ;
+number : NUMBER { $$ = $1; }
+ ;
%%
+
static void
yyerror(const char *s)
{
- twmrc_error_prefix();
- fprintf (stderr, "error in input file: %s\n", s ? s : "");
+ parseWarning("error in input file: %s", s ? s : "");
ParseError = 1;
}
@@ -678,208 +670,198 @@ RemoveDQuote(char *str)
register int n;
register int count;
- for (i=str+1, o=str; *i && *i != '\"'; o++)
- {
- if (*i == '\\')
- {
- switch (*++i)
- {
- case 'n':
- *o = '\n';
- i++;
- break;
- case 'b':
- *o = '\b';
- i++;
- break;
- case 'r':
- *o = '\r';
- i++;
- break;
- case 't':
- *o = '\t';
- i++;
- break;
- case 'f':
- *o = '\f';
- i++;
- break;
- case '0':
- if (*++i == 'x')
- goto hex;
- else
- --i;
- /* FALLTHRU */
- case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- n = 0;
- count = 0;
- while (*i >= '0' && *i <= '7' && count < 3)
- {
- n = (n<<3) + (*i++ - '0');
- count++;
- }
- *o = (char)n;
- break;
- hex:
- case 'x':
- n = 0;
- count = 0;
- while (i++, count++ < 2)
- {
- if (*i >= '0' && *i <= '9')
- n = (n<<4) + (*i - '0');
- else if (*i >= 'a' && *i <= 'f')
- n = (n<<4) + (*i - 'a') + 10;
- else if (*i >= 'A' && *i <= 'F')
- n = (n<<4) + (*i - 'A') + 10;
- else
- break;
- }
- *o = (char)n;
- break;
- case '\n':
- i++; /* punt */
- o--; /* to account for o++ at end of loop */
- break;
- case '\"':
- case '\'':
- case '\\':
- default:
- *o = *i++;
- break;
- }
- }
- else
- *o = *i++;
+ for (i = str + 1, o = str; *i && *i != '\"'; o++) {
+ if (*i == '\\') {
+ switch (*++i) {
+ case 'n':
+ *o = '\n';
+ i++;
+ break;
+ case 'b':
+ *o = '\b';
+ i++;
+ break;
+ case 'r':
+ *o = '\r';
+ i++;
+ break;
+ case 't':
+ *o = '\t';
+ i++;
+ break;
+ case 'f':
+ *o = '\f';
+ i++;
+ break;
+ case '0':
+ if (*++i == 'x')
+ goto hex;
+ else
+ --i;
+ /* FALLTHRU */
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ n = 0;
+ count = 0;
+ while (*i >= '0' && *i <= '7' && count < 3) {
+ n = (n << 3) + (*i++ - '0');
+ count++;
+ }
+ *o = (char) n;
+ break;
+ hex:
+ case 'x':
+ n = 0;
+ count = 0;
+ while (i++, count++ < 2) {
+ if (*i >= '0' && *i <= '9')
+ n = (n << 4) + (*i - '0');
+ else if (*i >= 'a' && *i <= 'f')
+ n = (n << 4) + (*i - 'a') + 10;
+ else if (*i >= 'A' && *i <= 'F')
+ n = (n << 4) + (*i - 'A') + 10;
+ else
+ break;
+ }
+ *o = (char) n;
+ break;
+ case '\n':
+ i++; /* punt */
+ o--; /* to account for o++ at end of loop */
+ break;
+ case '\"':
+ case '\'':
+ case '\\':
+ default:
+ *o = *i++;
+ break;
+ }
+ }
+ else
+ *o = *i++;
}
*o = '\0';
}
-static MenuRoot *GetRoot(const char *name, const char* fore, const char *back)
+static MenuRoot *
+GetRoot(const char *name, const char *fore, const char *back)
{
MenuRoot *tmp;
tmp = FindMenuRoot(name);
if (tmp == NULL)
- tmp = NewMenuRoot(name);
+ tmp = NewMenuRoot(name);
- if (fore)
- {
- int save;
+ if (fore) {
+ int save;
- save = Scr->FirstTime;
- Scr->FirstTime = TRUE;
- GetColor(COLOR, &tmp->hi_fore, fore);
- GetColor(COLOR, &tmp->hi_back, back);
- Scr->FirstTime = (short)save;
+ save = Scr->FirstTime;
+ Scr->FirstTime = TRUE;
+ GetColor(COLOR, &tmp->hi_fore, fore);
+ GetColor(COLOR, &tmp->hi_back, back);
+ Scr->FirstTime = (short) save;
}
return tmp;
}
-static void GotButton(int butt, int func)
+static void
+GotButton(int butt, int func)
{
int i;
- for (i = 0; i < NUM_CONTEXTS; i++)
- {
- if ((cont & (1 << i)) == 0)
- continue;
-
- Scr->Mouse[butt][i][mods].func = func;
- if (func == F_MENU)
- {
- pull->prev = NULL;
- Scr->Mouse[butt][i][mods].menu = pull;
- }
- else
- {
- root = GetRoot(TWM_ROOT, NULLSTR, NULLSTR);
- Scr->Mouse[butt][i][mods].item = AddToMenu(root,"x",Action,
- NULL, func, NULLSTR, NULLSTR);
- }
+ for (i = 0; i < NUM_CONTEXTS; i++) {
+ if ((cont & (1 << i)) == 0)
+ continue;
+
+ Scr->Mouse[butt][i][mods].func = func;
+ if (func == F_MENU) {
+ pull->prev = NULL;
+ Scr->Mouse[butt][i][mods].menu = pull;
+ }
+ else {
+ root = GetRoot(TWM_ROOT, NULLSTR, NULLSTR);
+ Scr->Mouse[butt][i][mods].item = AddToMenu(root, "x", Action,
+ NULL, func, NULLSTR, NULLSTR);
+ }
}
Action = empty;
pull = NULL;
cont = 0;
- mods_used |= (unsigned)mods;
+ mods_used |= (unsigned) mods;
mods = 0;
}
-static void GotKey(char *key, int func)
+static void
+GotKey(char *key, int func)
{
int i;
- for (i = 0; i < NUM_CONTEXTS; i++)
- {
- if ((cont & (1 << i)) == 0)
- continue;
- if (!AddFuncKey(key, i, mods, func, Name, Action))
- break;
+ for (i = 0; i < NUM_CONTEXTS; i++) {
+ if ((cont & (1 << i)) == 0)
+ continue;
+ if (!AddFuncKey(key, i, mods, func, Name, Action))
+ break;
}
Action = empty;
pull = NULL;
cont = 0;
- mods_used |= (unsigned)mods;
+ mods_used |= (unsigned) mods;
mods = 0;
}
-
-static void GotTitleButton (char *bitmapname, int func, Bool rightside)
+static void
+GotTitleButton(char *bitmapname, int func, Bool rightside)
{
- if (!CreateTitleButton (bitmapname, func, Action, pull, rightside, True)) {
- twmrc_error_prefix();
- fprintf (stderr,
- "unable to create %s titlebutton \"%s\"\n",
- rightside ? "right" : "left", bitmapname);
+ if (!CreateTitleButton(bitmapname, func, Action, pull, rightside, True)) {
+ parseWarning("unable to create %s titlebutton \"%s\"",
+ rightside ? "right" : "left", bitmapname);
}
Action = empty;
pull = NULL;
}
-static Bool CheckWarpScreenArg (char *s)
+static Bool
+CheckWarpScreenArg(char *s)
{
- XmuCopyISOLatin1Lowered (s, s);
+ XmuCopyISOLatin1Lowered(s, s);
- if (strcmp (s, WARPSCREEN_NEXT) == 0 ||
- strcmp (s, WARPSCREEN_PREV) == 0 ||
- strcmp (s, WARPSCREEN_BACK) == 0)
- return True;
+ if (strcmp(s, WARPSCREEN_NEXT) == 0 ||
+ strcmp(s, WARPSCREEN_PREV) == 0 ||
+ strcmp(s, WARPSCREEN_BACK) == 0)
+ return True;
- for (; *s && isascii(*s) && isdigit(*s); s++) ; /* SUPPRESS 530 */
+ for (; *s && isascii(*s) && isdigit(*s); s++); /* SUPPRESS 530 */
return (*s ? False : True);
}
-
-static Bool CheckWarpRingArg (char *s)
+static Bool
+CheckWarpRingArg(char *s)
{
- XmuCopyISOLatin1Lowered (s, s);
+ XmuCopyISOLatin1Lowered(s, s);
- if (strcmp (s, WARPSCREEN_NEXT) == 0 ||
- strcmp (s, WARPSCREEN_PREV) == 0)
- return True;
+ if (strcmp(s, WARPSCREEN_NEXT) == 0 ||
+ strcmp(s, WARPSCREEN_PREV) == 0)
+ return True;
return False;
}
-
-static Bool CheckColormapArg (char *s)
+static Bool
+CheckColormapArg(char *s)
{
- XmuCopyISOLatin1Lowered (s, s);
+ XmuCopyISOLatin1Lowered(s, s);
- if (strcmp (s, COLORMAP_NEXT) == 0 ||
- strcmp (s, COLORMAP_PREV) == 0 ||
- strcmp (s, COLORMAP_DEFAULT) == 0)
- return True;
+ if (strcmp(s, COLORMAP_NEXT) == 0 ||
+ strcmp(s, COLORMAP_PREV) == 0 ||
+ strcmp(s, COLORMAP_DEFAULT) == 0)
+ return True;
return False;
}
-
-
-void
-twmrc_error_prefix (void)
-{
- fprintf (stderr, "%s: line %d: ", ProgramName, yylineno);
-}
diff --git a/src/iconmgr.c b/src/iconmgr.c
index e59f849..48a2931 100644
--- a/src/iconmgr.c
+++ b/src/iconmgr.c
@@ -57,7 +57,6 @@ void
CreateIconManagers(void)
{
IconMgr *p;
- int mask;
char str[100];
char str1[100];
Pixel background;
@@ -74,9 +73,9 @@ CreateIconManagers(void)
}
for (p = &Scr->iconmgr; p != NULL; p = p->next) {
- mask = XParseGeometry(p->geometry, &JunkX, &JunkY,
- (unsigned int *) &p->width,
- (unsigned int *) &p->height);
+ int mask = XParseGeometry(p->geometry, &JunkX, &JunkY,
+ (unsigned int *) &p->width,
+ (unsigned int *) &p->height);
if (mask & XNegative)
JunkX = Scr->MyDisplayWidth - p->width -
@@ -129,7 +128,7 @@ AllocateIconManager(char *name, char *icon_name, char *geom, int columns)
#ifdef DEBUG_ICONMGR
fprintf(stderr, "AllocateIconManager\n");
fprintf(stderr, " name=\"%s\" icon_name=\"%s\", geom=\"%s\", col=%d\n",
- name, icon_name, geom, columns);
+ name, icon_name ? icon_name : "<null>", geom, columns);
#endif
if (Scr->NoIconManagers)
@@ -250,9 +249,8 @@ MoveIconManager(int dir)
}
if (!got_it) {
- fprintf(stderr,
- "%s: unable to find window (%d, %d) in icon manager\n",
- ProgramName, new_row, new_col);
+ twmWarning("unable to find window (%d, %d) in icon manager",
+ new_row, new_col);
return;
}
@@ -290,8 +288,6 @@ JumpIconManager(int dir)
{
IconMgr *ip, *tmp_ip = NULL;
int got_it = FALSE;
- ScreenInfo *sp;
- int screen;
if (!Active)
return;
@@ -309,8 +305,11 @@ JumpIconManager(int dir)
if (!got_it) {
int origscreen = ip->scr->screen;
int inc = (dir == F_NEXTICONMGR ? 1 : -1);
+ int screen;
for (screen = origscreen + inc;; screen += inc) {
+ ScreenInfo *sp;
+
if (screen >= NumScreens)
screen = 0;
else if (screen < 0)
@@ -629,7 +628,6 @@ void
PackIconManager(IconMgr *ip)
{
int newwidth, i, row, col, maxcol, colinc, rowinc, wheight, wwidth;
- int new_x, new_y;
int savewidth;
WList *tmp;
@@ -645,7 +643,10 @@ PackIconManager(IconMgr *ip)
row = 0;
col = ip->columns;
maxcol = 0;
+
for (i = 0, tmp = ip->first; tmp != NULL; i++, tmp = tmp->next) {
+ int new_x, new_y;
+
tmp->me = i;
if (++col >= ip->columns) {
col = 0;
diff --git a/src/iconmgr.h b/src/iconmgr.h
index c74ffb1..ae9214a 100644
--- a/src/iconmgr.h
+++ b/src/iconmgr.h
@@ -34,6 +34,8 @@ in this Software without prior written authorization from The Open Group.
#ifndef _ICONMGR_
#define _ICONMGR_
+#include "twm.h"
+
typedef struct WList {
struct WList *next;
struct WList *prev;
diff --git a/src/icons.c b/src/icons.c
index a437963..bf8d8aa 100644
--- a/src/icons.c
+++ b/src/icons.c
@@ -323,10 +323,11 @@ FreeIconEntries(IconRegion *ir)
void
FreeIconRegions(void)
{
- IconRegion *ir, *tmp;
+ IconRegion *ir;
for (ir = Scr->FirstRegion; ir != NULL;) {
- tmp = ir;
+ IconRegion *tmp = ir;
+
FreeIconEntries(ir);
ir = ir->next;
free(tmp);
@@ -344,7 +345,6 @@ CreateIconWindow(TwmWindow *tmp_win, int def_x, int def_y)
XSetWindowAttributes attributes; /* attributes for create windows */
Pixmap pm = None; /* tmp pixmap variable */
int final_x, final_y;
- int x;
FB(tmp_win->iconc.fore, tmp_win->iconc.back);
@@ -536,6 +536,7 @@ CreateIconWindow(TwmWindow *tmp_win, int def_x, int def_y)
if (pm != None &&
(!(tmp_win->wmhints && tmp_win->wmhints->flags & IconWindowHint))) {
int y;
+ int x;
y = 0;
if (tmp_win->icon_w_width == tmp_win->icon_width)
diff --git a/src/icons.h b/src/icons.h
index 4945967..4bac87a 100644
--- a/src/icons.h
+++ b/src/icons.h
@@ -34,6 +34,8 @@ in this Software without prior written authorization from The Open Group.
#ifndef ICONS_H
#define ICONS_H
+#include "twm.h"
+
typedef struct IconRegion {
struct IconRegion *next;
int x, y, w, h;
diff --git a/src/lex.l b/src/lex.l
index 320d206..d07a085 100644
--- a/src/lex.l
+++ b/src/lex.l
@@ -1,4 +1,5 @@
%{
+
/*****************************************************************************/
/*
@@ -56,12 +57,14 @@ in this Software without prior written authorization from The Open Group.
*
* .twmrc lex file
*
- * 12-Nov-87 Thomas E. LaStrange File created
+ * 12-Nov-87 Thomas E. LaStrange File created
*
***********************************************************************/
/* $XFree86: xc/programs/twm/lex.l,v 3.13 2001/08/27 21:11:39 dawes Exp $ */
-/* #include <stdio.h> */ /* lex already includes stdio.h */
+#define YY_NO_INPUT /* we have our own! */
+
+/* #include <stdio.h> */ /* lex already includes stdio.h */
#include "twm.h"
#include "gram.h"
#include "list.h"
@@ -72,75 +75,81 @@ int yylineno;
#undef YY_INPUT
#define YY_INPUT(buf,result,size) ((result) = doinput((buf),(size)))
-static int doinput (char *buf, int size)
+static int
+doinput(char *buf, int size)
{
- int c;
+ int c;
- if (size == 0)
- return (0);
+ if (size == 0)
+ return (0);
- if ((c = (*twmInputFunc)()) <= 0)
- return (0);
+ if ((c = (*twmInputFunc) ()) <= 0)
+ return (0);
- buf[0] = (char)c;
- return (1);
+ buf[0] = (char) c;
+ if (c == '\n')
+ ++yylineno;
+ return (1);
}
#define YY_NO_UNPUT
#endif
%}
-string \"([^"]|\\.)*\"
-number [0-9]+
+string \"([^"]|\\.)*\"
+number [0-9]+
%%
-"{" { return (LB); }
-"}" { return (RB); }
-"(" { return (LP); }
-")" { return (RP); }
-"=" { return (EQUALS); }
-":" { return (COLON); }
-"+" { return PLUS; }
-"-" { return MINUS; }
-"|" { return OR; }
-
-[a-zA-Z\.]+ { int token = parse_keyword ((char *)yytext,
- &yylval.num);
- if (token == ERRORTOKEN) {
- twmrc_error_prefix();
- fprintf (stderr,
- "ignoring unknown keyword: %s\n",
- yytext);
- ParseError = 1;
- } else
- return token;
- }
-
-"!" { yylval.num = F_EXEC; return FSKEYWORD; }
-"^" { yylval.num = F_CUT; return FSKEYWORD; }
-
-{string} { yylval.ptr = (char *)yytext; return STRING; }
-{number} { (void)sscanf((char *)yytext, "%d", &yylval.num);
- return (NUMBER);
- }
-\#[^\n]*\n {;}
-[\r\n\t ] {;}
-. {
- twmrc_error_prefix();
- fprintf (stderr,
- "ignoring character \"%s\"\n",
- yytext);
- ParseError = 1;
- }
+"{" { return (LB); }
+"}" { return (RB); }
+"(" { return (LP); }
+")" { return (RP); }
+"=" { return (EQUALS); }
+":" { return (COLON); }
+"+" { return PLUS; }
+"-" { return MINUS; }
+"|" { return OR; }
+
+[a-zA-Z\.]+ { int token = parse_keyword ((char *)yytext,
+ &yylval.num);
+ if (token == ERRORTOKEN) {
+ parseWarning (
+ "ignoring unknown keyword: %s",
+ yytext);
+ ParseError = 1;
+ } else
+ return token;
+ }
+
+"!" { yylval.num = F_EXEC; return FSKEYWORD; }
+"^" { yylval.num = F_CUT; return FSKEYWORD; }
+
+{string} { yylval.ptr = (char *)yytext; return STRING; }
+{number} { (void)sscanf((char *)yytext, "%d", &yylval.num);
+ return (NUMBER);
+ }
+\#[^\n]*\n {;}
+[\r\n\t ] {;}
+. {
+ parseWarning (
+ "ignoring character \"%s\"",
+ yytext);
+ ParseError = 1;
+ }
%%
+
#ifndef yywrap
-int yywrap() { return(1);}
+int
+yywrap()
+{
+ return (1);
+}
#endif
#undef unput
#undef input
#undef output
#undef feof
-#define unput(c) twmUnput(c)
-#define input() (*twmInputFunc)()
-#define output(c) TwmOutput(c)
-#define feof() (1)
+#define unput(c) twmUnput(c)
+#define input() (*twmInputFunc)()
+#define output(c) TwmOutput(c)
+#define feof() (1)
diff --git a/src/list.c b/src/list.c
index 9d9bec8..4422cc9 100644
--- a/src/list.c
+++ b/src/list.c
@@ -92,9 +92,8 @@ AddToList(name_list ** list_head, char *name, char *ptr)
nptr = malloc(sizeof(name_list));
if (nptr == NULL) {
- twmrc_error_prefix();
- fprintf(stderr, "unable to allocate %ld bytes for name_list\n",
- (unsigned long) sizeof(name_list));
+ parseWarning("unable to allocate %lu bytes for name_list",
+ (unsigned long) sizeof(name_list));
Done(NULL, NULL);
}
diff --git a/src/menus.c b/src/menus.c
index 5448bad..c721e00 100644
--- a/src/menus.c
+++ b/src/menus.c
@@ -133,7 +133,7 @@ void
InitMenus(void)
{
int i, j, k;
- FuncKey *key, *tmp;
+ FuncKey *key;
for (i = 0; i < MAX_BUTTONS + 1; i++)
for (j = 0; j < NUM_CONTEXTS; j++)
@@ -147,8 +147,9 @@ InitMenus(void)
if (FirstScreen) {
for (key = Scr->FuncKeyRoot.next; key != NULL;) {
+ FuncKey *tmp = key;
+
free(key->name);
- tmp = key;
key = key->next;
free(tmp);
}
@@ -215,9 +216,8 @@ CreateTitleButton(const char *name, int func, const char *action,
TitleButton *tb = malloc(sizeof(TitleButton));
if (!tb) {
- fprintf(stderr,
- "%s: unable to allocate %ld bytes for title button\n",
- ProgramName, (unsigned long) sizeof(TitleButton));
+ twmWarning("unable to allocate %lu bytes for title button",
+ (unsigned long) sizeof(TitleButton));
return 0;
}
@@ -306,11 +306,11 @@ InitTitlebarButtons(void)
/* insert extra buttons */
if (!CreateTitleButton(TBPM_ICONIFY, F_ICONIFY, "", (MenuRoot *) NULL,
False, False)) {
- fprintf(stderr, "%s: unable to add iconify button\n", ProgramName);
+ twmWarning("unable to add iconify button");
}
if (!CreateTitleButton(TBPM_RESIZE, F_RESIZE, "", (MenuRoot *) NULL,
True, True)) {
- fprintf(stderr, "%s: unable to add resize button\n", ProgramName);
+ twmWarning("unable to add resize button");
}
AddDefaultBindings();
}
@@ -325,9 +325,7 @@ InitTitlebarButtons(void)
if (!tb->bitmap) {
tb->bitmap = FindBitmap(TBPM_QUESTION, &tb->width, &tb->height);
if (!tb->bitmap) { /* cannot happen (see util.c) */
- fprintf(stderr,
- "%s: unable to add titlebar button \"%s\"\n",
- ProgramName, tb->name);
+ twmWarning("unable to add titlebar button \"%s\"", tb->name);
}
}
@@ -366,7 +364,6 @@ PaintEntry(MenuRoot *mr, MenuItem *mi, int exposure)
text_y = y_offset + Scr->MenuFont.y;
if (mi->func != F_TITLE) {
- int x, y;
if (mi->state) {
XSetForeground(dpy, Scr->NormalGC, mi->hi_back);
@@ -401,6 +398,8 @@ PaintEntry(MenuRoot *mr, MenuItem *mi, int exposure)
}
if (mi->func == F_MENU) {
+ int x, y;
+
/* create the pull right pixmap if needed */
if (Scr->pullPm == None) {
Scr->pullPm = CreateMenuIcon(Scr->MenuFont.height,
@@ -414,8 +413,6 @@ PaintEntry(MenuRoot *mr, MenuItem *mi, int exposure)
}
}
else {
- int y;
-
XSetForeground(dpy, Scr->NormalGC, mi->back);
/* fill the rectangle with the title background color */
@@ -423,6 +420,8 @@ PaintEntry(MenuRoot *mr, MenuItem *mi, int exposure)
(unsigned) mr->width, (unsigned) Scr->EntryHeight);
{
+ int y;
+
XSetForeground(dpy, Scr->NormalGC, mi->fore);
/* now draw the dividing lines */
if (y_offset)
@@ -658,8 +657,8 @@ AddToMenu(MenuRoot *menu, const char *item, const char *action,
int width;
#ifdef DEBUG_MENUS
- fprintf(stderr, "adding menu item=\"%s\", action=%s, sub=%d, f=%d\n",
- item, action, sub, func);
+ fprintf(stderr, "adding menu item=\"%s\", action=%s, sub=%p, f=%d\n",
+ item, action ? action : "<null>", sub, func);
#endif
tmp = malloc(sizeof(MenuItem));
@@ -731,18 +730,17 @@ MakeMenu(MenuRoot *mr)
XColor f1, f2, f3;
XColor b1, b2, b3;
XColor save_fore, save_back;
- int num, i;
- int fred, fgreen, fblue;
- int bred, bgreen, bblue;
- int width;
- unsigned long valuemask;
+ int i;
XSetWindowAttributes attributes;
Colormap cmap = Scr->TwmRoot.cmaps.cwins[0]->colormap->c;
Scr->EntryHeight = Scr->MenuFont.height + 4;
- /* lets first size the window accordingly */
+ /* let's first size the window accordingly */
if (mr->mapped == NEVER_MAPPED) {
+ int width;
+ unsigned long valuemask;
+
if (mr->pull == TRUE) {
mr->width = (short) (mr->width + (16 + 10));
}
@@ -837,7 +835,12 @@ MakeMenu(MenuRoot *mr)
return;
start = mr->first;
+
while (TRUE) {
+ int num;
+ int fred, fgreen, fblue;
+ int bred, bgreen, bblue;
+
for (; start != NULL; start = start->next) {
if (start->user_colors)
break;
@@ -915,10 +918,8 @@ MakeMenu(MenuRoot *mr)
Bool
PopUpMenu(MenuRoot *menu, int x, int y, Bool center)
{
- int WindowNameCount;
TwmWindow **WindowNames;
TwmWindow *tmp_win2, *tmp_win3;
- int i;
int (*compar) (const char *, const char *) =
(Scr->CaseSensitive ? strcmp : XmuCompareISOLatin1);
@@ -929,6 +930,7 @@ PopUpMenu(MenuRoot *menu, int x, int y, Bool center)
if (menu == Scr->Windows) {
TwmWindow *tmp_win;
+ int WindowNameCount;
/* this is the twm windows menu, let's go ahead and build it */
@@ -945,10 +947,14 @@ PopUpMenu(MenuRoot *menu, int x, int y, Bool center)
for (tmp_win = Scr->TwmRoot.next, WindowNameCount = 0;
tmp_win != NULL; tmp_win = tmp_win->next)
WindowNameCount++;
+
if (WindowNameCount != 0) {
+ int i;
+
WindowNames =
malloc(sizeof(TwmWindow *) * (size_t) WindowNameCount);
WindowNames[0] = Scr->TwmRoot.next;
+
for (tmp_win = Scr->TwmRoot.next->next, WindowNameCount = 1;
tmp_win != NULL; tmp_win = tmp_win->next, WindowNameCount++) {
tmp_win2 = tmp_win;
@@ -1285,7 +1291,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
if (smcConn)
SmcCloseConnection(smcConn, 0, NULL);
execvp(*Argv, Argv);
- fprintf(stderr, "%s: unable to restart: %s\n", ProgramName, *Argv);
+ twmWarning("unable to restart: %s", *Argv);
break;
}
@@ -1687,7 +1693,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
}
if (ConstMoveDir != MOVE_NONE) {
- int xl, yt, xr, yb, w2, h;
+ int xl, yt, w2, h;
xl = ConstMoveX;
yt = ConstMoveY;
@@ -1695,8 +1701,8 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
h = (int) ((unsigned) DragHeight + 2 * JunkBW);
if (Scr->DontMoveOff && MoveFunction != F_FORCEMOVE) {
- xr = xl + w2;
- yb = yt + h;
+ int xr = xl + w2;
+ int yb = yt + h;
if (xl < 0)
xl = 0;
@@ -1719,7 +1725,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
}
}
else if (DragWindow != None) {
- int xl, yt, xr, yb, w2, h;
+ int xl, yt, w2, h;
if (!menuFromFrameOrWindowOrTitlebar) {
xl = (int) ((unsigned) eventp->xmotion.x_root -
@@ -1735,8 +1741,8 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
h = (int) ((unsigned) DragHeight + 2 * JunkBW);
if (Scr->DontMoveOff && MoveFunction != F_FORCEMOVE) {
- xr = xl + w2;
- yb = yt + h;
+ int xr = xl + w2;
+ int yb = yt + h;
if (xl < 0)
xl = 0;
@@ -1773,8 +1779,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
MenuItem *mitem;
if ((mroot = FindMenuRoot(action)) == NULL) {
- fprintf(stderr, "%s: couldn't find function \"%s\"\n",
- ProgramName, action);
+ twmWarning("couldn't find function \"%s\"", action);
return TRUE;
}
@@ -1943,9 +1948,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
close(fd);
}
else {
- fprintf(stderr,
- "%s: unable to open cut file \"%s\"\n",
- ProgramName, tmp);
+ twmWarning("unable to open cut file \"%s\"", tmp);
}
free(ptr);
}
@@ -1955,7 +1958,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
}
}
else {
- fprintf(stderr, "%s: cut buffer is empty\n", ProgramName);
+ twmWarning("cut buffer is empty");
}
break;
@@ -1994,7 +1997,6 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_WARPNEXT:
{
register TwmWindow *t;
- static TwmWindow *savedwarp = NULL;
TwmWindow *of, *l, *n;
int c = 0;
@@ -2019,9 +2021,12 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
if (t == of)
c++;
- if (bwin(t) || c >= 2)
+ if (bwin(t) || c >= 2) {
Bell(XkbBI_MinorError, 0, None);
+ }
else {
+ static TwmWindow *savedwarp = NULL;
+
if (of && of == savedwarp) {
Iconify(of, 0, 0);
savedwarp = NULL;
@@ -2132,13 +2137,12 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
close(fd);
}
else {
- fprintf(stderr, "%s: unable to open file \"%s\"\n",
- ProgramName, ptr);
+ twmWarning("unable to open file \"%s\"", ptr);
}
free(ptr);
}
else {
- fprintf(stderr, "%s: error expanding filename\n", ProgramName);
+ twmWarning("error expanding filename");
}
break;
@@ -2194,7 +2198,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
break;
case F_STARTWM:
execlp("/bin/sh", "sh", "-c", action, (void *) NULL);
- fprintf(stderr, "%s: unable to start: %s\n", ProgramName, *Argv);
+ twmWarning("unable to start: %s", *Argv);
break;
}
@@ -2281,25 +2285,33 @@ NeedToDefer(MenuRoot *root)
return FALSE;
}
+/*
+ * We cannot safely free a value passed to putenv, but we can cache the most
+ * recent value, reducing the memory leaks.
+ */
+#define cache_env(saved) \
+ if (saved == NULL || strcmp(saved, update)) { \
+ saved = update; \
+ } else { \
+ free(update); \
+ update = saved; \
+ }
+
static void
Execute(const char *s)
{
- /* FIXME: is all this stuff needed? There could be security problems here. */
- static char buf[256];
+ static const char display_eqls[] = "DISPLAY=";
+ static char *main_display;
+ static char *exec_display;
+
char *ds = DisplayString(dpy);
- char *colon, *dot1;
- char oldDisplay[256];
- char *doisplay;
- int restorevar = 0;
-
- oldDisplay[0] = '\0';
- doisplay = getenv("DISPLAY");
- if (doisplay)
- if (strlcpy (oldDisplay, doisplay, sizeof(oldDisplay)) >=
- sizeof(oldDisplay)) {
- /* some error report? */
- return;
- }
+ char *colon;
+ char *oldDisplay = NULL;
+ char *value;
+ Bool restorevar = False;
+
+ value = getenv("DISPLAY");
+ oldDisplay = strdup(value ? value : "");
/*
* Build a display string using the current screen number, so that
@@ -2307,24 +2319,42 @@ Execute(const char *s)
* that they were invoked from, unless specifically overridden on
* their command line.
*/
- colon = strrchr (ds, ':');
- if (colon) { /* if host[:]:dpy */
- strlcpy (buf, "DISPLAY=", sizeof(buf));
- strlcat (buf, ds, sizeof(buf));
- colon = buf + 8 + (colon - ds); /* use version in buf */
- dot1 = strchr (colon, '.'); /* first period after colon */
- if (!dot1) dot1 = colon + strlen (colon); /* if not there, append */
- (void) sprintf (dot1, ".%d", Scr->screen);
- putenv (buf);
- restorevar = 1;
+ colon = strrchr(ds, ':');
+ if (colon) { /* if host[:]:dpy */
+ size_t need = sizeof(display_eqls) + strlen(ds) + 10;
+ char *update = malloc(need);
+
+ if (update != NULL) {
+ char *dot1;
+
+ strlcpy(update, display_eqls, need);
+ strlcat(update, ds, need);
+ colon = strrchr(update, ':');
+ dot1 = strchr(colon, '.'); /* first period after colon */
+ if (dot1 == NULL)
+ dot1 = colon + strlen(colon); /* if not there, append */
+ (void) sprintf(dot1, ".%d", Scr->screen);
+ cache_env(exec_display);
+ if (strcmp(update, oldDisplay)) {
+ putenv(update);
+ restorevar = True;
+ }
+ }
}
(void) system(s);
- if (restorevar) { /* why bother? */
- (void) snprintf(buf, sizeof(buf), "DISPLAY=%s", oldDisplay);
- putenv(buf);
+ if (restorevar) {
+ size_t need = sizeof(display_eqls) + strlen(oldDisplay);
+ char *update = malloc(need);
+
+ if (update != NULL) {
+ (void) snprintf(update, need, "%s%s", display_eqls, oldDisplay);
+ cache_env(main_display);
+ putenv(update);
+ }
}
+ free(oldDisplay);
}
/**
@@ -2505,7 +2535,7 @@ Iconify(TwmWindow *tmp_win, int def_x, int def_y)
static void
Identify(TwmWindow *t)
{
- int i, n, twidth, width, height;
+ int i, n, width, height;
int x, y;
unsigned int wwidth, wheight, bw, depth;
Window junk;
@@ -2528,9 +2558,9 @@ Identify(TwmWindow *t)
"Class.res_class = \"%s\"", t->class.res_class);
Info[n++][0] = '\0';
snprintf(Info[n++], INFO_SIZE,
- "Geometry/root = %dx%d+%d+%d", wwidth, wheight, x, y);
- snprintf(Info[n++], INFO_SIZE, "Border width = %d", bw);
- snprintf(Info[n++], INFO_SIZE, "Depth = %d", depth);
+ "Geometry/root = %ux%u+%d+%d", wwidth, wheight, x, y);
+ snprintf(Info[n++], INFO_SIZE, "Border width = %u", bw);
+ snprintf(Info[n++], INFO_SIZE, "Depth = %u", depth);
if (HasSync) {
int priority;
@@ -2546,8 +2576,9 @@ Identify(TwmWindow *t)
height = n * (Scr->DefaultFont.height + 2);
width = 1;
for (i = 0; i < n; i++) {
- twidth = MyFont_TextWidth(&Scr->DefaultFont, Info[i],
- (int) strlen(Info[i]));
+ int twidth = MyFont_TextWidth(&Scr->DefaultFont, Info[i],
+ (int) strlen(Info[i]));
+
if (twidth > width)
width = twidth;
}
@@ -2637,8 +2668,7 @@ WarpToScreen(int n, int inc)
n += inc;
continue;
}
- fprintf(stderr, "%s: unable to warp to unmanaged screen %d\n",
- ProgramName, n);
+ twmWarning("unable to warp to unmanaged screen %d", n);
Bell(XkbBI_MinorError, 0, None);
return;
}
@@ -2661,7 +2691,6 @@ WarpToScreen(int n, int inc)
static void
BumpWindowColormap(TwmWindow *tmp, int inc)
{
- int i, j, previously_installed;
ColormapWindow **cwins;
if (!tmp)
@@ -2671,6 +2700,9 @@ BumpWindowColormap(TwmWindow *tmp, int inc)
cwins =
malloc(sizeof(ColormapWindow *) * (size_t) tmp->cmaps.number_cwins);
if (cwins) {
+ int i;
+ int previously_installed;
+
/* SUPPRESS 560 */
if ((previously_installed = (Scr->cmapInfo.cmaps == &tmp->cmaps &&
tmp->cmaps.number_cwins))) {
@@ -2679,7 +2711,8 @@ BumpWindowColormap(TwmWindow *tmp, int inc)
}
for (i = 0; i < tmp->cmaps.number_cwins; i++) {
- j = i - inc;
+ int j = i - inc;
+
if (j >= tmp->cmaps.number_cwins)
j -= tmp->cmaps.number_cwins;
else if (j < 0)
diff --git a/src/menus.h b/src/menus.h
index de0629c..0692a27 100644
--- a/src/menus.h
+++ b/src/menus.h
@@ -60,6 +60,8 @@ in this Software without prior written authorization from The Open Group.
#ifndef _MENUS_
#define _MENUS_
+#include "twm.h"
+
#define TWM_ROOT "bLoB_GoOp" /* my private root menu */
#define TWM_WINDOWS "TwmWindows" /* for f.menu "TwmWindows" */
diff --git a/src/parse.c b/src/parse.c
index d81c2f3..48430b3 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -58,14 +58,17 @@ in this Software without prior written authorization from The Open Group.
***********************************************************************/
#include <stdio.h>
+#include <stdarg.h>
#include <X11/Xos.h>
#include <X11/Xmu/CharSet.h>
+
#include "twm.h"
#include "screen.h"
#include "menus.h"
#include "util.h"
#include "gram.h"
#include "parse.h"
+
#include <X11/Xatom.h>
#include <X11/extensions/sync.h>
@@ -82,8 +85,6 @@ static unsigned char overflowbuff[20]; /* really only need one */
static int overflowlen;
static unsigned char **stringListSource, *currentString;
-static int doparse(int (*ifunc) (void), const char *srctypename,
- const char *srcname);
static int twmFileInput(void);
static int twmStringListInput(void);
static int ParseUsePPosition(char *s);
@@ -95,6 +96,9 @@ int ConstrainedMoveTime = 400; /* milliseconds, event times */
int (*twmInputFunc) (void);
+static const char *twmInputFile;
+static const char *twmInputType;
+
/**
* parse the .twmrc file
* \param filename the filename to parse. NULL indicates $HOME/.twmrc
@@ -108,6 +112,8 @@ doparse(int (*ifunc) (void), const char *srctypename, const char *srcname)
yylineno = 1;
ParseError = FALSE;
twmInputFunc = ifunc;
+ twmInputFile = srcname;
+ twmInputType = srctypename;
overflowlen = 0;
yyparse();
@@ -146,11 +152,12 @@ doparse(int (*ifunc) (void), const char *srctypename, const char *srcname)
&Scr->PointerForeground, &Scr->PointerBackground);
}
if (ParseError) {
- fprintf(stderr, "%s: errors found in twm %s",
- ProgramName, srctypename);
- if (srcname)
- fprintf(stderr, " \"%s\"", srcname);
- fprintf(stderr, "\n");
+ if (srcname) {
+ twmWarning("errors found in twm %s \"%s\"", srctypename, srcname);
+ }
+ else {
+ twmWarning("errors found in twm %s", srctypename);
+ }
}
return (ParseError ? 0 : 1);
}
@@ -206,9 +213,8 @@ ParseTwmrc(char *filename)
int status;
if (filename && cp != filename) {
- fprintf(stderr,
- "%s: unable to open twmrc file %s, using %s instead\n",
- ProgramName, filename, cp);
+ twmWarning("unable to open twmrc file %s, using %s instead",
+ filename, cp);
}
status = doparse(twmFileInput, "file", cp);
fclose(twmrc);
@@ -216,9 +222,8 @@ ParseTwmrc(char *filename)
}
else {
if (filename) {
- fprintf(stderr,
- "%s: unable to open twmrc file %s, using built-in defaults instead\n",
- ProgramName, filename);
+ twmWarning("unable to open twmrc file %s,"
+ " using built-in defaults instead", filename);
}
return ParseStringList(defTwmrc);
}
@@ -285,8 +290,7 @@ twmUnput(int c)
overflowbuff[overflowlen++] = (unsigned char) c;
}
else {
- twmrc_error_prefix();
- fprintf(stderr, "unable to unput character (%d)\n", c);
+ parseWarning("unable to unput character (%d)", c);
}
}
@@ -749,9 +753,7 @@ do_string_keyword(int keyword, char *s)
int ppos = ParseUsePPosition(s);
if (ppos < 0) {
- twmrc_error_prefix();
- fprintf(stderr,
- "ignoring invalid UsePPosition argument \"%s\"\n", s);
+ parseWarning("ignoring invalid UsePPosition argument \"%s\"", s);
}
else {
Scr->UsePPosition = (short) ppos;
@@ -800,13 +802,11 @@ do_string_keyword(int keyword, char *s)
&JunkHeight);
if ((JunkMask & (WidthValue | HeightValue)) !=
(WidthValue | HeightValue)) {
- twmrc_error_prefix();
- fprintf(stderr, "bad MaxWindowSize \"%s\"\n", s);
+ parseWarning("bad MaxWindowSize \"%s\"", s);
return 0;
}
if (JunkWidth <= 0 || JunkHeight <= 0) {
- twmrc_error_prefix();
- fprintf(stderr, "MaxWindowSize \"%s\" must be positive\n", s);
+ parseWarning("MaxWindowSize \"%s\" must be positive", s);
return 0;
}
Scr->MaxWindowWidth = (int) JunkWidth;
@@ -983,19 +983,20 @@ do_color_keyword(int keyword, int colormode, char *s)
static void
put_pixel_on_root(Pixel pixel)
{
- int i, addPixel = 1;
+ int addPixel = 1;
Atom pixelAtom, retAtom;
int retFormat;
unsigned long nPixels, retAfter;
unsigned char *retProp;
- Pixel *pixelProp;
pixelAtom = XInternAtom(dpy, "_MIT_PRIORITY_COLORS", True);
if (XGetWindowProperty(dpy, Scr->Root, pixelAtom, 0, 8192,
False, XA_CARDINAL, &retAtom,
&retFormat, &nPixels, &retAfter,
&retProp) == Success) {
- pixelProp = (Pixel *) retProp;
+ int i;
+ Pixel *pixelProp = (Pixel *) retProp;
+
for (i = 0; (unsigned long) i < nPixels; i++)
if (pixel == pixelProp[i])
addPixel = 0;
@@ -1134,20 +1135,16 @@ do_squeeze_entry(name_list ** list, char *name, int justify, int num, int denom)
int absnum = (num < 0 ? -num : num);
if (denom < 0) {
- twmrc_error_prefix();
- fprintf(stderr, "negative SqueezeTitle denominator %d\n", denom);
+ parseWarning("negative SqueezeTitle denominator %d", denom);
return;
}
if (absnum > denom && denom != 0) {
- twmrc_error_prefix();
- fprintf(stderr, "SqueezeTitle fraction %d/%d outside window\n",
- num, denom);
+ parseWarning("SqueezeTitle fraction %d/%d outside window", num, denom);
return;
}
if (denom == 1) {
- twmrc_error_prefix();
- fprintf(stderr, "useless SqueezeTitle faction %d/%d, assuming 0/0\n",
- num, denom);
+ parseWarning("useless SqueezeTitle faction %d/%d, assuming 0/0",
+ num, denom);
num = 0;
denom = 0;
}
@@ -1158,9 +1155,8 @@ do_squeeze_entry(name_list ** list, char *name, int justify, int num, int denom)
sinfo = malloc(sizeof(SqueezeInfo));
if (!sinfo) {
- twmrc_error_prefix();
- fprintf(stderr, "unable to allocate %ld bytes for squeeze info\n",
- (unsigned long) sizeof(SqueezeInfo));
+ parseWarning("unable to allocate %lu bytes for squeeze info",
+ (unsigned long) sizeof(SqueezeInfo));
return;
}
sinfo->justify = justify;
@@ -1169,3 +1165,23 @@ do_squeeze_entry(name_list ** list, char *name, int justify, int num, int denom)
AddToList(list, name, (char *) sinfo);
}
}
+
+void
+parseWarning(const char *format, ...)
+{
+ if (message_level > 0) {
+ va_list ap;
+
+ va_start(ap, format);
+ if (twmInputFile != NULL) {
+ fprintf(stderr, "%s: line %d: ", twmInputFile, yylineno);
+ }
+ else {
+ fprintf(stderr, "%s[%s]: line %d: ", ProgramName, twmInputType,
+ yylineno);
+ }
+ vfprintf(stderr, format, ap);
+ fputc('\n', stderr);
+ va_end(ap);
+ }
+}
diff --git a/src/resize.c b/src/resize.c
index 07a1015..dce406d 100644
--- a/src/resize.c
+++ b/src/resize.c
@@ -608,7 +608,7 @@ ConstrainSize(TwmWindow *tmp_win, int *widthp, int *heightp)
#define makemult(a,b) ((b==1) ? (a) : (((int)((a)/(b))) * (b)) )
#define _min(a,b) (((a) < (b)) ? (a) : (b))
- int minWidth, minHeight, maxWidth, maxHeight, xinc, yinc, delta;
+ int minWidth, minHeight, maxWidth, maxHeight, xinc, yinc;
int baseWidth, baseHeight;
int dwidth = *widthp, dheight = *heightp;
@@ -694,6 +694,8 @@ ConstrainSize(TwmWindow *tmp_win, int *widthp, int *heightp)
*/
if (tmp_win->hints.flags & PAspect) {
+ int delta;
+
if (minAspectX * dheight > minAspectY * dwidth) {
delta = makemult(minAspectX * dheight / minAspectY - dwidth, xinc);
if (dwidth + delta <= maxWidth)
@@ -914,7 +916,6 @@ fullzoom(TwmWindow *tmp_win, int flag)
Window junkRoot;
unsigned int junkbw, junkDepth;
int basex, basey;
- int frame_bw_times_2;
XGetGeometry(dpy, (Drawable) tmp_win->frame, &junkRoot,
&dragx, &dragy, (unsigned int *) &dragWidth,
@@ -931,6 +932,8 @@ fullzoom(TwmWindow *tmp_win, int flag)
tmp_win->zoomed = ZOOM_NONE;
}
else {
+ int frame_bw_times_2;
+
if (tmp_win->zoomed == ZOOM_NONE) {
tmp_win->save_frame_x = dragx;
tmp_win->save_frame_y = dragy;
diff --git a/src/resize.h b/src/resize.h
index 5eb729e..a16a238 100644
--- a/src/resize.h
+++ b/src/resize.h
@@ -60,6 +60,8 @@ in this Software without prior written authorization from The Open Group.
#ifndef _RESIZE_
#define _RESIZE_
+#include "twm.h"
+
extern void AddEndResize(TwmWindow *tmp_win);
extern void AddStartResize(TwmWindow *tmp_win, int x, int y, int w, int h);
extern void ConstrainSize(TwmWindow *tmp_win, int *widthp, int *heightp);
diff --git a/src/session.c b/src/session.c
index ed8bb33..94b4d63 100644
--- a/src/session.c
+++ b/src/session.c
@@ -274,7 +274,7 @@ WriteWinConfigEntry(FILE *configFile, TwmWindow *theWindow,
char *clientId, char *windowRole)
{
char **wm_command;
- int wm_command_count, i;
+ int wm_command_count;
if (!write_counted_string(configFile, clientId))
return 0;
@@ -311,6 +311,8 @@ WriteWinConfigEntry(FILE *configFile, TwmWindow *theWindow,
return 0;
}
else {
+ int i;
+
if (!write_byte(configFile, (unsigned char) wm_command_count))
return 0;
for (i = 0; i < wm_command_count; i++)
@@ -574,12 +576,14 @@ GetWindowConfig(TwmWindow *theWindow,
*/
char **wm_command = NULL;
- int wm_command_count = 0, i;
+ int wm_command_count = 0;
XGetCommand(dpy, theWindow->w,
&wm_command, &wm_command_count);
if (wm_command_count == ptr->wm_command_count) {
+ int i;
+
for (i = 0; i < wm_command_count; i++)
if (strcmp(wm_command[i],
ptr->wm_command[i]) != 0)
diff --git a/src/session.h b/src/session.h
index 3b93fb7..c574a45 100644
--- a/src/session.h
+++ b/src/session.h
@@ -25,6 +25,9 @@
*/
#ifndef _SESSION_H
#define _SESSION_H
+
+#include "twm.h"
+
#include <X11/SM/SMlib.h>
extern void ConnectToSessionManager(char *previous_id);
diff --git a/src/twm.c b/src/twm.c
index d9a8f6c..2abb603 100644
--- a/src/twm.c
+++ b/src/twm.c
@@ -62,12 +62,13 @@ in this Software without prior written authorization from The Open Group.
#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
+#include <stdarg.h>
+
#include "twm.h"
#include "iconmgr.h"
#include "add_window.h"
#include "gc.h"
#include "parse.h"
-#include "version.h"
#include "menus.h"
#include "events.h"
#include "util.h"
@@ -75,6 +76,7 @@ in this Software without prior written authorization from The Open Group.
#include "screen.h"
#include "parse.h"
#include "session.h"
+
#include <X11/Xproto.h>
#include <X11/Xatom.h>
#include <X11/SM/SMlib.h>
@@ -115,7 +117,7 @@ ScreenInfo **ScreenList; /* structures for each screen */
ScreenInfo *Scr = NULL; /* the cur and prev screens */
int PreviousScreen; /* last screen that we were on */
int FirstScreen; /* TRUE ==> first screen of display */
-static Bool PrintErrorMessages = False; /* controls error messages */
+int message_level = 1; /* controls error messages */
static int RedirectError; /* TRUE ==> another window manager running */
static int TwmErrorHandler(Display *dpy, XErrorEvent *event); /* for settting RedirectError */
static int CatchRedirectError(Display *dpy, XErrorEvent *event); /* for everything else */
@@ -181,33 +183,31 @@ static char *atom_names[11] = {
#ifdef XPRINT
/* |hasExtension()| and |IsPrintScreen()| have been stolen from
* xc/programs/xdpyinfo/xdpyinfo.c */
-static
- Bool
-hasExtension(Display *dpy, char *extname)
+static Bool
+hasExtension(Display *dpy2, char *extname)
{
int num_extensions, i;
char **extensions;
- extensions = XListExtensions(dpy, &num_extensions);
+ extensions = XListExtensions(dpy2, &num_extensions);
for (i = 0; i < num_extensions &&
(strcmp(extensions[i], extname) != 0); i++);
XFreeExtensionList(extensions);
return i != num_extensions;
}
-static
- Bool
+static Bool
IsPrintScreen(Screen *s)
{
- Display *dpy = XDisplayOfScreen(s);
- int i;
+ Display *dpy2 = XDisplayOfScreen(s);
/* Check whether this is a screen of a print DDX */
- if (hasExtension(dpy, XP_PRINTNAME)) {
+ if (hasExtension(dpy2, XP_PRINTNAME)) {
Screen **pscreens;
int pscrcount;
+ int i;
- pscreens = XpQueryScreens(dpy, &pscrcount);
+ pscreens = XpQueryScreens(dpy2, &pscrcount);
for (i = 0; (i < pscrcount) && pscreens; i++) {
if (s == pscreens[i]) {
return True;
@@ -219,6 +219,31 @@ IsPrintScreen(Screen *s)
}
#endif /* XPRINT */
+static void
+usage(void)
+{
+ fprintf(stderr, "usage: %s [-display dpy] [-f file] [-s] [-q] [-v] [-V]"
+#ifdef XPRINT
+ " [-noprint]"
+#endif /* XPRINT */
+ " [-clientId id] [-restore file]\n", ProgramName);
+ exit(EXIT_FAILURE);
+}
+
+static Bool
+brief_opt(const char *param, const char *option)
+{
+ size_t have = strlen(++param);
+ size_t want = strlen(option);
+ Bool result = False;
+
+ if (have <= want) {
+ if (!strncmp(param, option, have))
+ result = True;
+ }
+ return result;
+}
+
/***********************************************************************
*
* Procedure:
@@ -249,57 +274,62 @@ main(int argc, char *argv[])
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
+ case 'V':
+ printf("%s %s\n", APP_NAME, APP_VERSION);
+ exit(EXIT_SUCCESS);
case 'd': /* -display dpy */
- if (strcmp(&argv[i][1], "display"))
- goto usage;
+ if (!brief_opt(argv[i], "display"))
+ usage();
if (++i >= argc)
- goto usage;
+ usage();
display_name = argv[i];
continue;
case 's': /* -single */
+ if (!brief_opt(argv[i], "single"))
+ usage();
MultiScreen = FALSE;
continue;
#ifdef XPRINT
case 'n': /* -noprint */
- if (strcmp(&argv[i][1], "noprint"))
- goto usage;
+ if (!brief_opt(argv[i], "noprint"))
+ usage();
NoPrintscreens = True;
continue;
#endif /* XPRINT */
case 'f': /* -file twmrcfilename */
+ if (!brief_opt(argv[i], "file"))
+ usage();
if (++i >= argc)
- goto usage;
+ usage();
InitFile = argv[i];
continue;
case 'v': /* -verbose */
- PrintErrorMessages = True;
+ if (!brief_opt(argv[i], "verbose"))
+ usage();
+ message_level++;
continue;
case 'c': /* -clientId */
- if (strcmp(&argv[i][1], "clientId"))
- goto usage;
+ if (!brief_opt(argv[i], "clientId"))
+ usage();
if (++i >= argc)
- goto usage;
+ usage();
client_id = argv[i];
continue;
case 'r': /* -restore */
- if (strcmp(&argv[i][1], "restore"))
- goto usage;
+ if (!brief_opt(argv[i], "restore"))
+ usage();
if (++i >= argc)
- goto usage;
+ usage();
restore_filename = argv[i];
continue;
case 'q': /* -quiet */
- PrintErrorMessages = False;
+ if (!brief_opt(argv[i], "quiet"))
+ usage();
+ --message_level;
continue;
}
}
- usage:
- fprintf(stderr, "usage: %s [-display dpy] [-f file] [-s] [-q] [-v]"
-#ifdef XPRINT
- " [-noprint]"
-#endif /* XPRINT */
- " [-clientId id] [-restore file]\n", ProgramName);
- exit(1);
+ usage();
}
loc = setlocale(LC_ALL, "");
@@ -350,16 +380,11 @@ main(int argc, char *argv[])
if (!(dpy = XtOpenDisplay(appContext, display_name, "twm", "twm",
NULL, 0, &zero, NULL))) {
- fprintf(stderr, "%s: unable to open display \"%s\"\n",
- ProgramName, XDisplayName(display_name));
- exit(1);
+ twmError("unable to open display \"%s\"", XDisplayName(display_name));
}
if (fcntl(ConnectionNumber(dpy), F_SETFD, 1) == -1) {
- fprintf(stderr,
- "%s: unable to mark display connection as close-on-exec\n",
- ProgramName);
- exit(1);
+ twmError("unable to mark display connection as close-on-exec");
}
if (restore_filename)
@@ -396,10 +421,7 @@ main(int argc, char *argv[])
/* for simplicity, always allocate NumScreens ScreenInfo struct pointers */
ScreenList = calloc((size_t) NumScreens, sizeof(ScreenInfo *));
if (ScreenList == NULL) {
- fprintf(stderr,
- "%s: Unable to allocate memory for screen list, exiting.\n",
- ProgramName);
- exit(1);
+ twmError("Unable to allocate memory for screen list, exiting");
}
numManaged = 0;
PreviousScreen = DefaultScreen(dpy);
@@ -409,8 +431,7 @@ main(int argc, char *argv[])
/* Ignore print screens to avoid that users accidentally warp on a
* print screen (which are not visible on video displays) */
if ((!NoPrintscreens) && IsPrintScreen(XScreenOfDisplay(dpy, scrnum))) {
- fprintf(stderr, "%s: skipping print screen %d\n",
- ProgramName, scrnum);
+ twmWarning("skipping print screen %d", scrnum);
continue;
}
#endif /* XPRINT */
@@ -428,12 +449,13 @@ main(int argc, char *argv[])
XSetErrorHandler(TwmErrorHandler);
if (RedirectError) {
- fprintf(stderr, "%s: another window manager is already running.",
- ProgramName);
- if (MultiScreen && NumScreens > 0)
- fprintf(stderr, " on screen %d?\n", scrnum);
- else
- fprintf(stderr, "?\n");
+ if (MultiScreen && NumScreens > 0) {
+ twmWarning("another window manager is already running."
+ " on screen %d?\n", scrnum);
+ }
+ else {
+ twmWarning("another window manager is already running.");
+ }
continue;
}
@@ -442,9 +464,9 @@ main(int argc, char *argv[])
/* Note: ScreenInfo struct is calloc'ed to initialize to zero. */
Scr = ScreenList[scrnum] = calloc(1, sizeof(ScreenInfo));
if (Scr == NULL) {
- fprintf(stderr,
- "%s: unable to allocate memory for ScreenInfo structure for screen %d.\n",
- ProgramName, scrnum);
+ twmWarning
+ ("unable to allocate memory for ScreenInfo structure for screen %d.",
+ scrnum);
continue;
}
@@ -677,10 +699,11 @@ main(int argc, char *argv[])
} /* for */
if (numManaged == 0) {
- if (MultiScreen && NumScreens > 0)
- fprintf(stderr, "%s: unable to find any unmanaged %sscreens.\n",
- ProgramName, NoPrintscreens ? "" : "video ");
- exit(1);
+ if (MultiScreen && NumScreens > 0) {
+ twmError("unable to find any unmanaged %sscreens.\n",
+ NoPrintscreens ? "" : "video ");
+ }
+ exit(EXIT_FAILURE);
}
(void) ConnectToSessionManager(client_id);
@@ -689,7 +712,7 @@ main(int argc, char *argv[])
HandlingEvents = TRUE;
InitEvents();
HandleEvents();
- exit(0);
+ exit(EXIT_SUCCESS);
}
/**
@@ -860,11 +883,12 @@ void
RestoreWithdrawnLocation(TwmWindow *tmp)
{
int gravx, gravy;
- unsigned int bw, mask;
+ unsigned int bw;
XWindowChanges xwc;
if (XGetGeometry(dpy, tmp->w, &JunkRoot, &xwc.x, &xwc.y,
&JunkWidth, &JunkHeight, &bw, &JunkDepth)) {
+ unsigned mask;
GetGravityOffsets(tmp, &gravx, &gravy);
if (gravy < 0)
@@ -945,7 +969,7 @@ Done(XtPointer client_data _X_UNUSED, XtSignalId *si2 _X_UNUSED)
Reborder(CurrentTime);
XCloseDisplay(dpy);
}
- exit(0);
+ exit(EXIT_SUCCESS);
}
/*
@@ -963,7 +987,7 @@ TwmErrorHandler(Display *dpy2, XErrorEvent *event)
LastErrorEvent = *event;
ErrorOccurred = True;
- if (PrintErrorMessages && /* don't be too obnoxious */
+ if ((message_level > 1) && /* don't be too obnoxious */
event->error_code != BadWindow && /* watch for dead puppies */
(event->request_code != X_GetGeometry && /* of all styles */
event->error_code != BadDrawable))
@@ -979,3 +1003,58 @@ CatchRedirectError(Display *dpy2 _X_UNUSED, XErrorEvent *event)
ErrorOccurred = True;
return 0;
}
+
+void
+twmError(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ fprintf(stderr, "%s: error: ", ProgramName);
+ vfprintf(stderr, format, ap);
+ fputc('\n', stderr);
+ va_end(ap);
+ exit(EXIT_FAILURE);
+}
+
+void
+twmWarning(const char *format, ...)
+{
+ if (message_level > 0) {
+ va_list ap;
+
+ va_start(ap, format);
+ fprintf(stderr, "%s: warning: ", ProgramName);
+ vfprintf(stderr, format, ap);
+ fputc('\n', stderr);
+ va_end(ap);
+ }
+}
+
+void
+twmVerbose(const char *format, ...)
+{
+ if (message_level > 1) {
+ va_list ap;
+
+ va_start(ap, format);
+ fprintf(stderr, "%s: warning: ", ProgramName);
+ vfprintf(stderr, format, ap);
+ fputc('\n', stderr);
+ va_end(ap);
+ }
+}
+
+void
+twmMessage(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ printf("%s: ", ProgramName);
+ vprintf(format, ap);
+ putc('\n', stdout);
+ va_end(ap);
+
+ fflush(stdout);
+}
diff --git a/src/twm.h b/src/twm.h
index 1fe106d..2428391 100644
--- a/src/twm.h
+++ b/src/twm.h
@@ -60,6 +60,7 @@ from The Open Group.
#ifndef _TWM_
#define _TWM_
+/* *INDENT-OFF* */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -73,6 +74,18 @@ from The Open Group.
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
+#ifndef GCC_PRINTFLIKE
+#if defined(GCC_PRINTF) && !defined(printf)
+#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
+#else
+#define GCC_PRINTFLIKE(fmt,var) /*nothing*/
+#endif
+#endif
+
+#ifndef GCC_NORETURN
+#define GCC_NORETURN _X_NORETURN
+#endif
+
#ifndef WithdrawnState
#define WithdrawnState 0
#endif
@@ -335,8 +348,7 @@ extern void CreateFonts(void);
extern void RestoreWithdrawnLocation(TwmWindow *tmp);
extern void Reborder(Time time);
extern void
-Done(XtPointer, XtSignalId *)
- _X_NORETURN;
+Done(XtPointer, XtSignalId *) _X_NORETURN;
extern void
ComputeCommonTitleOffsets(void);
extern void
@@ -392,6 +404,11 @@ NewBitmapCursor(Cursor *cp, char *source, char *mask);
extern Pixmap
CreateMenuIcon(int height, unsigned int *widthp, unsigned int *heightp);
+extern void twmError(const char *, ...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
+extern void twmWarning(const char *, ...) GCC_PRINTFLIKE(1,2);
+extern void twmVerbose(const char *, ...) GCC_PRINTFLIKE(1,2);
+extern void twmMessage(const char *, ...) GCC_PRINTFLIKE(1,2);
+
extern Bool ErrorOccurred;
extern XErrorEvent LastErrorEvent;
@@ -401,16 +418,16 @@ extern Bool RestartPreviousState;
extern Bool
GetWMState(Window w, int *statep, Window *iwp);
-extern void
-twmrc_error_prefix(void);
-
extern int
yyparse(void);
extern int
yylex(void);
+extern void parseWarning(const char *, ...) GCC_PRINTFLIKE(1,2);
+
extern Atom TwmAtoms[];
+extern int message_level;
extern Bool use_fontset;
extern int ShapeEventBase;
@@ -433,4 +450,5 @@ extern int XrandrErrorBase;
#define _XA_WM_CLIENT_LEADER TwmAtoms[9]
#define _XA_WM_WINDOW_ROLE TwmAtoms[10]
+/* *INDENT-ON* */
#endif /* _TWM_ */
diff --git a/src/util.c b/src/util.c
index c4e0a3f..a6bf902 100644
--- a/src/util.c
+++ b/src/util.c
@@ -260,10 +260,9 @@ ExpandFilename(const char *name)
retval = asprintf(&newname, "%s/%s", Home, &name[1]);
if (retval == -1 || !newname) {
- fprintf (stderr,
- "%s: unable to allocate %ld bytes to expand filename %s/%s\n",
- ProgramName, (unsigned long)HomeLen + (unsigned long)strlen(name) + 2,
- Home, &name[1]);
+ twmWarning("unable to allocate %lu bytes to expand filename %s/%s",
+ (unsigned long) HomeLen + (unsigned long) strlen(name) + 2,
+ Home, &name[1]);
}
return newname;
}
@@ -327,8 +326,7 @@ FindBitmap(const char *name, unsigned *widthp, unsigned *heightp)
if (XmuCompareISOLatin1(pmtab[i].name, name) == 0)
return (*pmtab[i].proc) (widthp, heightp);
}
- fprintf(stderr, "%s: no such built-in bitmap \"%s\"\n",
- ProgramName, name);
+ twmWarning("no such built-in bitmap \"%s\"", name);
return None;
}
@@ -353,9 +351,8 @@ FindBitmap(const char *name, unsigned *widthp, unsigned *heightp)
*/
asprintf(&bigname, "%s/%s", Scr->IconDirectory, name);
if (!bigname) {
- fprintf (stderr,
- "%s: unable to allocate memory for \"%s/%s\"\n",
- ProgramName, Scr->IconDirectory, name);
+ twmWarning("unable to allocate memory for \"%s/%s\"",
+ Scr->IconDirectory, name);
return None;
}
if (XReadBitmapFile (dpy, Scr->Root, bigname, widthp, heightp, &pm,
@@ -365,8 +362,7 @@ FindBitmap(const char *name, unsigned *widthp, unsigned *heightp)
}
free (bigname);
if (pm == None) {
- fprintf(stderr, "%s: unable to find bitmap \"%s\"\n",
- ProgramName, name);
+ twmWarning("unable to find bitmap \"%s\"", name);
}
return pm;
@@ -393,8 +389,8 @@ InsertRGBColormap(Atom a, XStandardColormap *maps, int nmaps, Bool replace)
if (!sc) { /* no existing, allocate new */
sc = malloc(sizeof(StdCmap));
if (!sc) {
- fprintf(stderr, "%s: unable to allocate %ld bytes for StdCmap\n",
- ProgramName, (unsigned long) sizeof(StdCmap));
+ twmWarning("unable to allocate %lu bytes for StdCmap",
+ (unsigned long) sizeof(StdCmap));
return;
}
replace = False;
@@ -496,8 +492,7 @@ GetColor(int kind, Pixel *what, const char *name)
if (name[0] != '#')
stat = XParseColor(dpy, cmap, name, &color);
if (!stat) {
- fprintf(stderr, "%s: invalid color name \"%s\"\n",
- ProgramName, name);
+ twmWarning("invalid color name \"%s\"", name);
return;
}
@@ -540,8 +535,7 @@ GetColor(int kind, Pixel *what, const char *name)
stdcmap->blue_mult));
}
else {
- fprintf(stderr, "%s: unable to allocate color \"%s\"\n",
- ProgramName, name);
+ twmWarning("unable to allocate color \"%s\"", name);
return;
}
}
@@ -564,7 +558,7 @@ GetColorValue(int kind, XColor *what, const char *name)
return;
if (!XLookupColor(dpy, cmap, name, what, &junkcolor)) {
- fprintf(stderr, "%s: invalid color name \"%s\"\n", ProgramName, name);
+ twmWarning("invalid color name \"%s\"", name);
}
else {
what->pixel = AllPlanes;
@@ -580,12 +574,13 @@ FindFontSet(MyFont *font, const char *fontname)
XFontSetExtents *font_extents;
XFontStruct **xfonts;
char **font_names;
- register int i;
- int ascent;
- int descent;
- int fnum;
if (use_fontset) {
+ int ascent;
+ int descent;
+ int fnum;
+ register int i;
+
if (font->fontset != NULL) {
XFreeFontSet(dpy, font->fontset);
}
@@ -596,9 +591,13 @@ FindFontSet(MyFont *font, const char *fontname)
&def_string_return)) == NULL) {
return False;
}
- for (i = 0; i < missing_charset_count_return; i++) {
- printf("%s: warning: font for charset %s is lacking.\n",
- ProgramName, missing_charset_list_return[i]);
+ if (missing_charset_count_return) {
+ twmVerbose("%d fonts are missing from fontset",
+ missing_charset_count_return);
+ for (i = 0; i < missing_charset_count_return; i++) {
+ twmVerbose("font for charset %s is lacking.",
+ missing_charset_list_return[i]);
+ }
}
font_extents = XExtentsOfFontSet(font->fontset);
@@ -614,6 +613,9 @@ FindFontSet(MyFont *font, const char *fontname)
font->y = ascent;
font->ascent = ascent;
font->descent = descent;
+ twmMessage("created fontset with %d fonts (%d missing) for \"%s\"",
+ fnum, missing_charset_count_return,
+ fontname ? fontname : "NULL");
return True;
}
@@ -643,10 +645,10 @@ FindFontSet(MyFont *font, const char *fontname)
void
GetFont(MyFont *font)
{
- const char *deffontname = "fixed";
if (!FindFontSet(font, font->name)) {
const char *what = "fonts";
+ const char *deffontname = "fixed";
if (use_fontset) {
what = "fontsets";
@@ -655,9 +657,8 @@ GetFont(MyFont *font)
deffontname = Scr->DefaultFont.name;
}
if (!FindFontSet(font, deffontname)) {
- fprintf(stderr, "%s: unable to open %s \"%s\" or \"%s\"\n",
- ProgramName, what, font->name, deffontname);
- exit(1);
+ twmError("unable to open %s \"%s\" or \"%s\"",
+ what, font->name, deffontname);
}
}
}
@@ -724,23 +725,38 @@ I18N_FetchName(Display *dpy2, Window w, char **winname)
{
int status;
XTextProperty text_prop;
- char **list;
- int num;
+ int rc = 0;
+
+ *winname = NULL;
status = XGetWMName(dpy2, w, &text_prop);
- if (!status || !text_prop.value || !text_prop.nitems) {
- *winname = NULL;
- return 0;
- }
- status = XmbTextPropertyToTextList(dpy2, &text_prop, &list, &num);
- if (status < Success || !num || !*list) {
- *winname = NULL;
- return 0;
+ if (status && text_prop.value && text_prop.nitems) {
+ char **list = NULL;
+ int num;
+
+ status = XmbTextPropertyToTextList(dpy2, &text_prop, &list, &num);
+ if (status >= Success && num && list && *list) {
+ XFree(text_prop.value);
+ *winname = strdup(*list);
+ XFreeStringList(list);
+ rc = 1;
+ }
+ else {
+ char *value = NULL;
+
+ /*
+ * If the system's locale support is broken (e.g., missing useful
+ * parts), the preceding Xmb call may fail.
+ */
+ if (XFetchName(dpy2, w, &value) && value != NULL) {
+ *winname = strdup(value);
+ XFree(value);
+ rc = 1;
+ }
+ }
}
- XFree(text_prop.value);
- *winname = (char *) strdup(*list);
- XFreeStringList(list);
- return 1;
+
+ return rc;
}
Status
@@ -774,11 +790,11 @@ SetFocus(TwmWindow *tmp_win, Time time)
#ifdef TRACE
if (tmp_win) {
- printf("Focusing on window \"%s\"\n", tmp_win->full_name);
+ twmMessage("Focusing on window \"%s\"", tmp_win->full_name);
}
else {
- printf("Unfocusing; Scr->Focus was \"%s\"\n",
- Scr->Focus ? Scr->Focus->full_name : "(nil)");
+ twmMessage("Unfocusing; Scr->Focus was \"%s\"",
+ Scr->Focus ? Scr->Focus->full_name : "(nil)");
}
#endif
@@ -947,15 +963,6 @@ Pixmap
CreateMenuIcon(int height, unsigned *widthp, unsigned *heightp)
{
int h, w;
- int ih, iw;
- int ix, iy;
- int mh, mw;
- int tw, th;
- int lw, lh;
- int lx, ly;
- int lines, dly;
- int off;
- int bw;
h = height;
w = h * 7 / 8;
@@ -968,6 +975,15 @@ CreateMenuIcon(int height, unsigned *widthp, unsigned *heightp)
if (Scr->tbpm.menu == None) {
Pixmap pix;
GC gc;
+ int ih, iw;
+ int ix, iy;
+ int mh, mw;
+ int tw, th;
+ int lw, lh;
+ int lx, ly;
+ int lines, dly;
+ int off;
+ int bw;
pix = Scr->tbpm.menu =
XCreatePixmap(dpy, Scr->Root, (unsigned) w, (unsigned) h, 1);
diff --git a/src/util.h b/src/util.h
index 195432c..448ed4d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -60,6 +60,8 @@ in this Software without prior written authorization from The Open Group.
#ifndef _UTIL_
#define _UTIL_
+#include "twm.h"
+
extern void MoveOutline(Window root, int x, int y, int width, int height,
int bw, int th);
extern void Zoom(Window wf, Window wt);