region: Simplify size code for input chooser dialog

The previous code was complex and caused the dialog to abruptly change size when
interacting with it. Instead choose a reasonable default height.
This commit is contained in:
Robert Ancell 2018-06-29 14:37:35 +12:00 committed by Georges Basile Stavracas Neto
parent 70d8427b04
commit aaee85e5c6
2 changed files with 1 additions and 34 deletions

View file

@ -35,7 +35,6 @@
#define INPUT_SOURCE_TYPE_XKB "xkb"
#define INPUT_SOURCE_TYPE_IBUS "ibus"
#define MAIN_WINDOW_WIDTH_RATIO 0.60
#define FILTER_TIMEOUT 150 /* ms */
typedef enum {
@ -282,29 +281,6 @@ remove_all_children (GtkContainer *container)
gtk_container_remove (container, (GtkWidget *) l->data);
}
static void
set_fixed_size (GtkWidget *chooser)
{
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
GtkPolicyType policy;
gint width, height;
gtk_scrolled_window_get_policy (GTK_SCROLLED_WINDOW (priv->scrolledwindow), &policy, NULL);
if (policy == GTK_POLICY_AUTOMATIC)
return;
/* Don't let it automatically get wider than the main CC window nor
get taller than the initial height */
gtk_window_get_size (gtk_window_get_transient_for (GTK_WINDOW (chooser)),
&width, NULL);
gtk_window_get_size (GTK_WINDOW (chooser), NULL, &height);
gtk_widget_set_size_request (chooser, width * MAIN_WINDOW_WIDTH_RATIO, height);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolledwindow),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
}
static void
add_input_source_rows_for_locale (GtkWidget *chooser,
LocaleInfo *info)
@ -332,8 +308,6 @@ show_input_sources_for_locale (GtkWidget *chooser,
{
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
set_fixed_size (chooser);
remove_all_children (GTK_CONTAINER (priv->list));
if (!info->back_row)
@ -609,8 +583,6 @@ show_more (GtkWidget *chooser)
{
CcInputChooserPrivate *priv = GET_PRIVATE (chooser);
set_fixed_size (chooser);
gtk_widget_show (priv->filter_entry);
gtk_widget_grab_focus (priv->filter_entry);
@ -1029,7 +1001,6 @@ cc_input_chooser_new (GtkWindow *main_window,
g_autoptr(GtkBuilder) builder = NULL;
GtkWidget *chooser;
CcInputChooserPrivate *priv;
gint width, height;
g_autoptr(GError) error = NULL;
builder = gtk_builder_new ();
@ -1074,11 +1045,6 @@ cc_input_chooser_new (GtkWindow *main_window,
#endif /* HAVE_IBUS */
show_locale_rows (chooser);
/* Try to come up with a sensible size */
gtk_window_get_size (main_window, &width, &height);
gtk_widget_set_size_request (chooser, width * MAIN_WINDOW_WIDTH_RATIO, -1);
gtk_window_set_resizable (GTK_WINDOW (chooser), TRUE);
gtk_window_set_transient_for (GTK_WINDOW (chooser), main_window);
return chooser;

View file

@ -44,6 +44,7 @@
<property name="margin-end">6</property>
<property name="margin-top">6</property>
<property name="margin-bottom">6</property>
<property name="min-content-height">300</property>
<child>
<object class="GtkViewport" id="viewport">
<property name="visible">True</property>