> 
> > I am writing a plugin for a system that supplies an X11 
> > window ID and expects the plugin to render its UI inside 
> > that. I want to, therefore, use CreatedWindow such that I am 
> > able to use FLTK in it. The following is a testcase that 
> > blows up in my face just like the real thing:

I lost the orginal message, but my eye just fell on this part.
I've done such thing before with fltk-1.3, but was never able
to run good tests. I just solved my problem.

I added an Fl_Window->attach(xid) member, to attach to an existing
X window. Fl_Window->detach() does the opposite. I leaves a window.

Kurt

Index: fltk-1.3.x-r8365/FL/Fl_Window.H
===================================================================
--- fltk-1.3.x-r8365.orig/FL/Fl_Window.H        2011-02-09 12:46:25.000000000 
+0100
+++ fltk-1.3.x-r8365/FL/Fl_Window.H     2011-02-09 12:46:46.000000000 +0100
@@ -339,6 +339,17 @@
   void icon(const char *xpm[]);
 
   /**
+    API for attaching/detaching windows on X11
+    attach() is to be called _before_ show(), and may resize the window.
+    detach() removes some event from the mask, so other processes
+    may 'attach()' for full functionality.
+    @primary: indicate that the caller should get all events,
+      event those that can only be delivered to 1 client
+  */
+  void detach(void);
+  void attach(long xid, int primary=1);
+
+  /**
     Returns non-zero if show() has been called (but not hide()
     ). You can tell if a window is iconified with (w->shown()
     && !w->visible()).
Index: fltk-1.3.x-r8365/src/Fl_mac.cxx
===================================================================
--- fltk-1.3.x-r8365.orig/src/Fl_mac.cxx        2010-11-29 19:18:27.000000000 
+0100
+++ fltk-1.3.x-r8365/src/Fl_mac.cxx     2011-02-09 12:46:46.000000000 +0100
@@ -2395,6 +2395,15 @@
 }
 
 
+void Fl_Window::detach(void) {
+  // stub function in win32
+}
+
+void Fl_Window::attach(long xid, int primary) {
+  // stub function in win32
+}
+
+
 /**
  * resize a window
  */
Index: fltk-1.3.x-r8365/src/Fl_win32.cxx
===================================================================
--- fltk-1.3.x-r8365.orig/src/Fl_win32.cxx      2011-02-02 13:42:47.000000000 
+0100
+++ fltk-1.3.x-r8365/src/Fl_win32.cxx   2011-02-09 12:46:46.000000000 +0100
@@ -1811,6 +1811,14 @@
   return fl_gc;
 }
 
+void Fl_Window::detach(void) {
+  // stub function in win32
+}
+
+void Fl_Window::attach(long xid, int primary) {
+  // stub function in win32
+}
+
 // make X drawing go into this window (called by subclass flush() impl.)
 void Fl_Window::make_current() {
   fl_GetDC(fl_xid(this));
Index: fltk-1.3.x-r8365/src/Fl_x.cxx
===================================================================
--- fltk-1.3.x-r8365.orig/src/Fl_x.cxx  2011-02-09 12:46:38.000000000 +0100
+++ fltk-1.3.x-r8365/src/Fl_x.cxx       2011-02-09 12:46:46.000000000 +0100
@@ -1553,6 +1553,38 @@
 |EnterWindowMask|LeaveWindowMask
 |PointerMotionMask;
 
+// mask of events that only 1 client can receive
+static const int uniqueEventMask =
+ButtonPressMask|ButtonReleaseMask
+;
+
+void Fl_Window::detach(void) {
+  if (parent() || !i)
+    return;
+
+  XSelectInput(fl_display, fl_xid(this), XEventMask & ~uniqueEventMask);
+}
+
+void Fl_Window::attach(long xid, int primary) {
+  XWindowAttributes wa;
+  long evmask = XEventMask;
+
+  if (!primary)
+    evmask &= ~uniqueEventMask;
+
+  fl_open_display();
+  if(XGetWindowAttributes(fl_display, xid, &wa))
+    this->resize(wa.x, wa.y, wa.width, wa.height);
+  (Fl_X::set_xid(this, xid))->setwindow(this);
+  XSelectInput(fl_display, xid, evmask);
+
+  this->damage(FL_DAMAGE_EXPOSE, 0, 0, wa.width, wa.height);
+  if (wa.map_state == IsViewable) {
+    this->set_visible();
+    Fl_X::i(this)->wait_for_expose = 0;
+  }
+}
+
 void Fl_X::make_xid(Fl_Window* win, XVisualInfo *visual, Colormap colormap)
 {
   Fl_Group::current(0); // get rid of very common user bug: forgot end()

_______________________________________________
fltk-dev mailing list
fltk-dev@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to