Damn, something went wrong with pasting in the patch. Here the complete patch, sorry. --- diff -r 52633c6c3fc6 src/xembed.cc --- a/src/xembed.cc Wed Dec 12 19:40:33 2012 +0000 +++ b/src/xembed.cc Sat Dec 15 11:49:23 2012 +0100 @@ -21,93 +21,49 @@ #ifdef X_PROTOCOL -typedef enum { - XEMBED_EMBEDDED_NOTIFY = 0, - XEMBED_WINDOW_ACTIVATE = 1, - XEMBED_WINDOW_DEACTIVATE = 2, - XEMBED_REQUEST_FOCUS = 3, - XEMBED_FOCUS_IN = 4, - XEMBED_FOCUS_OUT = 5, - XEMBED_FOCUS_NEXT = 6, - XEMBED_FOCUS_PREV = 7, - XEMBED_GRAB_KEY = 8, - XEMBED_UNGRAB_KEY = 9, - XEMBED_MODALITY_ON = 10, - XEMBED_MODALITY_OFF = 11, -} XEmbedMessageType; - -void -Xembed::setXembedInfo(unsigned long flags) -{ - unsigned long buffer[2]; - - Atom xembed_info_atom = XInternAtom (fl_display, "_XEMBED_INFO", false); - - buffer[0] = 1; - buffer[1] = flags; - - XChangeProperty (fl_display, - xid, - xembed_info_atom, xembed_info_atom, 32, - PropModeReplace, - (unsigned char *)buffer, 2); +void Xembed::update_size() { + XWindowAttributes winAttributes; + XGetWindowAttributes( fl_display, xid, &winAttributes ); + int width = winAttributes.width; + int height = winAttributes.height; + update_size(width, height); } -void -Xembed::sendXembedEvent(uint32_t message) { - XClientMessageEvent xclient; - - memset (&xclient, 0, sizeof (xclient)); - 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); - XSync(fl_display, False); +void Xembed::update_size(int width, int height) { + if (w() != width || h() != height) + { + resize(x(), y(), width, height); + redraw(); + } } -int -Xembed::handle(int e) { - if (e == FL_PUSH) - sendXembedEvent(XEMBED_REQUEST_FOCUS); - - return Fl_Window::handle(e); -} - +static Xembed *xembed = 0; static int event_handler(int e, Fl_Window *w) { - Atom xembed_atom = XInternAtom (fl_display, "_XEMBED", false); - - if (fl_xevent->type == ClientMessage) { - if (fl_xevent->xclient.message_type == xembed_atom) { - long message = fl_xevent->xclient.data.l[1]; - - switch (message) { - case XEMBED_WINDOW_ACTIVATE: - // Force a ConfigureNotify message so fltk can get the new - // coordinates after a move of the embedder window. - if (w) - w->resize(0,0, w->w(), w->h()); - break; - case XEMBED_WINDOW_DEACTIVATE: - break; - default: - break; - } + if ( fl_xevent->type == ConfigureNotify ) + { + XConfigureEvent *xcfg = (XConfigureEvent *)fl_xevent; + uint32_t xid = xcfg->window; + if (xembed && xembed->myxid() == xid) + { + xembed->update_size(xcfg->width, xcfg->height); } } - return Fl::handle_(e, w); } // TODO: Implement more XEMBED support; +void Xembed::create() { + xembed = this; + createInternal(xid); + long mask( StructureNotifyMask ); + XSelectInput(fl_display, xid, mask); + Fl::event_dispatch(event_handler); +} + void Xembed::show() { - createInternal(xid); - setXembedInfo(1); - Fl::event_dispatch(event_handler); + Fl_Window::show(); + update_size(); } void Xembed::createInternal(uint32_t parent) { diff -r 52633c6c3fc6 src/xembed.hh --- a/src/xembed.hh Wed Dec 12 19:40:33 2012 +0000 +++ b/src/xembed.hh Sat Dec 15 11:49:23 2012 +0100 @@ -9,15 +9,16 @@ private: 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; create(); }; + uint32_t myxid() const { return xid; } + void create(); void show(); - int handle(int event); + void update_size(); + void update_size( int, int ); }; #endif ---