diff --git a/po/POTFILES.in b/po/POTFILES.in index 50718bce9..d6dbf08a2 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -26,6 +26,7 @@ src/core/window.c src/ui/frames.c src/ui/theme.c src/wayland/meta-wayland-tablet-pad.c +src/x11/meta-x11-display.c src/x11/session.c src/x11/window-props.c src/x11/xprops.c diff --git a/src/Makefile.am b/src/Makefile.am index caef0a6a9..e6b931cb2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -332,6 +332,9 @@ libmutter_@LIBMUTTER_API_VERSION@_la_SOURCES = \ ui/theme-private.h \ ui/ui.c \ x11/atomnames.h \ + x11/meta-x11-display.c \ + x11/meta-x11-display-private.h \ + meta/meta-x11-display.h \ x11/events.c \ x11/events.h \ x11/group-private.h \ @@ -559,6 +562,7 @@ libmutterinclude_headers = \ meta/meta-window-actor.h \ meta/meta-window-group.h \ meta/meta-window-shape.h \ + meta/meta-x11-display.h \ meta/prefs.h \ meta/screen.h \ meta/theme.h \ diff --git a/src/core/display-private.h b/src/core/display-private.h index 9e4518bd3..a3b4cca4d 100644 --- a/src/core/display-private.h +++ b/src/core/display-private.h @@ -110,6 +110,8 @@ struct _MetaDisplay { GObject parent_instance; + MetaX11Display *x11_display; + char *name; Display *xdisplay; diff --git a/src/core/display.c b/src/core/display.c index e7dd4534b..9a592b218 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -74,6 +74,7 @@ #include "x11/window-props.h" #include "x11/group-props.h" #include "x11/xprops.h" +#include "x11/meta-x11-display-private.h" #ifdef HAVE_WAYLAND #include "wayland/meta-xwayland-private.h" @@ -584,7 +585,9 @@ on_startup_notification_changed (MetaStartupNotification *sn, gboolean meta_display_open (void) { + GError *error = NULL; MetaDisplay *display; + MetaX11Display *x11_display; Display *xdisplay; MetaScreen *screen; int i; @@ -622,6 +625,54 @@ meta_display_open (void) display = the_display = g_object_new (META_TYPE_DISPLAY, NULL); display->closing = 0; + display->display_opening = TRUE; + + display->pending_pings = NULL; + display->autoraise_timeout_id = 0; + display->autoraise_window = NULL; + display->focus_window = NULL; + display->screen = NULL; + display->x11_display = NULL; + + display->mouse_mode = TRUE; /* Only relevant for mouse or sloppy focus */ + display->allow_terminal_deactivation = TRUE; /* Only relevant for when a + terminal has the focus */ + + i = 0; + while (i < N_IGNORED_CROSSING_SERIALS) + { + display->ignored_crossing_serials[i] = 0; + ++i; + } + + display->current_time = CurrentTime; + display->sentinel_counter = 0; + + display->grab_resize_timeout_id = 0; + display->grab_have_keyboard = FALSE; + display->last_bell_time = 0; + + display->grab_op = META_GRAB_OP_NONE; + display->grab_window = NULL; + display->grab_tile_mode = META_TILE_NONE; + display->grab_tile_monitor_number = -1; + + display->grab_edge_resistance_data = NULL; + + meta_display_init_keys (display); + + meta_prefs_add_listener (prefs_changed_callback, display); + + /* Get events */ + meta_display_init_events (display); + + display->stamps = g_hash_table_new (g_int64_hash, + g_int64_equal); + display->wayland_windows = g_hash_table_new (NULL, NULL); + + x11_display = meta_x11_display_new (display, &error); + g_assert (x11_display != NULL); /* Required, for now */ + display->x11_display = x11_display; /* here we use XDisplayName which is what the user * probably put in, vs. DisplayString(display) which is @@ -629,26 +680,13 @@ meta_display_open (void) */ display->name = g_strdup (XDisplayName (NULL)); display->xdisplay = xdisplay; - display->display_opening = TRUE; - display->pending_pings = NULL; - display->autoraise_timeout_id = 0; - display->autoraise_window = NULL; - display->focus_window = NULL; display->focus_serial = 0; display->server_focus_window = None; display->server_focus_serial = 0; - display->mouse_mode = TRUE; /* Only relevant for mouse or sloppy focus */ - display->allow_terminal_deactivation = TRUE; /* Only relevant for when a - terminal has the focus */ - meta_bell_init (display); - meta_display_init_keys (display); - - meta_prefs_add_listener (prefs_changed_callback, display); - meta_verbose ("Creating %d atoms\n", (int) G_N_ELEMENTS (atom_names)); XInternAtoms (display->xdisplay, (char **)atom_names, G_N_ELEMENTS (atom_names), False, atoms); @@ -671,39 +709,10 @@ meta_display_open (void) display->groups_by_leader = NULL; - display->screen = NULL; - - /* Get events */ - meta_display_init_events (display); meta_display_init_events_x11 (display); display->xids = g_hash_table_new (meta_unsigned_long_hash, meta_unsigned_long_equal); - display->stamps = g_hash_table_new (g_int64_hash, - g_int64_equal); - display->wayland_windows = g_hash_table_new (NULL, NULL); - - i = 0; - while (i < N_IGNORED_CROSSING_SERIALS) - { - display->ignored_crossing_serials[i] = 0; - ++i; - } - - display->current_time = CurrentTime; - display->sentinel_counter = 0; - - display->grab_resize_timeout_id = 0; - display->grab_have_keyboard = FALSE; - - display->last_bell_time = 0; - - display->grab_op = META_GRAB_OP_NONE; - display->grab_window = NULL; - display->grab_tile_mode = META_TILE_NONE; - display->grab_tile_monitor_number = -1; - - display->grab_edge_resistance_data = NULL; { int major, minor; @@ -1126,7 +1135,6 @@ meta_display_close (MetaDisplay *display, display->focus_timeout_id = 0; /* Stop caring about events */ - meta_display_free_events_x11 (display); meta_display_free_events (display); if (display->screen) @@ -1136,10 +1144,20 @@ meta_display_close (MetaDisplay *display, /* Must be after all calls to meta_window_unmanage() since they * unregister windows */ - g_hash_table_destroy (display->xids); g_hash_table_destroy (display->wayland_windows); g_hash_table_destroy (display->stamps); + if (display->compositor) + meta_compositor_destroy (display->compositor); + + /* Stop caring about events */ + meta_display_free_events_x11 (display); + + /* Must be after all calls to meta_window_unmanage() since they + * unregister windows + */ + g_hash_table_destroy (display->xids); + if (display->leader_window != None) XDestroyWindow (display->xdisplay, display->leader_window); @@ -1150,10 +1168,13 @@ meta_display_close (MetaDisplay *display, g_free (display->name); - meta_display_shutdown_keys (display); + if (display->x11_display) + { + g_object_run_dispose (G_OBJECT (display->x11_display)); + g_clear_object (&display->x11_display); + } - if (display->compositor) - meta_compositor_destroy (display->compositor); + meta_display_shutdown_keys (display); g_object_unref (display); the_display = NULL; @@ -2965,6 +2986,17 @@ meta_display_get_compositor (MetaDisplay *display) return display->compositor; } +/** + * meta_display_get_x11_display: (skip) + * @display: a #MetaDisplay + * + */ +MetaX11Display * +meta_display_get_x11_display (MetaDisplay *display) +{ + return display->x11_display; +} + gboolean meta_display_has_shape (MetaDisplay *display) { diff --git a/src/meta/display.h b/src/meta/display.h index 3d70d8dab..26e8df767 100644 --- a/src/meta/display.h +++ b/src/meta/display.h @@ -76,7 +76,9 @@ GType meta_display_get_type (void) G_GNUC_CONST; int meta_display_get_xinput_opcode (MetaDisplay *display); gboolean meta_display_supports_extended_barriers (MetaDisplay *display); Display *meta_display_get_xdisplay (MetaDisplay *display); -MetaCompositor *meta_display_get_compositor (MetaDisplay *display); + +MetaCompositor *meta_display_get_compositor (MetaDisplay *display); +MetaX11Display *meta_display_get_x11_display (MetaDisplay *display); gboolean meta_display_has_shape (MetaDisplay *display); diff --git a/src/meta/meta-x11-display.h b/src/meta/meta-x11-display.h new file mode 100644 index 000000000..2ecd694c1 --- /dev/null +++ b/src/meta/meta-x11-display.h @@ -0,0 +1,33 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* + * Copyright (C) 2008 Iain Holmes + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef META_X11_DISPLAY_H +#define META_X11_DISPLAY_H + +#include +#include + +#include +#include +#include + +#define META_TYPE_X11_DISPLAY (meta_x11_display_get_type ()) +G_DECLARE_FINAL_TYPE (MetaX11Display, meta_x11_display, META, X11_DISPLAY, GObject) + +#endif /* META_X11_DISPLAY_H */ diff --git a/src/meta/types.h b/src/meta/types.h index d3a5ca32b..116bc9fed 100644 --- a/src/meta/types.h +++ b/src/meta/types.h @@ -27,6 +27,7 @@ typedef struct _MetaBackend MetaBackend; typedef struct _MetaCompositor MetaCompositor; typedef struct _MetaDisplay MetaDisplay; +typedef struct _MetaX11Display MetaX11Display; typedef struct _MetaFrame MetaFrame; typedef struct _MetaScreen MetaScreen; typedef struct _MetaWindow MetaWindow; diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h new file mode 100644 index 000000000..6d7cf5cc6 --- /dev/null +++ b/src/x11/meta-x11-display-private.h @@ -0,0 +1,44 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* Mutter X display handler */ + +/* + * Copyright (C) 2001 Havoc Pennington + * Copyright (C) 2002 Red Hat, Inc. + * Copyright (C) 2003 Rob Adams + * Copyright (C) 2004-2006 Elijah Newren + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef META_X11_DISPLAY_PRIVATE_H +#define META_X11_DISPLAY_PRIVATE_H + +#include + +#include "core/display-private.h" +#include "meta/common.h" +#include "meta/types.h" +#include "meta/meta-x11-display.h" + +struct _MetaX11Display +{ + GObject parent; + + MetaDisplay *display; +}; + +MetaX11Display *meta_x11_display_new (MetaDisplay *display, GError **error); + +#endif /* META_X11_DISPLAY_PRIVATE_H */ diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c new file mode 100644 index 000000000..e8ff4813c --- /dev/null +++ b/src/x11/meta-x11-display.c @@ -0,0 +1,75 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* + * Copyright (C) 2001 Havoc Pennington + * Copyright (C) 2002, 2003, 2004 Red Hat, Inc. + * Copyright (C) 2003, 2004 Rob Adams + * Copyright (C) 2004-2006 Elijah Newren + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +/** + * SECTION:display + * @title: MetaX11Display + * @short_description: Mutter X display handler + * + * The X11 display is represented as a #MetaX11Display struct. + */ + +#include "config.h" + +#include "x11/meta-x11-display-private.h" + +G_DEFINE_TYPE (MetaX11Display, meta_x11_display, G_TYPE_OBJECT) + +static void +meta_x11_display_dispose (GObject *object) +{ + G_OBJECT_CLASS (meta_x11_display_parent_class)->dispose (object); +} + +static void +meta_x11_display_class_init (MetaX11DisplayClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = meta_x11_display_dispose; +} + +static void +meta_x11_display_init (MetaX11Display *x11_display) +{ +} + +/** + * meta_x11_display_new: + * + * Opens a new X11 display, sets it up, initialises all the X extensions + * we will need. + * + * Returns: #MetaX11Display if the display was opened successfully, + * and %NULL otherwise-- that is, if the display doesn't exist or + * it already has a window manager, and sets the error appropriately. + */ +MetaX11Display * +meta_x11_display_new (MetaDisplay *display, GError **error) +{ + MetaX11Display *x11_display; + + x11_display = g_object_new (META_TYPE_X11_DISPLAY, NULL); + x11_display->display = display; + + return x11_display; +}