Skip to content

Commit 9af7269

Browse files
ptzieglerakurtakov
authored andcommitted
[GTK] Don't invalidate style context when setting background color #2702
When setting the background color while inside an SWT.Activate event, pending events are not processed. The gtk_style_context_invalidate() method is deprecated in GTK3 and doesn't have a GTK4 counterpart, as GTK invalidates the style context automatically. With b7dee8a, this method call was already removed, but later reverted due to test failures in the Eclipse Platform. Rather than removing all references, this change only does so for the call to setBackground(). To reproduce, execute the Snippet388. When clicking on a tree/table item, the item should be selected. This is the current behavior on Windows and MacOS, but not on Linux. Closes #2702
1 parent 1d450f7 commit 9af7269

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5258,7 +5258,6 @@ void setBackgroundGdkRGBA (long handle, GdkRGBA rgba) {
52585258

52595259
long context = GTK.gtk_widget_get_style_context(handle);
52605260
setBackgroundGdkRGBA(context, handle, rgba);
5261-
if (!GTK.GTK4) GTK3.gtk_style_context_invalidate(context);
52625261
}
52635262
/**
52645263
* Sets the receiver's background image to the image specified
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Patrick Ziegler and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Patrick Ziegler - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.swt.tests.gtk.snippets;
15+
16+
import org.eclipse.swt.*;
17+
import org.eclipse.swt.graphics.*;
18+
import org.eclipse.swt.layout.*;
19+
import org.eclipse.swt.widgets.*;
20+
21+
/**
22+
* This snippet demonstrates a missed selection event when updating the
23+
* background color within an SWT.Activate event. To reproduce, alternative
24+
* between the table and the tree. On each click, the clicked tree/table item
25+
* should be selected.
26+
*
27+
* @see <a href="https://github.com/eclipse-platform/eclipse.platform.swt/issues/2702">Issue 2702</a>
28+
*/
29+
public class Issue2702_DoubleClickBehavior {
30+
private static Color ACTIVE = new Color(255, 255, 255);
31+
private static Color INACTIVE = new Color(248, 248, 248);
32+
33+
public static void main(String[] args) {
34+
Shell shell = new Shell();
35+
shell.setLayout(new GridLayout(2, true));
36+
shell.setSize(400, 200);
37+
38+
Tree tree = new Tree(shell, SWT.FULL_SELECTION);
39+
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
40+
TreeItem treeItem1 = new TreeItem(tree, SWT.NONE);
41+
treeItem1.setText("Tree Item 1");
42+
TreeItem treeItem2 = new TreeItem(tree, SWT.NONE);
43+
treeItem2.setText("Tree Item 2");
44+
tree.addListener(SWT.Activate, event -> tree.setBackground(ACTIVE));
45+
tree.addListener(SWT.Deactivate, event -> tree.setBackground(INACTIVE));
46+
47+
Table table = new Table(shell, SWT.FULL_SELECTION);
48+
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
49+
TableItem tableItem1 = new TableItem(table, SWT.NONE);
50+
tableItem1.setText("Table Item 1");
51+
TableItem tableItem2 = new TableItem(table, SWT.NONE);
52+
tableItem2.setText("Table Item 2");
53+
table.addListener(SWT.Activate, event -> table.setBackground(ACTIVE));
54+
table.addListener(SWT.Deactivate, event -> table.setBackground(INACTIVE));
55+
56+
shell.open();
57+
58+
Display display = shell.getDisplay();
59+
while (!shell.isDisposed()) {
60+
if (!display.readAndDispatch()) {
61+
display.sleep();
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)