Commit 2689647d authored by runge's avatar runge

x11vnc: add clear_locks (Caps_Lock, etc) action.

parent e24cf949
2007-11-12 Karl Runge <runge@karlrunge.com>
* x11vnc: add clear_locks (Caps_Lock, etc) action. Fix
ssh tunnel on Darwin.
2007-10-27 Karl Runge <runge@karlrunge.com>
* x11vnc: fix ncache bug and others under -8to24, -ssh
option, socks and other proxies in -proxy option.
......
This diff is collapsed.
......@@ -159,6 +159,9 @@ void clean_up_exit (int ret) {
clear_modifiers(0);
} else if (clear_mods == 2) {
clear_keys();
} else if (clear_mods == 3) {
clear_keys();
clear_locks();
}
if (no_autorepeat) {
......@@ -420,6 +423,9 @@ static void interrupted (int sig) {
clear_modifiers(0);
} else if (clear_mods == 2) {
clear_keys();
} else if (clear_mods == 3) {
clear_keys();
clear_locks();
}
if (no_autorepeat) {
autorepeat(1, 0);
......
......@@ -1723,7 +1723,7 @@ void print_help(int mode) {
" If the remote SSH server is on a non-standard port\n"
" (i.e. not 22) use user@host:port:disp+secs.\n"
"\n"
" Note that the ssh process may NOT be killed when\n"
" Note that the ssh process MAY NOT be killed when\n"
" x11vnc exits. It tries by looking at ps(1) output.\n"
"\n"
"-usepw If no other password method was supplied on the command\n"
......@@ -2226,9 +2226,12 @@ void print_help(int mode) {
" KeyRelease for each one. The Lock modifiers are skipped.\n"
" Used to clear the state if the display was accidentally\n"
" left with any pressed down.\n"
"-clear_keys As -clear_mods, except try to release any pressed key.\n"
"-clear_keys As -clear_mods, except try to release ANY pressed key.\n"
" Note that this option and -clear_mods can interfere\n"
" with a person typing at the physical keyboard.\n"
"-clear_all As -clear_keys, except try to release any CapsLock,\n"
" NumLock, etc. locks as well.\n"
"\n"
"-remap string Read Keysym remappings from file named \"string\".\n"
" Format is one pair of Keysyms per line (can be name\n"
" or hex value) separated by a space. If no file named\n"
......@@ -3863,6 +3866,9 @@ void print_help(int mode) {
" noclear_mods disable -clear_mods mode.\n"
" clear_keys enable -clear_keys mode and clear them.\n"
" noclear_keys disable -clear_keys mode.\n"
" clear_locks do the clear_locks action.\n"
" clear_all do the clear_all action.\n"
" keystate have x11vnc print current keystate.\n"
/* filename */
" remap:str set -remap \"str\" (empty to disable).\n"
" See -remap for the form of \"str\"\n"
......@@ -4084,17 +4090,18 @@ void print_help(int mode) {
" 8to24_opts 24to32 no24to32 visual scale scale_cursor\n"
" viewonly noviewonly shared noshared forever noforever\n"
" once timeout tightfilexfer notightfilexfer ultrafilexfer\n"
" noultrafilexfer rfbversion deny lock nodeny unlock avahi\n"
" mdns noavahi nomdns connect proxy allowonce allow\n"
" localhost nolocalhost listen lookup nolookup accept\n"
" afteraccept gone shm noshm flipbyteorder noflipbyteorder\n"
" onetile noonetile solid_color solid nosolid blackout\n"
" xinerama noxinerama xtrap noxtrap xrandr noxrandr\n"
" xrandr_mode rotate padgeom quiet q noquiet modtweak\n"
" nomodtweak xkb noxkb capslock nocapslock skip_lockkeys\n"
" noskip_lockkeys skip_keycodes sloppy_keys nosloppy_keys\n"
" skip_dups noskip_dups add_keysyms noadd_keysyms\n"
" clear_mods noclear_mods clear_keys noclear_keys\n"
" noultrafilexfer rfbversion deny lock nodeny unlock\n"
" avahi mdns noavahi nomdns connect proxy allowonce\n"
" allow localhost nolocalhost listen lookup nolookup\n"
" accept afteraccept gone shm noshm flipbyteorder\n"
" noflipbyteorder onetile noonetile solid_color solid\n"
" nosolid blackout xinerama noxinerama xtrap noxtrap\n"
" xrandr noxrandr xrandr_mode rotate padgeom quiet\n"
" q noquiet modtweak nomodtweak xkb noxkb capslock\n"
" nocapslock skip_lockkeys noskip_lockkeys skip_keycodes\n"
" sloppy_keys nosloppy_keys skip_dups noskip_dups\n"
" add_keysyms noadd_keysyms clear_mods noclear_mods\n"
" clear_keys noclear_keys clear_all clear_locks keystate\n"
" remap repeat norepeat fb nofb bell nobell sel nosel\n"
" primary noprimary setprimary nosetprimary clipboard\n"
" noclipboard setclipboard nosetclipboard seldir\n"
......
......@@ -21,6 +21,7 @@ void get_keystate(int *keystate);
void clear_modifiers(int init);
int track_mod_state(rfbKeySym keysym, rfbBool down, rfbBool set);
void clear_keys(void);
void clear_locks(void);
int get_autorepeat_state(void);
int get_initial_autorepeat_state(void);
void autorepeat(int restore, int bequiet);
......@@ -250,6 +251,68 @@ void clear_keys(void) {
XFlush_wr(dpy);
}
void clear_locks(void) {
#if NO_X11
RAWFB_RET_VOID
return;
#else
XModifierKeymap *map;
int i, j, k = 0;
unsigned int state;
RAWFB_RET_VOID
/* n.b. caller decides to X_LOCK or not. */
#if LIBVNCSERVER_HAVE_XKEYBOARD
if (xkb_present) {
XkbStateRec kbstate;
XkbGetState(dpy, XkbUseCoreKbd, &kbstate);
rfbLog("locked: 0x%x\n", kbstate.locked_mods);
rfbLog("latched: 0x%x\n", kbstate.latched_mods);
rfbLog("compat: 0x%x\n", kbstate.compat_state);
state = kbstate.locked_mods;
if (! state) {
state = kbstate.compat_state;
}
} else
#endif
{
state = mask_state();
rfbLog("state: 0x%x\n", state);
}
if (! state) {
return;
}
map = XGetModifierMapping(dpy);
if (! map) {
return;
}
for (i = 0; i < 8; i++) {
int did = 0;
for (j = 0; j < map->max_keypermod; j++) {
if (! did && state & (0x1 << i)) {
if (map->modifiermap[k]) {
KeyCode key = map->modifiermap[k];
KeySym ks = XKeycodeToKeysym(dpy, key, 0);
char *nm = XKeysymToString(ks);
rfbLog("toggling: %03d / %03d -- %s\n", key, ks, nm ? nm : "BadKey");
did = 1;
XTestFakeKeyEvent_wr(dpy, key, True, CurrentTime);
usleep(10*1000);
XTestFakeKeyEvent_wr(dpy, key, False, CurrentTime);
XFlush_wr(dpy);
}
}
k++;
}
}
XFreeModifiermap(map);
XFlush_wr(dpy);
rfbLog("state: 0x%x\n", mask_state());
#endif
}
/*
* Kludge for -norepeat option: we turn off keystroke autorepeat in
* the X server when clients are connected. This may annoy people at
......@@ -2661,6 +2724,9 @@ void initialize_keyboard_and_pointer(void) {
if (clear_mods == 1) {
clear_modifiers(0);
}
if (clear_mods == 3) {
clear_locks();
}
}
void get_allowed_input(rfbClientPtr client, allowed_input_t *input) {
......
......@@ -8,6 +8,7 @@ extern void get_keystate(int *keystate);
extern void clear_modifiers(int init);
extern int track_mod_state(rfbKeySym keysym, rfbBool down, rfbBool set);
extern void clear_keys(void);
extern void clear_locks(void);
extern int get_autorepeat_state(void);
extern int get_initial_autorepeat_state(void);
extern void autorepeat(int restore, int bequiet);
......
......@@ -129,7 +129,7 @@ int use_modifier_tweak = 1; /* use the shift/altgr modifier tweak */
int watch_capslock = 0; /* -capslock */
int skip_lockkeys = 0; /* -skip_lockkeys */
int use_iso_level3 = 0; /* ISO_Level3_Shift instead of Mode_switch */
int clear_mods = 0; /* -clear_mods (1) and -clear_keys (2) */
int clear_mods = 0; /* -clear_mods (1) and -clear_keys (2) -clear_locks (3) */
int nofb = 0; /* do not send any fb updates */
char *raw_fb_str = NULL; /* used under -rawfb */
char *raw_fb_pixfmt = NULL;
......
......@@ -2246,6 +2246,33 @@ char *process_remote_cmd(char *cmd, int stringonly) {
rfbLog("remote_cmd: disabling -clear_keys mode.\n");
clear_mods = 0;
} else if (!strcmp(p, "clear_all")) {
if (query) {
snprintf(buf, bufn, "ans=%s:%d", p,
clear_mods == 3);
goto qry;
}
rfbLog("remote_cmd: doing clear_all action.\n");
clear_mods = 3;
clear_keys();
clear_locks();
} else if (!strcmp(p, "clear_locks")) {
NOTAPP
rfbLog("remote_cmd: doing clear_locks action.\n");
clear_locks();
} else if (!strcmp(p, "keystate")) {
int i, state[256];
NOTAPP
for (i=0; i<256; i++) {
state[i] = 0;
}
get_keystate(state);
for (i=0; i<256; i++) {
fprintf(stderr, "keystate[%03d] %d\n", i, state[i]);
}
} else if (strstr(p, "remap") == p) {
char *before, *old;
COLON_CHECK("remap:")
......
......@@ -208,6 +208,8 @@ Keyboard
=FP remap:
clear_mods
clear_keys
clear_all
=RA clear_locks
Pointer
=D-C:none,arrow,X,some,most cursor:
......
......@@ -219,6 +219,8 @@ char gui_code[] = "";
" =FP remap:\n"
" clear_mods\n"
" clear_keys\n"
" clear_all\n"
" =RA clear_locks\n"
"\n"
"Pointer\n"
" =D-C:none,arrow,X,some,most cursor:\n"
......
......@@ -1185,6 +1185,7 @@ void user_supplied_opts(char *opts) {
"skip-display", "skip-auth", "skip-shared",
"scale", "scale_cursor", "sc", "solid", "so", "id",
"clear_mods", "cm", "clear_keys", "ck", "repeat",
"clear_all", "ca",
"speeds", "sp", "readtimeout", "rd",
"rotate", "ro",
"geometry", "geom", "ge",
......@@ -1272,6 +1273,9 @@ void user_supplied_opts(char *opts) {
} else if (!strcmp(p, "clear_keys") ||
!strcmp(p, "ck")) {
clear_mods = 2;
} else if (!strcmp(p, "clear_all") ||
!strcmp(p, "ca")) {
clear_mods = 3;
} else if (!strcmp(p, "noncache") ||
!strcmp(p, "nc")) {
ncache = 0;
......
.\" This file was automatically generated from x11vnc -help output.
.TH X11VNC "1" "October 2007" "x11vnc " "User Commands"
.TH X11VNC "1" "November 2007" "x11vnc " "User Commands"
.SH NAME
x11vnc - allow VNC connections to real X11 displays
version: 0.9.4, lastmod: 2007-10-27
version: 0.9.4, lastmod: 2007-11-07
.SH SYNOPSIS
.B x11vnc
[OPTION]...
......@@ -1956,7 +1956,7 @@ this use user@host:disp+secs.
If the remote SSH server is on a non-standard port
(i.e. not 22) use user@host:port:disp+secs.
.IP
Note that the ssh process may NOT be killed when
Note that the ssh process MAY NOT be killed when
x11vnc exits. It tries by looking at
.IR ps (1)
output.
......@@ -2581,10 +2581,15 @@ left with any pressed down.
.PP
\fB-clear_keys\fR
.IP
As \fB-clear_mods,\fR except try to release any pressed key.
As \fB-clear_mods,\fR except try to release ANY pressed key.
Note that this option and \fB-clear_mods\fR can interfere
with a person typing at the physical keyboard.
.PP
\fB-clear_all\fR
.IP
As \fB-clear_keys,\fR except try to release any CapsLock,
NumLock, etc. locks as well.
.PP
\fB-remap\fR \fIstring\fR
.IP
Read Keysym remappings from file named \fIstring\fR.
......@@ -4587,6 +4592,12 @@ clear_keys enable \fB-clear_keys\fR mode and clear them.
.IP
noclear_keys disable \fB-clear_keys\fR mode.
.IP
clear_locks do the clear_locks action.
.IP
clear_all do the clear_all action.
.IP
keystate have x11vnc print current keystate.
.IP
remap:str set \fB-remap\fR "str" (empty to disable).
See \fB-remap\fR for the form of "str"
(basically: key1-key2,key3-key4,...)
......@@ -4993,17 +5004,18 @@ nooverlay_yescursor overlay_nocursor 8to24 no8to24
8to24_opts 24to32 no24to32 visual scale scale_cursor
viewonly noviewonly shared noshared forever noforever
once timeout tightfilexfer notightfilexfer ultrafilexfer
noultrafilexfer rfbversion deny lock nodeny unlock avahi
mdns noavahi nomdns connect proxy allowonce allow
localhost nolocalhost listen lookup nolookup accept
afteraccept gone shm noshm flipbyteorder noflipbyteorder
onetile noonetile solid_color solid nosolid blackout
xinerama noxinerama xtrap noxtrap xrandr noxrandr
xrandr_mode rotate padgeom quiet q noquiet modtweak
nomodtweak xkb noxkb capslock nocapslock skip_lockkeys
noskip_lockkeys skip_keycodes sloppy_keys nosloppy_keys
skip_dups noskip_dups add_keysyms noadd_keysyms
clear_mods noclear_mods clear_keys noclear_keys
noultrafilexfer rfbversion deny lock nodeny unlock
avahi mdns noavahi nomdns connect proxy allowonce
allow localhost nolocalhost listen lookup nolookup
accept afteraccept gone shm noshm flipbyteorder
noflipbyteorder onetile noonetile solid_color solid
nosolid blackout xinerama noxinerama xtrap noxtrap
xrandr noxrandr xrandr_mode rotate padgeom quiet
q noquiet modtweak nomodtweak xkb noxkb capslock
nocapslock skip_lockkeys noskip_lockkeys skip_keycodes
sloppy_keys nosloppy_keys skip_dups noskip_dups
add_keysyms noadd_keysyms clear_mods noclear_mods
clear_keys noclear_keys clear_all clear_locks keystate
remap repeat norepeat fb nofb bell nobell sel nosel
primary noprimary setprimary nosetprimary clipboard
noclipboard setclipboard nosetclipboard seldir
......
......@@ -1045,13 +1045,17 @@ void ssh_remote_tunnel(char *instr, int lport) {
int bestpid = -1;
int best = -1;
char line[1024];
char *ps = "ps -ef";
char *psef = "ps -ef";
char *psww = "ps wwwwwwaux";
char *ps = psef;
/* not portable... but it is really good to terminate the ssh when done. */
/* ps -ef | egrep 'ssh2.*-R.*5907:localhost:5900.*runge@celias.lbl.gov.*sleep 300' | grep -v grep | awk '{print $2}' */
if (strstr(UT.sysname, "Linux")) {
ps = "ps wwwwwaux";
ps = psww;
} else if (strstr(UT.sysname, "BSD")) {
ps = "ps wwwwwaux";
ps = psww;
} else if (strstr(UT.sysname, "Darwin")) {
ps = psww;
}
sprintf(cmd, "env COLUMNS=256 %s | egrep '%s.*-R *%d:localhost:%d.*%s.*sleep *%d' | grep -v grep | awk '{print $2}'", ps, ssh, rport, lport, s, sleep);
pipe = popen(cmd, "r");
......@@ -2961,6 +2965,8 @@ int main(int argc, char* argv[]) {
clear_mods = 1;
} else if (!strcmp(arg, "-clear_keys")) {
clear_mods = 2;
} else if (!strcmp(arg, "-clear_all")) {
clear_mods = 3;
} else if (!strcmp(arg, "-remap")) {
CHECK_ARGC
remap_file = strdup(argv[++i]);
......
......@@ -15,7 +15,7 @@ int xtrap_base_event_type = 0;
int xdamage_base_event_type = 0;
/* date +'lastmod: %Y-%m-%d' */
char lastmod[] = "0.9.4 lastmod: 2007-10-27";
char lastmod[] = "0.9.4 lastmod: 2007-11-07";
/* X display info */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment