Skip to content

Commit 5d5fbc5

Browse files
Copilotlaeubi
andcommitted
Add system property to disable beep sounds
Co-authored-by: laeubi <[email protected]>
1 parent ecb5777 commit 5d5fbc5

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ enum APPEARANCE {
116116
APPEARANCE appAppearance;
117117
/* System property to be set for SWT application to use the system's theme */
118118
static final String USE_SYSTEM_THEME = "org.eclipse.swt.display.useSystemTheme";
119+
/* System property to control beep sounds */
120+
static final String BEEP_ENABLED = "swt.beep";
119121

120122
/* Windows and Events */
121123
Event [] eventQueue;
@@ -671,7 +673,9 @@ public void execute(Runnable runnable) {
671673
*/
672674
public void beep () {
673675
checkDevice ();
674-
OS.NSBeep ();
676+
if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) {
677+
OS.NSBeep ();
678+
}
675679
}
676680

677681
void cascadeWindow (NSWindow window, NSScreen screen) {

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ public void stop() {
509509

510510
/* Package name */
511511
static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$
512+
/* System property to control beep sounds */
513+
static final String BEEP_ENABLED = "swt.beep";
512514
/* This code is intentionally commented.
513515
* ".class" can not be used on CLDC.
514516
*/
@@ -988,7 +990,9 @@ public void execute(Runnable runnable) {
988990
*/
989991
public void beep () {
990992
if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
991-
GDK.gdk_display_beep(GDK.gdk_display_get_default());
993+
if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) {
994+
GDK.gdk_display_beep(GDK.gdk_display_get_default());
995+
}
992996
}
993997

994998
long cellDataProc (long tree_column, long cell, long tree_model, long iter, long data) {

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ public class Display extends Device implements Executor {
224224
boolean useWsBorderTable = false;
225225
static final String USE_WS_BORDER_TEXT_KEY = "org.eclipse.swt.internal.win32.Text.use_WS_BORDER"; //$NON-NLS-1$
226226
boolean useWsBorderText = false;
227+
/* System property to control beep sounds */
228+
static final String BEEP_ENABLED = "swt.beep";
227229
/**
228230
* Changes the color of Table header's column delimiters.
229231
* Only affects custom-drawn header, that is when background/foreground header color is set.
@@ -852,7 +854,9 @@ public void execute(Runnable runnable) {
852854
*/
853855
public void beep () {
854856
checkDevice ();
855-
OS.MessageBeep (OS.MB_OK);
857+
if (!"off".equalsIgnoreCase(System.getProperty(BEEP_ENABLED))) {
858+
OS.MessageBeep (OS.MB_OK);
859+
}
856860
}
857861

858862
/**

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,50 @@ public void test_beep() {
231231
}
232232
}
233233

234+
@Test
235+
public void test_beep_disabled() {
236+
String originalValue = System.getProperty("swt.beep");
237+
try {
238+
System.setProperty("swt.beep", "off");
239+
Display display = new Display();
240+
try {
241+
// Should not beep when property is "off"
242+
display.beep();
243+
} finally {
244+
display.dispose();
245+
}
246+
} finally {
247+
// Restore original value
248+
if (originalValue != null) {
249+
System.setProperty("swt.beep", originalValue);
250+
} else {
251+
System.clearProperty("swt.beep");
252+
}
253+
}
254+
}
255+
256+
@Test
257+
public void test_beep_enabled() {
258+
String originalValue = System.getProperty("swt.beep");
259+
try {
260+
System.setProperty("swt.beep", "on");
261+
Display display = new Display();
262+
try {
263+
// Should beep when property is "on"
264+
display.beep();
265+
} finally {
266+
display.dispose();
267+
}
268+
} finally {
269+
// Restore original value
270+
if (originalValue != null) {
271+
System.setProperty("swt.beep", originalValue);
272+
} else {
273+
System.clearProperty("swt.beep");
274+
}
275+
}
276+
}
277+
234278
@Test
235279
public void test_close() {
236280
Display display = new Display();

0 commit comments

Comments
 (0)