[mutter] Add meta_window_is_remote



commit 3a73f6b8ec22f5cff2c35bcc3630fca10800b571
Author: Colin Walters <walters verbum org>
Date:   Fri Jun 4 13:57:41 2010 -0400

    Add meta_window_is_remote
    
    It's useful for plugins to be able to easily detect whether
    or not a window is from a remote host.  Also, make use of this
    in the window delete codepath, instead of looking up the hostname
    each time.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=620585

 src/core/delete.c          |   33 ++++++++++-----------------------
 src/core/display-private.h |    3 ++-
 src/core/display.c         |    6 ++++++
 src/core/window.c          |   15 +++++++++++++++
 src/include/window.h       |    1 +
 5 files changed, 34 insertions(+), 24 deletions(-)
---
diff --git a/src/core/delete.c b/src/core/delete.c
index 3198625..e59101a 100644
--- a/src/core/delete.c
+++ b/src/core/delete.c
@@ -179,36 +179,23 @@ meta_window_delete (MetaWindow  *window,
 void
 meta_window_kill (MetaWindow *window)
 {
-  char buf[257];
-  
   meta_topic (META_DEBUG_WINDOW_OPS,
               "Killing %s brutally\n",
               window->desc);
 
-  if (window->wm_client_machine != NULL &&
+  if (!meta_window_is_remote (window) &&
       window->net_wm_pid > 0)
     {
-      if (gethostname (buf, sizeof(buf)-1) == 0)
-        {
-          if (strcmp (buf, window->wm_client_machine) == 0)
-            {
-              meta_topic (META_DEBUG_WINDOW_OPS,
-                          "Killing %s with kill()\n",
-                          window->desc);
+      meta_topic (META_DEBUG_WINDOW_OPS,
+                  "Killing %s with kill()\n",
+                  window->desc);
 
-              if (kill (window->net_wm_pid, 9) < 0)
-                meta_topic (META_DEBUG_WINDOW_OPS,
-                            "Failed to signal %s: %s\n",
-                            window->desc, strerror (errno));
-            }
-        }
-      else
-        {
-          meta_warning (_("Failed to get hostname: %s\n"),
-                        strerror (errno));
-        }
+      if (kill (window->net_wm_pid, 9) < 0)
+        meta_topic (META_DEBUG_WINDOW_OPS,
+                    "Failed to signal %s: %s\n",
+                    window->desc, strerror (errno));
     }
-  
+
   meta_topic (META_DEBUG_WINDOW_OPS,
               "Disconnecting %s with XKillClient()\n",
               window->desc);
diff --git a/src/core/display-private.h b/src/core/display-private.h
index fa0676a..dc55338 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -83,10 +83,11 @@ struct _MetaDisplay
   
   char *name;
   Display *xdisplay;
+  char *hostname;
 
   Window leader_window;
   Window timestamp_pinging_window;
-  
+
   /* Pull in all the names of atoms as fields; we will intern them when the
    * class is constructed.
    */
diff --git a/src/core/display.c b/src/core/display.c
index 4e6dc3f..ad9d13a 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -429,6 +429,7 @@ meta_display_open (void)
   GSList *tmp;
   int i;
   guint32 timestamp;
+  char buf[257];
 
   /* A list of all atom names, so that we can intern them in one go. */
   char *atom_names[] = {
@@ -463,6 +464,11 @@ meta_display_open (void)
    */
   the_display->name = g_strdup (XDisplayName (NULL));
   the_display->xdisplay = xdisplay;
+  if (gethostname (buf, sizeof(buf)-1) == 0)
+    {
+      buf[sizeof(buf)-1] = '\0';
+      the_display->hostname = g_strdup (buf);
+    }
   the_display->error_trap_synced_at_last_pop = TRUE;
   the_display->error_traps = 0;
   the_display->error_trap_handler = NULL;
diff --git a/src/core/window.c b/src/core/window.c
index cf022e4..3c3877a 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -9116,6 +9116,21 @@ meta_window_get_client_machine (MetaWindow *window)
 }
 
 /**
+ * meta_window_is_remote:
+ * @window: a #MetaWindow
+ *
+ * Returns: %TRUE if this window originates from a host
+ * different from the one running mutter.
+ */
+gboolean
+meta_window_is_remote (MetaWindow *window)
+{
+  g_return_val_if_fail (META_IS_WINDOW (window), FALSE);
+
+  return g_strcmp0 (window->wm_client_machine, window->display->hostname) != 0;
+}
+
+/**
  * meta_window_is_modal:
  * @window: a #MetaWindow
  *
diff --git a/src/include/window.h b/src/include/window.h
index 367f2e2..8cdcd18 100644
--- a/src/include/window.h
+++ b/src/include/window.h
@@ -140,6 +140,7 @@ guint       meta_window_get_stable_sequence (MetaWindow *window);
 guint32     meta_window_get_user_time (MetaWindow *window);
 int         meta_window_get_pid (MetaWindow *window);
 const char *meta_window_get_client_machine (MetaWindow *window);
+gboolean    meta_window_is_remote (MetaWindow *window);
 gboolean    meta_window_is_modal (MetaWindow *window);
 const char *meta_window_get_mutter_hints (MetaWindow *window);
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]