[PATCH] Add XACE-SELinux security label to titlebar



This patch displays the security label of a window (as provided by the
SELinux extension to XACE*) in the titlebar.  At this point, the goal
isn't to provide a trusted label that can't be spoofed.

The approach I took was to put the security label in the same Pango
layout as the titlebar.  The titlebar is bigger, but the extra height is
subtracted from the size of the buttons to keep them at their original
height.  A GConf setting (/apps/metacity/general/show_security_label)
determines if the label is displayed or not.

I would appreciate any comments, in particular, if there is a better
approach to take.  The eventual goal would be to get this capability
upstreamed. 

*The X Access Control Extension (XACE), which is ready to be merged into
xorg, is a set of hooks that can be used by X extensions to perform
access checks.  The SELinux extension uses XACE to control access to
various X server objects according to a SELinux security policy.

See more about XACE here:
http://people.freedesktop.org/~ewalsh/

XACE-SELINUX branch ready for merge:
http://lists.freedesktop.org/archives/xorg/2007-November/030631.html


 display.c           |    4 +-
 display.h           |    1 
 frame.c             |    6 +++
 frames.c            |   95 +++++++++++++++++++++++++++++++++++++++++-----------
 frames.h            |    8 +++-
 metacity.schemas.in |   14 +++++++
 prefs.c             |   44 ++++++++++++++++++++++++
 prefs.h             |    4 +-
 preview-widget.c    |    6 ++-
 theme-viewer.c      |    6 ++-
 theme.c             |   33 +++++++++++-------
 theme.h             |   15 +++++---
 ui.c                |   11 +++++-
 ui.h                |    4 ++
 window-props.c      |   45 ++++++++++++++++++++++++
 window.c            |   11 +++++-
 window.h            |    1 
 17 files changed, 261 insertions(+), 47 deletions(-)

diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/display.c metacity-2.21.2.new/src/display.c
--- metacity-2.21.2.orig/src/display.c	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/display.c	2007-11-28 09:43:21.000000000 -0500
@@ -336,7 +336,8 @@
     "_NET_WM_VISIBLE_ICON_NAME",
     "_NET_WM_USER_TIME_WINDOW",
     "_NET_WM_ACTION_ABOVE",
-    "_NET_WM_ACTION_BELOW"
+    "_NET_WM_ACTION_BELOW",
+    "_SELINUX_CLIENT_CONTEXT",
   };
   Atom atoms[G_N_ELEMENTS(atom_names)];
   
@@ -498,6 +499,7 @@
   display->atom_net_wm_user_time_window = atoms[94];
   display->atom_net_wm_action_above = atoms[95];
   display->atom_net_wm_action_below = atoms[96];
+  display->atom_selinux_client_context = atoms[97];
 
   display->prop_hooks = NULL;
   meta_display_init_window_prop_hooks (display);
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/display.h metacity-2.21.2.new/src/display.h
--- metacity-2.21.2.orig/src/display.h	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/display.h	2007-11-28 09:43:21.000000000 -0500
@@ -184,6 +184,7 @@
   Atom atom_net_wm_visible_name;
   Atom atom_net_wm_visible_icon_name;
   Atom atom_net_wm_user_time_window;
+  Atom atom_selinux_client_context;
 
   /* This is the actual window from focus events,
    * not the one we last set
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/frame.c metacity-2.21.2.new/src/frame.c
--- metacity-2.21.2.orig/src/frame.c	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/frame.c	2007-11-28 09:43:21.000000000 -0500
@@ -157,6 +157,12 @@
                              window->frame->xwindow,
                              window->title);
 
+  if (window->label) {
+    meta_ui_set_frame_label (window->screen->ui,
+                             window->frame->xwindow,
+                             window->label);
+  }
+
   /* Move keybindings to frame instead of window */
   meta_window_grab_keys (window);
 
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/frames.c metacity-2.21.2.new/src/frames.c
--- metacity-2.21.2.orig/src/frames.c	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/frames.c	2007-11-28 09:43:21.000000000 -0500
@@ -91,6 +91,7 @@
 
 static void meta_frames_font_changed          (MetaFrames *frames);
 static void meta_frames_button_layout_changed (MetaFrames *frames);
+static void meta_frames_show_security_label_changed (MetaFrames *frames);
 
 
 static GdkRectangle*    control_rect (MetaFrameControl   control,
@@ -193,6 +194,9 @@
     case META_PREF_BUTTON_LAYOUT:
       meta_frames_button_layout_changed (META_FRAMES (data));
       break;
+    case META_PREF_SHOW_SECURITY_LABEL:
+      meta_frames_show_security_label_changed (META_FRAMES (data));
+      break;
     default:
       break;
     }
@@ -371,11 +375,6 @@
                                 frame->xwindow);
   if (frame->layout)
     {
-      /* save title to recreate layout */
-      g_free (frame->title);
-      
-      frame->title = g_strdup (pango_layout_get_text (frame->layout));
-
       g_object_unref (G_OBJECT (frame->layout));
       frame->layout = NULL;
     }
@@ -422,6 +421,20 @@
 }
 
 static void
+meta_frames_show_security_label_changed (MetaFrames *frames)
+{
+  if (g_hash_table_size (frames->text_heights) > 0)
+    {
+      g_hash_table_destroy (frames->text_heights);
+      frames->text_heights = g_hash_table_new (NULL, NULL);
+    }
+  
+  /* Queue a draw/resize on all frames */
+  g_hash_table_foreach (frames->frames,
+                        queue_recalc_func, frames);
+}
+
+static void
 meta_frames_style_set  (GtkWidget *widget,
                         GtkStyle  *prev_style)
 {
@@ -459,11 +472,6 @@
     {
       if (frame->layout)
         {
-          /* save title to recreate layout */
-          g_free (frame->title);
-          
-          frame->title = g_strdup (pango_layout_get_text (frame->layout));
-
           g_object_unref (G_OBJECT (frame->layout));
           frame->layout = NULL;
         }
@@ -482,7 +490,18 @@
                                           type,
                                           flags);
       
-      frame->layout = gtk_widget_create_pango_layout (widget, frame->title);
+      frame->layout = gtk_widget_create_pango_layout (widget, NULL);
+
+      char *title;
+      if (meta_prefs_get_show_security_label () && frame->label)
+        title = g_strdup_printf (_("%s \n%s"),
+                      frame->label, frame->title);
+      else
+        title = g_strdup (frame->title);
+      pango_layout_set_text(frame->layout, title, strlen(title));
+      g_free (title);
+
+      pango_layout_set_alignment(frame->layout, PANGO_ALIGN_CENTER);
 
       pango_layout_set_auto_dir (frame->layout, FALSE);
       
@@ -508,14 +527,19 @@
                                 GINT_TO_POINTER (frame->text_height));
         }
       
+      frame->label_height = 0;
+      if (meta_prefs_get_show_security_label () && frame->label)
+        {
+          int width, height;
+          pango_layout_get_pixel_size(frame->layout, &width, &height);
+          frame->label_height = height - frame->text_height;
+        }
+
       pango_layout_set_font_description (frame->layout, 
                                          font_desc);
       
       pango_font_description_free (font_desc);
 
-      /* Save some RAM */
-      g_free (frame->title);
-      frame->title = NULL;
     }
 }
 
@@ -546,7 +570,8 @@
                             flags,
                             width, height,
                             &button_layout,
-                            fgeom);
+                            fgeom,
+                            frame->label_height);
 }
 
 MetaFrames*
@@ -583,7 +608,9 @@
   frame->cache_style = NULL;
   frame->layout = NULL;
   frame->text_height = -1;
+  frame->label_height = 0;
   frame->title = NULL;
+  frame->label = NULL;
   frame->expose_delayed = FALSE;
   frame->shape_applied = FALSE;
   frame->prelit_control = META_FRAME_CONTROL_NONE;
@@ -700,7 +727,8 @@
                                 frame->text_height,
                                 flags,
                                 top_height, bottom_height,
-                                left_width, right_width);
+                                left_width, right_width, 
+                                frame->label_height);
 }
 
 void
@@ -1031,6 +1059,29 @@
 }
 
 void
+meta_frames_set_label (MetaFrames *frames,
+                       Window      xwindow,
+                       const char *label)
+{
+  MetaUIFrame *frame;
+  
+  frame = meta_frames_lookup_window (frames, xwindow);
+
+  g_assert (frame);
+  
+  g_free (frame->label);
+  frame->label = g_strdup (label);
+
+  if (frame->layout)
+    {
+      g_object_unref (frame->layout);
+      frame->layout = NULL;
+    }
+
+  invalidate_whole_window (frames, frame);
+}
+
+void
 meta_frames_repaint_frame (MetaFrames *frames,
                            Window      xwindow)
 {
@@ -2060,7 +2111,8 @@
                                 frame_type,
                                 frame->text_height,
                                 frame_flags,
-                                &top, &bottom, &left, &right);
+                                &top, &bottom, &left, &right, 
+                                frame->label_height);
 
   pixels = get_cache (frames, frame);
 
@@ -2364,7 +2416,8 @@
 
       meta_theme_get_frame_borders (meta_theme_get_current (),
                              type, frame->text_height, flags, 
-                             &top, &bottom, &left, &right);
+                                    &top, &bottom, &left, &right, 
+                                    frame->label_height);
 
       meta_core_get (gdk_display, frame->xwindow,
                      META_CORE_GET_SCREEN_WIDTH, &screen_width,
@@ -2421,7 +2474,8 @@
             frame->text_height,
             &button_layout,
             button_states,
-            mini_icon, icon);
+            mini_icon, icon,
+            frame->label_height);
 
           gdk_window_end_paint (drawable);
         }
@@ -2446,7 +2500,8 @@
                              frame->text_height,
                              &button_layout,
                              button_states,
-                             mini_icon, icon);
+                             mini_icon, icon,
+                             frame->label_height);
     }
 
 }
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/frames.h metacity-2.21.2.new/src/frames.h
--- metacity-2.21.2.orig/src/frames.h	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/frames.h	2007-11-28 09:43:21.000000000 -0500
@@ -78,7 +78,9 @@
   MetaFrameStyle *cache_style;
   PangoLayout *layout;
   int text_height;
-  char *title; /* NULL once we have a layout */
+  char *title;
+  int label_height;
+  char *label;
   guint expose_delayed : 1;
   guint shape_applied : 1;
   
@@ -123,6 +125,10 @@
                             Window      xwindow,
                             const char *title);
 
+void meta_frames_set_label (MetaFrames *frames,
+                            Window      xwindow,
+                            const char *label);
+
 void meta_frames_repaint_frame (MetaFrames *frames,
                                 Window      xwindow);
 
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/metacity.schemas.in metacity-2.21.2.new/src/metacity.schemas.in
--- metacity-2.21.2.orig/src/metacity.schemas.in	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/metacity.schemas.in	2007-11-28 09:43:21.000000000 -0500
@@ -339,6 +339,20 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/metacity/general/show_security_label</key>
+      <applyto>/apps/metacity/general/show_security_label</applyto>
+      <owner>metacity</owner>
+      <type>bool</type>
+      <default>false</default>
+      <locale name="C">
+         <short>Display security label</short>
+         <long>
+           Determines whether the security label should be displayed.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/metacity/workspace_names/name</key>
       <applyto>/apps/metacity/workspace_names/name_1</applyto>
       <applyto>/apps/metacity/workspace_names/name_2</applyto>
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/prefs.c metacity-2.21.2.new/src/prefs.c
--- metacity-2.21.2.orig/src/prefs.c	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/prefs.c	2007-11-28 09:43:21.000000000 -0500
@@ -77,6 +77,7 @@
 #define KEY_CURSOR_THEME "/desktop/gnome/peripherals/mouse/cursor_theme"
 #define KEY_CURSOR_SIZE "/desktop/gnome/peripherals/mouse/cursor_size"
 #define KEY_COMPOSITING_MANAGER "/apps/metacity/general/compositing_manager"
+#define KEY_SHOW_SECURITY_LABEL "/apps/metacity/general/show_security_label"
 
 #ifdef HAVE_GCONF
 static GConfClient *default_client = NULL;
@@ -107,6 +108,7 @@
 static char *cursor_theme = NULL;
 static int   cursor_size = 24;
 static gboolean compositing_manager = FALSE;
+static gboolean show_security_label = FALSE;
 
 static MetaVisualBellType visual_bell_type = META_VISUAL_BELL_FULLSCREEN_FLASH;
 static MetaButtonLayout button_layout;
@@ -156,6 +158,7 @@
 static gboolean update_cursor_theme       (const char *value);
 static gboolean update_cursor_size        (int size);
 static gboolean update_compositing_manager (gboolean	value);
+static gboolean update_show_security_label (gboolean    value);
 
 static void change_notify (GConfClient    *client,
                            guint           cnxn_id,
@@ -485,6 +488,9 @@
   if (get_bool (KEY_COMPOSITING_MANAGER, &bool_val))
     update_compositing_manager (bool_val);
   
+  if (get_bool (KEY_SHOW_SECURITY_LABEL, &bool_val))
+    update_show_security_label (bool_val);
+ 
   str_val = gconf_client_get_string (default_client, KEY_VISUAL_BELL_TYPE,
                                      &err);
   cleanup_error (&err);
@@ -1065,6 +1071,22 @@
       if (update_compositing_manager (b))
         queue_changed (META_PREF_COMPOSITING_MANAGER);
     }
+  else if (strcmp (key, KEY_SHOW_SECURITY_LABEL) == 0)
+    {
+      gboolean b;
+
+      if (value && value->type != GCONF_VALUE_BOOL)
+        {
+          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
+                        KEY_SHOW_SECURITY_LABEL);
+          goto out;
+        }
+
+      b = value ? gconf_value_get_bool (value) : FALSE;
+      
+      if (update_show_security_label (b))
+        queue_changed (META_PREF_SHOW_SECURITY_LABEL);
+    }
   else
     {
       meta_topic (META_DEBUG_PREFS, "Key %s doesn't mean anything to Metacity\n",
@@ -1850,6 +1872,9 @@
 
     case META_PREF_COMPOSITING_MANAGER:
       return "COMPOSITING_MANAGER";
+
+    case META_PREF_SHOW_SECURITY_LABEL:
+      return "SHOW SECURITY LABEL";
     }
 
   return "(unknown)";
@@ -3044,6 +3069,25 @@
   return compositing_manager;
 }
 
+#ifdef HAVE_GCONF
+static gboolean
+update_show_security_label (gboolean value)
+{
+  gboolean old = show_security_label;
+
+  show_security_label = value;
+
+  return old != value;
+}
+#endif /* HAVE_GCONF */
+
+gboolean
+meta_prefs_get_show_security_label (void)
+{
+  
+  return show_security_label;
+}
+
 static void
 init_button_layout(void)
 {
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/prefs.h metacity-2.21.2.new/src/prefs.h
--- metacity-2.21.2.orig/src/prefs.h	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/prefs.h	2007-11-28 09:43:21.000000000 -0500
@@ -58,7 +58,8 @@
   META_PREF_GNOME_ACCESSIBILITY,
   META_PREF_CURSOR_THEME,
   META_PREF_CURSOR_SIZE,
-  META_PREF_COMPOSITING_MANAGER
+  META_PREF_COMPOSITING_MANAGER,
+  META_PREF_SHOW_SECURITY_LABEL,
 } MetaPreference;
 
 typedef void (* MetaPrefsChangedFunc) (MetaPreference pref,
@@ -110,6 +111,7 @@
 const char* meta_prefs_get_cursor_theme      (void);
 int         meta_prefs_get_cursor_size       (void);
 gboolean    meta_prefs_get_compositing_manager (void);
+gboolean    meta_prefs_get_show_security_label     (void);
 
 /* Screen bindings */
 #define META_KEYBINDING_WORKSPACE_1              "switch_to_workspace_1"
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/preview-widget.c metacity-2.21.2.new/src/preview-widget.c
--- metacity-2.21.2.orig/src/preview-widget.c	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/preview-widget.c	2007-11-28 09:43:21.000000000 -0500
@@ -194,7 +194,8 @@
                                         &preview->top_height,
                                         &preview->bottom_height,
                                         &preview->left_width,
-                                        &preview->right_width);
+                                        &preview->right_width,
+                                        0);
         }
       else
         {
@@ -257,7 +258,8 @@
                              &preview->button_layout,
                              button_states,
                              meta_preview_get_mini_icon (),
-                             meta_preview_get_icon ());
+                             meta_preview_get_icon (),
+                             0);
     }
 
   /* draw child */
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/theme.c metacity-2.21.2.new/src/theme.c
--- metacity-2.21.2.orig/src/theme.c	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/theme.c	2007-11-28 09:43:21.000000000 -0500
@@ -344,7 +344,8 @@
                                int                   *top_height,
                                int                   *bottom_height,
                                int                   *left_width,
-                               int                   *right_width)
+                               int                   *right_width,
+                               int                    label_height)
 {
   int buttons_height, title_height;
   
@@ -358,7 +359,7 @@
   
   buttons_height = layout->button_height +
     layout->button_border.top + layout->button_border.bottom;
-  title_height = text_height +
+  title_height = text_height + label_height +
     layout->title_vertical_pad +
     layout->title_border.top + layout->title_border.bottom;
 
@@ -527,7 +528,8 @@
                                  int                     client_height,
                                  const MetaButtonLayout *button_layout,
                                  MetaFrameGeometry      *fgeom,
-                                 MetaTheme              *theme)
+                                 MetaTheme              *theme,
+                                 int                     label_height)
 {
   int i, n_left, n_right;
   int x;
@@ -550,7 +552,8 @@
                                  &fgeom->top_height,
                                  &fgeom->bottom_height,
                                  &fgeom->left_width,
-                                 &fgeom->right_width);
+                                 &fgeom->right_width,
+                                 label_height);
 
   width = client_width + fgeom->left_width + fgeom->right_width;
 
@@ -572,7 +575,7 @@
   switch (layout->button_sizing)
     {
     case META_BUTTON_SIZING_ASPECT:
-      button_height = fgeom->top_height - layout->button_border.top - layout->button_border.bottom;
+      button_height = fgeom->top_height - layout->button_border.top - layout->button_border.bottom - label_height;      
       button_width = button_height / layout->button_aspect;
       break;
     case META_BUTTON_SIZING_FIXED:
@@ -722,7 +725,7 @@
   
   /* center buttons vertically */
   button_y = (fgeom->top_height -
-              (button_height + layout->button_border.top + layout->button_border.bottom)) / 2 + layout->button_border.top;
+              (button_height + layout->button_border.top + layout->button_border.bottom + label_height)) / 2 + layout->button_border.top;
 
   /* right edge of farthest-right button */
   x = width - layout->right_titlebar_edge;
@@ -4819,7 +4822,8 @@
                        const MetaButtonLayout *button_layout,
                        MetaButtonState         button_states[META_BUTTON_TYPE_LAST],
                        GdkPixbuf              *mini_icon,
-                       GdkPixbuf              *icon)
+                       GdkPixbuf              *icon,
+                       int                     label_height)
 {
   MetaFrameGeometry fgeom;
   MetaFrameStyle *style;
@@ -4838,7 +4842,8 @@
                                    client_width, client_height,
                                    button_layout,
                                    &fgeom,
-                                   theme);  
+                                   theme,
+                                   label_height);  
 
   meta_frame_style_draw (style,
                          widget,
@@ -4861,7 +4866,8 @@
                               int            *top_height,
                               int            *bottom_height,
                               int            *left_width,
-                              int            *right_width)
+                              int            *right_width,
+                              int             label_height)
 {
   MetaFrameStyle *style;
 
@@ -4886,7 +4892,8 @@
                                  text_height,
                                  flags,
                                  top_height, bottom_height,
-                                 left_width, right_width);
+                                 left_width, right_width, 
+                                 label_height);
 }
 
 void
@@ -4897,7 +4904,8 @@
                           int                     client_width,
                           int                     client_height,
                           const MetaButtonLayout *button_layout,
-                          MetaFrameGeometry      *fgeom)
+                          MetaFrameGeometry      *fgeom,
+                          int                     label_height)
 {
   MetaFrameStyle *style;
 
@@ -4915,7 +4923,8 @@
                                    client_width, client_height,
                                    button_layout,
                                    fgeom,
-                                   theme);
+                                   theme,
+                                   label_height);
 }
 
 MetaFrameLayout*
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/theme.h metacity-2.21.2.new/src/theme.h
--- metacity-2.21.2.orig/src/theme.h	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/theme.h	2007-11-28 09:43:21.000000000 -0500
@@ -630,7 +630,8 @@
                                                   int                   *top_height,
                                                   int                   *bottom_height,
                                                   int                   *left_width,
-                                                  int                   *right_width);
+                                                  int                   *right_width,
+                                                  int                    label_height);
 void             meta_frame_layout_calc_geometry (const MetaFrameLayout  *layout,
                                                   int                     text_height,
                                                   MetaFrameFlags          flags,
@@ -638,7 +639,8 @@
                                                   int                     client_height,
                                                   const MetaButtonLayout *button_layout,
                                                   MetaFrameGeometry      *fgeom,
-                                                  MetaTheme              *theme);
+                                                  MetaTheme              *theme,
+                                                  int                     label_height);
 
 gboolean         meta_frame_layout_validate      (const MetaFrameLayout *layout,
                                                   GError               **error);
@@ -771,7 +773,8 @@
                             const MetaButtonLayout *button_layout,
                             MetaButtonState         button_states[META_BUTTON_TYPE_LAST],
                             GdkPixbuf              *mini_icon,
-                            GdkPixbuf              *icon);
+                            GdkPixbuf              *icon,
+                            int                     label_height);
 
 void meta_theme_get_frame_borders (MetaTheme         *theme,
                                    MetaFrameType      type,
@@ -780,7 +783,8 @@
                                    int               *top_height,
                                    int               *bottom_height,
                                    int               *left_width,
-                                   int               *right_width);
+                                   int               *right_width,
+                                   int                label_height);
 void meta_theme_calc_geometry (MetaTheme              *theme,
                                MetaFrameType           type,
                                int                     text_height,
@@ -788,7 +792,8 @@
                                int                     client_width,
                                int                     client_height,
                                const MetaButtonLayout *button_layout,
-                               MetaFrameGeometry      *fgeom);
+                               MetaFrameGeometry      *fgeom,
+                               int                     label_height);
                                    
 MetaFrameLayout*   meta_theme_lookup_layout       (MetaTheme         *theme,
                                                    const char        *name);
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/theme-viewer.c metacity-2.21.2.new/src/theme-viewer.c
--- metacity-2.21.2.orig/src/theme-viewer.c	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/theme-viewer.c	2007-11-28 09:43:21.000000000 -0500
@@ -938,7 +938,8 @@
                                 &top_height,
                                 &bottom_height,
                                 &left_width,
-                                &right_width);
+                                &right_width,
+                                0);
   
   layout = create_title_layout (widget);
   
@@ -989,7 +990,8 @@
                              &button_layout,
                              button_states,
                              meta_preview_get_mini_icon (),
-                             meta_preview_get_icon ());
+                             meta_preview_get_icon (),
+                             0);
 
       g_object_unref (G_OBJECT (pixmap));
       
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/ui.c metacity-2.21.2.new/src/ui.c
--- metacity-2.21.2.orig/src/ui.c	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/ui.c	2007-11-28 09:43:21.000000000 -0500
@@ -314,6 +314,14 @@
   meta_frames_set_title (ui->frames, xwindow, title);
 }
 
+void
+meta_ui_set_frame_label (MetaUI     *ui,
+                         Window      xwindow,
+                         const char *label)
+{
+  meta_frames_set_label (ui->frames, xwindow, label);
+}
+
 MetaWindowMenu*
 meta_ui_window_menu_new  (MetaUI             *ui,
                           Window              client_xwindow,
@@ -703,7 +711,8 @@
       meta_theme_get_frame_borders (meta_theme_get_current (),
                                     type, text_height, flags,
                                     top_height, bottom_height,
-                                    left_width, right_width);
+                                    left_width, right_width, 
+                                    0);
     }
   else
     {
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/ui.h metacity-2.21.2.new/src/ui.h
--- metacity-2.21.2.orig/src/ui.h	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/ui.h	2007-11-28 09:43:21.000000000 -0500
@@ -115,6 +115,10 @@
                               Window xwindow,
                               const char *title);
 
+void meta_ui_set_frame_label (MetaUI *ui,
+                              Window xwindow,
+                              const char *label);
+
 void meta_ui_repaint_frame (MetaUI *ui,
                             Window xwindow);
 
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/window.c metacity-2.21.2.new/src/window.c
--- metacity-2.21.2.orig/src/window.c	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/window.c	2007-11-28 09:43:21.000000000 -0500
@@ -239,7 +239,7 @@
   gulong existing_wm_state;
   gulong event_mask;
   MetaMoveResizeFlags flags;
-#define N_INITIAL_PROPS 18
+#define N_INITIAL_PROPS 19
   Atom initial_props[N_INITIAL_PROPS];
   int i;
   gboolean has_shape;
@@ -435,6 +435,7 @@
   window->colormap = attrs->colormap;
   
   window->title = NULL;
+  window->label = NULL;
   window->icon_name = NULL;
   window->icon = NULL;
   window->mini_icon = NULL;
@@ -581,6 +582,7 @@
   initial_props[i++] = display->atom_motif_wm_hints;
   initial_props[i++] = XA_WM_TRANSIENT_FOR;
   initial_props[i++] = display->atom_net_wm_user_time_window;
+  initial_props[i++] = display->atom_selinux_client_context;
   g_assert (N_INITIAL_PROPS == i);
   
   meta_window_reload_properties (window, initial_props, N_INITIAL_PROPS);
@@ -5482,6 +5484,13 @@
                                                 xid,
                                                 atom_net_wm_user_time);
     }
+  else if (event->atom == window->display->atom_selinux_client_context)
+    {
+      meta_verbose ("Property notify on %s for _SELINUX_CLIENT_CONTEXT\n", window->desc);
+      
+      meta_window_reload_property (window,
+                                   window->display->atom_selinux_client_context);
+    }
 
   return TRUE;
 }
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/window.h metacity-2.21.2.new/src/window.h
--- metacity-2.21.2.orig/src/window.h	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/window.h	2007-11-28 09:43:21.000000000 -0500
@@ -88,6 +88,7 @@
   Colormap colormap;
   char *desc; /* used in debug spew */
   char *title;
+  char *label;
 
   char *icon_name;
   GdkPixbuf *icon;
diff -X /home/jwcart2/dontdiff -rNu metacity-2.21.2.orig/src/window-props.c metacity-2.21.2.new/src/window-props.c
--- metacity-2.21.2.orig/src/window-props.c	2007-11-28 09:42:42.000000000 -0500
+++ metacity-2.21.2.new/src/window-props.c	2007-11-28 09:43:21.000000000 -0500
@@ -1437,7 +1437,45 @@
     meta_window_queue (window, META_QUEUE_MOVE_RESIZE);
 }
 
-#define N_HOOKS 26
+static void
+set_window_label (MetaWindow *window,
+                  const char *label)
+{
+  meta_verbose ("Using _SELINUX_CLIENT_CONTEXT for new label of %s: \"%s\"\n",
+                    window->desc, label);
+  g_free (window->label);
+  window->label = g_strdup (label);
+
+  if (window->frame)
+    meta_ui_set_frame_label (window->screen->ui,
+                             window->frame->xwindow,
+                             window->label);
+}
+
+static void
+init_selinux_client_context (MetaDisplay   *display,
+                  Atom           property,
+                  MetaPropValue *value)
+{
+  value->type = META_PROP_VALUE_STRING;
+  value->atom = display->atom_selinux_client_context;
+}
+
+static void
+reload_selinux_client_context (MetaWindow    *window,
+                    MetaPropValue *value)
+{
+  if (value->type != META_PROP_VALUE_INVALID)
+    {
+      set_window_label (window, value->v.str);
+    }
+  else
+    {
+      set_window_label (window, NULL);
+    }
+}
+
+#define N_HOOKS 27
 
 void
 meta_display_init_window_prop_hooks (MetaDisplay *display)
@@ -1582,6 +1620,11 @@
   hooks[i].reload_func = reload_net_wm_user_time_window;
   ++i;
 
+  hooks[i].property = display->atom_selinux_client_context;
+  hooks[i].init_func = init_selinux_client_context;
+  hooks[i].reload_func = reload_selinux_client_context;
+  ++i;
+
   if (i != N_HOOKS)
     g_error ("Initialized %d hooks should have been %d\n", i, N_HOOKS);
 }

-- 
James Carter <jwcart2 tycho nsa gov>
National Security Agency



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