Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images disappear after Display Resolution Change #235

Open
sheffler opened this issue Dec 30, 2023 · 2 comments
Open

Images disappear after Display Resolution Change #235

sheffler opened this issue Dec 30, 2023 · 2 comments

Comments

@sheffler
Copy link

sheffler commented Dec 30, 2023

I’ve recently installed gs-desktop (from github.com/onflapp/gs-desktop/) on Debian 12 into a clean partition in a System76 laptop. It all works very nicely as a desktop environment.

I have noticed an annoying problem when I change resolutions - I seem to do this often: when I plug in an external monitor I size things one way, and when not connected I size the display another way. I’ve investigated the problem, and do not have a good fix. I’m hoping that by sharing my experience here someone might be able to shed some light on the subject.

Upon resizing the main screen, icons and images disappear. The commands I use are

  • xrandr —output eDP-1 —mode 1400x1050
  • xrandr —output eDP-1 —mode 1600x900

After changing resolutions, images and icons in the following apps have been seen to dissappear

  • GWorkspace
  • Gorm
  • nextspace/Preferences
  • gs-desktop/Applications/VolMon
  • gs-desktop/Applications/MountUp

The picture below shows two versions of GWorkspace FileViewer. The one on top is GWorkspace installed “as-is” and shown after changing the resolution of the display. The large icons and the small icons are all gone. They do not reappear after any amount of fiddling
with controls or themes I attempt.

screen-20231216-annotated

The bottom FileViewer is a modified copy of GWorkspace that has been changed to add a new menu item called “Redraw” that does a couple of things. It deletes image caches in various places and then calls [NSApp updateWindows]. This does not immediately fix the images, but after scolling around the images get refreshed as the caches are rebuilt.

The two “DIFF” files attached in this message show what code modifications I made to support the “Redraw” menu item.

While clearing the caches helps fix the problem, I don’t really believe I’m on totally the right track for a permanent fix across applications. So I’m looking for suggestions or other insights. Or at least that this info helps someone else one day.

===

I”ve also investigated an entirely different track, changing the following line in NSImage.m
_cacheMode = NSImageCacheDefault;
to
_cacheMode = NSImageCacheNever;

and rebuilding. In GWorkspace, this fixes the Large icons, but breaks the Small icons. It does, however, also fix the module images in the Nextspace/Preferences app so that they do not disappear upon resolution changes.

========================

diff --git a/Source/NSImage.m b/Source/NSImage.m
index 071af32d..6b9b617b 100644
--- a/Source/NSImage.m
+++ b/Source/NSImage.m
@@ -2253,6 +2255,31 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
 }
 
 
++ (void) _FORCEreloadCachedImages
+{
+  NSString *name;
+  NSEnumerator *e = [nameDict keyEnumerator];
+
+  [imageLock lock];
+  while ((name = [e nextObject]) != nil)
+    {
+      NSImage *image = [nameDict objectForKey: name];
+      NSString *path = [[NSBundle mainBundle] pathForImageResource: name];
+
+      NSLog(@"FORCE: Loaded image %@ from %@", name, path);
+
+      if (path != nil) // NOTE: FORCE RELOAD
+	{
+	  /* Reset the existing image to use the contents of
+	   * the specified file.
+	   */
+	  [image _resetAndUseFromFile: path];
+	}   
+    }
+  [imageLock unlock];
+}
+
+
 + (NSString *) _resourceNameForImageNamed: (NSString *)aName 
                                      type: (NSString **)aType
 {

========================

diff --git a/GWorkspace/GWorkspace.m b/GWorkspace/GWorkspace.m
index 415c6f3d..43f3be5d 100644
--- a/GWorkspace/GWorkspace.m
+++ b/GWorkspace/GWorkspace.m
@@ -325,6 +325,9 @@ static GWorkspace *gworkspace = nil;
   // Quit
   [mainMenu addItemWithTitle:_(@"Quit") action:@selector(terminate:) keyEquivalent:@"Q"];
 
+  // Redraw
+  [mainMenu addItemWithTitle:_(@"Redraw") action:@selector(FORCEredrawAll:) keyEquivalent:@"R"];
+
   // Logout
   [mainMenu addItemWithTitle:_(@"Logout") action:@selector(logout:) keyEquivalent:@""];
 
@@ -2219,6 +2222,32 @@ static GWorkspace *gworkspace = nil;
 //
 // Menu Operations
 //
+
+- (void) FORCEredrawAll:(id)sender {
+  NSLog(@"FORCE: redrawAll");
+
+  // reload the fixed icons
+  [[FSNodeRep sharedInstance] themeDidActivate:nil];
+
+  /*
+   * Reload NSImage's cache of image by name
+   */
+  [NSImage _FORCEreloadCachedImages];
+
+  [NSApp updateWindows];
+  
+} 
+
+
 - (void)logout:(id)sender
 {
   [self startLogout];
@sheffler
Copy link
Author

sheffler commented Jan 5, 2024

Some more information.

In NSImage.m, by setting the default cache mode for all images

  _cacheMode = NSImageCacheNever;

many images are "fixed" as screens and resolutions are changed. However, there are some that are not. One kind in particular are the Button images in apps like gs-desktop/Applications/VolMon

Through a process of trial and error and print statements, I determined that these images are loaded through the last part of initWithCoder - these images have "reps" that are loaded from a Gorm project.

          /*
           * get the image reps and add them.
           */
          a = [coder decodeObject];
          NSLog(@"IMAGELOADED: image reps:%@", a);
          [self addRepresentations: a];

Images loaded this way do not receive the "CacheNever" flag treatment. Adding this line "fixed" the problem for VolMon and a few other things.

          /*
           * get the image reps and add them.
           */
          a = [coder decodeObject];
          NSLog(@"IMAGELOADED: image reps:%@", a);
          // Added this line
          _cacheMode = NSImageCacheNever;
          [self addRepresentations: a];

Perhaps this sheds some more light on the underlying problem. Setting CacheNever is a workaround that I think is masking something deeper.

FYI - using VolMon as a test case was good for tracing through the image handling because it only loads 4 images this way.

@buzzdeee
Copy link
Contributor

buzzdeee commented Jan 5, 2024

I did the two changes @sheffler suggested in NSImage.m, changing the _cacheMode, and adding the _cacheMode line.

Before the change, on initial startup and login, all images were there, now some are missing, i.e. the small icons in the File Viewer, and some app icons in the dock. See screenshot.

missing_images

However, those that are there, incl. my desktop background, now survive a suspend/resume cycle.

For those in the dock, I first thought it might have something to do with filetype, but that doesn't seem to be the case.
As all of the missing icons are .png, but at least one of the visible icons is also a .png.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants