You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-30 18:30:54 +00:00
Merge pull request #113656 from deralmas/gray-goo-scenario
Wayland: Work around window scale ambiguity
This commit is contained in:
@@ -236,6 +236,11 @@ void WindowWrapper::restore_window_from_saved_position(const Rect2 p_window_rect
|
||||
int screen = p_screen;
|
||||
Rect2 restored_screen_rect = p_screen_rect;
|
||||
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SELF_FITTING_WINDOWS)) {
|
||||
window_rect = Rect2i();
|
||||
restored_screen_rect = Rect2i();
|
||||
}
|
||||
|
||||
if (screen < 0 || screen >= DisplayServer::get_singleton()->get_screen_count()) {
|
||||
// Fallback to the main window screen if the saved screen is not available.
|
||||
screen = get_window()->get_window_id();
|
||||
|
||||
@@ -1228,6 +1228,15 @@ Size2i DisplayServerWayland::window_get_size_with_decorations(DisplayServer::Win
|
||||
return windows[p_window_id].rect.size;
|
||||
}
|
||||
|
||||
float DisplayServerWayland::window_get_scale(WindowID p_window_id) const {
|
||||
MutexLock mutex_lock(wayland_thread.mutex);
|
||||
|
||||
const WaylandThread::WindowState *ws = wayland_thread.window_get_state(p_window_id);
|
||||
ERR_FAIL_NULL_V(ws, 1);
|
||||
|
||||
return wayland_thread.window_state_get_scale_factor(ws);
|
||||
}
|
||||
|
||||
void DisplayServerWayland::window_set_mode(WindowMode p_mode, DisplayServer::WindowID p_window_id) {
|
||||
MutexLock mutex_lock(wayland_thread.mutex);
|
||||
|
||||
|
||||
@@ -290,6 +290,8 @@ public:
|
||||
virtual Size2i window_get_size(WindowID p_window_id = MAIN_WINDOW_ID) const override;
|
||||
virtual Size2i window_get_size_with_decorations(WindowID p_window_id = MAIN_WINDOW_ID) const override;
|
||||
|
||||
virtual float window_get_scale(WindowID p_window_id = MAIN_WINDOW_ID) const override;
|
||||
|
||||
virtual void window_set_mode(WindowMode p_mode, WindowID p_window_id = MAIN_WINDOW_ID) override;
|
||||
virtual WindowMode window_get_mode(WindowID p_window_id = MAIN_WINDOW_ID) const override;
|
||||
|
||||
|
||||
@@ -3435,7 +3435,7 @@ int WaylandThread::window_state_get_preferred_buffer_scale(WindowState *p_ws) {
|
||||
return max_size;
|
||||
}
|
||||
|
||||
double WaylandThread::window_state_get_scale_factor(WindowState *p_ws) {
|
||||
double WaylandThread::window_state_get_scale_factor(const WindowState *p_ws) {
|
||||
ERR_FAIL_NULL_V(p_ws, 1);
|
||||
|
||||
if (p_ws->fractional_scale > 0) {
|
||||
@@ -3972,6 +3972,10 @@ WaylandThread::WindowState *WaylandThread::window_get_state(DisplayServer::Windo
|
||||
return windows.getptr(p_window_id);
|
||||
}
|
||||
|
||||
const WaylandThread::WindowState *WaylandThread::window_get_state(DisplayServer::WindowID p_window_id) const {
|
||||
return windows.getptr(p_window_id);
|
||||
}
|
||||
|
||||
void WaylandThread::beep() const {
|
||||
if (registry.xdg_system_bell) {
|
||||
xdg_system_bell_v1_ring(registry.xdg_system_bell, nullptr);
|
||||
|
||||
@@ -1079,7 +1079,7 @@ public:
|
||||
void seat_state_echo_keys(SeatState *p_ss);
|
||||
|
||||
static int window_state_get_preferred_buffer_scale(WindowState *p_ws);
|
||||
static double window_state_get_scale_factor(WindowState *p_ws);
|
||||
static double window_state_get_scale_factor(const WindowState *p_ws);
|
||||
static void window_state_update_size(WindowState *p_ws, int p_width, int p_height);
|
||||
|
||||
static Vector2i scale_vector2i(const Vector2i &p_vector, double p_amount);
|
||||
@@ -1100,6 +1100,7 @@ public:
|
||||
|
||||
struct wl_surface *window_get_wl_surface(DisplayServer::WindowID p_window_id) const;
|
||||
WindowState *window_get_state(DisplayServer::WindowID p_window_id);
|
||||
const WindowState *window_get_state(DisplayServer::WindowID p_window_id) const;
|
||||
|
||||
void window_start_resize(DisplayServer::WindowResizeEdge p_edge, DisplayServer::WindowID p_window);
|
||||
|
||||
|
||||
@@ -702,6 +702,15 @@ void Window::_clear_window() {
|
||||
|
||||
bool had_focus = has_focus();
|
||||
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SELF_FITTING_WINDOWS)) {
|
||||
float win_scale = DisplayServer::get_singleton()->window_get_scale(window_id);
|
||||
|
||||
Size2i adjusted_size = Size2i(size.width / win_scale, size.height / win_scale);
|
||||
Size2i adjusted_pos = Size2i(position.x / win_scale, position.y / win_scale);
|
||||
|
||||
_rect_changed_callback(Rect2i(adjusted_pos, adjusted_size));
|
||||
}
|
||||
|
||||
if (transient_parent && transient_parent->window_id != DisplayServer::INVALID_WINDOW_ID) {
|
||||
DisplayServer::get_singleton()->window_set_transient(window_id, DisplayServer::INVALID_WINDOW_ID);
|
||||
}
|
||||
|
||||
@@ -493,6 +493,11 @@ public:
|
||||
virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const = 0;
|
||||
virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const = 0;
|
||||
|
||||
virtual float window_get_scale(WindowID p_window = MAIN_WINDOW_ID) const {
|
||||
int screen = window_get_current_screen(p_window);
|
||||
return screen_get_scale(screen);
|
||||
}
|
||||
|
||||
virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) = 0;
|
||||
virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user