2006-10-01 18:30:10 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
/* MetaGroup property handling */
|
|
|
|
|
2014-05-02 09:34:02 -04:00
|
|
|
/*
|
2002-11-30 22:58:04 -05:00
|
|
|
* Copyright (C) 2002 Red Hat, Inc.
|
2014-05-02 09:34:02 -04:00
|
|
|
*
|
2002-11-30 22:58:04 -05:00
|
|
|
* 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
|
|
|
|
* General Public License for more details.
|
2014-05-02 09:34:02 -04:00
|
|
|
*
|
2002-11-30 22:58:04 -05:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-11 20:42:06 -05:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2002-11-30 22:58:04 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include "group-props.h"
|
2014-03-19 09:11:23 -04:00
|
|
|
#include "group-private.h"
|
2002-11-30 22:58:04 -05:00
|
|
|
#include "xprops.h"
|
2017-08-26 12:26:30 -04:00
|
|
|
#include "x11/meta-x11-display-private.h"
|
2002-11-30 22:58:04 -05:00
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
2017-08-26 12:58:29 -04:00
|
|
|
typedef void (* InitValueFunc) (MetaX11Display *x11_display,
|
|
|
|
Atom property,
|
|
|
|
MetaPropValue *value);
|
|
|
|
typedef void (* ReloadValueFunc) (MetaGroup *group,
|
|
|
|
MetaPropValue *value);
|
2002-11-30 22:58:04 -05:00
|
|
|
|
|
|
|
struct _MetaGroupPropHooks
|
|
|
|
{
|
|
|
|
Atom property;
|
|
|
|
InitValueFunc init_func;
|
|
|
|
ReloadValueFunc reload_func;
|
|
|
|
};
|
|
|
|
|
2017-08-26 12:58:29 -04:00
|
|
|
static void init_prop_value (MetaX11Display *x11_display,
|
|
|
|
Atom property,
|
|
|
|
MetaPropValue *value);
|
|
|
|
static void reload_prop_value (MetaGroup *group,
|
|
|
|
MetaPropValue *value);
|
|
|
|
static MetaGroupPropHooks *find_hooks (MetaX11Display *x11_display,
|
|
|
|
Atom property);
|
2002-11-30 22:58:04 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_group_reload_property (MetaGroup *group,
|
|
|
|
Atom property)
|
|
|
|
{
|
|
|
|
meta_group_reload_properties (group, &property, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_group_reload_properties (MetaGroup *group,
|
|
|
|
const Atom *properties,
|
|
|
|
int n_properties)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
MetaPropValue *values;
|
|
|
|
|
|
|
|
g_return_if_fail (properties != NULL);
|
|
|
|
g_return_if_fail (n_properties > 0);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
values = g_new0 (MetaPropValue, n_properties);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
i = 0;
|
|
|
|
while (i < n_properties)
|
|
|
|
{
|
2017-08-26 12:58:29 -04:00
|
|
|
init_prop_value (group->x11_display, properties[i], &values[i]);
|
2002-11-30 22:58:04 -05:00
|
|
|
++i;
|
|
|
|
}
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2017-08-26 14:51:28 -04:00
|
|
|
meta_prop_get_values (group->x11_display,
|
2017-08-26 12:58:29 -04:00
|
|
|
group->group_leader,
|
2002-11-30 22:58:04 -05:00
|
|
|
values, n_properties);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < n_properties)
|
|
|
|
{
|
|
|
|
reload_prop_value (group, &values[i]);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_prop_free_values (values, n_properties);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
g_free (values);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in the MetaPropValue used to get the value of "property" */
|
|
|
|
static void
|
2017-08-26 12:58:29 -04:00
|
|
|
init_prop_value (MetaX11Display *x11_display,
|
|
|
|
Atom property,
|
|
|
|
MetaPropValue *value)
|
2002-11-30 22:58:04 -05:00
|
|
|
{
|
2014-05-02 09:34:02 -04:00
|
|
|
MetaGroupPropHooks *hooks;
|
2002-11-30 22:58:04 -05:00
|
|
|
|
|
|
|
value->type = META_PROP_VALUE_INVALID;
|
|
|
|
value->atom = None;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2017-08-26 12:58:29 -04:00
|
|
|
hooks = find_hooks (x11_display, property);
|
2002-11-30 22:58:04 -05:00
|
|
|
if (hooks && hooks->init_func != NULL)
|
2017-08-26 12:58:29 -04:00
|
|
|
(* hooks->init_func) (x11_display, property, value);
|
2002-11-30 22:58:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reload_prop_value (MetaGroup *group,
|
|
|
|
MetaPropValue *value)
|
|
|
|
{
|
2014-05-02 09:34:02 -04:00
|
|
|
MetaGroupPropHooks *hooks;
|
|
|
|
|
2017-08-26 12:58:29 -04:00
|
|
|
hooks = find_hooks (group->x11_display, value->atom);
|
2002-11-30 22:58:04 -05:00
|
|
|
if (hooks && hooks->reload_func != NULL)
|
|
|
|
(* hooks->reload_func) (group, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-08-26 12:58:29 -04:00
|
|
|
init_wm_client_machine (MetaX11Display *x11_display,
|
|
|
|
Atom property,
|
|
|
|
MetaPropValue *value)
|
2002-11-30 22:58:04 -05:00
|
|
|
{
|
|
|
|
value->type = META_PROP_VALUE_STRING;
|
2017-08-26 12:58:29 -04:00
|
|
|
value->atom = x11_display->atom_WM_CLIENT_MACHINE;
|
2002-11-30 22:58:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reload_wm_client_machine (MetaGroup *group,
|
|
|
|
MetaPropValue *value)
|
|
|
|
{
|
|
|
|
g_free (group->wm_client_machine);
|
|
|
|
group->wm_client_machine = NULL;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
if (value->type != META_PROP_VALUE_INVALID)
|
|
|
|
group->wm_client_machine = g_strdup (value->v.str);
|
|
|
|
|
|
|
|
meta_verbose ("Group has client machine \"%s\"\n",
|
|
|
|
group->wm_client_machine ? group->wm_client_machine : "unset");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-08-26 12:58:29 -04:00
|
|
|
init_net_startup_id (MetaX11Display *x11_display,
|
|
|
|
Atom property,
|
|
|
|
MetaPropValue *value)
|
2002-11-30 22:58:04 -05:00
|
|
|
{
|
|
|
|
value->type = META_PROP_VALUE_UTF8;
|
2017-08-26 12:58:29 -04:00
|
|
|
value->atom = x11_display->atom__NET_STARTUP_ID;
|
2002-11-30 22:58:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reload_net_startup_id (MetaGroup *group,
|
2006-08-04 18:33:42 -04:00
|
|
|
MetaPropValue *value)
|
2002-11-30 22:58:04 -05:00
|
|
|
{
|
|
|
|
g_free (group->startup_id);
|
|
|
|
group->startup_id = NULL;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
if (value->type != META_PROP_VALUE_INVALID)
|
|
|
|
group->startup_id = g_strdup (value->v.str);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
meta_verbose ("Group has startup id \"%s\"\n",
|
|
|
|
group->startup_id ? group->startup_id : "unset");
|
|
|
|
}
|
|
|
|
|
|
|
|
#define N_HOOKS 3
|
|
|
|
|
|
|
|
void
|
2017-08-26 12:58:29 -04:00
|
|
|
meta_x11_display_init_group_prop_hooks (MetaX11Display *x11_display)
|
2002-11-30 22:58:04 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
MetaGroupPropHooks *hooks;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2017-08-26 12:58:29 -04:00
|
|
|
g_assert (x11_display->group_prop_hooks == NULL);
|
2002-11-30 22:58:04 -05:00
|
|
|
|
2017-08-26 12:58:29 -04:00
|
|
|
x11_display->group_prop_hooks = g_new0 (MetaGroupPropHooks, N_HOOKS);
|
|
|
|
hooks = x11_display->group_prop_hooks;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
i = 0;
|
|
|
|
|
2017-08-26 12:58:29 -04:00
|
|
|
hooks[i].property = x11_display->atom_WM_CLIENT_MACHINE;
|
2002-11-30 22:58:04 -05:00
|
|
|
hooks[i].init_func = init_wm_client_machine;
|
|
|
|
hooks[i].reload_func = reload_wm_client_machine;
|
|
|
|
++i;
|
|
|
|
|
2017-08-26 12:58:29 -04:00
|
|
|
hooks[i].property = x11_display->atom__NET_WM_PID;
|
2002-11-30 22:58:04 -05:00
|
|
|
hooks[i].init_func = NULL;
|
|
|
|
hooks[i].reload_func = NULL;
|
|
|
|
++i;
|
|
|
|
|
2017-08-26 12:58:29 -04:00
|
|
|
hooks[i].property = x11_display->atom__NET_STARTUP_ID;
|
2002-11-30 22:58:04 -05:00
|
|
|
hooks[i].init_func = init_net_startup_id;
|
|
|
|
hooks[i].reload_func = reload_net_startup_id;
|
|
|
|
++i;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
if (i != N_HOOKS)
|
2008-05-04 13:57:11 -04:00
|
|
|
{
|
|
|
|
g_error ("Initialized %d group hooks should have been %d\n", i, N_HOOKS);
|
|
|
|
}
|
2002-11-30 22:58:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-08-26 12:58:29 -04:00
|
|
|
meta_x11_display_free_group_prop_hooks (MetaX11Display *x11_display)
|
2002-11-30 22:58:04 -05:00
|
|
|
{
|
2017-08-26 12:58:29 -04:00
|
|
|
g_assert (x11_display->group_prop_hooks != NULL);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2017-08-26 12:58:29 -04:00
|
|
|
g_free (x11_display->group_prop_hooks);
|
|
|
|
x11_display->group_prop_hooks = NULL;
|
2002-11-30 22:58:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static MetaGroupPropHooks*
|
2017-08-26 12:58:29 -04:00
|
|
|
find_hooks (MetaX11Display *x11_display,
|
|
|
|
Atom property)
|
2002-11-30 22:58:04 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* FIXME we could sort the array and do binary search or
|
|
|
|
* something
|
|
|
|
*/
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
i = 0;
|
|
|
|
while (i < N_HOOKS)
|
|
|
|
{
|
2017-08-26 12:58:29 -04:00
|
|
|
if (x11_display->group_prop_hooks[i].property == property)
|
|
|
|
return &x11_display->group_prop_hooks[i];
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-11-30 22:58:04 -05:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|