2010-11-07 08:44:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2001 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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
|
2015-11-20 22:28:37 +00:00
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
2010-11-07 08:44:27 +00:00
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Author: Owen Taylor, Red Hat, Inc.
|
|
|
|
*/
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
2015-11-20 22:28:37 +00:00
|
|
|
#include <X11/Xmd.h> /* For CARD16 */
|
2010-11-07 08:44:27 +00:00
|
|
|
|
|
|
|
#include "xsettings-client.h"
|
|
|
|
#include "server.h"
|
|
|
|
#include "panel.h"
|
|
|
|
#include "launcher.h"
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
struct _XSettingsClient {
|
2010-11-07 08:44:27 +00:00
|
|
|
Display *display;
|
|
|
|
int screen;
|
|
|
|
XSettingsNotifyFunc notify;
|
|
|
|
XSettingsWatchFunc watch;
|
|
|
|
void *cb_data;
|
|
|
|
|
|
|
|
Window manager_window;
|
|
|
|
XSettingsList *settings;
|
|
|
|
};
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
void xsettings_notify_cb(const char *name, XSettingsAction action, XSettingsSetting *setting, void *data)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
2015-11-20 22:28:37 +00:00
|
|
|
// printf("xsettings_notify_cb\n");
|
2010-11-07 08:44:27 +00:00
|
|
|
if ((action == XSETTINGS_ACTION_NEW || action == XSETTINGS_ACTION_CHANGED) && name != NULL && setting != NULL) {
|
|
|
|
if (!strcmp(name, "Net/IconThemeName") && setting->type == XSETTINGS_TYPE_STRING) {
|
2015-03-20 21:54:07 +00:00
|
|
|
if (icon_theme_name_xsettings) {
|
|
|
|
if (strcmp(icon_theme_name_xsettings, setting->data.v_string) == 0)
|
2010-11-07 08:44:27 +00:00
|
|
|
return;
|
2015-03-20 21:54:07 +00:00
|
|
|
free(icon_theme_name_xsettings);
|
2010-11-07 08:44:27 +00:00
|
|
|
}
|
2015-03-20 21:54:07 +00:00
|
|
|
icon_theme_name_xsettings = strdup(setting->data.v_string);
|
2015-11-20 22:28:37 +00:00
|
|
|
|
2010-11-07 08:44:27 +00:00
|
|
|
int i;
|
2015-11-20 22:28:37 +00:00
|
|
|
for (i = 0; i < num_panels; i++) {
|
|
|
|
Launcher *launcher = &panels[i].launcher;
|
2010-11-07 12:59:51 +00:00
|
|
|
cleanup_launcher_theme(launcher);
|
|
|
|
launcher_load_themes(launcher);
|
|
|
|
launcher_load_icons(launcher);
|
2015-11-18 20:57:10 +00:00
|
|
|
launcher->area.resize_needed = 1;
|
2010-11-07 08:44:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
static void notify_changes(XSettingsClient *client, XSettingsList *old_list)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
|
|
|
XSettingsList *old_iter = old_list;
|
|
|
|
XSettingsList *new_iter = client->settings;
|
|
|
|
|
|
|
|
if (!client->notify)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (old_iter || new_iter) {
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
if (old_iter && new_iter)
|
2015-11-20 22:28:37 +00:00
|
|
|
cmp = strcmp(old_iter->setting->name, new_iter->setting->name);
|
2010-11-07 08:44:27 +00:00
|
|
|
else if (old_iter)
|
|
|
|
cmp = -1;
|
|
|
|
else
|
|
|
|
cmp = 1;
|
|
|
|
|
|
|
|
if (cmp < 0) {
|
2015-11-20 22:28:37 +00:00
|
|
|
client->notify(old_iter->setting->name, XSETTINGS_ACTION_DELETED, NULL, client->cb_data);
|
|
|
|
} else if (cmp == 0) {
|
|
|
|
if (!xsettings_setting_equal(old_iter->setting, new_iter->setting))
|
|
|
|
client->notify(old_iter->setting->name, XSETTINGS_ACTION_CHANGED, new_iter->setting, client->cb_data);
|
|
|
|
} else {
|
|
|
|
client->notify(new_iter->setting->name, XSETTINGS_ACTION_NEW, new_iter->setting, client->cb_data);
|
2010-11-07 08:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (old_iter)
|
|
|
|
old_iter = old_iter->next;
|
|
|
|
if (new_iter)
|
|
|
|
new_iter = new_iter->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
static int ignore_errors(Display *display, XErrorEvent *event)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char local_byte_order = '\0';
|
|
|
|
|
|
|
|
#define BYTES_LEFT(buffer) ((buffer)->data + (buffer)->len - (buffer)->pos)
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
static XSettingsResult fetch_card16(XSettingsBuffer *buffer, CARD16 *result)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
|
|
|
CARD16 x;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
if (BYTES_LEFT(buffer) < 2)
|
2010-11-07 08:44:27 +00:00
|
|
|
return XSETTINGS_ACCESS;
|
|
|
|
|
|
|
|
x = *(CARD16 *)buffer->pos;
|
|
|
|
buffer->pos += 2;
|
|
|
|
|
|
|
|
if (buffer->byte_order == local_byte_order)
|
|
|
|
*result = x;
|
|
|
|
else
|
|
|
|
*result = (x << 8) | (x >> 8);
|
|
|
|
|
|
|
|
return XSETTINGS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
static XSettingsResult fetch_ushort(XSettingsBuffer *buffer, unsigned short *result)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
|
|
|
CARD16 x;
|
2015-11-20 22:28:37 +00:00
|
|
|
XSettingsResult r;
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
r = fetch_card16(buffer, &x);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (r == XSETTINGS_SUCCESS)
|
|
|
|
*result = x;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
static XSettingsResult fetch_card32(XSettingsBuffer *buffer, CARD32 *result)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
|
|
|
CARD32 x;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
if (BYTES_LEFT(buffer) < 4)
|
2010-11-07 08:44:27 +00:00
|
|
|
return XSETTINGS_ACCESS;
|
|
|
|
|
|
|
|
x = *(CARD32 *)buffer->pos;
|
|
|
|
buffer->pos += 4;
|
|
|
|
|
|
|
|
if (buffer->byte_order == local_byte_order)
|
|
|
|
*result = x;
|
|
|
|
else
|
|
|
|
*result = (x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24);
|
|
|
|
|
|
|
|
return XSETTINGS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
static XSettingsResult fetch_card8(XSettingsBuffer *buffer, CARD8 *result)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
2015-11-20 22:28:37 +00:00
|
|
|
if (BYTES_LEFT(buffer) < 1)
|
2015-01-20 02:23:28 +00:00
|
|
|
return XSETTINGS_ACCESS;
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-01-20 02:23:28 +00:00
|
|
|
*result = *(CARD8 *)buffer->pos;
|
|
|
|
buffer->pos += 1;
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-01-20 02:23:28 +00:00
|
|
|
return XSETTINGS_SUCCESS;
|
2010-11-07 08:44:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
#define XSETTINGS_PAD(n, m) ((n + m - 1) & (~(m - 1)))
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
static XSettingsList *parse_settings(unsigned char *data, size_t len)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
|
|
|
XSettingsBuffer buffer;
|
|
|
|
XSettingsResult result = XSETTINGS_SUCCESS;
|
|
|
|
XSettingsList *settings = NULL;
|
|
|
|
CARD32 serial;
|
|
|
|
CARD32 n_entries;
|
|
|
|
CARD32 i;
|
|
|
|
XSettingsSetting *setting = NULL;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
local_byte_order = xsettings_byte_order();
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-01-22 17:34:00 +00:00
|
|
|
buffer.byte_order = local_byte_order;
|
2010-11-07 08:44:27 +00:00
|
|
|
buffer.pos = buffer.data = data;
|
|
|
|
buffer.len = len;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
result = fetch_card8(&buffer, (CARD8 *)&buffer.byte_order);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (buffer.byte_order != MSBFirst && buffer.byte_order != LSBFirst) {
|
2015-11-20 22:28:37 +00:00
|
|
|
fprintf(stderr, "Invalid byte order %x in XSETTINGS property\n", buffer.byte_order);
|
2010-11-07 08:44:27 +00:00
|
|
|
result = XSETTINGS_FAILED;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.pos += 3;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
result = fetch_card32(&buffer, &serial);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
result = fetch_card32(&buffer, &n_entries);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (i = 0; i < n_entries; i++) {
|
|
|
|
CARD8 type;
|
|
|
|
CARD16 name_len;
|
|
|
|
CARD32 v_int;
|
|
|
|
size_t pad_len;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
result = fetch_card8(&buffer, &type);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
buffer.pos += 1;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
result = fetch_card16(&buffer, &name_len);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
pad_len = XSETTINGS_PAD(name_len, 4);
|
2015-11-20 22:28:37 +00:00
|
|
|
if (BYTES_LEFT(&buffer) < pad_len) {
|
2010-11-07 08:44:27 +00:00
|
|
|
result = XSETTINGS_ACCESS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
setting = calloc(1, sizeof *setting);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (!setting) {
|
|
|
|
result = XSETTINGS_NO_MEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
setting->type = XSETTINGS_TYPE_INT; /* No allocated memory */
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
setting->name = calloc(name_len + 1, 1);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (!setting->name) {
|
|
|
|
result = XSETTINGS_NO_MEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
memcpy(setting->name, buffer.pos, name_len);
|
2010-11-07 08:44:27 +00:00
|
|
|
setting->name[name_len] = '\0';
|
|
|
|
buffer.pos += pad_len;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
result = fetch_card32(&buffer, &v_int);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
setting->last_change_serial = v_int;
|
|
|
|
|
|
|
|
switch (type) {
|
2015-11-20 22:28:37 +00:00
|
|
|
case XSETTINGS_TYPE_INT:
|
|
|
|
result = fetch_card32(&buffer, &v_int);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
setting->data.v_int = (INT32)v_int;
|
|
|
|
break;
|
2015-11-20 22:28:37 +00:00
|
|
|
case XSETTINGS_TYPE_STRING:
|
|
|
|
result = fetch_card32(&buffer, &v_int);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
pad_len = XSETTINGS_PAD(v_int, 4);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (v_int + 1 == 0 || /* Guard against wrap-around */
|
2015-11-20 22:28:37 +00:00
|
|
|
BYTES_LEFT(&buffer) < pad_len) {
|
2010-11-07 08:44:27 +00:00
|
|
|
result = XSETTINGS_ACCESS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
setting->data.v_string = calloc(v_int + 1, 1);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (!setting->data.v_string) {
|
|
|
|
result = XSETTINGS_NO_MEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
memcpy(setting->data.v_string, buffer.pos, v_int);
|
2010-11-07 08:44:27 +00:00
|
|
|
setting->data.v_string[v_int] = '\0';
|
|
|
|
buffer.pos += pad_len;
|
|
|
|
break;
|
2015-11-20 22:28:37 +00:00
|
|
|
case XSETTINGS_TYPE_COLOR:
|
|
|
|
result = fetch_ushort(&buffer, &setting->data.v_color.red);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
|
|
|
goto out;
|
2015-11-20 22:28:37 +00:00
|
|
|
result = fetch_ushort(&buffer, &setting->data.v_color.green);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
|
|
|
goto out;
|
2015-11-20 22:28:37 +00:00
|
|
|
result = fetch_ushort(&buffer, &setting->data.v_color.blue);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
|
|
|
goto out;
|
2015-11-20 22:28:37 +00:00
|
|
|
result = fetch_ushort(&buffer, &setting->data.v_color.alpha);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
|
|
|
goto out;
|
|
|
|
break;
|
2015-11-20 22:28:37 +00:00
|
|
|
default:
|
2010-11-07 08:44:27 +00:00
|
|
|
/* Quietly ignore unknown types */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setting->type = type;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
result = xsettings_list_insert(&settings, setting);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (result != XSETTINGS_SUCCESS)
|
2015-11-20 22:28:37 +00:00
|
|
|
goto out;
|
2010-11-07 08:44:27 +00:00
|
|
|
|
|
|
|
setting = NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
out:
|
2010-11-07 08:44:27 +00:00
|
|
|
|
|
|
|
if (result != XSETTINGS_SUCCESS) {
|
|
|
|
switch (result) {
|
2015-11-20 22:28:37 +00:00
|
|
|
case XSETTINGS_NO_MEM:
|
2010-11-07 08:44:27 +00:00
|
|
|
fprintf(stderr, "Out of memory reading XSETTINGS property\n");
|
|
|
|
break;
|
2015-11-20 22:28:37 +00:00
|
|
|
case XSETTINGS_ACCESS:
|
2010-11-07 08:44:27 +00:00
|
|
|
fprintf(stderr, "Invalid XSETTINGS property (read off end)\n");
|
|
|
|
break;
|
2015-11-20 22:28:37 +00:00
|
|
|
case XSETTINGS_DUPLICATE_ENTRY:
|
|
|
|
fprintf(stderr, "Duplicate XSETTINGS entry for '%s'\n", setting->name);
|
|
|
|
case XSETTINGS_FAILED:
|
|
|
|
case XSETTINGS_SUCCESS:
|
|
|
|
case XSETTINGS_NO_ENTRY:
|
2010-11-07 08:44:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setting)
|
2015-11-20 22:28:37 +00:00
|
|
|
xsettings_setting_free(setting);
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
xsettings_list_free(settings);
|
2010-11-07 08:44:27 +00:00
|
|
|
settings = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
static void read_settings(XSettingsClient *client)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long n_items;
|
|
|
|
unsigned long bytes_after;
|
|
|
|
unsigned char *data;
|
|
|
|
int result;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
int (*old_handler)(Display *, XErrorEvent *);
|
2010-11-07 08:44:27 +00:00
|
|
|
|
|
|
|
XSettingsList *old_list = client->settings;
|
|
|
|
client->settings = NULL;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
old_handler = XSetErrorHandler(ignore_errors);
|
|
|
|
result = XGetWindowProperty(client->display,
|
|
|
|
client->manager_window,
|
|
|
|
server.atom._XSETTINGS_SETTINGS,
|
|
|
|
0,
|
|
|
|
LONG_MAX,
|
|
|
|
False,
|
|
|
|
server.atom._XSETTINGS_SETTINGS,
|
|
|
|
&type,
|
|
|
|
&format,
|
|
|
|
&n_items,
|
|
|
|
&bytes_after,
|
|
|
|
&data);
|
|
|
|
XSetErrorHandler(old_handler);
|
2010-11-07 08:44:27 +00:00
|
|
|
|
|
|
|
if (result == Success && type == server.atom._XSETTINGS_SETTINGS) {
|
|
|
|
if (format != 8) {
|
2015-11-20 22:28:37 +00:00
|
|
|
fprintf(stderr, "Invalid format for XSETTINGS property %d", format);
|
|
|
|
} else
|
|
|
|
client->settings = parse_settings(data, n_items);
|
|
|
|
XFree(data);
|
2010-11-07 08:44:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
notify_changes(client, old_list);
|
|
|
|
xsettings_list_free(old_list);
|
2010-11-07 08:44:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
static void check_manager_window(XSettingsClient *client)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
|
|
|
if (client->manager_window && client->watch)
|
2015-11-20 22:28:37 +00:00
|
|
|
client->watch(client->manager_window, False, 0, client->cb_data);
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
XGrabServer(client->display);
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
client->manager_window = XGetSelectionOwner(server.dsp, server.atom._XSETTINGS_SCREEN);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (client->manager_window)
|
2015-11-20 22:28:37 +00:00
|
|
|
XSelectInput(server.dsp, client->manager_window, PropertyChangeMask | StructureNotifyMask);
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
XUngrabServer(client->display);
|
|
|
|
XFlush(client->display);
|
2010-11-07 08:44:27 +00:00
|
|
|
|
|
|
|
if (client->manager_window && client->watch)
|
2015-11-20 22:28:37 +00:00
|
|
|
client->watch(client->manager_window, True, PropertyChangeMask | StructureNotifyMask, client->cb_data);
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
read_settings(client);
|
2010-11-07 08:44:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
XSettingsClient *xsettings_client_new(Display *display,
|
|
|
|
int screen,
|
|
|
|
XSettingsNotifyFunc notify,
|
|
|
|
XSettingsWatchFunc watch,
|
|
|
|
void *cb_data)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
|
|
|
XSettingsClient *client;
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
client = calloc(1, sizeof *client);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (!client)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
client->display = display;
|
|
|
|
client->screen = screen;
|
|
|
|
client->notify = notify;
|
|
|
|
client->watch = watch;
|
|
|
|
client->cb_data = cb_data;
|
|
|
|
|
|
|
|
client->manager_window = None;
|
|
|
|
client->settings = NULL;
|
|
|
|
|
|
|
|
if (client->watch)
|
2015-11-20 22:28:37 +00:00
|
|
|
client->watch(RootWindow(display, screen), True, StructureNotifyMask, client->cb_data);
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
check_manager_window(client);
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2010-11-07 17:43:14 +00:00
|
|
|
if (client->manager_window == None) {
|
|
|
|
printf("NO XSETTINGS manager, tint2 use config 'launcher_icon_theme'.\n");
|
2015-11-20 22:28:37 +00:00
|
|
|
free(client);
|
2010-11-07 17:43:14 +00:00
|
|
|
return NULL;
|
2015-11-20 22:28:37 +00:00
|
|
|
} else
|
2010-11-07 17:43:14 +00:00
|
|
|
return client;
|
2010-11-07 08:44:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
void xsettings_client_destroy(XSettingsClient *client)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
|
|
|
if (client->watch)
|
2015-11-20 22:28:37 +00:00
|
|
|
client->watch(RootWindow(client->display, client->screen), False, 0, client->cb_data);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (client->manager_window && client->watch)
|
2015-11-20 22:28:37 +00:00
|
|
|
client->watch(client->manager_window, False, 0, client->cb_data);
|
2010-11-07 08:44:27 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
xsettings_list_free(client->settings);
|
|
|
|
free(client);
|
2010-11-07 08:44:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
XSettingsResult xsettings_client_get_setting(XSettingsClient *client, const char *name, XSettingsSetting **setting)
|
2010-11-07 08:44:27 +00:00
|
|
|
{
|
2015-11-20 22:28:37 +00:00
|
|
|
XSettingsSetting *search = xsettings_list_lookup(client->settings, name);
|
2010-11-07 08:44:27 +00:00
|
|
|
if (search) {
|
2015-11-20 22:28:37 +00:00
|
|
|
*setting = xsettings_setting_copy(search);
|
2010-11-07 08:44:27 +00:00
|
|
|
return *setting ? XSETTINGS_SUCCESS : XSETTINGS_NO_MEM;
|
2015-11-20 22:28:37 +00:00
|
|
|
} else
|
2010-11-07 08:44:27 +00:00
|
|
|
return XSETTINGS_NO_ENTRY;
|
|
|
|
}
|
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
Bool xsettings_client_process_event(XSettingsClient *client, XEvent *xev)
|
2010-11-07 08:44:27 +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.
|
|
|
|
*/
|
2015-11-20 22:28:37 +00:00
|
|
|
if (xev->xany.window == RootWindow(server.dsp, server.screen)) {
|
2010-11-07 08:44:27 +00:00
|
|
|
if (xev->xany.type == ClientMessage && xev->xclient.message_type == server.atom.MANAGER) {
|
2015-11-20 22:28:37 +00:00
|
|
|
check_manager_window(client);
|
2010-11-07 08:44:27 +00:00
|
|
|
return True;
|
|
|
|
}
|
2015-11-20 22:28:37 +00:00
|
|
|
} else if (xev->xany.window == client->manager_window) {
|
2010-11-07 08:44:27 +00:00
|
|
|
if (xev->xany.type == DestroyNotify) {
|
2015-11-20 22:28:37 +00:00
|
|
|
check_manager_window(client);
|
2010-11-07 08:44:27 +00:00
|
|
|
return True;
|
2015-11-20 22:28:37 +00:00
|
|
|
} else if (xev->xany.type == PropertyNotify) {
|
|
|
|
read_settings(client);
|
2010-11-07 08:44:27 +00:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return False;
|
|
|
|
}
|