Skip to content

Commit

Permalink
Merge pull request #4 from LibVNC/multipointer
Browse files Browse the repository at this point in the history
Multipointer
  • Loading branch information
bk138 committed Jan 11, 2015
2 parents 59e6916 + 43a2fa1 commit bf916aa
Show file tree
Hide file tree
Showing 23 changed files with 1,628 additions and 149 deletions.
7 changes: 3 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ LD_CYGIPC=-lcygipc
endif

bin_PROGRAMS=x11vnc
x11vnc_SOURCES = 8to24.c appshare.c avahi.c cleanup.c connections.c cursor.c gui.c help.c inet.c keyboard.c linuxfb.c macosx.c macosxCG.c macosxCGP.c macosxCGS.c macosx_opengl.c options.c pm.c pointer.c rates.c remote.c scan.c screen.c selection.c solid.c sslcmds.c sslhelper.c uinput.c unixpw.c user.c userinput.c util.c v4l.c win_utils.c x11vnc.c x11vnc_defs.c xdamage.c xevents.c xinerama.c xkb_bell.c xrandr.c xrecord.c xwrappers.c 8to24.h allowed_input_t.h avahi.h blackout_t.h cleanup.h connections.h cursor.h enc.h enums.h gui.h help.h inet.h keyboard.h linuxfb.h macosx.h macosxCG.h macosxCGP.h macosxCGS.h macosx_opengl.h nox11.h nox11_funcs.h options.h params.h pm.h pointer.h rates.h remote.h scan.h screen.h scrollevent_t.h selection.h solid.h sslcmds.h sslhelper.h ssltools.h tkx11vnc.h uinput.h unixpw.h user.h userinput.h util.h v4l.h win_utils.h winattr_t.h x11vnc.h xdamage.h xevents.h xinerama.h xkb_bell.h xrandr.h xrecord.h xwrappers.h default8x16.h

x11vnc_SOURCES = 8to24.c appshare.c avahi.c cleanup.c connections.c cursor.c gui.c help.c inet.c keyboard.c linuxfb.c macosx.c macosxCG.c macosxCGP.c macosxCGS.c macosx_opengl.c options.c pm.c pointer.c rates.c remote.c scan.c screen.c selection.c solid.c sslcmds.c sslhelper.c uinput.c unixpw.c user.c userinput.c util.c v4l.c win_utils.c x11vnc.c x11vnc_defs.c xdamage.c xevents.c xinerama.c xkb_bell.c xrandr.c xrecord.c xwrappers.c xi2_devices.c 8to24.h allowed_input_t.h avahi.h blackout_t.h cleanup.h connections.h cursor.h enc.h enums.h gui.h help.h inet.h keyboard.h linuxfb.h macosx.h macosxCG.h macosxCGP.h macosxCGS.h macosx_opengl.h nox11.h nox11_funcs.h options.h params.h pm.h pointer.h rates.h remote.h scan.h screen.h scrollevent_t.h selection.h solid.h sslcmds.h sslhelper.h ssltools.h tkx11vnc.h uinput.h unixpw.h user.h userinput.h util.h v4l.h win_utils.h winattr_t.h x11vnc.h xdamage.h xevents.h xinerama.h xkb_bell.h xrandr.h xrecord.h xwrappers.h default8x16.h xi2_devices.h

INCLUDES_LIBVNCSERVER = @LIBVNCSERVER_CFLAGS@ @LIBVNCCLIENT_CFLAGS@

AM_CPPFLAGS = $(INCLUDES_LIBVNCSERVER) @X_CFLAGS@ @AVAHI_CFLAGS@
AM_CPPFLAGS = $(INCLUDES_LIBVNCSERVER) @X_CFLAGS@ @AVAHI_CFLAGS@ @XI2_CFLAGS@ @CAIRO_CFLAGS@

x11vnc_LDADD=$(LDADD) @SSL_LIBS@ @CRYPT_LIBS@ @X_LIBS@ @AVAHI_LIBS@ $(LD_CYGIPC)
x11vnc_LDADD=$(LDADD) @SSL_LIBS@ @CRYPT_LIBS@ @X_LIBS@ @AVAHI_LIBS@ @XI2_LIBS@ @CAIRO_LIBS@ $(LD_CYGIPC)
25 changes: 20 additions & 5 deletions cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ so, delete this exception statement from your version.
#include "xrecord.h"
#include "xevents.h"
#include "uinput.h"
#include "xi2_devices.h"

/*
* Exiting and error handling routines
Expand Down Expand Up @@ -143,6 +144,7 @@ static void clean_icon_mode(void) {
}
}


/*
* Normal exiting
*/
Expand Down Expand Up @@ -210,6 +212,10 @@ void clean_up_exit(int ret) {
/* X keyboard cleanups */
delete_added_keycodes(0);

/* remove all created XInput2 devices */
if(use_multipointer)
removeAllMDs(dpy);

if (clear_mods == 1) {
clear_modifiers(0);
} else if (clear_mods == 2) {
Expand Down Expand Up @@ -529,15 +535,20 @@ static void interrupted (int sig) {
if (exit_flag) {
fprintf(stderr, "extra[%d] signal: %d\n", exit_flag, sig);
exit_flag++;
if (use_threads) {
usleep2(250 * 1000);
} else if (exit_flag <= 2) {
return;
}
if (use_threads)
usleep2(250 * 1000);
if (exit_flag <= 2)
return;

if (rm_flagfile) {
unlink(rm_flagfile);
rm_flagfile = NULL;
}

/* remove all created XInput2 devices */
if(use_multipointer)
removeAllMDs(dpy);

exit(4);
}
exit_flag++;
Expand Down Expand Up @@ -578,6 +589,10 @@ static void interrupted (int sig) {
/* X keyboard cleanups */
delete_added_keycodes(0);

/* remove all created XInput2 devices */
if(use_multipointer)
removeAllMDs(dpy);

if (clear_mods == 1) {
clear_modifiers(0);
} else if (clear_mods == 2) {
Expand Down
51 changes: 51 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ AH_TEMPLATE(HAVE_LIBXRANDR, [XRANDR extension build environment present])
AH_TEMPLATE(HAVE_LIBXFIXES, [XFIXES extension build environment present])
AH_TEMPLATE(HAVE_LIBXDAMAGE, [XDAMAGE extension build environment present])
AH_TEMPLATE(HAVE_LIBXCOMPOSITE, [XCOMPOSITE extension build environment present])
AH_TEMPLATE(HAVE_LIBXCURSOR, [Xcursor library build environment present])
AH_TEMPLATE(HAVE_XI2, [XINPUT 2 extension build environment present])
AH_TEMPLATE(HAVE_LIBXTRAP, [DEC-XTRAP extension build environment present])
AH_TEMPLATE(HAVE_RECORD, [RECORD extension build environment present])
AH_TEMPLATE(HAVE_SOLARIS_XREADSCREEN, [Solaris XReadScreen available])
Expand Down Expand Up @@ -132,6 +134,9 @@ AC_ARG_WITH(uinput,
[ --without-uinput disable linux uinput device support],,)
AC_ARG_WITH(macosx-native,
[ --without-macosx-native disable MacOS X native display support],,)
AC_ARG_WITH(colormultipointer,
[ --without-colormultipointer disable color support for multiple pointers]
[ --with-cairo=DIR use cairo include/library files in DIR (needed for color cursor support)],,)

fi
# end x11vnc only.
Expand Down Expand Up @@ -251,6 +256,19 @@ elif test "$X_CFLAGS" != "-DX_DISPLAY_MISSING"; then
$X_LIBS $X_PRELIBS -lX11 $X_EXTRA_LIBS)
fi

# check for XI2 support
PKG_CHECK_MODULES(XI2, [xi >= 1.2.99] [inputproto >= 1.9.99.9],
HAVE_XI2="yes"; AC_DEFINE(HAVE_XI2, 1, [XI2 available]),
HAVE_XI2="no");

if test "$HAVE_XI2" = "yes" -a "x$with_colormultipointer" != "xno"; then
AC_CHECK_LIB(Xcursor, XcursorImageLoadCursor,
X_PRELIBS="$X_PRELIBS -lXcursor"
[AC_DEFINE(HAVE_LIBXCURSOR) HAVE_LIBXCURSOR="true"], ,
$X_LIBS $X_PRELIBS -lX11 $X_EXTRA_LIBS)
fi


if test ! -z "$HAVE_LIBXFIXES" -o ! -z "$HAVE_LIBXDAMAGE"; then
# need /usr/sfw/lib in RPATH for Solaris 10 and later
case `(uname -sr) 2>/dev/null` in
Expand Down Expand Up @@ -361,9 +379,42 @@ if test "x$with_avahi" = "xyes"; then
AC_SUBST(AVAHI_LIBS)
fi

if test "$HAVE_XI2" = "yes"; then
AH_TEMPLATE(HAVE_CAIRO, [cairo graphics library present])
if test "x$with_cairo" != "xno"; then
printf "checking for cairo... "
if test ! -z "$with_cairo" -a "x$with_cairo" != "xyes"; then
CAIRO_CFLAGS="-I$with_cairo/include"
CAIRO_LIBS="-L$with_cairo/lib -lcairo"
echo "using $with_cairo"
with_cairo=yes
elif pkg-config cairo >/dev/null 2>&1; then
CAIRO_CFLAGS=`pkg-config --cflags cairo`
CAIRO_LIBS=`pkg-config --libs cairo`
with_cairo=yes
echo yes
else
with_cairo=no
echo no
fi
fi
if test "x$with_cairo" = "xyes"; then
AC_DEFINE(HAVE_CAIRO)
AC_SUBST(CAIRO_CFLAGS)
AC_SUBST(CAIRO_LIBS)
fi
fi


fi
# end x11vnc only.

# XI2 present?
AM_CONDITIONAL(HAVE_XI2, [ test "$HAVE_XI2" = "yes" ])
# cairo?
AM_CONDITIONAL(HAVE_CAIRO, [ test "$with_cairo" = "yes" ])


# only used in x11vnc/Makefile.am but needs to always be defined:
AM_CONDITIONAL(OSX_OPENGL, test "$HAVE_MACOSX_OPENGL_H" = "true")

Expand Down
58 changes: 58 additions & 0 deletions connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ so, delete this exception statement from your version.
#include "userinput.h"
#include "pointer.h"
#include "xrandr.h"
#include "xi2_devices.h"


/*
* routines for handling incoming, outgoing, etc connections
Expand Down Expand Up @@ -783,6 +785,18 @@ static void free_client_data(rfbClientPtr client) {
free(cd->unixname);
cd->unixname = NULL;
}
if (cd->cursor) {
rfbFreeCursor(cd->cursor);
cd->cursor = NULL;
}
if (cd->under_cursor_buffer) {
free(cd->under_cursor_buffer);
cd->under_cursor_buffer = NULL;
}
if (cd->cursor_region) {
sraRgnDestroy(cd->cursor_region);
cd->cursor_region = NULL;
}
}
free(client->clientData);
client->clientData = NULL;
Expand Down Expand Up @@ -886,6 +900,11 @@ void client_gone(rfbClientPtr client) {
}
}

/* remove clients XInput2 master device */
if(use_multipointer)
if(removeMD(dpy, cd->ptr_id))
rfbLog("removed XInput2 MD for client %s.\n", client->host);

free_client_data(client);

if (inetd && client == inetd_client) {
Expand Down Expand Up @@ -3964,13 +3983,20 @@ enum rfbNewClientAction new_client(rfbClientPtr client) {
return(RFB_CLIENT_REFUSE);
}

if(use_multipointer && xi2_device_creation_in_progress) {
rfbLog("denying additional client: %s during MD creation.\n", client->host);
CLIENT_UNLOCK;
return(RFB_CLIENT_REFUSE);
}

client->clientData = (void *) calloc(sizeof(ClientData), 1);
cd = (ClientData *) client->clientData;

/* see client_set_net() we delay the DNS lookups during handshake */
cd->client_port = -1;
cd->username = strdup("");
cd->unixname = strdup("");
cd->cursor_x_saved = cd->cursor_y_saved = -1;

cd->input[0] = '-';
cd->login_viewonly = -1;
Expand Down Expand Up @@ -4015,6 +4041,38 @@ enum rfbNewClientAction new_client(rfbClientPtr client) {

cd->uid = clients_served;

/*
create new XInput2 master device and add it it to client
*/
if(use_multipointer)
{
char tmp[256];
snprintf(tmp, 256, "x11vnc %s", client->host);

xi2_device_creation_in_progress = 1;

if((cd->ptr_id = createMD(dpy, tmp)) < 0) {
rfbLog("ERROR creating XInput2 MD for client %s, denying client.\n", client->host);
free_client_data(client);
xi2_device_creation_in_progress = 0;
CLIENT_UNLOCK;
return(RFB_CLIENT_REFUSE);
}

cd->kbd_id = getPairedMD(dpy, cd->ptr_id);

rfbLog("Created XInput2 MD %i %i for client %s.\n", cd->ptr_id, cd->kbd_id, client->host);

xi2_device_creation_in_progress = 0;

snprintf(tmp, 256, "%i", cd->uid);
cd->cursor = setClientCursor(dpy, cd->ptr_id, 0.4*(cd->ptr_id%3), 0.2*(cd->ptr_id%5), 1*(cd->ptr_id%2), tmp);
if(!cd->cursor)
rfbLog("Setting cursor for client %s failed.\n", client->host);

cd->cursor_region = sraRgnCreate();
}

client->clientGoneHook = client_gone;

if (client_count) {
Expand Down
Loading

0 comments on commit bf916aa

Please sign in to comment.