shell-global: keep better track of screens and displays

Rather than constantly asking mutter for the MetaScreen, and then
figuring out the MetaDisplay/Display/etc from there, just keep track
of everything we care about inside ShellGlobal.

https://bugzilla.gnome.org/show_bug.cgi?id=654639
This commit is contained in:
Dan Winship 2011-07-13 12:22:32 -04:00
parent 3fd90dfcb1
commit b262a42458

View File

@ -45,7 +45,17 @@ static void grab_notify (GtkWidget *widget, gboolean is_grab, gpointer user_data
struct _ShellGlobal { struct _ShellGlobal {
GObject parent; GObject parent;
ClutterStage *stage;
Window stage_xwindow;
GdkWindow *stage_gdk_window;
MetaDisplay *meta_display;
GdkDisplay *gdk_display;
Display *xdisplay;
MetaScreen *meta_screen;
GdkScreen *gdk_screen;
/* We use this window to get a notification from GTK+ when /* We use this window to get a notification from GTK+ when
* a widget in our process does a GTK+ grab. See * a widget in our process does a GTK+ grab. See
* http://bugzilla.gnome.org/show_bug.cgi?id=570641 * http://bugzilla.gnome.org/show_bug.cgi?id=570641
@ -67,8 +77,6 @@ struct _ShellGlobal {
const char *userdatadir; const char *userdatadir;
StFocusManager *focus_manager; StFocusManager *focus_manager;
GdkWindow *stage_window;
guint work_count; guint work_count;
GSList *leisure_closures; GSList *leisure_closures;
guint leisure_function_id; guint leisure_function_id;
@ -147,10 +155,10 @@ shell_global_get_property(GObject *object,
g_value_set_object (value, meta_plugin_get_overlay_group (global->plugin)); g_value_set_object (value, meta_plugin_get_overlay_group (global->plugin));
break; break;
case PROP_SCREEN: case PROP_SCREEN:
g_value_set_object (value, shell_global_get_screen (global)); g_value_set_object (value, global->meta_screen);
break; break;
case PROP_GDK_SCREEN: case PROP_GDK_SCREEN:
g_value_set_object (value, shell_global_get_gdk_screen (global)); g_value_set_object (value, global->gdk_screen);
break; break;
case PROP_SCREEN_WIDTH: case PROP_SCREEN_WIDTH:
{ {
@ -169,7 +177,7 @@ shell_global_get_property(GObject *object,
} }
break; break;
case PROP_STAGE: case PROP_STAGE:
g_value_set_object (value, meta_plugin_get_stage (global->plugin)); g_value_set_object (value, global->stage);
break; break;
case PROP_STAGE_INPUT_MODE: case PROP_STAGE_INPUT_MODE:
g_value_set_enum (value, global->input_mode); g_value_set_enum (value, global->input_mode);
@ -238,8 +246,6 @@ shell_global_init (ShellGlobal *global)
g_signal_connect (global->grab_notifier, "grab-notify", G_CALLBACK (grab_notify), global); g_signal_connect (global->grab_notifier, "grab-notify", G_CALLBACK (grab_notify), global);
global->gtk_grab_active = FALSE; global->gtk_grab_active = FALSE;
global->stage_window = NULL;
global->input_mode = SHELL_STAGE_INPUT_MODE_NORMAL; global->input_mode = SHELL_STAGE_INPUT_MODE_NORMAL;
ca_context_create (&global->sound_context); ca_context_create (&global->sound_context);
@ -462,14 +468,8 @@ focus_window_changed (MetaDisplay *display,
static void static void
shell_global_focus_stage (ShellGlobal *global) shell_global_focus_stage (ShellGlobal *global)
{ {
Display *xdpy; XSetInputFocus (global->xdisplay, global->stage_xwindow,
ClutterActor *stage; RevertToPointerRoot,
Window xstage;
stage = meta_plugin_get_stage (global->plugin);
xstage = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
xdpy = meta_plugin_get_xdisplay (global->plugin);
XSetInputFocus (xdpy, xstage, RevertToPointerRoot,
shell_global_get_current_time (global)); shell_global_get_current_time (global));
} }
@ -556,7 +556,7 @@ shell_global_set_cursor (ShellGlobal *global,
g_return_if_reached (); g_return_if_reached ();
} }
cursor = gdk_cursor_new_from_name (gdk_display_get_default (), name); cursor = gdk_cursor_new_from_name (global->gdk_display, name);
if (!cursor) if (!cursor)
{ {
GdkCursorType cursor_type; GdkCursorType cursor_type;
@ -581,15 +581,8 @@ shell_global_set_cursor (ShellGlobal *global,
} }
cursor = gdk_cursor_new (cursor_type); cursor = gdk_cursor_new (cursor_type);
} }
if (!global->stage_window)
{
ClutterStage *stage = CLUTTER_STAGE (meta_plugin_get_stage (global->plugin));
global->stage_window = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), gdk_window_set_cursor (global->stage_gdk_window, cursor);
clutter_x11_get_stage_window (stage));
}
gdk_window_set_cursor (global->stage_window, cursor);
gdk_cursor_unref (cursor); gdk_cursor_unref (cursor);
} }
@ -603,10 +596,7 @@ shell_global_set_cursor (ShellGlobal *global,
void void
shell_global_unset_cursor (ShellGlobal *global) shell_global_unset_cursor (ShellGlobal *global)
{ {
if (!global->stage_window) /* cursor has never been set */ gdk_window_set_cursor (global->stage_gdk_window, NULL);
return;
gdk_window_set_cursor (global->stage_window, NULL);
} }
/** /**
@ -623,9 +613,6 @@ void
shell_global_set_stage_input_region (ShellGlobal *global, shell_global_set_stage_input_region (ShellGlobal *global,
GSList *rectangles) GSList *rectangles)
{ {
MetaScreen *screen = meta_plugin_get_screen (global->plugin);
MetaDisplay *display = meta_screen_get_display (screen);
Display *xdpy = meta_display_get_xdisplay (display);
MetaRectangle *rect; MetaRectangle *rect;
XRectangle *rects; XRectangle *rects;
int nrects, i; int nrects, i;
@ -645,9 +632,9 @@ shell_global_set_stage_input_region (ShellGlobal *global,
} }
if (global->input_region) if (global->input_region)
XFixesDestroyRegion (xdpy, global->input_region); XFixesDestroyRegion (global->xdisplay, global->input_region);
global->input_region = XFixesCreateRegion (xdpy, rects, nrects); global->input_region = XFixesCreateRegion (global->xdisplay, rects, nrects);
g_free (rects); g_free (rects);
/* set_stage_input_mode() will figure out whether or not we /* set_stage_input_mode() will figure out whether or not we
@ -664,7 +651,7 @@ shell_global_set_stage_input_region (ShellGlobal *global,
MetaScreen * MetaScreen *
shell_global_get_screen (ShellGlobal *global) shell_global_get_screen (ShellGlobal *global)
{ {
return meta_plugin_get_screen (global->plugin); return global->meta_screen;
} }
/** /**
@ -677,7 +664,7 @@ shell_global_get_gdk_screen (ShellGlobal *global)
{ {
g_return_val_if_fail (SHELL_IS_GLOBAL (global), NULL); g_return_val_if_fail (SHELL_IS_GLOBAL (global), NULL);
return gdk_screen_get_default (); return global->gdk_screen;
} }
/** /**
@ -735,26 +722,33 @@ void
_shell_global_set_plugin (ShellGlobal *global, _shell_global_set_plugin (ShellGlobal *global,
MetaPlugin *plugin) MetaPlugin *plugin)
{ {
ClutterActor *stage;
MetaScreen *screen;
MetaDisplay *display;
g_return_if_fail (SHELL_IS_GLOBAL (global)); g_return_if_fail (SHELL_IS_GLOBAL (global));
g_return_if_fail (global->plugin == NULL); g_return_if_fail (global->plugin == NULL);
global->plugin = plugin; global->plugin = plugin;
global->wm = shell_wm_new (plugin); global->wm = shell_wm_new (plugin);
stage = meta_plugin_get_stage (plugin); global->meta_screen = meta_plugin_get_screen (plugin);
global->meta_display = meta_screen_get_display (global->meta_screen);
global->xdisplay = meta_display_get_xdisplay (global->meta_display);
g_signal_connect (stage, "notify::width", global->gdk_display = gdk_x11_lookup_xdisplay (global->xdisplay);
global->gdk_screen = gdk_display_get_screen (global->gdk_display,
meta_screen_get_screen_number (global->meta_screen));
global->stage = CLUTTER_STAGE (meta_plugin_get_stage (plugin));
global->stage_xwindow = clutter_x11_get_stage_window (global->stage);
global->stage_gdk_window = gdk_x11_window_foreign_new_for_display (global->gdk_display,
global->stage_xwindow);
g_signal_connect (global->stage, "notify::width",
G_CALLBACK (global_stage_notify_width), global); G_CALLBACK (global_stage_notify_width), global);
g_signal_connect (stage, "notify::height", g_signal_connect (global->stage, "notify::height",
G_CALLBACK (global_stage_notify_height), global); G_CALLBACK (global_stage_notify_height), global);
g_signal_connect (stage, "paint", g_signal_connect (global->stage, "paint",
G_CALLBACK (global_stage_before_paint), global); G_CALLBACK (global_stage_before_paint), global);
g_signal_connect_after (stage, "paint", g_signal_connect_after (global->stage, "paint",
G_CALLBACK (global_stage_after_paint), global); G_CALLBACK (global_stage_after_paint), global);
shell_perf_log_define_event (shell_perf_log_get_default(), shell_perf_log_define_event (shell_perf_log_get_default(),
@ -766,12 +760,10 @@ _shell_global_set_plugin (ShellGlobal *global,
"End of stage page repaint", "End of stage page repaint",
""); "");
screen = meta_plugin_get_screen (global->plugin); g_signal_connect (global->meta_display, "notify::focus-window",
display = meta_screen_get_display (screen);
g_signal_connect (display, "notify::focus-window",
G_CALLBACK (focus_window_changed), global); G_CALLBACK (focus_window_changed), global);
global->focus_manager = st_focus_manager_get_for_stage (CLUTTER_STAGE (stage)); global->focus_manager = st_focus_manager_get_for_stage (global->stage);
} }
GjsContext * GjsContext *
@ -800,10 +792,8 @@ gboolean
shell_global_begin_modal (ShellGlobal *global, shell_global_begin_modal (ShellGlobal *global,
guint32 timestamp) guint32 timestamp)
{ {
ClutterStage *stage = CLUTTER_STAGE (meta_plugin_get_stage (global->plugin)); return meta_plugin_begin_modal (global->plugin, global->stage_xwindow,
Window stagewin = clutter_x11_get_stage_window (stage); None, 0, timestamp);
return meta_plugin_begin_modal (global->plugin, stagewin, None, 0, timestamp);
} }
/** /**
@ -838,12 +828,9 @@ shell_global_create_pointer_barrier (ShellGlobal *global,
int directions) int directions)
{ {
#if HAVE_XFIXESCREATEPOINTERBARRIER #if HAVE_XFIXESCREATEPOINTERBARRIER
Display *xdpy;
xdpy = meta_plugin_get_xdisplay (global->plugin);
return (guint32) return (guint32)
XFixesCreatePointerBarrier (xdpy, DefaultRootWindow(xdpy), XFixesCreatePointerBarrier (global->xdisplay,
DefaultRootWindow (global->xdisplay),
x1, y1, x1, y1,
x2, y2, x2, y2,
directions, directions,
@ -864,12 +851,9 @@ void
shell_global_destroy_pointer_barrier (ShellGlobal *global, guint32 barrier) shell_global_destroy_pointer_barrier (ShellGlobal *global, guint32 barrier)
{ {
#if HAVE_XFIXESCREATEPOINTERBARRIER #if HAVE_XFIXESCREATEPOINTERBARRIER
Display *xdpy;
g_return_if_fail (barrier > 0); g_return_if_fail (barrier > 0);
xdpy = meta_plugin_get_xdisplay (global->plugin); XFixesDestroyPointerBarrier (global->xdisplay, (PointerBarrier)barrier);
XFixesDestroyPointerBarrier (xdpy, (PointerBarrier)barrier);
#endif #endif
} }
@ -1168,29 +1152,24 @@ grab_notify (GtkWidget *widget, gboolean was_grabbed, gpointer user_data)
*/ */
void shell_global_init_xdnd (ShellGlobal *global) void shell_global_init_xdnd (ShellGlobal *global)
{ {
Window output_window = meta_get_overlay_window (global->meta_screen);
long xdnd_version = 5; long xdnd_version = 5;
MetaScreen *screen = shell_global_get_screen (global); XChangeProperty (global->xdisplay, global->stage_xwindow,
Window output_window = meta_get_overlay_window (screen); gdk_x11_get_xatom_by_name ("XdndAware"), XA_ATOM,
32, PropModeReplace, (const unsigned char *)&xdnd_version, 1);
MetaDisplay *display = meta_screen_get_display (screen); XChangeProperty (global->xdisplay, output_window,
Display *xdisplay = meta_display_get_xdisplay (display); gdk_x11_get_xatom_by_name ("XdndProxy"), XA_WINDOW,
32, PropModeReplace, (const unsigned char *)&global->stage_xwindow, 1);
ClutterStage *stage = CLUTTER_STAGE(meta_plugin_get_stage (global->plugin));
Window stage_win = clutter_x11_get_stage_window (stage);
XChangeProperty (xdisplay, stage_win, gdk_x11_get_xatom_by_name ("XdndAware"), XA_ATOM,
32, PropModeReplace, (const unsigned char *)&xdnd_version, 1);
XChangeProperty (xdisplay, output_window, gdk_x11_get_xatom_by_name ("XdndProxy"), XA_WINDOW,
32, PropModeReplace, (const unsigned char *)&stage_win, 1);
/* /*
* XdndProxy is additionally set on the proxy window as verification that the * XdndProxy is additionally set on the proxy window as verification that the
* XdndProxy property on the target window isn't a left-over * XdndProxy property on the target window isn't a left-over
*/ */
XChangeProperty (xdisplay, stage_win, gdk_x11_get_xatom_by_name ("XdndProxy"), XA_WINDOW, XChangeProperty (global->xdisplay, global->stage_xwindow,
32, PropModeReplace, (const unsigned char *)&stage_win, 1); gdk_x11_get_xatom_by_name ("XdndProxy"), XA_WINDOW,
32, PropModeReplace, (const unsigned char *)&global->stage_xwindow, 1);
} }
/** /**
@ -1213,7 +1192,7 @@ shell_global_get_pointer (ShellGlobal *global,
{ {
GdkModifierType raw_mods; GdkModifierType raw_mods;
gdk_display_get_pointer (gdk_display_get_default (), NULL, x, y, &raw_mods); gdk_display_get_pointer (global->gdk_display, NULL, x, y, &raw_mods);
*mods = raw_mods & GDK_MODIFIER_MASK; *mods = raw_mods & GDK_MODIFIER_MASK;
} }
@ -1232,7 +1211,7 @@ shell_global_sync_pointer (ShellGlobal *global)
GdkModifierType mods; GdkModifierType mods;
ClutterMotionEvent event; ClutterMotionEvent event;
gdk_display_get_pointer (gdk_display_get_default (), NULL, &x, &y, &mods); gdk_display_get_pointer (global->gdk_display, NULL, &x, &y, &mods);
event.type = CLUTTER_MOTION; event.type = CLUTTER_MOTION;
event.time = shell_global_get_current_time (global); event.time = shell_global_get_current_time (global);
@ -1241,7 +1220,7 @@ shell_global_sync_pointer (ShellGlobal *global)
* pointer is not inside the bounds of the stage given the current * pointer is not inside the bounds of the stage given the current
* stage_input_mode. For our current purposes however, this works. * stage_input_mode. For our current purposes however, this works.
*/ */
event.stage = CLUTTER_STAGE (meta_plugin_get_stage (global->plugin)); event.stage = global->stage;
event.x = x; event.x = x;
event.y = y; event.y = y;
event.modifier_state = mods; event.modifier_state = mods;
@ -1286,7 +1265,6 @@ guint32
shell_global_get_current_time (ShellGlobal *global) shell_global_get_current_time (ShellGlobal *global)
{ {
guint32 time; guint32 time;
MetaDisplay *display;
const ClutterEvent *clutter_event; const ClutterEvent *clutter_event;
/* In case we have a xdnd timestamp use it */ /* In case we have a xdnd timestamp use it */
@ -1306,8 +1284,7 @@ shell_global_get_current_time (ShellGlobal *global)
to clutter_get_current_event_time(). to clutter_get_current_event_time().
*/ */
display = meta_screen_get_display (shell_global_get_screen (global)); time = meta_display_get_current_time (global->meta_display);
time = meta_display_get_current_time (display);
if (time != CLUTTER_CURRENT_TIME) if (time != CLUTTER_CURRENT_TIME)
return time; return time;
/* /*
@ -1341,7 +1318,7 @@ shell_global_create_app_launch_context (ShellGlobal *global)
// Make sure that the app is opened on the current workspace even if // Make sure that the app is opened on the current workspace even if
// the user switches before it starts // the user switches before it starts
gdk_app_launch_context_set_desktop (context, meta_screen_get_active_workspace_index (shell_global_get_screen (global))); gdk_app_launch_context_set_desktop (context, meta_screen_get_active_workspace_index (global->meta_screen));
return (GAppLaunchContext *)context; return (GAppLaunchContext *)context;
} }
@ -1529,15 +1506,9 @@ shell_global_cancel_theme_sound (ShellGlobal *global,
gboolean _shell_global_check_xdnd_event (ShellGlobal *global, gboolean _shell_global_check_xdnd_event (ShellGlobal *global,
XEvent *xev) XEvent *xev)
{ {
MetaScreen *screen = meta_plugin_get_screen (global->plugin); Window output_window = meta_get_overlay_window (global->meta_screen);
Window output_window = meta_get_overlay_window (screen);
MetaDisplay *display = meta_screen_get_display (screen);
Display *xdisplay = meta_display_get_xdisplay (display);
ClutterStage *stage = CLUTTER_STAGE (meta_plugin_get_stage (global->plugin)); if (xev->xany.window != output_window && xev->xany.window != global->stage_xwindow)
Window stage_win = clutter_x11_get_stage_window (stage);
if (xev->xany.window != output_window && xev->xany.window != stage_win)
return FALSE; return FALSE;
if (xev->xany.type == ClientMessage && xev->xclient.message_type == gdk_x11_get_xatom_by_name ("XdndPosition")) if (xev->xany.type == ClientMessage && xev->xclient.message_type == gdk_x11_get_xatom_by_name ("XdndPosition"))
@ -1547,7 +1518,7 @@ gboolean _shell_global_check_xdnd_event (ShellGlobal *global,
memset (&xevent, 0, sizeof(xevent)); memset (&xevent, 0, sizeof(xevent));
xevent.xany.type = ClientMessage; xevent.xany.type = ClientMessage;
xevent.xany.display = xdisplay; xevent.xany.display = global->xdisplay;
xevent.xclient.window = src; xevent.xclient.window = src;
xevent.xclient.message_type = gdk_x11_get_xatom_by_name ("XdndStatus"); xevent.xclient.message_type = gdk_x11_get_xatom_by_name ("XdndStatus");
xevent.xclient.format = 32; xevent.xclient.format = 32;
@ -1556,7 +1527,7 @@ gboolean _shell_global_check_xdnd_event (ShellGlobal *global,
xevent.xclient.data.l[1] = 2; xevent.xclient.data.l[1] = 2;
xevent.xclient.data.l[4] = None; xevent.xclient.data.l[4] = None;
XSendEvent (xdisplay, src, False, 0, &xevent); XSendEvent (global->xdisplay, src, False, 0, &xevent);
/* Store the timestamp of the xdnd position event */ /* Store the timestamp of the xdnd position event */
global->xdnd_timestamp = xev->xclient.data.l[3]; global->xdnd_timestamp = xev->xclient.data.l[3];