### Godot version

v4.0.2.stable.official [7a0977c]

### System information

Window 10

### Issue description

If your project is set to `WINDOW_MODE_FULLSCREEN` in project settings, the first time you try to switch mode for `WINDOWED`, it will not switch properly.


### Steps to reproduce

1. Create a new project
2. Change project settings `Display > Window > Mode` for `FullScreen`
3. Run the following code :

Code that reproduce the issue:
```
func _ready():
	DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
	DisplayServer.window_set_size(Vector2i(800,600))
``` 

## Workaround
Calling the `window_set_mode` twice solve the issue...

```
func _ready():
	DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
	DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
	DisplayServer.window_set_size(Vector2i(800,600))
``` 


### Minimal reproduction project

N/A: reproduction steps are trivial
if (!keysym.is_empty()) {
						key_label = fix_key_label(keysym[0], keycode);
					}
				}
				if (keycode != Key::SHIFT) {
					k->set_shift_pressed(ke.shift);
				}
				if (keycode != Key::ALT) {
					k->set_alt_pressed(ke.alt);
				}
				if (keycode != Key::CTRL) {
					k->set_ctrl_pressed(ke.control);
				}
				if (keycode != Key::META) {
					k->set_meta_pressed(ke.meta);
				}
				k->set_keycode(keycode);
				k->set_physical_keycode(physical_keycode);
				k->set_key_label(key_label);
				if (i + 1 < key_event_pos && key_event_buffer[i + 1].uMsg == WM_CHAR) {
					char32_t unicode = key_event_buffer[i + 1].wParam;
					static char32_t prev_wck = 0;
					if ((unicode & 0xfffffc00) == 0xd800) {
						if (prev_wck != 0) {
							ERR_PRINT("invalid utf16 surrogate input");
						}
						prev_wck = unicode;
						break; 
					} else if ((unicode & 0xfffffc00) == 0xdc00) {
						if (prev_wck == 0) {