Window ID from Java SWT

I would like to find the window id of my SWT program.

I run my SWT shell in the standard way. How can I find the id of the created window? The program runs on Fedora 10 using the Compiz-Fusion window manager (if that matters).

Code to help explain what I mean:

public static void main(String[] args) {
  Display display = new Display();
  Shell shell = new Shell();

  // find window ID here??

  shell.open();

  while (!shell.isDisposed()) {
    if(!display.readAndDispatch()) {
      display.sleep();
    }
  }
}

Update March 6, 2009 After reviewing and trying out a number of things (thanks to VonC for the suggestions below), I came across what has worked so far. This is extremely trickery, but at least it allows me to continue working on some other job.

The identifier returned from Control.embeddedHandle is close to the identifier of the window. It has a predicted bias. So my code is:

public static void main(String[] args) {
  ...
  Shell shell = new shell(display, SWT.NONE);

  Composite e = new Composite(shell, SWT.EMBEDDED);
  long windowID = e.embeddedHandle - WINDOW_ID_MAGIC_NUMBER;
  e.dispose();
  ....

WINDOW_ID_MAGIC_NUMBER - 5+ ( , ).

, . , .

+5
3

Composite SWT.EMBEDDED, SWT/GTK + Composite.embeddedHandle X XEMBED.

Composite embed = new Composite(shell, SWT.EMBEDDED);
System.out.println ("X window ID: " + embed.embeddedHandle);
int hwndChild = OS.GetWindow ( c.handle, OS.GW_CHILD);

XEMBED.

JNI,

GtkWidget *widget = (GtkWidget *) handle;
GdkWindow *window = widget->window;
xwinid = GDK_WINDOW_XWINDOW(window);

.

:

org.eclipse.swt.widgets.Tree, org.eclipse.swt.widgets.CoolItem,

OS, org.eclipse.swt.internal.win32.OS, gtk, , , , .

org.eclipse.swt.internal.gtk.OS , Tree CoolItem, GetWindow .
GTK, , gtk_container_get_children(int container);

,

X, SWT API ( ), , , , , . , , , , :

  • Control.fixedHandle
  • OS.GTK_WIDGET_WINDOW (control.fixedHandle) GdkWindow
  • OS.gdk_x11_drawable_get_xid (gdkWindow), X

, Control.handle, GTK_WIDGET_WINDOW() null , GdkWindow, X.

, SWT GTK +, GDK, X. , X .

+3

, , 7 :-), :

private static long getWindowIdFromShell(Shell shell) {
  long handle = shell.handle;
  long topWidget = OS._gtk_widget_get_toplevel(handle);
  long topWindow = OS._gtk_widget_get_window(topWidget);
  long topXid = OS._gdk_x11_window_get_xid(topWindow);
  return topXid;
}

, "get_toplevel" - , /, , " " (- ).

+3

, . SWT- mplayer.

, Canvas SWT- . embeddedHandle , /.

SWT Control Composite, embeddedHandle, !

0

All Articles