DeskFrame icon indicating copy to clipboard operation
DeskFrame copied to clipboard

[BUG] - Issue with icon background hover color

Open onesounds opened this issue 10 months ago • 12 comments

Image

Describe the bug The issue occurs when hovering over icons in Grid View. While the background color changes correctly for the initial icons, the hover effect seems to stop applying to icons after a certain point in the list.

To Reproduce

  1. Add at least 4 icons to the frame.

  2. Hover over the icons in sequence from the first to the fourth, and verify that the background color changes and reverts correctly.

Suspected Cause It seems like there might be an issue with the conditional logic in the FileItem_MouseEnter and FileItem_MouseLeave functions.

When I tried removing the complex conditions and simply set the code to toggle the color on 'Enter' and off on 'Leave', the issue was resolved. It appears that the current logic might be causing unexpected behavior in certain scenarios.

Expected behavior The appropriate color should be displayed on hover, and the background should revert to transparent when the mouse leaves.

Desktop (please complete the following information):

  • OS Version [e.g. 22H2]
  • OS Build [e.g. 22000.1]

onesounds avatar Jan 24 '26 03:01 onesounds

Why did you close the pull request?

PinchToDebug avatar Jan 24 '26 03:01 PinchToDebug

I thought the issue was resolved, but I noticed some unexpected behaviors in the selected state—specifically when the mouse leaves the item or when double-clicking. Since this requires a better organization of the hover/selected states and potentially a single-click option, I felt it would be risky for me to make significant changes without further discussion

onesounds avatar Jan 24 '26 04:01 onesounds

I couldn't reproduce this issue, is your screen scaling set to 100%?

PinchToDebug avatar Jan 24 '26 05:01 PinchToDebug

I couldn't reproduce this issue, is your screen scaling set to 100%?

I'm using 200%. Based on your feedback, I tested at 100% DPI and confirmed the issue does not occur. This reminded me of a similar DPI issue I resolved in the past, so I attempted a fix based on that experience. It is now resolved in my local tests.

  • If only the function is modified without adding DPI awareness settings via the app manifest, the program must be restarted to reflect DPI changes. If the manifest is present, changes are applied immediately without a restart.

  • I noticed that a scaling factor (_windowsScalingFactor) already existed but was not being applied in the Window_MouseMove function, so I added it. I have added the detailed explanation generated by AI to the PR.

Thanks.

onesounds avatar Jan 24 '26 09:01 onesounds

I’ve been testing dpi awareness before, but due to how the app works now your PR can't be merged because it wouldn't work properly on multi-monitor setups. There need to be more changes to make sure everything works properly on multi-monitor setups first. The scaling related code parts have to be changed if dpi awareness is added.

PinchToDebug avatar Jan 24 '26 16:01 PinchToDebug

Thanks.

  • I tested it with dual monitors and I get what you're saying. I think you should probably handle DPI Awareness regardless, though.
  • With this fix, I was able to see improved behavior on multiple monitors.
        private void SetAsDesktopChild()
        {
            while (true)
            {
                while (shellView == IntPtr.Zero)
                {
                    EnumWindows((tophandle, _) =>
                    {
                        IntPtr shellViewIntPtr = FindWindowEx(tophandle, IntPtr.Zero, "SHELLDLL_DefView", null);
                        if (shellViewIntPtr != IntPtr.Zero)
                        {
                            shellView = shellViewIntPtr;
                            return false;
                        }
                        return true;
                    }, IntPtr.Zero);
                }
                if (shellView == IntPtr.Zero) Thread.Sleep(1000);
                else break;
            }
            if (shellView == IntPtr.Zero) throw new InvalidOperationException("SHELLDLL_DefView not found.");

            var interopHelper = new WindowInteropHelper(this);
            interopHelper.EnsureHandle();
            IntPtr hwnd = interopHelper.Handle;
            SetParent(hwnd, shellView);

            int style = (int)GetWindowLong(hwnd, GWL_STYLE);
            style &= ~WS_POPUP;
            style |= WS_CHILD;
            SetWindowLong(hwnd, GWL_STYLE, style);

            uint currentDpi = GetDpiForWindow(hwnd);
            double currentScale = currentDpi / 96.0;

            POINT pt = new POINT
            {
                X = (int)(Instance.PosX * currentScale),
                Y = (int)(Instance.PosY * currentScale)
            };
            ScreenToClient(shellView, ref pt);

            SetWindowPos(hwnd, IntPtr.Zero, pt.X, pt.Y, 0, 0,
                         SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);

            uint newDpi = GetDpiForWindow(hwnd);
            double newScale = newDpi / 96.0;

            bool scaleChanged = (Math.Abs(_windowsScalingFactor - newScale) > 0.001);
            _windowsScalingFactor = newScale;

            int realWidth = (int)(Instance.Width * newScale);
            int realHeight = (int)(Instance.Height * newScale);

            SetWindowPos(hwnd, IntPtr.Zero, 0, 0, realWidth, realHeight,
                         SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);

            if (scaleChanged)
            {
                Dispatcher.InvokeAsync(async () =>
                {
                    foreach (var item in FileItems)
                    {
                        item.Thumbnail = await GetThumbnailAsync(item.FullPath!);
                    }
                });
            }
        }

As I dug into this task, I realized this issue is significantly more complex than I initially thought.

Currently, it works reasonably well based on absolute coordinates. However, changing the monitor layout forces a re-arrangement (and there are edge cases where windows end up off-screen with no way to drag them back).

In my experience, multi-monitor users generally fall into two categories:

  • Users with a fixed, static setup.

  • Laptop users whose external monitors change frequently.

Users likely have varying expectations: some might expect all frames to migrate upon connection/disconnection, others might want them to stay put, or have specific frames bind to specific monitors. To cover all these bases, each frame would arguably need the following configurations:

  1. Target Monitor Criteria (Primary / Secondary / Monitor Number / Device Path)
  • "Secondary" would be defined as the lowest numbered monitor that isn't Primary.

  • I'm unsure how we would identify or display multiple monitors if they have identical names.

  1. Positioning Method
  • Absolute Coordinates / Percentage / Auto-fill / Anchor

  • Auto-fill: Would need start position and direction options (e.g., Start Top-Right, go Down).

  • This would provide the most consistency for users who frequently switch monitor setups.

  • Anchor: (e.g., Bottom-Right 20%)

Example: If Frame 1 is set to 'Primary Monitor' / 'Absolute Coordinates', and the Primary Monitor changes, this frame should reposition itself to 0,0 of the new Primary. Additionally, this implementation would necessitate a 'Reset Positions' option in the system tray menu to retrieve any off-screen windows.

Conclusion I generally dislike adding complex features for edge cases (low-percentage user scenarios), so I'm not entirely sure if this level of implementation is strictly necessary. Honestly, if I had to implement this myself, I would hate it. However, since a key feature of this program is the ability to granularly customize settings for every single window, this seems to be the logical direction to take.

Just sharing this as an idea, not asking for an implementation! Since I fixed the hover issue myself, I'm all set. Thanks for the awesome work.

onesounds avatar Jan 25 '26 00:01 onesounds

This won't work when changing an adjacent monitor's resolution / scaling.

PinchToDebug avatar Jan 25 '26 00:01 PinchToDebug

This won't work when changing an adjacent monitor's resolution / scaling.

The function needs to work with DPI awareness. In my branch https://github.com/onesounds/DeskFrame/commits/FixHoverEffect/ the hover effect works perfectly on both monitors, regardless of scaling or resolution changes. I won't open a new PR or Issue for this. Sorry for the trouble!

onesounds avatar Jan 25 '26 01:01 onesounds

I've fixed the hover effect thats why I closed this issue. See here.

PinchToDebug avatar Jan 25 '26 01:01 PinchToDebug

It doesn't works for me.

Your Fix : https://drive.google.com/file/d/1xTF29snLs4n2hLMECWU86lqDogvip8Xe/view?usp=drive_link My Branch : https://drive.google.com/file/d/1483YnLXMpvSde0GphR6aIzGovWgrb0iq/view?usp=drive_link

onesounds avatar Jan 25 '26 02:01 onesounds

I was trying to make proper scaling when moving between monitors, please look at the other branch (DPI testing). The changes probably affect the behavior of your code too.

Setup:

  • Monitor 1 at 150%+ scaling

  • Monitor 2 at 100% scaling

Achieved as of now:

  • when moving frames between monitors with different scaling frames adjust their scaling

  • they start with proper scaling on the monitor (dpi aware)

Expected behavior:

  • when disconnecting and connecting monitor 2, frames should go back to their original position on monitor 2. (it would be good if they stay off screen when monitor 2 isn't connected. I'm not sure about the current behavior.)

  • when changing the resolution of monitor 1, frames on monitor 2 shouldn't move.

  • when changing the dpi of monitor 1 the frames on monitor 2 shouldn't move.

Additional info:

  • when testing don’t grab and move any frames.

  • windows are called frames for the app.

My PC isn't strong enough to handle a VM with 2 virtual screens.

PinchToDebug avatar Jan 25 '26 03:01 PinchToDebug

I have tested the DPI Testing branch.

https://drive.google.com/file/d/1THkyw5cFFASXRelal9hTrufYtAdNPJwf/view?usp=drive_link

  • Changing the scale on the secondary monitor does not affect the position or size of the frame on the primary monitor (as seen in the beginning of the video).

  • However, changing the scale on the primary monitor does affect the frame position and icon size on the secondary monitor.

Also, the original issue where the Hover effect does not trigger at the correct coordinates still persists.

If you are currently testing the dual monitor setup in a VM environment, I suggest postponing this task until you can acquire an additional physical monitor.

onesounds avatar Jan 25 '26 04:01 onesounds