Skip to content

AeroSnap doesn't trigger the maximize/minimize events #1381

Closed

Description

@n457

On Windows, BrowserWindow maximize & unmaximize events are not triggered when maximizing/unmaximizing a atom-shell window by drag & drop.

atom-shell is really great, much better than NW.js (I used NW for quiet a long time), so congratulations to all contributors !

Activity

  1. zcbenz commented on Apr 13, 2015

    @zcbenz
    Contributor

    It seems that AeroSnap doesn't trigger the maximize/minimize handler.

  2. changed the title [-](Windows) BrowserWindow maximize & unmaximize events, and title bars drag & drop[/-] [+]AeroSnap doesn't trigger the maximize/minimize events[/+] on Apr 13, 2015
  3. Keavon commented on Apr 19, 2015

    @Keavon

    Also Windows Key + Up Arrow (maximize) and Windows Key + Down Arrow (unmaximize) doesn't trigger it. Neither does right clicking on the program in the Task Manager and clicking Maximize.

  4. etiktin commented on Aug 3, 2015

    @etiktin
    Contributor

    There's a discussion on the topic with suggested solutions at : http://stackoverflow.com/questions/9321549/handling-aerosnap-message-in-wndproc
    They basically say, that Aero Snap doesn't fire the SC_MAXIMIZE command and instead we should handle the WM_SIZE message or the WM_WINDOWPOSCHANGING message, which will fire.

  5. etiktin commented on Aug 3, 2015

    @etiktin
    Contributor

    I manged to work around this issue in my main process code.
    The basic idea is that after each specific event (e.g. maximize) you get a resize event. The resize event fires even after Aero Snap actions. So if you save your previous window state and listen to resize you can figure out the current window state.

    Here's the code:

    // mainWindow - is my main BrowserWindow
    // Replace the call to sendWindowSizeChange with what ever you want to do with that event
    
    var WND_STATE = {
        MINIMIZED: 0,
        NORMAL: 1,
        MAXIMIZED: 2,
        FULL_SCREEN: 3
    };
    
    // The initial state of the window
    var wndState = WND_STATE.NORMAL;
    
    mainWindow.on('resize', function () {
        var isMaximized = mainWindow.isMaximized();
        var isMinimized = mainWindow.isMinimized();
        var isFullScreen = mainWindow.isFullScreen();
        var state = wndState;
        if (isMinimized && state !== WND_STATE.MINIMIZED) {
            wndState = WND_STATE.MINIMIZED;
            sendWindowSizeChange('minimize');
        } else if (isFullScreen && state !== WND_STATE.FULL_SCREEN) {
            wndState = WND_STATE.FULL_SCREEN;
            sendWindowSizeChange('fullscreen');
        } else if (isMaximized && state !== WND_STATE.MAXIMIZED) {
            wndState = WND_STATE.MAXIMIZED;
            sendWindowSizeChange('maximize');
        } else if (state !== WND_STATE.NORMAL) {
            wndState = WND_STATE.NORMAL;
            sendWindowSizeChange('normal');
        }
    });
  6. levrik commented on Aug 14, 2015

    @levrik
    Contributor

    I do it this way in my Electron app with React. Maybe it helps somebody:

    _mainWindow: remote.getCurrentWindow(),
    getInitialState: function() {
        return {
            maximized: this._mainWindow.isMaximized()
        }
    },
    componentDidMount: function() {
        this._mainWindow.addListener('resize', this.handleResize);
    },
    componentWillUnmount: function() {
        this._mainWindow.removeListener('resize', this.handleResize);
    },
    
    handleResize: function() {
        let maximizedState = this._mainWindow.isMaximized();
        if (this.state.maximized !== maximizedState) {
            this.setState({
                maximized: maximizedState
            });
        }
    }
  7. added a commit that references this issue on Sep 28, 2015
    ee0f0f6
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