890{
891 std::unique_lock lock(_gfxLock);
892
893
894
895 const bool popupReady = !_isPopup || _hasGfx;
896
897 const bool unplaceable =
898 _frame || (_overlay && !railPlatformCaps().supportsWindowPositions && isFullDisplaySize());
899
900 const bool drawable =
901 _visible && (_windowRect.w > 0) && (_windowRect.h > 0) && popupReady && !unplaceable &&
902 (!_layered || (_hasGfx && !_visRects.empty() && (_shadowAnchored || _overlay)));
903
904 if (!drawable)
905 {
906
907 if (_layered && _hasGfx && !_visRects.empty() && !_shadowAnchored && !_overlay &&
908 !_shadowSuppressLogged)
909 {
910 _shadowSuppressLogged = true;
912 "shadow-rule suppressed id=0x%08" PRIx32 " %dx%d style=0x%08" PRIx32
913 " ex=0x%08" PRIx32,
914 static_cast<uint32_t>(_id), _windowRect.w, _windowRect.h, _style, _exStyle);
915 }
916 if (_win)
917 {
918 if ((SDL_GetWindowFlags(_win->window()) & SDL_WINDOW_HIDDEN) == 0)
919 {
920 WLog_DBG(
TAG,
"hide id=0x%08" PRIx32
" %s",
static_cast<uint32_t
>(_id), role());
921 SDL_HideWindow(_win->window());
922 _appIdDirty = !_appId.empty();
923 }
924 _mapped = false;
925 }
926 if (_isPopup && !_visible)
927 {
928 _gfxPresented = false;
929 _hasGfx = false;
930 }
931 return false;
932 }
933
934 if (!_win)
935 {
936 if (!create(parent, parentRect))
937 return false;
938 _geometryDirty = false;
939
940 }
941
942
943 if (_topmostDirty)
944 {
945 _topmostDirty = false;
946
947 if (!_isPopup && !_layered)
948 std::ignore = SDL_SetWindowAlwaysOnTop(_win->window(), _topmost);
949 }
950
951
952 if (_styleDirty)
953 {
954 _win->resizeable(styleResizable());
955 _styleDirty = false;
956
957 }
958
959
960
961 if (applyServerState(_maxState, "maximize", SDL_MaximizeWindow))
962 armDeadline(_awaitRestoreUntil, kAwaitRestoreRectMs);
963
964 if ((_localRestoreUntil != 0) && (SDL_GetTicks() >= _localRestoreUntil))
965 {
966 _localRestoreUntil = 0;
967 if (_minState.server && !_minState.rail && !_restoreRetried)
968 {
969 _restoreRetried = true;
970 _restoreRetry = true;
971 armDeadline(_localRestoreUntil, kAwaitRestoreRectMs);
972 }
973 else if (_minState.server != _minState.rail)
974 _minState.dirty = true;
975 }
976 std::ignore = applyServerState(_minState, "minimize", SDL_MinimizeWindow);
977 const bool restorePending = restoreRectPending();
978
979
980 const bool maxed = effectivelyMaximized();
981 const SDL_Rect band = bandInsets();
982 if ((maxed != _wasMaximized) && !_localMoveActive && !restorePending)
983 {
984 setAppliedInsets(band);
985 if (!maxed)
986 _geometryDirty = true;
987 _wasMaximized = maxed;
988 }
989
990
991 if ((railPlatformCaps().band == RailBandMechanism::FrameExtents) && !restorePending &&
992 !SDL_RectsEqual(&band, &_extentsApplied) && railPlatformSetBand(_win->window(), band))
993 {
994 _extentsApplied = band;
995 }
996 const bool wmOwnsGeometry =
997 _localMoveActive || geometryFrozen() || _fullscreen || restorePending;
998
999
1000 if ((_minMaxDirty || _geometryDirty) && !wmOwnsGeometry)
1001 {
1002 const SDL_Rect vis = targetOuterRect();
1003 const int bandW = band.x + band.w;
1004 const int bandH = band.y + band.h;
1005
1006 const SDL_Rect& m = _resizeMargins;
1007 const int padW = bandW - m.x - m.w;
1008 const int padH = bandH - m.y - m.h;
1009 const auto toOuter = [](int track, int pad)
1010 { return (track > 0) ? std::max(1, track + pad) : 0; };
1011 const int minW = toOuter(_minSize.x, padW);
1012 const int minH = toOuter(_minSize.y, padH);
1013 SDL_SetWindowMinimumSize(_win->window(), std::clamp(minW, 0, vis.w),
1014 std::clamp(minH, 0, vis.h));
1015 int maxW = toOuter(_maxSize.x, padW);
1016 int maxH = toOuter(_maxSize.y, padH);
1017
1018 SDL_Rect usable{};
1019 if (!railPlatformCaps().supportsWindowPositions &&
1020 SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &usable))
1021 {
1022 const int capW = usable.w + bandW;
1023 const int capH = usable.h + bandH;
1024 if ((maxW == 0) || (maxW > capW))
1025 maxW = capW;
1026 if ((maxH == 0) || (maxH > capH))
1027 maxH = capH;
1028 }
1029 SDL_SetWindowMaximumSize(_win->window(), maxW, maxH);
1030 _minMaxDirty = false;
1031 }
1032
1033
1034 if (_geometryDirty && !wmOwnsGeometry)
1035 {
1036 const SDL_Rect vis = targetOuterRect();
1037
1038 setAppliedInsets(band);
1039 int cw = 0;
1040 int ch = 0;
1041 SDL_GetWindowSize(_win->window(), &cw, &ch);
1042 bool applied = false;
1043 bool placed = false;
1044
1045 if (_isPopup && parent)
1046 {
1047 placePopup(vis, parentRect);
1048 applied = true;
1049 }
1050 else if (railPlatformCaps().supportsWindowPositions &&
1051 !(_isPopup && SDL_GetWindowParent(_win->window())))
1052 {
1053 int cx = 0;
1054 int cy = 0;
1055 SDL_GetWindowPosition(_win->window(), &cx, &cy);
1056 if ((cx != vis.x) || (cy != vis.y))
1057 {
1058 placed = railPlatformSetWindowRect(_win->window(), vis);
1059 if (!placed)
1060 SDL_SetWindowPosition(_win->window(), vis.x, vis.y);
1061 applied = true;
1062 }
1063 }
1064 if ((cw != vis.w) || (ch != vis.h))
1065 {
1066 if (!placed && !railPlatformSetWindowRect(_win->window(), vis))
1067 std::ignore = _win->resize({ vis.w, vis.h });
1068 applied = true;
1069
1070
1071 if (railPlatformCaps().supportsWindowPositions && !_isPopup && !_localMoveActive &&
1072 !_loopEnd.pending)
1073 {
1074 const bool settled = SDL_SyncWindow(_win->window());
1075 int aw = 0;
1076 int ah = 0;
1077 SDL_GetWindowSize(_win->window(), &aw, &ah);
1078 if (settled && ((aw != vis.w) || (ah != vis.h)))
1079 {
1080
1081 _wmRefusedOuter = { vis.x, vis.y, aw, ah };
1082 _wmRefused = true;
1083 applied = false;
1084 }
1085 }
1086 }
1087 _geometryDirty = false;
1088
1089 _geomApplyPending = applied && !_isPopup;
1090 }
1091
1092
1093 if (!_isPopup && parent && !_parentApplied &&
1094 ((SDL_GetWindowFlags(parent) & SDL_WINDOW_HIDDEN) == 0))
1095 {
1096 if (SDL_SetWindowParent(_win->window(), parent))
1097 {
1098 _parentApplied = true;
1099
1100 if (((SDL_GetWindowFlags(_win->window()) & SDL_WINDOW_HIDDEN) == 0) &&
1101 !railPlatformRaiseOwned(_win->window()))
1102 WLog_WARN(
TAG,
"raising dialog id=0x%08" PRIx32
" failed",
1103 static_cast<uint32_t>(_id));
1104 }
1105 }
1106 if (_titleDirty)
1107 {
1108 if (!_isPopup)
1109 SDL_SetWindowTitle(_win->window(), _title.c_str());
1110 _titleDirty = false;
1111 }
1112 if (_appIdDirty)
1113 {
1114
1115
1116 if ((_isPopup && !_fullscreen) || !sdl::utils::isWaylandDriver() ||
1117 sdl_wayland_set_app_id(_win->window(), _appId.c_str()))
1118 _appIdDirty = false;
1119 }
1120 if (_iconDirty)
1121 {
1122 if (!_isPopup && !_icon.bgra.empty())
1123 {
1124 SDL_Surface* s = SDL_CreateSurfaceFrom(
1125 static_cast<int>(_icon.w), static_cast<int>(_icon.h), SDL_PIXELFORMAT_BGRA32,
1126 _icon.bgra.data(), static_cast<int>(_icon.w * 4));
1127 if (s)
1128 {
1129 if (!SDL_SetWindowIcon(_win->window(), s))
1130 WLog_WARN(
TAG,
"SDL_SetWindowIcon failed for window 0x%08" PRIx32
": %s",
1131 static_cast<uint32_t>(_id), SDL_GetError());
1132 SDL_DestroySurface(s);
1133 }
1134 }
1135 _iconDirty = false;
1136 }
1137
1138
1139 if (!_minState.rail && _gfxPresented &&
1140 (SDL_GetWindowFlags(_win->window()) & SDL_WINDOW_HIDDEN))
1141 {
1142
1143 SDL_Window* owner = _isPopup ? nullptr : SDL_GetWindowParent(_win->window());
1144 if (owner && ((SDL_GetWindowFlags(owner) & SDL_WINDOW_HIDDEN) != 0))
1145 {
1146 if (SDL_SetWindowParent(_win->window(), nullptr))
1147 _parentApplied = false;
1148 else
1149 WLog_WARN(
TAG,
"detaching dialog id=0x%08" PRIx32
" failed: %s",
1150 static_cast<uint32_t>(_id), SDL_GetError());
1151 }
1152 SDL_ShowWindow(_win->window());
1153 }
1154 return true;
1155}