831{
832 std::unique_lock lock(_gfxLock);
833
834
835
836 const bool popupReady = !_isPopup || _hasGfx;
837
838 const bool unplaceable =
839 _frame || (_overlay && !railPlatformCaps().supportsWindowPositions && isFullDisplaySize());
840
841 const bool drawable =
842 _visible && (_windowRect.w > 0) && (_windowRect.h > 0) && popupReady && !unplaceable &&
843 (!_layered || (_hasGfx && !_visRects.empty() && (_shadowAnchored || _overlay)));
844
845 if (!drawable)
846 {
847
848 if (_layered && _hasGfx && !_visRects.empty() && !_shadowAnchored && !_overlay &&
849 !_shadowSuppressLogged)
850 {
851 _shadowSuppressLogged = true;
853 "shadow-rule suppressed id=0x%08" PRIx32 " %dx%d style=0x%08" PRIx32
854 " ex=0x%08" PRIx32,
855 static_cast<uint32_t>(_id), _windowRect.w, _windowRect.h, _style, _exStyle);
856 }
857 if (_win)
858 {
859 if ((SDL_GetWindowFlags(_win->window()) & SDL_WINDOW_HIDDEN) == 0)
860 {
861 WLog_DBG(
TAG,
"hide id=0x%08" PRIx32
" %s",
static_cast<uint32_t
>(_id), role());
862 SDL_HideWindow(_win->window());
863 _appIdDirty = !_appId.empty();
864 }
865 _mapped = false;
866 }
867 if (_isPopup && !_visible)
868 {
869 _gfxPresented = false;
870 _hasGfx = false;
871 }
872 return false;
873 }
874
875 if (!_win)
876 {
877 if (!create(parent, parentRect))
878 return false;
879 _geometryDirty = false;
880
881 }
882
883
884 if (_topmostDirty)
885 {
886 _topmostDirty = false;
887
888 if (!_isPopup && !_layered)
889 std::ignore = SDL_SetWindowAlwaysOnTop(_win->window(), _topmost);
890 }
891
892
893 if (_styleDirty)
894 {
895 _win->resizeable(styleResizable());
896 _styleDirty = false;
897
898 }
899
900
901
902 if (applyServerState(_maxState, "maximize", SDL_MaximizeWindow))
903 armDeadline(_awaitRestoreUntil, kAwaitRestoreRectMs);
904
905 if ((_localRestoreUntil != 0) && (SDL_GetTicks() >= _localRestoreUntil))
906 {
907 _localRestoreUntil = 0;
908 if (_minState.server && !_minState.rail && !_restoreRetried)
909 {
910 _restoreRetried = true;
911 _restoreRetry = true;
912 armDeadline(_localRestoreUntil, kAwaitRestoreRectMs);
913 }
914 else if (_minState.server != _minState.rail)
915 _minState.dirty = true;
916 }
917 std::ignore = applyServerState(_minState, "minimize", SDL_MinimizeWindow);
918 const bool restorePending = restoreRectPending();
919
920
921 const bool maxed = effectivelyMaximized();
922 const SDL_Rect band = bandInsets();
923 if ((maxed != _wasMaximized) && !_localMoveActive && !restorePending)
924 {
925 setAppliedInsets(band);
926 if (!maxed)
927 _geometryDirty = true;
928 _wasMaximized = maxed;
929 }
930
931
932 if ((railPlatformCaps().band == RailBandMechanism::FrameExtents) && !restorePending &&
933 !SDL_RectsEqual(&band, &_extentsApplied) && railPlatformSetBand(_win->window(), band))
934 {
935 _extentsApplied = band;
936 }
937 const bool wmOwnsGeometry =
938 _localMoveActive || geometryFrozen() || _fullscreen || restorePending;
939
940
941 if ((_minMaxDirty || _geometryDirty) && !wmOwnsGeometry)
942 {
943 const SDL_Rect vis = targetOuterRect();
944 const int bandW = band.x + band.w;
945 const int bandH = band.y + band.h;
946
947 const SDL_Rect& m = _resizeMargins;
948 const int padW = bandW - m.x - m.w;
949 const int padH = bandH - m.y - m.h;
950 const auto toOuter = [](int track, int pad)
951 { return (track > 0) ? std::max(1, track + pad) : 0; };
952 const int minW = toOuter(_minSize.x, padW);
953 const int minH = toOuter(_minSize.y, padH);
954 SDL_SetWindowMinimumSize(_win->window(), std::clamp(minW, 0, vis.w),
955 std::clamp(minH, 0, vis.h));
956 int maxW = toOuter(_maxSize.x, padW);
957 int maxH = toOuter(_maxSize.y, padH);
958
959 SDL_Rect usable{};
960 if (!railPlatformCaps().supportsWindowPositions &&
961 SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &usable))
962 {
963 const int capW = usable.w + bandW;
964 const int capH = usable.h + bandH;
965 if ((maxW == 0) || (maxW > capW))
966 maxW = capW;
967 if ((maxH == 0) || (maxH > capH))
968 maxH = capH;
969 }
970 SDL_SetWindowMaximumSize(_win->window(), maxW, maxH);
971 _minMaxDirty = false;
972 }
973
974
975 if (_geometryDirty && !wmOwnsGeometry)
976 {
977 const SDL_Rect vis = targetOuterRect();
978
979 setAppliedInsets(band);
980 int cw = 0;
981 int ch = 0;
982 SDL_GetWindowSize(_win->window(), &cw, &ch);
983 bool applied = false;
984 bool placed = false;
985
986 if (_isPopup && parent)
987 {
988 placePopup(vis, parentRect);
989 applied = true;
990 }
991 else if (railPlatformCaps().supportsWindowPositions &&
992 !(_isPopup && SDL_GetWindowParent(_win->window())))
993 {
994 int cx = 0;
995 int cy = 0;
996 SDL_GetWindowPosition(_win->window(), &cx, &cy);
997 if ((cx != vis.x) || (cy != vis.y))
998 {
999 placed = railPlatformSetWindowRect(_win->window(), vis);
1000 if (!placed)
1001 SDL_SetWindowPosition(_win->window(), vis.x, vis.y);
1002 applied = true;
1003 }
1004 }
1005 if ((cw != vis.w) || (ch != vis.h))
1006 {
1007 if (!placed && !railPlatformSetWindowRect(_win->window(), vis))
1008 std::ignore = _win->resize({ vis.w, vis.h });
1009 applied = true;
1010
1011
1012 if (railPlatformCaps().supportsWindowPositions && !_isPopup && !_localMoveActive &&
1013 !_loopEnd.pending)
1014 {
1015 const bool settled = SDL_SyncWindow(_win->window());
1016 int aw = 0;
1017 int ah = 0;
1018 SDL_GetWindowSize(_win->window(), &aw, &ah);
1019 if (settled && ((aw != vis.w) || (ah != vis.h)))
1020 {
1021
1022 _wmRefusedOuter = { vis.x, vis.y, aw, ah };
1023 _wmRefused = true;
1024 applied = false;
1025 }
1026 }
1027 }
1028 _geometryDirty = false;
1029
1030 _geomApplyPending = applied && !_isPopup;
1031 }
1032
1033
1034 if (!_isPopup && parent && !_parentApplied &&
1035 ((SDL_GetWindowFlags(parent) & SDL_WINDOW_HIDDEN) == 0))
1036 {
1037 if (SDL_SetWindowParent(_win->window(), parent))
1038 {
1039 _parentApplied = true;
1040
1041 if (((SDL_GetWindowFlags(_win->window()) & SDL_WINDOW_HIDDEN) == 0) &&
1042 !railPlatformRaiseOwned(_win->window()))
1043 WLog_WARN(
TAG,
"raising dialog id=0x%08" PRIx32
" failed",
1044 static_cast<uint32_t>(_id));
1045 }
1046 }
1047 if (_titleDirty)
1048 {
1049 if (!_isPopup)
1050 SDL_SetWindowTitle(_win->window(), _title.c_str());
1051 _titleDirty = false;
1052 }
1053 if (_appIdDirty)
1054 {
1055
1056
1057 if ((_isPopup && !_fullscreen) || !sdl::utils::isWaylandDriver() ||
1058 sdl_wayland_set_app_id(_win->window(), _appId.c_str()))
1059 _appIdDirty = false;
1060 }
1061 if (_iconDirty)
1062 {
1063 if (!_isPopup && !_icon.bgra.empty())
1064 {
1065 SDL_Surface* s = SDL_CreateSurfaceFrom(
1066 static_cast<int>(_icon.w), static_cast<int>(_icon.h), SDL_PIXELFORMAT_BGRA32,
1067 _icon.bgra.data(), static_cast<int>(_icon.w * 4));
1068 if (s)
1069 {
1070 if (!SDL_SetWindowIcon(_win->window(), s))
1071 WLog_WARN(
TAG,
"SDL_SetWindowIcon failed for window 0x%08" PRIx32
": %s",
1072 static_cast<uint32_t>(_id), SDL_GetError());
1073 SDL_DestroySurface(s);
1074 }
1075 }
1076 _iconDirty = false;
1077 }
1078
1079
1080 if (!_minState.rail && _gfxPresented &&
1081 (SDL_GetWindowFlags(_win->window()) & SDL_WINDOW_HIDDEN))
1082 {
1083
1084 SDL_Window* owner = _isPopup ? nullptr : SDL_GetWindowParent(_win->window());
1085 if (owner && ((SDL_GetWindowFlags(owner) & SDL_WINDOW_HIDDEN) != 0))
1086 {
1087 if (SDL_SetWindowParent(_win->window(), nullptr))
1088 _parentApplied = false;
1089 else
1090 WLog_WARN(
TAG,
"detaching dialog id=0x%08" PRIx32
" failed: %s",
1091 static_cast<uint32_t>(_id), SDL_GetError());
1092 }
1093 SDL_ShowWindow(_win->window());
1094 }
1095 return true;
1096}