Commit Graph

347 Commits

Author SHA1 Message Date
Matthias Clasen
724863c275 icontheme: Add a trailing / when enumerating resources
This avoids extra string copies in GResource.
2017-11-13 12:13:42 -05:00
Matthias Clasen
ec1ea0db04 icontheme: Append a / to the resource path
g_resources_enumerate_children expects the path to end
in a '/' (even though thats not stated in the docs), and
will copy it if that isn't the case. Avoid the copy
by putting  a '/' there to begin with.
2017-11-13 07:33:35 -05:00
Matthias Clasen
1da7dc890c Make the recoloring code more robust
Pass both width+height and scale, so we can handle the case
where width+height are zero and we are using the file, scaled.
2017-11-07 21:27:38 -05:00
Matthias Clasen
284fd36e5d Fix symbolic.svg rendering
With the shader approach to symbolic recoloring, we must
not recolor the svgs anymore as we're loading them. Instead,
load them the same way that gtk-encode-symbolic-svg does.

This fixes the rendering of large symbolic icons e.g. the
'no search results found' page in the file chooser.
2017-11-07 18:56:32 -05:00
Benjamin Otte
8d849458ac docs: You can't modify textures
So there's no need to tell people they must not do that.
2017-11-05 00:07:17 +01:00
Benjamin Otte
ca3c23662c GskTexture => GdkTexture
We want this thing to replace GdkPixbuf, so it has to live in GDK.
2017-11-04 00:07:13 +01:00
Benjamin Otte
3967072c66 docs: Fix up some places that still said screen instead of display 2017-10-31 08:25:37 +01:00
Benjamin Otte
ecd5b399a4 icontheme: Use GdkDisplay instead of GdkScreen 2017-10-31 03:05:55 +01:00
Benjamin Otte
9151e0b9f5 stylecontext: Port to use display instead of screen 2017-10-31 03:05:54 +01:00
Timm Bäder
134ba2ebf7 icontheme: Silence some compiler warnings 2017-10-23 14:23:52 +02:00
Matthias Clasen
02db8ccd89 icon theme: Add a texture cache
Return cached textures for icons. This lets us avoid duplicate
texture uploads for icons whose surfaces we already cache.
2017-10-23 08:07:35 +02:00
Benjamin Otte
43c212ac28 build: Enable -Wswitch-enum and -Wswitch-default
This patch makes that work using 1 of 2 options:

1. Add all missing enums to the switch statement
  or
2. Cast the switch argument to a uint to avoid having to do that (mostly
   for GdkEventType).

I even found a bug while doing that: clearing a GtkImage with a surface
did not notify thae surface property.

The reason for enabling this flag even though it is tedious at times is
that it is very useful when adding values to an enum, because it makes
GTK immediately warn about all the switch statements where this enum is
relevant.
And I expect changes to enums to be frequent during the GTK4 development
cycle.
2017-10-06 21:23:39 +02:00
Robert Ancell
7b8ea9af55 icon-theme: Show filename attempted when icon fails to load 2017-06-09 09:24:02 +12:00
Piotr Drąg
a2da4ddceb Use Unicode in translatable strings
See https://developer.gnome.org/hig/stable/typography.html

https://bugzilla.gnome.org/show_bug.cgi?id=772371
2016-12-19 15:08:10 -05:00
Timm Bäder
d188912338 icontheme: Remove deprecated API 2016-10-22 19:08:29 +02:00
Emmanuele Bassi
a9bcd05a14 icontheme: Simplify lookup_size()
No need to use an internal function, and no need to store the icon size
id, since we're using the id as the offset.
2016-10-19 14:04:00 +01:00
Ignacio Casal Quinteiro
a12b691b76 gtkicontheme: check if the context quark string is not null
On windows you might not have a theme installed by default which
means that when trying to create the context quark it will fail.
If then we try to replace a NULL key in the hash table it will crash.

https://bugzilla.gnome.org/show_bug.cgi?id=769859
2016-10-17 13:04:31 +02:00
Emmanuele Bassi
39e848c0eb icontheme: Drop unnecessary allocation
Use a static array for the known icon sizes, now that we don't allow
registering custom icon sizes any more. This allows us to cut a one-off
allocation that makes Valgrind sad.
2016-10-17 11:44:11 +01:00
Emmanuele Bassi
44885bcfed Remove redundant declarations 2016-10-17 11:10:14 +01:00
Timm Bäder
ed184b3935 Remove GtkIconFactory
Move the icon size lookup API into gtkicontheme.c
2016-10-16 18:17:21 +02:00
Benjamin Otte
0df388051d API: Remove GtkStyle
All the remaining gtkrc.c stuff like GtkRcStyle goes with it.
2016-10-16 18:17:21 +02:00
Benjamin Otte
9a5de96187 API: Remove GtkNumerableIcon 2016-10-16 18:17:21 +02:00
Victor Toso
9701b58c4e icon-theme: Fix leaks on error
13 bytes in 1 blocks are definitely lost in loss record 766 of 16,875
   at 0x4C2DB9D: malloc (vg_replace_malloc.c:299)
   by 0xA9D0247: vasprintf (in /usr/lib64/libc-2.24.so)
   by 0xA2453FC: g_vasprintf (gprintf.c:316)
   by 0xA2152F7: g_strdup_vprintf (gstrfuncs.c:514)
   by 0xA21539C: g_strdup_printf (gstrfuncs.c:540)
   by 0x678F25C: gdk_rgba_to_string (gdkrgba.c:360)
   by 0x5FAE00D: rgba_to_string_noalpha (gtkicontheme.c:4322)
   by 0x5FAE6F2: gtk_icon_info_load_symbolic_svg (gtkicontheme.c:4492)
   by 0x5FAED4F: gtk_icon_info_load_symbolic_internal (gtkicontheme.c:4622)
   by 0x5FAEEE8: gtk_icon_info_load_symbolic (gtkicontheme.c:4711)
   by 0x5F00246: gtk_css_image_recolor_load (gtkcssimagerecolor.c:118)
   by 0x5F003E4: gtk_css_image_recolor_compute (gtkcssimagerecolor.c:170)

14 bytes in 1 blocks are definitely lost in loss record 801 of 16,875
   at 0x4C2DB9D: malloc (vg_replace_malloc.c:299)
   by 0xA9D0247: vasprintf (in /usr/lib64/libc-2.24.so)
   by 0xA2453FC: g_vasprintf (gprintf.c:316)
   by 0xA2152F7: g_strdup_vprintf (gstrfuncs.c:514)
   by 0xA21539C: g_strdup_printf (gstrfuncs.c:540)
   by 0x678F25C: gdk_rgba_to_string (gdkrgba.c:360)
   by 0x5FAE00D: rgba_to_string_noalpha (gtkicontheme.c:4322)
   by 0x5FAE68E: gtk_icon_info_load_symbolic_svg (gtkicontheme.c:4482)
   by 0x5FAED4F: gtk_icon_info_load_symbolic_internal (gtkicontheme.c:4622)
   by 0x5FAEEE8: gtk_icon_info_load_symbolic (gtkicontheme.c:4711)
   by 0x5F00246: gtk_css_image_recolor_load (gtkcssimagerecolor.c:118)
   by 0x5F003E4: gtk_css_image_recolor_compute (gtkcssimagerecolor.c:170)

15 bytes in 1 blocks are definitely lost in loss record 838 of 16,875
   at 0x4C2DB9D: malloc (vg_replace_malloc.c:299)
   by 0xA9D0247: vasprintf (in /usr/lib64/libc-2.24.so)
   by 0xA2453FC: g_vasprintf (gprintf.c:316)
   by 0xA2152F7: g_strdup_vprintf (gstrfuncs.c:514)
   by 0xA21539C: g_strdup_printf (gstrfuncs.c:540)
   by 0x678F25C: gdk_rgba_to_string (gdkrgba.c:360)
   by 0x5FAE00D: rgba_to_string_noalpha (gtkicontheme.c:4322)
   by 0x5FAE6C3: gtk_icon_info_load_symbolic_svg (gtkicontheme.c:4487)
   by 0x5FAED4F: gtk_icon_info_load_symbolic_internal (gtkicontheme.c:4622)
   by 0x5FAEEE8: gtk_icon_info_load_symbolic (gtkicontheme.c:4711)
   by 0x5F00246: gtk_css_image_recolor_load (gtkcssimagerecolor.c:118)
   by 0x5F003E4: gtk_css_image_recolor_compute (gtkcssimagerecolor.c:170)

16,384 bytes in 1 blocks are definitely lost in loss record 16,847 of 16,875
   at 0x4C2DADE: malloc (vg_replace_malloc.c:298)
   by 0x4C2FC91: realloc (vg_replace_malloc.c:785)
   by 0xA1F89FA: g_realloc (gmem.c:159)
   by 0xA1BAD2E: g_array_maybe_expand (garray.c:779)
   by 0xA1BA566: g_array_set_size (garray.c:555)
   by 0xA1BBCB8: g_byte_array_set_size (garray.c:1752)
   by 0x8D1CC48: g_file_load_contents (gfile.c:6766)
   by 0x5FAE767: gtk_icon_info_load_symbolic_svg (gtkicontheme.c:4501)
   by 0x5FAED4F: gtk_icon_info_load_symbolic_internal (gtkicontheme.c:4622)
   by 0x5FAEEE8: gtk_icon_info_load_symbolic (gtkicontheme.c:4711)
   by 0x5F00246: gtk_css_image_recolor_load (gtkcssimagerecolor.c:118)
   by 0x5F003E4: gtk_css_image_recolor_compute (gtkcssimagerecolor.c:170)

https://bugzilla.gnome.org/show_bug.cgi?id=772215
2016-09-30 14:20:01 -04:00
Rico Tzschichholz
a3f1596069 Add some missing (nullable) annotations
https://bugzilla.gnome.org/show_bug.cgi?id=771826
2016-09-22 14:02:07 +02:00
Matthias Clasen
de7c15636d icon theme: Add a warning
Warn about the situation when we've found a resource or file path,
but gdk-pixbuf fails to give us a pixbuf. This generally means that
either pixbuf loaders are not found or the shared-mime database
is missing.
2016-05-19 09:03:20 -04:00
Matthias Clasen
d1acb786a7 icon theme: Make the builtin hicolor index match reality
We were missing all of the status directories, and a few sizes.
This was causing us to not find image-missing on systems without
hicolor icon theme (this basically only happens on Windows).

https://bugzilla.gnome.org/show_bug.cgi?id=764378
2016-03-31 07:12:50 -04:00
Matthias Clasen
2ee7fb1818 Don't use g_print for debug output
The g_print documentation explicitly says not to do this, since
g_print is meant to be redirected by applications. Instead use
g_message for logging that can be triggered via GTK_DEBUG.
2016-02-28 21:40:23 -05:00
Matthias Clasen
bbd94b5a9f gtk: Strip newlines from g_warning and g_error
g_logv adds one for us already.
2016-02-28 12:23:12 -05:00
Matthias Clasen
e54549502e icontheme: Avoid a crash
gtk_icon_info_new_for_file with a size of 0 would fail for
symbolic pngs because we ended up scaling with 0. Avoid this.
2016-01-30 00:29:04 -05:00
Matthias Clasen
001598a821 icon theme: Improve loading of unthemed files
When creating icon info objects for unthemed files, we don't
really have a nominal size, so we pass 0 to mean 'load at
original size'. However, this is not what was happening.
To make this possible, add variants of some pixbuf loading
functions that take a scale factor instead of a desired size,
and use those when we don't have a nominal size.
2016-01-29 17:27:35 -05:00
Matthias Clasen
1b0ef71696 icon theme: Export recoloring function
This will be used in subsequent commits.

https://bugzilla.gnome.org/show_bug.cgi?id=760536
2016-01-14 13:51:09 -05:00
Matthias Clasen
7d717c8113 icon theme: Add a way to create GtkIconInfos from files
This is sometimes needed, and calling into actual icon theme
code just for it is confusing - the resulting icon does not
depend on the icon theme at all.

https://bugzilla.gnome.org/show_bug.cgi?id=760536
2016-01-14 13:50:58 -05:00
Alberto Ruiz
496f0892fc introspection: This patch fixes nullable return values fixes for the following symbols in gtk
gtk_accel_group_query
  gtk_accel_group_from_accel_closure
  gtk_accel_label_get_accel_widget
  gtk_accessible_get_widget
  gtk_actionable_get_action_name
  gtk_app_chooser_get_app_info
  gtk_app_chooser_button_get_heading
  gtk_app_chooser_dialog_get_heading
  gtk_application_get_window_by_id
  gtk_assistant_get_nth_page
  gtk_binding_set_find
  gtk_builder_get_object
  gtk_builder_lookup_callback_symbol
  gtk_builder_get_application
  gtk_button_get_image
  gtk_cell_area_get_focus_from_sibling
  gtk_cell_renderer_start_editing
  gtk_cell_view_get_model
  gtk_cell_view_get_displayed_row
  gtk_clipboard_get_owner
  gtk_container_get_focus_child
  gtk_container_get_focus_vadjustment
  gtk_container_get_focus_hadjustment
  gtk_dialog_get_widget_for_response
  gtk_drag_get_source_widget
  gtk_drag_dest_get_target_list
  gtk_drag_source_get_target_list
  gtk_entry_completion_get_model
  gtk_entry_completion_compute_prefix
  gtk_expander_get_label_widget
  gtk_file_chooser_get_filename
  gtk_file_chooser_get_current_folder
  gtk_file_chooser_get_uri
  gtk_file_chooser_get_current_folder_uri
  gtk_file_chooser_get_preview_widget
  gtk_file_chooser_get_preview_file
  gtk_file_chooser_get_preview_filename
  gtk_file_chooser_get_preview_uri
  gtk_file_chooser_get_extra_widget
  gtk_file_chooser_get_filter
  gtk_file_chooser_native_get_accept_label
  gtk_file_chooser_native_get_cancel_label
  gtk_file_filter_get_name
  gtk_font_chooser_get_font_family
  gtk_font_chooser_get_font_face
  gtk_font_chooser_get_font
  gtk_font_chooser_get_font_desc
  gtk_font_chooser_get_font_map
  gtk_frame_get_label
  gtk_gesture_get_device
  gtk_gesture_get_window
  gtk_gl_area_get_error
  gtk_header_bar_get_title
  gtk_header_bar_get_subtitle
  gtk_header_bar_get_custom_title
  gtk_icon_info_get_filename
  gtk_icon_view_get_path_at_pos
  gtk_icon_view_get_model
  gtk_image_get_pixbuf
  gtk_image_get_animation
  gtk_label_get_mnemonic_widget
  gtk_label_get_attributes
  gtk_check_version
  gtk_menu_button_get_popup
  gtk_menu_button_get_menu_model
  gtk_menu_button_get_align_widget
  gtk_menu_button_get_popover
  gtk_menu_item_get_submenu
  gtk_menu_item_get_accel_path
  gtk_native_dialog_get_title
  gtk_native_dialog_get_transient_for
  gtk_notebook_get_nth_page
  gtk_notebook_get_tab_label_text
  gtk_notebook_get_menu_label
  gtk_notebook_get_menu_label_text
  gtk_notebook_get_group_name
  gtk_notebook_get_action_widget
  gtk_offscreen_window_get_surface
  gtk_offscreen_window_get_pixbuf
  gtk_paned_get_child1
  gtk_paned_get_child2
  gtk_places_sidebar_get_location
  gtk_places_sidebar_get_nth_bookmark
  gtk_plug_get_socket_window
  gtk_popover_get_default_widget
  gtk_progress_bar_get_text
  gtk_recent_filter_get_name
  gtk_recent_manager_lookup_item
  gtk_settings_get_default
  gtk_socket_get_plug_window
  gtk_stack_sidebar_get_stack
  gtk_stack_switcher_get_stack
  gtk_style_context_get_section
  gtk_style_context_get_parent
  gtk_style_context_get_frame_clock
  gtk_test_find_widget
  gtk_text_buffer_get_mark
  gtk_text_tag_table_lookup
  gtk_text_view_get_tabs
  gtk_text_view_toggle_cursor_visible
  gtk_text_view_get_window
  gtk_toolbar_get_nth_item
  gtk_tool_button_get_label
  gtk_tool_button_get_icon_name
  gtk_tool_button_get_label_widget
  gtk_tool_button_get_icon_widget
  gtk_tool_palette_get_drop_item
  gtk_tool_palette_get_drop_group
  gtk_tree_model_filter_convert_child_path_to_path
  gtk_tree_model_filter_convert_path_to_child_path
  gtk_tree_model_sort_convert_child_path_to_path
  gtk_tree_model_sort_convert_path_to_child_path
  gtk_tree_view_get_column
  gtk_tree_view_get_bin_window
  gtk_tree_view_column_get_widget
  gtk_tree_view_column_get_tree_view
  gtk_widget_get_frame_clock
  gtk_window_group_get_current_device_grab
  GtkTextBufferSerializeFunc
2016-01-08 12:18:23 +00:00
Benjamin Otte
ee6e685478 iconhelper: Pass only the CssStyle when loading icons
This is the first step in replacing StyleContext usage with CssNode
usage.
2015-12-09 13:30:39 +01:00
Benjamin Otte
7fa37e4bf8 css: Introduct -gtk-icon-palette
This borrows heavily from the CSS4 fonts draft's font-palette, currently
found at https://drafts.csswg.org/css-fonts-4/#font-palette-control

The palette is mainly meant to trigger invalidations when colors used for
symbolic icons change, to potentially allow extending supported colors
in symbolic icons and to recolor all colors of a symbolic icon, not just
the main one.

The syntax for the property goes like this:
Name:        -gtk-icon-palette
Value:       default | name <color> [ , name <color> ]*
Initial:     default
Applies to:  all elements with icons
Inherited:   yes
Animatable:  yes, each color animated separately

The property defines a list of named colors to be used when looking up
icons. If a name is not defined, the value of the current "color"
property is used. Which names are relevant depends on the icons in use.
Currently symbolic icons make use of the names "success", "warning" and
"error".

"default" is the current behavior of the GTK when coloring symbolic
icons and is equal to the string
  success @success_color, warning @warning_color, error @error_color

Animation is crudely implemented by animating colors that are in both
palettes that are animated and otherwise keeping the color from the
palette that defined it. Note that this can cause a sharp cut at the
beginning or end of the animation when the color goes away and will
therefore be replaced with the color property.

You can see an example of animations at
http://gfycat.com/CautiousPeacefulIaerismetalmark
2015-12-03 00:47:00 +01:00
Emmanuele Bassi
c1ecd1ef9d docs: Point at for_scale() variants
Using lookup_icon() and lookup_by_gicon() with a size multiplied by a
scaling factor is almost certainly going to get worse results than using
their for_scale() variants.
2015-11-04 11:50:37 +00:00
Benjamin Otte
8ec2362d81 icontheme: Clarify GENERIC_FALLBACK flag handling
- Add docs explaining that it doesn't work everywhere
- g_warn_if_fail() in the APIs where it doesn't work
2015-10-28 19:44:26 +01:00
Matthias Clasen
270e900f55 icon theme: Ensure to propagate an error
If the svg pixbuf loader is not available, we end up with criticals
from gtk_css_image_icon_theme_draw because gtk_icon_info_load_symbolic
returns NULL without setting an error.

Avoid this by propagating the load error.
2015-10-27 11:09:00 -04:00
Matthias Clasen
8ba55d80fc gtkicontheme: Check a return value
We were already looking at the error anyway, but rewriting things
this way lets coverity see the light.
2015-07-17 16:11:16 -04:00
Cosimo Cecchi
06df94ff7b icontheme: don't modify symbolic SVG dimensions when recoloring
When recoloring symbolic SVG, do not modify the original width and
height of the passed-in file; the function later will scale the image
through gdk_pixbuf_new_from_stream_at_scale(), but we should still
use the original size to create the proxy SVG, or the image will
possibly be doubly-resized or blurry.

https://bugzilla.gnome.org/show_bug.cgi?id=750605
2015-06-12 08:55:23 -07:00
Matthias Clasen
85b4eef004 icon theme: Fix compiler warnings
Fix warnings due to -Wdeclaration-after-statement and -Wshadow.
2015-06-02 09:08:15 -04:00
Daniel Drake
aba2de3443 icontheme: allow directories with mtime 0
In order to provide a constant mtime between OS build and deploy time,
while also maintaining a hardlink content-addressed model independent of
timestamps, ostree sets all mtimes to 0.

The icon cache code currently ignores directories with mtime 0, assuming
they don't exist.

Track directory existence in a more precise way.

https://bugzilla.gnome.org/show_bug.cgi?id=745052
2015-02-23 15:09:15 -06:00
Cosimo Cecchi
eddaf01676 icontheme: use desired size instead of negative for DIR_UNTHEMED SVGs
When loading SVGs from ICON_THEME_DIR_UNTHEMED GtkIconInfos,
such as those created for a GLoadableIcon, the size of the pixbuf to
load is set as a product of icon_info->scale.
But a few lines above, icon_info->scale is set to -1 for
ICON_THEME_DIR_UNTHEMED GtkIconInfos, so we'll end up always passing a
negative size to the GdkPixbuf loader, which is interpreted as the
nominal size of the image file.
Instead load the SVG at the desired scaled size in that case.

This fixes blurry icon in the notification panel in gnome-shell.

https://bugzilla.gnome.org/show_bug.cgi?id=744991
2015-02-23 09:56:06 -08:00
Cosimo Cecchi
acd72ffabe icontheme: fill correct information when loading GResource-backed GIcons
When loading a GResource-backed GFileIcon into a GtkIconInfo we
currently fail to populate the is_resource private field.
Also, since is_svg is set by looking at the filename, and
g_file_get_path() returns NULL for a GResourceFile, is_svg was always
FALSE.

https://bugzilla.gnome.org/show_bug.cgi?id=744991
2015-02-23 09:56:06 -08:00
Matthias Clasen
48a41b0119 Reduce symbolic icon warnings to a debug message
These icons are out there in the wild, and the warning causes
distcheck to fail. So, reduce it to a debug message.
2015-01-31 14:32:17 -05:00
Kjell Ahlstedt
5d3aa54a8a docs: Explain 'icon theme context' better in gtkicontheme.c
Add links from gtk_icon_theme_list_contexts() to
gtk_icon_theme_list_icons(), and from there to the Icon Theme
Specification and the Icon Naming Specification.

https://bugzilla.gnome.org/show_bug.cgi?id=461249
2014-12-07 23:35:31 -05:00
Matthias Clasen
95e8ae6e75 GtkIconTheme: Improve an error message
Mention the name of the theme when an icon lookup fails.
https://bugzilla.gnome.org/show_bug.cgi?id=687963
2014-11-03 00:25:14 -05:00
Matthias Clasen
964c202c38 GtkIconTheme: Repair symbolic fallback with rtl/ltr
For symbolic icons, we prefer symbolics in inherited themes over
generic icons in the theme itself. So far this was implemented
by looking at icon_name[0] and looking that up in inherited themes
if it is symbolic. But with automatic rtl/ltr handling, the first
icon  name will always have an -rtl or -ltr suffix, and an icon
with that suffix is not going to exist in most cases. To fix this,
look for shorter icon names too, as long as they are still symbolic.

https://bugzilla.gnome.org/show_bug.cgi?id=737000
2014-09-21 14:49:22 -04:00
Matthias Clasen
1b858e4212 Trivial: clarify a comment
Using 'highcolor' here seems confusing, since there is a theme
by that name. Just say full-color.
2014-09-21 14:29:36 -04:00
Matthias Clasen
1629903943 GtkIconTheme: Make suffix_from_name NULL-safe
This can happen sometimes with GFileIcons that are
not representable as a local path. Better not to crash
in this case.
2014-09-05 13:15:14 -04:00