Skip to content

Commit c051490

Browse files
committed
Fix Carret drawing on GTK 4
Hooked Gtk 4 focus and draw events for Canvas to enable drawing. It is unclear why cairo_set_source_rgb actually reverses color on Gtk 4 but this makes us move a step ahead towards working editor. Tested via Snippet74.
1 parent 0e04bc9 commit c051490

File tree

1 file changed

+22
-2
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets

1 file changed

+22
-2
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ long gtk_draw (long widget, long cairo) {
175175
return result;
176176
}
177177

178+
@Override
179+
void gtk4_draw (long widget, long cairo, Rectangle bounds) {
180+
if ((state & OBSCURED) != 0) return;
181+
super.gtk4_draw (widget, cairo, bounds);
182+
drawCaretInFocus(widget, cairo);
183+
}
184+
178185
void drawCaretInFocus(long widget, long cairo) {
179186
/*
180187
* blink is needed to be checked as gtk_draw() signals sent from other parts of the canvas
@@ -197,7 +204,9 @@ private void drawCaret(long widget, long cairo) {
197204
Cairo.cairo_save(cairo);
198205

199206
if (caret.image != null && !caret.image.isDisposed() && caret.image.mask == 0) {
200-
Cairo.cairo_set_source_rgb(cairo, 1, 1, 1);
207+
if (!GTK.GTK4) {
208+
Cairo.cairo_set_source_rgb(cairo, 1, 1, 1);
209+
}
201210
Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_DIFFERENCE);
202211
long surface = Cairo.cairo_get_target(cairo);
203212
int nWidth = 0;
@@ -215,7 +224,9 @@ private void drawCaret(long widget, long cairo) {
215224
Cairo.cairo_set_source_surface(cairo, caret.image.surface, 0, 0);
216225
Cairo.cairo_paint(cairo);
217226
} else {
218-
Cairo.cairo_set_source_rgb(cairo, 1, 1, 1);
227+
if (!GTK.GTK4) {
228+
Cairo.cairo_set_source_rgb(cairo, 1, 1, 1);
229+
}
219230
Cairo.cairo_set_operator(cairo, Cairo.CAIRO_OPERATOR_DIFFERENCE);
220231
int nWidth = caret.width, nHeight = caret.height;
221232
if (nWidth <= 0) nWidth = Caret.DEFAULT_WIDTH;
@@ -248,6 +259,15 @@ long gtk_focus_out_event (long widget, long event) {
248259
return result;
249260
}
250261

262+
@Override
263+
void gtk4_focus_window_event(long handle, long event) {
264+
if(event == SWT.FocusIn) {
265+
gtk_focus_in_event (handle, event);
266+
if (caret != null) caret.setFocus ();
267+
}
268+
else gtk_focus_out_event(handle, event);
269+
}
270+
251271
@Override
252272
long gtk_preedit_changed (long imcontext) {
253273
if (ime != null) {

0 commit comments

Comments
 (0)