SWT migration to GTK+ 3.x : Tracker Dilliemma

Couple of weeks I was trying to solve interesting dilemma, so I decided to share it with you.

 I have submitted patch regarding Tracker widget, where I implement Cairo instead of GDK deprecated methods, more about it here .

However, I got a response from Eclipse that it does not work under one condition:

 !! When you pass DISPLAY instead of SHELL as a surface on which Tracker should operate, Tracker does not produce any output.

Sounds like an “easy-breezy” thing to do, but actually it is not.

Let’s look at Tracker Code again and I will explain why:

void drawRectangles (Rectangle [] rects) {
int   window = OS.gdk_get_default_root_window();
if (parent != null) {
window = OS.GTK_WIDGET_WINDOW (parent.paintHandle());
if (window == 0) return;
// My Patch
int  cairo = OS.gdk_cairo_create(window);
if (cairo == 0) error (SWT.ERROR_NO_HANDLES);
Cairo.cairo_set_source_rgb(cairo, 1, 1, 1);
Cairo.cairo_set_line_width(cairo, 1);
Cairo.cairo_set_antialias(cairo, Cairo.CAIRO_ANTIALIAS_NONE);

for (int i=0; i
Rectangle rect = rects [i];
Cairo.cairo_rectangle (cairo, rect.x, rect.y, rect.width, rect.height);
int gc = OS.gdk_gc_new (window);
if (gc == 0) return;
int /*long*/ colormap = OS.gdk_colormap_get_system ();
GdkColor color = new GdkColor ();
OS.gdk_color_white (colormap, color);
OS.gdk_gc_set_foreground (gc, color);
OS.gdk_gc_set_subwindow (gc, OS.GDK_INCLUDE_INFERIORS);
OS.gdk_gc_set_function (gc, OS.GDK_XOR);
for (int i=0; i
Rectangle rect = rects [i];
int x = rect.x;
if (parent != null && (parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - rect.width - x;
OS.gdk_draw_rectangle (window, gc, 0, x, rect.y, rect.width, rect.height);
OS.g_object_unref (gc);

When display is passed to tracker, “parent” variable is null so:

int   window = OS.gdk_get_default_root_window();

is triggered.

Problem is: GDK uses native X11 library, and it allows to draw on root_window (in GNOME, in KDE is not allowed to draw on root), however when you try to do it with Cairo all drawings are clipped by inferiors.

To avoid clipping  GDK uses “wonderful” function:

OS.gdk_gc_set_subwindow (gc, OS.GDK_INCLUDE_INFERIORS);

Unfortunately for me, this function is deprecated and should not be used in newly written code. Also after contacting GTK+ maintainers, I have found out that  drawing on the root window is considered very bad practice, and should not be done.

After some brainstorming, I was advised to create a TRANSPARENT GTK_WINDOW with size of the rectangle, draw rectangle on this transparent window, and move this window depending on the  rectangle coordinates that are passed to the function.. Also I need to use the same XOR method to make rectangle inside the window disappear on mouse-release event, as it happens in the original GDK.

 All of this sounds very logical and appealing. However I am facing another set of challenges.

  •      To make window transparent I need to overwrite “draw” signal, which is not implemented  in SWT, and who knows, if such operation is even allowed in SWT?
  •       GDK way of dealing with rectangles was to redraw rectangle every time mouse moves. As now I have “window” appearing every when method is called – I need to close/reopen window every time, which also is a problem, as I need to find out, If window is opened? and than close it. Much better decision in this case would be to draw one window, and not to redraw it, but than I need to change implementation of the class.

And last question: If I change this implementation, what will happen to the working “when-shell-passed” solution ?

A lot of question and no answers yet….

If you know better solution, or if you have any suggestions regarding this case – please put them as the comment to this post, I appreciate any effort!

I will keep you updated!




Check out more posts on “SWT migration From GTK+ 2 to GTK+ 3”

About Anatoly Spektor

My name is Anatoly Spektor (originally Anatolijs Spektors) I am Software and Web Developer. I have worked in Seneca Center for Development of Open Technology on Big Blue Button Add-on - Polling Module, Red Hat and some other places :) I am an author of the book 'Eclipse Debugging How To', Muay Thai fighter and amateur photographer ;)
This entry was posted in Cairo Graphics Library, Eclipse Development, open-source, Red Hat, SWT and tagged , , , , , , , . Bookmark the permalink.

2 Responses to SWT migration to GTK+ 3.x : Tracker Dilliemma

  1. Pingback: SWT: GTK_INCLUDE_INFERIORS worst enemy (Sash Widget) « My Programming Blog

  2. Pingback: SWT: GTK_INCLUDE_INFERIORS worst enemy (Sash Widget) - My Programming Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s