[Xfce4-commits] [xfce/xfce4-settings] 01/01: display: Add profile support to the daemon

noreply at xfce.org noreply at xfce.org
Fri Mar 22 00:38:41 CET 2019


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfce4-settings.

commit 8d9f0402655904bede075ae3e1ed1883750c6f97
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Fri Mar 22 00:37:52 2019 +0100

    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.
---
 Makefile.am                                        |   1 +
 common/Makefile.am                                 |  35 +++++++
 .../display-settings => common}/display-name.c     |   2 +-
 common/display-profiles.c                          | 105 +++++++++++++++++++++
 common/display-profiles.h                          |  25 +++++
 {dialogs/display-settings => common}/edid-parse.c  |   0
 {dialogs/display-settings => common}/edid.h        |   0
 {dialogs/display-settings => common}/xfce-randr.c  |   0
 {dialogs/display-settings => common}/xfce-randr.h  |   0
 configure.ac.in                                    |   1 +
 dialogs/display-settings/Makefile.am               |   9 +-
 dialogs/display-settings/main.c                    |   2 +-
 xfsettingsd/Makefile.am                            |   3 +-
 xfsettingsd/displays.c                             |  40 ++++++++
 14 files changed, 213 insertions(+), 10 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 7c2f046..b62b2b8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,7 @@
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 
 SUBDIRS = \
+	common \
 	dialogs \
 	xfce4-settings-manager \
 	xfce4-settings-editor \
diff --git a/common/Makefile.am b/common/Makefile.am
new file mode 100644
index 0000000..e8d94df
--- /dev/null
+++ b/common/Makefile.am
@@ -0,0 +1,35 @@
+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)
diff --git a/dialogs/display-settings/display-name.c b/common/display-name.c
similarity index 99%
rename from dialogs/display-settings/display-name.c
rename to common/display-name.c
index 9b6b85e..26b2e2f 100644
--- a/dialogs/display-settings/display-name.c
+++ b/common/display-name.c
@@ -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
diff --git a/common/display-profiles.c b/common/display-profiles.c
new file mode 100644
index 0000000..40e7032
--- /dev/null
+++ b/common/display-profiles.c
@@ -0,0 +1,105 @@
+/*
+ *  Copyright (c) 2019 Simon Steinbeiß <simon at 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;
+}
diff --git a/common/display-profiles.h b/common/display-profiles.h
new file mode 100644
index 0000000..f56f32e
--- /dev/null
+++ b/common/display-profiles.h
@@ -0,0 +1,25 @@
+/*
+ *  Copyright (c) 2019 Simon Steinbeiß <simon at 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);
diff --git a/dialogs/display-settings/edid-parse.c b/common/edid-parse.c
similarity index 100%
rename from dialogs/display-settings/edid-parse.c
rename to common/edid-parse.c
diff --git a/dialogs/display-settings/edid.h b/common/edid.h
similarity index 100%
rename from dialogs/display-settings/edid.h
rename to common/edid.h
diff --git a/dialogs/display-settings/xfce-randr.c b/common/xfce-randr.c
similarity index 100%
rename from dialogs/display-settings/xfce-randr.c
rename to common/xfce-randr.c
diff --git a/dialogs/display-settings/xfce-randr.h b/common/xfce-randr.h
similarity index 100%
rename from dialogs/display-settings/xfce-randr.h
rename to common/xfce-randr.h
diff --git a/configure.ac.in b/configure.ac.in
index d7d5cf6..95fb1df 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -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
diff --git a/dialogs/display-settings/Makefile.am b/dialogs/display-settings/Makefile.am
index bd588a2..21c76eb 100644
--- a/dialogs/display-settings/Makefile.am
+++ b/dialogs/display-settings/Makefile.am
@@ -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
diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index 4939e81..214d4bc 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -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"
diff --git a/xfsettingsd/Makefile.am b/xfsettingsd/Makefile.am
index 0df1069..f2a0cae 100644
--- a/xfsettingsd/Makefile.am
+++ b/xfsettingsd/Makefile.am
@@ -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 += \
diff --git a/xfsettingsd/displays.c b/xfsettingsd/displays.c
index 8f536c9..32b5002 100644
--- a/xfsettingsd/displays.c
+++ b/xfsettingsd/displays.c
@@ -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 */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list