2010-08-22 07:38:11 -06:00
|
|
|
/* $XTermId: scrollbar.c,v 1.173 2010/06/15 22:47:34 tom Exp $ */
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
/*
|
2010-05-08 06:20:46 -06:00
|
|
|
* Copyright 2000-2009,2010 by Thomas E. Dickey
|
2006-11-26 04:11:12 -07:00
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Except as contained in this notice, the name(s) of the above copyright
|
|
|
|
* holders shall not be used in advertising or otherwise to promote the
|
|
|
|
* sale, use or other dealings in this Software without prior written
|
|
|
|
* authorization.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
|
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software and its
|
|
|
|
* documentation for any purpose and without fee is hereby granted,
|
|
|
|
* provided that the above copyright notice appear in all copies and that
|
|
|
|
* both that copyright notice and this permission notice appear in
|
|
|
|
* supporting documentation, and that the name of Digital Equipment
|
|
|
|
* Corporation not be used in advertising or publicity pertaining to
|
|
|
|
* distribution of the software without specific, written prior permission.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
* DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
|
|
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <xterm.h>
|
|
|
|
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
|
|
|
#if defined(HAVE_LIB_XAW)
|
|
|
|
#include <X11/Xaw/Scrollbar.h>
|
|
|
|
#elif defined(HAVE_LIB_XAW3D)
|
|
|
|
#include <X11/Xaw3d/Scrollbar.h>
|
|
|
|
#elif defined(HAVE_LIB_NEXTAW)
|
|
|
|
#include <X11/neXtaw/Scrollbar.h>
|
|
|
|
#elif defined(HAVE_LIB_XAWPLUS)
|
|
|
|
#include <X11/XawPlus/Scrollbar.h>
|
|
|
|
#endif
|
|
|
|
|
2010-05-08 06:20:46 -06:00
|
|
|
#if defined(HAVE_XKBQUERYEXTENSION) && defined(HAVE_X11_XKBLIB_H) && defined(HAVE_X11_EXTENSIONS_XKB_H)
|
|
|
|
#include <X11/extensions/XKB.h>
|
|
|
|
#include <X11/XKBlib.h>
|
|
|
|
#else
|
|
|
|
#undef HAVE_XKBQUERYEXTENSION
|
|
|
|
#endif
|
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
#include <data.h>
|
|
|
|
#include <error.h>
|
|
|
|
#include <menu.h>
|
|
|
|
#include <xcharmouse.h>
|
2009-01-06 13:10:20 -07:00
|
|
|
#include <xstrings.h>
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The scrollbar's border overlaps the border of the vt100 window. If there
|
|
|
|
* is no border for the vt100, there can be no border for the scrollbar.
|
|
|
|
*/
|
2009-03-09 16:13:04 -06:00
|
|
|
#define SCROLLBAR_BORDER(xw) (TScreenOf(xw)->scrollBarBorder)
|
2006-11-26 04:11:12 -07:00
|
|
|
#if OPT_TOOLBAR
|
|
|
|
#define ScrollBarBorder(xw) (BorderWidth(xw) ? SCROLLBAR_BORDER(xw) : 0)
|
|
|
|
#else
|
|
|
|
#define ScrollBarBorder(xw) SCROLLBAR_BORDER(xw)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Event handlers */
|
|
|
|
|
|
|
|
static void ScrollTextTo PROTO_XT_CALLBACK_ARGS;
|
|
|
|
static void ScrollTextUpDownBy PROTO_XT_CALLBACK_ARGS;
|
|
|
|
|
|
|
|
/* Resize the text window for a terminal screen, modifying the
|
|
|
|
* appropriate WM_SIZE_HINTS and taking advantage of bit gravity.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
DoResizeScreen(XtermWidget xw)
|
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2009-03-09 16:13:04 -06:00
|
|
|
int border = 2 * screen->border;
|
|
|
|
int min_wide = border + screen->fullVwin.sb_info.width;
|
2006-11-26 04:11:12 -07:00
|
|
|
int min_high = border;
|
|
|
|
XtGeometryResult geomreqresult;
|
|
|
|
Dimension reqWidth, reqHeight, repWidth, repHeight;
|
|
|
|
#ifndef NO_ACTIVE_ICON
|
2007-06-15 13:29:55 -06:00
|
|
|
VTwin *saveWin = WhichVWin(screen);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
/* all units here want to be in the normal font units */
|
|
|
|
WhichVWin(screen) = &screen->fullVwin;
|
|
|
|
#endif /* NO_ACTIVE_ICON */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I'm going to try to explain, as I understand it, why we
|
|
|
|
* have to do XGetWMNormalHints and XSetWMNormalHints here,
|
|
|
|
* although I can't guarantee that I've got it right.
|
|
|
|
*
|
|
|
|
* In a correctly written toolkit program, the Shell widget
|
|
|
|
* parses the user supplied geometry argument. However,
|
|
|
|
* because of the way xterm does things, the VT100 widget does
|
|
|
|
* the parsing of the geometry option, not the Shell widget.
|
|
|
|
* The result of this is that the Shell widget doesn't set the
|
|
|
|
* correct window manager hints, and doesn't know that the
|
|
|
|
* user has specified a geometry.
|
|
|
|
*
|
|
|
|
* The XtVaSetValues call below tells the Shell widget to
|
|
|
|
* change its hints. However, since it's confused about the
|
|
|
|
* hints to begin with, it doesn't get them all right when it
|
|
|
|
* does the SetValues -- it undoes some of what the VT100
|
|
|
|
* widget did when it originally set the hints.
|
|
|
|
*
|
|
|
|
* To fix this, we do the following:
|
|
|
|
*
|
|
|
|
* 1. Get the sizehints directly from the window, going around
|
|
|
|
* the (confused) shell widget.
|
|
|
|
* 2. Call XtVaSetValues to let the shell widget know which
|
|
|
|
* hints have changed. Note that this may not even be
|
|
|
|
* necessary, since we're going to right ahead after that
|
|
|
|
* and set the hints ourselves, but it's good to put it
|
|
|
|
* here anyway, so that when we finally do fix the code so
|
|
|
|
* that the Shell does the right thing with hints, we
|
|
|
|
* already have the XtVaSetValues in place.
|
|
|
|
* 3. We set the sizehints directly, this fixing up whatever
|
|
|
|
* damage was done by the Shell widget during the
|
|
|
|
* XtVaSetValues.
|
|
|
|
*
|
|
|
|
* Gross, huh?
|
|
|
|
*
|
|
|
|
* The correct fix is to redo VTRealize, VTInitialize and
|
|
|
|
* VTSetValues so that font processing happens early enough to
|
|
|
|
* give back responsibility for the size hints to the Shell.
|
|
|
|
*
|
|
|
|
* Someday, we hope to have time to do this. Someday, we hope
|
|
|
|
* to have time to completely rewrite xterm.
|
|
|
|
*/
|
|
|
|
|
|
|
|
TRACE(("DoResizeScreen\n"));
|
|
|
|
|
|
|
|
#if 1 /* ndef nothack */
|
|
|
|
/*
|
|
|
|
* NOTE: the hints and the XtVaSetValues() must match.
|
|
|
|
*/
|
|
|
|
TRACE(("%s@%d -- ", __FILE__, __LINE__));
|
|
|
|
TRACE_WM_HINTS(xw);
|
2007-06-15 13:29:55 -06:00
|
|
|
getXtermSizeHints(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
xtermSizeHints(xw, ScrollbarWidth(screen));
|
|
|
|
|
|
|
|
/* These are obsolete, but old clients may use them */
|
|
|
|
xw->hints.width = MaxCols(screen) * FontWidth(screen) + xw->hints.min_width;
|
|
|
|
xw->hints.height = MaxRows(screen) * FontHeight(screen) + xw->hints.min_height;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
XSetWMNormalHints(screen->display, XtWindow(SHELL_OF(xw)), &xw->hints);
|
|
|
|
|
2009-03-09 16:13:04 -06:00
|
|
|
reqWidth = (Dimension) (MaxCols(screen) * FontWidth(screen) + min_wide);
|
|
|
|
reqHeight = (Dimension) (MaxRows(screen) * FontHeight(screen) + min_high);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
TRACE(("...requesting screensize chars %dx%d, pixels %dx%d\n",
|
|
|
|
MaxRows(screen),
|
|
|
|
MaxCols(screen),
|
|
|
|
reqHeight, reqWidth));
|
|
|
|
|
2008-08-25 12:05:56 -06:00
|
|
|
geomreqresult = REQ_RESIZE((Widget) xw, reqWidth, reqHeight,
|
|
|
|
&repWidth, &repHeight);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
if (geomreqresult == XtGeometryAlmost) {
|
|
|
|
TRACE(("...almost, retry screensize %dx%d\n", repHeight, repWidth));
|
2008-08-25 12:05:56 -06:00
|
|
|
geomreqresult = REQ_RESIZE((Widget) xw, repWidth,
|
|
|
|
repHeight, NULL, NULL);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
2008-03-19 15:15:46 -06:00
|
|
|
|
|
|
|
if (geomreqresult != XtGeometryYes) {
|
|
|
|
/* The resize wasn't successful, so we might need to adjust
|
|
|
|
our idea of how large the screen is. */
|
|
|
|
TRACE(("...still no (%d) - resize the core-class\n", geomreqresult));
|
|
|
|
xw->core.widget_class->core_class.resize((Widget) xw);
|
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
#if 1 /* ndef nothack */
|
|
|
|
/*
|
|
|
|
* XtMakeResizeRequest() has the undesirable side-effect of clearing
|
|
|
|
* the window manager's hints, even on a failed request. This would
|
|
|
|
* presumably be fixed if the shell did its own work.
|
|
|
|
*/
|
|
|
|
if (xw->hints.flags
|
|
|
|
&& repHeight
|
|
|
|
&& repWidth) {
|
|
|
|
xw->hints.height = repHeight;
|
|
|
|
xw->hints.width = repWidth;
|
|
|
|
TRACE_HINTS(&xw->hints);
|
|
|
|
XSetWMNormalHints(screen->display, VShellWindow, &xw->hints);
|
|
|
|
}
|
|
|
|
#endif
|
2007-06-15 13:29:55 -06:00
|
|
|
XSync(screen->display, False); /* synchronize */
|
2006-11-26 04:11:12 -07:00
|
|
|
if (XtAppPending(app_con))
|
|
|
|
xevents();
|
|
|
|
|
|
|
|
#ifndef NO_ACTIVE_ICON
|
|
|
|
WhichVWin(screen) = saveWin;
|
|
|
|
#endif /* NO_ACTIVE_ICON */
|
|
|
|
}
|
|
|
|
|
|
|
|
static Widget
|
|
|
|
CreateScrollBar(XtermWidget xw, int x, int y, int height)
|
|
|
|
{
|
|
|
|
Widget result;
|
|
|
|
Arg args[6];
|
|
|
|
|
|
|
|
XtSetArg(args[0], XtNx, x);
|
|
|
|
XtSetArg(args[1], XtNy, y);
|
|
|
|
XtSetArg(args[2], XtNheight, height);
|
|
|
|
XtSetArg(args[3], XtNreverseVideo, xw->misc.re_verse);
|
|
|
|
XtSetArg(args[4], XtNorientation, XtorientVertical);
|
|
|
|
XtSetArg(args[5], XtNborderWidth, ScrollBarBorder(xw));
|
|
|
|
|
|
|
|
result = XtCreateWidget("scrollbar", scrollbarWidgetClass,
|
|
|
|
(Widget) xw, args, XtNumber(args));
|
|
|
|
XtAddCallback(result, XtNscrollProc, ScrollTextUpDownBy, 0);
|
|
|
|
XtAddCallback(result, XtNjumpProc, ScrollTextTo, 0);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScrollBarReverseVideo(Widget scrollWidget)
|
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
XtermWidget xw = getXtermWidget(scrollWidget);
|
2007-06-15 13:29:55 -06:00
|
|
|
|
|
|
|
if (xw != 0) {
|
2009-03-09 16:13:04 -06:00
|
|
|
SbInfo *sb = &(TScreenOf(xw)->fullVwin.sb_info);
|
2007-06-15 13:29:55 -06:00
|
|
|
Arg args[4];
|
|
|
|
Cardinal nargs = XtNumber(args);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remember the scrollbar's original colors.
|
|
|
|
*/
|
|
|
|
if (sb->rv_cached == False) {
|
|
|
|
XtSetArg(args[0], XtNbackground, &(sb->bg));
|
|
|
|
XtSetArg(args[1], XtNforeground, &(sb->fg));
|
|
|
|
XtSetArg(args[2], XtNborderColor, &(sb->bdr));
|
|
|
|
XtSetArg(args[3], XtNborderPixmap, &(sb->bdpix));
|
|
|
|
XtGetValues(scrollWidget, args, nargs);
|
|
|
|
sb->rv_cached = True;
|
|
|
|
sb->rv_active = 0;
|
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
sb->rv_active = !(sb->rv_active);
|
|
|
|
XtSetArg(args[!(sb->rv_active)], XtNbackground, sb->bg);
|
|
|
|
XtSetArg(args[(sb->rv_active)], XtNforeground, sb->fg);
|
|
|
|
nargs = 2; /* don't set border_pixmap */
|
|
|
|
if (sb->bdpix == XtUnspecifiedPixmap) {
|
|
|
|
/* if not pixmap then pixel */
|
|
|
|
if (sb->rv_active) {
|
|
|
|
/* keep border visible */
|
|
|
|
XtSetArg(args[2], XtNborderColor, args[1].value);
|
|
|
|
} else {
|
|
|
|
XtSetArg(args[2], XtNborderColor, sb->bdr);
|
|
|
|
}
|
|
|
|
nargs = 3;
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
2007-06-15 13:29:55 -06:00
|
|
|
XtSetValues(scrollWidget, args, nargs);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScrollBarDrawThumb(Widget scrollWidget)
|
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
XtermWidget xw = getXtermWidget(scrollWidget);
|
2007-06-15 13:29:55 -06:00
|
|
|
|
|
|
|
if (xw != 0) {
|
2009-03-09 16:13:04 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2007-06-15 13:29:55 -06:00
|
|
|
int thumbTop, thumbHeight, totalHeight;
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
thumbTop = ROW2INX(screen, screen->savedlines);
|
|
|
|
thumbHeight = MaxRows(screen);
|
|
|
|
totalHeight = thumbHeight + screen->savedlines;
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
XawScrollbarSetThumb(scrollWidget,
|
2010-08-22 07:38:11 -06:00
|
|
|
((float) thumbTop) / (float) totalHeight,
|
|
|
|
((float) thumbHeight) / (float) totalHeight);
|
2007-06-15 13:29:55 -06:00
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ResizeScrollBar(XtermWidget xw)
|
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2008-08-25 12:05:56 -06:00
|
|
|
if (screen->scrollWidget != 0) {
|
|
|
|
int height = screen->fullVwin.height + screen->border * 2;
|
|
|
|
int width = screen->scrollWidget->core.width;
|
|
|
|
int ypos = -ScrollBarBorder(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
#ifdef SCROLLBAR_RIGHT
|
2008-08-25 12:05:56 -06:00
|
|
|
int xpos = ((xw->misc.useRight)
|
|
|
|
? (screen->fullVwin.fullwidth -
|
|
|
|
screen->scrollWidget->core.width -
|
|
|
|
BorderWidth(screen->scrollWidget))
|
|
|
|
: -ScrollBarBorder(xw));
|
2006-11-26 04:11:12 -07:00
|
|
|
#else
|
2008-08-25 12:05:56 -06:00
|
|
|
int xpos = -ScrollBarBorder(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
#endif
|
|
|
|
|
2008-08-25 12:05:56 -06:00
|
|
|
TRACE(("ResizeScrollBar at %d,%d %dx%d\n", ypos, xpos, height, width));
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2008-08-25 12:05:56 -06:00
|
|
|
XtConfigureWidget(
|
|
|
|
screen->scrollWidget,
|
2009-03-09 16:13:04 -06:00
|
|
|
(Position) xpos,
|
|
|
|
(Position) ypos,
|
|
|
|
(Dimension) width,
|
|
|
|
(Dimension) height,
|
2008-08-25 12:05:56 -06:00
|
|
|
BorderWidth(screen->scrollWidget));
|
|
|
|
ScrollBarDrawThumb(screen->scrollWidget);
|
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-08 06:20:46 -06:00
|
|
|
WindowScroll(XtermWidget xw, int top, Bool always GCC_UNUSED)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
int i, lines;
|
|
|
|
int scrolltop, scrollheight, refreshtop;
|
|
|
|
|
2010-05-08 06:20:46 -06:00
|
|
|
#if OPT_SCROLL_LOCK
|
|
|
|
if (screen->allowScrollLock && (screen->scroll_lock && !always)) {
|
|
|
|
if (screen->scroll_dirty) {
|
|
|
|
screen->scroll_dirty = False;
|
|
|
|
ScrnRefresh(xw, 0, 0, MaxRows(screen), MaxCols(screen), False);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (top < -screen->savedlines) {
|
|
|
|
top = -screen->savedlines;
|
|
|
|
} else if (top > 0) {
|
|
|
|
top = 0;
|
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2010-05-08 06:20:46 -06:00
|
|
|
if ((i = screen->topline - top) != 0) {
|
|
|
|
|
|
|
|
if (screen->cursor_state)
|
|
|
|
HideCursor();
|
|
|
|
lines = i > 0 ? i : -i;
|
|
|
|
if (lines > MaxRows(screen))
|
|
|
|
lines = MaxRows(screen);
|
|
|
|
scrollheight = screen->max_row - lines + 1;
|
|
|
|
if (i > 0)
|
|
|
|
refreshtop = scrolltop = 0;
|
|
|
|
else {
|
|
|
|
scrolltop = lines;
|
|
|
|
refreshtop = scrollheight;
|
|
|
|
}
|
|
|
|
scrolling_copy_area(xw, scrolltop, scrollheight, -i);
|
|
|
|
screen->topline = top;
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2010-05-08 06:20:46 -06:00
|
|
|
ScrollSelection(screen, i, True);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2010-05-08 06:20:46 -06:00
|
|
|
XClearArea(
|
|
|
|
screen->display,
|
|
|
|
VWindow(screen),
|
|
|
|
OriginX(screen),
|
|
|
|
OriginY(screen) + refreshtop * FontHeight(screen),
|
|
|
|
(unsigned) Width(screen),
|
|
|
|
(unsigned) (lines * FontHeight(screen)),
|
|
|
|
False);
|
|
|
|
ScrnRefresh(xw, refreshtop, 0, lines, MaxCols(screen), False);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2009-10-31 08:11:57 -06:00
|
|
|
#if OPT_BLINK_CURS || OPT_BLINK_TEXT
|
2010-05-08 06:20:46 -06:00
|
|
|
RestartBlinking(screen);
|
2009-10-31 08:11:57 -06:00
|
|
|
#endif
|
2010-05-08 06:20:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ScrollBarDrawThumb(screen->scrollWidget);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SCROLLBAR_RIGHT
|
|
|
|
/*
|
|
|
|
* Adjust the scrollbar position if we're asked to turn on scrollbars for the
|
|
|
|
* first time (or after resizing) after the xterm is already running. That
|
|
|
|
* makes the window grow after we've initially configured the scrollbar's
|
|
|
|
* position. (There must be a better way).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
updateRightScrollbar(XtermWidget xw)
|
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
if (xw->misc.useRight
|
|
|
|
&& screen->fullVwin.fullwidth < xw->core.width)
|
|
|
|
XtVaSetValues(screen->scrollWidget,
|
|
|
|
XtNx, screen->fullVwin.fullwidth - BorderWidth(screen->scrollWidget),
|
|
|
|
(XtPointer) 0);
|
|
|
|
}
|
|
|
|
#endif
|
2007-06-15 13:29:55 -06:00
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
void
|
2009-09-05 09:58:09 -06:00
|
|
|
ScrollBarOn(XtermWidget xw, Bool init)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
if (screen->fullVwin.sb_info.width || IsIcon(screen))
|
|
|
|
return;
|
|
|
|
|
2009-09-05 09:58:09 -06:00
|
|
|
TRACE(("ScrollBarOn(init %s)\n", BtoS(init)));
|
2006-11-26 04:11:12 -07:00
|
|
|
if (init) { /* then create it only */
|
|
|
|
if (screen->scrollWidget == 0) {
|
|
|
|
/* make it a dummy size and resize later */
|
|
|
|
screen->scrollWidget = CreateScrollBar(xw,
|
|
|
|
-ScrollBarBorder(xw),
|
|
|
|
-ScrollBarBorder(xw),
|
|
|
|
5);
|
|
|
|
if (screen->scrollWidget == NULL) {
|
2010-08-22 07:38:11 -06:00
|
|
|
Bell(xw, XkbBI_MinorError, 0);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!screen->scrollWidget || !XtIsRealized((Widget) xw)) {
|
2010-08-22 07:38:11 -06:00
|
|
|
Bell(xw, XkbBI_MinorError, 0);
|
|
|
|
Bell(xw, XkbBI_MinorError, 0);
|
2006-11-26 04:11:12 -07:00
|
|
|
} else {
|
|
|
|
|
|
|
|
ResizeScrollBar(xw);
|
|
|
|
xtermAddInput(screen->scrollWidget);
|
|
|
|
XtRealizeWidget(screen->scrollWidget);
|
|
|
|
TRACE_TRANS("scrollbar", screen->scrollWidget);
|
|
|
|
|
|
|
|
screen->fullVwin.sb_info.rv_cached = False;
|
|
|
|
|
|
|
|
screen->fullVwin.sb_info.width = (screen->scrollWidget->core.width
|
|
|
|
+ BorderWidth(screen->scrollWidget));
|
|
|
|
|
|
|
|
TRACE(("setting scrollbar width %d = %d + %d\n",
|
|
|
|
screen->fullVwin.sb_info.width,
|
|
|
|
screen->scrollWidget->core.width,
|
|
|
|
BorderWidth(screen->scrollWidget)));
|
|
|
|
|
|
|
|
ScrollBarDrawThumb(screen->scrollWidget);
|
|
|
|
DoResizeScreen(xw);
|
|
|
|
|
|
|
|
#ifdef SCROLLBAR_RIGHT
|
|
|
|
updateRightScrollbar(xw);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
XtMapWidget(screen->scrollWidget);
|
|
|
|
update_scrollbar();
|
|
|
|
if (screen->visbuf) {
|
2007-06-15 13:29:55 -06:00
|
|
|
xtermClear(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
Redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-06-15 13:29:55 -06:00
|
|
|
ScrollBarOff(XtermWidget xw)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2007-06-15 13:29:55 -06:00
|
|
|
|
2006-11-26 04:11:12 -07:00
|
|
|
if (!screen->fullVwin.sb_info.width || IsIcon(screen))
|
|
|
|
return;
|
|
|
|
|
|
|
|
TRACE(("ScrollBarOff\n"));
|
2007-06-15 13:29:55 -06:00
|
|
|
if (XtIsRealized((Widget) xw)) {
|
2006-11-26 04:11:12 -07:00
|
|
|
XtUnmapWidget(screen->scrollWidget);
|
|
|
|
screen->fullVwin.sb_info.width = 0;
|
2007-06-15 13:29:55 -06:00
|
|
|
DoResizeScreen(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
update_scrollbar();
|
|
|
|
if (screen->visbuf) {
|
2007-06-15 13:29:55 -06:00
|
|
|
xtermClear(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
Redraw();
|
|
|
|
}
|
|
|
|
} else {
|
2010-08-22 07:38:11 -06:00
|
|
|
Bell(xw, XkbBI_MinorError, 0);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Toggle the visibility of the scrollbars.
|
|
|
|
*/
|
|
|
|
void
|
2007-06-15 13:29:55 -06:00
|
|
|
ToggleScrollBar(XtermWidget xw)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
if (IsIcon(screen)) {
|
2010-08-22 07:38:11 -06:00
|
|
|
Bell(xw, XkbBI_MinorError, 0);
|
2006-11-26 04:11:12 -07:00
|
|
|
} else {
|
|
|
|
TRACE(("ToggleScrollBar{{\n"));
|
|
|
|
if (screen->fullVwin.sb_info.width) {
|
2007-06-15 13:29:55 -06:00
|
|
|
ScrollBarOff(xw);
|
2006-11-26 04:11:12 -07:00
|
|
|
} else {
|
2009-09-05 09:58:09 -06:00
|
|
|
ScrollBarOn(xw, False);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
update_scrollbar();
|
|
|
|
TRACE(("...ToggleScrollBar}}\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static void
|
|
|
|
ScrollTextTo(
|
2007-06-15 13:29:55 -06:00
|
|
|
Widget scrollbarWidget,
|
2006-11-26 04:11:12 -07:00
|
|
|
XtPointer client_data GCC_UNUSED,
|
|
|
|
XtPointer call_data)
|
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
XtermWidget xw = getXtermWidget(scrollbarWidget);
|
2007-06-15 13:29:55 -06:00
|
|
|
|
|
|
|
if (xw != 0) {
|
|
|
|
float *topPercent = (float *) call_data;
|
2009-03-09 16:13:04 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2007-06-15 13:29:55 -06:00
|
|
|
int thumbTop; /* relative to first saved line */
|
|
|
|
int newTopLine;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* screen->savedlines : Number of offscreen text lines,
|
|
|
|
* MaxRows(screen) : Number of onscreen text lines,
|
|
|
|
*/
|
2010-08-22 07:38:11 -06:00
|
|
|
thumbTop = (int) (*topPercent
|
|
|
|
* (float) (screen->savedlines + MaxRows(screen)));
|
2007-06-15 13:29:55 -06:00
|
|
|
newTopLine = thumbTop - screen->savedlines;
|
2010-05-08 06:20:46 -06:00
|
|
|
WindowScroll(xw, newTopLine, True);
|
2007-06-15 13:29:55 -06:00
|
|
|
}
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static void
|
|
|
|
ScrollTextUpDownBy(
|
2007-06-15 13:29:55 -06:00
|
|
|
Widget scrollbarWidget,
|
2006-11-26 04:11:12 -07:00
|
|
|
XtPointer client_data GCC_UNUSED,
|
|
|
|
XtPointer call_data)
|
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
XtermWidget xw = getXtermWidget(scrollbarWidget);
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
if (xw != 0) {
|
|
|
|
long pixels = (long) call_data;
|
2006-11-26 04:11:12 -07:00
|
|
|
|
2009-03-09 16:13:04 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2007-06-15 13:29:55 -06:00
|
|
|
int rowOnScreen, newTopLine;
|
|
|
|
|
2010-05-08 06:20:46 -06:00
|
|
|
rowOnScreen = (int) (pixels / FontHeight(screen));
|
2007-06-15 13:29:55 -06:00
|
|
|
if (rowOnScreen == 0) {
|
|
|
|
if (pixels < 0)
|
|
|
|
rowOnScreen = -1;
|
|
|
|
else if (pixels > 0)
|
|
|
|
rowOnScreen = 1;
|
|
|
|
}
|
|
|
|
newTopLine = ROW2INX(screen, rowOnScreen);
|
2010-05-08 06:20:46 -06:00
|
|
|
WindowScroll(xw, newTopLine, True);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-01-06 13:10:20 -07:00
|
|
|
* assume that b is alphabetic and allow plural
|
2006-11-26 04:11:12 -07:00
|
|
|
*/
|
|
|
|
static int
|
2009-10-31 08:11:57 -06:00
|
|
|
CompareWidths(const char *a, const char *b, int *modifier)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-01-06 13:10:20 -07:00
|
|
|
int result;
|
2006-11-26 04:11:12 -07:00
|
|
|
char ca, cb;
|
|
|
|
|
|
|
|
*modifier = 0;
|
|
|
|
if (!a || !b)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (1) {
|
2009-01-06 13:10:20 -07:00
|
|
|
ca = x_toupper(*a);
|
|
|
|
cb = x_toupper(*b);
|
2006-11-26 04:11:12 -07:00
|
|
|
if (ca != cb || ca == '\0')
|
|
|
|
break; /* if not eq else both nul */
|
|
|
|
a++, b++;
|
|
|
|
}
|
|
|
|
if (cb != '\0')
|
|
|
|
return 0;
|
|
|
|
|
2009-01-06 13:10:20 -07:00
|
|
|
if (ca == 'S')
|
2006-11-26 04:11:12 -07:00
|
|
|
ca = *++a;
|
|
|
|
|
|
|
|
switch (ca) {
|
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
*modifier = (ca == '-' ? -1 : 1) * atoi(a + 1);
|
2009-01-06 13:10:20 -07:00
|
|
|
result = 1;
|
|
|
|
break;
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
case '\0':
|
2009-01-06 13:10:20 -07:00
|
|
|
result = 1;
|
|
|
|
break;
|
2006-11-26 04:11:12 -07:00
|
|
|
|
|
|
|
default:
|
2009-01-06 13:10:20 -07:00
|
|
|
result = 0;
|
|
|
|
break;
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
2009-01-06 13:10:20 -07:00
|
|
|
return result;
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static long
|
|
|
|
params_to_pixels(TScreen * screen, String * params, Cardinal n)
|
|
|
|
{
|
|
|
|
int mult = 1;
|
2010-08-22 07:38:11 -06:00
|
|
|
const char *s;
|
2006-11-26 04:11:12 -07:00
|
|
|
int modifier;
|
|
|
|
|
|
|
|
switch (n > 2 ? 2 : n) {
|
|
|
|
case 2:
|
|
|
|
s = params[1];
|
2009-01-06 13:10:20 -07:00
|
|
|
if (CompareWidths(s, "PAGE", &modifier)) {
|
2006-11-26 04:11:12 -07:00
|
|
|
mult = (MaxRows(screen) + modifier) * FontHeight(screen);
|
2009-01-06 13:10:20 -07:00
|
|
|
} else if (CompareWidths(s, "HALFPAGE", &modifier)) {
|
2006-11-26 04:11:12 -07:00
|
|
|
mult = ((MaxRows(screen) + modifier) * FontHeight(screen)) / 2;
|
2009-01-06 13:10:20 -07:00
|
|
|
} else if (CompareWidths(s, "PIXEL", &modifier)) {
|
2006-11-26 04:11:12 -07:00
|
|
|
mult = 1;
|
|
|
|
} else {
|
|
|
|
/* else assume that it is Line */
|
|
|
|
mult = FontHeight(screen);
|
|
|
|
}
|
|
|
|
mult *= atoi(params[0]);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
mult = atoi(params[0]) * FontHeight(screen); /* lines */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mult = screen->scrolllines * FontHeight(screen);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return mult;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long
|
2009-03-09 16:13:04 -06:00
|
|
|
AmountToScroll(Widget w, String * params, Cardinal nparams)
|
2006-11-26 04:11:12 -07:00
|
|
|
{
|
2009-03-09 16:13:04 -06:00
|
|
|
long result = 0;
|
|
|
|
XtermWidget xw;
|
|
|
|
|
|
|
|
if ((xw = getXtermWidget(w)) != 0) {
|
|
|
|
TScreen *screen = TScreenOf(xw);
|
|
|
|
if (nparams <= 2
|
|
|
|
|| screen->send_mouse_pos == MOUSE_OFF) {
|
|
|
|
result = params_to_pixels(screen, params, nparams);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
2009-03-09 16:13:04 -06:00
|
|
|
return result;
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
HandleScrollForward(
|
2007-06-15 13:29:55 -06:00
|
|
|
Widget xw,
|
2006-11-26 04:11:12 -07:00
|
|
|
XEvent * event GCC_UNUSED,
|
|
|
|
String * params,
|
|
|
|
Cardinal *nparams)
|
|
|
|
{
|
|
|
|
long amount;
|
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
if ((amount = AmountToScroll(xw, params, *nparams)) != 0) {
|
|
|
|
ScrollTextUpDownBy(xw, (XtPointer) 0, (XtPointer) amount);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
HandleScrollBack(
|
2007-06-15 13:29:55 -06:00
|
|
|
Widget xw,
|
2006-11-26 04:11:12 -07:00
|
|
|
XEvent * event GCC_UNUSED,
|
|
|
|
String * params,
|
|
|
|
Cardinal *nparams)
|
|
|
|
{
|
|
|
|
long amount;
|
|
|
|
|
2007-06-15 13:29:55 -06:00
|
|
|
if ((amount = -AmountToScroll(xw, params, *nparams)) != 0) {
|
|
|
|
ScrollTextUpDownBy(xw, (XtPointer) 0, (XtPointer) amount);
|
2006-11-26 04:11:12 -07:00
|
|
|
}
|
|
|
|
}
|
2010-05-08 06:20:46 -06:00
|
|
|
|
|
|
|
#if OPT_SCROLL_LOCK
|
|
|
|
#define SCROLL_LOCK_LED 3
|
|
|
|
|
|
|
|
#ifdef HAVE_XKBQUERYEXTENSION
|
|
|
|
/*
|
|
|
|
* Check for Xkb on client and server.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
have_xkb(Display * dpy)
|
|
|
|
{
|
|
|
|
static int initialized = -1;
|
|
|
|
|
|
|
|
if (initialized < 0) {
|
|
|
|
int xkbmajor = XkbMajorVersion;
|
|
|
|
int xkbminor = XkbMinorVersion;
|
|
|
|
int xkbopcode, xkbevent, xkberror;
|
|
|
|
|
|
|
|
initialized = 0;
|
|
|
|
if (XkbLibraryVersion(&xkbmajor, &xkbminor)
|
|
|
|
&& XkbQueryExtension(dpy,
|
|
|
|
&xkbopcode,
|
|
|
|
&xkbevent,
|
|
|
|
&xkberror,
|
|
|
|
&xkbmajor,
|
|
|
|
&xkbminor)) {
|
|
|
|
TRACE(("we have Xkb\n"));
|
|
|
|
initialized = 1;
|
|
|
|
#if OPT_TRACE
|
|
|
|
{
|
|
|
|
XkbDescPtr xkb;
|
|
|
|
unsigned int mask;
|
|
|
|
int n;
|
|
|
|
char *modStr;
|
|
|
|
|
|
|
|
xkb = XkbGetKeyboard(dpy, XkbAllComponentsMask, XkbUseCoreKbd);
|
|
|
|
if (xkb != NULL) {
|
|
|
|
|
|
|
|
TRACE(("XkbGetKeyboard ok\n"));
|
|
|
|
for (n = 0; n < XkbNumVirtualMods; ++n) {
|
|
|
|
if (xkb->names->vmods[n] != 0) {
|
|
|
|
modStr = XGetAtomName(xkb->dpy,
|
|
|
|
xkb->names->vmods[n]);
|
|
|
|
if (modStr != 0) {
|
2010-08-22 07:38:11 -06:00
|
|
|
XkbVirtualModsToReal(xkb,
|
|
|
|
(unsigned) (1 << n),
|
|
|
|
&mask);
|
2010-05-08 06:20:46 -06:00
|
|
|
TRACE((" name[%d] %s (%#x)\n", n, modStr, mask));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XkbFreeKeyboard(xkb, 0, True);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return initialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Boolean
|
|
|
|
getXkbLED(Display * dpy, const char *name, Boolean * result)
|
|
|
|
{
|
|
|
|
Atom my_atom;
|
|
|
|
Boolean success = False;
|
|
|
|
Bool state;
|
|
|
|
|
|
|
|
if (have_xkb(dpy)) {
|
2010-08-22 07:38:11 -06:00
|
|
|
my_atom = XInternAtom(dpy, name, False);
|
2010-05-08 06:20:46 -06:00
|
|
|
if ((my_atom != None) &&
|
|
|
|
XkbGetNamedIndicator(dpy, my_atom, NULL, &state, NULL, NULL)) {
|
|
|
|
*result = (Boolean) state;
|
|
|
|
success = True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use Xkb if we have it (still unreliable, but slightly better than hardcoded).
|
|
|
|
*/
|
|
|
|
static Boolean
|
|
|
|
showXkbLED(Display * dpy, const char *name, Bool enable)
|
|
|
|
{
|
|
|
|
Atom my_atom;
|
|
|
|
Boolean result = False;
|
|
|
|
|
|
|
|
if (have_xkb(dpy)) {
|
2010-08-22 07:38:11 -06:00
|
|
|
my_atom = XInternAtom(dpy, name, False);
|
2010-05-08 06:20:46 -06:00
|
|
|
if ((my_atom != None) &&
|
|
|
|
XkbGetNamedIndicator(dpy, my_atom, NULL, NULL, NULL, NULL) &&
|
|
|
|
XkbSetNamedIndicator(dpy, my_atom, True, enable, False, NULL)) {
|
|
|
|
result = True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-22 07:38:11 -06:00
|
|
|
/*
|
|
|
|
* xlsatoms agrees with this list. However Num/Caps lock are generally
|
|
|
|
* unusable due to special treatment in X. They are used here for
|
|
|
|
* completeness.
|
|
|
|
*/
|
2010-05-08 06:20:46 -06:00
|
|
|
static const char *led_table[] =
|
|
|
|
{
|
|
|
|
"Num Lock",
|
|
|
|
"Caps Lock",
|
|
|
|
"Scroll Lock"
|
|
|
|
};
|
|
|
|
|
|
|
|
static Boolean
|
|
|
|
xtermGetLED(TScreen * screen, Cardinal led_number)
|
|
|
|
{
|
|
|
|
Display *dpy = screen->display;
|
|
|
|
Boolean result = False;
|
|
|
|
|
|
|
|
#ifdef HAVE_XKBQUERYEXTENSION
|
|
|
|
if (!getXkbLED(dpy, led_table[led_number - 1], &result))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
XKeyboardState state;
|
|
|
|
unsigned long my_bit = (unsigned long) (1 << (led_number - 1));
|
|
|
|
|
|
|
|
XGetKeyboardControl(dpy, &state);
|
|
|
|
|
|
|
|
result = (Boolean) ((state.led_mask & my_bit) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(("xtermGetLED %d:%s\n", led_number, BtoS(result)));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Display the given LED, preferably independent of keyboard state.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xtermShowLED(TScreen * screen, Cardinal led_number, Bool enable)
|
|
|
|
{
|
|
|
|
TRACE(("xtermShowLED %d:%s\n", led_number, BtoS(enable)));
|
|
|
|
if ((led_number >= 1) && (led_number <= XtNumber(led_table))) {
|
|
|
|
Display *dpy = screen->display;
|
|
|
|
|
|
|
|
#ifdef HAVE_XKBQUERYEXTENSION
|
|
|
|
if (!showXkbLED(dpy, led_table[led_number - 1], enable))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
XKeyboardState state;
|
|
|
|
XKeyboardControl values;
|
|
|
|
unsigned long use_mask;
|
|
|
|
unsigned long my_bit = (unsigned long) (1 << (led_number - 1));
|
|
|
|
|
|
|
|
XGetKeyboardControl(dpy, &state);
|
|
|
|
use_mask = state.led_mask;
|
|
|
|
if (enable) {
|
|
|
|
use_mask |= my_bit;
|
|
|
|
} else {
|
|
|
|
use_mask &= ~my_bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.led_mask != use_mask) {
|
|
|
|
values.led = (int) led_number;
|
|
|
|
values.led_mode = enable;
|
|
|
|
XChangeKeyboardControl(dpy, KBLed | KBLedMode, &values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xtermClearLEDs(TScreen * screen)
|
|
|
|
{
|
|
|
|
Display *dpy = screen->display;
|
|
|
|
XKeyboardControl values;
|
|
|
|
|
|
|
|
TRACE(("xtermClearLEDs\n"));
|
2010-08-22 07:38:11 -06:00
|
|
|
#ifdef HAVE_XKBQUERYEXTENSION
|
|
|
|
ShowScrollLock(screen, False);
|
|
|
|
#endif
|
2010-05-08 06:20:46 -06:00
|
|
|
memset(&values, 0, sizeof(values));
|
|
|
|
XChangeKeyboardControl(dpy, KBLedMode, &values);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShowScrollLock(TScreen * screen, Bool enable)
|
|
|
|
{
|
|
|
|
xtermShowLED(screen, SCROLL_LOCK_LED, enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetScrollLock(TScreen * screen)
|
|
|
|
{
|
|
|
|
if (screen->allowScrollLock)
|
|
|
|
screen->scroll_lock = xtermGetLED(screen, SCROLL_LOCK_LED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetScrollLock(TScreen * screen, Bool enable)
|
|
|
|
{
|
|
|
|
if (screen->allowScrollLock) {
|
|
|
|
if (screen->scroll_lock != enable) {
|
|
|
|
screen->scroll_lock = (Boolean) enable;
|
|
|
|
ShowScrollLock(screen, enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HandleScrollLock(Widget w,
|
|
|
|
XEvent * event GCC_UNUSED,
|
|
|
|
String * params,
|
|
|
|
Cardinal *param_count)
|
|
|
|
{
|
|
|
|
XtermWidget xw;
|
|
|
|
|
|
|
|
if ((xw = getXtermWidget(w)) != 0) {
|
|
|
|
TScreen *screen = TScreenOf(xw);
|
|
|
|
|
|
|
|
if (screen->allowScrollLock) {
|
|
|
|
/*
|
|
|
|
* The default action (used with KeyRelease event) is to cycle the
|
|
|
|
* state on/off.
|
|
|
|
*/
|
|
|
|
if (*param_count == 0) {
|
|
|
|
SetScrollLock(screen, !screen->scroll_lock);
|
|
|
|
TRACE(("HandleScrollLock ->%d\n",
|
|
|
|
screen->scroll_lock));
|
|
|
|
} else {
|
|
|
|
SetScrollLock(screen, atoi(params[0]));
|
|
|
|
TRACE(("HandleScrollLock(%s) ->%d\n",
|
|
|
|
params[0],
|
|
|
|
screen->scroll_lock));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|