--- Makefile.am | 12 +++- configure.ac | 3 +- src/vdagent-display-config.c | 153 +++++++++++++++++++++++++++++++++++++++++++ src/vdagent-display-config.h | 27 ++++++++ src/vdagent.c | 8 +++ 5 files changed, 199 insertions(+), 4 deletions(-) create mode 100644 src/vdagent-display-config.c create mode 100644 src/vdagent-display-config.h diff --git a/Makefile.am b/Makefile.am index 74cc313..fa87420 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,9 +4,14 @@ NULL = bin_PROGRAMS = src/spice-vdagent sbin_PROGRAMS = src/spice-vdagentd -src_spice_vdagent_CFLAGS = $(X_CFLAGS) $(SPICE_CFLAGS) $(GLIB2_CFLAGS) -src_spice_vdagent_LDADD = $(X_LIBS) $(SPICE_LIBS) $(GLIB2_LIBS) -src_spice_vdagent_SOURCES = src/vdagent.c src/vdagent-x11.c src/vdagent-x11-randr.c src/vdagent-file-xfers.c src/udscs.c +src_spice_vdagent_CFLAGS = $(X_CFLAGS) $(SPICE_CFLAGS) $(GLIB2_CFLAGS) ${GIO2_CFLAGS} +src_spice_vdagent_LDADD = $(X_LIBS) $(SPICE_LIBS) $(GLIB2_LIBS) ${GIO2_LIBS} +src_spice_vdagent_SOURCES = src/vdagent.c \ + src/vdagent-x11.c \ + src/vdagent-x11-randr.c \ + src/vdagent-file-xfers.c \ + src/udscs.c \ + src/vdagent-display-config.c src_spice_vdagentd_CFLAGS = $(DBUS_CFLAGS) $(LIBSYSTEMD_LOGIN_CFLAGS) \ $(PCIACCESS_CFLAGS) $(SPICE_CFLAGS) $(GLIB2_CFLAGS) $(PIE_CFLAGS) @@ -34,6 +39,7 @@ noinst_HEADERS = src/glib-compat.h \ src/vdagent-virtio-port.h \ src/vdagent-x11.h \ src/vdagent-x11-priv.h \ + src/vdagent-display-config.h \ src/vdagentd-proto.h \ src/vdagentd-proto-strings.h \ src/vdagentd-uinput.h \ diff --git a/configure.ac b/configure.ac index a1ce6c0..93ddbda 100644 --- a/configure.ac +++ b/configure.ac @@ -76,7 +76,8 @@ AC_ARG_ENABLE([static-uinput], [enable_static_uinput="$enableval"], [enable_static_uinput="no"]) -PKG_CHECK_MODULES([GLIB2], [glib-2.0 >= 2.12]) +PKG_CHECK_MODULES([GLIB2], [glib-2.0 >= 2.26]) +PKG_CHECK_MODULES([GIO2], [gio-2.0 >= 2.26]) PKG_CHECK_MODULES(X, [xfixes xrandr >= 1.3 xinerama x11]) PKG_CHECK_MODULES(SPICE, [spice-protocol >= 0.12.5]) diff --git a/src/vdagent-display-config.c b/src/vdagent-display-config.c new file mode 100644 index 0000000..27e349f --- /dev/null +++ b/src/vdagent-display-config.c @@ -0,0 +1,153 @@ +/* vdagent-display-config.c vdagent display configuration code + + Copyright 2013 Red Hat, Inc. + + Authors: + Fedor Lyakhov <fedor.lyakhov@xxxxxxxxx> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <syslog.h> +#include <gio/gio.h> +#include <glib/gprintf.h> +#include <spice/vd_agent.h> + +#include "vdagent-display-config.h" + +/* TODO: Use get_settings_get_range to get correct enum nicks and values + This API function requires GIO 2.28 */ + +/** + * Changes wallpaper settings + * + * Enable: reset related settings to default + * + * Disable: + * 1. Set picture-options to 'none' (to remove wallpaper) + * 2. Set color-shading-type to 'solid' (to remove possible gradients) + * This makes desktop background to be solid color, the actual color is determined by + * primary-color field. It is set to #ffffff in case a wallpaper was used before. This function + * detects such case and resets the color to default. As drawing background isn't disabled, + * user can select a color via System settings. + */ +static void set_wallpaper(gboolean enable) +{ + syslog(LOG_DEBUG, "%s wallpaper", (enable) ? "Resetting" : "Disabling"); + GSettings *desktop_background_settings = g_settings_new("org.gnome.desktop.background"); + if (!desktop_background_settings) { + syslog(LOG_ERR, "No access to Gnome background settings"); + return; + } + + if (enable) { + g_settings_reset(desktop_background_settings, "picture-options"); + g_settings_reset(desktop_background_settings, "color-shading-type"); + g_settings_reset(desktop_background_settings, "primary-color"); + g_settings_reset(desktop_background_settings, "secondary-color"); + } else { + /* value 0 corresponds to 'none' */ + if (!g_settings_set_enum(desktop_background_settings, "picture-options", 0)) + syslog(LOG_ERR, "Cannot disable wallpaper"); + /* value 0 corresponds to 'solid' */ + if (!g_settings_set_enum(desktop_background_settings, "color-shading-type", 0)) + syslog(LOG_ERR, "Cannot enable solid background"); + const gchar *primary_color = + g_settings_get_string(desktop_background_settings, "primary-color"); + if (g_ascii_strcasecmp(primary_color, "#ffffff") == 0) + { + syslog(LOG_DEBUG, "Disable wallpaper: white background color detected - resetting"); + g_settings_reset(desktop_background_settings, "primary-color"); + g_settings_reset(desktop_background_settings, "secondary-color"); + } + g_free((gpointer)primary_color); + } +} + +/** + * Changes font smooth settings + * + * Enable: reset related settings to default + * + * Disable: + * 1. Set font antialiasing to 'none' + * 2. Set font hinting to 'slight' + * Disabling both antialiasing and hinting results in totally unusable font quality + * (at least for LCD displays) + */ +static void set_font_smooth(gboolean enable) +{ + syslog(LOG_DEBUG, "%s font smooth", (enable) ? "Resetting" : "Disabling"); + GSettings *xsettings = g_settings_new("org.gnome.settings-daemon.plugins.xsettings"); + if (!xsettings) { + syslog(LOG_ERR, "No access to xsettings plugin of Gnome settings daemon"); + return; + } + + if (enable) { + g_settings_reset(xsettings, "antialiasing"); + g_settings_reset(xsettings, "hinting"); + } else { + /* value 0 corresponds to 'none' */ + if (!g_settings_set_enum(xsettings, "antialiasing", 0)) + syslog(LOG_ERR, "Cannot disable font antialiasing"); + /* value 0 corresponds to 'slight' */ + if (!g_settings_set_enum(xsettings, "hinting", 1)) + syslog(LOG_ERR, "Cannot set font hinting to 'slight'"); + } +} + +/** + * Changes animation settings + * + * Enable: reset related settings to default + * + * Disable: set enable-animations to false + */ +static void set_animations(gboolean enable) +{ + syslog(LOG_DEBUG, "%s animations", (enable) ? "Resetting" : "Disabling"); + GSettings *desktop_interface_settings = g_settings_new("org.gnome.desktop.interface"); + if (!desktop_interface_settings) + { + syslog(LOG_ERR, "No access to Gnome interface settings"); + return; + } + + if (enable) { + g_settings_reset(desktop_interface_settings, "enable-animations"); + } else { + if (!g_settings_set_boolean(desktop_interface_settings, "enable-animations", FALSE)) + syslog(LOG_ERR, "Cannot disable animations"); + } +} + +void vdagent_set_display_config(VDAgentDisplayConfig *display_config) +{ + if (display_config->flags & VD_AGENT_DISPLAY_CONFIG_FLAG_DISABLE_WALLPAPER) + set_wallpaper(FALSE); + if (display_config->flags & VD_AGENT_DISPLAY_CONFIG_FLAG_DISABLE_FONT_SMOOTH) + set_font_smooth(FALSE); + if (display_config->flags & VD_AGENT_DISPLAY_CONFIG_FLAG_DISABLE_ANIMATION) + set_animations(FALSE); + if (display_config->flags & VD_AGENT_DISPLAY_CONFIG_FLAG_SET_COLOR_DEPTH) + syslog(LOG_DEBUG, "Changing color depth isn't supported"); + if (!display_config->flags) { + /* TODO: Treat empty flags as request to reset display config to default + set_wallpaper(TRUE); + set_font_smooth(TRUE); + set_animations(TRUE); + */ + } +} diff --git a/src/vdagent-display-config.h b/src/vdagent-display-config.h new file mode 100644 index 0000000..369c4ea --- /dev/null +++ b/src/vdagent-display-config.h @@ -0,0 +1,27 @@ +/* vdagent-dbus.h vdagent display configuration header file + + Copyright 2013 Red Hat, Inc. + + Authors: + Fedor Lyakhov <fedor.lyakhov@xxxxxxxxx> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef __VDAGENT_DISPLAY_CONFIG_H +#define __VDAGENT_DISPLAY_CONFIG_H + +struct VDAgentDisplayConfig; +void vdagent_set_display_config(VDAgentDisplayConfig *display_config); + +#endif \ No newline at end of file diff --git a/src/vdagent.c b/src/vdagent.c index 9e238d3..0f710af 100644 --- a/src/vdagent.c +++ b/src/vdagent.c @@ -35,12 +35,14 @@ #include <sys/stat.h> #include <spice/vd_agent.h> #include <glib.h> +#include <glib-object.h> #include "udscs.h" #include "vdagentd-proto.h" #include "vdagentd-proto-strings.h" #include "vdagent-x11.h" #include "vdagent-file-xfers.h" +#include "vdagent-display-config.h" static const char *portdev = "/dev/virtio-ports/com.redhat.spice.0"; static int debug = 0; @@ -107,6 +109,10 @@ void daemon_read_complete(struct udscs_connection **connp, vdagent_file_xfers = vdagent_file_xfers_create(client, fx_dir, fx_open_dir, debug); break; + case VDAGENTD_DISPLAY_CONFIG: + vdagent_set_display_config((VDAgentDisplayConfig *)data); + free(data); + break; default: syslog(LOG_ERR, "Unknown message from vdagentd type: %d, ignoring", header->type); @@ -234,6 +240,8 @@ int main(int argc, char *argv[]) if (do_daemonize) daemonize(); + g_type_init(); + reconnect: if (version_mismatch) { syslog(LOG_INFO, "Version mismatch, restarting"); -- 1.8.1.4 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel