From 57f87726895fd4f75cf01af2d0ae0bf482bd4b7d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 08:31:07 +0000 Subject: [PATCH 1/2] Add system property to disable beep sounds Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com> --- .../org/eclipse/swt/widgets/Display.java | 6 ++- .../gtk/org/eclipse/swt/widgets/Display.java | 6 ++- .../org/eclipse/swt/widgets/Display.java | 6 ++- .../Test_org_eclipse_swt_widgets_Display.java | 44 +++++++++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index abd8b2446dc..631cf940eac 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -116,6 +116,8 @@ enum APPEARANCE { APPEARANCE appAppearance; /* System property to be set for SWT application to use the system's theme */ static final String USE_SYSTEM_THEME = "org.eclipse.swt.display.useSystemTheme"; + /* System property to control beep sounds */ + static final String BEEP_ENABLED = "swt.beep"; /* Windows and Events */ Event [] eventQueue; @@ -671,7 +673,9 @@ public void execute(Runnable runnable) { */ public void beep () { checkDevice (); - OS.NSBeep (); + if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) { + OS.NSBeep (); + } } void cascadeWindow (NSWindow window, NSScreen screen) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 5b52c106f48..18034ff867a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -509,6 +509,8 @@ public void stop() { /* Package name */ static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$ + /* System property to control beep sounds */ + static final String BEEP_ENABLED = "swt.beep"; /* This code is intentionally commented. * ".class" can not be used on CLDC. */ @@ -988,7 +990,9 @@ public void execute(Runnable runnable) { */ public void beep () { if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - GDK.gdk_display_beep(GDK.gdk_display_get_default()); + if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) { + GDK.gdk_display_beep(GDK.gdk_display_get_default()); + } } long cellDataProc (long tree_column, long cell, long tree_model, long iter, long data) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java index 12ed1c2f9d5..c405debcf80 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java @@ -224,6 +224,8 @@ public class Display extends Device implements Executor { boolean useWsBorderTable = false; static final String USE_WS_BORDER_TEXT_KEY = "org.eclipse.swt.internal.win32.Text.use_WS_BORDER"; //$NON-NLS-1$ boolean useWsBorderText = false; + /* System property to control beep sounds */ + static final String BEEP_ENABLED = "swt.beep"; /** * Changes the color of Table header's column delimiters. * Only affects custom-drawn header, that is when background/foreground header color is set. @@ -852,7 +854,9 @@ public void execute(Runnable runnable) { */ public void beep () { checkDevice (); - OS.MessageBeep (OS.MB_OK); + if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) { + OS.MessageBeep (OS.MB_OK); + } } /** diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java index 5802d11f132..085917438bc 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java @@ -231,6 +231,50 @@ public void test_beep() { } } +@Test +public void test_beep_disabled() { + String originalValue = System.getProperty("swt.beep"); + try { + System.setProperty("swt.beep", "off"); + Display display = new Display(); + try { + // Should not beep when property is "off" + display.beep(); + } finally { + display.dispose(); + } + } finally { + // Restore original value + if (originalValue != null) { + System.setProperty("swt.beep", originalValue); + } else { + System.clearProperty("swt.beep"); + } + } +} + +@Test +public void test_beep_enabled() { + String originalValue = System.getProperty("swt.beep"); + try { + System.setProperty("swt.beep", "on"); + Display display = new Display(); + try { + // Should beep when property is "on" + display.beep(); + } finally { + display.dispose(); + } + } finally { + // Restore original value + if (originalValue != null) { + System.setProperty("swt.beep", originalValue); + } else { + System.clearProperty("swt.beep"); + } + } +} + @Test public void test_close() { Display display = new Display(); From f1622e5eff1a240e738ffd382b8b2296f126ba48 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 10 Oct 2025 08:55:54 +0000 Subject: [PATCH 2/2] Store beep property evaluation in static boolean field and remove test cases Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com> --- .../org/eclipse/swt/widgets/Display.java | 4 +- .../gtk/org/eclipse/swt/widgets/Display.java | 4 +- .../org/eclipse/swt/widgets/Display.java | 4 +- .../Test_org_eclipse_swt_widgets_Display.java | 44 ------------------- 4 files changed, 6 insertions(+), 50 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java index 631cf940eac..619e5212782 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java @@ -117,7 +117,7 @@ enum APPEARANCE { /* System property to be set for SWT application to use the system's theme */ static final String USE_SYSTEM_THEME = "org.eclipse.swt.display.useSystemTheme"; /* System property to control beep sounds */ - static final String BEEP_ENABLED = "swt.beep"; + public static final boolean BEEP_ENABLED = !"off".equalsIgnoreCase(System.getProperty("swt.beep")); /* Windows and Events */ Event [] eventQueue; @@ -673,7 +673,7 @@ public void execute(Runnable runnable) { */ public void beep () { checkDevice (); - if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) { + if (BEEP_ENABLED) { OS.NSBeep (); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 18034ff867a..d6b6f41902f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -510,7 +510,7 @@ public void stop() { /* Package name */ static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$ /* System property to control beep sounds */ - static final String BEEP_ENABLED = "swt.beep"; + public static final boolean BEEP_ENABLED = !"off".equalsIgnoreCase(System.getProperty("swt.beep")); /* This code is intentionally commented. * ".class" can not be used on CLDC. */ @@ -990,7 +990,7 @@ public void execute(Runnable runnable) { */ public void beep () { if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) { + if (BEEP_ENABLED) { GDK.gdk_display_beep(GDK.gdk_display_get_default()); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java index c405debcf80..4d41a343bb2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java @@ -225,7 +225,7 @@ public class Display extends Device implements Executor { static final String USE_WS_BORDER_TEXT_KEY = "org.eclipse.swt.internal.win32.Text.use_WS_BORDER"; //$NON-NLS-1$ boolean useWsBorderText = false; /* System property to control beep sounds */ - static final String BEEP_ENABLED = "swt.beep"; + public static final boolean BEEP_ENABLED = !"off".equalsIgnoreCase(System.getProperty("swt.beep")); /** * Changes the color of Table header's column delimiters. * Only affects custom-drawn header, that is when background/foreground header color is set. @@ -854,7 +854,7 @@ public void execute(Runnable runnable) { */ public void beep () { checkDevice (); - if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) { + if (BEEP_ENABLED) { OS.MessageBeep (OS.MB_OK); } } diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java index 085917438bc..5802d11f132 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java @@ -231,50 +231,6 @@ public void test_beep() { } } -@Test -public void test_beep_disabled() { - String originalValue = System.getProperty("swt.beep"); - try { - System.setProperty("swt.beep", "off"); - Display display = new Display(); - try { - // Should not beep when property is "off" - display.beep(); - } finally { - display.dispose(); - } - } finally { - // Restore original value - if (originalValue != null) { - System.setProperty("swt.beep", originalValue); - } else { - System.clearProperty("swt.beep"); - } - } -} - -@Test -public void test_beep_enabled() { - String originalValue = System.getProperty("swt.beep"); - try { - System.setProperty("swt.beep", "on"); - Display display = new Display(); - try { - // Should beep when property is "on" - display.beep(); - } finally { - display.dispose(); - } - } finally { - // Restore original value - if (originalValue != null) { - System.setProperty("swt.beep", originalValue); - } else { - System.clearProperty("swt.beep"); - } - } -} - @Test public void test_close() { Display display = new Display();