Skip to content

Commit

Permalink
setDesktopSize support: disable support if older libvncserver version
Browse files Browse the repository at this point in the history
Signed-off-by: Floris Bos <[email protected]>
  • Loading branch information
maxnet committed Jul 17, 2019
1 parent 4b64054 commit 2872260
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ elif test "$X_CFLAGS" != "-DX_DISPLAY_MISSING"; then
case `(uname -sr) 2>/dev/null` in
"SunOS 5"*) CPPFLAGS="$CPPFLAGS -I/usr/X11/include" ;;
esac

# support for setdesktopsize needs xrandr and libvncserver with setDesktopSizeHook
AC_CHECK_MEMBER([struct _rfbScreenInfo.setDesktopSizeHook],
[AC_DEFINE(HAVE_SETDESKTOPSIZE, 1, [libvncserver supports setDesktopSizeHook])],
[AC_MSG_WARN([Support for option -setdesktopsize disabled. Needs libvncserver 0.9.13])],
[[#include "rfb/rfb.h"]])
fi

X_LIBS="$X_LIBS $X_PRELIBS -lX11 $X_EXTRA_LIBS"
Expand Down
2 changes: 2 additions & 0 deletions src/connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,11 @@ void client_gone(rfbClientPtr client) {
}
}

#if HAVE_SETDESKTOPSIZE
if (enable_setdesktopsize && xrandr && client_count == 0) {
xrandr_reset_scaling();
}
#endif
if (no_autorepeat && client_count == 0) {
autorepeat(1, 0);
}
Expand Down
2 changes: 2 additions & 0 deletions src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -3058,12 +3058,14 @@ void print_help(int mode) {
" prefix \"string\" with \"nc:\", e.g. \"nc:+90\",\n"
" \"nc:xy\", etc.\n"
"\n"
#if HAVE_SETDESKTOPSIZE
"-setdesktopsize Allow client to change framebuffer resolution to fit\n"
" size of client window. x11vnc will use xrandr commands\n"
" to change the X framebuffer size. The mode of the physical\n"
" screen will not be changed, but scaling will be used to\n"
" display the new framebuffer size on the physical screen.\n"
"\n"
#endif
"-padgeom WxH Whenever a new vncviewer connects, the framebuffer is\n"
" replaced with a fake, solid black one of geometry WxH.\n"
" Shortly afterwards the framebuffer is replaced with the\n"
Expand Down
6 changes: 6 additions & 0 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ rfbBool vnc_reflect_send_cuttext(char *str, int len);
static void debug_colormap(XImage *fb);
static void set_visual(char *str);
static void nofb_hook(rfbClientPtr cl);
#if HAVE_SETDESKTOPSIZE
static int set_desktop_size_hook(int width, int height, int numScreens, rfbExtDesktopScreen* extDesktopScreens, rfbClientPtr cl);
#endif
static void remove_fake_fb(void);
static void install_fake_fb(int w, int h, int bpp);
static void initialize_snap_fb(void);
Expand Down Expand Up @@ -820,6 +822,7 @@ void free_old_fb(void) {
}
}

#if HAVE_SETDESKTOPSIZE
static int set_desktop_size_hook(int width, int height, int numScreens, rfbExtDesktopScreen* extDesktopScreens, rfbClientPtr cl)
{
int i;
Expand All @@ -836,6 +839,7 @@ static int set_desktop_size_hook(int width, int height, int numScreens, rfbExtDe

return xrandr_set_scale_from(width, height) ? rfbExtDesktopSize_Success : rfbExtDesktopSize_InvalidScreenLayout;
}
#endif

static char _lcs_tmp[128];
static int _bytes0_size = 128, _bytes0[128];
Expand Down Expand Up @@ -3669,9 +3673,11 @@ void initialize_screen(int *argc, char **argv, XImage *fb) {
screen->ptrAddEvent = pointer_event;
screen->setXCutText = xcut_receive;
screen->setTranslateFunction = set_xlate_wrapper;
#if HAVE_SETDESKTOPSIZE
if (enable_setdesktopsize) {
screen->setDesktopSizeHook = set_desktop_size_hook;
}
#endif

screen->kbdReleaseAllKeys = kbd_release_all_keys;
screen->setSingleWindow = set_single_window;
Expand Down
2 changes: 2 additions & 0 deletions src/x11vnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3888,10 +3888,12 @@ int main(int argc, char* argv[]) {
grab_buster = 0;
continue;
}
#if HAVE_SETDESKTOPSIZE
if (!strcmp(arg, "-setdesktopsize")) {
enable_setdesktopsize = 1;
continue;
}
#endif
if (!strcmp(arg, "-snapfb")) {
use_snapfb = 1;
continue;
Expand Down
8 changes: 2 additions & 6 deletions src/xrandr.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ int known_xrandr_mode(char *s) {
}
}

#if HAVE_SETDESKTOPSIZE
/* Set framebuffer size to w x h
* Does not alter physical resolution but scales desired framebuffer to physical display resolution */
rfbBool xrandr_set_scale_from(int w, int h)
{
#if HAVE_LIBXRANDR
XTransform transform;
XRRScreenResources *screens;
XRRCrtcInfo *crtcInfo;
Expand Down Expand Up @@ -446,16 +446,12 @@ rfbBool xrandr_set_scale_from(int w, int h)
the old size.) */

return TRUE;
#else
rfbLog("Cannot resize desktop. XRANDR support not compiled into x11vnc\n");
return FALSE;
#endif
}

/* Restore scaling to original size */
void xrandr_reset_scaling()
{
xrandr_set_scale_from(-1, -1);
}

#endif

0 comments on commit 2872260

Please sign in to comment.