@@ -141,47 +141,101 @@ def _create_program_button(self, program):
141141
142142 return button
143143
144+ # Icons that need special handling (manual search with size priority)
145+ _SPECIAL_ICONS = {
146+ 'scanner' ,
147+ 'network-workgroup' ,
148+ 'smartphone' ,
149+ 'network-wired-symbolic' ,
150+ }
151+
152+ # Cache for special icon paths
153+ _special_icon_cache = {}
154+
155+ def _find_special_icon (self , icon_name ):
156+ """
157+ Manual search for specific icons that GTK doesn't detect correctly.
158+ Priority order: scalable, 48, 64, 128, 32, 22, 16
159+ """
160+ # Check cache first
161+ if icon_name in self ._special_icon_cache :
162+ return self ._special_icon_cache [icon_name ]
163+
164+ # Get current theme
165+ theme = Gtk .IconTheme .get_for_display (Gdk .Display .get_default ())
166+ theme_name = theme .get_theme_name ()
167+
168+ # Directories to search (theme first, then common themes, then hicolor)
169+ search_bases = [
170+ f"/usr/share/icons/{ theme_name } " ,
171+ ]
172+
173+ # Add common inherited themes
174+ for parent_theme in ["bigicons-papient" , "bigicons-papient-dark" , "breeze" , "breeze-dark" , "Adwaita" ]:
175+ if parent_theme != theme_name :
176+ search_bases .append (f"/usr/share/icons/{ parent_theme } " )
177+
178+ search_bases .append ("/usr/share/icons/hicolor" )
179+
180+ # Size priority
181+ size_dirs = ["scalable" , "48x48" , "64x64" , "32x32" , "48" , "64" , "128" ]
182+ # Extended subdirs list
183+ subdirs = ["apps" , "devices" , "categories" , "status" , "actions" , "places" , "preferences" , "emblems" , "mimetypes" , "symbolic" ]
184+ extensions = ['.svg' , '.png' ]
185+
186+ # Search with size priority
187+ for size_dir in size_dirs :
188+ for base in search_bases :
189+ for subdir in subdirs :
190+ for ext in extensions :
191+ icon_file = f"{ base } /{ size_dir } /{ subdir } /{ icon_name } { ext } "
192+ if os .path .exists (icon_file ):
193+ self ._special_icon_cache [icon_name ] = icon_file
194+ return icon_file
195+
196+ # Try scalable as last resort
197+ for base in search_bases :
198+ for subdir in subdirs :
199+ icon_file = f"{ base } /scalable/{ subdir } /{ icon_name } .svg"
200+ if os .path .exists (icon_file ):
201+ self ._special_icon_cache [icon_name ] = icon_file
202+ return icon_file
203+
204+ # Cache miss
205+ self ._special_icon_cache [icon_name ] = None
206+ return None
207+
144208 def _create_icon_from_path_or_name (self , icon_path ):
145209 """Create an icon from either a file path or an icon name"""
146- icon = None
210+ target_size = 64
147211
148212 # If empty path, use default icon
149213 if not icon_path :
150214 icon = Gtk .Image .new_from_icon_name ("application-x-executable" )
151- icon .set_pixel_size (64 )
215+ icon .set_pixel_size (target_size )
152216 return icon
153217
154218 # Check if it's an absolute path
155219 if icon_path .startswith ("/" ) and os .path .exists (icon_path ):
156220 try :
157- # Load directly from file for absolute paths
158221 icon = Gtk .Image .new_from_file (icon_path )
159- icon .set_pixel_size (64 )
222+ icon .set_pixel_size (target_size )
160223 return icon
161- except Exception as e :
162- print (f"Error loading icon from file '{ icon_path } ': { e } " )
163- # Fall through to icon name handling on failure
164-
165- # Try to load as an icon name with specific sizes in order of preference
166- theme = Gtk .IconTheme .get_for_display (Gdk .Display .get_default ())
224+ except Exception :
225+ pass
167226
168- # Check if the icon exists in the theme
169- if theme . has_icon ( icon_path ) :
170- # Try preferred sizes in order: scalable(SVG), 64x64, 48x48, 128x128
171- for size in [ 64 , 48 , 128 ] :
227+ # Special handling for specific problematic icons
228+ if icon_path in self . _SPECIAL_ICONS :
229+ found_path = self . _find_special_icon ( icon_path )
230+ if found_path :
172231 try :
173- # Try to get the icon at preferred size
174- paintable = theme .lookup_icon (
175- icon_path , size , 1 , Gtk .TextDirection .NONE , 0
176- )
177- if paintable :
178- icon = Gtk .Image .new_from_paintable (paintable )
179- icon .set_pixel_size (64 )
180- return icon
232+ icon = Gtk .Image .new_from_file (found_path )
233+ icon .set_pixel_size (target_size )
234+ return icon
181235 except Exception :
182236 pass
183237
184- # Default approach - may not respect size preferences but will work
238+ # Use GTK icon theme lookup (fast) for all other icons
185239 icon = Gtk .Image .new_from_icon_name (icon_path )
186- icon .set_pixel_size (64 )
240+ icon .set_pixel_size (target_size )
187241 return icon
0 commit comments