2001-04-02 23:33:47 +00:00
|
|
|
/*
|
2007-01-02 19:07:03 +00:00
|
|
|
* Copyright © 2001, 2007 Red Hat, Inc.
|
2001-04-02 23:33:47 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of Red Hat not be used in advertising or
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. Red Hat makes no representations about the
|
|
|
|
* suitability of this software for any purpose. It is provided "as is"
|
|
|
|
* without express or implied warranty.
|
|
|
|
*
|
|
|
|
* RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
|
|
|
|
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Author: Owen Taylor, Red Hat, Inc.
|
|
|
|
*/
|
2010-10-15 02:05:51 +00:00
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2010-10-15 02:05:51 +00:00
|
|
|
|
|
|
|
#include "xsettings-client.h"
|
|
|
|
|
2013-02-10 00:20:38 +00:00
|
|
|
#include <gdk/x11/gdkx11display.h>
|
2013-02-15 18:14:25 +00:00
|
|
|
#include <gdk/x11/gdkx11property.h>
|
2013-02-10 00:20:38 +00:00
|
|
|
#include <gdk/x11/gdkx11screen.h>
|
2018-03-20 10:46:11 +00:00
|
|
|
#include <gdk/x11/gdkx11surface.h>
|
2013-02-18 16:16:57 +00:00
|
|
|
#include <gdk/x11/gdkprivate-x11.h>
|
2018-02-07 05:00:01 +00:00
|
|
|
#include <gdk/x11/gdkdisplay-x11.h>
|
2013-02-14 14:06:56 +00:00
|
|
|
#include <gdk/x11/gdkscreen-x11.h>
|
2013-02-10 00:06:58 +00:00
|
|
|
|
2013-02-12 15:31:03 +00:00
|
|
|
#include <gdkinternals.h>
|
|
|
|
|
2001-04-02 23:33:47 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xmd.h> /* For CARD16 */
|
|
|
|
|
2017-10-30 13:47:26 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GDK_SETTING_ACTION_NEW,
|
|
|
|
GDK_SETTING_ACTION_CHANGED,
|
|
|
|
GDK_SETTING_ACTION_DELETED
|
|
|
|
} GdkSettingAction;
|
|
|
|
|
2013-02-14 14:06:56 +00:00
|
|
|
#include "gdksettings.c"
|
|
|
|
|
2013-02-16 23:37:09 +00:00
|
|
|
/* Types of settings possible. Enum values correspond to
|
|
|
|
* protocol values.
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
XSETTINGS_TYPE_INT = 0,
|
|
|
|
XSETTINGS_TYPE_STRING = 1,
|
|
|
|
XSETTINGS_TYPE_COLOR = 2
|
|
|
|
} XSettingsType;
|
|
|
|
|
2013-02-12 15:47:45 +00:00
|
|
|
typedef struct _XSettingsBuffer XSettingsBuffer;
|
|
|
|
|
|
|
|
struct _XSettingsBuffer
|
|
|
|
{
|
|
|
|
char byte_order;
|
|
|
|
size_t len;
|
|
|
|
unsigned char *data;
|
|
|
|
unsigned char *pos;
|
|
|
|
};
|
|
|
|
|
2013-02-14 14:06:56 +00:00
|
|
|
static void
|
2013-02-19 13:31:03 +00:00
|
|
|
gdk_xsettings_notify (GdkX11Screen *x11_screen,
|
|
|
|
const char *name,
|
|
|
|
GdkSettingAction action)
|
2013-02-14 14:06:56 +00:00
|
|
|
{
|
2017-11-01 23:41:45 +00:00
|
|
|
gdk_display_setting_changed (x11_screen->display, name);
|
2013-02-14 14:06:56 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 23:30:06 +00:00
|
|
|
static gboolean
|
|
|
|
value_equal (const GValue *value_a,
|
|
|
|
const GValue *value_b)
|
|
|
|
{
|
|
|
|
if (G_VALUE_TYPE (value_a) != G_VALUE_TYPE (value_b))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (G_VALUE_TYPE (value_a))
|
|
|
|
{
|
|
|
|
case G_TYPE_INT:
|
|
|
|
return g_value_get_int (value_a) == g_value_get_int (value_b);
|
|
|
|
case XSETTINGS_TYPE_COLOR:
|
|
|
|
return gdk_rgba_equal (g_value_get_boxed (value_a), g_value_get_boxed (value_b));
|
|
|
|
case G_TYPE_STRING:
|
|
|
|
return g_str_equal (g_value_get_string (value_a), g_value_get_string (value_b));
|
|
|
|
default:
|
|
|
|
g_warning ("unable to compare values of type %s", g_type_name (G_VALUE_TYPE (value_a)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-02 23:33:47 +00:00
|
|
|
static void
|
2013-02-19 13:31:03 +00:00
|
|
|
notify_changes (GdkX11Screen *x11_screen,
|
|
|
|
GHashTable *old_list)
|
2001-04-02 23:33:47 +00:00
|
|
|
{
|
2013-01-26 21:47:09 +00:00
|
|
|
GHashTableIter iter;
|
2013-02-16 23:30:06 +00:00
|
|
|
GValue *setting, *old_setting;
|
2013-02-12 19:10:23 +00:00
|
|
|
const char *name;
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2013-02-19 13:31:03 +00:00
|
|
|
if (x11_screen->xsettings != NULL)
|
2001-04-02 23:33:47 +00:00
|
|
|
{
|
2013-02-19 13:31:03 +00:00
|
|
|
g_hash_table_iter_init (&iter, x11_screen->xsettings);
|
2013-02-12 19:10:23 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer*) &setting))
|
2001-04-02 23:33:47 +00:00
|
|
|
{
|
2013-02-12 19:10:23 +00:00
|
|
|
old_setting = old_list ? g_hash_table_lookup (old_list, name) : NULL;
|
2013-01-26 21:47:09 +00:00
|
|
|
|
|
|
|
if (old_setting == NULL)
|
2013-02-19 13:31:03 +00:00
|
|
|
gdk_xsettings_notify (x11_screen, name, GDK_SETTING_ACTION_NEW);
|
2013-02-16 23:30:06 +00:00
|
|
|
else if (!value_equal (setting, old_setting))
|
2013-02-19 13:31:03 +00:00
|
|
|
gdk_xsettings_notify (x11_screen, name, GDK_SETTING_ACTION_CHANGED);
|
2013-01-26 21:47:09 +00:00
|
|
|
|
|
|
|
/* remove setting from old_list */
|
|
|
|
if (old_setting != NULL)
|
2013-02-12 19:10:23 +00:00
|
|
|
g_hash_table_remove (old_list, name);
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|
2013-01-26 21:47:09 +00:00
|
|
|
}
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2013-01-26 21:47:09 +00:00
|
|
|
if (old_list != NULL)
|
|
|
|
{
|
|
|
|
/* old_list now contains only deleted settings */
|
|
|
|
g_hash_table_iter_init (&iter, old_list);
|
2013-02-12 19:10:23 +00:00
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer*) &old_setting))
|
2013-02-19 13:31:03 +00:00
|
|
|
gdk_xsettings_notify (x11_screen, name, GDK_SETTING_ACTION_DELETED);
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BYTES_LEFT(buffer) ((buffer)->data + (buffer)->len - (buffer)->pos)
|
|
|
|
|
2013-02-12 18:28:41 +00:00
|
|
|
#define return_if_fail_bytes(buffer, n_bytes) G_STMT_START{ \
|
|
|
|
if (BYTES_LEFT (buffer) < (n_bytes)) \
|
2013-02-12 18:35:46 +00:00
|
|
|
{ \
|
2018-06-11 15:14:23 +00:00
|
|
|
g_warning ("Invalid XSETTINGS property (read off end: Expected %u bytes, only %"G_GSIZE_FORMAT" left", \
|
2013-02-12 18:35:46 +00:00
|
|
|
(n_bytes), BYTES_LEFT (buffer)); \
|
2013-02-12 18:44:28 +00:00
|
|
|
return FALSE; \
|
2013-02-12 18:35:46 +00:00
|
|
|
} \
|
2013-02-12 18:28:41 +00:00
|
|
|
}G_STMT_END
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
static gboolean
|
2001-04-02 23:33:47 +00:00
|
|
|
fetch_card16 (XSettingsBuffer *buffer,
|
|
|
|
CARD16 *result)
|
|
|
|
{
|
|
|
|
CARD16 x;
|
|
|
|
|
2013-02-12 18:28:41 +00:00
|
|
|
return_if_fail_bytes (buffer, 2);
|
2001-04-02 23:33:47 +00:00
|
|
|
|
|
|
|
x = *(CARD16 *)buffer->pos;
|
|
|
|
buffer->pos += 2;
|
|
|
|
|
2013-02-02 18:10:02 +00:00
|
|
|
if (buffer->byte_order == MSBFirst)
|
|
|
|
*result = GUINT16_FROM_BE (x);
|
2001-04-02 23:33:47 +00:00
|
|
|
else
|
2013-02-02 18:10:02 +00:00
|
|
|
*result = GUINT16_FROM_LE (x);
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
return TRUE;
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
static gboolean
|
2001-04-02 23:33:47 +00:00
|
|
|
fetch_ushort (XSettingsBuffer *buffer,
|
|
|
|
unsigned short *result)
|
|
|
|
{
|
|
|
|
CARD16 x;
|
2013-02-12 18:44:28 +00:00
|
|
|
gboolean r;
|
2001-04-02 23:33:47 +00:00
|
|
|
|
|
|
|
r = fetch_card16 (buffer, &x);
|
2013-02-12 18:44:28 +00:00
|
|
|
if (r)
|
2001-04-02 23:33:47 +00:00
|
|
|
*result = x;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
static gboolean
|
2001-04-02 23:33:47 +00:00
|
|
|
fetch_card32 (XSettingsBuffer *buffer,
|
|
|
|
CARD32 *result)
|
|
|
|
{
|
|
|
|
CARD32 x;
|
|
|
|
|
2013-02-12 18:28:41 +00:00
|
|
|
return_if_fail_bytes (buffer, 4);
|
2001-04-02 23:33:47 +00:00
|
|
|
|
|
|
|
x = *(CARD32 *)buffer->pos;
|
|
|
|
buffer->pos += 4;
|
|
|
|
|
2013-02-02 18:10:02 +00:00
|
|
|
if (buffer->byte_order == MSBFirst)
|
|
|
|
*result = GUINT32_FROM_BE (x);
|
2001-04-02 23:33:47 +00:00
|
|
|
else
|
2013-02-02 18:10:02 +00:00
|
|
|
*result = GUINT32_FROM_LE (x);
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
return TRUE;
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
static gboolean
|
2001-04-02 23:33:47 +00:00
|
|
|
fetch_card8 (XSettingsBuffer *buffer,
|
|
|
|
CARD8 *result)
|
|
|
|
{
|
2013-02-12 18:28:41 +00:00
|
|
|
return_if_fail_bytes (buffer, 1);
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2002-04-12 21:52:57 +00:00
|
|
|
*result = *(CARD8 *)buffer->pos;
|
2001-04-02 23:33:47 +00:00
|
|
|
buffer->pos += 1;
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
return TRUE;
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define XSETTINGS_PAD(n,m) ((n + m - 1) & (~(m-1)))
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
static gboolean
|
2013-02-12 17:45:03 +00:00
|
|
|
fetch_string (XSettingsBuffer *buffer,
|
|
|
|
guint length,
|
|
|
|
char **result)
|
|
|
|
{
|
|
|
|
guint pad_len;
|
|
|
|
|
|
|
|
pad_len = XSETTINGS_PAD (length, 4);
|
2013-02-12 18:28:41 +00:00
|
|
|
if (pad_len < length) /* guard against overflow */
|
2013-02-12 18:35:46 +00:00
|
|
|
{
|
|
|
|
g_warning ("Invalid XSETTINGS property (overflow in string length)");
|
2013-02-12 18:44:28 +00:00
|
|
|
return FALSE;
|
2013-02-12 18:35:46 +00:00
|
|
|
}
|
2013-02-12 17:45:03 +00:00
|
|
|
|
2013-02-12 18:28:41 +00:00
|
|
|
return_if_fail_bytes (buffer, pad_len);
|
|
|
|
|
2013-02-12 17:45:03 +00:00
|
|
|
*result = g_strndup ((char *) buffer->pos, length);
|
|
|
|
buffer->pos += pad_len;
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
return TRUE;
|
2013-02-12 17:45:03 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 23:30:06 +00:00
|
|
|
static void
|
|
|
|
free_value (gpointer data)
|
|
|
|
{
|
|
|
|
GValue *value = data;
|
|
|
|
|
|
|
|
g_value_unset (value);
|
|
|
|
g_free (value);
|
|
|
|
}
|
|
|
|
|
2013-02-02 18:22:04 +00:00
|
|
|
static GHashTable *
|
2001-04-02 23:33:47 +00:00
|
|
|
parse_settings (unsigned char *data,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
XSettingsBuffer buffer;
|
2013-02-02 18:22:04 +00:00
|
|
|
GHashTable *settings = NULL;
|
2001-04-02 23:33:47 +00:00
|
|
|
CARD32 serial;
|
|
|
|
CARD32 n_entries;
|
|
|
|
CARD32 i;
|
2013-02-16 23:30:06 +00:00
|
|
|
GValue *value = NULL;
|
2013-02-14 16:20:26 +00:00
|
|
|
char *x_name = NULL;
|
|
|
|
const char *gdk_name;
|
2001-04-02 23:33:47 +00:00
|
|
|
|
|
|
|
buffer.pos = buffer.data = data;
|
|
|
|
buffer.len = len;
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
if (!fetch_card8 (&buffer, (unsigned char *)&buffer.byte_order))
|
|
|
|
goto out;
|
|
|
|
|
2001-04-02 23:33:47 +00:00
|
|
|
if (buffer.byte_order != MSBFirst &&
|
|
|
|
buffer.byte_order != LSBFirst)
|
|
|
|
{
|
2013-02-12 18:35:46 +00:00
|
|
|
g_warning ("Invalid XSETTINGS property (unknown byte order %u)", buffer.byte_order);
|
2001-04-02 23:33:47 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.pos += 3;
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
if (!fetch_card32 (&buffer, &serial) ||
|
|
|
|
!fetch_card32 (&buffer, &n_entries))
|
2001-04-02 23:33:47 +00:00
|
|
|
goto out;
|
|
|
|
|
2018-06-11 15:14:23 +00:00
|
|
|
GDK_NOTE (SETTINGS, g_message ("reading %lu settings (serial %lu byte order %u)",
|
|
|
|
(unsigned long)n_entries, (unsigned long)serial, buffer.byte_order));
|
2013-02-12 15:31:03 +00:00
|
|
|
|
2001-04-02 23:33:47 +00:00
|
|
|
for (i = 0; i < n_entries; i++)
|
|
|
|
{
|
|
|
|
CARD8 type;
|
|
|
|
CARD16 name_len;
|
|
|
|
CARD32 v_int;
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
if (!fetch_card8 (&buffer, &type))
|
2001-04-02 23:33:47 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
buffer.pos += 1;
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
if (!fetch_card16 (&buffer, &name_len))
|
2001-04-02 23:33:47 +00:00
|
|
|
goto out;
|
|
|
|
|
2013-02-14 16:20:26 +00:00
|
|
|
if (!fetch_string (&buffer, name_len, &x_name) ||
|
2013-02-12 18:44:28 +00:00
|
|
|
/* last change serial (we ignore it) */
|
|
|
|
!fetch_card32 (&buffer, &v_int))
|
2001-04-02 23:33:47 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case XSETTINGS_TYPE_INT:
|
2013-02-12 18:44:28 +00:00
|
|
|
if (!fetch_card32 (&buffer, &v_int))
|
2001-04-02 23:33:47 +00:00
|
|
|
goto out;
|
|
|
|
|
2013-02-16 23:30:06 +00:00
|
|
|
value = g_new0 (GValue, 1);
|
|
|
|
g_value_init (value, G_TYPE_INT);
|
|
|
|
g_value_set_int (value, (gint32) v_int);
|
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_NOTE (SETTINGS, g_message (" %s = %d", x_name, (gint32) v_int));
|
2001-04-02 23:33:47 +00:00
|
|
|
break;
|
|
|
|
case XSETTINGS_TYPE_STRING:
|
2013-02-16 23:30:06 +00:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (!fetch_card32 (&buffer, &v_int) ||
|
|
|
|
!fetch_string (&buffer, v_int, &s))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
value = g_new0 (GValue, 1);
|
|
|
|
g_value_init (value, G_TYPE_STRING);
|
|
|
|
g_value_take_string (value, s);
|
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_NOTE (SETTINGS, g_message (" %s = \"%s\"", x_name, s));
|
2013-02-16 23:30:06 +00:00
|
|
|
}
|
2001-04-02 23:33:47 +00:00
|
|
|
break;
|
|
|
|
case XSETTINGS_TYPE_COLOR:
|
2013-02-16 23:30:06 +00:00
|
|
|
{
|
|
|
|
unsigned short red, green, blue, alpha;
|
|
|
|
GdkRGBA rgba;
|
|
|
|
|
|
|
|
if (!fetch_ushort (&buffer, &red) ||
|
|
|
|
!fetch_ushort (&buffer, &green) ||
|
|
|
|
!fetch_ushort (&buffer, &blue) ||
|
|
|
|
!fetch_ushort (&buffer, &alpha))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
rgba.red = red / 65535.0;
|
|
|
|
rgba.green = green / 65535.0;
|
|
|
|
rgba.blue = blue / 65535.0;
|
|
|
|
rgba.alpha = alpha / 65535.0;
|
|
|
|
|
|
|
|
value = g_new0 (GValue, 1);
|
|
|
|
g_value_init (value, G_TYPE_STRING);
|
|
|
|
g_value_set_boxed (value, &rgba);
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_NOTE (SETTINGS, g_message (" %s = #%02X%02X%02X%02X", x_name, alpha,red, green, blue));
|
2013-02-16 23:30:06 +00:00
|
|
|
}
|
2001-04-02 23:33:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Quietly ignore unknown types */
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_NOTE (SETTINGS, g_message (" %s = ignored (unknown type %u)", x_name, type));
|
2001-04-02 23:33:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-02-14 16:20:26 +00:00
|
|
|
gdk_name = gdk_from_xsettings_name (x_name);
|
|
|
|
g_free (x_name);
|
|
|
|
x_name = NULL;
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2013-02-14 16:20:26 +00:00
|
|
|
if (gdk_name == NULL)
|
|
|
|
{
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_NOTE (SETTINGS, g_message (" ==> unknown to GTK"));
|
2014-01-13 01:12:39 +00:00
|
|
|
free_value (value);
|
2013-02-14 16:20:26 +00:00
|
|
|
}
|
|
|
|
else
|
2013-02-02 18:22:04 +00:00
|
|
|
{
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_NOTE (SETTINGS, g_message (" ==> storing as '%s'", gdk_name));
|
2013-02-14 16:20:26 +00:00
|
|
|
|
|
|
|
if (settings == NULL)
|
|
|
|
settings = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
NULL,
|
2013-02-16 23:30:06 +00:00
|
|
|
free_value);
|
2013-02-14 16:20:26 +00:00
|
|
|
|
|
|
|
if (g_hash_table_lookup (settings, gdk_name) != NULL)
|
|
|
|
{
|
|
|
|
g_warning ("Invalid XSETTINGS property (Duplicate entry for '%s')", gdk_name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-02-16 23:30:06 +00:00
|
|
|
g_hash_table_insert (settings, (gpointer) gdk_name, value);
|
2013-02-02 18:22:04 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 23:30:06 +00:00
|
|
|
value = NULL;
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
return settings;
|
|
|
|
|
2001-04-02 23:33:47 +00:00
|
|
|
out:
|
|
|
|
|
2013-02-16 23:30:06 +00:00
|
|
|
if (value)
|
|
|
|
free_value (value);
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
if (settings)
|
|
|
|
g_hash_table_unref (settings);
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2013-02-14 16:20:26 +00:00
|
|
|
g_free (x_name);
|
|
|
|
|
2013-02-12 18:44:28 +00:00
|
|
|
return NULL;
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-02-19 13:31:03 +00:00
|
|
|
read_settings (GdkX11Screen *x11_screen,
|
|
|
|
gboolean do_notify)
|
2001-04-02 23:33:47 +00:00
|
|
|
{
|
2017-10-30 21:01:18 +00:00
|
|
|
GdkDisplay *display = x11_screen->display;
|
2014-07-11 20:42:38 +00:00
|
|
|
|
2001-04-02 23:33:47 +00:00
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long n_items;
|
|
|
|
unsigned long bytes_after;
|
|
|
|
unsigned char *data;
|
|
|
|
int result;
|
|
|
|
|
2013-02-19 13:31:03 +00:00
|
|
|
GHashTable *old_list = x11_screen->xsettings;
|
2013-06-27 20:45:40 +00:00
|
|
|
GValue value = G_VALUE_INIT;
|
2013-06-28 11:23:45 +00:00
|
|
|
GValue *setting, *copy;
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2013-02-19 13:31:03 +00:00
|
|
|
x11_screen->xsettings = NULL;
|
2004-02-10 18:51:19 +00:00
|
|
|
|
2017-08-22 19:08:14 +00:00
|
|
|
if (x11_screen->xsettings_manager_window != 0)
|
2001-04-02 23:33:47 +00:00
|
|
|
{
|
2013-02-15 18:14:25 +00:00
|
|
|
Atom xsettings_atom = gdk_x11_get_xatom_by_name_for_display (display, "_XSETTINGS_SETTINGS");
|
|
|
|
|
|
|
|
gdk_x11_display_error_trap_push (display);
|
2013-02-16 22:59:07 +00:00
|
|
|
result = XGetWindowProperty (gdk_x11_display_get_xdisplay (display),
|
2017-08-22 19:08:14 +00:00
|
|
|
x11_screen->xsettings_manager_window,
|
2013-02-15 18:14:25 +00:00
|
|
|
xsettings_atom, 0, LONG_MAX,
|
|
|
|
False, xsettings_atom,
|
2004-02-10 18:51:19 +00:00
|
|
|
&type, &format, &n_items, &bytes_after, &data);
|
2013-02-15 18:14:25 +00:00
|
|
|
gdk_x11_display_error_trap_pop_ignored (display);
|
2004-02-10 18:51:19 +00:00
|
|
|
|
2004-02-27 00:52:45 +00:00
|
|
|
if (result == Success && type != None)
|
2001-04-02 23:33:47 +00:00
|
|
|
{
|
2013-02-15 18:14:25 +00:00
|
|
|
if (type != xsettings_atom)
|
2004-02-27 00:52:45 +00:00
|
|
|
{
|
2013-02-15 18:18:11 +00:00
|
|
|
g_warning ("Invalid type for XSETTINGS property: %s", gdk_x11_get_xatom_name_for_display (display, type));
|
2004-02-27 00:52:45 +00:00
|
|
|
}
|
2004-02-27 01:31:16 +00:00
|
|
|
else if (format != 8)
|
2004-02-10 18:51:19 +00:00
|
|
|
{
|
2013-02-15 18:18:11 +00:00
|
|
|
g_warning ("Invalid format for XSETTINGS property: %d", format);
|
2004-02-10 18:51:19 +00:00
|
|
|
}
|
|
|
|
else
|
2013-02-19 13:31:03 +00:00
|
|
|
x11_screen->xsettings = parse_settings (data, n_items);
|
2004-02-10 18:51:19 +00:00
|
|
|
|
|
|
|
XFree (data);
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-28 11:23:45 +00:00
|
|
|
/* Since we support scaling we look at the specific Gdk/UnscaledDPI
|
|
|
|
setting if it exists and use that instead of Xft/DPI if it is set */
|
2018-03-20 11:05:26 +00:00
|
|
|
if (x11_screen->xsettings && !x11_screen->fixed_surface_scale)
|
2013-06-28 11:23:45 +00:00
|
|
|
{
|
2013-07-01 18:50:44 +00:00
|
|
|
setting = g_hash_table_lookup (x11_screen->xsettings, "gdk-unscaled-dpi");
|
|
|
|
if (setting)
|
|
|
|
{
|
|
|
|
copy = g_new0 (GValue, 1);
|
|
|
|
g_value_init (copy, G_VALUE_TYPE (setting));
|
|
|
|
g_value_copy (setting, copy);
|
|
|
|
g_hash_table_insert (x11_screen->xsettings,
|
2017-10-06 14:01:19 +00:00
|
|
|
(gpointer) "gtk-xft-dpi", copy);
|
2013-07-01 18:50:44 +00:00
|
|
|
}
|
2013-06-28 11:23:45 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 14:09:49 +00:00
|
|
|
if (do_notify)
|
2013-02-19 13:31:03 +00:00
|
|
|
notify_changes (x11_screen, old_list);
|
2013-02-02 18:22:04 +00:00
|
|
|
if (old_list)
|
|
|
|
g_hash_table_unref (old_list);
|
2013-06-27 20:45:40 +00:00
|
|
|
|
|
|
|
g_value_init (&value, G_TYPE_INT);
|
2014-07-11 20:42:38 +00:00
|
|
|
|
2018-03-20 11:05:26 +00:00
|
|
|
if (!x11_screen->fixed_surface_scale &&
|
2017-10-30 21:01:18 +00:00
|
|
|
gdk_display_get_setting (display, "gdk-window-scaling-factor", &value))
|
2018-03-20 11:05:26 +00:00
|
|
|
_gdk_x11_screen_set_surface_scale (x11_screen, g_value_get_int (&value));
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 16:16:57 +00:00
|
|
|
static Atom
|
2013-02-19 13:31:03 +00:00
|
|
|
get_selection_atom (GdkX11Screen *x11_screen)
|
2013-02-18 16:16:57 +00:00
|
|
|
{
|
2013-02-19 13:31:03 +00:00
|
|
|
return _gdk_x11_get_xatom_for_display_printf (x11_screen->display, "_XSETTINGS_S%d", x11_screen->screen_num);
|
2013-02-18 16:16:57 +00:00
|
|
|
}
|
|
|
|
|
2001-04-02 23:33:47 +00:00
|
|
|
static void
|
2013-02-19 13:31:03 +00:00
|
|
|
check_manager_window (GdkX11Screen *x11_screen,
|
|
|
|
gboolean notify_changes)
|
2001-04-02 23:33:47 +00:00
|
|
|
{
|
2013-02-15 21:26:45 +00:00
|
|
|
GdkDisplay *display;
|
2013-02-16 22:59:07 +00:00
|
|
|
Display *xdisplay;
|
2013-02-15 21:26:45 +00:00
|
|
|
|
2013-02-19 13:31:03 +00:00
|
|
|
display = x11_screen->display;
|
2013-02-16 22:59:07 +00:00
|
|
|
xdisplay = gdk_x11_display_get_xdisplay (display);
|
2013-02-15 21:26:45 +00:00
|
|
|
|
|
|
|
gdk_x11_display_grab (display);
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2017-08-22 19:08:14 +00:00
|
|
|
x11_screen->xsettings_manager_window = XGetSelectionOwner (xdisplay, get_selection_atom (x11_screen));
|
|
|
|
|
|
|
|
if (x11_screen->xsettings_manager_window != 0)
|
2013-02-16 22:59:07 +00:00
|
|
|
XSelectInput (xdisplay,
|
2017-08-22 19:08:14 +00:00
|
|
|
x11_screen->xsettings_manager_window,
|
2013-02-16 17:36:05 +00:00
|
|
|
PropertyChangeMask | StructureNotifyMask);
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2013-02-15 21:26:45 +00:00
|
|
|
gdk_x11_display_ungrab (display);
|
2017-08-22 19:08:14 +00:00
|
|
|
|
2013-02-15 21:26:45 +00:00
|
|
|
gdk_display_flush (display);
|
2001-04-02 23:33:47 +00:00
|
|
|
|
2013-02-19 13:31:03 +00:00
|
|
|
read_settings (x11_screen, notify_changes);
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|
|
|
|
|
2017-08-22 19:08:14 +00:00
|
|
|
GdkFilterReturn
|
2017-12-12 23:39:32 +00:00
|
|
|
gdk_xsettings_root_window_filter (const XEvent *xev,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data)
|
2013-02-14 14:06:56 +00:00
|
|
|
{
|
2013-02-19 13:31:03 +00:00
|
|
|
GdkX11Screen *x11_screen = data;
|
|
|
|
GdkDisplay *display = x11_screen->display;
|
2013-02-14 14:06:56 +00:00
|
|
|
|
|
|
|
/* The checks here will not unlikely cause us to reread
|
|
|
|
* the properties from the manager window a number of
|
|
|
|
* times when the manager changes from A->B. But manager changes
|
|
|
|
* are going to be pretty rare.
|
|
|
|
*/
|
2013-02-16 22:56:10 +00:00
|
|
|
if (xev->xany.type == ClientMessage &&
|
|
|
|
xev->xclient.message_type == gdk_x11_get_xatom_by_name_for_display (display, "MANAGER") &&
|
2013-02-19 13:31:03 +00:00
|
|
|
xev->xclient.data.l[1] == get_selection_atom (x11_screen))
|
2013-02-14 14:06:56 +00:00
|
|
|
{
|
2013-02-19 13:31:03 +00:00
|
|
|
check_manager_window (x11_screen, TRUE);
|
2013-02-16 22:56:10 +00:00
|
|
|
return GDK_FILTER_REMOVE;
|
2013-02-14 14:06:56 +00:00
|
|
|
}
|
2017-08-22 19:08:14 +00:00
|
|
|
|
2013-02-16 22:56:10 +00:00
|
|
|
return GDK_FILTER_CONTINUE;
|
2013-02-14 14:06:56 +00:00
|
|
|
}
|
|
|
|
|
2017-08-22 19:08:14 +00:00
|
|
|
GdkFilterReturn
|
2017-12-12 23:39:32 +00:00
|
|
|
gdk_xsettings_manager_window_filter (const XEvent *xev,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data)
|
2013-02-15 21:32:28 +00:00
|
|
|
{
|
2013-02-19 13:31:03 +00:00
|
|
|
GdkX11Screen *x11_screen = data;
|
2013-02-15 21:32:28 +00:00
|
|
|
|
2013-02-16 22:56:10 +00:00
|
|
|
if (xev->xany.type == DestroyNotify)
|
|
|
|
{
|
2013-02-19 13:31:03 +00:00
|
|
|
check_manager_window (x11_screen, TRUE);
|
2013-02-16 22:56:10 +00:00
|
|
|
/* let GDK do its cleanup */
|
2017-08-22 19:08:14 +00:00
|
|
|
return GDK_FILTER_CONTINUE;
|
2013-02-16 22:56:10 +00:00
|
|
|
}
|
|
|
|
else if (xev->xany.type == PropertyNotify)
|
|
|
|
{
|
2013-02-19 13:31:03 +00:00
|
|
|
read_settings (x11_screen, TRUE);
|
2013-02-16 22:56:10 +00:00
|
|
|
return GDK_FILTER_REMOVE;
|
|
|
|
}
|
2017-08-22 19:08:14 +00:00
|
|
|
|
|
|
|
return GDK_FILTER_CONTINUE;
|
2013-02-14 14:06:56 +00:00
|
|
|
}
|
|
|
|
|
2013-02-19 13:31:03 +00:00
|
|
|
void
|
|
|
|
_gdk_x11_xsettings_init (GdkX11Screen *x11_screen)
|
2001-04-02 23:33:47 +00:00
|
|
|
{
|
2013-02-19 13:31:03 +00:00
|
|
|
check_manager_window (x11_screen, FALSE);
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 20:42:38 +00:00
|
|
|
void
|
|
|
|
_gdk_x11_settings_force_reread (GdkX11Screen *x11_screen)
|
|
|
|
{
|
|
|
|
read_settings (x11_screen, TRUE);
|
|
|
|
}
|
|
|
|
|
2001-04-02 23:33:47 +00:00
|
|
|
void
|
2013-02-19 13:31:03 +00:00
|
|
|
_gdk_x11_xsettings_finish (GdkX11Screen *x11_screen)
|
2001-04-02 23:33:47 +00:00
|
|
|
{
|
2013-02-19 13:31:03 +00:00
|
|
|
if (x11_screen->xsettings_manager_window)
|
2017-08-22 19:08:14 +00:00
|
|
|
x11_screen->xsettings_manager_window = 0;
|
|
|
|
|
2013-02-19 13:31:03 +00:00
|
|
|
if (x11_screen->xsettings)
|
|
|
|
{
|
|
|
|
g_hash_table_unref (x11_screen->xsettings);
|
|
|
|
x11_screen->xsettings = NULL;
|
|
|
|
}
|
2001-04-02 23:33:47 +00:00
|
|
|
}
|