Move groups and window/group prop hooks to MetaX11Display

https://bugzilla.gnome.org/show_bug.cgi?id=759538
This commit is contained in:
Armin Krezović 2017-08-26 18:58:29 +02:00 committed by Jonas Ådahl
parent 722c975aca
commit 9e5ea8def4
12 changed files with 152 additions and 145 deletions

View File

@ -50,9 +50,6 @@
typedef struct _MetaStack MetaStack;
typedef struct _MetaUISlave MetaUISlave;
typedef struct _MetaGroupPropHooks MetaGroupPropHooks;
typedef struct _MetaWindowPropHooks MetaWindowPropHooks;
typedef struct MetaEdgeResistanceData MetaEdgeResistanceData;
typedef enum {
@ -235,17 +232,6 @@ struct _MetaDisplay
/* Closing down the display */
int closing;
/* Managed by group.c */
GHashTable *groups_by_leader;
/* Managed by window-props.c */
MetaWindowPropHooks *prop_hooks_table;
GHashTable *prop_hooks;
int n_prop_hooks;
/* Managed by group-props.c */
MetaGroupPropHooks *group_prop_hooks;
/* Managed by compositor.c */
MetaCompositor *compositor;

View File

@ -72,8 +72,6 @@
#include "x11/events.h"
#include "x11/window-x11.h"
#include "x11/window-props.h"
#include "x11/group-props.h"
#include "x11/xprops.h"
#include "x11/meta-x11-display-private.h"
@ -717,19 +715,12 @@ meta_display_open (void)
meta_bell_init (display);
display->prop_hooks = NULL;
meta_display_init_window_prop_hooks (display);
display->group_prop_hooks = NULL;
meta_display_init_group_prop_hooks (display);
/* Offscreen unmapped window used for _NET_SUPPORTING_WM_CHECK,
* created in screen_new
*/
display->leader_window = None;
display->timestamp_pinging_window = None;
display->groups_by_leader = NULL;
meta_display_init_events_x11 (display);
/* Create the leader window here. Set its properties and
@ -1020,9 +1011,6 @@ meta_display_close (MetaDisplay *display,
if (display->leader_window != None)
XDestroyWindow (display->x11_display->xdisplay, display->leader_window);
meta_display_free_window_prop_hooks (display);
meta_display_free_group_prop_hooks (display);
if (display->x11_display)
{
g_signal_emit (display, display_signals[X11_DISPLAY_CLOSING], 0);

View File

@ -34,8 +34,8 @@ void meta_window_shutdown_group (MetaWindow *window);
void meta_window_group_leader_changed (MetaWindow *window);
/* note, can return NULL */
MetaGroup* meta_display_lookup_group (MetaDisplay *display,
Window group_leader);
MetaGroup *meta_x11_display_lookup_group (MetaX11Display *x11_display,
Window group_leader);
GSList* meta_group_list_windows (MetaGroup *group);
@ -49,7 +49,3 @@ gboolean meta_group_property_notify (MetaGroup *group,
XEvent *event);
#endif

View File

@ -1480,8 +1480,8 @@ handle_other_xevent (MetaDisplay *display,
else if (property_for_window && !frame_was_receiver)
meta_window_x11_property_notify (property_for_window, event);
group = meta_display_lookup_group (display,
event->xproperty.window);
group = meta_x11_display_lookup_group (x11_display,
event->xproperty.window);
if (group != NULL)
meta_group_property_notify (group, event);

View File

@ -27,7 +27,7 @@
struct _MetaGroup
{
int refcount;
MetaDisplay *display;
MetaX11Display *x11_display;
GSList *windows;
Window group_leader;
char *startup_id;

View File

@ -26,11 +26,11 @@
#include "x11/meta-x11-display-private.h"
#include <X11/Xatom.h>
typedef void (* InitValueFunc) (MetaDisplay *display,
Atom property,
MetaPropValue *value);
typedef void (* ReloadValueFunc) (MetaGroup *group,
MetaPropValue *value);
typedef void (* InitValueFunc) (MetaX11Display *x11_display,
Atom property,
MetaPropValue *value);
typedef void (* ReloadValueFunc) (MetaGroup *group,
MetaPropValue *value);
struct _MetaGroupPropHooks
{
@ -39,15 +39,13 @@ struct _MetaGroupPropHooks
ReloadValueFunc reload_func;
};
static void init_prop_value (MetaDisplay *display,
Atom property,
MetaPropValue *value);
static void reload_prop_value (MetaGroup *group,
MetaPropValue *value);
static MetaGroupPropHooks* find_hooks (MetaDisplay *display,
Atom property);
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);
void
meta_group_reload_property (MetaGroup *group,
@ -72,11 +70,12 @@ meta_group_reload_properties (MetaGroup *group,
i = 0;
while (i < n_properties)
{
init_prop_value (group->display, properties[i], &values[i]);
init_prop_value (group->x11_display, properties[i], &values[i]);
++i;
}
meta_prop_get_values (group->display, group->group_leader,
meta_prop_get_values (group->x11_display->display,
group->group_leader,
values, n_properties);
i = 0;
@ -94,18 +93,18 @@ meta_group_reload_properties (MetaGroup *group,
/* Fill in the MetaPropValue used to get the value of "property" */
static void
init_prop_value (MetaDisplay *display,
Atom property,
MetaPropValue *value)
init_prop_value (MetaX11Display *x11_display,
Atom property,
MetaPropValue *value)
{
MetaGroupPropHooks *hooks;
value->type = META_PROP_VALUE_INVALID;
value->atom = None;
hooks = find_hooks (display, property);
hooks = find_hooks (x11_display, property);
if (hooks && hooks->init_func != NULL)
(* hooks->init_func) (display, property, value);
(* hooks->init_func) (x11_display, property, value);
}
static void
@ -114,18 +113,18 @@ reload_prop_value (MetaGroup *group,
{
MetaGroupPropHooks *hooks;
hooks = find_hooks (group->display, value->atom);
hooks = find_hooks (group->x11_display, value->atom);
if (hooks && hooks->reload_func != NULL)
(* hooks->reload_func) (group, value);
}
static void
init_wm_client_machine (MetaDisplay *display,
Atom property,
MetaPropValue *value)
init_wm_client_machine (MetaX11Display *x11_display,
Atom property,
MetaPropValue *value)
{
value->type = META_PROP_VALUE_STRING;
value->atom = display->x11_display->atom_WM_CLIENT_MACHINE;
value->atom = x11_display->atom_WM_CLIENT_MACHINE;
}
static void
@ -143,12 +142,12 @@ reload_wm_client_machine (MetaGroup *group,
}
static void
init_net_startup_id (MetaDisplay *display,
Atom property,
MetaPropValue *value)
init_net_startup_id (MetaX11Display *x11_display,
Atom property,
MetaPropValue *value)
{
value->type = META_PROP_VALUE_UTF8;
value->atom = display->x11_display->atom__NET_STARTUP_ID;
value->atom = x11_display->atom__NET_STARTUP_ID;
}
static void
@ -168,29 +167,29 @@ reload_net_startup_id (MetaGroup *group,
#define N_HOOKS 3
void
meta_display_init_group_prop_hooks (MetaDisplay *display)
meta_x11_display_init_group_prop_hooks (MetaX11Display *x11_display)
{
int i;
MetaGroupPropHooks *hooks;
g_assert (display->group_prop_hooks == NULL);
g_assert (x11_display->group_prop_hooks == NULL);
display->group_prop_hooks = g_new0 (MetaGroupPropHooks, N_HOOKS);
hooks = display->group_prop_hooks;
x11_display->group_prop_hooks = g_new0 (MetaGroupPropHooks, N_HOOKS);
hooks = x11_display->group_prop_hooks;
i = 0;
hooks[i].property = display->x11_display->atom_WM_CLIENT_MACHINE;
hooks[i].property = x11_display->atom_WM_CLIENT_MACHINE;
hooks[i].init_func = init_wm_client_machine;
hooks[i].reload_func = reload_wm_client_machine;
++i;
hooks[i].property = display->x11_display->atom__NET_WM_PID;
hooks[i].property = x11_display->atom__NET_WM_PID;
hooks[i].init_func = NULL;
hooks[i].reload_func = NULL;
++i;
hooks[i].property = display->x11_display->atom__NET_STARTUP_ID;
hooks[i].property = x11_display->atom__NET_STARTUP_ID;
hooks[i].init_func = init_net_startup_id;
hooks[i].reload_func = reload_net_startup_id;
++i;
@ -202,17 +201,17 @@ meta_display_init_group_prop_hooks (MetaDisplay *display)
}
void
meta_display_free_group_prop_hooks (MetaDisplay *display)
meta_x11_display_free_group_prop_hooks (MetaX11Display *x11_display)
{
g_assert (display->group_prop_hooks != NULL);
g_assert (x11_display->group_prop_hooks != NULL);
g_free (display->group_prop_hooks);
display->group_prop_hooks = NULL;
g_free (x11_display->group_prop_hooks);
x11_display->group_prop_hooks = NULL;
}
static MetaGroupPropHooks*
find_hooks (MetaDisplay *display,
Atom property)
find_hooks (MetaX11Display *x11_display,
Atom property)
{
int i;
@ -223,8 +222,8 @@ find_hooks (MetaDisplay *display,
i = 0;
while (i < N_HOOKS)
{
if (display->group_prop_hooks[i].property == property)
return &display->group_prop_hooks[i];
if (x11_display->group_prop_hooks[i].property == property)
return &x11_display->group_prop_hooks[i];
++i;
}

View File

@ -30,7 +30,8 @@ void meta_group_reload_property (MetaGroup *group,
void meta_group_reload_properties (MetaGroup *group,
const Atom *properties,
int n_properties);
void meta_display_init_group_prop_hooks (MetaDisplay *display);
void meta_display_free_group_prop_hooks (MetaDisplay *display);
void meta_x11_display_init_group_prop_hooks (MetaX11Display *x11_display);
void meta_x11_display_free_group_prop_hooks (MetaX11Display *x11_display);
#endif /* META_GROUP_PROPS_H */

View File

@ -35,8 +35,8 @@
#include <X11/Xlib-xcb.h>
static MetaGroup*
meta_group_new (MetaDisplay *display,
Window group_leader)
meta_group_new (MetaX11Display *x11_display,
Window group_leader)
{
MetaGroup *group;
#define N_INITIAL_PROPS 3
@ -47,12 +47,12 @@ meta_group_new (MetaDisplay *display,
group = g_new0 (MetaGroup, 1);
group->display = display;
group->x11_display = x11_display;
group->windows = NULL;
group->group_leader = group_leader;
group->refcount = 1; /* owned by caller, hash table has only weak ref */
xcb_connection_t *xcb_conn = XGetXCBConnection (display->x11_display->xdisplay);
xcb_connection_t *xcb_conn = XGetXCBConnection (x11_display->xdisplay);
xcb_generic_error_t *e;
g_autofree xcb_get_window_attributes_reply_t *attrs =
xcb_get_window_attributes_reply (xcb_conn,
@ -65,21 +65,21 @@ meta_group_new (MetaDisplay *display,
xcb_change_window_attributes (xcb_conn, group_leader,
XCB_CW_EVENT_MASK, events);
if (display->groups_by_leader == NULL)
display->groups_by_leader = g_hash_table_new (meta_unsigned_long_hash,
meta_unsigned_long_equal);
if (x11_display->groups_by_leader == NULL)
x11_display->groups_by_leader = g_hash_table_new (meta_unsigned_long_hash,
meta_unsigned_long_equal);
g_assert (g_hash_table_lookup (display->groups_by_leader, &group_leader) == NULL);
g_assert (g_hash_table_lookup (x11_display->groups_by_leader, &group_leader) == NULL);
g_hash_table_insert (display->groups_by_leader,
g_hash_table_insert (x11_display->groups_by_leader,
&group->group_leader,
group);
/* Fill these in the order we want them to be gotten */
i = 0;
initial_props[i++] = display->x11_display->atom_WM_CLIENT_MACHINE;
initial_props[i++] = display->x11_display->atom__NET_WM_PID;
initial_props[i++] = display->x11_display->atom__NET_STARTUP_ID;
initial_props[i++] = x11_display->atom_WM_CLIENT_MACHINE;
initial_props[i++] = x11_display->atom__NET_WM_PID;
initial_props[i++] = x11_display->atom__NET_STARTUP_ID;
g_assert (N_INITIAL_PROPS == i);
meta_group_reload_properties (group, initial_props, N_INITIAL_PROPS);
@ -103,16 +103,16 @@ meta_group_unref (MetaGroup *group)
"Destroying group with leader 0x%lx\n",
group->group_leader);
g_assert (group->display->groups_by_leader != NULL);
g_assert (group->x11_display->groups_by_leader != NULL);
g_hash_table_remove (group->display->groups_by_leader,
g_hash_table_remove (group->x11_display->groups_by_leader,
&group->group_leader);
/* mop up hash table, this is how it gets freed on display close */
if (g_hash_table_size (group->display->groups_by_leader) == 0)
if (g_hash_table_size (group->x11_display->groups_by_leader) == 0)
{
g_hash_table_destroy (group->display->groups_by_leader);
group->display->groups_by_leader = NULL;
g_hash_table_destroy (group->x11_display->groups_by_leader);
group->x11_display->groups_by_leader = NULL;
}
g_free (group->wm_client_machine);
@ -141,6 +141,7 @@ meta_window_compute_group (MetaWindow* window)
{
MetaGroup *group;
MetaWindow *ancestor;
MetaX11Display *x11_display = window->display->x11_display;
/* use window->xwindow if no window->xgroup_leader */
@ -151,15 +152,15 @@ meta_window_compute_group (MetaWindow* window)
*/
ancestor = meta_window_find_root_ancestor (window);
if (window->display->groups_by_leader)
if (x11_display->groups_by_leader)
{
if (ancestor != window)
group = ancestor->group;
else if (window->xgroup_leader != None)
group = g_hash_table_lookup (window->display->groups_by_leader,
group = g_hash_table_lookup (x11_display->groups_by_leader,
&window->xgroup_leader);
else
group = g_hash_table_lookup (window->display->groups_by_leader,
group = g_hash_table_lookup (x11_display->groups_by_leader,
&window->xwindow);
}
@ -171,13 +172,13 @@ meta_window_compute_group (MetaWindow* window)
else
{
if (ancestor != window && ancestor->xgroup_leader != None)
group = meta_group_new (window->display,
group = meta_group_new (x11_display,
ancestor->xgroup_leader);
else if (window->xgroup_leader != None)
group = meta_group_new (window->display,
group = meta_group_new (x11_display,
window->xgroup_leader);
else
group = meta_group_new (window->display,
group = meta_group_new (x11_display,
window->xwindow);
window->group = group;
@ -224,21 +225,21 @@ meta_window_shutdown_group (MetaWindow *window)
}
/**
* meta_display_lookup_group: (skip)
* @display: a #MetaDisplay
* meta_x11_display_lookup_group: (skip)
* @x11_display: a #MetaX11Display
* @group_leader: a X window
*
*/
MetaGroup*
meta_display_lookup_group (MetaDisplay *display,
Window group_leader)
MetaGroup *
meta_x11_display_lookup_group (MetaX11Display *x11_display,
Window group_leader)
{
MetaGroup *group;
group = NULL;
if (display->groups_by_leader)
group = g_hash_table_lookup (display->groups_by_leader,
if (x11_display->groups_by_leader)
group = g_hash_table_lookup (x11_display->groups_by_leader,
&group_leader);
return group;

View File

@ -33,6 +33,9 @@
#include "meta/types.h"
#include "meta/meta-x11-display.h"
typedef struct _MetaGroupPropHooks MetaGroupPropHooks;
typedef struct _MetaWindowPropHooks MetaWindowPropHooks;
typedef gboolean (*MetaAlarmFilter) (MetaX11Display *x11_display,
XSyncAlarmNotifyEvent *event,
gpointer data);
@ -60,6 +63,17 @@ struct _MetaX11Display
GHashTable *xids;
/* Managed by group.c */
GHashTable *groups_by_leader;
/* Managed by window-props.c */
MetaWindowPropHooks *prop_hooks_table;
GHashTable *prop_hooks;
int n_prop_hooks;
/* Managed by group-props.c */
MetaGroupPropHooks *group_prop_hooks;
MetaAlarmFilter alarm_filter;
gpointer alarm_filter_data;

View File

@ -52,6 +52,9 @@
#include "core/util-private.h"
#include "meta/errors.h"
#include "x11/group-props.h"
#include "x11/window-props.h"
#ifdef HAVE_WAYLAND
#include "wayland/meta-xwayland-private.h"
#endif
@ -68,6 +71,18 @@ meta_x11_display_dispose (GObject *object)
{
MetaX11Display *x11_display = META_X11_DISPLAY (object);
if (x11_display->prop_hooks)
{
meta_x11_display_free_window_prop_hooks (x11_display);
x11_display->prop_hooks = NULL;
}
if (x11_display->group_prop_hooks)
{
meta_x11_display_free_group_prop_hooks (x11_display);
x11_display->group_prop_hooks = NULL;
}
if (x11_display->xids)
{
/* Must be after all calls to meta_window_unmanage() since they
@ -409,6 +424,13 @@ meta_x11_display_new (MetaDisplay *display, GError **error)
x11_display->xids = g_hash_table_new (meta_unsigned_long_hash,
meta_unsigned_long_equal);
x11_display->groups_by_leader = NULL;
x11_display->prop_hooks = NULL;
meta_x11_display_init_window_prop_hooks (x11_display);
x11_display->group_prop_hooks = NULL;
meta_x11_display_init_group_prop_hooks (x11_display);
return x11_display;
}

View File

@ -82,8 +82,8 @@ static void reload_prop_value (MetaWindow *window,
MetaWindowPropHooks *hooks,
MetaPropValue *value,
gboolean initial);
static MetaWindowPropHooks* find_hooks (MetaDisplay *display,
Atom property);
static MetaWindowPropHooks *find_hooks (MetaX11Display *x11_display,
Atom property);
void
@ -95,7 +95,7 @@ meta_window_reload_property_from_xwindow (MetaWindow *window,
MetaPropValue value = { 0, };
MetaWindowPropHooks *hooks;
hooks = find_hooks (window->display, property);
hooks = find_hooks (window->display->x11_display, property);
if (!hooks)
return;
@ -130,13 +130,14 @@ meta_window_load_initial_properties (MetaWindow *window)
int i, j;
MetaPropValue *values;
int n_properties = 0;
MetaX11Display *x11_display = window->display->x11_display;
values = g_new0 (MetaPropValue, window->display->n_prop_hooks);
values = g_new0 (MetaPropValue, x11_display->n_prop_hooks);
j = 0;
for (i = 0; i < window->display->n_prop_hooks; i++)
for (i = 0; i < x11_display->n_prop_hooks; i++)
{
MetaWindowPropHooks *hooks = &window->display->prop_hooks_table[i];
MetaWindowPropHooks *hooks = &x11_display->prop_hooks_table[i];
if (hooks->flags & LOAD_INIT)
{
init_prop_value (window, hooks, &values[j]);
@ -149,9 +150,9 @@ meta_window_load_initial_properties (MetaWindow *window)
values, n_properties);
j = 0;
for (i = 0; i < window->display->n_prop_hooks; i++)
for (i = 0; i < x11_display->n_prop_hooks; i++)
{
MetaWindowPropHooks *hooks = &window->display->prop_hooks_table[i];
MetaWindowPropHooks *hooks = &x11_display->prop_hooks_table[i];
if (hooks->flags & LOAD_INIT)
{
/* If we didn't actually manage to load anything then we don't need
@ -1799,8 +1800,8 @@ RELOAD_STRING (gtk_menubar_object_path, "gtk-menubar-object-path")
#undef RELOAD_STRING
/**
* meta_display_init_window_prop_hooks:
* @display: The #MetaDisplay
* meta_x11_display_init_window_prop_hooks:
* @x11_display: The #MetaDX11isplay
*
* Initialises the property hooks system. Each row in the table named "hooks"
* represents an action to take when a property is found on a newly-created
@ -1816,9 +1817,8 @@ RELOAD_STRING (gtk_menubar_object_path, "gtk-menubar-object-path")
* This value may be NULL, in which case no callback will be called.
*/
void
meta_display_init_window_prop_hooks (MetaDisplay *display)
meta_x11_display_init_window_prop_hooks (MetaX11Display *x11_display)
{
MetaX11Display *x11_display = display->x11_display;
/* The ordering here is significant for the properties we load
* initially: they are roughly ordered in the order we want them to
* be gotten. We want to get window name and class first so we can
@ -1877,10 +1877,10 @@ meta_display_init_window_prop_hooks (MetaDisplay *display)
MetaWindowPropHooks *table = g_memdup (hooks, sizeof (hooks)),
*cursor = table;
g_assert (display->prop_hooks == NULL);
g_assert (x11_display->prop_hooks == NULL);
display->prop_hooks_table = (gpointer) table;
display->prop_hooks = g_hash_table_new (NULL, NULL);
x11_display->prop_hooks_table = (gpointer) table;
x11_display->prop_hooks = g_hash_table_new (NULL, NULL);
while (cursor->property)
{
@ -1894,28 +1894,28 @@ meta_display_init_window_prop_hooks (MetaDisplay *display)
* anything 32 bits or less, and atoms are 32 bits with the top three
* bits clear. (Scheifler & Gettys, 2e, p372)
*/
g_hash_table_insert (display->prop_hooks,
g_hash_table_insert (x11_display->prop_hooks,
GINT_TO_POINTER (cursor->property),
cursor);
cursor++;
}
display->n_prop_hooks = cursor - table;
x11_display->n_prop_hooks = cursor - table;
}
void
meta_display_free_window_prop_hooks (MetaDisplay *display)
meta_x11_display_free_window_prop_hooks (MetaX11Display *x11_display)
{
g_hash_table_unref (display->prop_hooks);
display->prop_hooks = NULL;
g_hash_table_unref (x11_display->prop_hooks);
x11_display->prop_hooks = NULL;
g_free (display->prop_hooks_table);
display->prop_hooks_table = NULL;
g_free (x11_display->prop_hooks_table);
x11_display->prop_hooks_table = NULL;
}
static MetaWindowPropHooks*
find_hooks (MetaDisplay *display,
Atom property)
static MetaWindowPropHooks *
find_hooks (MetaX11Display *x11_display,
Atom property)
{
return g_hash_table_lookup (display->prop_hooks,
return g_hash_table_lookup (x11_display->prop_hooks,
GINT_TO_POINTER (property));
}

View File

@ -60,22 +60,22 @@ void meta_window_reload_property_from_xwindow (MetaWindow *window,
void meta_window_load_initial_properties (MetaWindow *window);
/**
* meta_display_init_window_prop_hooks:
* @display: The display.
* meta_x11_display_init_window_prop_hooks:
* @x11_display: The X11 display.
*
* Initialises the hooks used for the reload_propert* functions
* on a particular display, and stores a pointer to them in the
* display.
* x11_display.
*/
void meta_display_init_window_prop_hooks (MetaDisplay *display);
void meta_x11_display_init_window_prop_hooks (MetaX11Display *x11_display);
/**
* meta_display_free_window_prop_hooks:
* @display: The display.
* meta_x11_display_free_window_prop_hooks:
* @x11_display: The X11 display.
* Frees the hooks used for the reload_propert* functions
* for a particular display.
*/
void meta_display_free_window_prop_hooks (MetaDisplay *display);
void meta_x11_display_free_window_prop_hooks (MetaX11Display *x11_display);
/**
* meta_set_normal_hints: