Merge branch 'misc-cleanups' into 'master'

Misc cleanups

See merge request GNOME/gtk!1832
This commit is contained in:
Matthias Clasen 2020-05-05 21:02:25 +00:00
commit 539f06147a
6 changed files with 593 additions and 836 deletions

View File

@ -3,24 +3,6 @@
outline-width: 0;
}
.border-inset {
border-style: inset;
}
.border-outset {
border-style: outset;
}
.border-groove {
border-style: groove;
}
.border-ridge {
border-style: ridge;
}
/* These effects use 2 lines, so show them */
.border-groove,
.border-ridge {
border-width: 2px;
.toolbar {
-gtk-icon-style: symbolic;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -37,30 +37,6 @@ G_BEGIN_DECLS
typedef struct _GtkPlacesView GtkPlacesView;
typedef struct _GtkPlacesViewClass GtkPlacesViewClass;
typedef struct _GtkPlacesViewPrivate GtkPlacesViewPrivate;
struct _GtkPlacesViewClass
{
GtkBoxClass parent_class;
void (* open_location) (GtkPlacesView *view,
GFile *location,
GtkPlacesOpenFlags open_flags);
void (* show_error_message) (GtkPlacesSidebar *sidebar,
const gchar *primary,
const gchar *secondary);
/*< private >*/
/* Padding for future expansion */
gpointer reserved[10];
};
struct _GtkPlacesView
{
GtkBox parent_instance;
};
GType gtk_places_view_get_type (void) G_GNUC_CONST;

View File

@ -90,14 +90,7 @@ typedef struct _GtkSearchBarClass GtkSearchBarClass;
struct _GtkSearchBar
{
GtkWidget parent;
};
struct _GtkSearchBarClass
{
GtkWidgetClass parent_class;
};
typedef struct {
GtkWidget *child;
GtkWidget *revealer;
GtkWidget *box_center;
@ -108,12 +101,16 @@ typedef struct {
GtkWidget *capture_widget;
GtkEventController *capture_widget_controller;
} GtkSearchBarPrivate;
};
struct _GtkSearchBarClass
{
GtkWidgetClass parent_class;
};
static void gtk_search_bar_buildable_iface_init (GtkBuildableIface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkSearchBar, gtk_search_bar, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkSearchBar)
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_search_bar_buildable_iface_init))
@ -153,8 +150,7 @@ static void
stop_search_cb (GtkWidget *entry,
GtkSearchBar *bar)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->revealer), FALSE);
gtk_revealer_set_reveal_child (GTK_REVEALER (bar->revealer), FALSE);
}
static void
@ -162,24 +158,23 @@ reveal_child_changed_cb (GObject *object,
GParamSpec *pspec,
GtkSearchBar *bar)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
gboolean reveal_child;
g_object_get (object, "reveal-child", &reveal_child, NULL);
if (reveal_child == priv->reveal_child)
if (reveal_child == bar->reveal_child)
return;
priv->reveal_child = reveal_child;
bar->reveal_child = reveal_child;
if (priv->entry)
if (bar->entry)
{
if (reveal_child && GTK_IS_ENTRY (priv->entry))
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (priv->entry));
else if (GTK_IS_SEARCH_ENTRY (priv->entry))
gtk_widget_grab_focus (priv->entry);
if (reveal_child && GTK_IS_ENTRY (bar->entry))
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (bar->entry));
else if (GTK_IS_SEARCH_ENTRY (bar->entry))
gtk_widget_grab_focus (bar->entry);
else
gtk_editable_set_text (GTK_EDITABLE (priv->entry), "");
gtk_editable_set_text (GTK_EDITABLE (bar->entry), "");
}
g_object_notify_by_pspec (G_OBJECT (bar), widget_props[PROP_SEARCH_MODE_ENABLED]);
@ -189,9 +184,7 @@ static void
close_button_clicked_cb (GtkWidget *button,
GtkSearchBar *bar)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->revealer), FALSE);
gtk_revealer_set_reveal_child (GTK_REVEALER (bar->revealer), FALSE);
}
static void
@ -251,16 +244,15 @@ static void
gtk_search_bar_dispose (GObject *object)
{
GtkSearchBar *bar = GTK_SEARCH_BAR (object);
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
gtk_search_bar_set_key_capture_widget (bar, NULL);
gtk_search_bar_set_entry (bar, NULL);
g_clear_pointer (&priv->revealer, gtk_widget_unparent);
g_clear_pointer (&bar->revealer, gtk_widget_unparent);
priv->child = NULL;
priv->box_center = NULL;
priv->close_button = NULL;
bar->child = NULL;
bar->box_center = NULL;
bar->close_button = NULL;
G_OBJECT_CLASS (gtk_search_bar_parent_class)->dispose (object);
}
@ -271,12 +263,11 @@ gtk_search_bar_compute_expand (GtkWidget *widget,
gboolean *vexpand)
{
GtkSearchBar *bar = GTK_SEARCH_BAR (widget);
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
if (priv->child)
if (bar->child)
{
*hexpand = gtk_widget_compute_expand (priv->child, GTK_ORIENTATION_HORIZONTAL);
*vexpand = gtk_widget_compute_expand (priv->child, GTK_ORIENTATION_VERTICAL);
*hexpand = gtk_widget_compute_expand (bar->child, GTK_ORIENTATION_HORIZONTAL);
*vexpand = gtk_widget_compute_expand (bar->child, GTK_ORIENTATION_VERTICAL);
}
else
{
@ -338,27 +329,25 @@ gtk_search_bar_class_init (GtkSearchBarClass *klass)
static void
gtk_search_bar_init (GtkSearchBar *bar)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
bar->revealer = gtk_revealer_new ();
gtk_revealer_set_reveal_child (GTK_REVEALER (bar->revealer), FALSE);
gtk_widget_set_hexpand (bar->revealer, TRUE);
gtk_widget_set_parent (bar->revealer, GTK_WIDGET (bar));
priv->revealer = gtk_revealer_new ();
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->revealer), FALSE);
gtk_widget_set_hexpand (priv->revealer, TRUE);
gtk_widget_set_parent (priv->revealer, GTK_WIDGET (bar));
bar->box_center = gtk_center_box_new ();
gtk_widget_set_hexpand (bar->box_center, TRUE);
priv->box_center = gtk_center_box_new ();
gtk_widget_set_hexpand (priv->box_center, TRUE);
bar->close_button = gtk_button_new_from_icon_name ("window-close-symbolic");
gtk_widget_add_css_class (bar->close_button, "close");
gtk_center_box_set_end_widget (GTK_CENTER_BOX (bar->box_center), bar->close_button);
gtk_widget_hide (bar->close_button);
priv->close_button = gtk_button_new_from_icon_name ("window-close-symbolic");
gtk_widget_add_css_class (priv->close_button, "close");
gtk_center_box_set_end_widget (GTK_CENTER_BOX (priv->box_center), priv->close_button);
gtk_widget_hide (priv->close_button);
gtk_revealer_set_child (GTK_REVEALER (bar->revealer), bar->box_center);
gtk_revealer_set_child (GTK_REVEALER (priv->revealer), priv->box_center);
g_signal_connect (priv->revealer, "notify::reveal-child",
g_signal_connect (bar->revealer, "notify::reveal-child",
G_CALLBACK (reveal_child_changed_cb), bar);
g_signal_connect (priv->close_button, "clicked",
g_signal_connect (bar->close_button, "clicked",
G_CALLBACK (close_button_clicked_cb), bar);
}
@ -381,28 +370,26 @@ static void
gtk_search_bar_set_entry (GtkSearchBar *bar,
GtkEditable *entry)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
if (priv->entry != NULL)
if (bar->entry != NULL)
{
if (GTK_IS_SEARCH_ENTRY (priv->entry))
if (GTK_IS_SEARCH_ENTRY (bar->entry))
{
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (priv->entry), NULL);
g_signal_handlers_disconnect_by_func (priv->entry, stop_search_cb, bar);
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (bar->entry), NULL);
g_signal_handlers_disconnect_by_func (bar->entry, stop_search_cb, bar);
}
g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *) &priv->entry);
g_object_remove_weak_pointer (G_OBJECT (bar->entry), (gpointer *) &bar->entry);
}
priv->entry = GTK_WIDGET (entry);
bar->entry = GTK_WIDGET (entry);
if (priv->entry != NULL)
if (bar->entry != NULL)
{
g_object_add_weak_pointer (G_OBJECT (priv->entry), (gpointer *) &priv->entry);
if (GTK_IS_SEARCH_ENTRY (priv->entry))
g_object_add_weak_pointer (G_OBJECT (bar->entry), (gpointer *) &bar->entry);
if (GTK_IS_SEARCH_ENTRY (bar->entry))
{
g_signal_connect (priv->entry, "stop-search",
g_signal_connect (bar->entry, "stop-search",
G_CALLBACK (stop_search_cb), bar);
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (priv->entry),
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (bar->entry),
GTK_WIDGET (bar));
}
@ -440,11 +427,9 @@ gtk_search_bar_connect_entry (GtkSearchBar *bar,
gboolean
gtk_search_bar_get_search_mode (GtkSearchBar *bar)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
g_return_val_if_fail (GTK_IS_SEARCH_BAR (bar), FALSE);
return priv->reveal_child;
return bar->reveal_child;
}
/**
@ -458,11 +443,9 @@ void
gtk_search_bar_set_search_mode (GtkSearchBar *bar,
gboolean search_mode)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->revealer), search_mode);
gtk_revealer_set_reveal_child (GTK_REVEALER (bar->revealer), search_mode);
}
/**
@ -476,11 +459,9 @@ gtk_search_bar_set_search_mode (GtkSearchBar *bar,
gboolean
gtk_search_bar_get_show_close_button (GtkSearchBar *bar)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
g_return_val_if_fail (GTK_IS_SEARCH_BAR (bar), FALSE);
return gtk_widget_get_visible (priv->close_button);
return gtk_widget_get_visible (bar->close_button);
}
/**
@ -497,15 +478,13 @@ void
gtk_search_bar_set_show_close_button (GtkSearchBar *bar,
gboolean visible)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
visible = visible != FALSE;
if (gtk_widget_get_visible (priv->close_button) != visible)
if (gtk_widget_get_visible (bar->close_button) != visible)
{
gtk_widget_set_visible (priv->close_button, visible);
gtk_widget_set_visible (bar->close_button, visible);
g_object_notify_by_pspec (G_OBJECT (bar), widget_props[PROP_SHOW_CLOSE_BUTTON]);
}
}
@ -523,22 +502,21 @@ capture_widget_key_handled (GtkEventControllerKey *controller,
GdkModifierType state,
GtkSearchBar *bar)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
gboolean handled;
if (!gtk_widget_get_mapped (GTK_WIDGET (bar)))
return GDK_EVENT_PROPAGATE;
if (priv->reveal_child)
if (bar->reveal_child)
return GDK_EVENT_PROPAGATE;
if (priv->entry == NULL)
if (bar->entry == NULL)
{
g_warning ("The search bar does not have an entry connected to it. Call gtk_search_bar_connect_entry() to connect one.");
return GDK_EVENT_PROPAGATE;
}
if (GTK_IS_SEARCH_ENTRY (priv->entry))
if (GTK_IS_SEARCH_ENTRY (bar->entry))
{
/* The search entry was told to listen to events from the search bar, so
* just forward the event to self, so the search entry has an opportunity
@ -559,9 +537,9 @@ capture_widget_key_handled (GtkEventControllerKey *controller,
if (keyval == GDK_KEY_Escape)
{
if (gtk_revealer_get_reveal_child (GTK_REVEALER (priv->revealer)))
if (gtk_revealer_get_reveal_child (GTK_REVEALER (bar->revealer)))
{
stop_search_cb (priv->entry, bar);
stop_search_cb (bar->entry, bar);
return GDK_EVENT_STOP;
}
@ -570,22 +548,22 @@ capture_widget_key_handled (GtkEventControllerKey *controller,
handled = GDK_EVENT_PROPAGATE;
preedit_changed = buffer_changed = FALSE;
preedit_change_id = g_signal_connect_swapped (priv->entry, "preedit-changed",
preedit_change_id = g_signal_connect_swapped (bar->entry, "preedit-changed",
G_CALLBACK (changed_cb), &preedit_changed);
buffer_change_id = g_signal_connect_swapped (priv->entry, "changed",
buffer_change_id = g_signal_connect_swapped (bar->entry, "changed",
G_CALLBACK (changed_cb), &buffer_changed);
res = gtk_event_controller_key_forward (controller, priv->entry);
res = gtk_event_controller_key_forward (controller, bar->entry);
g_signal_handler_disconnect (priv->entry, preedit_change_id);
g_signal_handler_disconnect (priv->entry, buffer_change_id);
g_signal_handler_disconnect (bar->entry, preedit_change_id);
g_signal_handler_disconnect (bar->entry, buffer_change_id);
if ((res && buffer_changed) || preedit_changed)
handled = GDK_EVENT_STOP;
}
if (handled == GDK_EVENT_STOP)
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->revealer), TRUE);
gtk_revealer_set_reveal_child (GTK_REVEALER (bar->revealer), TRUE);
return handled;
}
@ -602,39 +580,37 @@ capture_widget_key_handled (GtkEventControllerKey *controller,
**/
void
gtk_search_bar_set_key_capture_widget (GtkSearchBar *bar,
GtkWidget *widget)
GtkWidget *widget)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
g_return_if_fail (!widget || GTK_IS_WIDGET (widget));
if (priv->capture_widget == widget)
if (bar->capture_widget == widget)
return;
if (priv->capture_widget)
if (bar->capture_widget)
{
gtk_widget_remove_controller (priv->capture_widget,
priv->capture_widget_controller);
g_object_remove_weak_pointer (G_OBJECT (priv->capture_widget),
(gpointer *) &priv->capture_widget);
gtk_widget_remove_controller (bar->capture_widget,
bar->capture_widget_controller);
g_object_remove_weak_pointer (G_OBJECT (bar->capture_widget),
(gpointer *) &bar->capture_widget);
}
priv->capture_widget = widget;
bar->capture_widget = widget;
if (widget)
{
g_object_add_weak_pointer (G_OBJECT (priv->capture_widget),
(gpointer *) &priv->capture_widget);
g_object_add_weak_pointer (G_OBJECT (bar->capture_widget),
(gpointer *) &bar->capture_widget);
priv->capture_widget_controller = gtk_event_controller_key_new ();
gtk_event_controller_set_propagation_phase (priv->capture_widget_controller,
bar->capture_widget_controller = gtk_event_controller_key_new ();
gtk_event_controller_set_propagation_phase (bar->capture_widget_controller,
GTK_PHASE_CAPTURE);
g_signal_connect (priv->capture_widget_controller, "key-pressed",
g_signal_connect (bar->capture_widget_controller, "key-pressed",
G_CALLBACK (capture_widget_key_handled), bar);
g_signal_connect (priv->capture_widget_controller, "key-released",
g_signal_connect (bar->capture_widget_controller, "key-released",
G_CALLBACK (capture_widget_key_handled), bar);
gtk_widget_add_controller (widget, priv->capture_widget_controller);
gtk_widget_add_controller (widget, bar->capture_widget_controller);
}
}
@ -649,11 +625,9 @@ gtk_search_bar_set_key_capture_widget (GtkSearchBar *bar,
GtkWidget *
gtk_search_bar_get_key_capture_widget (GtkSearchBar *bar)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
g_return_val_if_fail (GTK_IS_SEARCH_BAR (bar), NULL);
return priv->capture_widget;
return bar->capture_widget;
}
/**
@ -667,21 +641,19 @@ void
gtk_search_bar_set_child (GtkSearchBar *bar,
GtkWidget *child)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
if (priv->child)
if (bar->child)
{
if (GTK_IS_EDITABLE (priv->child))
if (GTK_IS_EDITABLE (bar->child))
gtk_search_bar_connect_entry (bar, NULL);
gtk_center_box_set_center_widget (GTK_CENTER_BOX (priv->box_center), NULL);
gtk_center_box_set_center_widget (GTK_CENTER_BOX (bar->box_center), NULL);
}
priv->child = child;
bar->child = child;
if (priv->child)
if (bar->child)
{
gtk_center_box_set_center_widget (GTK_CENTER_BOX (priv->box_center), child);
gtk_center_box_set_center_widget (GTK_CENTER_BOX (bar->box_center), child);
if (GTK_IS_EDITABLE (child))
gtk_search_bar_connect_entry (bar, GTK_EDITABLE (child));
@ -701,7 +673,5 @@ gtk_search_bar_set_child (GtkSearchBar *bar,
GtkWidget *
gtk_search_bar_get_child (GtkSearchBar *bar)
{
GtkSearchBarPrivate *priv = gtk_search_bar_get_instance_private (bar);
return priv->child;
return bar->child;
}

View File

@ -163,7 +163,10 @@
#define MENU_BAR_ACCEL GDK_KEY_F10
#define RESIZE_HANDLE_SIZE 20
#define MNEMONICS_DELAY 300 /* ms */
#define NO_CONTENT_CHILD_NAT 200
#define NO_CONTENT_CHILD_NAT 200 /* ms */
#define VISIBLE_FOCUS_DURATION 3 /* s */
/* In case the content (excluding header bar and shadows) of the window
* would be empty, either because there is no visible child widget or only an
* empty container widget, we use NO_CONTENT_CHILD_NAT as natural width/height
@ -7470,7 +7473,7 @@ gtk_window_set_focus_visible (GtkWindow *window,
}
if (priv->focus_visible)
priv->focus_visible_timeout = g_timeout_add_seconds (5, unset_focus_visible, window);
priv->focus_visible_timeout = g_timeout_add_seconds (VISIBLE_FOCUS_DURATION, unset_focus_visible, window);
if (changed)
{