Skip to content

[GTK4] setXORMode does not work if no explicit drawing done before use in Cairo #2816

@jonahgraham

Description

@jonahgraham

Consider this sample program (inspired by how Caret works)

public class Snippet999 {

public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	shell.setText("Snippet 999");
	shell.setLayout(new RowLayout());
	Button button = new Button(shell, SWT.TOGGLE);
	button.setText("Toggle");
	Canvas canvas = new Canvas(shell, SWT.NONE);
	canvas.setSize(100, 100);
	canvas.addPaintListener(e -> {
		if (button.getSelection()) {
			e.gc.setXORMode(true);
			e.gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
			e.gc.fillRectangle(10, 10, 5, 20);
		}
	});
	button.addListener(SWT.Selection, e -> {
		canvas.redraw();
	});
	shell.pack();
	shell.open ();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}

On GTK3 it will draw a "caret" the turns on and off each time you press the button in black:

Image

But on GTK4 it will draw in the wrong color because Cairo doesn't know about the background color that Gsk(??) draws and Xors with black, leading to:

Image

Adding an explicit background color draw in Cairo (via GC) does make it work (these lines go at beginning of paint listener)

		e.gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
		e.gc.fillRectangle(e.x, e.y, e.width, e.height);

Originally posted by @jonahgraham in #2812

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions