Merge branch 'matthiasc/for-master' into 'master'

Matthiasc/for master

Closes #227, #328, and #1010

See merge request GNOME/gtk!1954
This commit is contained in:
Matthias Clasen 2020-05-22 01:59:34 +00:00
commit 641f2f72cd
6 changed files with 116 additions and 111 deletions

View File

@ -220,14 +220,14 @@ static inline gboolean
is_primary (const gchar *string)
{
return ((string[0] == '<') &&
(string[1] == 'p' || string[1] == 'P') &&
(string[2] == 'r' || string[2] == 'R') &&
(string[3] == 'i' || string[3] == 'I') &&
(string[4] == 'm' || string[4] == 'M') &&
(string[5] == 'a' || string[5] == 'A') &&
(string[6] == 'r' || string[6] == 'R') &&
(string[7] == 'y' || string[7] == 'Y') &&
(string[8] == '>'));
(string[1] == 'p' || string[1] == 'P') &&
(string[2] == 'r' || string[2] == 'R') &&
(string[3] == 'i' || string[3] == 'I') &&
(string[4] == 'm' || string[4] == 'M') &&
(string[5] == 'a' || string[5] == 'A') &&
(string[6] == 'r' || string[6] == 'R') &&
(string[7] == 'y' || string[7] == 'Y') &&
(string[8] == '>'));
}
static inline gboolean
@ -411,15 +411,15 @@ gtk_accelerator_parse_with_keycode (const gchar *accelerator,
goto out;
}
}
else
{
keyval = gdk_keyval_from_name (accelerator);
if (keyval == GDK_KEY_VoidSymbol)
{
error = TRUE;
goto out;
}
}
else
{
keyval = gdk_keyval_from_name (accelerator);
if (keyval == GDK_KEY_VoidSymbol)
{
error = TRUE;
goto out;
}
}
if (keyval && accelerator_codes != NULL)
{
@ -841,7 +841,7 @@ gtk_accelerator_print_label (GString *gstring,
g_string_append (gstring, C_("keyboard label", "Shift"));
#else
/* U+21E7 UPWARDS WHITE ARROW */
g_string_append (gstring, "\xe2\x87\xa7");
g_string_append (gstring, "");
#endif
seen_mod = TRUE;
}
@ -860,7 +860,7 @@ gtk_accelerator_print_label (GString *gstring,
g_string_append (gstring, C_("keyboard label", "Ctrl"));
#else
/* U+2303 UP ARROWHEAD */
g_string_append (gstring, "\xe2\x8c\x83");
g_string_append (gstring, "");
#endif
seen_mod = TRUE;
}
@ -879,7 +879,7 @@ gtk_accelerator_print_label (GString *gstring,
g_string_append (gstring, C_("keyboard label", "Alt"));
#else
/* U+2325 OPTION KEY */
g_string_append (gstring, "\xe2\x8c\xa5");
g_string_append (gstring, "");
#endif
seen_mod = TRUE;
}
@ -925,8 +925,7 @@ gtk_accelerator_print_label (GString *gstring,
*/
g_string_append (gstring, C_("keyboard label", "Meta"));
#else
/* Command key symbol U+2318 PLACE OF INTEREST SIGN */
g_string_append (gstring, "\xe2\x8c\x98");
g_string_append (gstring, "");
#endif
seen_mod = TRUE;
}
@ -937,18 +936,25 @@ gtk_accelerator_print_label (GString *gstring,
if (seen_mod)
append_separator (gstring);
if (accelerator_key >= GDK_KEY_KP_Space &&
accelerator_key <= GDK_KEY_KP_Equal)
{
g_string_append (gstring, C_("keyboard label", "KP"));
g_string_append (gstring, "");
}
switch (ch)
{
case ' ':
g_string_append (gstring, C_("keyboard label", "Space"));
break;
case '\\':
g_string_append (gstring, C_("keyboard label", "Backslash"));
break;
default:
g_string_append_unichar (gstring, g_unichar_toupper (ch));
break;
}
{
case ' ':
g_string_append (gstring, C_("keyboard label", "Space"));
break;
case '\\':
g_string_append (gstring, C_("keyboard label", "Backslash"));
break;
default:
g_string_append_unichar (gstring, g_unichar_toupper (ch));
break;
}
}
else if (!append_keyval_symbol (accelerator_key, gstring))
{
@ -956,22 +962,22 @@ gtk_accelerator_print_label (GString *gstring,
tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
if (tmp != NULL)
{
{
if (seen_mod)
append_separator (gstring);
if (tmp[0] != 0 && tmp[1] == 0)
g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
else
{
const char *str;
if (tmp[0] != 0 && tmp[1] == 0)
g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
else
{
const char *str;
str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp);
if (str == tmp)
if (str == tmp)
append_without_underscores (gstring, tmp);
else
g_string_append (gstring, str);
}
}
else
g_string_append (gstring, str);
}
}
}
}

View File

@ -1746,9 +1746,9 @@ coord_to_value (GtkRange *range,
else
{
if (priv->slider_size_fixed)
frac = MAX (0, coord) / (double) (trough_length);
frac = CLAMP (coord / (double) trough_length, 0, 1);
else
frac = MAX (0, coord) / (double) (trough_length - slider_length);
frac = CLAMP (coord / (double) (trough_length - slider_length), 0, 1);
}
if (should_invert (range))

View File

@ -919,18 +919,21 @@ _gtk_tooltip_handle_event (GtkWidget *target,
GdkSurface *surface;
double x, y;
double nx, ny;
GtkWidget *native;
GtkNative *native;
if (!tooltips_enabled (event))
return;
native = gtk_widget_get_native (target);
if (!native)
return;
event_type = gdk_event_get_event_type (event);
surface = gdk_event_get_surface (event);
gdk_event_get_position (event, &x, &y);
native = GTK_WIDGET (gtk_widget_get_native (target));
gtk_native_get_surface_transform (GTK_NATIVE (native), &nx, &ny);
gtk_widget_translate_coordinates (native, target, x - nx, y - ny, &x, &y);
gtk_native_get_surface_transform (native, &nx, &ny);
gtk_widget_translate_coordinates (GTK_WIDGET (native), target, x - nx, y - ny, &x, &y);
gtk_tooltip_handle_event_internal (event_type, surface, target, x, y);
}

View File

@ -24,6 +24,8 @@
#include "gtkmarshalers.h"
#include "gtktrashmonitor.h"
#define UPDATE_RATE_SECONDS 1
struct _GtkTrashMonitor
{
GObject parent;
@ -31,6 +33,9 @@ struct _GtkTrashMonitor
GFileMonitor *file_monitor;
gulong file_monitor_changed_id;
gboolean pending;
gint timeout_id;
guint has_trash : 1;
};
@ -70,6 +75,10 @@ gtk_trash_monitor_dispose (GObject *object)
g_clear_object (&monitor->file_monitor);
}
if (monitor->timeout_id > 0)
g_source_remove (monitor->timeout_id);
monitor->timeout_id = 0;
G_OBJECT_CLASS (_gtk_trash_monitor_parent_class)->dispose (object);
}
@ -84,18 +93,18 @@ _gtk_trash_monitor_class_init (GtkTrashMonitorClass *class)
signals[TRASH_STATE_CHANGED] =
g_signal_new (I_("trash-state-changed"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkTrashMonitorClass, trash_state_changed),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkTrashMonitorClass, trash_state_changed),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
}
/* Updates the internal has_trash flag and emits the "trash-state-changed" signal */
static void
update_has_trash_and_notify (GtkTrashMonitor *monitor,
gboolean has_trash)
gboolean has_trash)
{
if (monitor->has_trash == !!has_trash)
return;
@ -136,12 +145,38 @@ trash_query_info_cb (GObject *source,
g_object_unref (monitor); /* was reffed in recompute_trash_state() */
}
static void recompute_trash_state (GtkTrashMonitor *monitor);
static gboolean
recompute_trash_state_cb (gpointer data)
{
GtkTrashMonitor *monitor = data;
monitor->timeout_id = 0;
if (monitor->pending)
{
monitor->pending = FALSE;
recompute_trash_state (monitor);
}
return G_SOURCE_REMOVE;
}
/* Asynchronously recomputes whether there is trash or not */
static void
recompute_trash_state (GtkTrashMonitor *monitor)
{
GFile *file;
/* Rate limit the updates to not flood the gvfsd-trash when too many changes
* happended in a short time.
*/
if (monitor->timeout_id > 0)
{
monitor->pending = TRUE;
return;
}
file = g_file_new_for_uri ("trash:///");
g_file_query_info_async (file,
G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT,
@ -149,6 +184,10 @@ recompute_trash_state (GtkTrashMonitor *monitor)
G_PRIORITY_DEFAULT, NULL,
trash_query_info_cb, g_object_ref (monitor));
monitor->timeout_id = g_timeout_add_seconds (UPDATE_RATE_SECONDS,
recompute_trash_state_cb,
monitor);
g_object_unref (file);
}
@ -156,11 +195,11 @@ recompute_trash_state (GtkTrashMonitor *monitor)
* whenever something happens.
*/
static void
file_monitor_changed_cb (GFileMonitor *file_monitor,
GFile *child,
GFile *other_file,
GFileMonitorEvent event_type,
GtkTrashMonitor *monitor)
file_monitor_changed_cb (GFileMonitor *file_monitor,
GFile *child,
GFile *other_file,
GFileMonitorEvent event_type,
GtkTrashMonitor *monitor)
{
recompute_trash_state (monitor);
}
@ -173,12 +212,14 @@ _gtk_trash_monitor_init (GtkTrashMonitor *monitor)
file = g_file_new_for_uri ("trash:///");
monitor->file_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
monitor->pending = FALSE;
monitor->timeout_id = 0;
g_object_unref (file);
if (monitor->file_monitor)
monitor->file_monitor_changed_id = g_signal_connect (monitor->file_monitor, "changed",
G_CALLBACK (file_monitor_changed_cb), monitor);
G_CALLBACK (file_monitor_changed_cb), monitor);
recompute_trash_state (monitor);
}

View File

@ -106,37 +106,6 @@ restore_window_clicked (GtkModelButton *button,
gtk_window_unmaximize (window);
}
static void
move_window_clicked (GtkModelButton *button,
GtkWindowHandle *self)
{
GtkNative *native = gtk_widget_get_native (GTK_WIDGET (self));
GdkSurface *surface = gtk_native_get_surface (native);
if (GDK_IS_TOPLEVEL (surface))
gdk_toplevel_begin_move (GDK_TOPLEVEL (surface),
NULL,
0, /* 0 means "use keyboard" */
0, 0,
GDK_CURRENT_TIME);
}
static void
resize_window_clicked (GtkModelButton *button,
GtkWindowHandle *self)
{
GtkNative *native = gtk_widget_get_native (GTK_WIDGET (self));
GdkSurface *surface = gtk_native_get_surface (native);
if (GDK_IS_TOPLEVEL (surface))
gdk_toplevel_begin_resize (GDK_TOPLEVEL (surface),
0,
NULL,
0, /* 0 means "use keyboard" */
0, 0,
GDK_CURRENT_TIME);
}
static void
minimize_window_clicked (GtkModelButton *button,
GtkWindowHandle *self)
@ -251,20 +220,6 @@ do_popup_fallback (GtkWindowHandle *self,
G_CALLBACK (restore_window_clicked), self);
gtk_box_append (GTK_BOX (box), menuitem);
menuitem = gtk_model_button_new ();
g_object_set (menuitem, "text", _("Move"), NULL);
gtk_widget_set_sensitive (menuitem, !maximized);
g_signal_connect (G_OBJECT (menuitem), "clicked",
G_CALLBACK (move_window_clicked), self);
gtk_box_append (GTK_BOX (box), menuitem);
menuitem = gtk_model_button_new ();
g_object_set (menuitem, "text", _("Resize"), NULL);
gtk_widget_set_sensitive (menuitem, resizable && !maximized);
g_signal_connect (G_OBJECT (menuitem), "clicked",
G_CALLBACK (resize_window_clicked), self);
gtk_box_append (GTK_BOX (box), menuitem);
menuitem = gtk_model_button_new ();
g_object_set (menuitem, "text", _("Minimize"), NULL);
g_signal_connect (G_OBJECT (menuitem), "clicked",

View File

@ -87,13 +87,13 @@ accel2 (void)
static void
accel3 (void)
{
test_one_accel ("KP_7", 0, GDK_KEY_KP_7, "7", TRUE);
test_one_accel ("KP_7", 0, GDK_KEY_KP_7, "KP7", TRUE);
}
static void
accel4 (void)
{
test_one_accel ("<Control>KP_7", GDK_CONTROL_MASK, GDK_KEY_KP_7, "Ctrl+7", TRUE);
test_one_accel ("<Control>KP_7", GDK_CONTROL_MASK, GDK_KEY_KP_7, "Ctrl+KP7", TRUE);
}
static void