diff options
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/tabpopup.c | 56 | 
1 files changed, 43 insertions, 13 deletions
| diff --git a/src/ui/tabpopup.c b/src/ui/tabpopup.c index d7887ca8..18ee83d5 100644 --- a/src/ui/tabpopup.c +++ b/src/ui/tabpopup.c @@ -221,10 +221,11 @@ MetaTabPopup*  meta_ui_tab_popup_new (const MetaTabEntry *entries,                         int                 entry_count,                         int                 width, +                       gboolean            expand_for_titles,                         gint                border)  {    MetaTabPopup *popup; -  int i, left, right, top, bottom; +  int i, left, top;    int height;    GtkWidget *grid;    GtkWidget *vbox; @@ -233,7 +234,7 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,    int max_label_width; /* the actual max width of the labels we create */    AtkObject *obj;    GdkScreen *screen; -  int screen_width, scale; +  int scale;    popup = g_new (MetaTabPopup, 1); @@ -278,7 +279,6 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,    popup->border = border;    scale = gtk_widget_get_scale_factor (GTK_WIDGET (popup->window)); -  screen_width = WidthOfScreen (gdk_x11_screen_get_xscreen (screen));    for (i = 0; i < entry_count; ++i)      {        TabEntry* new_entry = tab_entry_new (&entries[i], border & BORDER_OUTLINE_WINDOW, scale); @@ -325,13 +325,14 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,    max_label_width = 0;    top = 0; -  bottom = 1; +  left = 0;    tmp = popup->entries; +  gtk_widget_show(popup->label); /* for gtk_widget_get_preferred_size() */ +      while (tmp && top < height)      {        left = 0; -      right = 1;        while (tmp && left < width)          { @@ -383,11 +384,9 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,            tmp = tmp->next;            ++left; -          ++right;          }        ++top; -      ++bottom;      }    /* remove all the temporary text */ @@ -395,16 +394,47 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,    /* Make it so that we ellipsize if the text is too long */    gtk_label_set_ellipsize (GTK_LABEL (popup->label), PANGO_ELLIPSIZE_END); -  /* Limit the window size to no bigger than screen_width/4 */ -  if (max_label_width>(screen_width/4)) +  int default_window_width = 0; /* 0 == small as possible, truncate label */ + +  if (expand_for_titles && top <= 1 && left < width)      { -      max_label_width = screen_width/4; +      /* only one row partially filled with columns and additional_columns given +         => calculate default_window_width to fit max_label_width if possible */ +       +      GtkWidget **dummies = g_try_malloc(sizeof(GtkWidget*) * (width - left)); +      if (dummies) +        { +          int j; +          for (j = 0; j < width - left; ++j)  +            { +              GtkWidget *dummy = gtk_label_new (""); +              dummies[j] = dummy; +              gtk_grid_attach (GTK_GRID (grid), dummy, left + j, top, 1, 1); +            } +             +          gtk_grid_set_column_homogeneous(GTK_GRID(grid), TRUE); +          gtk_widget_set_halign (grid, GTK_ALIGN_CENTER); +          gtk_widget_show_all(grid); /* for gtk_widget_get_preferred_size */ +     +          GtkRequisition req; +          gtk_widget_get_preferred_size (grid, &req, NULL); +          default_window_width = req.width; +     +          for (j = 0; j < width - left; ++j)  +            { +              gtk_container_remove(GTK_CONTAINER(grid), dummies[j]); +            } +          g_free(dummies); +          /* Limit the window size to no bigger than max_label_width */ +          if (max_label_width < default_window_width) +            { +              default_window_width = max_label_width; +            } +        }      } -  max_label_width += 20; /* add random padding */ -    gtk_window_set_default_size (GTK_WINDOW (popup->window), -                               max_label_width, +                               default_window_width,                                 -1);    return popup; | 
