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

Matthiasc/for master

See merge request GNOME/gtk!1897
This commit is contained in:
Matthias Clasen 2020-05-14 05:47:26 +00:00
commit 64db8be7d5
7 changed files with 77 additions and 16 deletions

View File

@ -419,6 +419,7 @@ do_dnd (GtkWidget *do_widget)
{ {
if (!window) if (!window)
{ {
GtkWidget *button;
GtkWidget *sw; GtkWidget *sw;
GtkWidget *canvas; GtkWidget *canvas;
GtkWidget *box, *box2, *box3; GtkWidget *box, *box2, *box3;
@ -431,7 +432,8 @@ do_dnd (GtkWidget *do_widget)
int i; int i;
int x, y; int x, y;
g_type_ensure (GTK_TYPE_COLOR_BUTTON); button = gtk_color_button_new ();
g_object_unref (g_object_ref_sink (button));
window = gtk_window_new (); window = gtk_window_new ();
gtk_window_set_display (GTK_WINDOW (window), gtk_window_set_display (GTK_WINDOW (window),

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

View File

@ -1082,13 +1082,29 @@ typedef struct {
gchar *filename; gchar *filename;
} BackgroundData; } BackgroundData;
static void
add_background (GtkWidget *flowbox,
const char *filename,
GdkPixbuf *pixbuf,
gboolean is_resource)
{
GtkWidget *child;
child = gtk_picture_new_for_pixbuf (pixbuf);
gtk_widget_set_size_request (child, 110, 70);
gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), child, -1);
child = gtk_widget_get_parent (child);
g_object_set_data_full (G_OBJECT (child), "filename", g_strdup (filename), g_free);
if (is_resource)
g_object_set_data (G_OBJECT (child), "is-resource", GINT_TO_POINTER (1));
}
static void static void
background_loaded_cb (GObject *source, background_loaded_cb (GObject *source,
GAsyncResult *res, GAsyncResult *res,
gpointer data) gpointer data)
{ {
BackgroundData *bd = data; BackgroundData *bd = data;
GtkWidget *child;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
GError *error = NULL; GError *error = NULL;
@ -1100,11 +1116,9 @@ background_loaded_cb (GObject *source,
return; return;
} }
child = gtk_picture_new_for_pixbuf (pixbuf); add_background (bd->flowbox, bd->filename, pixbuf, FALSE);
gtk_widget_set_size_request (child, 110, 70);
gtk_flow_box_insert (GTK_FLOW_BOX (bd->flowbox), child, -1); g_free (bd->filename);
child = gtk_widget_get_parent (child);
g_object_set_data_full (G_OBJECT (child), "filename", bd->filename, g_free);
g_free (bd); g_free (bd);
} }
@ -1121,6 +1135,10 @@ populate_flowbox (GtkWidget *flowbox)
BackgroundData *bd; BackgroundData *bd;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
GtkWidget *child; GtkWidget *child;
int i;
const char *resources[] = {
"sunset.jpg", "snowy.jpg", "portland-rose.jpg"
};
if (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (flowbox), "populated"))) if (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (flowbox), "populated")))
return; return;
@ -1132,6 +1150,13 @@ populate_flowbox (GtkWidget *flowbox)
child = gtk_picture_new_for_pixbuf (pixbuf); child = gtk_picture_new_for_pixbuf (pixbuf);
gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), child, -1); gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), child, -1);
for (i = 0; i < G_N_ELEMENTS (resources); i++)
{
filename = g_strconcat ("/org/gtk/WidgetFactory4/", resources[i], NULL);
pixbuf = gdk_pixbuf_new_from_resource_at_scale (filename, 110, 110, TRUE, NULL);
add_background (flowbox, filename, pixbuf, TRUE);
}
location = "/usr/share/backgrounds/gnome"; location = "/usr/share/backgrounds/gnome";
dir = g_dir_open (location, 0, &error); dir = g_dir_open (location, 0, &error);
if (error) if (error)
@ -1153,7 +1178,7 @@ populate_flowbox (GtkWidget *flowbox)
{ {
g_warning ("%s", error->message); g_warning ("%s", error->message);
g_clear_error (&error); g_clear_error (&error);
g_free (filename); g_free (filename);
} }
else else
{ {
@ -1169,6 +1194,7 @@ populate_flowbox (GtkWidget *flowbox)
} }
g_dir_close (dir); g_dir_close (dir);
} }
static void static void
@ -1197,6 +1223,7 @@ typedef struct
{ {
GtkTextView tv; GtkTextView tv;
GdkTexture *texture; GdkTexture *texture;
GtkAdjustment *adjustment;
} MyTextView; } MyTextView;
typedef GtkTextViewClass MyTextViewClass; typedef GtkTextViewClass MyTextViewClass;
@ -1215,10 +1242,16 @@ my_tv_snapshot_layer (GtkTextView *widget,
GtkSnapshot *snapshot) GtkSnapshot *snapshot)
{ {
MyTextView *tv = (MyTextView *)widget; MyTextView *tv = (MyTextView *)widget;
double opacity;
double scale;
opacity = gtk_adjustment_get_value (tv->adjustment) / 100.0;
if (layer == GTK_TEXT_VIEW_LAYER_BELOW_TEXT && tv->texture) if (layer == GTK_TEXT_VIEW_LAYER_BELOW_TEXT && tv->texture)
{ {
gtk_snapshot_push_opacity (snapshot, 0.333); scale = gtk_widget_get_width (GTK_WIDGET (widget)) / (double)gdk_texture_get_width (tv->texture);
gtk_snapshot_push_opacity (snapshot, opacity);
gtk_snapshot_scale (snapshot, scale, scale);
gtk_snapshot_append_texture (snapshot, gtk_snapshot_append_texture (snapshot,
tv->texture, tv->texture,
&GRAPHENE_RECT_INIT( &GRAPHENE_RECT_INIT(
@ -1226,6 +1259,7 @@ my_tv_snapshot_layer (GtkTextView *widget,
gdk_texture_get_width (tv->texture), gdk_texture_get_width (tv->texture),
gdk_texture_get_height (tv->texture) gdk_texture_get_height (tv->texture)
)); ));
gtk_snapshot_scale (snapshot, 1/scale, 1/scale);
gtk_snapshot_pop (snapshot); gtk_snapshot_pop (snapshot);
} }
} }
@ -1251,7 +1285,7 @@ my_text_view_class_init (MyTextViewClass *class)
} }
static void static void
my_text_view_set_background (MyTextView *tv, const gchar *filename) my_text_view_set_background (MyTextView *tv, const gchar *filename, gboolean is_resource)
{ {
GError *error = NULL; GError *error = NULL;
GFile *file; GFile *file;
@ -1261,9 +1295,14 @@ my_text_view_set_background (MyTextView *tv, const gchar *filename)
if (filename == NULL) if (filename == NULL)
return; return;
file = g_file_new_for_path (filename); if (is_resource)
tv->texture = gdk_texture_new_from_file (file, &error); tv->texture = gdk_texture_new_from_resource (filename);
g_object_unref (file); else
{
file = g_file_new_for_path (filename);
tv->texture = gdk_texture_new_from_file (file, &error);
g_object_unref (file);
}
if (error) if (error)
{ {
@ -1275,6 +1314,19 @@ my_text_view_set_background (MyTextView *tv, const gchar *filename)
gtk_widget_queue_draw (GTK_WIDGET (tv)); gtk_widget_queue_draw (GTK_WIDGET (tv));
} }
static void
value_changed (GtkAdjustment *adjustment, MyTextView *tv)
{
gtk_widget_queue_draw (GTK_WIDGET (tv));
}
static void
my_text_view_set_adjustment (MyTextView *tv, GtkAdjustment *adjustment)
{
g_set_object (&tv->adjustment, adjustment);
g_signal_connect (tv->adjustment, "value-changed", G_CALLBACK (value_changed), tv);
}
static void static void
close_selection_dialog (GtkWidget *dialog, gint response, GtkWidget *tv) close_selection_dialog (GtkWidget *dialog, gint response, GtkWidget *tv)
{ {
@ -1282,6 +1334,7 @@ close_selection_dialog (GtkWidget *dialog, gint response, GtkWidget *tv)
GtkWidget *child; GtkWidget *child;
GList *children; GList *children;
const gchar *filename; const gchar *filename;
gboolean is_resource;
gtk_widget_hide (dialog); gtk_widget_hide (dialog);
@ -1297,10 +1350,11 @@ close_selection_dialog (GtkWidget *dialog, gint response, GtkWidget *tv)
child = children->data; child = children->data;
filename = (const gchar *)g_object_get_data (G_OBJECT (child), "filename"); filename = (const gchar *)g_object_get_data (G_OBJECT (child), "filename");
is_resource = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (child), "is-resource"));
g_list_free (children); g_list_free (children);
my_text_view_set_background ((MyTextView *)tv, filename); my_text_view_set_background ((MyTextView *)tv, filename, is_resource);
} }
static void static void
@ -1985,6 +2039,8 @@ activate (GApplication *app)
g_object_set_data (G_OBJECT (window), "selection_dialog", dialog); g_object_set_data (G_OBJECT (window), "selection_dialog", dialog);
widget = (GtkWidget *)gtk_builder_get_object (builder, "text3"); widget = (GtkWidget *)gtk_builder_get_object (builder, "text3");
g_signal_connect (dialog, "response", G_CALLBACK (close_selection_dialog), widget); g_signal_connect (dialog, "response", G_CALLBACK (close_selection_dialog), widget);
widget2 = (GtkWidget *)gtk_builder_get_object (builder, "opacity");
my_text_view_set_adjustment ((MyTextView *)widget, gtk_range_get_adjustment (GTK_RANGE (widget2)));
widget = (GtkWidget *)gtk_builder_get_object (builder, "selection_dialog_button"); widget = (GtkWidget *)gtk_builder_get_object (builder, "selection_dialog_button");
g_signal_connect (widget, "clicked", G_CALLBACK (show_dialog), dialog); g_signal_connect (widget, "clicked", G_CALLBACK (show_dialog), dialog);

View File

@ -37,5 +37,8 @@
</gresource> </gresource>
<gresource prefix="/org/gtk/WidgetFactory4"> <gresource prefix="/org/gtk/WidgetFactory4">
<file>gtk-logo.webm</file> <file>gtk-logo.webm</file>
<file>sunset.jpg</file>
<file>snowy.jpg</file>
<file>portland-rose.jpg</file>
</gresource> </gresource>
</gresources> </gresources>

View File

@ -129,7 +129,7 @@
</menu> </menu>
<object class="GtkAdjustment" id="adjustment1"> <object class="GtkAdjustment" id="adjustment1">
<property name="upper">100</property> <property name="upper">100</property>
<property name="lower">1</property> <property name="lower">0</property>
<property name="value">50</property> <property name="value">50</property>
<property name="step-increment">1</property> <property name="step-increment">1</property>
<property name="page-increment">10</property> <property name="page-increment">10</property>
@ -1709,7 +1709,7 @@ microphone-sensitivity-medium-symbolic</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkScale"> <object class="GtkScale" id="opacity">
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">center</property> <property name="valign">center</property>
<property name="margin-top">6</property> <property name="margin-top">6</property>