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

Resize event isn't called on time #494

Closed
morajabi opened this issue Jul 24, 2022 · 2 comments
Closed

Resize event isn't called on time #494

morajabi opened this issue Jul 24, 2022 · 2 comments

Comments

@morajabi
Copy link

morajabi commented Jul 24, 2022

In order to preserve window control buttons position, we need to re-apply the logic to update their position on resize, move, and exit/start full-screen. (taken from Electron) Although the move event works fine, on resize we get a flicker.

CleanShot 2022-07-24 at 13 11 27

Code that updates the titlebar:

   unsafe {
            let id = self.ns_window().unwrap() as cocoa::base::id;
            NSWindow::setTitlebarAppearsTransparent_(id, cocoa::base::YES);
            let mut style_mask = id.styleMask();
            style_mask.set(
                NSWindowStyleMask::NSFullSizeContentViewWindowMask,
                title_transparent,
            );

            if remove_tool_bar {
                style_mask.remove(
                    NSWindowStyleMask::NSClosableWindowMask
                        | NSWindowStyleMask::NSMiniaturizableWindowMask
                        | NSWindowStyleMask::NSResizableWindowMask,
                );
            }

            id.setStyleMask_(style_mask);

            id.setTitleVisibility_(if title_transparent {
                NSWindowTitleVisibility::NSWindowTitleHidden
            } else {
                NSWindowTitleVisibility::NSWindowTitleVisible
            });

            id.setTitlebarAppearsTransparent_(if title_transparent {
                cocoa::base::YES
            } else {
                cocoa::base::NO
            });

            let title_bar_x = -4.0;
            let title_bar_y = 26.0;

            // TAKEN FROM ELECTRON
            // https://github.com/patr0nus/DeskGap/blob/master/lib/src/platform/mac/BrowserWindow.mm#L100
            // also need to handle on full screen enter, exit, resize, etc

            let close = NSWindow::standardWindowButton_(id, NSWindowButton::NSWindowCloseButton);
            let miniaturize = id.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton);
            let zoom = id.standardWindowButton_(NSWindowButton::NSWindowZoomButton);

            let title_bar_container_view = close.superview().superview();

            let button_height = NSView::frame(close).size.height;
            let title_bar_frame_height = button_height + title_bar_y;
            let mut title_bar_rect = NSView::frame(title_bar_container_view);
            title_bar_rect.size.height = title_bar_frame_height;
            title_bar_rect.origin.y = NSWindow::frame(id).size.height - title_bar_frame_height;
            NSView::setFrameOrigin(title_bar_container_view, title_bar_rect.origin);
            NSView::setFrameSize(title_bar_container_view, title_bar_rect.size);

            // OG: NSArray* windowButtons = @[ close, miniaturize, zoom ];
            // i don't know what is @ in rust code
            let _window_buttons = [close, miniaturize, zoom];
            let space_between = NSView::frame(miniaturize).origin.x - NSView::frame(close).origin.x;

            let mut button_rect1 = NSView::frame(close);
            button_rect1.origin.x = title_bar_x + (1.0 * space_between);
            button_rect1.origin.y = (title_bar_frame_height - button_rect1.size.height) / 2.0;
            NSView::setFrameOrigin(close, button_rect1.origin);

            let mut button_rect2 = NSView::frame(miniaturize);
            button_rect2.origin.x = title_bar_x + (2.0 * space_between);
            button_rect2.origin.y = (title_bar_frame_height - button_rect2.size.height) / 2.0;
            NSView::setFrameOrigin(miniaturize, button_rect2.origin);

            let mut button_rect3 = NSView::frame(zoom);
            button_rect3.origin.x = title_bar_x + (3.0 * space_between);
            button_rect3.origin.y = (title_bar_frame_height - button_rect3.size.height) / 2.0;
            NSView::setFrameOrigin(zoom, button_rect3.origin);
        }

cc @wusyong (sorry to @, since you were recently involved in the resize logic, I'd love to know what can I do about it.)

@morajabi
Copy link
Author

For future reference, there is another event made for this: Event::RedrawRequested(_).
However, this feature has been made in tao in #513 so once merged we'd no longer need to do it manually.

@alexandernanberg
Copy link

@morajabi Have you been able to use Event::RedrawRequested(_) in your Tauri app? Don't quite understand if it's possible or I'm missing something

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

No branches or pull requests

2 participants