From aaeee37f0ad4afb2e857aa07bd2874ca3e8ecde4 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 17 Mar 2020 13:54:16 +0100 Subject: [PATCH] Don't resize viewer window when maximized Most window managers won't like this, and it tends to provoke bugs in FLTK, so let's avoid it. It's probably not what the user wants anyway. --- vncviewer/DesktopWindow.cxx | 39 ++++++++++++++++++++++++++++++++++++- vncviewer/cocoa.h | 2 ++ vncviewer/cocoa.mm | 7 +++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx index 47fd3dbe..78893925 100644 --- a/vncviewer/DesktopWindow.cxx +++ b/vncviewer/DesktopWindow.cxx @@ -252,13 +252,50 @@ void DesktopWindow::updateWindow() void DesktopWindow::resizeFramebuffer(int new_w, int new_h) { + bool maximized; + if ((new_w == viewport->w()) && (new_h == viewport->h())) return; + maximized = false; + +#ifdef WIN32 + WINDOWPLACEMENT wndpl; + memset(&wndpl, 0, sizeof(WINDOWPLACEMENT)); + wndpl.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement(fl_xid(this), &wndpl); + if (wndpl.showCmd == SW_SHOWMAXIMIZED) + maximized = true; +#elif defined(__APPLE__) + if (cocoa_win_is_zoomed(this)) + maximized = true; +#else + Atom net_wm_state = XInternAtom (fl_display, "_NET_WM_STATE", 0); + Atom net_wm_state_maximized_vert = XInternAtom (fl_display, "_NET_WM_STATE_MAXIMIZED_VERT", 0); + Atom net_wm_state_maximized_horz = XInternAtom (fl_display, "_NET_WM_STATE_MAXIMIZED_HORZ", 0); + + Atom type; + int format; + unsigned long nitems, remain; + Atom *atoms; + + XGetWindowProperty(fl_display, fl_xid(this), net_wm_state, 0, 1024, False, XA_ATOM, &type, &format, &nitems, &remain, (unsigned char**)&atoms); + + for (unsigned long i = 0;i < nitems;i++) { + if ((atoms[i] == net_wm_state_maximized_vert) || + (atoms[i] == net_wm_state_maximized_horz)) { + maximized = true; + break; + } + } + + XFree(atoms); +#endif + // If we're letting the viewport match the window perfectly, then // keep things that way for the new size, otherwise just keep things // like they are. - if (!fullscreen_active()) { + if (!fullscreen_active() && !maximized) { if ((w() == viewport->w()) && (h() == viewport->h())) size(new_w, new_h); else { diff --git a/vncviewer/cocoa.h b/vncviewer/cocoa.h index a7138026..c65e19eb 100644 --- a/vncviewer/cocoa.h +++ b/vncviewer/cocoa.h @@ -26,6 +26,8 @@ typedef struct CGColorSpace *CGColorSpaceRef; CGColorSpaceRef cocoa_win_color_space(Fl_Window *win); +bool cocoa_win_is_zoomed(Fl_Window *win); + int cocoa_is_keyboard_event(const void *event); int cocoa_is_key_press(const void *event); diff --git a/vncviewer/cocoa.mm b/vncviewer/cocoa.mm index a22937f8..bd0e0800 100644 --- a/vncviewer/cocoa.mm +++ b/vncviewer/cocoa.mm @@ -138,6 +138,13 @@ CGColorSpaceRef cocoa_win_color_space(Fl_Window *win) return lut; } +bool cocoa_win_is_zoomed(Fl_Window *win) +{ + NSWindow *nsw; + nsw = (NSWindow*)fl_xid(win); + return [nsw isZoomed]; +} + int cocoa_is_keyboard_event(const void *event) { NSEvent *nsevent; -- 2.39.5