Re: Patch for xembed updated

podarcis <[email protected]>
Newsgroups gmane.comp.web.dillo.devel
Message-ID <[email protected]>
Hi,

I have updated my patch (no removal of existing code, added comments, 
trimmed the source,..).

Let me perhaps explain from the beginning:

My starting point was, that when embedding dillo from an external 
program using the --xid parameter, dillo's window didn't show up in the 
embedder.

I have now found, there's a one-line fix for that problem:

-> dillo_xembed_patch_1.txt

After that was working again (by the way: it worked in dillo2 already) I 
tried to make resizing of the embedder window work too:

-> dillo_xembed_patch_2.txt

A test program for all this:

-> dembed.cxx

Looking forward for your comments.

Cheers,
Podarcis


P.S.:
I am aware now, that *real* embedding (to make tab-switching and 
focus-handling work together with the embedder) will require the usage 
of the xembed-protocol from the embedder side.

I didn't touch the existing part of this implementation.

But I guess embedding dillo without caring for this issues may be useful 
too, for example to just display help pages (no focus handling or 
tabbing required).

_______________________________________________
Dillo-dev mailing list
[email protected]
http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
dillo_xembed_patch_1.txt (text/plain, 294 B)
diff -r 88ac1e8678aa src/xembed.cc
--- a/src/xembed.cc	Thu Jan 03 07:47:25 2013 +0000
+++ b/src/xembed.cc	Sat Jan 05 10:26:17 2013 +0100
@@ -107,6 +107,7 @@
 void Xembed::show() {
    createInternal(xid);
    setXembedInfo(1);
+   Fl_Window::show();
    Fl::event_dispatch(event_handler);
 }
dillo_xembed_patch_2.txt (text/plain, 3.2 KB)
diff -r 9195a2df5ca3 src/xembed.cc
--- a/src/xembed.cc	Fri Jan 04 11:17:00 2013 +0100
+++ b/src/xembed.cc	Sat Jan 05 10:27:16 2013 +0100
@@ -47,7 +47,7 @@
   buffer[1] = flags;
 
   XChangeProperty (fl_display,
-     xid,
+     xid_,
      xembed_info_atom, xembed_info_atom, 32,
      PropModeReplace,
      (unsigned char *)buffer, 2);
@@ -58,14 +58,14 @@
    XClientMessageEvent xclient;
 
    memset (&xclient, 0, sizeof (xclient));
-   xclient.window = xid;
+   xclient.window = xid_;
    xclient.type = ClientMessage;
    xclient.message_type = XInternAtom (fl_display, "_XEMBED", false);
    xclient.format = 32;
    xclient.data.l[0] = fl_event_time;
    xclient.data.l[1] = message;
 
-   XSendEvent(fl_display, xid, False, NoEventMask, (XEvent *)&xclient);
+   XSendEvent(fl_display, xid_, False, NoEventMask, (XEvent *)&xclient);
    XSync(fl_display, False);
 }
 
@@ -77,6 +77,24 @@
    return Fl_Window::handle(e);
 }
 
+void Xembed::updateSize() {
+   // Query X11 for the current dimensions of the embedder window
+   XWindowAttributes winAttributes;
+   XGetWindowAttributes(fl_display, xid_, &winAttributes);
+   int w = winAttributes.width;
+   int h = winAttributes.height;
+   updateSize(w, h);
+}
+
+void Xembed::updateSize(int _w, int _h) {
+   // Resize dillo window only if neccessary
+   if (w() != _w || h() != _h)
+   {
+      resize(x(), y(), _w, _h);
+   }
+}
+
+static Xembed *xembed = 0; // Needed to access class from within...
 static int event_handler(int e, Fl_Window *w) {
    Atom xembed_atom = XInternAtom (fl_display, "_XEMBED", false);
 
@@ -98,16 +116,30 @@
          }
       }
    }
-
+   else if (fl_xevent->type == ConfigureNotify) {
+      // If we get a ConfigureNotify *for the embedder window*
+      // resize dillo window according to the size told.
+      const XConfigureEvent& xcfg = fl_xevent->xconfigure;
+      uint32_t xid = xcfg.window;
+      if (xembed && xembed->xid() == xid)
+      {
+         xembed->updateSize(xcfg.width, xcfg.height);
+      }
+   }
    return Fl::handle_(e, w);
 }
 
 // TODO: Implement more XEMBED support;
 
 void Xembed::show() {
-   createInternal(xid);
+   createInternal(xid_);
    setXembedInfo(1);
+   xembed = this;
+   long mask(StructureNotifyMask);        // Listen to X11 ConfigureNotify events
+   XSelectInput(fl_display, xid_, mask);  // to detect resize of embedder window
+   Fl_Window::show();
    Fl::event_dispatch(event_handler);
+   updateSize(); // initial resize to embedder window size
 }
 
 void Xembed::createInternal(uint32_t parent) {
diff -r 9195a2df5ca3 src/xembed.hh
--- a/src/xembed.hh	Fri Jan 04 11:17:00 2013 +0100
+++ b/src/xembed.hh	Sat Jan 05 10:27:16 2013 +0100
@@ -7,17 +7,20 @@
 
 class Xembed : public Fl_Window {
    private:
-      uint32_t xid;
+      uint32_t xid_;
       void createInternal(uint32_t parent);
       void setXembedInfo(unsigned long flags);
       void sendXembedEvent(uint32_t message);
 
    public:
       Xembed(uint32_t xid, int _w, int _h) : Fl_Window(_w, _h) {
-         this->xid = xid;
+         this->xid_ = xid;
       };
       void show();
       int handle(int event);
+      void updateSize();
+      void updateSize(int _w, int _h);
+      uint32_t xid() const { return xid_; }
 };
 
 #endif
dembed.cxx (text/x-c++src, 511 B)
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/x.H>
#include <iostream>
#include <sstream>

using namespace std;

int main( int argc_, char *argv_[] )
{
   Fl_Window dw( 800, 600, "dillo embedded" );
   dw.resizable( &dw );
   dw.show();
   ostringstream cmd;
   cmd << "dillo -f --xid 0x" << hex << (unsigned long)fl_xid(&dw);
   if ( argc_ > 1 )
      cmd << " " << argv_[1];
   cmd << " &";
   cout << "system '" << cmd.str() << "'" << endl;
   system( cmd.str().c_str() );
   return Fl::run();
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.