group-props.c

Go to the documentation of this file.
00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 
00003 /* MetaGroup property handling */
00004 
00005 /* 
00006  * Copyright (C) 2002 Red Hat, Inc.
00007  * 
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00021  * 02111-1307, USA.
00022  */
00023 
00024 #include <config.h>
00025 #include "group-props.h"
00026 #include "group-private.h"
00027 #include "xprops.h"
00028 #include <X11/Xatom.h>
00029 
00030 typedef void (* InitValueFunc)   (MetaDisplay   *display,
00031                                   Atom           property,
00032                                   MetaPropValue *value);
00033 typedef void (* ReloadValueFunc) (MetaGroup     *group,
00034                                   MetaPropValue *value);
00035 
00036 struct _MetaGroupPropHooks
00037 {
00038   Atom property;
00039   InitValueFunc   init_func;
00040   ReloadValueFunc reload_func;
00041 };
00042 
00043 static void                init_prop_value   (MetaDisplay   *display,
00044                                               Atom           property,
00045                                               MetaPropValue *value);
00046 static void                reload_prop_value (MetaGroup     *group,
00047                                               MetaPropValue *value);
00048 static MetaGroupPropHooks* find_hooks        (MetaDisplay   *display,
00049                                               Atom           property);
00050 
00051 
00052 
00053 void
00054 meta_group_reload_property (MetaGroup *group,
00055                             Atom       property)
00056 {
00057   meta_group_reload_properties (group, &property, 1);
00058 }
00059 
00060 void
00061 meta_group_reload_properties (MetaGroup  *group,
00062                               const Atom *properties,
00063                               int         n_properties)
00064 {
00065   int i;
00066   MetaPropValue *values;
00067 
00068   g_return_if_fail (properties != NULL);
00069   g_return_if_fail (n_properties > 0);
00070   
00071   values = g_new0 (MetaPropValue, n_properties);
00072   
00073   i = 0;
00074   while (i < n_properties)
00075     {
00076       init_prop_value (group->display, properties[i], &values[i]);
00077       ++i;
00078     }
00079   
00080   meta_prop_get_values (group->display, group->group_leader,
00081                         values, n_properties);
00082 
00083   i = 0;
00084   while (i < n_properties)
00085     {
00086       reload_prop_value (group, &values[i]);
00087       
00088       ++i;
00089     }
00090 
00091   meta_prop_free_values (values, n_properties);
00092   
00093   g_free (values);
00094 }
00095 
00096 /* Fill in the MetaPropValue used to get the value of "property" */
00097 static void
00098 init_prop_value (MetaDisplay   *display,
00099                  Atom           property,
00100                  MetaPropValue *value)
00101 {
00102   MetaGroupPropHooks *hooks;  
00103 
00104   value->type = META_PROP_VALUE_INVALID;
00105   value->atom = None;
00106   
00107   hooks = find_hooks (display, property);
00108   if (hooks && hooks->init_func != NULL)
00109     (* hooks->init_func) (display, property, value);
00110 }
00111 
00112 static void
00113 reload_prop_value (MetaGroup    *group,
00114                    MetaPropValue *value)
00115 {
00116   MetaGroupPropHooks *hooks;  
00117   
00118   hooks = find_hooks (group->display, value->atom);
00119   if (hooks && hooks->reload_func != NULL)
00120     (* hooks->reload_func) (group, value);
00121 }
00122 
00123 static void
00124 init_wm_client_machine (MetaDisplay   *display,
00125                         Atom           property,
00126                         MetaPropValue *value)
00127 {
00128   value->type = META_PROP_VALUE_STRING;
00129   value->atom = display->atom_WM_CLIENT_MACHINE;
00130 }
00131 
00132 static void
00133 reload_wm_client_machine (MetaGroup     *group,
00134                           MetaPropValue *value)
00135 {
00136   g_free (group->wm_client_machine);
00137   group->wm_client_machine = NULL;
00138   
00139   if (value->type != META_PROP_VALUE_INVALID)
00140     group->wm_client_machine = g_strdup (value->v.str);
00141 
00142   meta_verbose ("Group has client machine \"%s\"\n",
00143                 group->wm_client_machine ? group->wm_client_machine : "unset");
00144 }
00145 
00146 static void
00147 init_net_startup_id (MetaDisplay   *display,
00148                      Atom           property,
00149                      MetaPropValue *value)
00150 {
00151   value->type = META_PROP_VALUE_UTF8;
00152   value->atom = display->atom__NET_STARTUP_ID;
00153 }
00154 
00155 static void
00156 reload_net_startup_id (MetaGroup     *group,
00157                        MetaPropValue *value)
00158 {
00159   g_free (group->startup_id);
00160   group->startup_id = NULL;
00161   
00162   if (value->type != META_PROP_VALUE_INVALID)
00163     group->startup_id = g_strdup (value->v.str);
00164   
00165   meta_verbose ("Group has startup id \"%s\"\n",
00166                 group->startup_id ? group->startup_id : "unset");
00167 }
00168 
00169 #define N_HOOKS 3
00170 
00171 void
00172 meta_display_init_group_prop_hooks (MetaDisplay *display)
00173 {
00174   int i;
00175   MetaGroupPropHooks *hooks;
00176   
00177   g_assert (display->group_prop_hooks == NULL);
00178 
00179   display->group_prop_hooks = g_new0 (MetaGroupPropHooks, N_HOOKS); 
00180   hooks = display->group_prop_hooks;
00181   
00182   i = 0;
00183 
00184   hooks[i].property = display->atom_WM_CLIENT_MACHINE;
00185   hooks[i].init_func = init_wm_client_machine;
00186   hooks[i].reload_func = reload_wm_client_machine;
00187   ++i;
00188 
00189   hooks[i].property = display->atom__NET_WM_PID;
00190   hooks[i].init_func = NULL;
00191   hooks[i].reload_func = NULL;
00192   ++i;
00193 
00194   hooks[i].property = display->atom__NET_STARTUP_ID;
00195   hooks[i].init_func = init_net_startup_id;
00196   hooks[i].reload_func = reload_net_startup_id;
00197   ++i;
00198   
00199   if (i != N_HOOKS)
00200     {
00201       g_error ("Initialized %d group hooks should have been %d\n", i, N_HOOKS);
00202     }
00203 }
00204 
00205 void
00206 meta_display_free_group_prop_hooks (MetaDisplay *display)
00207 {
00208   g_assert (display->group_prop_hooks != NULL);
00209   
00210   g_free (display->group_prop_hooks);
00211   display->group_prop_hooks = NULL;
00212 }
00213 
00214 static MetaGroupPropHooks*
00215 find_hooks (MetaDisplay *display,
00216             Atom         property)
00217 {
00218   int i;
00219 
00220   /* FIXME we could sort the array and do binary search or
00221    * something
00222    */
00223   
00224   i = 0;
00225   while (i < N_HOOKS)
00226     {
00227       if (display->group_prop_hooks[i].property == property)
00228         return &display->group_prop_hooks[i];
00229       
00230       ++i;
00231     }
00232 
00233   return NULL;
00234 }

Generated on Sat Aug 23 22:04:16 2008 for metacity by  doxygen 1.5.5