Skip to content

isMaximized does not reflect OS window state on windows #27838

Closed

Description

@suedama1756

Changes to isMaximized implementation recently have made reporting of isMaximized worse as they do not use standard operating system calls to determine the window state. Maximizing a window using the windows system menu, or using WIN + Up Arrow will always return isMaximized() false.

Preflight Checklist

  • [x ] I have read the Contributing Guidelines for this project.
  • [ x] I agree to follow the Code of Conduct that this project adheres to.
  • [ x] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    Seen in 10.3.2 and 11.2.3
  • Operating System:
    Windows 10
  • Last Known Working Electron version:
    Not 100% sure as different versions have various issues with isMaximized.

Expected Behavior

Execute

   const { app, BrowserWindow } = require('electron');
  app.on('ready', function() {
     const window = new BrowserWindow({
         frame: false,
         thickFrame: false,
         width: 200,
         height: 200  
     });
     window.show();
     setInterval(() => {
        if (!window.isDestroyed()) {
            console.log(window.isMaximized())
        }
     }, 5000);
  });

Should return true when the window has been maximized by the operating system

Actual Behavior

Returns false

To Reproduce

  1. Enter the code above into a file named main.js and execute with
electron main.js
  1. maximize the window using "alt+space" menu and select maximize, or use "WIN+Up Arrow" shortcut

Additional Information

Replacing the implementations on BrowserWindow with calls to native operating system APIs via a NAPI extension fixes this issue for me. I'd love to understand why electron does not use these standard calls as the code is simpler and should be more reliable (perhaps there were legacy issues, if so do they still apply?)

   isMaximized() { 
       return Native.getWindowPlacement(this.getNativeWindowHandle()).showCmd === 3;
   },
   maximize() {
       Native.showWindow(window.getNativeWindowHandle(), 3);
   }

The NAPI extension is simply a wrapper on the following two windows APIs https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowplacement and https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow

Activity

  1. changed the title [-]isMaximized is always false on frameless, thickframe: false window[/-] [+]isMaximized does not reflect OS window state on windows[/+] on Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions