Commit 8d9f0402 authored by Simon Steinbeiss's avatar Simon Steinbeiss

display: Add profile support to the daemon

If there is one matching profile, the daemon will immediately enable it
if the option is set in the dialog.
If there is more than one matching profile, the minimal dialog will be
shown and the first profile will be enabled.
parent 40410bc3
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
SUBDIRS = \
common \
dialogs \
xfce4-settings-manager \
xfce4-settings-editor \
......
AM_CPPFLAGS = \
-I${top_srcdir} \
-DPNP_IDS=\"$(PNP_IDS)\" \
$(PLATFORM_CPPFLAGS)
noinst_LTLIBRARIES = \
libxfce4-settings.la
libxfce4_settings_la_SOURCES = \
display-name.c \
display-profiles.c \
display-profiles.h \
edid-parse.c \
edid.h \
xfce-randr.c \
xfce-randr.h
libxfce4_settings_la_CFLAGS = \
$(GTK_CFLAGS) \
$(LIBXFCE4UTIL_CFLAGS) \
$(XFCONF_CFLAGS) \
$(XRANDR_CFLAGS) \
$(LIBX11_CFLAGS) \
$(PLATFORM_CFLAGS)
libxfce4_settings_la_LDFLAGS = \
-no-undefined \
$(PLATFORM_LDFLAGS)
libxfce4_settings_la_LIBADD = \
$(GTK_LIBS) \
$(XFCONF_LIBS) \
$(LIBX11_LIBS) -lm \
$(XRANDR_LIBS) \
$(GLIB_LIBS)
......@@ -35,7 +35,7 @@
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "edid.h"
#include "common/edid.h"
typedef struct Vendor Vendor;
struct Vendor
......
/*
* Copyright (c) 2019 Simon Steinbeiß <simon@xfce.org>
*
* 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 2 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 Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <glib.h>
#include <display-profiles.h>
GList*
display_settings_get_profiles (XfceRandr *xfce_randr, XfconfChannel *channel)
{
GHashTable *properties;
GList *channel_contents, *profiles = NULL, *current;
guint m;
gchar *edid, *output_info_name, **display_infos;
properties = xfconf_channel_get_properties (channel, NULL);
channel_contents = g_hash_table_get_keys (properties);
display_infos = g_new0 (gchar *, xfce_randr->noutput);
/* get all display connectors in combination with their respective edids */
for (m = 0; m < xfce_randr->noutput; ++m)
{
edid = xfce_randr_get_edid (xfce_randr, m);
output_info_name = xfce_randr_get_output_info_name (xfce_randr, m);
display_infos[m] = g_strdup_printf ("%s/%s", output_info_name, edid);
}
/* get all profiles */
current = g_list_first (channel_contents);
while (current)
{
gchar* buf = strtok (current->data, "/");
gboolean profile_match = TRUE;
/* walk all connected displays and filter for edids matching the current profile */
for (m = 0; m < xfce_randr->noutput; ++m)
{
gchar *property;
gchar *current_edid, *output_edid;
gchar **display_infos_tokens;
display_infos_tokens = g_strsplit (display_infos[m], "/", 2);
property = g_strdup_printf ("/%s/%s/EDID", buf, display_infos_tokens[0]);
current_edid = xfconf_channel_get_string (channel, property, NULL);
output_edid = g_strdup_printf ("%s/%s", display_infos_tokens[0], current_edid);
if (current_edid)
{
if (g_strcmp0 (display_infos[m], output_edid) != 0)
profile_match = FALSE;
}
else
{
profile_match = FALSE;
}
g_free (property);
g_free (current_edid);
g_free (output_edid);
g_strfreev (display_infos_tokens);
}
/* filter the content of the combobox to only matching profiles and exclude "Notify", "Default" and "Schemes" */
if (!g_list_find_custom (profiles, (char*) buf, (GCompareFunc) strcmp) &&
strcmp (buf, "Notify") &&
strcmp (buf, "Default") &&
strcmp (buf, "Schemes") &&
profile_match)
{
profiles = g_list_prepend (profiles, buf);
}
/* else don't add the profile to the list */
current = g_list_next (current);
}
for (m = 0; m < xfce_randr->noutput; ++m)
{
g_free (display_infos[m]);
}
g_free (display_infos);
g_list_free (channel_contents);
return profiles;
}
/*
* Copyright (c) 2019 Simon Steinbeiß <simon@xfce.org>
*
* 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 2 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 Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <glib.h>
#include <xfconf/xfconf.h>
#include "xfce-randr.h"
GList* display_settings_get_profiles (XfceRandr *xfce_randr, XfconfChannel *channel);
......@@ -257,6 +257,7 @@ AC_SUBST([PLATFORM_LDFLAGS])
AC_OUTPUT([
Makefile
po/Makefile.in
common/Makefile
dialogs/Makefile
dialogs/appearance-settings/Makefile
dialogs/accessibility-settings/Makefile
......
......@@ -4,7 +4,6 @@ AM_CPPFLAGS = \
-DSRCDIR=\"$(top_srcdir)\" \
-DLOCALEDIR=\"$(localedir)\" \
-DG_LOG_DOMAIN=\"xfce4-display-settings\" \
-DPNP_IDS=\"$(PNP_IDS)\" \
$(PLATFORM_CPPFLAGS)
bin_PROGRAMS = \
......@@ -12,15 +11,10 @@ bin_PROGRAMS = \
xfce4_display_settings_SOURCES = \
main.c \
xfce-randr.c \
xfce-randr.h \
confirmation-dialog_ui.h \
display-dialog_ui.h \
minimal-display-dialog_ui.h \
identity-popup_ui.h \
display-name.c \
edid-parse.c \
edid.h \
scrollarea.c \
scrollarea.h \
foo-marshal.c \
......@@ -46,7 +40,8 @@ xfce4_display_settings_LDADD = \
$(EXO_LIBS) \
$(LIBX11_LIBS) -lm \
$(XRANDR_LIBS) \
$(GLIB_LIBS)
$(GLIB_LIBS) \
$(top_builddir)/common/libxfce4-settings.la
# Optional support for colord
if HAVE_COLORD
......
......@@ -44,7 +44,7 @@
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#include "xfce-randr.h"
#include <common/xfce-randr.h>
#include "display-dialog_ui.h"
#include "confirmation-dialog_ui.h"
#include "minimal-display-dialog_ui.h"
......
......@@ -93,7 +93,8 @@ xfsettingsd_CFLAGS += \
$(XRANDR_CFLAGS)
xfsettingsd_LDADD += \
$(XRANDR_LIBS)
$(XRANDR_LIBS) \
$(top_builddir)/common/libxfce4-settings.la
if HAVE_UPOWERGLIB
xfsettingsd_SOURCES += \
......
......@@ -36,6 +36,9 @@
#include <X11/extensions/Xrandr.h>
#include "common/display-profiles.h"
#include "common/xfce-randr.h"
#include "debug.h"
#include "displays.h"
#ifdef HAVE_UPOWERGLIB
......@@ -424,6 +427,13 @@ xfce_displays_helper_screen_on_event (GdkXEvent *xevent,
gint j;
guint n, m, nactive = 0;
gboolean found = FALSE, changed = FALSE;
GList *profiles = NULL;
GdkDisplay *display;
GError *error = NULL;
gpointer *profile;
XfceRandr *xfce_randr;
gchar *profile_name;
gchar *property;
if (!e)
return GDK_FILTER_CONTINUE;
......@@ -440,6 +450,36 @@ xfce_displays_helper_screen_on_event (GdkXEvent *xevent,
xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Noutput: before = %d, after = %d.",
old_outputs->len, helper->outputs->len);
/* Check if we have a matching profile and apply it if there's only one */
if (xfconf_channel_get_bool (helper->channel, "/AutoEnableProfiles", TRUE))
{
display = gdk_display_get_default ();
xfce_randr = xfce_randr_new (display, &error);
profiles = display_settings_get_profiles (xfce_randr, helper->channel);
if (xfce_randr)
xfce_randr_free (xfce_randr);
if (g_list_length (profiles) == 1)
{
profile = g_list_nth_data (profiles, 0);
xfce_randr_apply (xfce_randr, (gchar *)profile, helper->channel);
property = g_strdup_printf ("/%s", (gchar *) profile);
profile_name = xfconf_channel_get_string (helper->channel, property, NULL);
xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Applied the only matching display profile: %s", profile_name);
g_free (profile_name);
g_free (property);
return GDK_FILTER_CONTINUE;
}
else if (profiles == NULL)
{
xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "No matching display profiles found.");
}
else
{
xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "Found %d matching display profiles.", g_list_length (profiles));
}
}
if (old_outputs->len > helper->outputs->len)
{
/* Diff the new and old output list to find removed outputs */
......
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