Quellcode durchsuchen

Merge pull request #104959 from bruvzg/kde_swap

Linux: Detect KDE/LXQt and swap OK/Cancel buttons to Windows style.
Thaddeus Crews vor 4 Monaten
Ursprung
Commit
6392241742

+ 8 - 0
platform/linuxbsd/wayland/display_server_wayland.cpp

@@ -1142,6 +1142,10 @@ void DisplayServerWayland::cursor_set_custom_image(const Ref<Resource> &p_cursor
 	}
 }
 
+bool DisplayServerWayland::get_swap_cancel_ok() {
+	return swap_cancel_ok;
+}
+
 int DisplayServerWayland::keyboard_get_layout_count() const {
 	MutexLock mutex_lock(wayland_thread.mutex);
 
@@ -1450,6 +1454,10 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win
 	r_error = ERR_UNAVAILABLE;
 	context = p_context;
 
+	String current_desk = OS::get_singleton()->get_environment("XDG_CURRENT_DESKTOP").to_lower();
+	String session_desk = OS::get_singleton()->get_environment("XDG_SESSION_DESKTOP").to_lower();
+	swap_cancel_ok = (current_desk.contains("kde") || session_desk.contains("kde") || current_desk.contains("lxqt") || session_desk.contains("lxqt"));
+
 	Error thread_err = wayland_thread.init();
 
 	if (thread_err != OK) {

+ 3 - 0
platform/linuxbsd/wayland/display_server_wayland.h

@@ -123,6 +123,7 @@ class DisplayServerWayland : public DisplayServer {
 	WaylandThread wayland_thread;
 
 	Context context;
+	bool swap_cancel_ok = false;
 
 	String ime_text;
 	Vector2i ime_selection;
@@ -295,6 +296,8 @@ public:
 	virtual CursorShape cursor_get_shape() const override;
 	virtual void cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) override;
 
+	virtual bool get_swap_cancel_ok() override;
+
 	virtual int keyboard_get_layout_count() const override;
 	virtual int keyboard_get_current_layout() const override;
 	virtual void keyboard_set_current_layout(int p_index) override;

+ 9 - 1
platform/linuxbsd/x11/display_server_x11.cpp

@@ -3395,6 +3395,10 @@ void DisplayServerX11::cursor_set_custom_image(const Ref<Resource> &p_cursor, Cu
 	}
 }
 
+bool DisplayServerX11::get_swap_cancel_ok() {
+	return swap_cancel_ok;
+}
+
 int DisplayServerX11::keyboard_get_layout_count() const {
 	int _group_count = 0;
 	XkbDescRec *kbd = XkbAllocKeyboard();
@@ -6515,8 +6519,12 @@ static ::XIMStyle _get_best_xim_style(const ::XIMStyle &p_style_a, const ::XIMSt
 DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, int64_t p_parent_window, Error &r_error) {
 	KeyMappingX11::initialize();
 
+	String current_desk = OS::get_singleton()->get_environment("XDG_CURRENT_DESKTOP").to_lower();
+	String session_desk = OS::get_singleton()->get_environment("XDG_SESSION_DESKTOP").to_lower();
+	swap_cancel_ok = (current_desk.contains("kde") || session_desk.contains("kde") || current_desk.contains("lxqt") || session_desk.contains("lxqt"));
+
 	xwayland = OS::get_singleton()->get_environment("XDG_SESSION_TYPE").to_lower() == "wayland";
-	kde5_embed_workaround = OS::get_singleton()->get_environment("XDG_CURRENT_DESKTOP").to_lower() == "kde" && OS::get_singleton()->get_environment("KDE_SESSION_VERSION") == "5";
+	kde5_embed_workaround = current_desk == "kde" && OS::get_singleton()->get_environment("KDE_SESSION_VERSION") == "5";
 
 	native_menu = memnew(NativeMenu);
 	context = p_context;

+ 3 - 0
platform/linuxbsd/x11/display_server_x11.h

@@ -359,6 +359,7 @@ class DisplayServerX11 : public DisplayServer {
 	void _update_context(WindowData &wd);
 
 	Context context = CONTEXT_ENGINE;
+	bool swap_cancel_ok = false;
 
 	WindowID _get_focused_window_or_popup() const;
 	bool _window_focus_check();
@@ -550,6 +551,8 @@ public:
 	virtual CursorShape cursor_get_shape() const override;
 	virtual void cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) override;
 
+	virtual bool get_swap_cancel_ok() override;
+
 	virtual int keyboard_get_layout_count() const override;
 	virtual int keyboard_get_current_layout() const override;
 	virtual void keyboard_set_current_layout(int p_index) override;